OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mpls.h
Go to the documentation of this file.
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>
13 
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  MplsLabelKey(uint32_t label) : AgentKey(), label_(label) { }
23  virtual ~MplsLabelKey() { }
24 
25  uint32_t label() const { return label_; }
26 private:
27  uint32_t label_;
28 };
29 
30 class MplsLabelData : public AgentData {
31 public:
33  }
34 
35  virtual ~MplsLabelData() {
36  }
37 
38  const NextHopKey *nh_key() const { return nh_key_.get(); }
39  std::string vrf_name() const {return vrf_name_;}
40  void set_vrf_name(const std::string &vrf_name) {
42  }
43 
44 private:
45  std::unique_ptr<const NextHopKey> nh_key_;
46  std::string vrf_name_;
47 };
48 
50 // MplsLabel entry
52 class MplsLabel : AgentRefCount<MplsLabel>, public AgentDBEntry {
53 public:
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  uint32_t label() const {return label_;}
80  const NextHop *nexthop() const {return nh_;}
82  return fmg_nh_list_;
83  }
84 
85 private:
86  friend class MplsTable;
88  uint32_t label_;
92  DEPENDENCY_LIST(AgentRoute, MplsLabel, mpls_label_);
94 };
95 
97 // MPLS Table
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  virtual size_t Hash(const DBEntry *entry) const {return 0;}
112  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);
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();
138  void FreeMplsLabelIndex(size_t label) { label_table_.Remove(label); }
139 private:
140  bool ChangeHandler(MplsLabel *mpls, const DBRequest *req);
145 };
146 
147 #endif // vnsw_agent_mpls_hpp
virtual bool DBEntrySandesh(Sandesh *sresp, std::string &name) const
Definition: mpls.cc:144
MplsLabel(Agent *agent, uint32_t label)
Definition: mpls.cc:26
MplsTable(DB *db, const std::string &name)
Definition: mpls.cc:235
std::string vrf_name() const
Definition: mpls.h:39
bool IsFabricMulticastLabel(uint32_t label) const
Definition: mpls.cc:368
uint32_t label() const
Definition: mpls.h:79
virtual size_t Hash(const DBRequestKey *key) const
Definition: mpls.h:112
virtual void SetKey(const DBRequestKey *key)
Definition: mpls.cc:54
virtual bool OnChange(DBEntry *entry, const DBRequest *req)
Definition: mpls.cc:301
bool ChangeNH(NextHop *nh)
Definition: mpls.cc:97
bool ChangeInternal(const DBRequest *req)
Definition: mpls.cc:83
Agent * agent_
Definition: mpls.h:87
SandeshTraceBufferPtr MplsTraceBuf
void Add(const DBRequest *req)
Definition: mpls.cc:63
const NextHop * nexthop() const
Definition: mpls.h:80
NextHop * nh_
Definition: mpls.h:90
static const uint32_t kInvalidExportLabel
Definition: mpls.h:102
boost::shared_ptr< ResourceKey > KeyPtr
uint32_t label_
Definition: mpls.h:88
MplsLabelKey(uint32_t label)
Definition: mpls.h:22
void ReserveLabel(uint32_t start, uint32_t end)
Definition: mpls.cc:376
DISALLOW_COPY_AND_ASSIGN(MplsTable)
void FreeReserveLabel(uint32_t start, uint32_t end)
Definition: mpls.cc:384
size_t InUseIndexCount()
Definition: index_vector.h:89
boost::shared_ptr< TraceBuffer< SandeshTrace > > SandeshTraceBufferPtr
Definition: sandesh_trace.h:18
std::unique_ptr< DBRequestKey > KeyPtr
Definition: db_entry.h:25
Base class for all Route entries in agent.
Definition: agent_route.h:224
static const uint32_t kStartLabel
Definition: mpls.h:103
virtual ~MplsTable()
Definition: mpls.cc:239
void CheckVrLabelLimit()
Definition: mpls.cc:443
static const uint32_t kDpdkShiftBits
Definition: mpls.h:104
IndexVector< MplsLabel * > label_table_
Definition: mpls.h:141
static DBTableBase * CreateTable(DB *db, const std::string &name)
Definition: mpls.cc:242
void Remove(size_t index)
Definition: index_vector.h:78
virtual ~MplsLabel()
Definition: mpls.cc:30
Definition: db.h:24
void FreeMplsLabelIndex(size_t label)
Definition: mpls.h:138
virtual ~MplsLabelKey()
Definition: mpls.h:23
void ReserveMulticastLabel(uint32_t start, uint32_t end, uint8_t idx)
Definition: mpls.cc:392
uint8_t type
Definition: load_balance.h:109
uint32_t label() const
Definition: mpls.h:25
virtual bool IsLess(const DBEntry &rhs) const
Definition: mpls.cc:40
Definition: agent.h:358
bool ChangeHandler(MplsLabel *mpls, const DBRequest *req)
MplsLabel * AllocLabel(const NextHopKey *nh_key)
Definition: mpls.cc:405
std::map< std::string, NextHopRef > FmgVrfNhMap
Definition: mpls.h:55
uint32_t multicast_label_end_[MAX_XMPP_SERVERS]
Definition: mpls.h:143
virtual AgentSandeshPtr GetAgentSandesh(const AgentSandeshArguments *args, const std::string &context)
Definition: mpls.cc:470
virtual KeyPtr GetDBRequestKey() const
Definition: mpls.cc:49
std::string vrf_name_
Definition: mpls.h:46
virtual DBEntry * Add(const DBRequest *req)
Definition: mpls.cc:290
virtual void Process(DBRequest &req)
Definition: mpls.cc:248
DISALLOW_COPY_AND_ASSIGN(MplsLabel)
class boost::shared_ptr< AgentSandesh > AgentSandeshPtr
Definition: agent_db.h:18
const std::string & name() const
Definition: db_table.h:110
void SendObjectLog(const AgentDBTable *table, AgentLogEvent::type event) const
Definition: mpls.cc:157
virtual uint32_t GetRefCount() const
Definition: mpls.cc:59
FmgVrfNhMap & fmg_nh_list()
Definition: mpls.h:81
virtual size_t Hash(const DBEntry *entry) const
Definition: mpls.h:111
bool free_label_
Definition: mpls.h:89
#define MAX_XMPP_SERVERS
Definition: agent.h:291
static const uint32_t kInvalidLabel
Definition: mpls.h:101
void SyncDependentPath()
Definition: mpls.cc:126
void Delete()
Definition: db_entry.cc:131
static const uint32_t kImplicitNullLabel
Definition: mpls.h:105
virtual ~MplsLabelData()
Definition: mpls.h:35
uint32_t CreateRouteLabel(uint32_t label, const NextHopKey *nh_key, const std::string &vrf_name, const std::string &route)
Definition: mpls.cc:341
Definition: mpls.h:99
uint32_t label_
Definition: mpls.h:27
virtual std::unique_ptr< DBEntry > AllocEntry(const DBRequestKey *k) const
Definition: mpls.cc:284
uint32_t multicast_label_start_[MAX_XMPP_SERVERS]
Definition: mpls.h:142
Definition: mpls.h:52
bool Change(const DBRequest *req)
Definition: mpls.cc:70
bool IsFabricMulticastReservedLabel() const
Definition: mpls.cc:135
FmgVrfNhMap fmg_nh_list_
Definition: mpls.h:91
std::unique_ptr< const NextHopKey > nh_key_
Definition: mpls.h:45
MplsLabel * FindMplsLabel(uint32_t label)
Definition: mpls.cc:399
void set_vrf_name(const std::string &vrf_name)
Definition: mpls.h:40
MplsLabelData(const NextHopKey *nh_key)
Definition: mpls.h:32
virtual bool Delete(DBEntry *entry, const DBRequest *req)
Definition: mpls.cc:306
uint32_t LabelIndexCount()
Definition: mpls.h:137
DEPENDENCY_LIST(AgentRoute, MplsLabel, mpls_label_)
virtual void OnZeroRefcount(AgentDBEntry *e)
Definition: mpls.cc:331
virtual std::string ToString() const
Definition: mpls.cc:45
DependencyList< AgentRoute, MplsLabel > DependentPathList
Definition: mpls.h:54
void FreeLabel(uint32_t label)
Definition: mpls.cc:267
const NextHopKey * nh_key() const
Definition: mpls.h:38