Line data Source code
1 : /*
2 : * Copyright (c) 2015 Juniper Networks, Inc. All rights reserved.
3 : * Copyright Contributors to the OpenSDN project
4 : */
5 : #ifndef __AGENT_FLOW_MGMT_REQUEST_H__
6 : #define __AGENT_FLOW_MGMT_REQUEST_H__
7 :
8 : #include "pkt/flow_table.h"
9 : #include "pkt/flow_event.h"
10 :
11 : ////////////////////////////////////////////////////////////////////////////
12 : // Request to the Flow Management module
13 : ////////////////////////////////////////////////////////////////////////////
14 : class FlowMgmtRequest {
15 : public:
16 : enum Event {
17 : INVALID,
18 : ADD_FLOW,
19 : DELETE_FLOW,
20 : UPDATE_FLOW,
21 : ADD_DBENTRY,
22 : CHANGE_DBENTRY,
23 : DELETE_DBENTRY,
24 : RETRY_DELETE_VRF,
25 : DELETE_BGP_AAS_FLOWS,
26 : UPDATE_FLOW_STATS,
27 : IMPLICIT_ROUTE_DELETE,
28 : DELETE_LAYER2_FLOW,
29 : DUMMY
30 :
31 : };
32 :
33 604 : FlowMgmtRequest(Event event, FlowEntry *flow) :
34 1208 : event_(event), flow_(flow), db_entry_(NULL), vrf_id_(0), gen_id_(),
35 604 : bytes_(), packets_(), oflow_bytes_(), params_() {
36 604 : if (event == RETRY_DELETE_VRF)
37 0 : assert(vrf_id_);
38 604 : }
39 :
40 144 : FlowMgmtRequest(Event event, FlowEntry *flow,
41 144 : const RevFlowDepParams ¶ms) :
42 288 : event_(event), flow_(flow), db_entry_(NULL), vrf_id_(0), gen_id_(),
43 144 : bytes_(), packets_(), oflow_bytes_(), params_(params) {
44 144 : }
45 :
46 0 : FlowMgmtRequest(Event event, FlowEntry *flow, uint32_t bytes,
47 : uint32_t packets, uint32_t oflow_bytes,
48 0 : const boost::uuids::uuid &u) :
49 0 : event_(event), flow_(flow), db_entry_(NULL), vrf_id_(0), gen_id_(),
50 0 : bytes_(bytes), packets_(packets), oflow_bytes_(oflow_bytes), params_(),
51 0 : flow_uuid_(u) {
52 0 : if (event == RETRY_DELETE_VRF)
53 0 : assert(vrf_id_);
54 0 : }
55 :
56 8787 : FlowMgmtRequest(Event event, const DBEntry *db_entry, uint32_t gen_id) :
57 17574 : event_(event), flow_(NULL), db_entry_(db_entry), vrf_id_(0),
58 8787 : gen_id_(gen_id), bytes_(), packets_(), oflow_bytes_(), params_() {
59 8787 : if (event == RETRY_DELETE_VRF) {
60 222 : const VrfEntry *vrf = dynamic_cast<const VrfEntry *>(db_entry);
61 222 : assert(vrf);
62 222 : vrf_id_ = vrf->vrf_id();
63 : }
64 8787 : }
65 :
66 0 : FlowMgmtRequest(Event event) :
67 0 : event_(event), flow_(NULL), db_entry_(NULL), vrf_id_(),
68 0 : gen_id_(), bytes_(), packets_(), oflow_bytes_(), params_() {
69 0 : }
70 :
71 19049 : virtual ~FlowMgmtRequest() { }
72 :
73 : // At the end of Flow Management Request, we may enqueue a response message
74 : // back to FlowTable module. Compute the message type to be enqueued in
75 : // response. Returns INVALID if no message to be enqueued
76 8540 : FlowEvent::Event GetResponseEvent() const {
77 8540 : FlowEvent::Event resp_event = FlowEvent::INVALID;
78 8540 : if (event_ == DELETE_BGP_AAS_FLOWS)
79 0 : return FlowEvent::DELETE_FLOW;
80 :
81 8540 : if (event_ == IMPLICIT_ROUTE_DELETE) {
82 0 : resp_event = FlowEvent::RECOMPUTE_FLOW;
83 : }
84 :
85 8540 : if (db_entry_ == NULL)
86 0 : return resp_event;
87 :
88 8540 : if (dynamic_cast<const VrfEntry *>(db_entry_)) {
89 218 : return resp_event;
90 : }
91 :
92 8322 : if (event_ == ADD_DBENTRY || event_ == CHANGE_DBENTRY) {
93 4902 : resp_event = FlowEvent::REVALUATE_DBENTRY;
94 3420 : } else if (event_ == DELETE_DBENTRY) {
95 3420 : resp_event = FlowEvent::DELETE_DBENTRY;
96 : }
97 :
98 : // Add/Change in route needs complete recomputation of flows
99 : // 1. Bridge route change can be result of MAC-Move. This will need
100 : // recomputing rpf-nh also.
101 : // 2. Add/Delete of inet-uc route can result in change of route used
102 : // used for flow
103 8322 : const AgentRoute *rt =
104 8322 : dynamic_cast<const AgentRoute *>(db_entry_);
105 8322 : if (rt) {
106 4188 : resp_event = FlowEvent::RECOMPUTE_FLOW;
107 : }
108 :
109 8322 : return resp_event;
110 : }
111 :
112 21647 : Event event() const { return event_; }
113 1725 : FlowEntryPtr &flow() { return flow_; }
114 : void set_flow(FlowEntry *flow) { flow_.reset(flow); }
115 23159 : const DBEntry *db_entry() const { return db_entry_; }
116 : void set_db_entry(const DBEntry *db_entry) { db_entry_ = db_entry; }
117 222 : uint32_t vrf_id() const { return vrf_id_; }
118 3564 : uint32_t gen_id() const { return gen_id_; }
119 0 : uint32_t bytes() const { return bytes_;}
120 0 : uint32_t packets() const { return packets_;}
121 0 : uint32_t oflow_bytes() const { return oflow_bytes_;}
122 432 : const RevFlowDepParams& params() const { return params_; }
123 224 : void set_params(const RevFlowDepParams ¶ms) {
124 224 : params_ = params;
125 224 : }
126 0 : boost::uuids::uuid flow_uuid() const { return flow_uuid_; }
127 :
128 : private:
129 : Event event_;
130 : // FlowEntry pointer to hold flow reference till message is processed
131 : FlowEntryPtr flow_;
132 : // DBEntry pointer. The DBState from FlowTable module ensures DBEntry is
133 : // not deleted while message holds pointer
134 : const DBEntry *db_entry_;
135 : uint32_t vrf_id_;
136 : uint32_t gen_id_;
137 : uint32_t bytes_;
138 : uint32_t packets_;
139 : uint32_t oflow_bytes_;
140 : RevFlowDepParams params_;
141 : boost::uuids::uuid flow_uuid_;
142 :
143 : DISALLOW_COPY_AND_ASSIGN(FlowMgmtRequest);
144 : };
145 :
146 : class BgpAsAServiceFlowMgmtRequest : public FlowMgmtRequest {
147 : public:
148 : enum Type {
149 : VMI,
150 : CONTROLLER,
151 : HEALTH_CHECK_ADD,
152 : HEALTH_CHECK_DEL
153 : };
154 :
155 21 : BgpAsAServiceFlowMgmtRequest(uint8_t index) :
156 : FlowMgmtRequest(FlowMgmtRequest::DELETE_BGP_AAS_FLOWS, NULL, 0),
157 21 : type_(BgpAsAServiceFlowMgmtRequest::CONTROLLER), vm_uuid_(),
158 21 : source_port_(), index_(index), health_check_uuid_() { }
159 0 : BgpAsAServiceFlowMgmtRequest(const boost::uuids::uuid &vm_uuid,
160 0 : uint32_t source_port) :
161 : FlowMgmtRequest(FlowMgmtRequest::DELETE_BGP_AAS_FLOWS, NULL, 0),
162 0 : type_(BgpAsAServiceFlowMgmtRequest::VMI), vm_uuid_(vm_uuid),
163 0 : source_port_(source_port), index_(), health_check_uuid_() { }
164 0 : BgpAsAServiceFlowMgmtRequest(const boost::uuids::uuid &vm_uuid,
165 : uint32_t source_port,
166 : const boost::uuids::uuid &hc_uuid,
167 0 : Type type) :
168 : FlowMgmtRequest(FlowMgmtRequest::DELETE_BGP_AAS_FLOWS, NULL, 0),
169 0 : type_(type), vm_uuid_(vm_uuid), source_port_(source_port), index_(),
170 0 : health_check_uuid_(hc_uuid) { }
171 42 : virtual ~BgpAsAServiceFlowMgmtRequest() { }
172 42 : BgpAsAServiceFlowMgmtRequest::Type type() const { return type_; }
173 0 : const boost::uuids::uuid &vm_uuid() const { return vm_uuid_; }
174 0 : uint32_t source_port() const { return source_port_; }
175 21 : uint8_t index() const { return index_; }
176 0 : const boost::uuids::uuid &health_check_uuid() const {
177 0 : return health_check_uuid_;
178 : }
179 :
180 : private:
181 : BgpAsAServiceFlowMgmtRequest::Type type_;
182 : boost::uuids::uuid vm_uuid_;
183 : uint32_t source_port_;
184 : uint8_t index_;
185 : boost::uuids::uuid health_check_uuid_;
186 : DISALLOW_COPY_AND_ASSIGN(BgpAsAServiceFlowMgmtRequest);
187 : };
188 : #endif // __AGENT_FLOW_MGMT_REQUEST_H__
|