OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
policy_set.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #ifndef SRC_VNSW_AGENT_FILTER_POLICY_SET_H_
6 #define SRC_VNSW_AGENT_FILTER_POLICY_SET_H_
7 
8 #include <boost/scoped_ptr.hpp>
9 #include <db/db.h>
10 #include <cmn/agent.h>
11 #include <cmn/agent_db.h>
12 #include <oper/oper_db.h>
13 
14 class PolicySetTable;
15 
16 //Policy set is a list of ACL.
17 //Schema of policy set looks as below
18 //
19 // |---P1-->firewall-policy --R1-->firewall-rule
20 // |
21 // TAG <--- application-policy-set --P2--> firewall-policy --R2-->firewall-rule
22 // |
23 // |---P3-->firewall-policy --R3-->firewall-rule
24 //
25 //Application policy set would be linked to firewall policy by a link
26 //with attribute which is strings what gives lexical order in which
27 //firewall-policy have to be applied.
28 //
29 //Firewall-policy at scheam is equivalent of ACL in agent.
30 //Firewall-policy is linked to firewall-rule with attribute which gives the
31 //lexical order in which firewall-rule have to be applied
32 //
33 //How does APS get applied on VMI?
34 // ++++++++++++++++++
35 // VMI ---> + Application Tag+ <----application-policy-set--->firewall-policy
36 // ++++++++++++++++++
37 //
38 //VMI parses thru above links and frames the ACL to be applied
39 //for flow of VMI
40 struct PolicySetKey : public AgentOperDBKey {
42  AgentOperDBKey(), uuid_(uuid) {};
44 };
45 
46 //Policy set has a link with attribute to firewall-rule
47 //Firewall rule gives the sequence no. or ace id to determine
48 //the order in which Fw rule have to be applied. Below map
49 //is used to store that list in order
50 typedef std::map<std::string, boost::uuids::uuid> FirewallPolicyUuidList;
51 typedef std::pair<std::string, boost::uuids::uuid> FirewallPolicyPair;
52 
53 struct PolicySetData : public AgentOperDBData {
54  PolicySetData(Agent *agent, IFMapNode *node, const std::string &name,
55  bool global, FirewallPolicyUuidList &list):
56  AgentOperDBData(agent, node), name_(name),
57  global_(global), fw_policy_uuid_list_(list) {}
59 
60  const std::string name_;
61  bool global_;
63 };
64 
65 class PolicySet : AgentRefCount<PolicySet>, public AgentOperDBEntry {
66 public:
67  typedef std::vector<AclDBEntryConstRef> FirewallPolicyList;
69  ~PolicySet();
70 
71  virtual bool IsLess(const DBEntry &rhs) const;
72  virtual std::string ToString() const;
73  virtual KeyPtr GetDBRequestKey() const;
74  virtual void SetKey(const DBRequestKey *key);
75  bool DBEntrySandesh(Sandesh *resp, std::string &name) const;
76  bool Change(PolicySetTable *table, const PolicySetData *data);
77  void Delete();
78 
79  const boost::uuids::uuid &uuid() const { return uuid_; }
80  const std::string &name() const { return name_; }
81 
82  virtual uint32_t GetRefCount() const {
84  }
85 
86  const AclDBEntry* GetAcl(uint32_t index) {
87  return fw_policy_list_[index].get();
88  }
89 
91  return fw_policy_list_;
92  }
93 
95  return fw_policy_list_;
96  }
97 
98  bool global() const {
99  return global_;
100  }
101 
102 private:
103  friend class PolicySetTable;
105  std::string name_;
108  bool global_;
110 };
111 
113 public:
114  PolicySetTable(DB *db, const std::string &name) :
115  AgentOperDBTable(db, name), global_policy_set_(NULL) {};
117 
118  virtual std::unique_ptr<DBEntry> AllocEntry(const DBRequestKey *key) const;
119 
120  virtual size_t Hash(const DBEntry *entry) const {return 0;}
121  virtual size_t Hash(const DBRequestKey *key) const {return 0;}
122 
123  virtual DBEntry *OperDBAdd(const DBRequest *req);
124  virtual bool OperDBOnChange(DBEntry *entry, const DBRequest *req);
125  virtual bool OperDBResync(DBEntry *entry, const DBRequest *req);
126  virtual bool OperDBDelete(DBEntry *entry, const DBRequest *req);
127 
128  virtual bool IFNodeToReq(IFMapNode *node, DBRequest &req,
129  const boost::uuids::uuid &u);
130  bool ProcessConfig(IFMapNode *node, DBRequest &req,
131  const boost::uuids::uuid &u);
132  virtual bool IFNodeToUuid(IFMapNode *node, boost::uuids::uuid &u);
133 
134  virtual AgentSandeshPtr
136  const std::string &context);
137  PolicySet* Find(const boost::uuids::uuid &u);
138  static DBTableBase *CreateTable(DB *db, const std::string &name);
139 
141  return global_policy_set_;
142  }
143 
145  global_policy_set_ = ps;
146  }
147 
148 private:
151 };
152 #endif
bool global_
Definition: policy_set.h:108
DISALLOW_COPY_AND_ASSIGN(PolicySetTable)
const AclDBEntry * GetAcl(uint32_t index)
Definition: policy_set.h:86
std::string name_
Definition: policy_set.h:105
bool Change(PolicySetTable *table, const PolicySetData *data)
Definition: policy_set.cc:48
uint32_t GetRefCount() const
Definition: agent_db.h:54
virtual bool IFNodeToUuid(IFMapNode *node, boost::uuids::uuid &u)
Definition: policy_set.cc:224
const FirewallPolicyList & fw_policy_list() const
Definition: policy_set.h:94
const std::string & name() const
Definition: policy_set.h:80
boost::uuids::uuid uuid_
Definition: policy_set.h:104
virtual uint32_t GetRefCount() const
Definition: policy_set.h:82
FirewallPolicyList fw_policy_list_
Definition: policy_set.h:107
virtual AgentSandeshPtr GetAgentSandesh(const AgentSandeshArguments *args, const std::string &context)
Definition: policy_set.cc:274
PolicySetData(Agent *agent, IFMapNode *node, const std::string &name, bool global, FirewallPolicyUuidList &list)
Definition: policy_set.h:54
std::pair< std::string, boost::uuids::uuid > FirewallPolicyPair
Definition: policy_set.h:51
virtual DBEntry * OperDBAdd(const DBRequest *req)
Definition: policy_set.cc:232
PolicySet(const boost::uuids::uuid &uuid)
Definition: policy_set.cc:17
virtual bool IFNodeToReq(IFMapNode *node, DBRequest &req, const boost::uuids::uuid &u)
Definition: policy_set.cc:190
boost::uuids::uuid uuid
PolicySetTable(DB *db, const std::string &name)
Definition: policy_set.h:114
virtual size_t Hash(const DBRequestKey *key) const
Definition: policy_set.h:121
PolicySet * global_policy_set_
Definition: policy_set.h:149
std::map< std::string, boost::uuids::uuid > FirewallPolicyUuidList
Definition: policy_set.h:50
std::unique_ptr< DBRequestKey > KeyPtr
Definition: db_entry.h:25
virtual std::unique_ptr< DBEntry > AllocEntry(const DBRequestKey *key) const
Definition: policy_set.cc:118
virtual bool OperDBOnChange(DBEntry *entry, const DBRequest *req)
Definition: policy_set.cc:247
PolicySetKey(const boost::uuids::uuid &uuid)
Definition: policy_set.h:41
Definition: db.h:24
std::vector< AclDBEntryConstRef > FirewallPolicyList
Definition: policy_set.h:67
FirewallPolicyList & fw_policy_list()
Definition: policy_set.h:90
Definition: agent.h:358
bool global() const
Definition: policy_set.h:98
bool DBEntrySandesh(Sandesh *resp, std::string &name) const
Definition: policy_set.cc:92
virtual bool IsLess(const DBEntry &rhs) const
Definition: policy_set.cc:25
class boost::shared_ptr< AgentSandesh > AgentSandeshPtr
Definition: agent_db.h:18
const std::string & name() const
Definition: db_table.h:110
const boost::uuids::uuid & uuid() const
Definition: policy_set.h:79
FirewallPolicyUuidList fw_policy_uuid_list_
Definition: policy_set.h:106
void Delete()
static DBTableBase * CreateTable(DB *db, const std::string &name)
Definition: policy_set.cc:261
virtual std::string ToString() const
Definition: policy_set.cc:30
PolicySet * global_policy_set() const
Definition: policy_set.h:140
const Agent * agent() const
Definition: oper_db.h:65
const std::string name_
Definition: policy_set.h:60
virtual void SetKey(const DBRequestKey *key)
Definition: policy_set.cc:43
bool ProcessConfig(IFMapNode *node, DBRequest &req, const boost::uuids::uuid &u)
Definition: policy_set.cc:208
virtual size_t Hash(const DBEntry *entry) const
Definition: policy_set.h:120
virtual bool OperDBDelete(DBEntry *entry, const DBRequest *req)
Definition: policy_set.cc:251
boost::uuids::uuid uuid_
Definition: policy_set.h:42
DISALLOW_COPY_AND_ASSIGN(PolicySet)
virtual bool OperDBResync(DBEntry *entry, const DBRequest *req)
Definition: policy_set.cc:241
void set_global_policy_set(PolicySet *ps)
Definition: policy_set.h:144
Definition: acl.h:92
virtual KeyPtr GetDBRequestKey() const
Definition: policy_set.cc:38
FirewallPolicyUuidList fw_policy_uuid_list_
Definition: policy_set.h:62
PolicySet * Find(const boost::uuids::uuid &u)