Line data Source code
1 : /*
2 : * Copyright (c) 2018 Juniper Networks, Inc. All rights reserved.
3 : */
4 :
5 : #ifndef __AGENT_PKT_FLOW_MGMT_ENTRY_H__
6 : #define __AGENT_PKT_FLOW_MGMT_ENTRY_H__
7 :
8 : #include <string>
9 : #include <map>
10 : #include <boost/intrusive/list.hpp>
11 : #include <base/util.h>
12 : #include <pkt/flow_mgmt/flow_mgmt_key_node.h>
13 : #include <filter/acl_entry.h>
14 :
15 : class Agent;
16 : class FlowEntry;
17 : class FlowMgmtManager;
18 : class FlowMgmtRequest;
19 : class VrfFlowMgmtTree;
20 :
21 : class FlowMgmtKey;
22 : class InetRouteFlowMgmtKey;
23 : class BgpAsAServiceFlowMgmtKey;
24 : class BgpAsAServiceFlowMgmtRequest;
25 :
26 : class AclDBEntry;
27 : class AclFlowResp;
28 : class AclFlowCountResp;
29 :
30 : class FlowMgmtEntry {
31 : public:
32 : // Flow management state of the entry
33 : enum State {
34 : INVALID,
35 : OPER_NOT_SEEN,
36 : OPER_ADD_SEEN,
37 : OPER_DEL_SEEN,
38 : };
39 :
40 : typedef boost::intrusive::member_hook<FlowMgmtKeyNode,
41 : boost::intrusive::list_member_hook<>,
42 : &FlowMgmtKeyNode::hook_> Node;
43 : typedef boost::intrusive::list<FlowMgmtKeyNode, Node> FlowList;
44 :
45 : static const int MaxResponses = 100;
46 :
47 346 : FlowMgmtEntry() : oper_state_(OPER_NOT_SEEN) {
48 346 : }
49 346 : virtual ~FlowMgmtEntry() {
50 346 : assert(flow_list_.size() == 0);
51 346 : }
52 :
53 0 : uint32_t Size() const { return flow_list_.size(); }
54 : // Make flow dependent on the DBEntry
55 : virtual bool Add(FlowEntry *flow, FlowMgmtKeyNode *node);
56 : // Remove flow from dependency tree
57 : virtual bool Delete(FlowEntry *flow, FlowMgmtKeyNode *node);
58 :
59 : // Handle Add/Change event for DBEntry
60 : virtual bool OperEntryAdd(FlowMgmtManager *mgr, const FlowMgmtRequest *req,
61 : FlowMgmtKey *key);
62 : virtual bool OperEntryChange(FlowMgmtManager *mgr,
63 : const FlowMgmtRequest *req, FlowMgmtKey *key);
64 : // Handle Delete event for DBEntry
65 : virtual bool OperEntryDelete(FlowMgmtManager *mgr,
66 : const FlowMgmtRequest *req, FlowMgmtKey *key);
67 : // Handle Delete event for Non-DBEntry
68 0 : virtual bool NonOperEntryDelete(FlowMgmtManager *mgr,
69 : const FlowMgmtRequest *req,
70 0 : FlowMgmtKey *key) { return true; }
71 : // Can the entry be deleted?
72 : virtual bool CanDelete() const;
73 :
74 : void set_oper_state(State state) { oper_state_ = state; }
75 346 : State oper_state() const { return oper_state_; }
76 344 : uint32_t gen_id() const { return gen_id_; }
77 0 : const FlowList &flow_list() const { return flow_list_; }
78 :
79 : protected:
80 : // Add seen from OperDB entry
81 : State oper_state_;
82 : uint32_t gen_id_;
83 : FlowList flow_list_;
84 :
85 : private:
86 : DISALLOW_COPY_AND_ASSIGN(FlowMgmtEntry);
87 : };
88 :
89 : class AclFlowMgmtEntry : public FlowMgmtEntry {
90 : public:
91 : typedef std::map<std::string, int> AceIdFlowCntMap;
92 4 : AclFlowMgmtEntry() : FlowMgmtEntry() { }
93 8 : virtual ~AclFlowMgmtEntry() { }
94 : void FillAclFlowSandeshInfo(const AclDBEntry *acl, AclFlowResp &data,
95 : const int last_count, Agent *agent);
96 : void FillAceFlowSandeshInfo(const AclDBEntry *acl, AclFlowCountResp &data,
97 : const std::string &ace_id);
98 : bool Add(const AclEntryIDList *ace_id_list, FlowEntry *flow,
99 : const AclEntryIDList *old_id_list, FlowMgmtKeyNode *node);
100 : bool Delete(const AclEntryIDList *ace_id_list, FlowEntry *flow,
101 : FlowMgmtKeyNode *node);
102 : void DecrementAceIdCountMap(const AclEntryIDList *id_list);
103 :
104 : private:
105 : std::string GetAceSandeshDataKey(const AclDBEntry *acl,
106 : const std::string &ace_id);
107 : std::string GetAclFlowSandeshDataKey(const AclDBEntry *acl,
108 : const int last_count) const;
109 : uint32_t flow_miss_;
110 : AceIdFlowCntMap aceid_cnt_map_;
111 : DISALLOW_COPY_AND_ASSIGN(AclFlowMgmtEntry);
112 : };
113 :
114 : class VnFlowMgmtEntry : public FlowMgmtEntry {
115 : public:
116 6 : VnFlowMgmtEntry() :
117 6 : FlowMgmtEntry(), ingress_flow_count_(0), egress_flow_count_(0) {
118 6 : }
119 12 : virtual ~VnFlowMgmtEntry() { }
120 :
121 : void UpdateCounterOnAdd(FlowEntry *flow, bool add_flow, bool local_flow,
122 : bool old_ingress);
123 : void UpdateCounterOnDel(FlowEntry *flow, bool local_flow, bool old_ingress);
124 0 : uint32_t ingress_flow_count() const { return ingress_flow_count_; }
125 0 : uint32_t egress_flow_count() const { return egress_flow_count_; }
126 :
127 : private:
128 : uint32_t ingress_flow_count_;
129 : uint32_t egress_flow_count_;
130 : DISALLOW_COPY_AND_ASSIGN(VnFlowMgmtEntry);
131 : };
132 :
133 : class InterfaceFlowMgmtEntry : public FlowMgmtEntry {
134 : public:
135 62 : InterfaceFlowMgmtEntry() : FlowMgmtEntry(), flow_created_(0),
136 31 : flow_aged_(0) { }
137 62 : virtual ~InterfaceFlowMgmtEntry() { }
138 :
139 : bool Add(FlowEntry *flow, FlowMgmtKeyNode *node);
140 : bool Delete(FlowEntry *flow, FlowMgmtKeyNode *node);
141 0 : uint64_t flow_created() const { return flow_created_; }
142 0 : uint64_t flow_aged() const { return flow_aged_; }
143 :
144 : private:
145 : uint64_t flow_created_;
146 : uint64_t flow_aged_;
147 : DISALLOW_COPY_AND_ASSIGN(InterfaceFlowMgmtEntry);
148 : };
149 :
150 : class NhFlowMgmtEntry : public FlowMgmtEntry {
151 : public:
152 160 : NhFlowMgmtEntry() : FlowMgmtEntry() { }
153 320 : virtual ~NhFlowMgmtEntry() { }
154 :
155 : private:
156 : DISALLOW_COPY_AND_ASSIGN(NhFlowMgmtEntry);
157 : };
158 :
159 : class RouteFlowMgmtEntry : public FlowMgmtEntry {
160 : public:
161 133 : RouteFlowMgmtEntry() : FlowMgmtEntry() { }
162 133 : virtual ~RouteFlowMgmtEntry() { }
163 :
164 : private:
165 : DISALLOW_COPY_AND_ASSIGN(RouteFlowMgmtEntry);
166 : };
167 :
168 : class InetRouteFlowMgmtEntry : public RouteFlowMgmtEntry {
169 : public:
170 81 : InetRouteFlowMgmtEntry() : RouteFlowMgmtEntry() { }
171 162 : virtual ~InetRouteFlowMgmtEntry() { }
172 : // Handle covering routeEntry
173 : bool RecomputeCoveringRouteEntry(FlowMgmtManager *mgr,
174 : InetRouteFlowMgmtKey *covering_route,
175 : InetRouteFlowMgmtKey *key);
176 : bool HandleNhChange(FlowMgmtManager *mgr, const FlowMgmtRequest *req,
177 : FlowMgmtKey *key);
178 :
179 : private:
180 : DISALLOW_COPY_AND_ASSIGN(InetRouteFlowMgmtEntry);
181 : };
182 :
183 : class BridgeRouteFlowMgmtEntry : public RouteFlowMgmtEntry {
184 : public:
185 52 : BridgeRouteFlowMgmtEntry() : RouteFlowMgmtEntry() { }
186 104 : virtual ~BridgeRouteFlowMgmtEntry() { }
187 :
188 : private:
189 : DISALLOW_COPY_AND_ASSIGN(BridgeRouteFlowMgmtEntry);
190 : };
191 :
192 : class VrfFlowMgmtEntry : public FlowMgmtEntry {
193 : public:
194 : struct Data {
195 : Data(VrfFlowMgmtEntry *vrf_mgmt_entry, const VrfEntry *vrf,
196 : AgentRouteTable *table);
197 : virtual ~Data();
198 : void ManagedDelete();
199 66 : bool deleted() const { return deleted_; }
200 :
201 : bool deleted_;
202 : LifetimeRef<Data> table_ref_;
203 : VrfFlowMgmtEntry *vrf_mgmt_entry_;
204 : const VrfEntry *vrf_;
205 : };
206 :
207 : VrfFlowMgmtEntry(VrfFlowMgmtTree *vrf_tree, const VrfEntry *vrf);
208 24 : virtual ~VrfFlowMgmtEntry() { }
209 : bool CanDelete() const;
210 36 : VrfFlowMgmtTree *vrf_tree() const { return vrf_tree_; }
211 : uint32_t vrf_id() const { return vrf_id_; }
212 :
213 : private:
214 : friend class VrfFlowMgmtTree;
215 : const VrfEntry *vrf_;
216 : uint32_t vrf_id_;
217 : Data inet4_;
218 : Data inet6_;
219 : Data bridge_;
220 : // Back reference for the tree
221 : VrfFlowMgmtTree *vrf_tree_;
222 : DISALLOW_COPY_AND_ASSIGN(VrfFlowMgmtEntry);
223 : };
224 :
225 : class BgpAsAServiceFlowMgmtEntry : public FlowMgmtEntry {
226 : public:
227 0 : BgpAsAServiceFlowMgmtEntry() : FlowMgmtEntry() { }
228 0 : virtual ~BgpAsAServiceFlowMgmtEntry() { }
229 : virtual bool NonOperEntryDelete(FlowMgmtManager *mgr,
230 : const FlowMgmtRequest *req,
231 : FlowMgmtKey *key);
232 : virtual bool HealthCheckUpdate(Agent *agent, FlowMgmtManager *mgr,
233 : BgpAsAServiceFlowMgmtKey &key,
234 : BgpAsAServiceFlowMgmtRequest *req);
235 :
236 : private:
237 : DISALLOW_COPY_AND_ASSIGN(BgpAsAServiceFlowMgmtEntry);
238 : };
239 :
240 : #endif // __AGENT_PKT_FLOW_MGMT_ENTRY_H__
|