/
test_ksync_route.cc
396 lines (317 loc) · 13.8 KB
/
test_ksync_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
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#include "base/os.h"
#include <stdio.h>
#include <stdlib.h>
#include "testing/gunit.h"
#include "test/test_cmn_util.h"
#include "vrouter/ksync/route_ksync.h"
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:01:01:02", 1, 2}
};
class TestKSyncRoute : public ::testing::Test {
public:
virtual void SetUp() {
agent_ = Agent::GetInstance();
CreateVmportEnv(input, 2, 1);
client->WaitForIdle();
EXPECT_TRUE(VmPortActive(1));
EXPECT_TRUE(VmPortActive(2));
vnet1_ = static_cast<VmInterface *>(VmPortGet(1));
vnet2_ = static_cast<VmInterface *>(VmPortGet(2));
vrf1_obj_ = agent_->ksync()->vrf_ksync_obj();
vrf_listener_id_ = vrf1_obj_->vrf_listener_id();
VrfTable *table = static_cast<VrfTable *>(agent_->vrf_table());
VrfKSyncObject::VrfState *state;
vrf1_ = vnet1_->vrf();
vrf1_uc_table_ = static_cast<InetUnicastAgentRouteTable *>
(vrf1_->GetInet4UnicastRouteTable());
state = static_cast<VrfKSyncObject::VrfState *>
(vrf1_->GetState(table, vrf_listener_id_));
vrf1_rt_obj_ = state->inet4_uc_route_table_;
vrf1_evpn_table_ = static_cast<EvpnAgentRouteTable *>
(vrf1_->GetEvpnRouteTable());
vrf1_bridge_table_ = static_cast<BridgeAgentRouteTable *>
(vrf1_->GetBridgeRouteTable());
vrf1_bridge_rt_obj_ = state->bridge_route_table_;
VrfEntry *fabric_vrf =
table->FindVrfFromName(agent_->fabric_vrf_name());
fabric_uc_table_ = static_cast<InetUnicastAgentRouteTable *>
(fabric_vrf->GetInet4UnicastRouteTable());
state = static_cast<VrfKSyncObject::VrfState *>
(fabric_vrf->GetState(table, vrf_listener_id_));
fabric_rt_obj_ = state->inet4_uc_route_table_;
}
virtual void TearDown() {
DeleteVmportEnv(input, 2, true, 1);
client->WaitForIdle();
WAIT_FOR(1000, 100, (VmPortFindRetDel(1) == false));
WAIT_FOR(1000, 100, (VmPortFindRetDel(2) == false));
WAIT_FOR(1000, 100, (VmPortGet(1) == NULL));
WAIT_FOR(1000, 100, (VmPortGet(2) == NULL));
WAIT_FOR(1000, 100, (VnGet(1) == NULL));
}
void AddRemoteRoute(Peer *peer, const IpAddress &addr, int plen,
const string &vn) {
SecurityGroupList sg_list;
PathPreference path_pref;
ControllerVmRoute *data = NULL;
data = ControllerVmRoute::MakeControllerVmRoute
(NULL, agent_->fabric_vrf_name(), agent_->router_id(),
"vrf1", Ip4Address::from_string("10.10.10.2"), TunnelType::GREType(),
100, vn, sg_list, path_pref);
vrf1_uc_table_->AddRemoteVmRouteReq(peer, "vrf1", addr, plen, data);
client->WaitForIdle();
}
void AddRemoteEvpnRoute(Peer *peer, const MacAddress &mac,
const IpAddress &addr, uint32_t ethernet_tag,
const string &vn) {
SecurityGroupList sg_list;
PathPreference path_pref;
ControllerVmRoute *data = NULL;
data = ControllerVmRoute::MakeControllerVmRoute
(NULL, agent_->fabric_vrf_name(), agent_->router_id(),
"vrf1", Ip4Address::from_string("10.10.10.2"), TunnelType::GREType(),
100, vn, sg_list, path_pref);
vrf1_evpn_table_->AddRemoteVmRouteReq(peer, "vrf1", mac, addr,
ethernet_tag, data);
client->WaitForIdle();
}
Agent *agent_;
VnswInterfaceListener *vnswif_;
VmInterface *vnet1_;
VmInterface *vnet2_;
DBTableBase::ListenerId vrf_listener_id_;
VrfEntry *vrf1_;
VrfKSyncObject *vrf1_obj_;
InetUnicastAgentRouteTable *vrf1_uc_table_;
InetUnicastAgentRouteTable *fabric_uc_table_;
EvpnAgentRouteTable *vrf1_evpn_table_;
BridgeAgentRouteTable *vrf1_bridge_table_;
RouteKSyncObject *vrf1_rt_obj_;
RouteKSyncObject *vrf1_bridge_rt_obj_;
RouteKSyncObject *fabric_rt_obj_;
};
// proxy_arp_ and flood_ flags for interface-route
TEST_F(TestKSyncRoute, vm_interface_route_1) {
InetUnicastRouteEntry *rt = vrf1_uc_table_->FindLPM(vnet1_->ip_addr());
EXPECT_TRUE(rt != NULL);
std::auto_ptr<RouteKSyncEntry> ksync(new RouteKSyncEntry(vrf1_rt_obj_, rt));
EXPECT_TRUE(vrf1_obj_->RouteNeedsMacBinding(rt));
ksync->BuildArpFlags(rt, rt->GetActivePath(), vnet1_->mac());
EXPECT_TRUE(ksync->proxy_arp());
EXPECT_FALSE(ksync->flood());
}
// proxy_arp_ and flood_ flags for interface-route when MAC not stitched
TEST_F(TestKSyncRoute, vm_interface_route_2) {
InetUnicastRouteEntry *rt = vrf1_uc_table_->FindLPM(vnet1_->ip_addr());
EXPECT_TRUE(rt != NULL);
std::auto_ptr<RouteKSyncEntry> ksync(new RouteKSyncEntry(vrf1_rt_obj_, rt));
EXPECT_TRUE(vrf1_obj_->RouteNeedsMacBinding(rt));
ksync->BuildArpFlags(rt, rt->GetActivePath(), MacAddress());
EXPECT_FALSE(ksync->proxy_arp());
EXPECT_TRUE(ksync->flood());
}
// proxy_arp_ and flood_ flags for remote route
TEST_F(TestKSyncRoute, remote_route_1) {
IpAddress addr = IpAddress(Ip4Address::from_string("1.1.1.100"));
AddRemoteRoute(NULL, addr, 32, "vn1");
InetUnicastRouteEntry *rt = vrf1_uc_table_->FindLPM(addr);
EXPECT_TRUE(rt != NULL);
std::auto_ptr<RouteKSyncEntry> ksync(new RouteKSyncEntry(vrf1_rt_obj_, rt));
EXPECT_TRUE(vrf1_obj_->RouteNeedsMacBinding(rt));
ksync->BuildArpFlags(rt, rt->GetActivePath(), vnet1_->mac());
EXPECT_TRUE(ksync->proxy_arp());
EXPECT_FALSE(ksync->flood());
vrf1_uc_table_->DeleteReq(NULL, "vrf1", addr, 32, NULL);
client->WaitForIdle();
}
// proxy_arp_ and flood_ flags for remote-route when MAC not stitched
TEST_F(TestKSyncRoute, remote_route_2) {
IpamInfo ipam_info[] = {
{"1.1.1.0", 24, "1.1.1.200"},
};
AddIPAM("vn1", ipam_info, 1);
client->WaitForIdle();
IpAddress addr = IpAddress(Ip4Address::from_string("1.1.1.100"));
AddRemoteRoute(NULL, addr, 32, "vn1");
InetUnicastRouteEntry *rt = vrf1_uc_table_->FindLPM(addr);
EXPECT_TRUE(rt != NULL);
std::auto_ptr<RouteKSyncEntry> ksync(new RouteKSyncEntry(vrf1_rt_obj_, rt));
EXPECT_TRUE(vrf1_obj_->RouteNeedsMacBinding(rt));
ksync->BuildArpFlags(rt, rt->GetActivePath(), MacAddress());
EXPECT_FALSE(ksync->proxy_arp());
EXPECT_TRUE(ksync->flood());
vrf1_uc_table_->DeleteReq(NULL, "vrf1", addr, 32, NULL);
DelIPAM("vn1");
client->WaitForIdle();
}
// dhcp_flood flag for remote EVPN route
TEST_F(TestKSyncRoute, remote_evpn_route_1) {
MacAddress vmi_mac(input[0].mac);
BridgeRouteEntry *vmi_rt = vrf1_bridge_table_->FindRoute(vmi_mac);
EXPECT_TRUE(vmi_rt != NULL);
std::auto_ptr<RouteKSyncEntry> ksync_vmi(new RouteKSyncEntry(
vrf1_bridge_rt_obj_, vmi_rt));
ksync_vmi->Sync(vmi_rt);
EXPECT_FALSE(ksync_vmi->flood_dhcp()); // flood DHCP not set when VMI exists
uint32_t ethernet_tag = 1000;
MacAddress mac("00:01:02:03:04:05");
IpAddress addr = IpAddress(Ip4Address::from_string("1.1.1.100"));
AddRemoteEvpnRoute(NULL, mac, addr, ethernet_tag, "vn1");
BridgeRouteEntry *rt = vrf1_bridge_table_->FindRoute(mac);
EXPECT_TRUE(rt != NULL);
std::auto_ptr<RouteKSyncEntry> ksync(new RouteKSyncEntry(vrf1_bridge_rt_obj_, rt));
ksync->Sync(rt);
EXPECT_TRUE(ksync->flood_dhcp()); // flood DHCP set for MAC without VMI
vrf1_evpn_table_->DeleteReq(NULL, "vrf1", mac, addr, ethernet_tag);
client->WaitForIdle();
}
// proxy_arp_ and flood_ flags for route with different VNs
TEST_F(TestKSyncRoute, different_vn_1) {
IpAddress addr = IpAddress(Ip4Address::from_string("2.2.2.100"));
AddRemoteRoute(NULL, addr, 32, "Vn3");
InetUnicastRouteEntry *rt = vrf1_uc_table_->FindLPM(addr);
EXPECT_TRUE(rt != NULL);
std::auto_ptr<RouteKSyncEntry> ksync(new RouteKSyncEntry(vrf1_rt_obj_, rt));
EXPECT_TRUE(vrf1_obj_->RouteNeedsMacBinding(rt));
ksync->BuildArpFlags(rt, rt->GetActivePath(), vnet1_->mac());
EXPECT_TRUE(ksync->proxy_arp());
EXPECT_FALSE(ksync->flood());
vrf1_uc_table_->DeleteReq(NULL, "vrf1", addr, 32, NULL);
client->WaitForIdle();
}
// Validate flags from the replacement route
TEST_F(TestKSyncRoute, replacement_rt_1) {
IpAddress addr1 = IpAddress(Ip4Address::from_string("2.2.2.100"));
AddRemoteRoute(NULL, addr1, 32, "Vn3");
InetUnicastRouteEntry *rt1 = vrf1_uc_table_->FindLPM(addr1);
EXPECT_TRUE(rt1 != NULL);
std::auto_ptr<RouteKSyncEntry> ksync1(new RouteKSyncEntry(vrf1_rt_obj_, rt1));
EXPECT_TRUE(vrf1_obj_->RouteNeedsMacBinding(rt1));
ksync1->BuildArpFlags(rt1, rt1->GetActivePath(), vnet1_->mac());
EXPECT_TRUE(ksync1->proxy_arp());
EXPECT_FALSE(ksync1->flood());
IpamInfo ipam_info[] = {
{"1.1.1.0", 24, "1.1.1.200"},
};
AddIPAM("vn1", ipam_info, 1);
client->WaitForIdle();
IpAddress addr2 = IpAddress(Ip4Address::from_string("1.1.1.100"));
AddRemoteRoute(NULL, addr2, 32, "vn1");
InetUnicastRouteEntry *rt2 = vrf1_uc_table_->FindLPM(addr2);
EXPECT_TRUE(rt2 != NULL);
std::auto_ptr<RouteKSyncEntry> ksync2(new RouteKSyncEntry(vrf1_rt_obj_, rt2));
EXPECT_TRUE(vrf1_obj_->RouteNeedsMacBinding(rt2));
ksync2->BuildArpFlags(rt2, rt2->GetActivePath(), MacAddress());
EXPECT_FALSE(ksync2->proxy_arp());
EXPECT_TRUE(ksync2->flood());
std::auto_ptr<RouteKSyncEntry> ksync3(new RouteKSyncEntry(vrf1_rt_obj_, rt2));
ksync3->CopyReplacementData(NULL, ksync2.get());
EXPECT_FALSE(ksync3->proxy_arp());
EXPECT_TRUE(ksync3->flood());
ksync3->CopyReplacementData(NULL, ksync1.get());
EXPECT_TRUE(ksync3->proxy_arp());
EXPECT_FALSE(ksync3->flood());
vrf1_uc_table_->DeleteReq(NULL, "vrf1", addr1, 32, NULL);
DelIPAM("vn1");
client->WaitForIdle();
vrf1_uc_table_->DeleteReq(NULL, "vrf1", addr2, 32, NULL);
client->WaitForIdle();
}
TEST_F(TestKSyncRoute, no_replacement_rt_1) {
IpAddress addr1 = IpAddress(Ip4Address::from_string("2.2.2.100"));
AddRemoteRoute(NULL, addr1, 32, "Vn3");
InetUnicastRouteEntry *rt1 = vrf1_uc_table_->FindLPM(addr1);
EXPECT_TRUE(rt1 != NULL);
std::auto_ptr<RouteKSyncEntry> ksync1(new RouteKSyncEntry(vrf1_rt_obj_, rt1));
EXPECT_TRUE(vrf1_obj_->RouteNeedsMacBinding(rt1));
ksync1->BuildArpFlags(rt1, rt1->GetActivePath(), vnet1_->mac());
EXPECT_TRUE(ksync1->proxy_arp());
EXPECT_FALSE(ksync1->flood());
ksync1->CopyReplacementData(NULL, NULL);
EXPECT_TRUE(ksync1->mac().IsZero());
vrf1_uc_table_->DeleteReq(NULL, "vrf1", addr1, 32, NULL);
DelIPAM("vn1");
client->WaitForIdle();
}
// proxy_arp_ and flood_ flags for IPAM subnet route
TEST_F(TestKSyncRoute, ipam_subnet_route_1) {
IpamInfo ipam_info[] = {
{"1.1.1.0", 24, "1.1.1.200"},
};
AddIPAM("vn1", ipam_info, 1);
client->WaitForIdle();
IpAddress addr = IpAddress(Ip4Address::from_string("1.1.1.100"));
InetUnicastRouteEntry *rt = vrf1_uc_table_->FindLPM(addr);
EXPECT_TRUE(rt != NULL);
std::auto_ptr<RouteKSyncEntry> ksync(new RouteKSyncEntry(vrf1_rt_obj_, rt));
EXPECT_FALSE(vrf1_obj_->RouteNeedsMacBinding(rt));
ksync->BuildArpFlags(rt, rt->GetActivePath(), MacAddress());
EXPECT_FALSE(ksync->proxy_arp());
EXPECT_TRUE(ksync->flood());
DelIPAM("vn1");
client->WaitForIdle();
}
// proxy_arp_ and flood_ flags for IPAM subnet route exported by Gateway
TEST_F(TestKSyncRoute, ipam_subnet_route_2) {
boost::system::error_code ec;
BgpPeer *bgp_peer = CreateBgpPeer(Ip4Address::from_string("0.0.0.1", ec),
"xmpp channel");
IpamInfo ipam_info[] = {
{"1.1.1.0", 24, "1.1.1.200"},
};
AddIPAM("vn1", ipam_info, 1);
client->WaitForIdle();
IpAddress addr = IpAddress(Ip4Address::from_string("1.1.1.0"));
AddRemoteRoute(bgp_peer, addr, 24, "vn1");
InetUnicastRouteEntry *rt = vrf1_uc_table_->FindLPM(addr);
EXPECT_TRUE(rt != NULL);
std::auto_ptr<RouteKSyncEntry> ksync(new RouteKSyncEntry(vrf1_rt_obj_, rt));
EXPECT_FALSE(vrf1_obj_->RouteNeedsMacBinding(rt));
ksync->BuildArpFlags(rt, rt->GetActivePath(), MacAddress());
EXPECT_FALSE(ksync->proxy_arp());
EXPECT_TRUE(ksync->flood());
vrf1_uc_table_->DeleteReq(NULL, "vrf1", addr, 24, NULL);
DelIPAM("vn1");
DeleteBgpPeer(bgp_peer);
client->WaitForIdle();
}
// proxy_arp_ and flood_ flags for IPAM subnet ECMP route exported by Gateway
TEST_F(TestKSyncRoute, ecmp_ipam_subnet_route_2) {
boost::system::error_code ec;
BgpPeer *bgp_peer = CreateBgpPeer(Ip4Address::from_string("0.0.0.1", ec),
"xmpp channel");
IpamInfo ipam_info[] = {
{"1.1.1.0", 24, "1.1.1.200"},
};
AddIPAM("vn1", ipam_info, 1);
client->WaitForIdle();
EcmpTunnelRouteAdd(agent_, bgp_peer, "vrf1", "1.1.1.0", 24,
"100.100.100.1", 1, "100.100.100.2", 2, "vn1");
IpAddress addr = IpAddress(Ip4Address::from_string("1.1.1.100"));
InetUnicastRouteEntry *rt = vrf1_uc_table_->FindLPM(addr);
EXPECT_TRUE(rt != NULL);
std::auto_ptr<RouteKSyncEntry> ksync(new RouteKSyncEntry(vrf1_rt_obj_, rt));
EXPECT_FALSE(vrf1_obj_->RouteNeedsMacBinding(rt));
ksync->BuildArpFlags(rt, rt->GetActivePath(), MacAddress());
EXPECT_FALSE(ksync->proxy_arp());
EXPECT_TRUE(ksync->flood());
vrf1_uc_table_->DeleteReq(NULL, "vrf1",
IpAddress(Ip4Address::from_string("1.1.1.10")),
24, NULL);
DelIPAM("vn1");
client->WaitForIdle();
DeleteBgpPeer(bgp_peer);
client->WaitForIdle();
}
int main(int argc, char **argv) {
GETUSERARGS();
client = TestInit(init_file, ksync_init);
int ret = RUN_ALL_TESTS();
TestShutdown();
delete client;
return ret;
}