-
Notifications
You must be signed in to change notification settings - Fork 390
/
test_ovs_event.cc
232 lines (199 loc) · 7.66 KB
/
test_ovs_event.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
/*
* Copyright (c) 2015 Juniper Networks, Inc. All rights reserved.
*/
#include "base/os.h"
#include "testing/gunit.h"
#include <base/logging.h>
#include <io/event_manager.h>
#include <io/test/event_manager_test.h>
#include <tbb/task.h>
#include <base/task.h>
#include <cmn/agent_cmn.h>
#include "cfg/cfg_init.h"
#include "cfg/cfg_interface.h"
#include "pkt/pkt_init.h"
#include "services/services_init.h"
#include "vrouter/ksync/ksync_init.h"
#include "oper/interface_common.h"
#include "oper/nexthop.h"
#include "oper/tunnel_nh.h"
#include "route/route.h"
#include "oper/vrf.h"
#include "oper/mpls.h"
#include "oper/vm.h"
#include "oper/vn.h"
#include "filter/acl.h"
#include "openstack/instance_service_server.h"
#include "test_cmn_util.h"
#include "vr_types.h"
#include "openstack/instance_service_server.h"
#include "xmpp/xmpp_init.h"
#include "xmpp/test/xmpp_test_util.h"
#include "vr_types.h"
#include "control_node_mock.h"
#include "xml/xml_pugi.h"
#include "controller/controller_peer.h"
#include "controller/controller_export.h"
#include "controller/controller_vrf_export.h"
#include "ovs_tor_agent/ovsdb_client/ovsdb_route_peer.h"
#include "ovs_tor_agent/ovsdb_client/physical_switch_ovsdb.h"
#include "ovs_tor_agent/ovsdb_client/logical_switch_ovsdb.h"
#include "ovs_tor_agent/ovsdb_client/physical_port_ovsdb.h"
#include "ovs_tor_agent/ovsdb_client/unicast_mac_local_ovsdb.h"
#include "test_ovs_agent_init.h"
#include "test-xml/test_xml.h"
#include "test-xml/test_xml_oper.h"
#include "test_xml_physical_device.h"
#include "test_xml_ovsdb.h"
#include "test_ovs_agent_util.h"
#include <ovsdb_types.h>
using namespace pugi;
using namespace OVSDB;
using namespace boost::uuids;
EventManager evm1;
ServerThread *thread1;
test::ControlNodeMock *bgp_peer1;
EventManager evm2;
ServerThread *thread2;
test::ControlNodeMock *bgp_peer2;
void RouterIdDepInit(Agent *agent) {
Agent::GetInstance()->controller()->Connect();
}
class OvsdbEventTest : public ::testing::Test {
public:
OvsdbEventTest() {
}
UnicastMacLocalEntry *FindUcastLocal(const string &logical_switch,
const string &mac) {
UnicastMacLocalOvsdb *table =
tcp_session_->client_idl()->unicast_mac_local_ovsdb();
UnicastMacLocalEntry key(table, logical_switch, mac);
UnicastMacLocalEntry *entry =
static_cast<UnicastMacLocalEntry *> (table->Find(&key));
return entry;
}
virtual void SetUp() {
agent_ = Agent::GetInstance();
init_ = static_cast<TestOvsAgentInit *>(client->agent_init());
peer_manager_ = init_->ovs_peer_manager();
WAIT_FOR(100, 10000,
(tcp_session_ = static_cast<OvsdbClientTcpSession *>
(init_->ovsdb_client()->NextSession(NULL))) != NULL);
WAIT_FOR(100, 10000,
(tcp_session_->client_idl() != NULL));
WAIT_FOR(100, 10000, (tcp_session_->status() == string("Established")));
AgentUtXmlTest test("controller/src/vnsw/agent/ovs_tor_agent/ovsdb_"
"client/test/xml/ucast-local-test-setup.xml");
// set current session in test context
OvsdbTestSetSessionContext(tcp_session_);
AgentUtXmlOperInit(&test);
AgentUtXmlPhysicalDeviceInit(&test);
AgentUtXmlOvsdbInit(&test);
if (test.Load() == true) {
test.ReadXml();
string str;
test.ToString(&str);
cout << str << endl;
test.Run();
}
}
virtual void TearDown() {
AgentUtXmlTest test("controller/src/vnsw/agent/ovs_tor_agent/ovsdb_"
"client/test/xml/ucast-local-test-teardown.xml");
// set current session in test context
OvsdbTestSetSessionContext(tcp_session_);
AgentUtXmlOperInit(&test);
AgentUtXmlPhysicalDeviceInit(&test);
AgentUtXmlOvsdbInit(&test);
if (test.Load() == true) {
test.ReadXml();
string str;
test.ToString(&str);
cout << str << endl;
test.Run();
}
}
void NoOpSessionEvent(OvsdbClientTcpSession *session) {
}
void ImmediateCloseSessionEventDone(OvsdbClientTcpSession *session) {
immediate_close_done_ = true;
tcp_session_ = session;
OvsdbClientTcp *ovs_server =
static_cast<OvsdbClientTcp *>(init_->ovsdb_client());
ovs_server->set_connect_complete_cb(
boost::bind(&OvsdbEventTest::NoOpSessionEvent, this, _1));
}
void ImmediateCloseSessionEvent(OvsdbClientTcpSession *session) {
if (session->client_idl() && !session->client_idl()->deleted()) {
// take reference for idl to validate
immediate_close_idl_ = session->client_idl();
}
session->TriggerClose();
OvsdbClientTcp *ovs_server =
static_cast<OvsdbClientTcp *>(init_->ovsdb_client());
ovs_server->set_pre_connect_complete_cb(
boost::bind(&OvsdbEventTest::NoOpSessionEvent, this, _1));
ovs_server->set_connect_complete_cb(
boost::bind(&OvsdbEventTest::ImmediateCloseSessionEventDone, this, _1));
tcp_session_ = NULL;
}
Agent *agent_;
TestOvsAgentInit *init_;
OvsPeerManager *peer_manager_;
OvsdbClientTcpSession *tcp_session_;
OvsdbClientIdlPtr immediate_close_idl_;
tbb::atomic<bool> immediate_close_done_;
};
TEST_F(OvsdbEventTest, ImmediateConnectionDown) {
TestTaskHold *hold =
new TestTaskHold(TaskScheduler::GetInstance()->GetTaskId("db::DBTableStop"), 0);
OvsdbClientTcp *ovs_server =
static_cast<OvsdbClientTcp *>(init_->ovsdb_client());
ovs_server->set_connect_complete_cb(
boost::bind(&OvsdbEventTest::ImmediateCloseSessionEvent, this, _1));
immediate_close_done_ = false;
tcp_session_->TriggerClose();
// wait for completion of immediate_close
WAIT_FOR(500, 10000, (immediate_close_done_ == true));
// wait for idl table delete complete
// only ref count remaining for session and test code
WAIT_FOR(300, 10000, (immediate_close_idl_->refcount() == 2));
immediate_close_idl_ = NULL;
WAIT_FOR(100, 10000, tcp_session_ != NULL &&
tcp_session_->status() == string("Established"));
delete hold;
client->WaitForIdle();
}
TEST_F(OvsdbEventTest, ImmediateConnectionDownBeforeEstablish) {
TestTaskHold *hold =
new TestTaskHold(TaskScheduler::GetInstance()->GetTaskId("db::DBTableStop"), 0);
OvsdbClientTcp *ovs_server =
static_cast<OvsdbClientTcp *>(init_->ovsdb_client());
// Set callback to close the session before processing connect complete event
ovs_server->set_pre_connect_complete_cb(
boost::bind(&OvsdbEventTest::ImmediateCloseSessionEvent, this, _1));
immediate_close_done_ = false;
tcp_session_->TriggerClose();
// wait for completion of immediate_close
WAIT_FOR(500, 10000, (immediate_close_done_ == true));
WAIT_FOR(100, 10000, tcp_session_ != NULL &&
tcp_session_->status() == string("Established"));
delete hold;
client->WaitForIdle();
}
int main(int argc, char *argv[]) {
GETUSERARGS();
// override with true to initialize ovsdb server and client
ksync_init = true;
client = OvsTestInit(init_file, ksync_init);
// create a task exclusion policy to hold db::DBTable task
TaskScheduler *scheduler = TaskScheduler::GetInstance();
TaskPolicy policy;
int task_id = scheduler->GetTaskId("db::DBTable");
policy.push_back(TaskExclusion(task_id));
scheduler->SetPolicy(scheduler->GetTaskId("db::DBTableStop"), policy);
client->WaitForIdle();
int ret = RUN_ALL_TESTS();
TestShutdown();
return ret;
}