5 #ifndef __AGENT_FLOW_TABLE_H__
6 #define __AGENT_FLOW_TABLE_H__
11 #if __GNUC_PREREQ(4, 5)
12 #pragma GCC diagnostic push
13 #pragma GCC diagnostic ignored "-Wunused-result"
16 #include <boost/uuid/random_generator.hpp>
18 #if __GNUC_PREREQ(4, 6)
19 #pragma GCC diagnostic pop
23 #include <boost/uuid/uuid_io.hpp>
24 #include <boost/intrusive_ptr.hpp>
25 #include <tbb/atomic.h>
26 #include <tbb/mutex.h>
35 #include <pkt/pkt_types.h>
40 #include <sandesh/sandesh_trace.h>
49 #include <sandesh/common/flow_types.h>
53 class FetchFlowRecord;
61 #define FLOW_LOCK(flow, rflow, flow_event) \
62 bool is_flow_rflow_key_same = false; \
63 if (flow == rflow) { \
64 if (flow_event == FlowEvent::DELETE_FLOW) { \
67 is_flow_rflow_key_same = true; \
70 tbb::mutex tmp_mutex1, tmp_mutex2, *mutex_ptr_1, *mutex_ptr_2; \
71 FlowTable::GetMutexSeq(flow ? flow->mutex() : tmp_mutex1, \
72 rflow ? rflow->mutex() : tmp_mutex2, \
73 &mutex_ptr_1, &mutex_ptr_2); \
74 tbb::mutex::scoped_lock lock1(*mutex_ptr_1); \
75 tbb::mutex::scoped_lock lock2(*mutex_ptr_2); \
76 if (is_flow_rflow_key_same) { \
77 flow->MakeShortFlow(FlowEntry::SHORT_SAME_FLOW_RFLOW_KEY); \
98 typedef boost::intrusive::member_hook<
FlowEntry,
99 boost::intrusive::list_member_hook<>,
101 typedef boost::intrusive::list<FlowEntry, Node>
FreeList;
148 return lhs_base.
IsLess(rhs);
200 FlowTable::FlowEntryMap::iterator
begin() {
203 FlowTable::FlowEntryMap::iterator
end() {
211 const uint64_t timestamp);
218 const int last_count);
228 bool active_flow,
bool deleted_flow);
230 int ksync_error, uint32_t flow_handle,
257 static void GetMutexSeq(tbb::mutex &mutex1, tbb::mutex &mutex2,
258 tbb::mutex **mutex_ptr_1, tbb::mutex **mutex_ptr_2);
260 std::string &action_str);
282 FlowEntry *new_rflow,
bool fwd_flow_update,
283 bool rev_flow_update);
285 FlowEntry *new_rflow,
bool fwd_flow_update,
bool rev_flow_update);
325 #define FLOW_TRACE(obj, ...)\
327 Flow##obj::TraceMsg(FlowTraceBuf, __FILE__, __LINE__, ##__VA_ARGS__);\
FlowIndexTree flow_index_tree_
bool IsEvictedFlow(const FlowKey &key)
std::set< FlowEntryPtr, FlowEntryCmp > FlowEntryTree
boost::uuids::uuid rand_gen()
LinkLocalFlowInfoMap linklocal_flow_info_map_
bool operator()(const FlowKey &lhs, const FlowKey &rhs) const
bool ConcurrencyCheck(int task_id, bool check_task_instance)
boost::function< bool(FlowEntry *flow)> FlowEntryCb
void DelLinkLocalFlowInfo(int fd)
FlowEntryMap flow_entry_map_
static const char * TaskName()
bool DeleteUnLocked(const FlowKey &key, bool del_reverse_flow)
void DeleteFlowInfo(FlowEntry *fe, const RevFlowDepParams ¶ms)
FlowEntryFreeList free_list_
bool IsLess(const FlowKey &key) const
bool Delete(const FlowKey &key, bool del_reverse_flow)
static const uint32_t kMinThreshold
void SetAceSandeshData(const AclDBEntry *acl, AclFlowCountResp &data, int ace_id)
void DeleteFlow(const AclDBEntry *acl, const FlowKey &key, AclEntryIDList &id_list)
static const uint32_t kInitCount
static const uint32_t kPortNatFlowTableInstance
boost::uuids::random_generator rand_gen_
bool operator()(const FlowEntryPtr &l, const FlowEntryPtr &r)
void HandleKSyncError(FlowEntry *flow, FlowTableKSyncEntry *ksync_entry, int ksync_error, uint32_t flow_handle, uint32_t gen_id)
std::vector< FlowEntryPtr > FlowIndexTree
int flow_update_task_id() const
std::vector< AclEntryID > AclEntryIDList
FlowEntry * Locate(FlowEntry *flow, uint64_t t)
static void GetMutexSeq(tbb::mutex &mutex1, tbb::mutex &mutex2, tbb::mutex **mutex_ptr_1, tbb::mutex **mutex_ptr_2)
static const uint32_t kTestInitCount
void DeleteKSync(FlowEntry *flow)
void set_ksync_object(FlowTableKSyncObject *obj)
uint16_t table_index() const
void HandleRevaluateDBEntry(const DBEntry *entry, FlowEntry *flow, bool active_flow, bool deleted_flow)
FlowTable(Agent *agent, uint16_t table_index)
void SetActionStr(const FlowAction &action_info, std::vector< ActionStr > &action_str_l)
void DeleteInternal(FlowEntry *fe, uint64_t t, const RevFlowDepParams &p)
boost::shared_ptr< TraceBuffer< SandeshTrace > > SandeshTraceBufferPtr
std::pair< FlowKey, FlowEntry * > FlowEntryMapPair
uint32_t total_alloc() const
int flow_ksync_task_id() const
static const uint32_t kMaxThreshold
void UpdateKSync(FlowEntry *flow, bool update)
bool ProcessFlowEvent(const FlowEvent *req, FlowEntry *flow, FlowEntry *rflow)
int flow_logging_task_id() const
FlowEntry * Find(const FlowKey &key)
void AddLinkLocalFlowInfo(int fd, uint32_t index, const FlowKey &key, const uint64_t timestamp)
void AddFlowInfo(FlowEntry *fe)
boost::intrusive::member_hook< FlowEntry, boost::intrusive::list_member_hook<>,&FlowEntry::free_list_node_ > Node
boost::intrusive::list< FlowEntry, Node > FreeList
LinkLocalFlowInfo(uint32_t index, const FlowKey &key, uint64_t t)
void DeleteVrf(VrfEntry *vrf)
friend class FetchFlowRecord
std::pair< int, LinkLocalFlowInfo > LinkLocalFlowInfoPair
void DisableKSyncSend(FlowEntry *flow, uint32_t evict_gen_id)
int flow_logging_task_id_
uint32_t free_count() const
FlowEntryFreeList(FlowTable *table)
FlowEntry * Allocate(const FlowKey &key)
DISALLOW_COPY_AND_ASSIGN(FlowTable)
void Add(FlowEntry *flow, FlowEntry *rflow)
void ReleasePort(FlowEntry *flow, bool evict)
const LinkLocalFlowInfoMap & linklocal_flow_info_map()
static void GetFlowSandeshActionParams(const FlowAction &action_info, std::string &action_str)
virtual ~FlowEntryFreeList()
std::map< int, LinkLocalFlowInfo > LinkLocalFlowInfoMap
void Copy(FlowEntry *lhs, FlowEntry *rhs, bool update)
DISALLOW_COPY_AND_ASSIGN(FlowEntryFreeList)
void RecomputeFlow(FlowEntry *flow)
bool DeleteFlows(FlowEntry *flow, FlowEntry *rflow)
static const uint32_t kInvalidFlowTableInstance
FlowTaskMsg(FlowEntry *fe)
void PopulateFlowEntriesUsingKey(const FlowKey &key, bool reverse_flow, FlowEntry **flow, FlowEntry **rflow)
void UpdateUnLocked(FlowEntry *flow, FlowEntry *rflow)
SandeshTraceBufferPtr FlowTraceBuf
uint32_t alloc_count() const
void ProcessKSyncFlowEvent(const FlowEventKSync *req, FlowEntry *flow)
boost::intrusive::list_member_hook free_list_node_
uint32_t total_free() const
FlowTable::FlowEntryMap::iterator begin()
void Free(FlowEntry *flow)
FlowTableKSyncObject * ksync_object_
std::map< FlowKey, FlowEntry *, Inet4FlowKeyCmp > FlowEntryMap
int flow_delete_task_id() const
void AddInternal(FlowEntry *flow, FlowEntry *new_flow, FlowEntry *rflow, FlowEntry *new_rflow, bool fwd_flow_update, bool rev_flow_update)
void SetAclFlowSandeshData(const AclDBEntry *acl, AclFlowResp &data, const int last_count)
void EvictFlow(FlowEntry *flow, FlowEntry *rflow, uint32_t evict_gen_id)
FlowTable::FlowEntryMap::iterator end()
FlowTableKSyncObject * ksync_object() const
uint32_t max_count() const
void DeleteMessage(FlowEntry *flow)
FlowEntryFreeList * free_list()
void DeleteFlowUveInfo(FlowEntry *fe)
boost::intrusive_ptr< FlowEntry > FlowEntryPtr
void Update(FlowEntry *flow, FlowEntry *rflow)
friend void intrusive_ptr_release(FlowEntry *fe)
void UpdateReverseFlow(FlowEntry *flow, FlowEntry *rflow)
static const uint32_t kGrowSize