OpenSDN source code
flow_mgmt_entry.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
6 #ifndef __AGENT_PKT_FLOW_MGMT_ENTRY_H__
7 #define __AGENT_PKT_FLOW_MGMT_ENTRY_H__
8 
9 #include <string>
10 #include <map>
11 #include <boost/intrusive/list.hpp>
12 #include <base/util.h>
14 #include <filter/acl_entry.h>
15 
16 class Agent;
17 class FlowEntry;
18 class FlowMgmtManager;
19 class FlowMgmtRequest;
20 class VrfFlowMgmtTree;
21 
22 class FlowMgmtKey;
26 
27 class AclDBEntry;
28 class AclFlowResp;
29 class AclFlowCountResp;
30 
32 public:
33  // Flow management state of the entry
34  enum State {
39  };
40 
41  typedef boost::intrusive::member_hook<FlowMgmtKeyNode,
42  boost::intrusive::list_member_hook<>,
44  typedef boost::intrusive::list<FlowMgmtKeyNode, Node> FlowList;
45 
46  static const int MaxResponses = 100;
47 
49  }
50  virtual ~FlowMgmtEntry() {
51  assert(flow_list_.size() == 0);
52  }
53 
54  uint32_t Size() const { return flow_list_.size(); }
55  // Make flow dependent on the DBEntry
56  virtual bool Add(FlowEntry *flow, FlowMgmtKeyNode *node);
57  // Remove flow from dependency tree
58  virtual bool Delete(FlowEntry *flow, FlowMgmtKeyNode *node);
59 
60  // Handle Add/Change event for DBEntry
61  virtual bool OperEntryAdd(FlowMgmtManager *mgr, const FlowMgmtRequest *req,
62  FlowMgmtKey *key);
63  virtual bool OperEntryChange(FlowMgmtManager *mgr,
64  const FlowMgmtRequest *req, FlowMgmtKey *key);
65  // Handle Delete event for DBEntry
66  virtual bool OperEntryDelete(FlowMgmtManager *mgr,
67  const FlowMgmtRequest *req, FlowMgmtKey *key);
68  // Handle Delete event for Non-DBEntry
70  const FlowMgmtRequest *req,
71  FlowMgmtKey *key) { return true; }
72  // Can the entry be deleted?
73  virtual bool CanDelete() const;
74 
75  void set_oper_state(State state) { oper_state_ = state; }
76  State oper_state() const { return oper_state_; }
77  uint32_t gen_id() const { return gen_id_; }
78  const FlowList &flow_list() const { return flow_list_; }
79 
80 protected:
81  // Add seen from OperDB entry
83  uint32_t gen_id_;
85 
86 private:
88 };
89 
91 public:
92  typedef std::map<std::string, int> AceIdFlowCntMap;
94  virtual ~AclFlowMgmtEntry() { }
95  void FillAclFlowSandeshInfo(const AclDBEntry *acl, AclFlowResp &data,
96  const int last_count, Agent *agent);
97  void FillAceFlowSandeshInfo(const AclDBEntry *acl, AclFlowCountResp &data,
98  const std::string &ace_id);
99  bool Add(const AclEntryIDList *ace_id_list, FlowEntry *flow,
100  const AclEntryIDList *old_id_list, FlowMgmtKeyNode *node);
101  bool Delete(const AclEntryIDList *ace_id_list, FlowEntry *flow,
102  FlowMgmtKeyNode *node);
103  void DecrementAceIdCountMap(const AclEntryIDList *id_list);
104 
105 private:
106  std::string GetAceSandeshDataKey(const AclDBEntry *acl,
107  const std::string &ace_id);
108  std::string GetAclFlowSandeshDataKey(const AclDBEntry *acl,
109  const int last_count) const;
110  uint32_t flow_miss_;
113 };
114 
116 public:
119  }
120  virtual ~VnFlowMgmtEntry() { }
121 
122  void UpdateCounterOnAdd(FlowEntry *flow, bool add_flow, bool local_flow,
123  bool old_ingress);
124  void UpdateCounterOnDel(FlowEntry *flow, bool local_flow, bool old_ingress);
125  uint32_t ingress_flow_count() const { return ingress_flow_count_; }
126  uint32_t egress_flow_count() const { return egress_flow_count_; }
127 
128 private:
132 };
133 
135 public:
137  flow_aged_(0) { }
139 
140  bool Add(FlowEntry *flow, FlowMgmtKeyNode *node);
141  bool Delete(FlowEntry *flow, FlowMgmtKeyNode *node);
142  uint64_t flow_created() const { return flow_created_; }
143  uint64_t flow_aged() const { return flow_aged_; }
144 
145 private:
146  uint64_t flow_created_;
147  uint64_t flow_aged_;
149 };
150 
152 public:
154  virtual ~NhFlowMgmtEntry() { }
155 
156 private:
158 };
159 
161 public:
163  virtual ~RouteFlowMgmtEntry() { }
164 
165 private:
167 };
168 
170 public:
173  // Handle covering routeEntry
175  InetRouteFlowMgmtKey *covering_route,
176  InetRouteFlowMgmtKey *key);
177  bool HandleNhChange(FlowMgmtManager *mgr, const FlowMgmtRequest *req,
178  FlowMgmtKey *key);
179 
180 private:
182 };
183 
185 public:
188 
189 private:
191 };
192 
194 public:
195  struct Data {
196  Data(VrfFlowMgmtEntry *vrf_mgmt_entry, const VrfEntry *vrf,
197  AgentRouteTable *table);
198  virtual ~Data();
199  void ManagedDelete();
200  bool deleted() const { return deleted_; }
201 
202  bool deleted_;
205  const VrfEntry *vrf_;
206  };
207 
209  virtual ~VrfFlowMgmtEntry() { }
210  bool CanDelete() const;
211  VrfFlowMgmtTree *vrf_tree() const { return vrf_tree_; }
212  uint32_t vrf_id() const { return vrf_id_; }
213 
214 private:
215  friend class VrfFlowMgmtTree;
216  const VrfEntry *vrf_;
217  uint32_t vrf_id_;
221  // Back reference for the tree
224 };
225 
227 public:
230  virtual bool NonOperEntryDelete(FlowMgmtManager *mgr,
231  const FlowMgmtRequest *req,
232  FlowMgmtKey *key);
233  virtual bool HealthCheckUpdate(Agent *agent, FlowMgmtManager *mgr,
236 
237 private:
239 };
240 
241 #endif // __AGENT_PKT_FLOW_MGMT_ENTRY_H__
std::vector< AclEntryID > AclEntryIDList
Definition: acl_entry.h:86
Definition: acl.h:92
void FillAclFlowSandeshInfo(const AclDBEntry *acl, AclFlowResp &data, const int last_count, Agent *agent)
AceIdFlowCntMap aceid_cnt_map_
std::string GetAclFlowSandeshDataKey(const AclDBEntry *acl, const int last_count) const
std::map< std::string, int > AceIdFlowCntMap
std::string GetAceSandeshDataKey(const AclDBEntry *acl, const std::string &ace_id)
bool Add(const AclEntryIDList *ace_id_list, FlowEntry *flow, const AclEntryIDList *old_id_list, FlowMgmtKeyNode *node)
void FillAceFlowSandeshInfo(const AclDBEntry *acl, AclFlowCountResp &data, const std::string &ace_id)
void DecrementAceIdCountMap(const AclEntryIDList *id_list)
DISALLOW_COPY_AND_ASSIGN(AclFlowMgmtEntry)
virtual ~AclFlowMgmtEntry()
bool Delete(const AclEntryIDList *ace_id_list, FlowEntry *flow, FlowMgmtKeyNode *node)
Agent supports multiple route tables - Inet-unicast (IPv4/IPv6), Inet-multicast, bridge,...
Definition: agent_route.h:110
Definition: agent.h:361
virtual bool HealthCheckUpdate(Agent *agent, FlowMgmtManager *mgr, BgpAsAServiceFlowMgmtKey &key, BgpAsAServiceFlowMgmtRequest *req)
DISALLOW_COPY_AND_ASSIGN(BgpAsAServiceFlowMgmtEntry)
virtual bool NonOperEntryDelete(FlowMgmtManager *mgr, const FlowMgmtRequest *req, FlowMgmtKey *key)
DISALLOW_COPY_AND_ASSIGN(BridgeRouteFlowMgmtEntry)
DISALLOW_COPY_AND_ASSIGN(FlowMgmtEntry)
virtual bool OperEntryAdd(FlowMgmtManager *mgr, const FlowMgmtRequest *req, FlowMgmtKey *key)
virtual bool CanDelete() const
boost::intrusive::member_hook< FlowMgmtKeyNode, boost::intrusive::list_member_hook<>, &FlowMgmtKeyNode::hook_ > Node
uint32_t gen_id_
uint32_t Size() const
FlowList flow_list_
uint32_t gen_id() const
virtual bool Add(FlowEntry *flow, FlowMgmtKeyNode *node)
virtual bool NonOperEntryDelete(FlowMgmtManager *mgr, const FlowMgmtRequest *req, FlowMgmtKey *key)
static const int MaxResponses
virtual ~FlowMgmtEntry()
virtual bool OperEntryChange(FlowMgmtManager *mgr, const FlowMgmtRequest *req, FlowMgmtKey *key)
boost::intrusive::list< FlowMgmtKeyNode, Node > FlowList
const FlowList & flow_list() const
void set_oper_state(State state)
virtual bool Delete(FlowEntry *flow, FlowMgmtKeyNode *node)
virtual bool OperEntryDelete(FlowMgmtManager *mgr, const FlowMgmtRequest *req, FlowMgmtKey *key)
State oper_state() const
boost::intrusive::list_member_hook hook_
bool HandleNhChange(FlowMgmtManager *mgr, const FlowMgmtRequest *req, FlowMgmtKey *key)
bool RecomputeCoveringRouteEntry(FlowMgmtManager *mgr, InetRouteFlowMgmtKey *covering_route, InetRouteFlowMgmtKey *key)
DISALLOW_COPY_AND_ASSIGN(InetRouteFlowMgmtEntry)
bool Delete(FlowEntry *flow, FlowMgmtKeyNode *node)
uint64_t flow_created() const
bool Add(FlowEntry *flow, FlowMgmtKeyNode *node)
DISALLOW_COPY_AND_ASSIGN(InterfaceFlowMgmtEntry)
uint64_t flow_aged() const
DISALLOW_COPY_AND_ASSIGN(NhFlowMgmtEntry)
virtual ~NhFlowMgmtEntry()
virtual ~RouteFlowMgmtEntry()
DISALLOW_COPY_AND_ASSIGN(RouteFlowMgmtEntry)
DISALLOW_COPY_AND_ASSIGN(VnFlowMgmtEntry)
void UpdateCounterOnDel(FlowEntry *flow, bool local_flow, bool old_ingress)
virtual ~VnFlowMgmtEntry()
void UpdateCounterOnAdd(FlowEntry *flow, bool add_flow, bool local_flow, bool old_ingress)
uint32_t ingress_flow_count_
uint32_t ingress_flow_count() const
uint32_t egress_flow_count_
uint32_t egress_flow_count() const
Definition: vrf.h:90
virtual ~VrfFlowMgmtEntry()
bool CanDelete() const
VrfFlowMgmtTree * vrf_tree() const
uint32_t vrf_id() const
DISALLOW_COPY_AND_ASSIGN(VrfFlowMgmtEntry)
const VrfEntry * vrf_
VrfFlowMgmtEntry(VrfFlowMgmtTree *vrf_tree, const VrfEntry *vrf)
VrfFlowMgmtTree * vrf_tree_
LifetimeRef< Data > table_ref_
Data(VrfFlowMgmtEntry *vrf_mgmt_entry, const VrfEntry *vrf, AgentRouteTable *table)
VrfFlowMgmtEntry * vrf_mgmt_entry_
const VrfEntry * vrf_