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