Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : * Copyright Contributors to the OpenSDN project 4 : */ 5 : 6 : #ifndef vnsw_agent_mpls_hpp 7 : #define vnsw_agent_mpls_hpp 8 : 9 : #include <cmn/agent_cmn.h> 10 : #include <cmn/agent.h> 11 : #include <oper/route_common.h> 12 : #include <oper/nexthop.h> 13 : #include <resource_manager/resource_manager.h> 14 : 15 : extern SandeshTraceBufferPtr MplsTraceBuf; 16 : #define MPLS_TRACE(obj, ...) \ 17 : do { \ 18 : obj::TraceMsg(MplsTraceBuf, __FILE__, __LINE__, ##__VA_ARGS__); \ 19 : } while (false) 20 : 21 : class MplsLabelKey : public AgentKey { 22 : public: 23 7135 : MplsLabelKey(uint32_t label) : AgentKey(), label_(label) { } 24 11035 : virtual ~MplsLabelKey() { } 25 : 26 10091 : uint32_t label() const { return label_; } 27 : private: 28 : uint32_t label_; 29 : }; 30 : 31 : class MplsLabelData : public AgentData { 32 : public: 33 2998 : MplsLabelData(const NextHopKey *nh_key) : nh_key_(nh_key), vrf_name_() { 34 2998 : } 35 : 36 5996 : virtual ~MplsLabelData() { 37 5996 : } 38 : 39 2873 : const NextHopKey *nh_key() const { return nh_key_.get(); } 40 0 : std::string vrf_name() const {return vrf_name_;} 41 2096 : void set_vrf_name(const std::string &vrf_name) { 42 2096 : vrf_name_ = vrf_name; 43 2096 : } 44 : 45 : private: 46 : std::unique_ptr<const NextHopKey> nh_key_; 47 : std::string vrf_name_; 48 : }; 49 : 50 : ///////////////////////////////////////////////////////////////////////////// 51 : // MplsLabel entry 52 : ///////////////////////////////////////////////////////////////////////////// 53 : class MplsLabel : AgentRefCount<MplsLabel>, public AgentDBEntry { 54 : public: 55 : typedef DependencyList<AgentRoute, MplsLabel> DependentPathList; 56 : typedef std::map<std::string, NextHopRef> FmgVrfNhMap; 57 : MplsLabel(Agent *agent, uint32_t label); 58 : virtual ~MplsLabel(); 59 : 60 : virtual bool IsLess(const DBEntry &rhs) const; 61 : virtual std::string ToString() const; 62 : 63 : virtual void SetKey(const DBRequestKey *key); 64 : virtual KeyPtr GetDBRequestKey() const; 65 : 66 : virtual uint32_t GetRefCount() const; 67 : virtual bool DBEntrySandesh(Sandesh *sresp, std::string &name) const; 68 : 69 : void Add(const DBRequest *req); 70 : bool Change(const DBRequest *req); 71 : void Delete(const DBRequest *req); 72 : bool ChangeInternal(const DBRequest *req); 73 : bool ChangeNH(NextHop *nh); 74 : 75 : void SyncDependentPath(); 76 : bool IsFabricMulticastReservedLabel() const; 77 : void SendObjectLog(const AgentDBTable *table, 78 : AgentLogEvent::type event) const; 79 : 80 6591 : uint32_t label() const {return label_;} 81 5895 : const NextHop *nexthop() const {return nh_;} 82 0 : FmgVrfNhMap &fmg_nh_list() { 83 0 : return fmg_nh_list_; 84 : } 85 : 86 : private: 87 : friend class MplsTable; 88 : Agent *agent_; 89 : uint32_t label_; 90 : bool free_label_; 91 : NextHop *nh_; 92 : FmgVrfNhMap fmg_nh_list_; 93 112 : DEPENDENCY_LIST(AgentRoute, MplsLabel, mpls_label_); 94 : DISALLOW_COPY_AND_ASSIGN(MplsLabel); 95 : }; 96 : 97 : ///////////////////////////////////////////////////////////////////////////// 98 : // MPLS Table 99 : ///////////////////////////////////////////////////////////////////////////// 100 : class MplsTable : public AgentDBTable { 101 : public: 102 : static const uint32_t kInvalidLabel = 0xFFFFFFFF; 103 : static const uint32_t kInvalidExportLabel = 0; 104 : static const uint32_t kStartLabel = 16; 105 : static const uint32_t kDpdkShiftBits = 4; 106 : static const uint32_t kImplicitNullLabel = 3; 107 : 108 : MplsTable(DB *db, const std::string &name); 109 : virtual ~MplsTable(); 110 : 111 : virtual void Process(DBRequest &req); 112 8148 : virtual size_t Hash(const DBEntry *entry) const {return 0;} 113 8037 : virtual size_t Hash(const DBRequestKey *key) const {return 0;} 114 : virtual std::unique_ptr<DBEntry> AllocEntry(const DBRequestKey *k) const; 115 : 116 : virtual DBEntry *Add(const DBRequest *req); 117 : virtual bool OnChange(DBEntry *entry, const DBRequest *req); 118 : virtual bool Delete(DBEntry *entry, const DBRequest *req); 119 : virtual void OnZeroRefcount(AgentDBEntry *e); 120 : virtual AgentSandeshPtr GetAgentSandesh(const AgentSandeshArguments *args, 121 : const std::string &context); 122 : uint32_t CreateRouteLabel(uint32_t label, const NextHopKey *nh_key, 123 : const std::string &vrf_name, 124 : const std::string &route); 125 : void ReserveLabel(uint32_t start, uint32_t end); 126 : void FreeReserveLabel(uint32_t start, uint32_t end); 127 : MplsLabel *AllocLabel(const NextHopKey *nh_key); 128 : uint32_t AllocLabel(ResourceManager::KeyPtr key); 129 : void FreeLabel(uint32_t label); 130 : void FreeLabel(uint32_t label, const std::string &vrf_name); 131 : 132 : void ReserveMulticastLabel(uint32_t start, uint32_t end, uint8_t idx); 133 : bool IsFabricMulticastLabel(uint32_t label) const; 134 : MplsLabel *FindMplsLabel(uint32_t label); 135 : 136 : static DBTableBase *CreateTable(DB *db, const std::string &name); 137 : void CheckVrLabelLimit(); 138 15 : uint32_t LabelIndexCount() { return label_table_.InUseIndexCount(); } 139 1027 : void FreeMplsLabelIndex(size_t label) { label_table_.Remove(label); } 140 : private: 141 : bool ChangeHandler(MplsLabel *mpls, const DBRequest *req); 142 : IndexVector<MplsLabel *> label_table_; 143 : uint32_t multicast_label_start_[MAX_XMPP_SERVERS]; 144 : uint32_t multicast_label_end_[MAX_XMPP_SERVERS]; 145 : DISALLOW_COPY_AND_ASSIGN(MplsTable); 146 : }; 147 : 148 : #endif // vnsw_agent_mpls_hpp