/
test_vrf.cc
420 lines (360 loc) · 13.7 KB
/
test_vrf.cc
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#include "base/os.h"
#include "testing/gunit.h"
#include <base/logging.h>
#include <io/event_manager.h>
#include <io/test/event_manager_test.h>
#include <tbb/task.h>
#include <base/task.h>
#include <cmn/agent_cmn.h>
#include "cfg/cfg_init.h"
#include "cfg/cfg_interface.h"
#include "oper/operdb_init.h"
#include "pkt/pkt_init.h"
#include "services/services_init.h"
#include "vrouter/ksync/ksync_init.h"
#include "oper/interface_common.h"
#include "oper/nexthop.h"
#include "route/route.h"
#include "oper/vrf.h"
#include "oper/mpls.h"
#include "oper/vm.h"
#include "oper/vn.h"
#include "filter/acl.h"
#include "test_cmn_util.h"
#include "vr_types.h"
#include "xmpp/xmpp_init.h"
#include "xmpp/test/xmpp_test_util.h"
#include "vr_types.h"
#include "control_node_mock.h"
#include "xml/xml_pugi.h"
#include "controller/controller_peer.h"
#include "controller/controller_export.h"
#include "controller/controller_vrf_export.h"
#include <boost/assign/list_of.hpp>
using namespace boost::assign;
using namespace pugi;
void RouterIdDepInit(Agent *agent) {
Agent::GetInstance()->controller()->Connect();
}
static void ValidateSandeshResponse(Sandesh *sandesh, vector<int> &result) {
//TBD
//Validate the response by the expectation
}
class VrfTest : public ::testing::Test {
protected:
VrfTest(): bgp_peer1(NULL) {
};
virtual void SetUp() {
agent = Agent::GetInstance();
Agent::GetInstance()->controller()->Cleanup();
client->WaitForIdle();
Agent::GetInstance()->controller()->DisConnect();
client->WaitForIdle();
client->Reset();
thread_ = new ServerThread(&evm_);
bgp_peer1 = new test::ControlNodeMock(&evm_, "127.0.0.1");
Agent::GetInstance()->set_controller_ifmap_xmpp_server("127.0.0.1", 0);
Agent::GetInstance()->set_controller_ifmap_xmpp_port(bgp_peer1->GetServerPort(), 0);
Agent::GetInstance()->set_dns_server("127.0.0.1", 0);
Agent::GetInstance()->set_dns_server_port(bgp_peer1->GetServerPort(), 0);
RouterIdDepInit(Agent::GetInstance());
thread_->Start();
WAIT_FOR(100, 10000, (bgp_peer1->IsEstablished() == true));
}
virtual void TearDown() {
if (Agent::GetInstance()->headless_agent_mode()) {
TaskScheduler::GetInstance()->Stop();
Agent::GetInstance()->controller()->unicast_cleanup_timer().cleanup_timer_->Fire();
Agent::GetInstance()->controller()->multicast_cleanup_timer().cleanup_timer_->Fire();
TaskScheduler::GetInstance()->Start();
client->WaitForIdle();
Agent::GetInstance()->controller()->Cleanup();
client->WaitForIdle();
}
Agent::GetInstance()->controller()->config_cleanup_timer().cleanup_timer_->Cancel();
bgp_peer1->Shutdown();
client->WaitForIdle();
delete bgp_peer1;
evm_.Shutdown();
thread_->Join();
delete thread_;
client->WaitForIdle();
}
EventManager evm_;
ServerThread *thread_;
test::ControlNodeMock *bgp_peer1;
Agent *agent;
};
//Add VRF1 and fabric VRF
//Add routes in VRF1
//Delete VRF1, and verify route table is deleted
TEST_F(VrfTest, VrfAddDelTest_1) {
client->Reset();
VrfAddReq("vrf1");
EXPECT_TRUE(client->VrfNotifyWait(1));
EXPECT_TRUE(DBTableFind("vrf1.uc.route.0"));
Ip4Address vm1_ip = Ip4Address::from_string("1.1.1.1");
Ip4Address vm2_ip = Ip4Address::from_string("1.1.1.2");
client->WaitForIdle();
bgp_peer1->AddRoute("vrf1", "1.1.1.1/32", "10.1.1.10", 10, "vn1");
bgp_peer1->AddRoute("vrf1", "1.1.1.2/32", "10.1.1.10", 10, "vn1");
WAIT_FOR(100, 10000, (RouteFind("vrf1", vm1_ip, 32) == true));
WAIT_FOR(100, 10000, (RouteFind("vrf1", vm2_ip, 32) == true));
VrfDelReq("vrf1");
client->WaitForIdle();
WAIT_FOR(100, 10000, (VrfFind("vrf1")== false));
EXPECT_FALSE(DBTableFind("vrf1.uc.route.0"));
}
TEST_F(VrfTest, VrfAddDelTest_sandesh_test_1) {
client->Reset();
VrfAddReq("vrf1");
EXPECT_TRUE(client->VrfNotifyWait(1));
EXPECT_TRUE(DBTableFind("vrf1.uc.route.0"));
Ip4Address vm1_ip = Ip4Address::from_string("1.1.1.1");
Ip4Address vm2_ip = Ip4Address::from_string("1.1.1.2");
client->WaitForIdle();
bgp_peer1->AddRoute("vrf1", "1.1.1.1/32", "10.1.1.10", 10, "vn1");
bgp_peer1->AddRoute("vrf1", "1.1.1.2/32", "10.1.1.10", 10, "vn1");
WAIT_FOR(100, 10000, (RouteFind("vrf1", vm1_ip, 32) == true));
WAIT_FOR(100, 10000, (RouteFind("vrf1", vm2_ip, 32) == true));
VrfListReq *vrf_list_req = new VrfListReq();
std::vector<int> result = list_of(1);
Sandesh::set_response_callback(boost::bind(ValidateSandeshResponse, _1, result));
vrf_list_req->HandleRequest();
client->WaitForIdle();
vrf_list_req->Release();
client->WaitForIdle();
VrfDelReq("vrf1");
client->WaitForIdle();
WAIT_FOR(100, 10000, (VrfFind("vrf1")== false));
EXPECT_FALSE(DBTableFind("vrf1.uc.route.0"));
}
//
//Create a interface, belonging to vrf1 and verify
//upon delete of vrf, local routes are deleted
TEST_F(VrfTest, VrfAddDelWithVm_1) {
client->Reset();
struct PortInfo input[] = {
{"vnet1", 1, "1.1.1.1", "00:00:00:01:01:01", 1, 1},
{"vnet2", 2, "1.1.1.2", "00:00:00:02:02:02", 1, 2},
};
Ip4Address vm1_ip = Ip4Address::from_string(input[0].addr);
Ip4Address vm2_ip = Ip4Address::from_string(input[1].addr);
CreateVmportEnv(input, 2);
client->WaitForIdle();
EXPECT_TRUE(client->VrfNotifyWait(2));
EXPECT_TRUE(DBTableFind("vrf1.uc.route.0"));
EXPECT_TRUE(RouteFind("vrf1", vm1_ip, 32));
EXPECT_TRUE(RouteFind("vrf1", vm2_ip, 32));
WAIT_FOR(100, 10000, PathCount("vrf1", vm1_ip, 32) == 2);
WAIT_FOR(100, 10000, PathCount("vrf1", vm2_ip, 32) == 2);
//Interface still present
DeleteVmportEnv(input, 2, true);
WAIT_FOR(100, 10000, (VrfFind("vrf1") == false));
client->WaitForIdle();
EXPECT_FALSE(DBTableFind("vrf1.uc.route.0"));
}
TEST_F(VrfTest, VrfAddDelWithNoRoutes_1) {
AddVrf("vrf10");
client->WaitForIdle();
WAIT_FOR(100, 10000, (VrfFind("vrf10") == true));
DelVrf("vrf10");
WAIT_FOR(100, 10000, (VrfFind("vrf10") == false));
EXPECT_FALSE(DBTableFind("vrf10.route.0"));
}
TEST_F(VrfTest, CheckDefaultVrfDelete) {
AddVrf(Agent::GetInstance()->fabric_vrf_name().c_str());
client->WaitForIdle();
EXPECT_TRUE(VrfFind(Agent::GetInstance()->fabric_vrf_name().c_str()));
DelVrf(Agent::GetInstance()->fabric_vrf_name().c_str());
client->WaitForIdle();
EXPECT_TRUE(VrfFind(Agent::GetInstance()->fabric_vrf_name().c_str()));
}
TEST_F(VrfTest, CheckTableDeleteAndEntryDelete) {
// Vrf route table and entry have to deleted
// at same time, as we may get some pending route
// input after route delete is done
AddVrf("vrf1");
client->WaitForIdle();
EXPECT_TRUE(VrfFind("vrf1"));
EXPECT_TRUE(DBTableFind("vrf1.uc.route.0"));
//Acquire a refernece to vrf1 to delay vrf deletion
VrfEntryRef vrf_ref = VrfGet("vrf1");
DelVrf("vrf1");
client->WaitForIdle();
VrfKey key("vrf1");
EXPECT_TRUE(Agent::GetInstance()->vrf_table()->Find(&key, true));
EXPECT_TRUE(DBTableFind("vrf1.uc.route.0"));
//Release pending reference on vrf
vrf_ref = NULL;
client->WaitForIdle();
EXPECT_FALSE(VrfFind("vrf1"));
EXPECT_FALSE(DBTableFind("vrf1.uc.route.0"));
}
TEST_F(VrfTest, CheckVrfReuse) {
VrfEntry *vrf = NULL;
//Add a vrf config
AddVrf("vrf1", 1);
client->WaitForIdle();
EXPECT_TRUE(VrfFind("vrf1"));
EXPECT_TRUE(DBTableFind("vrf1.uc.route.0"));
//Acquire a refernece to vrf1 to delay vrf deletion
VrfEntryRef vrf_ref = VrfGet("vrf1");
DelVrf("vrf1");
client->WaitForIdle();
VrfKey key("vrf1");
vrf = static_cast<VrfEntry *>(Agent::GetInstance()->vrf_table()->Find(&key, true));
EXPECT_TRUE(vrf->IsDeleted());
EXPECT_TRUE(DBTableFind("vrf1.uc.route.0"));
AddVrf("vrf1", 1);
//Release VRF reference
vrf_ref = NULL;
client->WaitForIdle();
vrf = VrfGet("vrf1");
EXPECT_FALSE(vrf->IsDeleted());
EXPECT_TRUE(DBTableFind("vrf1.uc.route.0"));
DelVrf("vrf1");
client->WaitForIdle();
EXPECT_FALSE(VrfFind("vrf1"));
EXPECT_FALSE(DBTableFind("vrf1.uc.route.0"));
}
TEST_F(VrfTest, CheckIntfActivate) {
//Add couple of interface in a VRF
client->Reset();
struct PortInfo input[] = {
{"vnet1", 1, "1.1.1.1", "00:00:00:01:01:01", 1, 1},
{"vnet2", 2, "1.1.1.2", "00:00:00:02:02:02", 1, 2},
};
Ip4Address vm1_ip = Ip4Address::from_string(input[0].addr);
Ip4Address vm2_ip = Ip4Address::from_string(input[1].addr);
CreateVmportEnv(input, 2);
client->WaitForIdle();
EXPECT_TRUE(client->VrfNotifyWait(2));
EXPECT_TRUE(DBTableFind("vrf1.uc.route.0"));
EXPECT_TRUE(RouteFind("vrf1", vm1_ip, 32));
EXPECT_TRUE(RouteFind("vrf1", vm2_ip, 32));
VrfEntryRef vrf_ref = VrfGet("vrf1");
DeleteVmportEnv(input, 2, true);
client->WaitForIdle();
//Vrf is pending delete, due to reference
//Re-add the vmport and since VRF link is
//not parsed the interface should be inactive
CreateVmportEnv(input, 2);
client->WaitForIdle();
EXPECT_FALSE(VmPortActive(input, 0) == true);
EXPECT_FALSE(VmPortActive(input, 1) == true);
EXPECT_FALSE(RouteFind("vrf1", vm1_ip, 32));
EXPECT_FALSE(RouteFind("vrf1", vm2_ip, 32));
//Release reference to VRF, and expect interface
//to be active
vrf_ref = NULL;
client->WaitForIdle();
EXPECT_TRUE(VmPortActive(input, 0) == true);
EXPECT_TRUE(VmPortActive(input, 1) == true);
EXPECT_TRUE(RouteFind("vrf1", vm1_ip, 32));
EXPECT_TRUE(RouteFind("vrf1", vm2_ip, 32));
DeleteVmportEnv(input, 2, true);
client->WaitForIdle();
}
TEST_F(VrfTest, FloatingIpRouteWithdraw) {
client->Reset();
struct PortInfo input[] = {
{"vnet1", 1, "1.1.1.1", "00:00:00:01:01:01", 1, 1},
{"vnet2", 2, "1.1.1.2", "00:00:00:02:02:02", 2, 2},
};
Ip4Address vm1_ip = Ip4Address::from_string(input[0].addr);
Ip4Address vm2_ip = Ip4Address::from_string(input[1].addr);
CreateVmportFIpEnv(input, 2);
client->WaitForIdle();
EXPECT_TRUE(client->VrfNotifyWait(4));
EXPECT_TRUE(DBTableFind("default-project:vn1:vn1.uc.route.0"));
EXPECT_TRUE(RouteFind("default-project:vn1:vn1", vm1_ip, 32));
EXPECT_TRUE(DBTableFind("default-project:vn2:vn2.uc.route.0"));
EXPECT_TRUE(RouteFind("default-project:vn2:vn2", vm2_ip, 32));
//Add floating IP for vm2 to talk to vm1
AddFloatingIpPool("fip-pool1", 1);
AddFloatingIp("fip1", 1, "2.1.1.100");
AddLink("floating-ip", "fip1", "floating-ip-pool", "fip-pool1");
AddLink("floating-ip-pool", "fip-pool1", "virtual-network",
"default-project:vn1");
client->WaitForIdle();
AddLink("virtual-machine-interface", "vnet2", "floating-ip", "fip1");
client->WaitForIdle();
Ip4Address floating_ip = Ip4Address::from_string("2.1.1.100");
EXPECT_TRUE(RouteFind("default-project:vn1:vn1", floating_ip, 32));
WAIT_FOR(100, 10000,
PathCount("default-project:vn1:vn1", floating_ip, 32) == 2);
//Delete floating IP and expect route to get deleted
DelLink("floating-ip", "fip1", "floating-ip-pool", "fip-pool1");
DelLink("floating-ip-pool", "fip-pool1", "virtual-network",
"default-project:vn1");
DelLink("virtual-machine-interface", "vnet2", "floating-ip", "fip1");
DelFloatingIp("fip1");
client->WaitForIdle();
WAIT_FOR(100, 1000,
RouteFind("default-project:vn1:vn1",floating_ip, 32) == false);
DeleteVmportFIpEnv(input, 2, true);
client->WaitForIdle();
}
TEST_F(VrfTest, DelReqonDeletedVrfRouteTable) {
client->Reset();
VrfAddReq("vrf1");
EXPECT_TRUE(client->VrfNotifyWait(1));
client->WaitForIdle();
// take reference of vrf entry
VrfEntryRef vrf_ref = VrfGet("vrf1");
VrfDelReq("vrf1");
client->WaitForIdle();
WAIT_FOR(1000, 1000, vrf_ref->IsDeleted());
// once vrf is deleted enqueue a del request for route
MacAddress mac("00:00:00:01:00:01");
Ip4Address zero_ip;
EvpnAgentRouteTable::DeleteReq(Agent::GetInstance()->local_peer(),
std::string("vrf1"),
mac, zero_ip, 0, NULL);
client->WaitForIdle();
// release the VRF reference
vrf_ref = NULL;
}
//Test case for bug #1580733
//If route ADD is notified to ksync after route ksync object
//is notified, ksyncobject would unregister from table before
//all the states are cleared
TEST_F(VrfTest, AddReqonDeletedVrfRouteTable) {
client->Reset();
VrfAddReq("vrf1");
EXPECT_TRUE(client->VrfNotifyWait(1));
client->WaitForIdle();
// take reference of vrf entry
VrfEntryRef vrf_ref = VrfGet("vrf1");
vrf_ref->set_allow_route_add_on_deleted_vrf(true);
VrfDelReq("vrf1");
Ip4Address vip(0);
Ip4Address server_ip(0);
Inet4TunnelRouteAdd(agent->local_peer(), "vrf1", vip, 32,
server_ip, TunnelType::AllType(),
16, "vn1", SecurityGroupList(), PathPreference());
client->WaitForIdle();
agent->fabric_inet4_unicast_table()->DeleteReq(agent->local_peer(), "vrf1",
vip, 32, NULL);
client->WaitForIdle();
// release the VRF reference
vrf_ref = NULL;
client->WaitForIdle();
EXPECT_TRUE(VrfFind("vrf1", true) == false);
}
int main(int argc, char **argv) {
GETUSERARGS();
client = TestInit(init_file, ksync_init, false, true, false);
int ret = RUN_ALL_TESTS();
client->WaitForIdle();
ShutdownAgentController(Agent::GetInstance());
Agent::GetInstance()->event_manager()->Shutdown();
client->WaitForIdle();
TestShutdown();
delete client;
return ret;
}