10 #include <boost/asio/ip/host_name.hpp>
11 #include <boost/bind/bind.hpp>
12 #include <boost/date_time/posix_time/posix_time.hpp>
13 #include <boost/program_options.hpp>
15 #include "nodeinfo_types.h"
26 #include "bgp/bgp_peer_types.h"
36 #include "control-node/buildinfo.h"
46 #include "sandesh/common/vns_constants.h"
47 #include "sandesh/common/vns_types.h"
48 #include "sandesh/sandesh_http.h"
49 #include "sandesh/sandesh_trace.h"
50 #include "schema/bgp_schema_types.h"
51 #include "schema/vnc_cfg_types.h"
52 #include "xmpp/sandesh/xmpp_peer_info_types.h"
58 using namespace boost::asio::ip;
59 using process::ConnectionInfo;
62 using process::ProcessState;
63 using process::ConnectionType;
65 using process::g_process_info_constants;
67 using namespace boost::placeholders;
73 ifstream file(filename);
74 string content((istreambuf_iterator<char>(file)),
75 istreambuf_iterator<char>());
81 vnc_cfg_JsonParserInit(json_parser);
82 vnc_cfg_Server_ModuleInit(server->
database(), server->
graph());
83 bgp_schema_JsonParserInit(json_parser);
84 bgp_schema_Server_ModuleInit(server->
database(), server->
graph());
107 boost::system::error_code ec;
111 " conversion error:" << ec.message());
117 return (xmpp_server);
122 static const int kTimeout = 15;
125 for (
int i = 0; i < (kTimeout * 1000); i++) {
135 boost::scoped_ptr<BgpXmppChannelManager> *channel_manager) {
138 BgpServer *bgp_server = (*channel_manager)->bgp_server();
139 XmppServer *xmpp_server = (*channel_manager)->xmpp_server();
146 for (
int cnt = 0; xmpp_server->
ConnectionCount() != 0 && cnt < 15; cnt++) {
161 channel_manager->reset();
165 ConnectionStateManager::
166 GetInstance()->Shutdown();
180 static bool shutdown_;
182 if (shutdown_)
return;
191 const std::vector<ConnectionInfo> &cinfos,
193 std::vector<ConnectionTypeName> expected_connections) {
210 LOG(ERROR,
"SIGHUP handler ERROR: " << error);
213 LOG(WARN,
"Received signal " << sig <<
" inside ReConfigSignalHandler()");
214 options.ParseReConfig(force_reinit);
217 int main(
int argc,
char *argv[]) {
223 srand(
unsigned(time(NULL)));
224 std::vector<Signal::SignalHandler> sighup_handlers = boost::assign::list_of
226 std::vector<Signal::SignalHandler> sigusr1_handlers = boost::assign::list_of
228 std::vector<Signal::SignalHandler> sigterm_handler = boost::assign::list_of
230 Signal::SignalCallbackMap smap = boost::assign::map_list_of
231 (SIGHUP, sighup_handlers)
232 (SIGUSR1, sigusr1_handlers)
233 (SIGTERM, sigterm_handler);
240 string module_name = g_vns_constants.ModuleNames.find(module)->second;
241 std::string log_property_file =
options.log_property_file();
242 if (log_property_file.size()) {
243 logging.
Init(log_property_file);
247 options.syslog_facility(), module_name,
256 options.task_track_run_time());
277 boost::scoped_ptr<BgpServer> bgp_server(
new BgpServer(&
evm));
279 sandesh_context.
bgp_server = bgp_server.get();
281 bgp_server->set_mvpn_ipv4_enable(
options.mvpn_ipv4_enable());
283 ConnectionStateManager::GetInstance();
292 boost::scoped_ptr<ConfigClientManager> config_client_manager_ptr(
294 ConfigStaticObjectFactory::Create<ConfigJsonParserBase>(),
303 ifmap_server.set_config_manager(config_client_manager);
312 boost::system::error_code ec;
316 " conversion error: " << ec.message());
318 bgp_server->rtarget_group_mgr()->Initialize();
319 bgp_server->session_manager()->Initialize(
options.bgp_port(),
324 xmpp_cfg.dscp_value = bgp_server->global_qos()->control_dscp();
326 if (xmpp_server == NULL) {
331 boost::scoped_ptr<BgpXmppChannelManager> bgp_peer_manager(
335 ifmap_server.set_ifmap_channel_manager(&ifmap_channel_mgr);
349 std::vector<ConnectionTypeName> expected_connections;
350 expected_connections = boost::assign::list_of
352 ConnectionType::DATABASE)->second,
"Cassandra"))
354 ConnectionType::DATABASE)->second,
"RabbitMQ"))
356 ConnectionType::COLLECTOR)->second,
""))
357 .convert_to_container<vector<\
360 if (!
options.collectors_configured()) {
361 LOG(INFO,
"Collectors are not configured!");
362 expected_connections.pop_back();
365 ConnectionStateManager::GetInstance()->Init(
367 module_name, g_vns_constants.INSTANCE_ID_DEFAULT,
369 bgp_server.get(), config_client_manager, _1, _2, _3,
370 expected_connections),
"ObjectBgpRouter");
373 g_vns_constants.Module2NodeType.find(module)->second;
375 if (
options.collectors_configured()) {
379 g_vns_constants.NodeTypeNames.find(node_type)->second,
380 g_vns_constants.INSTANCE_ID_DEFAULT,
383 options.randomized_collector_server_list(),
389 g_vns_constants.ModuleNames.find(module)->second,
391 g_vns_constants.NodeTypeNames.find(node_type)->second,
392 g_vns_constants.INSTANCE_ID_DEFAULT,
407 bgp_peer_manager.get(),
410 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