Line data Source code
1 : /* 2 : * Copyright (c) 2015 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : #ifndef __VNSW_AGENT_VROUTER_KSYNC_KSYNC_FLOW_INDEX_MANAGER_H__ 5 : #define __VNSW_AGENT_VROUTER_KSYNC_KSYNC_FLOW_INDEX_MANAGER_H__ 6 : 7 : #include <mutex> 8 : 9 : #include <pkt/flow_entry.h> 10 : 11 : //////////////////////////////////////////////////////////////////////////// 12 : // The module is responsible to manage assignment of vrouter flow-table index 13 : // to the flow. 14 : // 15 : // The module maintains following information, 16 : // 17 : // KSyncFlowIndexManager::IndexTree 18 : // Common table containing information about which flow owns the index. 19 : // Each entry in tree is of type KSyncFlowIndexManager::IndexEntry. 20 : // It contains, 21 : // owner_ : Flow owning the index 22 : //////////////////////////////////////////////////////////////////////////// 23 : class FlowEntry; 24 : class FlowProto; 25 : class KSyncFlowIndexManager; 26 : class FlowTableKSyncObject; 27 : class SandeshFlowIndexInfo; 28 : 29 : class KSyncFlowIndexManager { 30 : public: 31 : // use buffer of 127 (half of the gen-id range) to identify Active 32 : // gen id while accounting for roll-over of gen-id 33 : static const uint8_t kActiveGenIdDiffMax = 127; 34 : 35 : struct IndexEntry { 36 393216 : IndexEntry() : owner_(NULL) { } 37 393216 : virtual ~IndexEntry() { 38 393216 : assert(owner_.get() == NULL); 39 393216 : } 40 : // copy-contructor is needed by std::vector but should never be used 41 : IndexEntry(const IndexEntry& i) { 42 : assert(0); 43 : } 44 : 45 : std::mutex mutex_; 46 : FlowEntryPtr owner_; 47 : }; 48 : KSyncFlowIndexManager(KSync *ksync); 49 : virtual ~KSyncFlowIndexManager(); 50 : void InitDone(uint32_t count); 51 : 52 : FlowEntryPtr FindByIndex(uint32_t idx); 53 : 54 : void Update(FlowEntry *flow); 55 : void Delete(FlowEntry *flow); 56 : void DisableSend(FlowEntry *flow, uint8_t evict_gen_id); 57 : void UpdateFlowHandle(FlowTableKSyncEntry *kentry, uint32_t index, 58 : uint8_t gen_id); 59 : void TriggerKSyncEvent(FlowTableKSyncEntry *kentry, 60 : KSyncEntry::KSyncEvent event); 61 : 62 188 : uint16_t sm_log_count() const { return sm_log_count_; } 63 : 64 : private: 65 : uint8_t AcquireIndexUnLocked(uint32_t index, uint8_t gen_id, 66 : FlowEntry *flow); 67 : void ReleaseIndexUnLocked(FlowEntry *flow); 68 : 69 : void CreateInternal(FlowEntry *flow); 70 : 71 : KSync *ksync_; 72 : FlowProto *proto_; 73 : uint32_t count_; 74 : struct IndexEntry *index_list_; 75 : uint16_t sm_log_count_; 76 : }; 77 : 78 : #endif // __VNSW_AGENT_VROUTER_KSYNC_KSYNC_FLOW_INDEX_MANAGER_H__