/
test_flow_mgmt_route.cc
448 lines (369 loc) · 15.5 KB
/
test_flow_mgmt_route.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
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
/*
* Copyright (c) 2015 Juniper Networks, Inc. All rights reserved.
*/
#include <netinet/in.h>
#include "base/os.h"
#include "test/test_cmn_util.h"
#include "test_flow_util.h"
#include "ksync/ksync_sock_user.h"
#include "oper/tunnel_nh.h"
#include "pkt/flow_mgmt.h"
#include "pkt/flow_mgmt_dbclient.h"
#include <algorithm>
#define vm1_ip "1.1.1.1"
#define vm2_ip "1.1.1.2"
struct PortInfo input[] = {
{"vif0", 1, vm1_ip, "00:00:00:01:01:01", 1, 1},
{"vif1", 2, vm2_ip, "00:00:00:01:01:02", 1, 2},
};
class FlowMgmtRouteTest : public ::testing::Test {
public:
FlowMgmtRouteTest() : peer_(NULL), agent_(Agent::GetInstance()) {
flow_proto_ = agent_->pkt()->get_flow_proto();
flow_mgmt_ = agent_->pkt()->flow_mgmt_manager();
flow_mgmt_dbclient_ = flow_mgmt_->flow_mgmt_dbclient();
eth = EthInterfaceGet("vnet0");
EXPECT_TRUE(eth != NULL);
}
void FlushFlowTable() {
client->EnqueueFlowFlush();
client->WaitForIdle();
WAIT_FOR(100, 100, (flow_proto_->FlowCount() == 0));
}
protected:
virtual void SetUp() {
WAIT_FOR(100, 100, (flow_proto_->FlowCount() == 0));
client->Reset();
CreateVmportEnv(input, 2, 1);
client->WaitForIdle(5);
EXPECT_TRUE(VmPortActive(input, 0));
EXPECT_TRUE(VmPortActive(input, 1));
vif0 = VmInterfaceGet(input[0].intf_id);
assert(vif0);
vif1 = VmInterfaceGet(input[1].intf_id);
assert(vif1);
client->WaitForIdle();
peer_ = CreateBgpPeer(Ip4Address(1), "BGP Peer 1");
client->WaitForIdle();
}
virtual void TearDown() {
FlushFlowTable();
client->Reset();
DeleteVmportEnv(input, 2, true, 1);
client->WaitForIdle(3);
EXPECT_FALSE(VmPortFind(input, 0));
EXPECT_FALSE(VmPortFind(input, 1));
EXPECT_EQ(0U, agent()->vm_table()->Size());
EXPECT_EQ(0U, agent()->vn_table()->Size());
EXPECT_EQ(0U, agent()->acl_table()->Size());
DeleteBgpPeer(peer_);
}
int CreateMpls(int tag) {
int label = agent_->mpls_table()->AllocLabel();
MplsLabel::CreateVlanNh(agent_, label, MakeUuid(100), tag);
return label;
}
void DeleteMpls(unsigned long label) {
MplsLabel::DeleteReq(agent_, label);
}
void CreateTunnelNH(unsigned long addr) {
TunnelType::TypeBmap bmap = TunnelType::AllType();
DBRequest req(DBRequest::DB_ENTRY_ADD_CHANGE);
req.key.reset(new TunnelNHKey(agent_->fabric_vrf_name(),
agent_->router_id(),
Ip4Address(addr),
true, TunnelType::ComputeType(bmap)));
req.data.reset(new TunnelNHData());
Agent::GetInstance()->nexthop_table()->Enqueue(&req);
}
void DeleteTunnelNH(unsigned long addr) {
TunnelType::TypeBmap bmap = TunnelType::AllType();
DBRequest req(DBRequest::DB_ENTRY_DELETE);
req.key.reset(new TunnelNHKey(agent_->fabric_vrf_name(),
agent_->router_id(),
Ip4Address(addr),
true, TunnelType::ComputeType(bmap)));
req.data.reset(new TunnelNHData());
Agent::GetInstance()->nexthop_table()->Enqueue(&req);
}
FlowMgmtManager *flow_mgmt() {return flow_mgmt_;}
Agent *agent() {return agent_;}
protected:
BgpPeer *peer_;
Agent *agent_;
FlowProto *flow_proto_;
FlowMgmtManager *flow_mgmt_;
FlowMgmtDbClient *flow_mgmt_dbclient_;
VmInterface *vif0;
VmInterface *vif1;
PhysicalInterface *eth;
};
TEST_F(FlowMgmtRouteTest, RouteDelete_1) {
EXPECT_EQ(0U, flow_proto_->FlowCount());
boost::system::error_code ec;
Ip4Address remote_subnet = Ip4Address::from_string("10.10.10.0", ec);
Ip4Address remote_ip = Ip4Address::from_string("10.10.10.1", ec);
Ip4Address remote_compute = Ip4Address::from_string("1.1.1.1", ec);
string vrf_name = vif0->vrf()->GetName();
string vn_name = vif0->vn()->GetName();
Inet4TunnelRouteAdd(peer_, vrf_name, remote_subnet, 24, remote_compute,
TunnelType::AllType(), 10, vn_name, SecurityGroupList(),
PathPreference());
client->WaitForIdle();
char router_id[80];
strcpy(router_id, Agent::GetInstance()->router_id().to_string().c_str());
TxIpMplsPacket(eth->id(), remote_compute.to_string().c_str(),
router_id, vif0->label(), remote_ip.to_string().c_str(),
vm1_ip, 1, 1);
client->WaitForIdle();
uint32_t vrf_id = vif0->vrf_id();
FlowEntry *flow = FlowGet(vrf_id, remote_ip.to_string().c_str(),
vm1_ip, 1, 0, 0, vif0->flow_key_nh()->id());
EXPECT_TRUE(flow != NULL);
InetUnicastRouteKey key(peer_, vrf_name, remote_subnet, 24);
InetUnicastAgentRouteTable *table =
vif0->vrf()->GetInet4UnicastRouteTable();
AgentRoute *rt = table->FindRoute(remote_ip);
flow_mgmt_->DeleteDBEntryEvent(rt, 0xFFFFFFFF);
client->WaitForIdle();
DeleteRoute(vrf_name.c_str(), remote_subnet.to_string().c_str(), 24, peer_);
}
TEST_F(FlowMgmtRouteTest, RouteDelete_2) {
EXPECT_EQ(0U, flow_proto_->FlowCount());
boost::system::error_code ec;
Ip4Address remote_subnet = Ip4Address::from_string("10.10.10.0", ec);
Ip4Address remote_ip = Ip4Address::from_string("10.10.10.1", ec);
Ip4Address remote_compute = Ip4Address::from_string("1.1.1.1", ec);
string vrf_name = vif0->vrf()->GetName();
string vn_name = vif0->vn()->GetName();
Inet4TunnelRouteAdd(peer_, vrf_name, remote_subnet, 24, remote_compute,
TunnelType::AllType(), 10, vn_name, SecurityGroupList(),
PathPreference());
client->WaitForIdle();
char router_id[80];
strcpy(router_id, Agent::GetInstance()->router_id().to_string().c_str());
TxIpMplsPacket(eth->id(), remote_compute.to_string().c_str(),
router_id, vif0->label(), remote_ip.to_string().c_str(),
vm1_ip, 1, 1);
client->WaitForIdle();
uint32_t vrf_id = vif0->vrf_id();
FlowEntry *flow = FlowGet(vrf_id, remote_ip.to_string().c_str(),
vm1_ip, 1, 0, 0, vif0->flow_key_nh()->id());
EXPECT_TRUE(flow != NULL);
InetUnicastRouteKey key(peer_, vrf_name, remote_subnet, 24);
InetUnicastAgentRouteTable *table =
vif0->vrf()->GetInet4UnicastRouteTable();
AgentRoute *rt = table->FindRoute(remote_ip);
RevFlowDepParams params;
flow_mgmt_->DeleteEvent(flow, params);
client->WaitForIdle();
flow_mgmt_->DeleteDBEntryEvent(rt, 0xFFFFFFFF);
client->WaitForIdle();
DeleteRoute(vrf_name.c_str(), remote_subnet.to_string().c_str(), 24, peer_);
}
TEST_F(FlowMgmtRouteTest, RouteDelete_3) {
EXPECT_EQ(0U, flow_proto_->FlowCount());
boost::system::error_code ec;
Ip4Address remote_subnet = Ip4Address::from_string("10.10.10.0", ec);
Ip4Address remote_ip = Ip4Address::from_string("10.10.10.1", ec);
Ip4Address remote_compute = Ip4Address::from_string("1.1.1.1", ec);
string vrf_name = vif0->vrf()->GetName();
string vn_name = vif0->vn()->GetName();
Inet4TunnelRouteAdd(peer_, vrf_name, remote_subnet, 24, remote_compute,
TunnelType::AllType(), 10, vn_name, SecurityGroupList(),
PathPreference());
client->WaitForIdle();
char router_id[80];
strcpy(router_id, Agent::GetInstance()->router_id().to_string().c_str());
TxIpMplsPacket(eth->id(), remote_compute.to_string().c_str(),
router_id, vif0->label(), remote_ip.to_string().c_str(),
vm1_ip, 1, 1);
client->WaitForIdle();
uint32_t vrf_id = vif0->vrf_id();
FlowEntry *flow = FlowGet(vrf_id, remote_ip.to_string().c_str(),
vm1_ip, 1, 0, 0, vif0->flow_key_nh()->id());
EXPECT_TRUE(flow != NULL);
RevFlowDepParams params;
flow_mgmt_->DeleteEvent(flow, params);
client->WaitForIdle();
DeleteRoute(vrf_name.c_str(), remote_subnet.to_string().c_str(), 24, peer_);
client->WaitForIdle();
}
TEST_F(FlowMgmtRouteTest, RouteDelete_4) {
EXPECT_EQ(0U, flow_proto_->FlowCount());
boost::system::error_code ec;
Ip4Address remote_subnet = Ip4Address::from_string("10.10.10.0", ec);
Ip4Address remote_ip = Ip4Address::from_string("10.10.10.1", ec);
Ip4Address remote_compute = Ip4Address::from_string("1.1.1.1", ec);
char router_id[80];
strcpy(router_id, Agent::GetInstance()->router_id().to_string().c_str());
string vrf_name = vif0->vrf()->GetName();
string vn_name = vif0->vn()->GetName();
Inet4TunnelRouteAdd(peer_, vrf_name, remote_subnet, 24, remote_compute,
TunnelType::AllType(), 10, vn_name, SecurityGroupList(),
PathPreference());
client->WaitForIdle();
TxIpMplsPacket(eth->id(), remote_compute.to_string().c_str(),
router_id, vif0->label(), remote_ip.to_string().c_str(),
vm1_ip, 1, 1);
client->WaitForIdle();
FlowEntry *flow = FlowGet(vif0->vrf_id(), remote_ip.to_string().c_str(),
vm1_ip, 1, 0, 0, vif0->flow_key_nh()->id());
EXPECT_TRUE(flow != NULL);
FlowMgmtManager *mgr = agent_->pkt()->flow_mgmt_manager();
flow_proto_->DisableFlowEventQueue(0, true);
VrfDelReq("vrf1");
client->WaitForIdle(10);
RevFlowDepParams params;
flow_proto_->DisableFlowUpdateQueue(true);
flow_mgmt_->DeleteEvent(flow, params);
flow_mgmt_->DeleteEvent(flow->reverse_flow_entry(), params);
flow_mgmt_->AddEvent(flow);
flow_mgmt_->AddEvent(flow->reverse_flow_entry());
client->WaitForIdle();
DeleteVmportEnv(input, 3, true, 1);
client->WaitForIdle(3);
flow_proto_->DisableFlowUpdateQueue(false);
mgr->DisableWorkQueue(false);
client->WaitForIdle(10);
flow_proto_->DisableFlowEventQueue(0, false);
client->WaitForIdle(10);
}
TEST_F(FlowMgmtRouteTest, RouteDelete_5) {
VrfAddReq("vrf10");
client->WaitForIdle();
boost::system::error_code ec;
Ip4Address remote_ip1 = Ip4Address::from_string("0.0.0.0", ec);
Ip4Address remote_compute = Ip4Address::from_string("1.1.1.1", ec);
char router_id[80];
strcpy(router_id, Agent::GetInstance()->router_id().to_string().c_str());
string vn_name = "vn10";
Inet4TunnelRouteAdd(agent_->local_peer(), "vrf10", remote_ip1, 0,
remote_compute, TunnelType::AllType(), 10,
vn_name, SecurityGroupList(),
PathPreference());
Inet4TunnelRouteAdd(agent_->local_peer(), "vrf10", remote_compute, 24,
remote_compute, TunnelType::AllType(), 10,
vn_name, SecurityGroupList(), PathPreference());
client->WaitForIdle();
VrfDelReq("vrf10");
client->WaitForIdle();
DeleteRoute("vrf10", "1.1.1.1", 24, agent_->local_peer());
client->WaitForIdle();
DeleteRoute("vrf10", "0.0.0.0", 0, agent_->local_peer());
client->WaitForIdle();
}
TEST_F(FlowMgmtRouteTest, RouteAddDelete_6) {
VrfAddReq("vrf10");
client->WaitForIdle();
boost::system::error_code ec;
Ip4Address remote_compute = Ip4Address::from_string("1.1.1.1", ec);
char router_id[80];
strcpy(router_id, Agent::GetInstance()->router_id().to_string().c_str());
//uint32_t id = VrfGet("vrf10")->vrf_id();
string vn_name = "vn10";
for (uint32_t i = 1; i < 100; i++) {
Ip4Address ip(i);
Inet4TunnelRouteAdd(agent_->local_peer(), "vrf10",
ip, 32,
remote_compute, TunnelType::AllType(), 10,
vn_name, SecurityGroupList(),
PathPreference());
client->WaitForIdle();
}
flow_mgmt_->FlowUpdateQueueDisable(true);
for (uint32_t i = 0; i < 100; i++) {
Ip4Address ip(i);
DeleteRoute("vrf10", ip.to_string().c_str(), 32, agent_->local_peer());
client->WaitForIdle();
}
// Enable flow-mgmt queue
flow_mgmt_->FlowUpdateQueueDisable(false);
Agent::GetInstance()->vrf_table()->DeleteVrfReq("vrf10");
WAIT_FOR(1000, 1000, (flow_mgmt_->FlowUpdateQueueLength() == 0));
WAIT_FOR(1000, 10000, (VrfFind("vrf10", true) == false));
}
////////////////////////////////////////////////////////////////////////////
// UT for bug 1551577
// Simulate the following scenario,
// 1. Delete a DBEntry and enqueue DELETE_DBENTRY event
// 2. Renew the DBEntry and enqueue ADD_DBENTRY
// 3. Delete the DBEntry and not notify DELETE
// 4. Process the DELETE_DBENTRY in (1)
// 5. Free DBState
// 6. Process the DELETE in (3) and let the DBEntry get freed
// 7. Process the ADD_DBENTRY from (2).
// Agent asserts since its trying to process deleted DBEntry
////////////////////////////////////////////////////////////////////////////
TEST_F(FlowMgmtRouteTest, DB_Entry_Reuse) {
#define vm3_ip "1.1.1.3"
unsigned long addr = Ip4Address::from_string("100.100.100.1").to_ulong();
// Create TunnelNH
CreateTunnelNH(addr);
client->WaitForIdle();
// Create some MPLS Labels. They will be used to delay the DB-notification
// in later stages
ConcurrencyScope scope("db::DBTable");
int label_list[2000];
// Enqueue requests into flow-mgmt queue
for (int i = 100; i < 1000; i++) {
label_list[i] = CreateMpls(i);
}
client->WaitForIdle();
WAIT_FOR(100, 1000, (flow_mgmt_->FlowUpdateQueueLength() == 0));
// Disable flow-management queue
flow_mgmt_->FlowUpdateQueueDisable(true);
// Delete the NH. This should trigger clear of DBState
DeleteTunnelNH(addr);
client->WaitForIdle();
// Make dummy enqueues so that subsequent operation on tunnel-nh are
// delayed
for (int i = 0; i < 100000; i++) {
flow_mgmt_->DummyEvent();
}
// Revoke the tunnel-nh and delete it again
CreateTunnelNH(addr);
client->WaitForIdle();
DeleteTunnelNH(addr);
// Delay notification tunnel-nh creation above to ensure the DBState
// for NH is cleared by flow-mgmt module
for (int i = 100; i < 1000; i++) {
DeleteMpls(label_list[i]);
}
// Enable flow-mgmt queue
flow_mgmt_->FlowUpdateQueueDisable(false);
WAIT_FOR(1000, 1000, (flow_mgmt_->FlowUpdateQueueLength() == 0));
}
TEST_F(FlowMgmtRouteTest, FlowEntry_dbstate_1) {
EXPECT_EQ(0U, flow_proto_->FlowCount());
boost::system::error_code ec;
Ip4Address remote_subnet = Ip4Address::from_string("10.10.10.0", ec);
Ip4Address remote_compute = Ip4Address::from_string("1.1.1.100", ec);
string vrf_name = vif0->vrf()->GetName();
string vn_name = vif0->vn()->GetName();
Inet4TunnelRouteAdd(agent_->local_peer(), "vrf1", remote_subnet, 24, remote_compute,
TunnelType::AllType(), 10, vn_name, SecurityGroupList(),
PathPreference());
client->WaitForIdle();
VrfEntry *vrf = VrfGet("vrf1");
agent_->vrf_table()->DeleteVrfReq("vrf1", 0xFF);
client->WaitForIdle();
flow_mgmt_dbclient_->FreeVrfState(vrf, 0xFFFFFFFF);
client->WaitForIdle();
//Time for final cleanup
DelVrf("vrf1");
client->WaitForIdle();
DeleteRoute(vrf_name.c_str(), remote_subnet.to_string().c_str(), 24,
agent_->local_peer());
client->WaitForIdle();
}
int main(int argc, char *argv[]) {
int ret = 0;
GETUSERARGS();
client = TestInit(init_file, ksync_init, true, true, true, 100*1000);
ret = RUN_ALL_TESTS();
usleep(100000);
TestShutdown();
delete client;
return ret;
}