Skip to content

Commit

Permalink
Merge "Walk Discovery Publisher list during service unavailability."
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Aug 17, 2016
2 parents e5cf9fa + e59f53c commit 98cf3ef
Show file tree
Hide file tree
Showing 5 changed files with 357 additions and 47 deletions.
16 changes: 15 additions & 1 deletion src/vnsw/agent/controller/controller_dns.cc
Expand Up @@ -112,7 +112,21 @@ void AgentDnsXmppChannel::HandleXmppClientChannelEvent(AgentDnsXmppChannel *peer
} else if (state == xmps::TIMEDOUT) {
DiscoveryAgentClient *dac = Agent::GetInstance()->discovery_client();
if (dac) {
dac->ReDiscoverDNS();
std::vector<DSResponse> resp =
Agent::GetInstance()->GetDiscoveryServerResponseList();
std::vector<DSResponse>::iterator iter;
for (iter = resp.begin(); iter != resp.end(); iter++) {
DSResponse dr = *iter;
if (peer->GetXmppServer().compare(
dr.ep.address().to_string()) == 0) {

// Add the TIMEDOUT server to the end.
if (iter+1 == resp.end()) break;
std::rotate(iter, iter+1, resp.end());
Agent::GetInstance()->controller()->ApplyDiscoveryDnsXmppServices(resp);
break;
}
}
}
}
}
Expand Down
30 changes: 19 additions & 11 deletions src/vnsw/agent/controller/controller_init.cc
Expand Up @@ -2,6 +2,7 @@
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/

#include <algorithm>
#include "base/logging.h"
#include "base/timer.h"
#include "base/contrail_ports.h"
Expand Down Expand Up @@ -438,11 +439,14 @@ void VNController::DisConnectControllerIfmapServer(uint8_t idx) {
agent_->reset_controller_ifmap_xmpp_server(idx);
}

bool VNController::AgentXmppServerExists(const std::string &server_ip,
std::vector<DSResponse> resp) {
bool VNController::AgentXmppServerConnectedExists(
const std::string &server_ip,
std::vector<DSResponse> resp) {

std::vector<DSResponse>::iterator iter;
for (iter = resp.begin(); iter != resp.end(); iter++) {
int8_t count = -1;
int8_t min_iter = std::min(static_cast<int>(resp.size()), MAX_XMPP_SERVERS);
for (iter = resp.begin(); ++count < min_iter; iter++) {
DSResponse dr = *iter;
if (dr.ep.address().to_string().compare(server_ip) == 0) {
return true;
Expand All @@ -462,15 +466,17 @@ bool VNController::ApplyDiscoveryXmppServicesInternal(std::vector<DSResponse> re
std::vector<DSResponse>::iterator iter;
int8_t count = -1;
agent_->UpdateDiscoveryServerResponseList(resp);
for (iter = resp.begin(); iter != resp.end(); iter++) {

/* Apply only MAX_XMPP_SERVERS from list as the list is ordered */
int8_t min_iter = std::min(static_cast<int>(resp.size()), MAX_XMPP_SERVERS);
for (iter = resp.begin(); ++count < min_iter; iter++) {
DSResponse dr = *iter;
count ++;

CONTROLLER_DISCOVERY_TRACE(DiscoveryConnection, "XMPP Discovery Server Response",
count, dr.ep.address().to_string(), integerToString(dr.ep.port()));

AgentXmppChannel *chnl = FindAgentXmppChannel(dr.ep.address().to_string());
if (chnl) {
if (chnl) {
if (chnl->GetXmppChannel() &&
chnl->GetXmppChannel()->GetPeerState() == xmps::READY) {
CONTROLLER_DISCOVERY_TRACE(DiscoveryConnection,
Expand Down Expand Up @@ -502,7 +508,7 @@ bool VNController::ApplyDiscoveryXmppServicesInternal(std::vector<DSResponse> re

} else if (agent_->controller_xmpp_channel(xs_idx)) {

if (AgentXmppServerExists(
if (AgentXmppServerConnectedExists(
agent_->controller_ifmap_xmpp_server(xs_idx), resp)) {

CONTROLLER_DISCOVERY_TRACE(DiscoveryConnection,
Expand Down Expand Up @@ -580,16 +586,18 @@ bool VNController::ApplyDiscoveryDnsXmppServicesInternal(
std::vector<DSResponse>::iterator iter;
int8_t count = -1;
agent_->UpdateDiscoveryDnsServerResponseList(resp);
for (iter = resp.begin(); iter != resp.end(); iter++) {

/* Apply only MAX_XMPP_SERVERS from list as the list is ordered */
int8_t min_iter = std::min(static_cast<int>(resp.size()), MAX_XMPP_SERVERS);
for (iter = resp.begin(); ++count < min_iter; iter++) {
DSResponse dr = *iter;
count++;

CONTROLLER_DISCOVERY_TRACE(DiscoveryConnection,
"DNS Discovery Server Response", count,
dr.ep.address().to_string(), integerToString(dr.ep.port()));

AgentDnsXmppChannel *chnl = FindAgentDnsXmppChannel(dr.ep.address().to_string());
if (chnl) {
if (chnl) {
if (chnl->GetXmppChannel() &&
chnl->GetXmppChannel()->GetPeerState() == xmps::READY) {
CONTROLLER_DISCOVERY_TRACE(DiscoveryConnection,
Expand Down Expand Up @@ -619,7 +627,7 @@ bool VNController::ApplyDiscoveryDnsXmppServicesInternal(

} else if (agent_->dns_xmpp_channel(xs_idx)) {

if (AgentXmppServerExists(
if (AgentXmppServerConnectedExists(
agent_->dns_server(xs_idx), resp)) {

CONTROLLER_DISCOVERY_TRACE(DiscoveryConnection,
Expand Down
2 changes: 1 addition & 1 deletion src/vnsw/agent/controller/controller_init.h
Expand Up @@ -183,7 +183,7 @@ class VNController {
AgentDnsXmppChannel *FindAgentDnsXmppChannel(const std::string &server_ip);
void DeleteConnectionInfo(const std::string &addr, bool is_dns) const;
const std::string MakeConnectionPrefix(bool is_dns) const;
bool AgentXmppServerExists(const std::string &server_ip,
bool AgentXmppServerConnectedExists(const std::string &server_ip,
std::vector<DSResponse> resp);
bool ApplyDiscoveryXmppServicesInternal(std::vector<DSResponse> resp);
bool ApplyDiscoveryDnsXmppServicesInternal(std::vector<DSResponse> resp);
Expand Down
16 changes: 15 additions & 1 deletion src/vnsw/agent/controller/controller_peer.cc
Expand Up @@ -1622,7 +1622,21 @@ void AgentXmppChannel::HandleAgentXmppClientChannelEvent(AgentXmppChannel *peer,
"NULL", "Connection to Xmpp Server, Timed out");
DiscoveryAgentClient *dac = Agent::GetInstance()->discovery_client();
if (dac) {
dac->ReDiscoverController();
std::vector<DSResponse> resp =
Agent::GetInstance()->GetDiscoveryServerResponseList();
std::vector<DSResponse>::iterator iter;
for (iter = resp.begin(); iter != resp.end(); iter++) {
DSResponse dr = *iter;
if (peer->GetXmppServer().compare(
dr.ep.address().to_string()) == 0) {

// Add the TIMEDOUT server to the end.
if (iter+1 == resp.end()) break;
std::rotate(iter, iter+1, resp.end());
agent->controller()->ApplyDiscoveryXmppServices(resp);
break;
}
}
}
}
}
Expand Down

0 comments on commit 98cf3ef

Please sign in to comment.