Line data Source code
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>
13 : #include <pkt/flow_mgmt/flow_mgmt_key_node.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;
23 : class InetRouteFlowMgmtKey;
24 : class BgpAsAServiceFlowMgmtKey;
25 : class BgpAsAServiceFlowMgmtRequest;
26 :
27 : class AclDBEntry;
28 : class AclFlowResp;
29 : class AclFlowCountResp;
30 :
31 : class FlowMgmtEntry {
32 : public:
33 : // Flow management state of the entry
34 : enum State {
35 : INVALID,
36 : OPER_NOT_SEEN,
37 : OPER_ADD_SEEN,
38 : OPER_DEL_SEEN,
39 : };
40 :
41 : typedef boost::intrusive::member_hook<FlowMgmtKeyNode,
42 : boost::intrusive::list_member_hook<>,
43 : &FlowMgmtKeyNode::hook_> Node;
44 : typedef boost::intrusive::list<FlowMgmtKeyNode, Node> FlowList;
45 :
46 : static const int MaxResponses = 100;
47 :
48 3515 : FlowMgmtEntry() : oper_state_(OPER_NOT_SEEN) {
49 3515 : }
50 3515 : virtual ~FlowMgmtEntry() {
51 3515 : assert(flow_list_.size() == 0);
52 3515 : }
53 :
54 0 : 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
69 0 : virtual bool NonOperEntryDelete(FlowMgmtManager *mgr,
70 : const FlowMgmtRequest *req,
71 0 : 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 3516 : State oper_state() const { return oper_state_; }
77 3494 : uint32_t gen_id() const { return gen_id_; }
78 0 : const FlowList &flow_list() const { return flow_list_; }
79 :
80 : protected:
81 : // Add seen from OperDB entry
82 : State oper_state_;
83 : uint32_t gen_id_;
84 : FlowList flow_list_;
85 :
86 : private:
87 : DISALLOW_COPY_AND_ASSIGN(FlowMgmtEntry);
88 : };
89 :
90 : class AclFlowMgmtEntry : public FlowMgmtEntry {
91 : public:
92 : typedef std::map<std::string, int> AceIdFlowCntMap;
93 5 : AclFlowMgmtEntry() : FlowMgmtEntry() { }
94 10 : 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_;
111 : AceIdFlowCntMap aceid_cnt_map_;
112 : DISALLOW_COPY_AND_ASSIGN(AclFlowMgmtEntry);
113 : };
114 :
115 : class VnFlowMgmtEntry : public FlowMgmtEntry {
116 : public:
117 69 : VnFlowMgmtEntry() :
118 69 : FlowMgmtEntry(), ingress_flow_count_(0), egress_flow_count_(0) {
119 69 : }
120 138 : 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 0 : uint32_t ingress_flow_count() const { return ingress_flow_count_; }
126 0 : uint32_t egress_flow_count() const { return egress_flow_count_; }
127 :
128 : private:
129 : uint32_t ingress_flow_count_;
130 : uint32_t egress_flow_count_;
131 : DISALLOW_COPY_AND_ASSIGN(VnFlowMgmtEntry);
132 : };
133 :
134 : class InterfaceFlowMgmtEntry : public FlowMgmtEntry {
135 : public:
136 674 : InterfaceFlowMgmtEntry() : FlowMgmtEntry(), flow_created_(0),
137 337 : flow_aged_(0) { }
138 674 : virtual ~InterfaceFlowMgmtEntry() { }
139 :
140 : bool Add(FlowEntry *flow, FlowMgmtKeyNode *node);
141 : bool Delete(FlowEntry *flow, FlowMgmtKeyNode *node);
142 0 : uint64_t flow_created() const { return flow_created_; }
143 0 : uint64_t flow_aged() const { return flow_aged_; }
144 :
145 : private:
146 : uint64_t flow_created_;
147 : uint64_t flow_aged_;
148 : DISALLOW_COPY_AND_ASSIGN(InterfaceFlowMgmtEntry);
149 : };
150 :
151 : class NhFlowMgmtEntry : public FlowMgmtEntry {
152 : public:
153 1650 : NhFlowMgmtEntry() : FlowMgmtEntry() { }
154 3300 : virtual ~NhFlowMgmtEntry() { }
155 :
156 : private:
157 : DISALLOW_COPY_AND_ASSIGN(NhFlowMgmtEntry);
158 : };
159 :
160 : class RouteFlowMgmtEntry : public FlowMgmtEntry {
161 : public:
162 1380 : RouteFlowMgmtEntry() : FlowMgmtEntry() { }
163 1380 : virtual ~RouteFlowMgmtEntry() { }
164 :
165 : private:
166 : DISALLOW_COPY_AND_ASSIGN(RouteFlowMgmtEntry);
167 : };
168 :
169 : class InetRouteFlowMgmtEntry : public RouteFlowMgmtEntry {
170 : public:
171 956 : InetRouteFlowMgmtEntry() : RouteFlowMgmtEntry() { }
172 1912 : virtual ~InetRouteFlowMgmtEntry() { }
173 : // Handle covering routeEntry
174 : bool RecomputeCoveringRouteEntry(FlowMgmtManager *mgr,
175 : InetRouteFlowMgmtKey *covering_route,
176 : InetRouteFlowMgmtKey *key);
177 : bool HandleNhChange(FlowMgmtManager *mgr, const FlowMgmtRequest *req,
178 : FlowMgmtKey *key);
179 :
180 : private:
181 : DISALLOW_COPY_AND_ASSIGN(InetRouteFlowMgmtEntry);
182 : };
183 :
184 : class BridgeRouteFlowMgmtEntry : public RouteFlowMgmtEntry {
185 : public:
186 424 : BridgeRouteFlowMgmtEntry() : RouteFlowMgmtEntry() { }
187 848 : virtual ~BridgeRouteFlowMgmtEntry() { }
188 :
189 : private:
190 : DISALLOW_COPY_AND_ASSIGN(BridgeRouteFlowMgmtEntry);
191 : };
192 :
193 : class VrfFlowMgmtEntry : public FlowMgmtEntry {
194 : public:
195 : struct Data {
196 : Data(VrfFlowMgmtEntry *vrf_mgmt_entry, const VrfEntry *vrf,
197 : AgentRouteTable *table);
198 : virtual ~Data();
199 : void ManagedDelete();
200 308 : bool deleted() const { return deleted_; }
201 :
202 : bool deleted_;
203 : LifetimeRef<Data> table_ref_;
204 : VrfFlowMgmtEntry *vrf_mgmt_entry_;
205 : const VrfEntry *vrf_;
206 : };
207 :
208 : VrfFlowMgmtEntry(VrfFlowMgmtTree *vrf_tree, const VrfEntry *vrf);
209 148 : virtual ~VrfFlowMgmtEntry() { }
210 : bool CanDelete() const;
211 222 : 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_;
218 : Data inet4_;
219 : Data inet6_;
220 : Data bridge_;
221 : // Back reference for the tree
222 : VrfFlowMgmtTree *vrf_tree_;
223 : DISALLOW_COPY_AND_ASSIGN(VrfFlowMgmtEntry);
224 : };
225 :
226 : class BgpAsAServiceFlowMgmtEntry : public FlowMgmtEntry {
227 : public:
228 0 : BgpAsAServiceFlowMgmtEntry() : FlowMgmtEntry() { }
229 0 : virtual ~BgpAsAServiceFlowMgmtEntry() { }
230 : virtual bool NonOperEntryDelete(FlowMgmtManager *mgr,
231 : const FlowMgmtRequest *req,
232 : FlowMgmtKey *key);
233 : virtual bool HealthCheckUpdate(Agent *agent, FlowMgmtManager *mgr,
234 : BgpAsAServiceFlowMgmtKey &key,
235 : BgpAsAServiceFlowMgmtRequest *req);
236 :
237 : private:
238 : DISALLOW_COPY_AND_ASSIGN(BgpAsAServiceFlowMgmtEntry);
239 : };
240 :
241 : #endif // __AGENT_PKT_FLOW_MGMT_ENTRY_H__
|