OpenSDN source code
flow_proto.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #ifndef vnsw_agent_flow_proto_hpp
6 #define vnsw_agent_flow_proto_hpp
7 
8 #include <atomic>
9 
10 #include <net/if.h>
11 #include "cmn/agent_cmn.h"
12 #include "base/queue_task.h"
13 #include "proto.h"
14 #include "proto_handler.h"
15 #include "flow_table.h"
16 #include "flow_handler.h"
17 #include "flow_event.h"
18 #include "flow_token.h"
19 #include "flow_trace_filter.h"
20 #include "flow_entry.h"
21 
22 class ProfileData;
23 
24 struct FlowStats {
25  uint64_t add_count_;
26  uint64_t delete_count_;
27  uint64_t flow_messages_;
28  uint64_t revaluate_count_;
29  uint64_t recompute_count_;
30  uint64_t audit_count_;
32  uint64_t vrouter_error_;
33  uint64_t evict_count_;
34 
35  // Number of events actually processed
36  uint64_t delete_process_;
39 
45  }
46 };
47 
48 class FlowProto : public Proto {
49 public:
50  static const int kMinTableCount = 1;
51  static const int kMaxTableCount = 16;
52 
53  FlowProto(Agent *agent, boost::asio::io_context &io);
54  virtual ~FlowProto();
55 
56  void Init();
57  void InitDone();
58  void Shutdown();
59  void FlushFlows();
60 
61  bool Validate(PktInfo *msg);
63  boost::asio::io_context &io);
64  bool Enqueue(PktInfoPtr msg);
65 
66  FlowEntry *Find(const FlowKey &key, uint32_t table_index) const;
67  uint16_t FlowTableIndex(const IpAddress &sip, const IpAddress &dip,
68  uint8_t proto, uint16_t sport,
69  uint16_t dport, uint32_t flow_handle) const;
70  uint32_t flow_table_count() const { return flow_table_list_.size(); }
71  FlowTable *GetTable(uint16_t index) const;
72  FlowTable *GetFlowTable(const FlowKey &key, uint32_t flow_handle) const;
73  uint32_t FlowCount() const;
74  void VnFlowCounters(const VnEntry *vn, uint32_t *in_count,
75  uint32_t *out_count);
76  void InterfaceFlowCount(const Interface *intf, uint64_t *created,
77  uint64_t *aged, uint32_t *active_flows) const;
78 
79  bool AddFlow(FlowEntry *flow);
80  bool UpdateFlow(FlowEntry *flow);
81 
82  void EnqueueFlowEvent(FlowEvent *event);
84  void DeleteFlowRequest(FlowEntry *flow);
85  void DeleteFlowRequest(const FlowKey &key);
86  void EvictFlowRequest(FlowEntry *flow, uint32_t flow_handle,
87  uint8_t gen_id, uint8_t evict_gen_id);
88  void CreateAuditEntry(const FlowKey &key, uint32_t flow_handle,
89  uint8_t gen_id);
90  bool FlowEventHandler(FlowEvent *req, FlowTable *table);
91  bool FlowUpdateHandler(FlowEvent *req);
92  bool FlowDeleteHandler(FlowEvent *req, FlowTable *table);
93  bool FlowKSyncMsgHandler(FlowEvent *req, FlowTable *table);
94  void GrowFreeListRequest(FlowTable *table);
95  void KSyncEventRequest(KSyncEntry *ksync_entry,
96  KSyncEntry::KSyncEvent event, uint32_t flow_handle,
97  uint8_t gen_id, int ksync_error,
98  uint64_t evict_flow_bytes,
99  uint64_t evict_flow_packets,
100  int32_t evict_flow_oflow,
101  uint32_t transcation_id);
102  void MessageRequest(FlowEntry *flow);
103 
104  void DisableFlowEventQueue(uint32_t index, bool disabled);
105  void DisableFlowUpdateQueue(bool disabled);
106  void DisableFlowKSyncQueue(uint32_t index, bool disabled);
107  void DisableFlowDeleteQueue(uint32_t index, bool disabled);
108  size_t FlowUpdateQueueLength();
109 
110  const FlowStats *flow_stats() const { return &stats_; }
111 
112  void SetProfileData(ProfileData *data);
113  uint32_t linklocal_flow_count() const { return linklocal_flow_count_; }
115  int tmp = linklocal_flow_count_.fetch_add(val);
116  if (val < 0)
117  assert(tmp >= val);
118  }
119  bool EnqueueReentrant(boost::shared_ptr<PktInfo> msg,
120  uint8_t table_index);
121  bool ShouldTrace(const FlowEntry *flow, const FlowEntry *rflow);
123 
124  virtual void TokenAvailable(TokenPool *pool_base);
126  bool TokenCheck(const FlowTokenPool *pool) const;
127 
129  return &port_table_manager_;
130  }
131 
132 private:
136  friend class FlowTraceFilterTest;
137  friend class FlowUpdateTest;
138  friend class FlowTest;
141 
142  bool ProcessFlowEvent(const FlowEvent &req, FlowTable *table);
143  bool FlowStatsUpdate() const;
144 
149  std::vector<FlowEventQueue *> flow_event_queue_;
150  std::vector<FlowEventQueue *> flow_tokenless_queue_;
151  std::vector<DeleteFlowEventQueue *> flow_delete_queue_;
152  std::vector<KSyncFlowEventQueue *> flow_ksync_queue_;
153  std::vector<FlowTable *> flow_table_list_;
155  std::atomic<int> linklocal_flow_count_;
162 };
163 
165 
166 #define PKTFLOW_TRACE(obj, ...)\
167 do {\
168  PktFlow##obj::TraceMsg(PktFlowTraceBuf, __FILE__, __LINE__, ##__VA_ARGS__);\
169 } while (false)
170 
171 #endif // vnsw_agent_flow_proto_hpp
boost::asio::ip::address IpAddress
Definition: address.h:13
Definition: agent.h:360
TokenPtr GetToken(FlowEvent::Event event)
Definition: flow_proto.cc:714
void EvictFlowRequest(FlowEntry *flow, uint32_t flow_handle, uint8_t gen_id, uint8_t evict_gen_id)
Definition: flow_proto.cc:611
FlowTokenPool del_tokens_
Definition: flow_proto.h:147
FlowStats stats_
Definition: flow_proto.h:159
bool FlowStatsUpdate() const
Definition: flow_proto.cc:917
std::vector< DeleteFlowEventQueue * > flow_delete_queue_
Definition: flow_proto.h:151
void DeleteFlowRequest(FlowEntry *flow)
Definition: flow_proto.cc:598
bool FlowDeleteHandler(FlowEvent *req, FlowTable *table)
Definition: flow_proto.cc:571
void GrowFreeListRequest(FlowTable *table)
Definition: flow_proto.cc:627
void CreateAuditEntry(const FlowKey &key, uint32_t flow_handle, uint8_t gen_id)
Definition: flow_proto.cc:619
void ForceEnqueueFreeFlowReference(FlowEntryPtr &flow)
Definition: flow_proto.cc:662
bool FlowUpdateHandler(FlowEvent *req)
Definition: flow_proto.cc:545
void DisableFlowDeleteQueue(uint32_t index, bool disabled)
Definition: flow_proto.cc:248
FlowTable * GetTable(uint16_t index) const
Definition: flow_proto.cc:261
Timer * stats_update_timer_
Definition: flow_proto.h:161
void DisableFlowUpdateQueue(bool disabled)
Definition: flow_proto.cc:236
FlowTraceFilter ipv4_trace_filter_
Definition: flow_proto.h:157
std::vector< FlowTable * > flow_table_list_
Definition: flow_proto.h:153
uint32_t flow_table_count() const
Definition: flow_proto.h:70
void InterfaceFlowCount(const Interface *intf, uint64_t *created, uint64_t *aged, uint32_t *active_flows) const
Definition: flow_proto.cc:925
void FlushFlows()
Definition: flow_proto.cc:255
uint32_t FlowCount() const
Definition: flow_proto.cc:265
void VnFlowCounters(const VnEntry *vn, uint32_t *in_count, uint32_t *out_count)
Definition: flow_proto.cc:273
void InitDone()
Definition: flow_proto.cc:99
FlowHandler * AllocProtoHandler(PktInfoPtr info, boost::asio::io_context &io)
Definition: flow_proto.cc:188
bool ProcessFlowEvent(const FlowEvent &req, FlowTable *table)
bool use_vrouter_hash_
Definition: flow_proto.h:156
void update_linklocal_flow_count(int val)
Definition: flow_proto.h:114
FlowTraceFilter * ipv6_trace_filter()
Definition: flow_proto.h:140
virtual void TokenAvailable(TokenPool *pool_base)
Definition: flow_proto.cc:753
friend class SandeshIPv6FlowFilterRequest
Definition: flow_proto.h:134
PortTableManager port_table_manager_
Definition: flow_proto.h:160
const FlowStats * flow_stats() const
Definition: flow_proto.h:110
friend class FlowUpdateTest
Definition: flow_proto.h:137
void EnqueueUnResolvedFlowEntry(FlowEntry *flow)
Definition: flow_proto.cc:676
std::atomic< int > linklocal_flow_count_
Definition: flow_proto.h:155
bool ShouldTrace(const FlowEntry *flow, const FlowEntry *rflow)
Definition: flow_proto.cc:683
FlowTable * GetFlowTable(const FlowKey &key, uint32_t flow_handle) const
Definition: flow_proto.cc:213
FlowProto(Agent *agent, boost::asio::io_context &io)
Definition: flow_proto.cc:22
void EnqueueFlowEvent(FlowEvent *event)
Definition: flow_proto.cc:307
static const int kMaxTableCount
Definition: flow_proto.h:51
void Shutdown()
Definition: flow_proto.cc:107
void DisableFlowKSyncQueue(uint32_t index, bool disabled)
Definition: flow_proto.cc:240
FlowTokenPool add_tokens_
Definition: flow_proto.h:145
std::vector< FlowEventQueue * > flow_tokenless_queue_
Definition: flow_proto.h:150
FlowTokenPool update_tokens_
Definition: flow_proto.h:148
FlowTraceFilter ipv6_trace_filter_
Definition: flow_proto.h:158
static const int kMinTableCount
Definition: flow_proto.h:50
friend class FlowTraceFilterTest
Definition: flow_proto.h:136
FlowTokenPool ksync_tokens_
Definition: flow_proto.h:146
void MessageRequest(FlowEntry *flow)
Definition: flow_proto.cc:646
FlowTraceFilter * ipv4_trace_filter()
Definition: flow_proto.h:139
bool FlowEventHandler(FlowEvent *req, FlowTable *table)
Definition: flow_proto.cc:401
FlowEntry * Find(const FlowKey &key, uint32_t table_index) const
Definition: flow_proto.cc:288
virtual ~FlowProto()
Definition: flow_proto.cc:76
bool TokenCheck(const FlowTokenPool *pool) const
Definition: flow_proto.cc:749
friend class SandeshShowFlowFilterRequest
Definition: flow_proto.h:135
uint32_t linklocal_flow_count() const
Definition: flow_proto.h:113
void KSyncEventRequest(KSyncEntry *ksync_entry, KSyncEntry::KSyncEvent event, uint32_t flow_handle, uint8_t gen_id, int ksync_error, uint64_t evict_flow_bytes, uint64_t evict_flow_packets, int32_t evict_flow_oflow, uint32_t transcation_id)
Definition: flow_proto.cc:633
void Init()
Definition: flow_proto.cc:84
void DisableFlowEventQueue(uint32_t index, bool disabled)
Definition: flow_proto.cc:230
bool UpdateFlow(FlowEntry *flow)
Definition: flow_proto.cc:298
UpdateFlowEventQueue flow_update_queue_
Definition: flow_proto.h:154
void SetProfileData(ProfileData *data)
Definition: flow_proto.cc:866
PortTableManager * port_table_manager()
Definition: flow_proto.h:128
std::vector< KSyncFlowEventQueue * > flow_ksync_queue_
Definition: flow_proto.h:152
friend class SandeshIPv4FlowFilterRequest
Definition: flow_proto.h:133
bool EnqueueReentrant(boost::shared_ptr< PktInfo > msg, uint8_t table_index)
Definition: flow_proto.cc:669
friend class FlowTest
Definition: flow_proto.h:138
bool FlowKSyncMsgHandler(FlowEvent *req, FlowTable *table)
Definition: flow_proto.cc:510
uint16_t FlowTableIndex(const IpAddress &sip, const IpAddress &dip, uint8_t proto, uint16_t sport, uint16_t dport, uint32_t flow_handle) const
Definition: flow_proto.cc:161
size_t FlowUpdateQueueLength()
Definition: flow_proto.cc:244
bool Enqueue(PktInfoPtr msg)
Definition: flow_proto.cc:220
std::vector< FlowEventQueue * > flow_event_queue_
Definition: flow_proto.h:149
bool Validate(PktInfo *msg)
Definition: flow_proto.cc:196
bool AddFlow(FlowEntry *flow)
Definition: flow_proto.cc:292
Definition: timer.h:57
Definition: vn.h:151
boost::intrusive_ptr< FlowEntry > FlowEntryPtr
Definition: flow_entry.h:125
SandeshTraceBufferPtr PktFlowTraceBuf
boost::shared_ptr< Token > TokenPtr
Definition: flow_token.h:11
Definition: io_utils.cc:11
boost::shared_ptr< PktInfo > PktInfoPtr
Definition: pkt_handler.h:60
boost::shared_ptr< TraceBuffer< SandeshTrace > > SandeshTraceBufferPtr
Definition: sandesh_trace.h:18
uint64_t revaluate_count_
Definition: flow_proto.h:28
uint64_t add_count_
Definition: flow_proto.h:25
uint64_t revaluate_process_
Definition: flow_proto.h:37
uint64_t vrouter_error_
Definition: flow_proto.h:32
uint64_t delete_count_
Definition: flow_proto.h:26
uint64_t delete_process_
Definition: flow_proto.h:36
uint64_t evict_count_
Definition: flow_proto.h:33
uint64_t audit_count_
Definition: flow_proto.h:30
uint64_t vrouter_responses_
Definition: flow_proto.h:31
uint64_t flow_messages_
Definition: flow_proto.h:27
uint64_t recompute_count_
Definition: flow_proto.h:29
uint64_t recompute_process_
Definition: flow_proto.h:38