OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
acl_entry.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #ifndef __AGENT_ACL_ENTRY_H__
6 #define __AGENT_ACL_ENTRY_H__
7 
8 #include <boost/ptr_container/ptr_list.hpp>
9 #include <boost/intrusive/list.hpp>
10 #include <boost/intrusive/slist.hpp>
11 #include <boost/uuid/uuid.hpp>
12 
13 #include <cmn/agent_cmn.h>
14 #include <cmn/agent.h>
15 
16 #include <agent_types.h>
17 
18 struct PacketHeader;
19 struct FlowPolicyInfo;
20 class AclEntrySpec;
21 class TrafficAction;
22 class AclEntryMatch;
23 
24 struct AclEntryID {
25 
26  enum Type {
28  //In case of bidirection rule DERIVED rule represents the ACE which
29  //agent internally adds for matching the
30  //reverse session
31  //Ex. If forward rule says EP1 <> EP2 DPORT
32  //FORWARD rule would be
33  //EP1 > EP2 DPORT
34  //DERIVED rule would be
35  //EP2 > EP1 DPORT
37  };
38 
39  AclEntryID(int32_t id) : type_(FORWARD) {
40  std::stringstream stream;
41  stream << std::setfill('0') << std::setw(8) << id;
42  id_ = stream.str();
43  }
44 
45  AclEntryID(std::string id, Type type):
46  id_(id), type_(type) {
47  }
48 
49  bool operator ==(const AclEntryID &ace_id) const {
50  if (id_ == ace_id.id_ && type_ == ace_id.type_) {
51  return true;
52  }
53  return false;
54  }
55 
56  bool operator <(const AclEntryID &ace_id) const {
57  if (id_ != ace_id.id_) {
58  return id_ < ace_id.id_;
59  }
60 
61  return type_ < ace_id.type_;
62  }
63 
64  bool operator >(const AclEntryID &ace_id) const {
65  if (id_ != ace_id.id_) {
66  return id_ > ace_id.id_;
67  }
68 
69  return type_ > ace_id.type_;
70  }
71 
72  bool operator !=(const AclEntryID &ace_id) const {
73  if (id_ != ace_id.id_ ||
74  type_ != ace_id.type_) {
75  return true;
76  }
77 
78  return false;
79  }
80 
81  std::string id_;
83 };
84 
85 typedef std::vector<AclEntryID> AclEntryIDList;
86 
87 class AclEntry {
88 public:
89  enum AclType {
90  TERMINAL = 1,
92  };
93 
94  typedef std::list<TrafficAction *> ActionList;
97  id_(0), type_(TERMINAL), matches_(), actions_(), mirror_entry_(NULL),
98  uuid_(), family_(Address::UNSPEC) {}
99 
101  id_(0), type_(type), matches_(), actions_(), mirror_entry_(NULL),
102  uuid_(), family_(Address::UNSPEC) {}
103 
104  ~AclEntry();
105 
106  // Create the entry
107  void PopulateAclEntry(const AclEntrySpec &acl_entry_spec);
108  // Set Mirror ref
110 
111  // Match packet header
112  const ActionList &PacketMatch(const PacketHeader &packet_header,
113  FlowPolicyInfo *info) const;
114  const ActionList &Actions() const {return actions_;};
115 
116  void SetAclEntrySandeshData(AclEntrySandeshData &data) const;
117 
118  bool IsTerminal() const;
119 
120  const AclEntryID& id() const { return id_; }
121  const std::string &uuid() const { return uuid_; }
122 
123  boost::intrusive::list_member_hook<> acl_list_node;
124 
125  bool operator==(const AclEntry &rhs) const;
126  bool ResyncQosConfigEntries();
127  bool IsQosConfigResolved();
128  const AclEntryMatch* Get(uint32_t index) const {
129  return matches_[index];
130  }
131  const Address::Family& family() const { return family_ ;}
132 
133 private:
136  std::vector<AclEntryMatch *> matches_;
139  std::string uuid_;
142 };
143 
144 #endif
const ActionList & Actions() const
Definition: acl_entry.h:114
bool IsQosConfigResolved()
Definition: acl_entry.cc:198
~AclEntry()
Definition: acl_entry.cc:30
std::list< TrafficAction * > ActionList
Definition: acl_entry.h:94
ActionList actions_
Definition: acl_entry.h:137
Family
Definition: address.h:24
MirrorEntryRef mirror_entry_
Definition: acl_entry.h:138
std::vector< AclEntryID > AclEntryIDList
Definition: acl_entry.h:85
bool operator==(const AclEntry &rhs) const
Definition: acl_entry.cc:296
AclEntryID id_
Definition: acl_entry.h:134
std::string id_
Definition: acl_entry.h:81
void SetAclEntrySandeshData(AclEntrySandeshData &data) const
Definition: acl_entry.cc:244
static ActionList kEmptyActionList
Definition: acl_entry.h:95
AclEntry(AclType type)
Definition: acl_entry.h:100
uint8_t type
Definition: load_balance.h:109
const Address::Family & family() const
Definition: acl_entry.h:131
AclEntryID(std::string id, Type type)
Definition: acl_entry.h:45
const AclEntryID & id() const
Definition: acl_entry.h:120
AclType type_
Definition: acl_entry.h:135
AclEntry()
Definition: acl_entry.h:96
const AclEntryMatch * Get(uint32_t index) const
Definition: acl_entry.h:128
bool ResyncQosConfigEntries()
Definition: acl_entry.cc:211
bool operator>(const AclEntryID &ace_id) const
Definition: acl_entry.h:64
bool operator==(const AclEntryID &ace_id) const
Definition: acl_entry.h:49
std::vector< AclEntryMatch * > matches_
Definition: acl_entry.h:136
std::string uuid_
Definition: acl_entry.h:139
void PopulateAclEntry(const AclEntrySpec &acl_entry_spec)
Definition: acl_entry.cc:46
boost::intrusive_ptr< MirrorEntry > MirrorEntryRef
Definition: agent.h:99
Address::Family family_
Definition: acl_entry.h:140
boost::intrusive::list_member_hook acl_list_node
Definition: acl_entry.h:123
bool IsTerminal() const
Definition: acl_entry.cc:288
const std::string & uuid() const
Definition: acl_entry.h:121
const ActionList & PacketMatch(const PacketHeader &packet_header, FlowPolicyInfo *info) const
Definition: acl_entry.cc:232
DISALLOW_COPY_AND_ASSIGN(AclEntry)
Type type_
Definition: acl_entry.h:82
bool operator!=(const AclEntryID &ace_id) const
Definition: acl_entry.h:72
void set_mirror_entry(MirrorEntryRef me)
Definition: acl_entry.cc:228
bool operator<(const AclEntryID &ace_id) const
Definition: acl_entry.h:56
AclEntryID(int32_t id)
Definition: acl_entry.h:39