/
test_vrf_assign_acl.cc
587 lines (528 loc) · 23.8 KB
/
test_vrf_assign_acl.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
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#include "base/os.h"
#include "test/test_cmn_util.h"
#include "test_flow_util.h"
void RouterIdDepInit(Agent *agent) {
}
struct PortInfo input[] = {
{"intf1", 1, "1.1.1.1", "00:00:00:01:01:01", 1, 1},
{"intf2", 2, "1.1.1.2", "00:00:00:01:01:02", 1, 2},
};
IpamInfo ipam_info1[] = {
{"1.1.1.0", 24, "1.1.1.10", true},
};
struct PortInfo input1[] = {
{"intf3", 3, "2.1.1.1", "00:00:00:01:01:01", 2, 3},
{"intf4", 4, "2.1.1.2", "00:00:00:01:01:02", 2, 4},
};
IpamInfo ipam_info2[] = {
{"2.1.1.0", 24, "2.1.1.10", true},
};
struct PortInfo input2[] = {
{"intf5", 5, "2.1.1.1", "00:00:00:01:01:01", 3, 5},
{"intf6", 6, "2.1.1.2", "00:00:00:01:01:02", 3, 6},
};
IpamInfo ipam_info3[] = {
{"2.1.1.0", 24, "2.1.1.10", true},
};
class TestVrfAssignAclFlow : public ::testing::Test {
protected:
virtual void SetUp() {
agent_ = Agent::GetInstance();
flow_proto_ = agent_->pkt()->get_flow_proto();
EXPECT_EQ(0U, flow_proto_->FlowCount());
CreateVmportFIpEnv(input, 2);
CreateVmportFIpEnv(input1, 2);
CreateVmportFIpEnv(input2, 2);
client->WaitForIdle();
AddIPAM("default-project:vn1", ipam_info1, 1);
AddIPAM("default-project:vn2", ipam_info2, 1);
AddIPAM("default-project:vn3", ipam_info3, 1);
client->WaitForIdle();
EXPECT_TRUE(VmPortActive(1));
EXPECT_TRUE(VmPortActive(2));
EXPECT_TRUE(VmPortActive(3));
EXPECT_TRUE(VmPortActive(4));
EXPECT_TRUE(VmPortActive(5));
EXPECT_TRUE(VmPortActive(6));
client->WaitForIdle();
//Leak route for 1.1.1.0 to default-project:vn2:vn2 and
//default-project:vn3:vn3
VnListType vn_list;
vn_list.insert(std::string("default-project:vn1"));
Ip4Address ip2 = Ip4Address::from_string("1.1.1.0");
agent_->fabric_inet4_unicast_table()->
AddLocalVmRouteReq(agent_->local_peer(),
"default-project:vn2:vn2", ip2, 24, MakeUuid(1),
vn_list,
16, SecurityGroupList(),
CommunityList(), false,
PathPreference(), Ip4Address(0),
EcmpLoadBalance(), false, false);
agent_->fabric_inet4_unicast_table()->
AddLocalVmRouteReq(agent_->local_peer(),
"default-project:vn3:vn3", ip2, 24, MakeUuid(1),
vn_list,
16, SecurityGroupList(),
CommunityList(), false,
PathPreference(), Ip4Address(0),
EcmpLoadBalance(), false, false);
client->WaitForIdle();
}
virtual void TearDown() {
Ip4Address ip1 = Ip4Address::from_string("2.1.1.0");
agent_->fabric_inet4_unicast_table()->DeleteReq(
agent_->local_peer(), "default-project:vn1:vn1", ip1, 24, NULL);
Ip4Address ip2 = Ip4Address::from_string("1.1.1.0");
agent_->fabric_inet4_unicast_table()->DeleteReq(
agent_->local_peer(), "default-project:vn2:vn2", ip2, 24, NULL);
agent_->fabric_inet4_unicast_table()->DeleteReq(
agent_->local_peer(), "default-project:vn3:vn3", ip2, 24, NULL);
client->WaitForIdle();
DeleteVmportFIpEnv(input, 2, true);
DeleteVmportFIpEnv(input1, 2, true);
DeleteVmportFIpEnv(input2, 2, true);
DelIPAM("default-project:vn1");
DelIPAM("default-project:vn2");
DelIPAM("default-project:vn3");
client->WaitForIdle();
WAIT_FOR(1000, 1000, (0U == flow_proto_->FlowCount()));
EXPECT_FALSE(VmPortFindRetDel(1));
EXPECT_FALSE(VmPortFindRetDel(2));
client->WaitForIdle();
EXPECT_FALSE(VmPortFindRetDel(3));
EXPECT_FALSE(VmPortFindRetDel(4));
EXPECT_FALSE(VmPortFindRetDel(5));
EXPECT_FALSE(VmPortFindRetDel(6));
EXPECT_EQ(0U, flow_proto_->FlowCount());
}
Agent *agent_;
FlowProto *flow_proto_;
};
//Add an VRF translate ACL to send all ssh traffic to "2.1.1.1"
//via default-project:vn2
TEST_F(TestVrfAssignAclFlow, VrfAssignAcl1) {
AddAddressVrfAssignAcl("intf1", 1, "1.1.1.0", "2.1.1.0", 6, 1, 65535,
1, 65535, "default-project:vn2:vn2", "true");
TestFlow flow[] = {
{ TestFlowPkt(Address::INET, "1.1.1.1", "2.1.1.1", IPPROTO_TCP, 10, 20,
"default-project:vn1:vn1", VmPortGet(1)->id()),
{
new VerifyVn("default-project:vn1", "default-project:vn2"),
new VerifyAction((1 << TrafficAction::PASS) |
(1 << TrafficAction::VRF_TRANSLATE),
(1 << TrafficAction::PASS))
}
}
};
CreateFlow(flow, 1);
}
//Add an VRF tranlsate ACL to send all traffic destined to "2.1.1.1"
//via default-project:vn3
TEST_F(TestVrfAssignAclFlow, VrfAssignAcl2) {
AddAddressVrfAssignAcl("intf1", 1, "1.1.1.0", "2.1.1.0", 6, 1, 65535,
1, 65535, "default-project:vn3:vn3", "true");
TestFlow flow[] = {
{ TestFlowPkt(Address::INET, "1.1.1.1", "2.1.1.1", IPPROTO_TCP, 10, 20,
"default-project:vn1:vn1", VmPortGet(1)->id()),
{
new VerifyVn("default-project:vn1", "default-project:vn3"),
new VerifyAction((1 << TrafficAction::PASS) |
(1 << TrafficAction::VRF_TRANSLATE),
(1 << TrafficAction::PASS))
}
}
};
CreateFlow(flow, 1);
}
//Add an VRF translate ACL to send all ssh traffic to "2.1.1.1" via VN4
//which is not present, make sure flow is marked as short flow
TEST_F(TestVrfAssignAclFlow, VrfAssignAcl3) {
client->agent()->flow_stats_manager()->set_delete_short_flow(false);
//Leak route for 2.1.1.0 to default-project:vn1:vn1
Ip4Address ip1 = Ip4Address::from_string("2.1.1.0");
VnListType vn_list;
vn_list.insert(std::string("default-project:vn2"));
agent_->fabric_inet4_unicast_table()->
AddLocalVmRouteReq(agent_->local_peer(),
"default-project:vn1:vn1", ip1, 24, MakeUuid(3),
vn_list, 16, SecurityGroupList(),
CommunityList(), false,
PathPreference(), Ip4Address(0), EcmpLoadBalance(),
false, false);
AddAddressVrfAssignAcl("intf1", 1, "1.1.1.0", "2.1.1.0", 6, 1, 65535,
1, 65535, "vrf4", "true");
TestFlow flow[] = {
{ TestFlowPkt(Address::INET, "1.1.1.1", "2.1.1.1", IPPROTO_TCP, 10, 20,
"default-project:vn1:vn1", VmPortGet(1)->id()),
{
new ShortFlow()
}
}
};
CreateFlow(flow, 1);
int nh_id = InterfaceTable::GetInstance()->FindInterface(VmPortGet(1)->id())->flow_key_nh()->id();
FlowEntry *fe = FlowGet(1, "1.1.1.1", "2.1.1.1", IPPROTO_TCP,
10, 20, nh_id);
EXPECT_TRUE(fe != NULL && fe->is_flags_set(FlowEntry::ShortFlow) == true &&
fe->short_flow_reason() == FlowEntry::SHORT_NO_SRC_ROUTE);
client->agent()->flow_stats_manager()->set_delete_short_flow(true);
}
//Add a VRF translate ACL to send all ssh traffic to "2.1.1.1"
//via default-project:vn2 with ignore acl option set, add an ACL
//to deny all traffic from default-project:vn1 to default-project:vn2
TEST_F(TestVrfAssignAclFlow, VrfAssignAcl4) {
AddAcl("Acl", 10, "default-project:vn1", "default-project:vn2", "deny");
AddLink("virtual-network", "default-project:vn1", "access-control-list", "Acl");
AddAddressVrfAssignAcl("intf1", 1, "1.1.1.0", "2.1.1.0", 6, 1, 65535,
1, 65535, "default-project:vn2:vn2", "false");
client->WaitForIdle();
TestFlow flow[] = {
{ TestFlowPkt(Address::INET, "1.1.1.1", "2.1.1.1", IPPROTO_TCP, 10, 20,
"default-project:vn1:vn1", VmPortGet(1)->id()),
{
new VerifyVn("default-project:vn1", "default-project:vn2"),
new VerifyAction((1 << TrafficAction::DENY) |
(1 << TrafficAction::VRF_TRANSLATE),
(1 << TrafficAction::DENY))
}
}
};
CreateFlow(flow, 1);
DelLink("virtual-network", "default-project:vn1", "access-control-list", "Acl");
DelAcl("Acl");
}
//Add a SG acl to deny traffic from 1.1.1.0/24 subnet to 2.2.2.0/24
//and ensure it get applied
TEST_F(TestVrfAssignAclFlow, VrfAssignAcl5) {
AddAcl("egress-access-control-list-Acl", 10, "default-project:vn1",
"default-project:vn2", "deny");
AddSg("sg1", 1);
AddLink("security-group", "sg1", "access-control-list",
"egress-access-control-list-Acl");
AddLink("virtual-machine-interface", "intf1", "security-group", "sg1");
AddAddressVrfAssignAcl("intf1", 1, "1.1.1.0", "2.1.1.0", 6, 1, 65535,
1, 65535, "default-project:vn2:vn2", "true");
client->WaitForIdle();
TestFlow flow[] = {
{ TestFlowPkt(Address::INET, "1.1.1.1", "2.1.1.1", IPPROTO_TCP, 10, 20,
"default-project:vn1:vn1", VmPortGet(1)->id()),
{
new VerifyVn("default-project:vn1", "default-project:vn2"),
new VerifyAction((1 << TrafficAction::DENY) |
(1 << TrafficAction::VRF_TRANSLATE),
(1 << TrafficAction::DENY))
}
}
};
CreateFlow(flow, 1);
DelLink("virtual-machine-interface", "intf1", "security-group", "sg1");
DelLink("security-group", "sg1", "access-control-list",
"egress-access-control-list-Acl");
DelNode("security-group", "sg1");
DelAcl("egress-access-control-list-Acl");
}
//Send MplsoUdp packet to 1.1.1.1 from 3.1.1.1
//Assume packet from 3.1.1.1 is routed via SI on remote server
//Verify that RPF information is setup properly
TEST_F(TestVrfAssignAclFlow, VrfAssignAcl6) {
AddAddressVrfAssignAcl("intf1", 1, "3.1.1.0", "1.1.1.0", 6, 1, 65535,
1, 65535, "default-project:vn2:vn2", "false");
//Remote VM IP
Ip4Address ip = Ip4Address::from_string("3.1.1.1");
//Add route in vn1 saying 3.1.1.1 is reachable on remote server1
//Add a route in vn2 saying 3.1.1.1 is reachable on remote server2
Ip4Address remote_server1 = Ip4Address::from_string("10.1.1.100");
Ip4Address remote_server2 = Ip4Address::from_string("10.1.1.101");
Inet4TunnelRouteAdd(agent_->local_peer(), "default-project:vn1:vn1",
ip, 32, remote_server1, TunnelType::AllType(), 20,
"default-project:vn2", SecurityGroupList(),
PathPreference());
Inet4TunnelRouteAdd(agent_->local_peer(), "default-project:vn2:vn2",
ip, 32, remote_server2, TunnelType::AllType(), 20,
"default-project:vn2", SecurityGroupList(),
PathPreference());
client->WaitForIdle();
VmInterface *vm_intf = static_cast<VmInterface *>(VmPortGet(1));
Ip4Address dest_vm_rt = Ip4Address::from_string("1.1.1.0");
uint32_t fwd_nh_id = RouteGet("default-project:vn2:vn2", ip, 32)->
GetActiveNextHop()->id();
uint32_t rev_nh_id = RouteGet("default-project:vn2:vn2", dest_vm_rt, 24)->
GetActiveNextHop()->id();
TestFlow flow[] = {
{ TestFlowPkt(Address::INET, "3.1.1.1", "1.1.1.1", IPPROTO_TCP, 10, 20,
"default-project:vn1:vn1", "10.1.1.101", vm_intf->label()),
{
new VerifyVn("default-project:vn2", "default-project:vn1"),
new VerifyAction((1 << TrafficAction::PASS) |
(1 << TrafficAction::VRF_TRANSLATE),
(1 << TrafficAction::PASS)),
new VerifyRpf(fwd_nh_id, rev_nh_id)
}
}
};
CreateFlow(flow, 1);
//Delete the leaked routes
agent_->fabric_inet4_unicast_table()->DeleteReq(agent_->local_peer(),
"default-project:vn2:vn2", ip, 32, NULL);
agent_->fabric_inet4_unicast_table()->DeleteReq(agent_->local_peer(),
"default-project:vn1:vn1", ip, 32, NULL);
client->WaitForIdle();
}
//Send MplsoUdp packet to 1.1.1.1 from 3.1.1.1
//Where 3.1.1.1 is a ecmp source and verify
//that flow becomes short flow since destination VRF is not present
TEST_F(TestVrfAssignAclFlow, VrfAssignAcl7) {
client->agent()->flow_stats_manager()->set_delete_short_flow(false);
AddAddressVrfAssignAcl("intf1", 1, "3.1.1.0", "1.1.1.0", 6, 1, 65535,
1, 65535, "xyz", "no");
//Remote VM IP
Ip4Address ip = Ip4Address::from_string("3.1.1.1");
ComponentNHKeyList comp_nh;
Ip4Address server_ip1 = Ip4Address::from_string("10.1.1.100");
Ip4Address server_ip2 = Ip4Address::from_string("10.1.1.101");
ComponentNHKeyPtr comp_nh_data1(new ComponentNHKey(
16, agent_->fabric_vrf_name(),
agent_->router_id(), server_ip1, false,
TunnelType::AllType()));
comp_nh.push_back(comp_nh_data1);
ComponentNHKeyPtr comp_nh_data2(new ComponentNHKey(
17, agent_->fabric_vrf_name(),
agent_->router_id(),
server_ip2, false, TunnelType::AllType()));
comp_nh.push_back(comp_nh_data2);
EcmpTunnelRouteAdd(agent_->local_peer(), "default-project:vn1:vn1",
ip, 32, comp_nh, false,
"default-project:vn2", SecurityGroupList(),
PathPreference());
EcmpTunnelRouteAdd(agent_->local_peer(), "default-project:vn2:vn2",
ip, 32, comp_nh, false,
"default-project:vn2", SecurityGroupList(),
PathPreference());
client->WaitForIdle();
VmInterface *vm_intf = static_cast<VmInterface *>(VmPortGet(1));
TestFlow flow[] = {
{ TestFlowPkt(Address::INET, "3.1.1.1", "1.1.1.1", IPPROTO_TCP, 10, 20,
"default-project:vn1:vn1", "10.1.1.101", vm_intf->label()),
{
new ShortFlow()
}
}
};
CreateFlow(flow, 1);
//Delete the leaked routes
agent_->fabric_inet4_unicast_table()->DeleteReq(agent_->local_peer(),
"default-project:vn2:vn2", ip, 32, NULL);
agent_->fabric_inet4_unicast_table()->DeleteReq(agent_->local_peer(),
"default-project:vn1:vn1", ip, 32, NULL);
client->WaitForIdle();
client->agent()->flow_stats_manager()->set_delete_short_flow(true);
}
TEST_F(TestVrfAssignAclFlow, VrfAssignAcl8) {
Ip4Address server_ip = Ip4Address::from_string("10.1.1.2");
Ip4Address vm_ip = Ip4Address::from_string("2.1.1.1");
Inet4TunnelRouteAdd(bgp_peer_, "default-project:vn1:vn1", vm_ip, 32,
server_ip, TunnelType::AllType(), 16,
"default-project:vn2",
SecurityGroupList(), PathPreference());
client->WaitForIdle();
TestFlow flow[] = {
{ TestFlowPkt(Address::INET, "1.1.1.1", "2.1.1.1", IPPROTO_TCP, 10, 20,
"default-project:vn1:vn1", VmPortGet(1)->id()),
{
new VerifyVn("default-project:vn1", "default-project:vn2"),
}
}
};
CreateFlow(flow, 1);
AddAddressVrfAssignAcl("intf1", 1, "1.1.1.0", "2.1.1.0", 6, 1, 65535,
1, 65535, "default-project:vn3:vn3", "true");
client->WaitForIdle();
int nh_id = VmPortGet(1)->flow_key_nh()->id();
FlowEntry *fe = FlowGet(1, "1.1.1.1", "2.1.1.1", IPPROTO_TCP,
10, 20, nh_id);
EXPECT_TRUE(fe != NULL);
EXPECT_TRUE(fe->acl_assigned_vrf() == "default-project:vn3:vn3");
DeleteRoute("default-project:vn1:vn1", "2.1.1.1", 32, bgp_peer_);
client->WaitForIdle();
}
TEST_F(TestVrfAssignAclFlow, VrfAssignAcl9) {
AddAddressVrfAssignAcl("intf1", 1, "1.1.1.0", "2.1.1.0", 6, 1, 65535,
1, 65535, "default-project:vn3:vn3", "true");
TestFlow flow[] = {
{ TestFlowPkt(Address::INET, "1.1.1.1", "2.1.1.1", IPPROTO_TCP, 10, 20,
"default-project:vn1:vn1", VmPortGet(1)->id()),
{
new VerifyVn("default-project:vn1", "default-project:vn3"),
new VerifyAction((1 << TrafficAction::PASS) |
(1 << TrafficAction::VRF_TRANSLATE),
(1 << TrafficAction::PASS))
}
}
};
CreateFlow(flow, 1);
int nh_id = VmPortGet(1)->flow_key_nh()->id();
AddAddressVrfAssignAcl("intf1", 1, "2.1.1.0", "2.1.1.0", 7, 1, 65535,
1, 65535, "default-project:vn3:vn3", "true");
client->WaitForIdle();
FlowEntry *fe = FlowGet(1, "1.1.1.1", "2.1.1.1", IPPROTO_TCP,
10, 20, nh_id);
EXPECT_TRUE(fe != NULL);
EXPECT_TRUE(fe->is_flags_set(FlowEntry::ShortFlow) == true);
}
//Modify ACL and check if new flow is set with proper action
TEST_F(TestVrfAssignAclFlow, VrfAssignAcl10) {
AddAddressVrfAssignAcl("intf1", 1, "1.1.1.0", "2.1.1.0", 6, 1, 65535,
1, 65535, "default-project:vn2:vn2", "true");
TestFlow flow[] = {
{ TestFlowPkt(Address::INET, "1.1.1.1", "2.1.1.1", IPPROTO_TCP, 10, 20,
"default-project:vn1:vn1", VmPortGet(1)->id()),
{
new VerifyVn("default-project:vn1", "default-project:vn2"),
new VerifyAction((1 << TrafficAction::PASS) |
(1 << TrafficAction::VRF_TRANSLATE),
(1 << TrafficAction::PASS))
}
}
};
CreateFlow(flow, 1);
AddAddressVrfAssignAcl("intf1", 1, "2.1.1.0", "2.1.1.0", 6, 1, 65535,
1, 65535, "default-project:vn2:vn2", "true");
TestFlow flow2[] = {
{ TestFlowPkt(Address::INET, "1.1.1.1", "2.1.1.1", IPPROTO_TCP, 10, 20,
"default-project:vn1:vn1", VmPortGet(1)->id()),
{
new ShortFlow()
}
}
};
CreateFlow(flow2, 1);
}
//Add an VRF translate ACL to send all ssh traffic to "2.1.1.1"
//via default-project:vn2 and also add mirror ACL for VN1
//Verify that final action has mirror action also
TEST_F(TestVrfAssignAclFlow, VrfAssignAclWithMirror1) {
AddAddressVrfAssignAcl("intf1", 1, "1.1.1.0", "2.1.1.0", 6, 1, 65535,
1, 65535, "default-project:vn2:vn2", "true");
VnListType vn_list;
vn_list.insert(std::string("default-project:vn2"));
//Leak route for 2.1.1.0 to default-project:vn1:vn1
Ip4Address ip1 = Ip4Address::from_string("2.1.1.0");
agent_->fabric_inet4_unicast_table()->
AddLocalVmRouteReq(agent_->local_peer(),
"default-project:vn1:vn1", ip1, 24, MakeUuid(3),
vn_list, 16, SecurityGroupList(),
CommunityList(), false,
PathPreference(), Ip4Address(0), EcmpLoadBalance(),
false, false);
client->WaitForIdle();
AddMirrorAcl("Acl", 10, "default-project:vn1", "default-project:vn2", "pass",
"10.1.1.1");
AddLink("virtual-network", "default-project:vn1", "access-control-list", "Acl");
client->WaitForIdle();
TestFlow flow[] = {
{ TestFlowPkt(Address::INET, "1.1.1.1", "2.1.1.1", IPPROTO_TCP, 10, 20,
"default-project:vn1:vn1", VmPortGet(1)->id()),
{
new VerifyVn("default-project:vn1", "default-project:vn2"),
new VerifyAction((1 << TrafficAction::PASS) |
(1 << TrafficAction::VRF_TRANSLATE) |
(1 << TrafficAction::MIRROR),
(1 << TrafficAction::PASS |
1 << TrafficAction::MIRROR))
}
}
};
CreateFlow(flow, 1);
FlowEntry *entry = FlowGet(VmPortGet(1)->flow_key_nh()->id(), "1.1.1.1",
"2.1.1.1", IPPROTO_TCP, 10, 20);
EXPECT_TRUE(entry != NULL);
if (entry != NULL) {
WAIT_FOR(1000, 1000, (entry->IsOnUnresolvedList() == false));
}
EXPECT_TRUE(entry->ksync_entry()->old_first_mirror_index() == 0);
DelLink("virtual-network", "default-project:vn1", "access-control-list", "Acl");
DelAcl("Acl");
client->WaitForIdle();
}
TEST_F(TestVrfAssignAclFlow, VrfAssignAclWithMirror2) {
AddAddressVrfAssignAcl("intf1", 1, "1.1.1.0", "2.1.1.0", 6, 1, 65535,
1, 65535, "default-project:vn2:vn2", "true");
VnListType vn_list;
vn_list.insert(std::string("default-project:vn2"));
//Leak route for 2.1.1.0 to default-project:vn1:vn1
Ip4Address ip1 = Ip4Address::from_string("2.1.1.0");
agent_->fabric_inet4_unicast_table()->
AddLocalVmRouteReq(agent_->local_peer(),
"default-project:vn1:vn1", ip1, 24, MakeUuid(3),
vn_list, 16, SecurityGroupList(),
CommunityList(), false,
PathPreference(), Ip4Address(0), EcmpLoadBalance(),
false, false);
client->WaitForIdle();
// pushing more DB Request so just before addin mirror entry
// so its creation gets delayed
for (int i =0; i<500; i++) {
std::ostringstream stream;
stream << "Vn" << i;
AddVn(stream.str().c_str(), i, false);
}
AddMirrorAcl("Acl", 10, "default-project:vn1", "default-project:vn2", "pass",
"10.1.1.1");
AddLink("virtual-network", "default-project:vn1", "access-control-list", "Acl");
TestFlow flow[] = {
{ TestFlowPkt(Address::INET, "1.1.1.1", "2.1.1.1", IPPROTO_TCP, 10, 20,
"default-project:vn1:vn1", VmPortGet(1)->id()),
{
}
}
};
CreateFlow(flow, 1);
client->WaitForIdle();
FlowEntry *entry = FlowGet(VmPortGet(1)->flow_key_nh()->id(), "1.1.1.1",
"2.1.1.1", IPPROTO_TCP, 10, 20);
EXPECT_TRUE(entry != NULL);
if (entry != NULL) {
WAIT_FOR(1000, 1000, (entry->IsOnUnresolvedList() == false));
}
DelLink("virtual-network", "default-project:vn1", "access-control-list", "Acl");
DelAcl("Acl");
for (int i =0; i<500; i++) {
std::ostringstream stream;
stream<<"Vn"<<i;
DelVn(stream.str().c_str());
}
client->WaitForIdle();
}
TEST_F(TestVrfAssignAclFlow, Vmi_Proxy_Arp_1) {
AddAddressVrfAssignAcl("intf1", 1, "1.1.1.0", "2.1.1.0", 6, 1, 65535,
1, 65535, "default-project:vn2:vn2", "true");
const VmInterface *vmi = static_cast<const VmInterface *>(VmPortGet(1));
EXPECT_EQ(vmi->proxy_arp_mode(), VmInterface::PROXY_ARP_NONE);
AddAddressVrfAssignAcl("intf1", 1, "1.1.1.0", "2.1.1.0", 6, 1, 65535,
1, 65535, "default-project:vn2:vn2", "true", "left");
EXPECT_EQ(vmi->proxy_arp_mode(), VmInterface::PROXY_ARP_UNRESTRICTED);
AddAddressVrfAssignAcl("intf1", 1, "1.1.1.0", "2.1.1.0", 6, 1, 65535,
1, 65535, "default-project:vn2:vn2", "true", "right");
EXPECT_EQ(vmi->proxy_arp_mode(), VmInterface::PROXY_ARP_UNRESTRICTED);
AddAddressVrfAssignAcl("intf1", 1, "1.1.1.0", "2.1.1.0", 6, 1, 65535,
1, 65535, "default-project:vn2:vn2", "true", "management");
EXPECT_EQ(vmi->proxy_arp_mode(), VmInterface::PROXY_ARP_NONE);
CreateVmportFIpEnv(input, 2);
EXPECT_EQ(vmi->proxy_arp_mode(), VmInterface::PROXY_ARP_NONE);
}
int main(int argc, char *argv[]) {
GETUSERARGS();
client = TestInit(init_file, ksync_init);
boost::system::error_code ec;
bgp_peer_ = CreateBgpPeer(Ip4Address::from_string("0.0.0.1", ec),
"xmpp channel");
int ret = RUN_ALL_TESTS();
client->WaitForIdle();
DeleteBgpPeer(bgp_peer_);
TestShutdown();
delete client;
return ret;
}