Skip to content

Commit

Permalink
Merge "Handle Session Close before established processing" into R2.20
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Jul 13, 2015
2 parents 52ed1af + c053208 commit 703b16b
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 10 deletions.
Expand Up @@ -127,6 +127,9 @@ void OvsdbClientSession::OnEstablish() {

void OvsdbClientSession::OnClose() {
OVSDB_SESSION_TRACE(Trace, this, "Connection to client Closed");
if (!idl_inited_) {
return;
}
client_idl_->TriggerDeletion();
}

Expand Down
24 changes: 18 additions & 6 deletions src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_tcp.cc
Expand Up @@ -78,6 +78,10 @@ void OvsdbClientTcp::set_connect_complete_cb(SessionEventCb cb) {
connect_complete_cb_ = cb;
}

void OvsdbClientTcp::set_pre_connect_complete_cb(SessionEventCb cb) {
pre_connect_complete_cb_ = cb;
}

OvsdbClientSession *OvsdbClientTcp::FindSession(Ip4Address ip, uint16_t port) {
// match both ip and port with available session
// if port is not provided match only ip
Expand Down Expand Up @@ -222,12 +226,20 @@ bool OvsdbClientTcpSession::ProcessSessionEvent(OvsdbSessionEvent ovs_event) {
}
break;
case TcpSession::CONNECT_COMPLETE:
ec = SetSocketOptions();
assert(ec.value() == 0);
set_status("Established");
OnEstablish();
if (!ovs_server->connect_complete_cb_.empty()) {
ovs_server->connect_complete_cb_(this);
if (!ovs_server->pre_connect_complete_cb_.empty()) {
ovs_server->pre_connect_complete_cb_(this);
}
if (!IsClosed()) {
ec = SetSocketOptions();
assert(ec.value() == 0);
set_status("Established");
OnEstablish();
if (!ovs_server->connect_complete_cb_.empty()) {
ovs_server->connect_complete_cb_(this);
}
} else {
OVSDB_SESSION_TRACE(Trace, this, "Skipping connection complete on"
" closed session");
}
break;
default:
Expand Down
2 changes: 2 additions & 0 deletions src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_tcp.h
Expand Up @@ -118,6 +118,7 @@ class OvsdbClientTcp : public TcpServer, public OvsdbClient {

// Used by Test Code to trigger events in specific order
void set_connect_complete_cb(SessionEventCb cb);
void set_pre_connect_complete_cb(SessionEventCb cb);

// API to shutdown the TCP server
void shutdown();
Expand All @@ -136,6 +137,7 @@ class OvsdbClientTcp : public TcpServer, public OvsdbClient {
Ip4Address tsn_ip_;
bool shutdown_;
SessionEventCb connect_complete_cb_;
SessionEventCb pre_connect_complete_cb_;
DISALLOW_COPY_AND_ASSIGN(OvsdbClientTcp);
};
};
Expand Down
30 changes: 26 additions & 4 deletions src/vnsw/agent/ovs_tor_agent/ovsdb_client/test/test_ovs_event.cc
Expand Up @@ -144,14 +144,15 @@ class OvsdbEventTest : public ::testing::Test {
}

void ImmediateCloseSessionEvent(OvsdbClientTcpSession *session) {
if (session->client_idl()->deleted()) {
return;
if (session->client_idl() && !session->client_idl()->deleted()) {
// take reference for idl to validate
immediate_close_idl_ = session->client_idl();
}
// 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;
Expand Down Expand Up @@ -190,6 +191,27 @@ TEST_F(OvsdbEventTest, ImmediateConnectionDown) {
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
Expand Down

0 comments on commit 703b16b

Please sign in to comment.