5 #ifndef __AGENT_FLOW_TABLE_H__
6 #define __AGENT_FLOW_TABLE_H__
13 #if __GNUC_PREREQ(4, 5)
14 #pragma GCC diagnostic push
15 #pragma GCC diagnostic ignored "-Wunused-result"
18 #include <boost/uuid/random_generator.hpp>
20 #if __GNUC_PREREQ(4, 6)
21 #pragma GCC diagnostic pop
25 #include <boost/uuid/uuid_io.hpp>
26 #include <boost/intrusive_ptr.hpp>
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 std::unique_lock<std::mutex> lock1, lock2; \
71 if (flow && rflow) { \
72 auto l1 = std::unique_lock<std::mutex>(flow->mutex(), std::defer_lock); \
74 auto l2 = std::unique_lock<std::mutex>(rflow->mutex(), std::defer_lock); \
76 std::lock(lock1, lock2); \
78 auto l1 = std::unique_lock<std::mutex>(flow->mutex(), std::defer_lock); \
82 auto l2 = std::unique_lock<std::mutex>(rflow->mutex(), std::defer_lock); \
86 if (is_flow_rflow_key_same) { \
87 flow->MakeShortFlow(FlowEntry::SHORT_SAME_FLOW_RFLOW_KEY); \
108 typedef boost::intrusive::member_hook<
FlowEntry,
109 boost::intrusive::list_member_hook<>,
111 typedef boost::intrusive::list<FlowEntry, Node>
FreeList;
158 return lhs_base.
IsLess(rhs);
210 FlowTable::FlowEntryMap::iterator
begin() {
213 FlowTable::FlowEntryMap::iterator
end() {
221 const uint64_t timestamp);
228 const int last_count);
238 bool active_flow,
bool deleted_flow);
240 int ksync_error, uint32_t flow_handle,
268 std::string &action_str);
290 FlowEntry *new_rflow,
bool fwd_flow_update,
291 bool rev_flow_update);
293 FlowEntry *new_rflow,
bool fwd_flow_update,
bool rev_flow_update);
333 #define FLOW_TRACE(obj, ...)\
335 Flow##obj::TraceMsg(FlowTraceBuf, __FILE__, __LINE__, ##__VA_ARGS__);\
std::vector< AclEntryID > AclEntryIDList
static const uint32_t kTestInitCount
DISALLOW_COPY_AND_ASSIGN(FlowEntryFreeList)
virtual ~FlowEntryFreeList()
static const uint32_t kMaxThreshold
boost::intrusive::member_hook< FlowEntry, boost::intrusive::list_member_hook<>, &FlowEntry::free_list_node_ > Node
boost::intrusive::list< FlowEntry, Node > FreeList
uint32_t alloc_count() const
FlowEntry * Allocate(const FlowKey &key)
static const uint32_t kMinThreshold
uint32_t total_free() const
void Free(FlowEntry *flow)
static const uint32_t kInitCount
uint32_t free_count() const
FlowEntryFreeList(FlowTable *table)
uint32_t max_count() const
static const uint32_t kGrowSize
uint32_t total_alloc() const
boost::intrusive::list_member_hook free_list_node_
const LinkLocalFlowInfoMap & linklocal_flow_info_map()
friend class FetchFlowRecord
bool DeleteFlows(FlowEntry *flow, FlowEntry *rflow)
void SetAclFlowSandeshData(const AclDBEntry *acl, AclFlowResp &data, const int last_count)
void Copy(FlowEntry *lhs, FlowEntry *rhs, bool update)
int flow_ksync_task_id() const
void Add(FlowEntry *flow, FlowEntry *new_flow, FlowEntry *rflow, FlowEntry *new_rflow, bool fwd_flow_update, bool rev_flow_update)
FlowEntry * Find(const FlowKey &key)
static void GetFlowSandeshActionParams(const FlowAction &action_info, std::string &action_str)
FlowTable::FlowEntryMap::iterator begin()
FlowEntryFreeList free_list_
int flow_logging_task_id() const
FlowTableKSyncObject * ksync_object_
void DelLinkLocalFlowInfo(int fd)
void RecomputeFlow(FlowEntry *flow)
int flow_delete_task_id() const
std::map< FlowKey, FlowEntry *, Inet4FlowKeyCmp > FlowEntryMap
void AddInternal(FlowEntry *flow, FlowEntry *new_flow, FlowEntry *rflow, FlowEntry *new_rflow, bool fwd_flow_update, bool rev_flow_update)
friend void intrusive_ptr_release(FlowEntry *fe)
FlowEntry * Locate(FlowEntry *flow, uint64_t t)
void Add(FlowEntry *flow, FlowEntry *rflow)
int flow_update_task_id() const
static const uint32_t kInvalidFlowTableInstance
void ReleasePort(FlowEntry *flow, bool evict)
void PopulateFlowEntriesUsingKey(const FlowKey &key, bool reverse_flow, FlowEntry **flow, FlowEntry **rflow)
void DisableKSyncSend(FlowEntry *flow, uint32_t evict_gen_id)
LinkLocalFlowInfoMap linklocal_flow_info_map_
bool Delete(const FlowKey &key, bool del_reverse_flow)
void set_ksync_object(FlowTableKSyncObject *obj)
void EvictFlow(FlowEntry *flow, FlowEntry *rflow, uint32_t evict_gen_id)
FlowTable(Agent *agent, uint16_t table_index)
bool ProcessFlowEvent(const FlowEvent *req, FlowEntry *flow, FlowEntry *rflow)
FlowIndexTree flow_index_tree_
uint16_t table_index() const
void UpdateUnLocked(FlowEntry *flow, FlowEntry *rflow)
void ProcessKSyncFlowEvent(const FlowEventKSync *req, FlowEntry *flow)
void DeleteKSync(FlowEntry *flow)
static const uint32_t kPortNatFlowTableInstance
void UpdateReverseFlow(FlowEntry *flow, FlowEntry *rflow)
void DeleteFlowUveInfo(FlowEntry *fe)
void UpdateKSync(FlowEntry *flow, bool update)
void HandleKSyncError(FlowEntry *flow, FlowTableKSyncEntry *ksync_entry, int ksync_error, uint32_t flow_handle, uint32_t gen_id)
void DeleteFlowInfo(FlowEntry *fe, const RevFlowDepParams ¶ms)
FlowTableKSyncObject * ksync_object() const
FlowEntryFreeList * free_list()
DISALLOW_COPY_AND_ASSIGN(FlowTable)
boost::uuids::random_generator rand_gen_
boost::uuids::uuid rand_gen()
std::vector< FlowEntryPtr > FlowIndexTree
boost::function< bool(FlowEntry *flow)> FlowEntryCb
bool DeleteUnLocked(const FlowKey &key, bool del_reverse_flow)
void DeleteInternal(FlowEntry *fe, uint64_t t, const RevFlowDepParams &p)
std::map< int, LinkLocalFlowInfo > LinkLocalFlowInfoMap
FlowEntryMap flow_entry_map_
int flow_logging_task_id_
void DeleteVrf(VrfEntry *vrf)
bool IsEvictedFlow(const FlowKey &key)
std::pair< int, LinkLocalFlowInfo > LinkLocalFlowInfoPair
static const char * TaskName()
std::pair< FlowKey, FlowEntry * > FlowEntryMapPair
void AddLinkLocalFlowInfo(int fd, uint32_t index, const FlowKey &key, const uint64_t timestamp)
void DeleteFlow(const AclDBEntry *acl, const FlowKey &key, AclEntryIDList &id_list)
void Update(FlowEntry *flow, FlowEntry *rflow)
void HandleRevaluateDBEntry(const DBEntry *entry, FlowEntry *flow, bool active_flow, bool deleted_flow)
void AddFlowInfo(FlowEntry *fe)
void SetAceSandeshData(const AclDBEntry *acl, AclFlowCountResp &data, int ace_id)
void DeleteMessage(FlowEntry *flow)
bool ConcurrencyCheck(int task_id, bool check_task_instance)
FlowTable::FlowEntryMap::iterator end()
boost::intrusive_ptr< FlowEntry > FlowEntryPtr
void SetActionStr(const FlowAction &, std::vector< ActionStr > &)
std::set< FlowEntryPtr, FlowEntryCmp > FlowEntryTree
SandeshTraceBufferPtr FlowTraceBuf
boost::shared_ptr< TraceBuffer< SandeshTrace > > SandeshTraceBufferPtr
bool operator()(const FlowEntryPtr &l, const FlowEntryPtr &r)
bool IsLess(const FlowKey &key) const
LinkLocalFlowInfo(uint32_t index, const FlowKey &key, uint64_t t)
FlowTaskMsg(FlowEntry *fe)
bool operator()(const FlowKey &lhs, const FlowKey &rhs) const