-
Notifications
You must be signed in to change notification settings - Fork 390
/
arp_path_preference_test.cc
163 lines (135 loc) · 5.08 KB
/
arp_path_preference_test.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
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#include "base/os.h"
#include "testing/gunit.h"
#include <sys/socket.h>
#include <netinet/if_ether.h>
#include <base/logging.h>
#include <io/event_manager.h>
#include <cmn/agent_cmn.h>
#include <oper/operdb_init.h>
#include <controller/controller_init.h>
#include <controller/controller_vrf_export.h>
#include <pkt/pkt_init.h>
#include <services/services_init.h>
#include <vrouter/ksync/ksync_init.h>
#include <oper/vrf.h>
#include <oper/mirror_table.h>
#include <pugixml/pugixml.hpp>
#include <services/arp_proto.h>
#include <vr_interface.h>
#include <test/test_cmn_util.h>
#include <test/pkt_gen.h>
#include "vr_types.h"
#include "xmpp/test/xmpp_test_util.h"
#include <services/services_sandesh.h>
#include "oper/path_preference.h"
struct PortInfo input1[] = {
{"vnet1", 1, "8.1.1.1", "00:00:00:01:01:01", 1, 1}
};
struct PortInfo input2[] = {
{"vnet2", 2, "8.1.1.1", "00:00:00:01:01:01", 1, 1}
};
IpamInfo ipam_info[] = {
{"8.1.1.0", 24, "8.1.1.10", true},
};
class ArpPathPreferenceTest : public ::testing::Test {
public:
ArpPathPreferenceTest(): agent(Agent::GetInstance()) {}
virtual void SetUp() {
CreateVmportEnv(input1, 1);
client->WaitForIdle();
EXPECT_TRUE(VmPortActive(1));
AddIPAM("vn1", ipam_info, 1);
client->WaitForIdle();
}
virtual void TearDown() {
DeleteVmportEnv(input1, 1, true);
DelIPAM("vn1");
client->WaitForIdle();
EXPECT_TRUE(VrfGet("vrf1", true) == NULL);
}
const ArpVrfState* GetVrfState(uint32_t vrf_id) {
const VrfEntry *vrf = agent->vrf_table()->FindVrfFromId(vrf_id);
return static_cast<const ArpVrfState *>(
vrf->GetState(agent->vrf_table(),
agent->GetArpProto()->
vrf_table_listener_id()));
}
bool CheckIpMap(uint32_t vrf_id, uint32_t id, const IpAddress &ip) {
const ArpVrfState *state = GetVrfState(vrf_id);
return state->Get(ip)->IntfPresentInIpMap(id);
}
bool CheckEvpnMap(uint32_t vrf_id, uint32_t id, const IpAddress &ip) {
const ArpVrfState *state = GetVrfState(vrf_id);
return state->Get(ip)->IntfPresentInEvpnMap(id);
}
uint32_t GetIpMapRetryCount(uint32_t vrf_id, uint32_t id, const IpAddress &ip) {
const ArpVrfState *state = GetVrfState(vrf_id);
return state->Get(ip)->IntfRetryCountInIpMap(id);
}
uint32_t GetEvpnMapRetryCount(uint32_t vrf_id, uint32_t id, const IpAddress &ip) {
const ArpVrfState *state = GetVrfState(vrf_id);
return state->Get(ip)->IntfRetryCountInEvpnMap(id);
}
protected:
Agent *agent;
};
//Check EVPN route and IP route list has
//interface ID
TEST_F(ArpPathPreferenceTest, Test1) {
uint32_t vrf_id = VrfGet("vrf1")->vrf_id();
uint32_t intf_id = VmPortGetId(1);
const IpAddress ip = Ip4Address::from_string("8.1.1.1");
EXPECT_TRUE(CheckIpMap(vrf_id, intf_id, ip));
EXPECT_TRUE(CheckEvpnMap(vrf_id, intf_id, ip));
EXPECT_TRUE(GetIpMapRetryCount(vrf_id, intf_id, ip) >= 1);
EXPECT_TRUE(GetEvpnMapRetryCount(vrf_id, intf_id, ip) >= 1);
}
//Enqueue Traffic seen for IP route, verify
//EVPN route still has interface ID in map
TEST_F(ArpPathPreferenceTest, Test2) {
CreateVmportEnv(input2, 1);
client->WaitForIdle();
uint32_t vrf_id = VrfGet("vrf1")->vrf_id();
uint32_t intf_id = VmPortGetId(1);
uint32_t intf_id1 = VmPortGetId(2);
const IpAddress ip = Ip4Address::from_string("8.1.1.1");
EXPECT_TRUE(CheckIpMap(vrf_id, intf_id, ip));
EXPECT_TRUE(CheckEvpnMap(vrf_id, intf_id, ip));
EXPECT_TRUE(GetIpMapRetryCount(vrf_id, intf_id, ip) >= 2);
EXPECT_TRUE(GetEvpnMapRetryCount(vrf_id, intf_id, ip) >= 2);
EXPECT_TRUE(CheckIpMap(vrf_id, intf_id1, ip));
EXPECT_TRUE(CheckEvpnMap(vrf_id, intf_id1, ip));
EXPECT_TRUE(GetIpMapRetryCount(vrf_id, intf_id1, ip) >= 1);
EXPECT_TRUE(GetEvpnMapRetryCount(vrf_id, intf_id1, ip) >= 1);
DeleteVmportEnv(input2, 1, false);
client->WaitForIdle();
}
TEST_F(ArpPathPreferenceTest, Test3) {
uint32_t vrf_id = VrfGet("vrf1")->vrf_id();
uint32_t intf_id = VmPortGetId(1);
const Ip4Address ip = Ip4Address::from_string("8.1.1.1");
EXPECT_TRUE(CheckIpMap(vrf_id, intf_id, ip));
EXPECT_TRUE(CheckEvpnMap(vrf_id, intf_id, ip));
EXPECT_TRUE(GetIpMapRetryCount(vrf_id, intf_id, ip) >= 1);
EXPECT_TRUE(GetEvpnMapRetryCount(vrf_id, intf_id, ip) >= 1);
agent->oper_db()->route_preference_module()->
EnqueueTrafficSeen(ip, 32, intf_id, vrf_id,
MacAddress::ZeroMac());
client->WaitForIdle();
EXPECT_TRUE(CheckIpMap(vrf_id, intf_id, ip));
EXPECT_TRUE(CheckEvpnMap(vrf_id, intf_id, ip));
EXPECT_TRUE(GetEvpnMapRetryCount(vrf_id, intf_id, ip) >= 2);
}
int main(int argc, char *argv[]) {
GETUSERARGS();
client = TestInit(init_file, ksync_init, true, true);
usleep(100000);
client->WaitForIdle();
int ret = RUN_ALL_TESTS();
TestShutdown();
delete client;
return ret;
}