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