/
test_ecmp_mx.cc
381 lines (327 loc) · 13.7 KB
/
test_ecmp_mx.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
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#include "base/os.h"
#include "test/test_cmn_util.h"
#include "test_pkt_util.h"
#include "pkt/flow_proto.h"
#define AGE_TIME 10*1000
void RouterIdDepInit(Agent *agent) {
}
struct PortInfo input1[] = {
{"vnet1", 1, "1.1.1.1", "00:00:00:01:01:01", 1, 1},
};
class EcmpTest : public ::testing::Test {
virtual void SetUp() {
agent_ = Agent::GetInstance();
boost::system::error_code ec;
bgp_peer = CreateBgpPeer(Ip4Address::from_string("0.0.0.1", ec),
"xmpp channel");
client->WaitForIdle();
flow_proto_ = agent_->pkt()->get_flow_proto();
CreateVmportWithEcmp(input1, 1);
AddVn("vn2", 2);
AddVrf("vrf2");
client->WaitForIdle();
strcpy(router_id, agent_->router_id().to_string().c_str());
strcpy(MX_0, "100.1.1.1");
strcpy(MX_1, "100.1.1.2");
strcpy(MX_2, "100.1.1.3");
strcpy(MX_3, "100.1.1.4");
const VmInterface *vmi = static_cast<const VmInterface *>(VmPortGet(1));
vm1_label = vmi->label();
eth_intf_id = EthInterfaceGet("vnet0")->id();
}
virtual void TearDown() {
DeleteVmportEnv(input1, 1, true);
DelVn("vn2");
DelVrf("vrf2");
client->WaitForIdle();
DeleteBgpPeer(bgp_peer);
client->WaitForIdle();
EXPECT_FALSE(VrfFind("vrf1", true));
EXPECT_FALSE(VrfFind("vrf2", true));
WAIT_FOR(1000, 1000, (flow_proto_->FlowCount() == 0));
client->WaitForIdle();
}
public:
void AddRemoteEcmpRoute(const string vrf_name, const string ip,
uint32_t plen, const string vn, int count, bool reverse = false,
bool same_label = false) {
//If there is a local route, include that always
Ip4Address vm_ip = Ip4Address::from_string(ip);
ComponentNHKeyList comp_nh_list;
int remote_server_ip = 0x64010101;
int label = 16;
SecurityGroupList sg_id_list;
for(int i = 0; i < count; i++) {
ComponentNHKeyPtr comp_nh(new ComponentNHKey(
label, Agent::GetInstance()->fabric_vrf_name(),
Agent::GetInstance()->router_id(),
Ip4Address(remote_server_ip++),
false, TunnelType::AllType()));
comp_nh_list.push_back(comp_nh);
if (!same_label) {
label++;
}
}
if (reverse) {
std::reverse(comp_nh_list.begin(), comp_nh_list.end());
}
EcmpTunnelRouteAdd(bgp_peer, vrf_name, vm_ip, plen,
comp_nh_list, -1, vn, sg_id_list,
PathPreference());
}
FlowProto *get_flow_proto() const { return flow_proto_; }
Agent *agent_;
Peer *bgp_peer;
FlowProto *flow_proto_;
AgentXmppChannel *channel;
char router_id[80];
char MX_0[80];
char MX_1[80];
char MX_2[80];
char MX_3[80];
int vm1_label;
int eth_intf_id;
};
//Send packet from VM to ECMP MX
//Verify component index is set and correspnding
//rpf nexthop
TEST_F(EcmpTest, EcmpTest_1) {
AddRemoteEcmpRoute("vrf1", "0.0.0.0", 0, "vn1", 4);
TxIpPacket(VmPortGetId(1), "1.1.1.1", "2.1.1.1", 1);
client->WaitForIdle();
AgentRoute *rt = RouteGet("vrf1", Ip4Address::from_string("0.0.0.0"), 0);
FlowEntry *entry = FlowGet(VrfGet("vrf1")->vrf_id(),
"1.1.1.1", "2.1.1.1", 1, 0, 0, GetFlowKeyNH(1));
EXPECT_TRUE(entry != NULL);
EXPECT_TRUE(entry->data().component_nh_idx !=
CompositeNH::kInvalidComponentNHIdx);
//Reverse flow is no ECMP
FlowEntry *rev_entry = entry->reverse_flow_entry();
EXPECT_TRUE(rev_entry->data().component_nh_idx ==
CompositeNH::kInvalidComponentNHIdx);
EXPECT_TRUE(rev_entry->data().nh.get() == rt->GetActiveNextHop());
DeleteRoute("vrf1", "0.0.0.0", 0, bgp_peer);
client->WaitForIdle();
WAIT_FOR(1000, 1000, (get_flow_proto()->FlowCount() == 0));
}
//Send packet from ECMP MX to VM
//Verify:
// Forward flow is ecmp
// Reverse flow ecmp index is not set
// Reverse flow rpf next is composite NH
// and the index matches originating MX
TEST_F(EcmpTest, EcmpTest_2) {
AddRemoteEcmpRoute("vrf1", "0.0.0.0", 0, "vn1", 4);
TxIpMplsPacket(eth_intf_id, MX_2, router_id, vm1_label,
"8.8.8.8", "1.1.1.1", 1, 10);
client->WaitForIdle();
AgentRoute *rt = RouteGet("vrf1", Ip4Address::from_string("0.0.0.0"), 0);
FlowEntry *entry = FlowGet(VrfGet("vrf1")->vrf_id(),
"1.1.1.1", "8.8.8.8", 1, 0, 0, GetFlowKeyNH(1));
EXPECT_TRUE(entry != NULL);
EXPECT_TRUE(entry->data().component_nh_idx == 2);
//Reverse flow is no ECMP
FlowEntry *rev_entry = entry->reverse_flow_entry();
EXPECT_TRUE(rev_entry->data().component_nh_idx ==
CompositeNH::kInvalidComponentNHIdx);
EXPECT_TRUE(rev_entry->data().nh.get() == rt->GetActiveNextHop());
DeleteRoute("vrf1", "0.0.0.0", 0, bgp_peer);
client->WaitForIdle();
WAIT_FOR(1000, 1000, (get_flow_proto()->FlowCount() == 0));
}
//Send packet from MX3 to VM
//Verify that index are set fine
TEST_F(EcmpTest, EcmpTest_3) {
AddRemoteEcmpRoute("vrf1", "0.0.0.0", 0, "vn1", 4);
TxIpMplsPacket(eth_intf_id, MX_3, router_id, vm1_label,
"8.8.8.8", "1.1.1.1", 1, 10);
client->WaitForIdle();
AgentRoute *rt = RouteGet("vrf1", Ip4Address::from_string("0.0.0.0"), 0);
FlowEntry *entry = FlowGet(VrfGet("vrf1")->vrf_id(),
"1.1.1.1", "8.8.8.8", 1, 0, 0, GetFlowKeyNH(1));
EXPECT_TRUE(entry != NULL);
EXPECT_TRUE(entry->data().component_nh_idx == 3);
//Reverse flow is no ECMP
FlowEntry *rev_entry = entry->reverse_flow_entry();
EXPECT_TRUE(rev_entry->data().component_nh_idx ==
CompositeNH::kInvalidComponentNHIdx);
EXPECT_TRUE(rev_entry->data().nh.get() == rt->GetActiveNextHop());
DeleteRoute("vrf1", "0.0.0.0", 0, bgp_peer);
client->WaitForIdle();
WAIT_FOR(1000, 1000, (get_flow_proto()->FlowCount() == 0));
}
//Send packet from MX1 to VM
//Trap a ecmp resolve packet from MX2 to VM
//verify that component index gets update
TEST_F(EcmpTest, EcmpTest_4) {
AddRemoteEcmpRoute("vrf1", "0.0.0.0", 0, "vn1", 4);
TxIpMplsPacket(eth_intf_id, MX_0, router_id, vm1_label,
"8.8.8.8", "1.1.1.1", 1, 10);
client->WaitForIdle();
AgentRoute *rt = RouteGet("vrf1", Ip4Address::from_string("0.0.0.0"), 0);
FlowEntry *entry = FlowGet(VrfGet("vrf1")->vrf_id(),
"1.1.1.1", "8.8.8.8", 1, 0, 0, GetFlowKeyNH(1));
EXPECT_TRUE(entry != NULL);
EXPECT_TRUE(entry->data().component_nh_idx == 0);
FlowEntry *rev_entry = entry->reverse_flow_entry();
EXPECT_TRUE(rev_entry->data().component_nh_idx ==
CompositeNH::kInvalidComponentNHIdx);
EXPECT_TRUE(rev_entry->data().nh.get() == rt->GetActiveNextHop());
TxIpMplsPacket(eth_intf_id, MX_2, router_id, vm1_label,
"8.8.8.8", "1.1.1.1", 1, 10);
client->WaitForIdle();
EXPECT_TRUE(entry->data().component_nh_idx == 2);
EXPECT_TRUE(rev_entry->data().nh.get() == rt->GetActiveNextHop());
DeleteRoute("vrf1", "0.0.0.0", 0, bgp_peer);
client->WaitForIdle();
WAIT_FOR(1000, 1000, (get_flow_proto()->FlowCount() == 0));
}
//Send packet from MX to VM
// Fwd flow has no vrf assign ACL
// Reverese flow has vrf assign ACL
// hence component index has to set based on vrf2
TEST_F(EcmpTest, EcmpTest_5) {
AddRemoteEcmpRoute("vrf1", "0.0.0.0", 0, "vn2", 4);
//Reverse all the nexthop in vrf2
AddRemoteEcmpRoute("vrf2", "0.0.0.0", 0, "vn2", 4, true);
VnListType vn_list;
vn_list.insert("vn1");
Ip4Address ip = Ip4Address::from_string("1.1.1.1");
agent_->fabric_inet4_unicast_table()->
AddLocalVmRouteReq(agent_->local_peer(),
"vrf2", ip, 32, MakeUuid(1), vn_list,
vm1_label, SecurityGroupList(), CommunityList(),
false, PathPreference(), Ip4Address(0), EcmpLoadBalance());
client->WaitForIdle();
AddVrfAssignNetworkAcl("Acl", 10, "vn1", "vn2", "pass", "vrf2");
AddLink("virtual-network", "vn1", "access-control-list", "Acl");
client->WaitForIdle();
TxIpMplsPacket(eth_intf_id, MX_3, router_id, vm1_label,
"8.8.8.8", "1.1.1.1", 1, 10);
client->WaitForIdle();
AgentRoute *rt = RouteGet("vrf2", Ip4Address::from_string("0.0.0.0"), 0);
FlowEntry *entry = FlowGet(VrfGet("vrf1")->vrf_id(),
"1.1.1.1", "8.8.8.8", 1, 0, 0, GetFlowKeyNH(1));
EXPECT_TRUE(entry != NULL);
//MX 3 would be placed at index 0 because of nexthop
//order reversal
EXPECT_TRUE(entry->data().component_nh_idx == 0);
//Reverse flow is no ECMP
FlowEntry *rev_entry = entry->reverse_flow_entry();
EXPECT_TRUE(rev_entry->data().component_nh_idx ==
CompositeNH::kInvalidComponentNHIdx);
EXPECT_TRUE(rev_entry->data().nh.get() == rt->GetActiveNextHop());
DeleteRoute("vrf1", "0.0.0.0", 0, bgp_peer);
DeleteRoute("vrf2", "0.0.0.0", 0, bgp_peer);
DeleteRoute("vrf2", "1.1.1.1", 32, agent_->local_peer());
DelLink("virtual-network", "vn1", "access-control-list", "Acl");
DelAcl("Acl");
client->WaitForIdle();
WAIT_FOR(1000, 1000, (get_flow_proto()->FlowCount() == 0));
}
//Floating IP traffic from VM going to ECMP MX
TEST_F(EcmpTest, EcmpTest_6) {
//Setup
//Add IP 2.1.1.1 as floating IP to 1.1.1.1
//Make address 8.8.8.8 reachable on 4 MX
//Send traffic from MX3 to FIP
//Verify RPF nh and component index
AddVn("fip", 3);
AddVrf("fip:fip");
AddLink("virtual-network", "fip", "routing-instance", "fip:fip");
AddFloatingIpPool("fip-pool1", 1);
AddFloatingIp("fip1", 1, "2.1.1.1");
AddLink("floating-ip", "fip1", "floating-ip-pool", "fip-pool1");
AddLink("floating-ip-pool", "fip-pool1", "virtual-network", "fip");
AddLink("virtual-machine-interface", "vnet1", "floating-ip", "fip1");
client->WaitForIdle();
AddRemoteEcmpRoute("fip:fip", "0.0.0.0", 0, "fip", 4);
client->WaitForIdle();
TxIpMplsPacket(eth_intf_id, MX_3, router_id, vm1_label,
"8.8.8.8", "2.1.1.1", 1, 10);
client->WaitForIdle();
AgentRoute *rt = RouteGet("fip:fip", Ip4Address::from_string("0.0.0.0"), 0);
FlowEntry *entry = FlowGet(VrfGet("vrf1")->vrf_id(),
"1.1.1.1", "8.8.8.8", 1, 0, 0, GetFlowKeyNH(1));
EXPECT_TRUE(entry != NULL);
EXPECT_TRUE(entry->data().component_nh_idx == 3);
//Reverse flow is no ECMP
FlowEntry *rev_entry = entry->reverse_flow_entry();
EXPECT_TRUE(rev_entry->data().component_nh_idx ==
CompositeNH::kInvalidComponentNHIdx);
EXPECT_TRUE(rev_entry->data().nh.get() == rt->GetActiveNextHop());
//Clean up
DeleteRoute("fip:fip", "0.0.0.0", 0, bgp_peer);
DelLink("virtual-machine-interface", "vnet1", "floating-ip", "fip1");
DelLink("floating-ip-pool", "fip-pool1", "virtual-network", "fip");
DelNode("floating-ip", "fip1");
DelNode("floating-ip-pool", "fip-pool1");
client->WaitForIdle();
DelLink("virtual-network", "fip", "routing-instance", "fip:fip");
DelVrf("fip:fip");
DelVn("fip");
client->WaitForIdle();
WAIT_FOR(1000, 1000, (get_flow_proto()->FlowCount() == 0));
}
//Floating IP traffic from VM going to ECMP MX with
//VRF translation to vrf2
TEST_F(EcmpTest, EcmpTest_7) {
//Setup
//Add IP 2.1.1.1 as floating IP to 1.1.1.1
//Make address 8.8.8.8 reachable on 4 MX
//Send traffic from MX3 to FIP with vrf translation
//Verify RPF nh and component index
AddVn("fip", 3);
AddVrf("fip:fip");
AddLink("virtual-network", "fip", "routing-instance", "fip:fip");
AddFloatingIpPool("fip-pool1", 1);
AddFloatingIp("fip1", 1, "2.1.1.1");
AddLink("floating-ip", "fip1", "floating-ip-pool", "fip-pool1");
AddLink("floating-ip-pool", "fip-pool1", "virtual-network", "fip");
AddLink("virtual-machine-interface", "vnet1", "floating-ip", "fip1");
client->WaitForIdle();
AddRemoteEcmpRoute("fip:fip", "0.0.0.0", 0, "fip", 4);
//Add the routes in vrf2 in reverese order
AddRemoteEcmpRoute("vrf2", "0.0.0.0", 0, "fip", 4, true);
client->WaitForIdle();
AddVrfAssignNetworkAcl("Acl", 10, "fip", "fip", "pass", "vrf2");
AddLink("virtual-network", "fip", "access-control-list", "Acl");
client->WaitForIdle();
TxIpMplsPacket(eth_intf_id, MX_3, router_id, vm1_label,
"8.8.8.8", "2.1.1.1", 1, 10);
client->WaitForIdle();
AgentRoute *rt = RouteGet("vrf2", Ip4Address::from_string("0.0.0.0"), 0);
FlowEntry *entry = FlowGet(VrfGet("vrf1")->vrf_id(),
"1.1.1.1", "8.8.8.8", 1, 0, 0, GetFlowKeyNH(1));
EXPECT_TRUE(entry != NULL);
EXPECT_TRUE(entry->data().component_nh_idx == 0);
//Reverse flow is no ECMP
FlowEntry *rev_entry = entry->reverse_flow_entry();
EXPECT_TRUE(rev_entry->data().component_nh_idx ==
CompositeNH::kInvalidComponentNHIdx);
EXPECT_TRUE(rev_entry->data().nh.get() == rt->GetActiveNextHop());
//Clean up
DeleteRoute("fip:fip", "0.0.0.0", 0, bgp_peer);
DelLink("virtual-machine-interface", "vnet1", "floating-ip", "fip1");
DelLink("floating-ip-pool", "fip-pool1", "virtual-network", "fip");
DelNode("floating-ip", "fip1");
DelNode("floating-ip-pool", "fip-pool1");
client->WaitForIdle();
DelLink("virtual-network", "fip", "routing-instance", "fip:fip");
DelVrf("fip:fip");
DelVn("fip");
client->WaitForIdle();
WAIT_FOR(1000, 1000, (get_flow_proto()->FlowCount() == 0));
}
int main(int argc, char *argv[]) {
GETUSERARGS();
client = TestInit(init_file, ksync_init, true, true, true, 100*1000);
int ret = RUN_ALL_TESTS();
client->WaitForIdle();
TestShutdown();
delete client;
return ret;
}