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