OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
traffic_action.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #ifndef __AGENT_TRAFFIC_ACTION_H__
6 #define __AGENT_TRAFFIC_ACTION_H__
7 
8 #include <vector>
9 #include <string>
10 #include <base/util.h>
11 #include <base/address.h>
12 #include <boost/uuid/uuid.hpp>
13 #include <boost/uuid/uuid_io.hpp>
14 #include <boost/uuid/nil_generator.hpp>
15 
16 #include <cmn/agent_cmn.h>
17 #include <cmn/agent.h>
18 #include <oper/qos_config.h>
19 
20 #include <agent_types.h>
21 
23 public:
32  };
33  // Don't go beyond 31
34  enum Action {
35  ALERT = 1,
36  DENY = 3,
37  LOG = 4,
38  PASS = 5,
39  MIRROR = 7,
41  APPLY_QOS = 9,
42  TRAP = 28,
43  HBS = 10,
45  RESERVED = 30,
46  UNKNOWN = 31,
47  };
48  static const std::string kActionLogStr;
49  static const std::string kActionAlertStr;
50  static const std::string kActionHbsStr;
51  static const uint32_t DROP_FLAGS = ((1 << DENY));
52  static const uint32_t PASS_FLAGS = ((1 << PASS));
53  static const uint32_t IMPLICIT_DENY_FLAGS = ((1 << IMPLICIT_DENY));
54 
57  action_type_(type) {}
58  virtual ~TrafficAction() {}
59 
60  bool IsDrop() const;
61  Action action() const {return action_;}
63  static std::string ActionToString(enum Action at);
64  virtual void SetActionSandeshData(std::vector<ActionStr> &actions);
65  virtual bool Compare(const TrafficAction &rhs) const = 0;
66  bool operator==(const TrafficAction &rhs) const {
67  if (action_type_ != rhs.action_type_) {
68  return false;
69  }
70  if (action_ != rhs.action_) {
71  return false;
72  }
73  return Compare(rhs);
74  }
75 private:
78 };
79 
80 class SimpleAction : public TrafficAction {
81 public:
84  virtual bool Compare(const TrafficAction &rhs) const {
85  if (action() != rhs.action()) {
86  return false;
87  }
88  return true;
89  }
90 private:
92 };
93 
94 class MirrorAction : public TrafficAction {
95 public:
96  MirrorAction(std::string analyzer_name, std::string vrf_name,
97  IpAddress ip, uint16_t port, std::string encap) :
99  vrf_name_(vrf_name), m_ip_(ip), port_(port), encap_(encap) {}
100  ~MirrorAction();
101  IpAddress GetIp() {return m_ip_;}
102  uint32_t GetPort() {return port_;}
103  std::string vrf_name() {return vrf_name_;}
104  std::string GetAnalyzerName() {return analyzer_name_;}
105  std::string GetEncap() {return encap_;}
106  virtual void SetActionSandeshData(std::vector<ActionStr> &actions);
107  virtual bool Compare(const TrafficAction &rhs) const;
108 private:
109  std::string analyzer_name_;
110  std::string vrf_name_;
112  uint16_t port_;
113  std::string encap_;
115 };
116 
118 public:
119  VrfTranslateAction(const std::string &vrf_name, bool ignore_acl):
121  vrf_name_(vrf_name), ignore_acl_(ignore_acl) {}
122  const std::string& vrf_name() const { return vrf_name_;}
123  bool ignore_acl() const { return ignore_acl_;}
124  virtual void SetActionSandeshData(std::vector<ActionStr> &actions);
125  virtual bool Compare(const TrafficAction &rhs) const;
126 private:
127  std::string vrf_name_;
129 };
130 
132 public:
135  QosConfigAction(const std::string &qos_config_name):
137  name_(qos_config_name), qos_config_ref_(NULL) {}
138  virtual ~QosConfigAction() { }
139  const std::string& name() const {
140  return name_;
141  }
142 
143  void set_qos_config_ref(const AgentQosConfig *config) {
144  qos_config_ref_ = config;
145  }
147  return qos_config_ref_.get();
148  }
149 
150  virtual bool Compare(const TrafficAction &rhs) const;
151  virtual void SetActionSandeshData(std::vector<ActionStr> &actions);
152 private:
153  std::string name_;
155 };
156 
157 class LogAction : public TrafficAction {
158 public:
161  virtual bool Compare(const TrafficAction &rhs) const {
162  if (action() != rhs.action()) {
163  return false;
164  }
165  return true;
166  }
167 private:
169 };
170 
171 class AlertAction : public TrafficAction {
172 public:
175  virtual bool Compare(const TrafficAction &rhs) const {
176  if (action() != rhs.action()) {
177  return false;
178  }
179  return true;
180  }
181 private:
183 };
184 
185 class HbsAction : public TrafficAction {
186 public:
189  virtual bool Compare(const TrafficAction &rhs) const {
190  if (action() != rhs.action()) {
191  return false;
192  }
193  return true;
194  }
195 private:
197 };
198 #endif
std::string GetAnalyzerName()
virtual ~QosConfigAction()
virtual bool Compare(const TrafficAction &rhs) const =0
boost::asio::ip::address IpAddress
Definition: address.h:13
const AgentQosConfig * qos_config_ref() const
const std::string & vrf_name() const
static const uint32_t DROP_FLAGS
virtual bool Compare(const TrafficAction &rhs) const
const std::string & name() const
bool IsDrop() const
DISALLOW_COPY_AND_ASSIGN(AlertAction)
virtual void SetActionSandeshData(std::vector< ActionStr > &actions)
static const std::string kActionLogStr
QosConfigAction(const std::string &qos_config_name)
virtual void SetActionSandeshData(std::vector< ActionStr > &actions)
std::string encap_
std::string GetEncap()
SimpleAction(Action action)
MirrorAction(std::string analyzer_name, std::string vrf_name, IpAddress ip, uint16_t port, std::string encap)
uint8_t type
Definition: load_balance.h:109
virtual bool Compare(const TrafficAction &rhs) const
static const std::string kActionHbsStr
std::string name_
boost::intrusive_ptr< const AgentQosConfig > AgentQosConfigConstRef
Definition: agent.h:178
void set_qos_config_ref(const AgentQosConfig *config)
uint32_t GetPort()
virtual bool Compare(const TrafficAction &rhs) const
DISALLOW_COPY_AND_ASSIGN(SimpleAction)
static std::string ActionToString(enum Action at)
virtual bool Compare(const TrafficAction &rhs) const
virtual void SetActionSandeshData(std::vector< ActionStr > &actions)
bool ignore_acl() const
std::string vrf_name_
IpAddress m_ip_
std::string analyzer_name_
TrafficAction(Action action, TrafficActionType type)
IpAddress GetIp()
virtual bool Compare(const TrafficAction &rhs) const
uint16_t port_
virtual bool Compare(const TrafficAction &rhs) const
virtual bool Compare(const TrafficAction &rhs) const
DISALLOW_COPY_AND_ASSIGN(LogAction)
std::string vrf_name()
Action action() const
TrafficActionType action_type_
bool operator==(const TrafficAction &rhs) const
std::string vrf_name_
VrfTranslateAction(const std::string &vrf_name, bool ignore_acl)
static const std::string kActionAlertStr
static const uint32_t IMPLICIT_DENY_FLAGS
DISALLOW_COPY_AND_ASSIGN(MirrorAction)
virtual ~TrafficAction()
AgentQosConfigConstRef qos_config_ref_
static const uint32_t PASS_FLAGS
TrafficActionType action_type() const
DISALLOW_COPY_AND_ASSIGN(HbsAction)
virtual void SetActionSandeshData(std::vector< ActionStr > &actions)