/
vrf.h
249 lines (212 loc) · 8.79 KB
/
vrf.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#ifndef vnsw_agent_vrf_hpp
#define vnsw_agent_vrf_hpp
#include <cmn/agent_cmn.h>
#include <cmn/index_vector.h>
#include <cmn/agent.h>
#include <oper/agent_types.h>
#include <oper/oper_db.h>
using namespace std;
class LifetimeActor;
class LifetimeManager;
class ComponentNHData;
class AgentRouteWalker;
class AgentRouteResync;
struct VrfKey : public AgentOperDBKey {
VrfKey(const string &name) : AgentOperDBKey(), name_(name) { }
virtual ~VrfKey() { }
void Init(const string &vrf_name) {name_ = vrf_name;};
bool IsLess(const VrfKey &rhs) const {
return name_ < rhs.name_;
}
bool IsEqual(const VrfKey &rhs) const {
if ((IsLess(rhs) == false) && (rhs.IsLess(*this) == false)) {
return true;
}
return false;
}
string name_;
};
struct VrfData : public AgentOperDBData {
enum VrfEntryFlags {
ConfigVrf = 1 << 0, // vrf is received from config
GwVrf = 1 << 1, // GW configured for this VRF
};
VrfData(Agent *agent, IFMapNode *node, uint32_t flags,
const boost::uuids::uuid &vn_uuid) :
AgentOperDBData(agent, node), flags_(flags), vn_uuid_(vn_uuid) {}
virtual ~VrfData() {}
uint32_t flags_;
boost::uuids::uuid vn_uuid_;
};
class VrfEntry : AgentRefCount<VrfEntry>, public AgentOperDBEntry {
public:
static const uint32_t kInvalidIndex = 0xFFFFFFFF;
static const uint32_t kDeleteTimeout = 900 * 1000;
VrfEntry(const string &name, uint32_t flags, Agent *agent);
virtual ~VrfEntry();
virtual bool IsLess(const DBEntry &rhs) const;
virtual KeyPtr GetDBRequestKey() const;
virtual void SetKey(const DBRequestKey *key);
virtual string ToString() const;
const uint32_t vrf_id() const {return id_;};
const string &GetName() const {return name_;};
VnEntry *vn() const { return vn_.get(); }
uint32_t GetRefCount() const {
return AgentRefCount<VrfEntry>::GetRefCount();
}
uint32_t flags() const { return flags_; }
void set_flags(uint32_t flags) { flags_ |= flags; }
bool are_flags_set(const VrfData::VrfEntryFlags &flags) const {
return (flags_ & flags);
}
void set_table_label(uint32_t label) {
table_label_ = label;
}
uint32_t table_label() const {
return table_label_;
}
bool DBEntrySandesh(Sandesh *sresp, std::string &name) const;
InetUnicastRouteEntry *GetUcRoute(const IpAddress &addr) const;
InetUnicastRouteEntry *GetUcRoute(const InetUnicastRouteEntry &rt_key)const;
bool UpdateVxlanId(Agent *agent, uint32_t new_vxlan_id);
LifetimeActor *deleter();
virtual void RetryDelete();
bool AllRouteTablesEmpty() const;
void SendObjectLog(AgentLogEvent::type event) const;
void StartDeleteTimer();
bool DeleteTimeout();
void CancelDeleteTimer();
void PostAdd();
void AddNH(Ip4Address ip, uint8_t plen, ComponentNHData *nh_data) ;
void DeleteNH(Ip4Address ip, uint8_t plen, ComponentNHData *nh_data) ;
uint32_t GetNHCount(Ip4Address ip, uint8_t plen) ;
void UpdateLabel(Ip4Address ip, uint8_t plen, uint32_t label);
uint32_t GetLabel(Ip4Address ip, uint8_t plen);
uint32_t vxlan_id() const {return vxlan_id_;}
std::vector<ComponentNHData>* GetNHList(Ip4Address ip, uint8_t plen);
bool FindNH(const Ip4Address &ip, uint8_t plen,
const ComponentNHData &nh_data);
InetUnicastAgentRouteTable *GetInet4UnicastRouteTable() const;
AgentRouteTable *GetInet4MulticastRouteTable() const;
AgentRouteTable *GetEvpnRouteTable() const;
AgentRouteTable *GetBridgeRouteTable() const;
InetUnicastAgentRouteTable *GetInet6UnicastRouteTable() const;
AgentRouteTable *GetRouteTable(uint8_t table_type) const;
void CreateTableLabel();
bool AllRouteTableDeleted() const;
bool RouteTableDeleted(uint8_t table_type) const;
void SetRouteTableDeleted(uint8_t table_type);
void DeleteRouteTables();
void ResyncRoutes();
bool allow_route_add_on_deleted_vrf() const {
return allow_route_add_on_deleted_vrf_;
}
//To be set in test cases only
void set_allow_route_add_on_deleted_vrf(bool val) {
allow_route_add_on_deleted_vrf_ = val;
}
private:
friend class VrfTable;
void CreateRouteTables();
class DeleteActor;
string name_;
uint32_t id_;
uint32_t flags_;
VnEntryRef vn_;
DBTableWalker::WalkId walkid_;
boost::scoped_ptr<DeleteActor> deleter_;
AgentRouteTable *rt_table_db_[Agent::ROUTE_TABLE_MAX];
Timer *delete_timeout_timer_;
uint32_t table_label_;
uint32_t vxlan_id_;
uint32_t rt_table_delete_bmap_;
IFMapDependencyManager::IFMapNodePtr vrf_node_ptr_;
boost::scoped_ptr<AgentRouteResync> route_resync_walker_;
bool allow_route_add_on_deleted_vrf_;
DISALLOW_COPY_AND_ASSIGN(VrfEntry);
};
class VrfTable : public AgentOperDBTable {
public:
// Map from VRF Name to VRF Entry
typedef map<string, VrfEntry *> VrfNameTree;
typedef pair<string, VrfEntry *> VrfNamePair;
// Config tree of VRF to VMI entries. Tree used to track the VMIs that are
// already processed after VRF has been added
typedef set<std::string, boost::uuids::uuid> CfgVmiTree;
// Map from VRF Name to Route Table
typedef map<string, RouteTable *> VrfDbTree;
typedef pair<string, RouteTable *> VrfDbPair;
VrfTable(DB *db, const std::string &name) :
AgentOperDBTable(db, name), db_(db),
walkid_(DBTableWalker::kInvalidWalkerId),
route_delete_walker_(NULL),
vrf_delete_walker_(NULL) { };
virtual ~VrfTable();
virtual std::auto_ptr<DBEntry> AllocEntry(const DBRequestKey *k) const;
virtual size_t Hash(const DBEntry *entry) const {return 0;};
virtual size_t Hash(const DBRequestKey *key) const {return 0;};
virtual void Input(DBTablePartition *root, DBClient *client,
DBRequest *req);
void VrfReuse(std::string name);
virtual DBEntry *OperDBAdd(const DBRequest *req);
virtual bool OperDBOnChange(DBEntry *entry, const DBRequest *req);
virtual bool OperDBDelete(DBEntry *entry, const DBRequest *req);
virtual void OnZeroRefcount(AgentDBEntry *e);
virtual AgentSandeshPtr GetAgentSandesh(const AgentSandeshArguments *args,
const std::string &context);
// Create a VRF entry with given name
void CreateVrf(const string &name, uint32_t flags = VrfData::ConfigVrf);
void DeleteVrf(const string &name, uint32_t flags = VrfData::ConfigVrf);
void CreateVrfReq(const string &name, uint32_t flags = VrfData::ConfigVrf);
void CreateVrfReq(const string &name, const boost::uuids::uuid &vn_uuid,
uint32_t flags = VrfData::ConfigVrf);
void DeleteVrfReq(const string &name, uint32_t flags = VrfData::ConfigVrf);
//Add and delete routine for VRF not deleted on VRF config delete
void CreateStaticVrf(const string &name);
void DeleteStaticVrf(const string &name);
// Create VRF Table with given name
static DBTableBase *CreateTable(DB *db, const std::string &name);
static VrfTable *GetInstance() {return vrf_table_;};
virtual bool IFNodeToReq(IFMapNode *node, DBRequest &req,
const boost::uuids::uuid &u);
bool ProcessConfig(IFMapNode *node, DBRequest &req,
const boost::uuids::uuid &u);
VrfEntry *FindVrfFromName(const string &name);
VrfEntry *FindVrfFromId(size_t index);
VrfEntry *FindVrfFromIdIncludingDeletedVrf(size_t index);
void FreeVrfId(size_t index) {index_table_.Remove(index);};
virtual bool CanNotify(IFMapNode *dbe);
InetUnicastAgentRouteTable *GetInet4UnicastRouteTable
(const std::string &vrf_name);
AgentRouteTable *GetInet4MulticastRouteTable(const std::string &vrf_name);
AgentRouteTable *GetEvpnRouteTable(const std::string &vrf_name);
AgentRouteTable *GetBridgeRouteTable(const std::string &vrf_name);
AgentRouteTable *GetRouteTable(const string &vrf_name, uint8_t table_type);
InetUnicastAgentRouteTable *GetInet6UnicastRouteTable
(const std::string &vrf_name);
bool IsStaticVrf(const std::string &vrf_name) const {
if (static_vrf_set_.find(vrf_name) != static_vrf_set_.end()) {
return true;
}
return false;
}
void DeleteRoutes();
void Shutdown();
void DeleteFromDbTree(int table_type, const std::string &vrf_name);
private:
friend class VrfEntry;
DB *db_;
static VrfTable *vrf_table_;
IndexVector<VrfEntry> index_table_;
VrfNameTree name_tree_;
VrfDbTree dbtree_[Agent::ROUTE_TABLE_MAX];
DBTableWalker::WalkId walkid_;
std::set<std::string> static_vrf_set_;
AgentRouteWalker *route_delete_walker_;
AgentRouteWalker *vrf_delete_walker_;
DISALLOW_COPY_AND_ASSIGN(VrfTable);
};
#endif // vnsw_agent_vrf_hpp