Skip to content

Commit

Permalink
Merge "Report status as non-functional if IFMap EndofRIB is not compu…
Browse files Browse the repository at this point in the history
…ted" into R2.20
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Aug 21, 2015
2 parents ff2ba2c + de0d390 commit 97e35be
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 82 deletions.
118 changes: 60 additions & 58 deletions src/control-node/main.cc
Expand Up @@ -479,18 +479,23 @@ void ControlNodeShutdown() {
evm.Shutdown();
}

static void ControlNodeGetProcessStateCb(const BgpServer *server,
static void ControlNodeGetProcessStateCb(const BgpServer *bgp_server,
const IFMapManager *ifmap_manager,
const std::vector<ConnectionInfo> &cinfos,
ProcessState::type &state, std::string &message,
size_t expected_connections) {
GetProcessStateCb(cinfos, state, message, expected_connections);
if (state == ProcessState::NON_FUNCTIONAL)
return;
if (server->bgp_identifier() &&
server->local_autonomous_system() && server->autonomous_system())
return;
state = ProcessState::NON_FUNCTIONAL;
message = "No BGP configuration for self";
if (!ifmap_manager->GetEndOfRibComputed()) {
state = ProcessState::NON_FUNCTIONAL;
message = "IFMap Server End-Of-RIB not computed";
} else if (!bgp_server->bgp_identifier() ||
!bgp_server->local_autonomous_system() ||
!bgp_server->autonomous_system()) {
state = ProcessState::NON_FUNCTIONAL;
message = "No BGP configuration for self";
}
}

int main(int argc, char *argv[]) {
Expand All @@ -508,8 +513,7 @@ int main(int argc, char *argv[]) {
std::string log_property_file = options.log_property_file();
if (log_property_file.size()) {
LoggingInit(log_property_file);
}
else {
} else {
LoggingInit(options.log_file(), options.log_file_size(),
options.log_files_count(), options.use_syslog(),
options.syslog_facility(), module_name);
Expand Down Expand Up @@ -559,7 +563,7 @@ int main(int argc, char *argv[]) {
Sandesh::SetLoggingParams(options.log_local(), options.log_category(),
options.log_level());

// XXX Disable logging -- for test purposes only
// Disable logging -- for test purposes only.
if (options.log_disable()) {
SetLoggingDisabled(true);
}
Expand All @@ -582,21 +586,20 @@ int main(int argc, char *argv[]) {
BgpConfigParser parser(&config_db);
parser.Parse(FileRead(options.bgp_config_file().c_str()));

bgp_server->rtarget_group_mgr()->Initialize();
// TODO: Initialize throws an exception (via boost) in case the
// user does not have permissions to bind to the port.

bgp_server->rtarget_group_mgr()->Initialize();
LOG(DEBUG, "Starting Bgp Server at port " << options.bgp_port());
if (!bgp_server->session_manager()->Initialize(options.bgp_port()))
exit(1);

//Create Xmpp Server
// Create Xmpp Server.
XmppChannelConfig xmpp_cfg(false);
XmppServer *xmpp_server = CreateXmppServer(&evm, &options, &xmpp_cfg);

// Register XMPP channel peers
// Create BGP and IFMap channel managers.
boost::scoped_ptr<BgpXmppChannelManager> bgp_peer_manager(
new BgpXmppChannelManager(xmpp_server, bgp_server.get()));
new BgpXmppChannelManager(xmpp_server, bgp_server.get()));
sandesh_context.xmpp_peer_manager = bgp_peer_manager.get();
IFMapChannelManager ifmap_channel_mgr(xmpp_server, &ifmap_server);
ifmap_server.set_ifmap_channel_manager(&ifmap_channel_mgr);
Expand All @@ -607,6 +610,16 @@ int main(int argc, char *argv[]) {
IFMapSandeshContext ifmap_sandesh_context(&ifmap_server);
Sandesh::set_module_context("IFMap", &ifmap_sandesh_context);

// Create IFMapManager and associate with the IFMapServer.
IFMapServerParser *ifmap_parser = IFMapServerParser::GetInstance("vnc_cfg");
IFMapManager *ifmap_manager = new IFMapManager(&ifmap_server,
options.ifmap_server_url(), options.ifmap_user(),
options.ifmap_password(), options.ifmap_certs_store(),
boost::bind(
&IFMapServerParser::Receive, ifmap_parser, &config_db, _1, _2, _3),
evm.io_service());
ifmap_server.set_ifmap_manager(ifmap_manager);

// Determine if the number of connections is as expected. At the moment,
// consider connections to collector, discovery server and IFMap (irond)
// servers as critical to the normal functionality of control-node.
Expand All @@ -616,76 +629,68 @@ int main(int argc, char *argv[]) {
// 3. Discovery Server subscribe Collector
// 4. Discovery Server subscribe IfmapServer
// 5. IFMap Server (irond)
ConnectionStateManager<NodeStatusUVE, NodeStatus>::
GetInstance()->Init(*evm.io_service(), options.hostname(),
module_name, g_vns_constants.INSTANCE_ID_DEFAULT,
boost::bind(&ControlNodeGetProcessStateCb,
bgp_server.get(), _1, _2, _3, 5));

//Register services with Discovery Service Server
DiscoveryServiceClient *ds_client = NULL;
ConnectionStateManager<NodeStatusUVE, NodeStatus>::GetInstance()->Init(
*evm.io_service(), options.hostname(),
module_name, g_vns_constants.INSTANCE_ID_DEFAULT,
boost::bind(&ControlNodeGetProcessStateCb,
bgp_server.get(), ifmap_manager, _1, _2, _3, 5));

// Parse discovery server configuration.
DiscoveryServiceClient *ds_client = NULL;
tcp::endpoint dss_ep;
if (DiscoveryServiceClient::ParseDiscoveryServerConfig(
options.discovery_server(), options.discovery_port(), &dss_ep)) {

string subscriber_name =
// Create and initialize discovery client.
string subscriber_name =
g_vns_constants.ModuleNames.find(Module::CONTROL_NODE)->second;
ds_client = new DiscoveryServiceClient(&evm, dss_ep, subscriber_name);
ds_client = new DiscoveryServiceClient(&evm, dss_ep, subscriber_name);
ds_client->Init();
// publish xmpp-server service

// Publish xmpp-server service.
ControlNode::SetSelfIp(options.host_ip());
if (!options.host_ip().empty()) {
stringstream pub_ss;
const std::string &sname(
g_vns_constants.XMPP_SERVER_DISCOVERY_SERVICE_NAME);
pub_ss << "<" << sname << "><ip-address>" << options.host_ip() <<
"</ip-address><port>" << options.xmpp_port() <<
"</port></" << sname << ">";
"</ip-address><port>" << options.xmpp_port() <<
"</port></" << sname << ">";
string pub_msg;
pub_msg = pub_ss.str();
ds_client->Publish(sname, pub_msg);
}

// subscribe to collector service if not configured
// Subscribe to collector service if collector isn't explicitly configured.
if (!options.collectors_configured()) {
Module::type module = Module::CONTROL_NODE;
NodeType::type node_type =
NodeType::type node_type =
g_vns_constants.Module2NodeType.find(module)->second;
string subscriber_name =
string subscriber_name =
g_vns_constants.ModuleNames.find(module)->second;
string node_type_name =
g_vns_constants.NodeTypeNames.find(node_type)->second;
string node_type_name =
g_vns_constants.NodeTypeNames.find(node_type)->second;
Sandesh::CollectorSubFn csf = 0;
csf = boost::bind(&DiscoveryServiceClient::Subscribe,
ds_client, _1, _2, _3);
vector<string> list;
list.clear();
Sandesh::InitGenerator(subscriber_name,
options.hostname(),
Sandesh::InitGenerator(subscriber_name, options.hostname(),
node_type_name,
g_vns_constants.INSTANCE_ID_DEFAULT,
&evm,
options.http_server_port(),
csf,
list,
&sandesh_context);
g_vns_constants.INSTANCE_ID_DEFAULT,
&evm, options.http_server_port(),
csf, list, &sandesh_context);
}
} else {
LOG(ERROR, "Invalid Discovery Server hostname or ip " <<
options.discovery_server());
LOG(ERROR, "Invalid Discovery Server hostname or address " <<
options.discovery_server());
}
ControlNode::SetDiscoveryServiceClient(ds_client);

IFMapServerParser *ifmap_parser = IFMapServerParser::GetInstance("vnc_cfg");

IFMapManager *ifmapmgr = new IFMapManager(&ifmap_server,
options.ifmap_server_url(), options.ifmap_user(),
options.ifmap_password(), options.ifmap_certs_store(),
boost::bind(&IFMapServerParser::Receive, ifmap_parser,
&config_db, _1, _2, _3), evm.io_service(),
ds_client);
ifmap_server.set_ifmap_manager(ifmapmgr);
// Initialize discovery mechanism for IFMapManager.
// Must happen after call to ConnectionStateManager::Init to ensure that
// ConnectionState is not updated before the ConnectionStateManager gets
// initialized.
ifmap_manager->InitializeDiscovery(ds_client, options.ifmap_server_url());

CpuLoadData::Init();
uint64_t start_time = UTCTimestampUsec();
Expand All @@ -702,18 +707,15 @@ int main(int argc, char *argv[]) {
start_time, node_info_log_timer.get()),
TaskScheduler::GetInstance()->GetTaskId("bgp::Config"), 0));

// Start Periodic timer to send BGPRouterInfo UVE
// Start periodic timer to send BGPRouterInfo UVE.
node_info_log_timer->Start(
60 * 1000,
boost::bind(&ControlNodeInfoLogTimer, node_info_trigger.get()),
NULL);

/*
* Event loop
*/
// Event loop.
evm.Run();

ShutdownServers(&bgp_peer_manager, ds_client, node_info_log_timer.get());

return 0;
}
3 changes: 2 additions & 1 deletion src/dns/main.cc
Expand Up @@ -250,8 +250,9 @@ int main(int argc, char *argv[]) {
options.ifmap_password(), options.ifmap_certs_store(),
boost::bind(&IFMapServerParser::Receive, ifmap_parser,
&config_db, _1, _2, _3),
Dns::GetEventManager()->io_service(), ds_client);
Dns::GetEventManager()->io_service());
ifmap_server.set_ifmap_manager(ifmapmgr);
ifmapmgr->InitializeDiscovery(ds_client, options.ifmap_server_url());

Dns::GetEventManager()->Run();

Expand Down
1 change: 1 addition & 0 deletions src/ifmap/client/ifmap_channel.cc
Expand Up @@ -645,6 +645,7 @@ bool IFMapChannel::EndOfRibProcTimeout() {
IFMAP_PEER_DEBUG(IFMapServerConnection, integerToString(timeout),
"millisecond end of rib timer fired");
set_end_of_rib_computed(true);
process::ConnectionState::GetInstance()->Update();
return false;
}

Expand Down
6 changes: 4 additions & 2 deletions src/ifmap/client/ifmap_channel.h
Expand Up @@ -172,11 +172,13 @@ class IFMapChannel {
void set_start_stale_entries_cleanup(bool value) {
start_stale_entries_cleanup_ = value;
}
bool start_stale_entries_cleanup() { return start_stale_entries_cleanup_; }
bool start_stale_entries_cleanup() const {
return start_stale_entries_cleanup_;
}
void set_end_of_rib_computed(bool value) {
end_of_rib_computed_ = value;
}
bool end_of_rib_computed() { return end_of_rib_computed_; }
bool end_of_rib_computed() const { return end_of_rib_computed_; }
bool EndOfRibTimerRunning();

private:
Expand Down
24 changes: 9 additions & 15 deletions src/ifmap/client/ifmap_manager.cc
Expand Up @@ -14,20 +14,6 @@
#include <boost/function.hpp>
#include <boost/asio/io_service.hpp>

IFMapManager::IFMapManager(IFMapServer *ifmap_server, const std::string& url,
const std::string& user, const std::string& passwd,
const std::string& certstore, PollReadCb readcb,
boost::asio::io_service *io_service,
DiscoveryServiceClient *ds_client)
: pollreadcb_(readcb), io_service_(io_service),
channel_(new IFMapChannel(this, user, passwd, certstore)),
state_machine_(new IFMapStateMachine(this)),
peer_finder_(new PeerIFMapServerFinder(this, ds_client, url)),
ifmap_server_(ifmap_server) {

ifmap_server->set_ifmap_manager(this);
}

IFMapManager::IFMapManager(IFMapServer *ifmap_server, const std::string& url,
const std::string& user, const std::string& passwd,
const std::string& certstore, PollReadCb readcb,
Expand All @@ -36,7 +22,6 @@ IFMapManager::IFMapManager(IFMapServer *ifmap_server, const std::string& url,
channel_(new IFMapChannel(this, user, passwd, certstore)),
state_machine_(new IFMapStateMachine(this)), peer_finder_(NULL),
ifmap_server_(ifmap_server) {

ifmap_server->set_ifmap_manager(this);
}

Expand All @@ -48,6 +33,11 @@ IFMapManager::IFMapManager()
IFMapManager::~IFMapManager() {
}

void IFMapManager::InitializeDiscovery(DiscoveryServiceClient *ds_client,
const std::string& url) {
peer_finder_.reset(new PeerIFMapServerFinder(this, ds_client, url));
}

void IFMapManager::Start(const std::string &host, const std::string &port) {
channel_->SetHostPort(host, port);
channel_->set_sm(state_machine_.get());
Expand All @@ -64,6 +54,10 @@ uint64_t IFMapManager::GetChannelSequenceNumber() {
return channel_->get_sequence_number();
}

bool IFMapManager::GetEndOfRibComputed() const {
return channel_->end_of_rib_computed();
}

void IFMapManager::SetStartStaleEntriesCleanup(bool value) {
channel_->set_start_stale_entries_cleanup(value);
}
Expand Down
9 changes: 3 additions & 6 deletions src/ifmap/client/ifmap_manager.h
Expand Up @@ -29,14 +29,10 @@ class IFMapManager {
const std::string& user, const std::string& passwd,
const std::string& certstore, PollReadCb readcb,
boost::asio::io_service *io_service);
IFMapManager(IFMapServer *ifmap_server, const std::string& url,
const std::string& user, const std::string& passwd,
const std::string& certstore, PollReadCb readcb,
boost::asio::io_service *io_service,
DiscoveryServiceClient *ds_client);

virtual ~IFMapManager();

void InitializeDiscovery(DiscoveryServiceClient *ds_client,
const std::string& url);
virtual void Start(const std::string &host, const std::string &port);

boost::asio::io_service *io_service() { return io_service_; }
Expand All @@ -50,6 +46,7 @@ class IFMapManager {
}
std::string get_url();
uint64_t GetChannelSequenceNumber();
bool GetEndOfRibComputed() const;
void GetPeerServerInfo(IFMapPeerServerInfoUI &server_info);
void RetrieveStaticHostPort(const std::string& url);
void GetAllDSPeerInfo(IFMapDSPeerInfo *ds_peer_info);
Expand Down

0 comments on commit 97e35be

Please sign in to comment.