OpenSDN source code
traffic_action.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
6 #include <vector>
7 
8 #include <cmn/agent_cmn.h>
9 #include <vnc_cfg_types.h>
10 #include <agent_types.h>
11 
12 #include <filter/traffic_action.h>
13 #include <filter/acl_entry_match.h>
14 #include <filter/acl_entry.h>
15 #include <filter/acl_entry_spec.h>
16 #include <filter/packet_header.h>
17 
18 #include <oper/vn.h>
19 #include <oper/nexthop.h>
20 #include <oper/mirror_table.h>
21 
22 const std::string TrafficAction::kActionLogStr = "log";
23 const std::string TrafficAction::kActionAlertStr = "alert";
24 const std::string TrafficAction::kActionHbsStr = "hbs";
25 
26 bool TrafficAction::IsDrop() const {
27  if (((1 << action_) & TrafficAction::DROP_FLAGS) ||
29  return true;
30  }
31  return false;
32 }
33 
35 {
36  switch(at) {
37  case ALERT:
38  return kActionAlertStr;
39  case DENY:
40  return("deny");
41  case LOG:
42  return kActionLogStr;
43  case PASS:
44  return("pass");
45  case MIRROR:
46  return("mirror");
47  case TRAP:
48  return("trap");
49  case IMPLICIT_DENY:
50  return("implicit deny");
51  case VRF_TRANSLATE:
52  return("VRF assign");
53  case APPLY_QOS:
54  return ("Apply QOS marking");
55  case HBS:
56  return ("Apply HBS");
57  default:
58  return("unknown");
59  }
60 }
61 
62 void TrafficAction::SetActionSandeshData(std::vector<ActionStr> &actions) {
63  ActionStr astr;
64  astr.action = ActionToString(action());
65  actions.push_back(astr);
66  return;
67 }
68 
69 void MirrorAction::SetActionSandeshData(std::vector<ActionStr> &actions) {
70  ActionStr astr;
71  astr.action = ActionToString(action());
72  actions.push_back(astr);
73  astr.action = m_ip_.to_string();
74  actions.push_back(astr);
75  std::stringstream ss;
76  ss << port_;
77  astr.action = ss.str();
78  actions.push_back(astr);
79  return;
80 }
81 
82 bool MirrorAction::Compare(const TrafficAction &rhs) const {
83  const MirrorAction &rhs_mirror_action =
84  static_cast<const MirrorAction &>(rhs);
85  if (analyzer_name_ != rhs_mirror_action.analyzer_name_) {
86  return false;
87  }
88 
89  if (vrf_name_ != rhs_mirror_action.vrf_name_) {
90  return false;
91  }
92 
93  if (m_ip_ != rhs_mirror_action.m_ip_) {
94  return false;
95  }
96 
97  if (port_ != rhs_mirror_action.port_) {
98  return false;
99  }
100 
101  if (encap_ != rhs_mirror_action.encap_) {
102  return false;
103  }
104  return true;
105 }
106 
108  //Agent::mirror_table()->DelMirrorEntry(analyzer_name_);
109 }
110 
111 void VrfTranslateAction::SetActionSandeshData(std::vector<ActionStr> &actions) {
112  ActionStr astr;
113  astr.action = ActionToString(action());
114  actions.push_back(astr);
115  std::stringstream ss;
116  ss << vrf_name_;
117  if (ignore_acl_) {
118  ss << " ignore acl";
119  }
120  astr.action = ss.str();
121  actions.push_back(astr);
122  return;
123 }
124 
126  const VrfTranslateAction &rhs_vrf_action =
127  static_cast<const VrfTranslateAction &>(rhs);
128  if (vrf_name_ != rhs_vrf_action.vrf_name_) {
129  return false;
130  }
131  if (ignore_acl_ != rhs_vrf_action.ignore_acl_) {
132  return false;
133  }
134  return true;
135 }
136 
137 void QosConfigAction::SetActionSandeshData(std::vector<ActionStr> &actions) {
138  ActionStr astr;
139  astr.action = ActionToString(action());
140  actions.push_back(astr);
141  std::stringstream ss;
142  ss << name_;
143  astr.action = ss.str();
144  actions.push_back(astr);
145  return;
146 }
147 
149  const QosConfigAction &rhs = static_cast<const QosConfigAction &>(r);
150  if (name_ != rhs.name_) {
151  return false;
152  }
153  if (qos_config_ref_.get() != rhs.qos_config_ref_.get()) {
154  return false;
155  }
156  return true;
157 }
std::string encap_
std::string vrf_name_
IpAddress m_ip_
uint16_t port_
virtual void SetActionSandeshData(std::vector< ActionStr > &actions)
std::string analyzer_name_
virtual bool Compare(const TrafficAction &rhs) const
virtual void SetActionSandeshData(std::vector< ActionStr > &actions)
std::string name_
virtual bool Compare(const TrafficAction &rhs) const
AgentQosConfigConstRef qos_config_ref_
static std::string ActionToString(enum Action at)
virtual void SetActionSandeshData(std::vector< ActionStr > &actions)
static const std::string kActionHbsStr
static const std::string kActionLogStr
Action action() const
static const uint32_t IMPLICIT_DENY_FLAGS
static const uint32_t DROP_FLAGS
bool IsDrop() const
static const std::string kActionAlertStr
std::string vrf_name_
virtual void SetActionSandeshData(std::vector< ActionStr > &actions)
virtual bool Compare(const TrafficAction &rhs) const