11 #include <boost/asio/ip/host_name.hpp>
12 #include <boost/bind/bind.hpp>
13 #include <boost/date_time/posix_time/posix_time.hpp>
14 #include <boost/program_options.hpp>
16 #include "nodeinfo_types.h"
27 #include "bgp/bgp_peer_types.h"
37 #include "control-node/buildinfo.h"
47 #include "sandesh/common/vns_constants.h"
48 #include "sandesh/common/vns_types.h"
49 #include "sandesh/sandesh_http.h"
50 #include "sandesh/sandesh_trace.h"
51 #include "schema/bgp_schema_types.h"
52 #include "schema/vnc_cfg_types.h"
53 #include "xmpp/sandesh/xmpp_peer_info_types.h"
59 using namespace boost::asio::ip;
60 using process::ConnectionInfo;
63 using process::ProcessState;
64 using process::ConnectionType;
66 using process::g_process_info_constants;
68 using namespace boost::placeholders;
74 ifstream file(filename);
75 string content((istreambuf_iterator<char>(file)),
76 istreambuf_iterator<char>());
82 vnc_cfg_JsonParserInit(json_parser);
83 vnc_cfg_Server_ModuleInit(server->
database(), server->
graph());
84 bgp_schema_JsonParserInit(json_parser);
85 bgp_schema_Server_ModuleInit(server->
database(), server->
graph());
108 boost::system::error_code ec;
112 " conversion error:" << ec.message());
118 return (xmpp_server);
123 static const int kTimeout = 15;
126 for (
int i = 0; i < (kTimeout * 1000); i++) {
136 boost::scoped_ptr<BgpXmppChannelManager> *channel_manager) {
139 BgpServer *bgp_server = (*channel_manager)->bgp_server();
140 XmppServer *xmpp_server = (*channel_manager)->xmpp_server();
147 for (
int cnt = 0; xmpp_server->
ConnectionCount() != 0 && cnt < 15; cnt++) {
162 channel_manager->reset();
166 ConnectionStateManager::
167 GetInstance()->Shutdown();
181 static bool shutdown_;
183 if (shutdown_)
return;
192 const std::vector<ConnectionInfo> &cinfos,
194 std::vector<ConnectionTypeName> expected_connections) {
211 LOG(ERROR,
"SIGHUP handler ERROR: " << error);
214 LOG(WARN,
"Received signal " << sig <<
" inside ReConfigSignalHandler()");
215 options.ParseReConfig(force_reinit);
218 int main(
int argc,
char *argv[]) {
224 srand(
unsigned(time(NULL)));
225 std::vector<Signal::SignalHandler> sighup_handlers = boost::assign::list_of
227 std::vector<Signal::SignalHandler> sigusr1_handlers = boost::assign::list_of
229 std::vector<Signal::SignalHandler> sigterm_handler = boost::assign::list_of
231 Signal::SignalCallbackMap smap = boost::assign::map_list_of
232 (SIGHUP, sighup_handlers)
233 (SIGUSR1, sigusr1_handlers)
234 (SIGTERM, sigterm_handler);
241 string module_name = g_vns_constants.ModuleNames.find(module)->second;
242 std::string log_property_file =
options.log_property_file();
243 if (log_property_file.size()) {
244 logging.
Init(log_property_file);
248 options.syslog_facility(), module_name,
257 options.task_track_run_time());
278 boost::scoped_ptr<BgpServer> bgp_server(
new BgpServer(&
evm));
280 sandesh_context.
bgp_server = bgp_server.get();
282 bgp_server->set_mvpn_ipv4_enable(
options.mvpn_ipv4_enable());
284 ConnectionStateManager::GetInstance();
293 boost::scoped_ptr<ConfigClientManager> config_client_manager_ptr(
295 ConfigStaticObjectFactory::Create<ConfigJsonParserBase>(),
304 ifmap_server.set_config_manager(config_client_manager);
313 boost::system::error_code ec;
317 " conversion error: " << ec.message());
319 bgp_server->rtarget_group_mgr()->Initialize();
320 bgp_server->session_manager()->Initialize(
options.bgp_port(),
325 xmpp_cfg.dscp_value = bgp_server->global_qos()->control_dscp();
327 if (xmpp_server == NULL) {
332 boost::scoped_ptr<BgpXmppChannelManager> bgp_peer_manager(
336 ifmap_server.set_ifmap_channel_manager(&ifmap_channel_mgr);
350 std::vector<ConnectionTypeName> expected_connections;
351 expected_connections = boost::assign::list_of
353 ConnectionType::DATABASE)->second,
"Cassandra"))
355 ConnectionType::DATABASE)->second,
"RabbitMQ"))
357 ConnectionType::COLLECTOR)->second,
""))
358 .convert_to_container<vector<\
361 if (!
options.collectors_configured()) {
362 LOG(INFO,
"Collectors are not configured!");
363 expected_connections.pop_back();
366 ConnectionStateManager::GetInstance()->Init(
368 module_name, g_vns_constants.INSTANCE_ID_DEFAULT,
370 bgp_server.get(), config_client_manager, _1, _2, _3,
371 expected_connections),
"ObjectBgpRouter");
374 g_vns_constants.Module2NodeType.find(module)->second;
376 if (
options.collectors_configured()) {
380 g_vns_constants.NodeTypeNames.find(node_type)->second,
381 g_vns_constants.INSTANCE_ID_DEFAULT,
384 options.randomized_collector_server_list(),
390 g_vns_constants.ModuleNames.find(module)->second,
392 g_vns_constants.NodeTypeNames.find(node_type)->second,
393 g_vns_constants.INSTANCE_ID_DEFAULT,
408 bgp_peer_manager.get(),
411 options.set_config_client_manager(config_client_manager);
boost::asio::ip::address IpAddress
IpAddress AddressFromString(const std::string &ip_address_str, boost::system::error_code *ec)
void RegisterSandeshShowIfmapHandlers(BgpSandeshContext *bsc)
void RegisterSandeshShowXmppExtensions(BgpSandeshContext *bsc)
void Initialize(DB *db, DBGraph *db_graph, const std::string &localname)
RoutingInstanceMgr * routing_instance_mgr()
void set_gr_helper_disable(bool gr_helper_disable)
bool HasSelfConfiguration() const
bool GetEndOfRibComputed() const
ConfigJsonParserBase * config_json_parser()
static int GetNumWorkers()
void ifmap_server_set(IFMapServer *ifmap_server)
static std::string GetProcessState(bool bgpHasSelfConfiguration, bool bgpIsAdminDown, bool configEndOfRibComputed, process::ProcessState::type *state, std::string *message)
static void SetSelfIp(std::string ip)
static void SetTestMode(const bool flag)
static void StartControlNodeInfoLogger(EventManager &evm, uint64_t period_msecs, const BgpServer *server, const BgpXmppChannelManager *xmpp_channel_mgr, const IFMapServer *ifmap_server, const string &build_info)
static void SetHostname(const std::string name)
static void SetProgramName(const char *name)
static void SetDefaultSchedulingPolicy()
static bool GetTestMode()
boost::asio::io_context * io_service()
A class providing basic control over logging capabilities in OpenSDN control plane.
void Init()
Performs basic initialization of the logging system ( log4cplus).
static void set_module_context(const std::string &module_name, SandeshContext *context)
static bool InitGenerator(const std::string &module, const std::string &source, const std::string &node_type, const std::string &instance_id, EventManager *evm, unsigned short http_port, const std::vector< std::string > &collectors, SandeshContext *client_context=NULL, DerivedStats ds=DerivedStats(), const SandeshConfig &config=SandeshConfig())
std::map< std::string, std::map< std::string, std::string > > DerivedStats
static void SetLoggingParams(bool enable_local_log, std::string category, std::string level, bool enable_trace_print=false, bool enable_flow_log=false, bool enable_session_syslog=false)
static SandeshLevel::type StringToLevel(std::string level)
The TaskScheduler keeps track of what tasks are currently schedulable. When a task is enqueued it is ...
static int GetDefaultThreadCount()
void SetTrackRunTime(bool value)
static void Initialize(uint32_t thread_count=0, EventManager *evm=NULL)
static TaskScheduler * GetInstance()
bool IsEmpty(bool running_only=false)
Returns true if there are no tasks running and/or enqueued If running_only is true,...
static void DeleteServer(TcpServer *server)
boost::asio::ip::tcp::endpoint endpoint
std::string path_to_ca_cert
std::string path_to_server_cert
std::string path_to_server_priv_key
static const char * kControlNodeJID
size_t ConnectionCount() const
virtual bool Initialize(short port)
#define CONTROL_NODE_EXIT(message)
void ControlNodeShutdown()
static void IFMap_Initialize(IFMapServer *server, ConfigJsonParser *json_parser)
void SigTermSignalHandler(const boost::system::error_code &error, int sig, bool force_reinit)
void ReConfigSignalHandler(const boost::system::error_code &error, int sig, bool force_reinit)
static string FileRead(const char *filename)
static void ShutdownServers(boost::scoped_ptr< BgpXmppChannelManager > *channel_manager)
static void ControlNodeGetProcessStateCb(const BgpServer *bgp_server, const ConfigClientManager *config_client_manager, const std::vector< ConnectionInfo > &cinfos, ProcessState::type &state, std::string &message, std::vector< ConnectionTypeName > expected_connections)
static void WaitForIdle()
static XmppServer * CreateXmppServer(EventManager *evm, Options *options, XmppChannelConfig *xmpp_cfg)
void IFMapLinkTable_Init(DB *db, DBGraph *graph)
void SetLoggingDisabled(bool flag)
#define LOG(_Level, _Msg)
void GetProcessStateCb(const vector< ConnectionInfo > &cinfos, ProcessState::type &state, string &message, const vector< ConnectionTypeName > &expected_connections)
std::pair< std::string, std::string > ConnectionTypeName
log4cplus::LogLevel SandeshLevelTolog4Level(SandeshLevel::type slevel)
BgpXmppChannelManager * xmpp_peer_manager
void set_test_mode(bool test_mode)
const std::string BuildInfo