-
Notifications
You must be signed in to change notification settings - Fork 390
/
test_path_preference_walker.cc
210 lines (188 loc) · 6.46 KB
/
test_path_preference_walker.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
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#include "base/os.h"
#include <base/logging.h>
#include <io/event_manager.h>
#include <boost/shared_ptr.hpp>
#include "cfg/cfg_init.h"
#include "cfg/cfg_interface.h"
#include "oper/operdb_init.h"
#include "oper/agent_path.h"
#include "oper/path_preference.h"
#include "controller/controller_init.h"
#include "pkt/pkt_init.h"
#include "services/services_init.h"
#include "test_cmn_util.h"
using namespace std;
void RouterIdDepInit(Agent *agent) {
}
static void ValidateSandeshResponse(Sandesh *sandesh, vector<int> &result) {
//TBD
//Validate the response by the expectation
}
struct PortInfo input_1[] = {
{"vnet1", 1, "1.1.1.10", "00:00:01:01:01:10", 1, 1},
};
struct PortInfo input_2[] = {
{"vnet2", 2, "2.2.2.20", "00:00:02:02:02:20", 2, 2},
};
struct PortInfo input_3[] = {
{"vnet3", 3, "3.3.3.30", "00:00:03:03:03:30", 3, 3},
};
struct TestPathPreferenceRouteListener : public PathPreferenceRouteListener {
TestPathPreferenceRouteListener(Agent *agent, AgentRouteTable *table) :
PathPreferenceRouteListener(agent, table), walk_done_(false) { }
bool DeleteState(DBTablePartBase *partition, DBEntryBase *e) {
bool ret = PathPreferenceRouteListener::DeleteState(partition, e);
PathPreferenceRouteListener::Notify(partition, e);
return ret;
}
void Walkdone(DBTableBase *partition, PathPreferenceRouteListener *state) {
PathPreferenceRouteListener::Walkdone(partition, state);
walk_done_ = true;
}
virtual void Delete() { } //Dont call parent delete as it will start
// parallel walk
bool walk_done_;
};
class PathPreferenceRouteTableWalkerTest : public ::testing::Test {
public:
PathPreferenceRouteTableWalkerTest() {
vrf_name_1_ = "vrf1";
vrf_name_2_ = "vrf2";
vrf_name_3_ = "vrf3";
server_ip_ = Ip4Address::from_string("10.1.1.11");
local_vm_ip_1_ = Ip4Address::from_string("1.1.1.10");
local_vm_ip_2_ = Ip4Address::from_string("2.2.2.20");
remote_vm_ip_ = Ip4Address::from_string("1.1.1.11");
test_listener_ = NULL;
agent_ = Agent::GetInstance();
};
~PathPreferenceRouteTableWalkerTest() {
}
void SetupEnvironment(int num_vrfs) {
client->Reset();
if (num_vrfs == 0)
return;
if (num_vrfs > 0) {
VrfAddReq(vrf_name_1_.c_str());
}
if (num_vrfs > 1) {
VrfAddReq(vrf_name_2_.c_str());
}
if (num_vrfs > 2) {
VrfAddReq(vrf_name_3_.c_str());
}
VrfEntry *vrf = VrfGet("vrf1", false);
WAIT_FOR(1000, 1000, vrf->GetEvpnRouteTable() != NULL);
EvpnAgentRouteTable *evpn_rt_table =
static_cast<EvpnAgentRouteTable*>(vrf->GetEvpnRouteTable());
test_listener_ =
new TestPathPreferenceRouteListener(agent_, evpn_rt_table);
client->WaitForIdle();
test_listener_->Init();
client->WaitForIdle();
InetInterfaceKey vhost_intf_key(
Agent::GetInstance()->vhost_interface()->name());
Agent::GetInstance()->fabric_inet4_unicast_table()->AddResolveRoute(
Agent::GetInstance()->local_peer(),
Agent::GetInstance()->fabric_vrf_name(), server_ip_, 24,
vhost_intf_key, 0, false, "", SecurityGroupList());
client->WaitForIdle();
client->WaitForIdle();
if (num_vrfs > 0) {
CreateVmportEnv(input_1, 1);
}
if (num_vrfs > 1) {
CreateVmportEnv(input_2, 1);
}
if (num_vrfs > 2) {
CreateVmportEnv(input_3, 1);
}
client->WaitForIdle();
client->Reset();
}
void DeleteEnvironment(int num_vrfs) {
client->Reset();
if (num_vrfs == 0)
return;
if (num_vrfs > 0) {
DeleteVmportEnv(input_1, 1, true);
}
if (num_vrfs > 1) {
DeleteVmportEnv(input_2, 1, true);
}
if (num_vrfs > 2) {
DeleteVmportEnv(input_3, 1, true);
}
client->WaitForIdle();
if (num_vrfs > 0) {
VrfDelReq(vrf_name_1_.c_str());
client->WaitForIdle();
WAIT_FOR(100, 100, (VrfFind(vrf_name_1_.c_str()) != true));
}
if (num_vrfs > 1) {
VrfDelReq(vrf_name_2_.c_str());
client->WaitForIdle();
WAIT_FOR(100, 100, (VrfFind(vrf_name_2_.c_str()) != true));
}
if (num_vrfs > 2) {
VrfDelReq(vrf_name_3_.c_str());
client->WaitForIdle();
WAIT_FOR(100, 100, (VrfFind(vrf_name_3_.c_str()) != true));
}
client->WaitForIdle();
}
virtual void SetUp() {
client->Reset();
VxLanNetworkIdentifierMode(false);
client->WaitForIdle();
AddEncapList("MPLSoGRE", "MPLSoUDP", "VXLAN");
client->WaitForIdle();
}
virtual void TearDown() {
client->Reset();
DelEncapList();
client->WaitForIdle();
}
std::string vrf_name_1_;
std::string vrf_name_2_;
std::string vrf_name_3_;
Ip4Address local_vm_ip_1_;
Ip4Address local_vm_ip_2_;
Ip4Address remote_vm_ip_;
Ip4Address server_ip_;
TestPathPreferenceRouteListener *test_listener_;
Agent *agent_;
};
TEST_F(PathPreferenceRouteTableWalkerTest, notify_on_deleted_before_walk_done) {
client->Reset();
SetupEnvironment(3);
VrfDelReq("vrf1");
client->WaitForIdle();
DBTableWalker *walker = agent_->db()->GetWalker();
VrfEntry *vrf = VrfGet("vrf1", true);
EvpnAgentRouteTable *evpn_rt_table =
static_cast<EvpnAgentRouteTable*>(vrf->GetEvpnRouteTable());
test_listener_->set_deleted();//Artificially mark it for delete
walker->WalkTable(evpn_rt_table, NULL,
boost::bind(&TestPathPreferenceRouteListener::DeleteState,
test_listener_, _1, _2),
boost::bind(&TestPathPreferenceRouteListener::Walkdone,
test_listener_, _1, test_listener_));
WAIT_FOR(1000, 1000, (test_listener_->walk_done_ == true));
DeleteEnvironment(3);
}
//TODO REMAINING TESTS
// - based on walktype - unicast/multicast/all
//
int main(int argc, char **argv) {
GETUSERARGS();
client = TestInit(init_file, ksync_init);
int ret = RUN_ALL_TESTS();
client->WaitForIdle();
TestShutdown();
delete client;
return ret;
}