diff --git a/src/analytics/main.cc b/src/analytics/main.cc index 95e0c5532b0..d88f5e6de6a 100644 --- a/src/analytics/main.cc +++ b/src/analytics/main.cc @@ -44,7 +44,7 @@ using process::GetProcessStateCb; static TaskTrigger *collector_info_trigger; static Timer *collector_info_log_timer; -static EventManager * a_evm = NULL; +static EventManager * a_evm = NULL; bool CollectorInfoLogTimer() { collector_info_trigger->Set(); @@ -180,7 +180,7 @@ void CollectorShutdown() { static void terminate(int param) { // Shutdown can result in a malloc-detected error - // Taking a stack trace during this error can result in + // Taking a stack trace during this error can result in // the process not terminating correctly // using mallopt in this way ensures that we get a core, // but we don't print a stack trace @@ -251,10 +251,15 @@ int main(int argc, char *argv[]) NodeType::type node_type = g_vns_constants.Module2NodeType.find(module)->second; std::string instance_id(g_vns_constants.INSTANCE_ID_DEFAULT); - LoggingInit(options.log_file(), options.log_file_size(), - options.log_files_count(), options.use_syslog(), - options.syslog_facility(), module_id); - + std::string log_property_file = options.log_property_file(); + if (log_property_file.size()) { + LoggingInit(log_property_file); + } + else { + LoggingInit(options.log_file(), options.log_file_size(), + options.log_files_count(), options.use_syslog(), + options.syslog_facility(), module_id); + } vector cassandra_servers(options.cassandra_server_list()); vector cassandra_ips; vector cassandra_ports; @@ -358,7 +363,7 @@ int main(int argc, char *argv[]) module_id, analytics.name(), g_vns_constants.NodeTypeNames.find(node_type)->second, - instance_id, + instance_id, a_evm, "127.0.0.1", options.collector_port(), options.http_server_port(), &vsc); @@ -395,7 +400,6 @@ int main(int argc, char *argv[]) pub_msg = pub_ss.str(); ds_client->Publish(service_name, pub_msg); } - CpuLoadData::Init(); collector_info_trigger = new TaskTrigger(boost::bind(&CollectorInfoLogger, vsc), diff --git a/src/analytics/options.cc b/src/analytics/options.cc index 8ef9656a9a1..2b4c94b491e 100644 --- a/src/analytics/options.cc +++ b/src/analytics/options.cc @@ -111,6 +111,8 @@ void Options::Initialize(EventManager &evm, "Disable sandesh logging") ("DEFAULT.log_file", opt::value()->default_value(""), "Filename for the logs to be written to") + ("DEFAULT.log_property_file", opt::value()->default_value(""), + "log4cplus property file name") ("DEFAULT.log_files_count", opt::value()->default_value(10), "Maximum log file roll over index") @@ -196,7 +198,7 @@ void Options::GetOptValueImpl( std::vector tmp( var_map[val].as >()); // Now split the individual elements - for (typename std::vector::const_iterator it = + for (typename std::vector::const_iterator it = tmp.begin(); it != tmp.end(); it++) { std::stringstream ss(*it); @@ -275,6 +277,7 @@ void Options::Process(int argc, char *argv[], GetOptValue(var_map, log_category_, "DEFAULT.log_category"); GetOptValue(var_map, log_file_, "DEFAULT.log_file"); + GetOptValue(var_map, log_property_file_, "DEFAULT.log_property_file"); GetOptValue(var_map, log_files_count_, "DEFAULT.log_files_count"); GetOptValue(var_map, log_file_size_, "DEFAULT.log_file_size"); GetOptValue(var_map, log_level_, "DEFAULT.log_level"); diff --git a/src/analytics/options.h b/src/analytics/options.h index 9c0493e2572..528ce4482bf 100644 --- a/src/analytics/options.h +++ b/src/analytics/options.h @@ -36,6 +36,7 @@ class Options { const std::string log_category() const { return log_category_; } const bool log_disable() const { return log_disable_; } const std::string log_file() const { return log_file_; } + const std::string log_property_file() const { return log_property_file_; } const int log_files_count() const { return log_files_count_; } const long log_file_size() const { return log_file_size_; } const std::string log_level() const { return log_level_; } @@ -93,6 +94,7 @@ class Options { std::string log_category_; bool log_disable_; std::string log_file_; + std::string log_property_file_; int log_files_count_; long log_file_size_; std::string log_level_; diff --git a/src/base/logging.cc b/src/base/logging.cc index 0a37a16d3dd..3500f94c05d 100644 --- a/src/base/logging.cc +++ b/src/base/logging.cc @@ -81,3 +81,10 @@ void LoggingInit(const std::string &filename, long maxFileSize, int maxBackupInd CheckEnvironmentAndUpdate(); } + + +void LoggingInit(const std::string &propertyFile) { + PropertyConfigurator::doConfigure(propertyFile); + CheckEnvironmentAndUpdate(); +} + diff --git a/src/base/logging.h b/src/base/logging.h index cdb58c1d63b..be256840823 100644 --- a/src/base/logging.h +++ b/src/base/logging.h @@ -45,6 +45,8 @@ void LoggingInit(const std::string &filename, const std::string &syslogFacility, const std::string &ident); +void LoggingInit(const std::string &propertyFile); + // // Disable logging - For testing purposes only // diff --git a/src/control-node/main.cc b/src/control-node/main.cc index 933a910319a..e9302058070 100644 --- a/src/control-node/main.cc +++ b/src/control-node/main.cc @@ -402,9 +402,15 @@ int main(int argc, char *argv[]) { ControlNode::SetProgramName(argv[0]); Module::type module = Module::CONTROL_NODE; string module_name = g_vns_constants.ModuleNames.find(module)->second; - LoggingInit(options.log_file(), options.log_file_size(), - options.log_files_count(), options.use_syslog(), - options.syslog_facility(), module_name); + std::string log_property_file = options.log_property_file(); + if (log_property_file.size()) { + LoggingInit(log_property_file); + } + else { + LoggingInit(options.log_file(), options.log_file_size(), + options.log_files_count(), options.use_syslog(), + options.syslog_facility(), module_name); + } TaskScheduler::Initialize(); ControlNode::SetDefaultSchedulingPolicy(); diff --git a/src/control-node/options.cc b/src/control-node/options.cc index 96bc254cb3d..ae294b4bd90 100644 --- a/src/control-node/options.cc +++ b/src/control-node/options.cc @@ -100,6 +100,8 @@ void Options::Initialize(EventManager &evm, "Disable sandesh logging") ("DEFAULT.log_file", opt::value()->default_value(""), "Filename for the logs to be written to") + ("DEFAULT.log_property_file", opt::value()->default_value(""), + "log4cplus property file name") ("DEFAULT.log_files_count", opt::value()->default_value(10), "Maximum log file roll over index") @@ -241,6 +243,7 @@ bool Options::Process(int argc, char *argv[], GetOptValue(var_map, log_category_, "DEFAULT.log_category"); GetOptValue(var_map, log_file_, "DEFAULT.log_file"); + GetOptValue(var_map, log_property_file_, "DEFAULT.log_property_file"); GetOptValue(var_map, log_files_count_, "DEFAULT.log_files_count"); GetOptValue(var_map, log_file_size_, "DEFAULT.log_file_size"); GetOptValue(var_map, log_level_, "DEFAULT.log_level"); diff --git a/src/control-node/options.h b/src/control-node/options.h index 1f326647d2b..e24952e6215 100644 --- a/src/control-node/options.h +++ b/src/control-node/options.h @@ -25,6 +25,7 @@ class Options { const std::string log_category() const { return log_category_; } const bool log_disable() const { return log_disable_; } const std::string log_file() const { return log_file_; } + const std::string log_property_file() const { return log_property_file_; } const int log_files_count() const { return log_files_count_; } const long log_file_size() const { return log_file_size_; } const std::string log_level() const { return log_level_; } @@ -69,6 +70,7 @@ class Options { std::string log_category_; bool log_disable_; std::string log_file_; + std::string log_property_file_; int log_files_count_; long log_file_size_; std::string log_level_; diff --git a/src/dns/cmn/dns_options.cc b/src/dns/cmn/dns_options.cc index d3e0f486cae..815f349c7ef 100644 --- a/src/dns/cmn/dns_options.cc +++ b/src/dns/cmn/dns_options.cc @@ -104,6 +104,8 @@ void Options::Initialize(EventManager &evm, "Category filter for local logging of sandesh messages") ("DEFAULT.log_disable", opt::bool_switch(&log_disable_), "Disable sandesh logging") + ("DEFAULT.log_property_file", opt::value()->default_value(""), + "log4cplus property file name") ("DEFAULT.log_file", opt::value()->default_value(""), "Filename for the logs to be written to") ("DEFAULT.log_files_count", @@ -170,7 +172,7 @@ void Options::GetOptValueImpl( std::vector tmp( var_map[val].as >()); // Now split the individual elements - for (typename std::vector::const_iterator it = + for (typename std::vector::const_iterator it = tmp.begin(); it != tmp.end(); it++) { std::stringstream ss(*it); @@ -241,6 +243,8 @@ void Options::Process(int argc, char *argv[], GetOptValue(var_map, log_category_, "DEFAULT.log_category"); GetOptValue(var_map, log_file_, "DEFAULT.log_file"); + GetOptValue(var_map, log_property_file_, + "DEFAULT.log_property_file"); GetOptValue(var_map, log_files_count_, "DEFAULT.log_files_count"); GetOptValue(var_map, log_file_size_, "DEFAULT.log_file_size"); GetOptValue(var_map, log_level_, "DEFAULT.log_level"); diff --git a/src/dns/cmn/dns_options.h b/src/dns/cmn/dns_options.h index 191a4c125fd..90e757424e2 100644 --- a/src/dns/cmn/dns_options.h +++ b/src/dns/cmn/dns_options.h @@ -30,6 +30,7 @@ class Options { const std::string log_category() const { return log_category_; } const bool log_disable() const { return log_disable_; } const std::string log_file() const { return log_file_; } + const std::string log_property_file() const { return log_property_file_; } const int log_files_count() const { return log_files_count_; } const long log_file_size() const { return log_file_size_; } const std::string log_level() const { return log_level_; } @@ -80,6 +81,7 @@ class Options { std::string log_category_; bool log_disable_; std::string log_file_; + std::string log_property_file_; int log_files_count_; long log_file_size_; std::string log_level_; diff --git a/src/dns/contrail-dns.conf b/src/dns/contrail-dns.conf index b6b324855de..164ab31bfbb 100644 --- a/src/dns/contrail-dns.conf +++ b/src/dns/contrail-dns.conf @@ -22,6 +22,7 @@ log_file=/var/log/contrail/contrail-dns.log log_level=SYS_NOTICE log_local=1 # test_mode=0 +# log_property_file= # log4cplus property file [DISCOVERY] # port=5998 diff --git a/src/dns/main.cc b/src/dns/main.cc index ab8fe868a41..83aca07d37f 100644 --- a/src/dns/main.cc +++ b/src/dns/main.cc @@ -106,9 +106,15 @@ int main(int argc, char *argv[]) { Module::type module = Module::DNS; string module_name = g_vns_constants.ModuleNames.find(module)->second; - LoggingInit(options.log_file(), options.log_file_size(), - options.log_files_count(), options.use_syslog(), - options.syslog_facility(), module_name); + std::string log_property_file = options.log_property_file(); + if (log_property_file.size()) { + LoggingInit(log_property_file); + } + else { + LoggingInit(options.log_file(), options.log_file_size(), + options.log_files_count(), options.use_syslog(), + options.syslog_facility(), module_name); + } string build_info_str; Dns::GetVersion(build_info_str); @@ -125,11 +131,11 @@ int main(int argc, char *argv[]) { string hostname = host_name(ec); Dns::SetHostName(hostname); if (options.discovery_server().empty()) { - NodeType::type node_type = + NodeType::type node_type = g_vns_constants.Module2NodeType.find(module)->second; Sandesh::InitGenerator( module_name, - options.hostname(), + options.hostname(), g_vns_constants.NodeTypeNames.find(node_type)->second, g_vns_constants.INSTANCE_ID_DEFAULT, Dns::GetEventManager(), @@ -172,7 +178,7 @@ int main(int argc, char *argv[]) { new TaskTrigger(boost::bind(&DnsInfoLogger), TaskScheduler::GetInstance()->GetTaskId("dns::Config"), 0); - dns_info_log_timer = + dns_info_log_timer = TimerManager::CreateTimer(*(Dns::GetEventManager()->io_service()), "Dns Info log timer"); dns_info_log_timer->Start(60*1000, boost::bind(&DnsInfoLogTimer), NULL); @@ -207,9 +213,9 @@ int main(int argc, char *argv[]) { //subscribe to collector service if not configured if (!options.collectors_configured()) { Module::type module = Module::DNS; - 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; @@ -241,7 +247,7 @@ int main(int argc, char *argv[]) { ifmap_server.set_ifmap_manager(ifmapmgr); Dns::GetEventManager()->Run(); - + Dns::ShutdownDiscoveryClient(ds_client); return 0; diff --git a/src/dns/test/dns_options_test.cc b/src/dns/test/dns_options_test.cc index d7bd52e49e9..77b832382ad 100644 --- a/src/dns/test/dns_options_test.cc +++ b/src/dns/test/dns_options_test.cc @@ -106,6 +106,7 @@ TEST_F(OptionsTest, DefaultConfFile) { EXPECT_EQ(options_.log_category(), ""); EXPECT_EQ(options_.log_disable(), false); EXPECT_EQ(options_.log_file(), "/var/log/contrail/contrail-dns.log"); + EXPECT_EQ(options_.log_property_file(), ""); EXPECT_EQ(options_.log_files_count(), 10); EXPECT_EQ(options_.log_file_size(), 1024*1024); EXPECT_EQ(options_.log_level(), "SYS_NOTICE"); @@ -118,18 +119,20 @@ TEST_F(OptionsTest, DefaultConfFile) { } TEST_F(OptionsTest, OverrideStringFromCommandLine) { - int argc = 5; + int argc = 6; char *argv[argc]; char argv_0[] = "dns_options_test"; char argv_1[] = "--conf_file=controller/src/dns/contrail-dns.conf"; char argv_2[] = "--DEFAULT.log_file=test.log"; char argv_3[] = "--DEFAULT.rndc_config_file=test.rndc"; char argv_4[] = "--DEFAULT.rndc_secret=secret123"; + char argv_5[] = "--DEFAULT.log_property_file=log4cplus.prop"; argv[0] = argv_0; argv[1] = argv_1; argv[2] = argv_2; argv[3] = argv_3; argv[4] = argv_4; + argv[5] = argv_5; options_.Parse(evm_, argc, argv); @@ -152,6 +155,7 @@ TEST_F(OptionsTest, OverrideStringFromCommandLine) { EXPECT_EQ(options_.log_category(), ""); EXPECT_EQ(options_.log_disable(), false); EXPECT_EQ(options_.log_file(), "test.log"); // Overridden from cmd line. + EXPECT_EQ(options_.log_property_file(), "log4cplus.prop"); EXPECT_EQ(options_.log_files_count(), 10); EXPECT_EQ(options_.log_file_size(), 1024*1024); EXPECT_EQ(options_.log_level(), "SYS_NOTICE"); @@ -224,6 +228,7 @@ TEST_F(OptionsTest, CustomConfigFile) { "log_level=SYS_DEBUG\n" "log_local=1\n" "test_mode=1\n" + "log_property_file=log4cplus.prop\n" "\n" "[DISCOVERY]\n" "port=100\n" @@ -272,6 +277,7 @@ TEST_F(OptionsTest, CustomConfigFile) { EXPECT_EQ(options_.log_category(), "dns"); EXPECT_EQ(options_.log_disable(), true); EXPECT_EQ(options_.log_file(), "test.log"); + EXPECT_EQ(options_.log_property_file(), "log4cplus.prop"); EXPECT_EQ(options_.log_files_count(), 20); EXPECT_EQ(options_.log_file_size(), 1024); EXPECT_EQ(options_.log_level(), "SYS_DEBUG"); diff --git a/src/query_engine/options.cc b/src/query_engine/options.cc index 4a39ed1ce8d..d397e613e38 100644 --- a/src/query_engine/options.cc +++ b/src/query_engine/options.cc @@ -93,6 +93,8 @@ void Options::Initialize(EventManager &evm, "Disable sandesh logging") ("DEFAULT.log_file", opt::value()->default_value(""), "Filename for the logs to be written to") + ("DEFAULT.log_property_file", opt::value()->default_value(""), + "log4cplus property file name") ("DEFAULT.log_files_count", opt::value()->default_value(10), "Maximum log file roll over index") @@ -217,6 +219,7 @@ void Options::Process(int argc, char *argv[], GetOptValue(var_map, log_category_, "DEFAULT.log_category"); GetOptValue(var_map, log_file_, "DEFAULT.log_file"); + GetOptValue(var_map, log_property_file_, "DEFAULT.log_property_file"); GetOptValue(var_map, log_files_count_, "DEFAULT.log_files_count"); GetOptValue(var_map, log_file_size_, "DEFAULT.log_file_size"); GetOptValue(var_map, log_level_, "DEFAULT.log_level"); diff --git a/src/query_engine/options.h b/src/query_engine/options.h index b63eb0f3f06..93cafb95e44 100644 --- a/src/query_engine/options.h +++ b/src/query_engine/options.h @@ -31,6 +31,7 @@ class Options { const int max_tasks() const { return max_tasks_; } const int max_slice() const { return max_slice_; } const std::string log_category() const { return log_category_; } + const std::string log_property_file() const { return log_property_file_; } const bool log_disable() const { return log_disable_; } const std::string log_file() const { return log_file_; } const int log_files_count() const { return log_files_count_; } @@ -69,6 +70,7 @@ class Options { std::string host_ip_; uint16_t http_server_port_; std::string log_category_; + std::string log_property_file_; bool log_disable_; std::string log_file_; int log_files_count_; diff --git a/src/query_engine/qed.cc b/src/query_engine/qed.cc index f217a0d93dd..7c8caffd9cd 100644 --- a/src/query_engine/qed.cc +++ b/src/query_engine/qed.cc @@ -153,10 +153,15 @@ main(int argc, char *argv[]) { Module::type module = Module::QUERY_ENGINE; string module_name = g_vns_constants.ModuleNames.find(module)->second; - LoggingInit(options.log_file(), options.log_file_size(), - options.log_files_count(), options.use_syslog(), - options.syslog_facility(), module_name); - + std::string log_property_file = options.log_property_file(); + if (log_property_file.size()) { + LoggingInit(log_property_file); + } + else { + LoggingInit(options.log_file(), options.log_file_size(), + options.log_files_count(), options.use_syslog(), + options.syslog_facility(), module_name); + } error_code error; DiscoveryServiceClient *ds_client = NULL; ip::tcp::endpoint dss_ep; diff --git a/src/vnsw/agent/init/agent_init.cc b/src/vnsw/agent/init/agent_init.cc index e369e0b269a..737ca09f173 100644 --- a/src/vnsw/agent/init/agent_init.cc +++ b/src/vnsw/agent/init/agent_init.cc @@ -78,10 +78,16 @@ int AgentInit::Start() { agent_->set_agent_name(AgentName()); agent_->set_instance_id(InstanceId()); - LoggingInit(agent_param_->log_file(), agent_param_->log_file_size(), - agent_param_->log_files_count(), agent_param_->use_syslog(), - agent_param_->syslog_facility(), module_name); + std::string log_property_file = agent_param_->log_property_file(); + if (log_property_file.size()) { + LoggingInit(log_property_file); + } + else { + LoggingInit(agent_param_->log_file(), agent_param_->log_file_size(), + agent_param_->log_files_count(), agent_param_->use_syslog(), + agent_param_->syslog_facility(), module_name); + } agent_param_->LogConfig(); int ret = agent_param_->Validate(); diff --git a/src/vnsw/agent/init/agent_param.cc b/src/vnsw/agent/init/agent_param.cc index 418e662e0dc..3f055c92d73 100644 --- a/src/vnsw/agent/init/agent_param.cc +++ b/src/vnsw/agent/init/agent_param.cc @@ -47,7 +47,7 @@ bool AgentParam::GetOptValueImpl( std::vector tmp( var_map[val].as >()); // Now split the individual elements - for (typename std::vector::const_iterator it = + for (typename std::vector::const_iterator it = tmp.begin(); it != tmp.end(); it++) { std::stringstream ss(*it); @@ -75,8 +75,8 @@ bool AgentParam::ParseIp(const string &key, Ip4Address *server) { if (opt_str = tree_.get_optional(key)) { Ip4Address addr; if (GetIpAddress(opt_str.get(), &addr) == false) { - LOG(ERROR, "Error in config file <" << config_file_ - << ">. Error parsing IP address from <" + LOG(ERROR, "Error in config file <" << config_file_ + << ">. Error parsing IP address from <" << opt_str.get() << ">"); return false; @@ -95,8 +95,8 @@ bool AgentParam::ParseServerList(const string &key, Ip4Address *server1, if (opt_str = tree_.get_optional(key)) { boost::split(tokens, opt_str.get(), boost::is_any_of(" \t")); if (tokens.size() > 2) { - LOG(ERROR, "Error in config file <" << config_file_ - << ">. Cannot have more than 2 servers <" + LOG(ERROR, "Error in config file <" << config_file_ + << ">. Cannot have more than 2 servers <" << opt_str.get() << ">"); return false; } @@ -232,7 +232,7 @@ bool AgentParam::ParseServerListArguments return true; } -void AgentParam::ParseCollector() { +void AgentParam::ParseCollector() { optional opt_str; if (opt_str = tree_.get_optional("DEFAULT.collectors")) { boost::split(collector_server_list_, opt_str.get(), @@ -263,7 +263,7 @@ void AgentParam::BuildAddressList(const string &val) { } } -void AgentParam::ParseVirtualHost() { +void AgentParam::ParseVirtualHost() { boost::system::error_code ec; optional opt_str; @@ -272,16 +272,16 @@ void AgentParam::ParseVirtualHost() { if (opt_str = tree_.get_optional("VIRTUAL-HOST-INTERFACE.ip")) { ec = Ip4PrefixParse(opt_str.get(), &vhost_.addr_, &vhost_.plen_); if (ec != 0 || vhost_.plen_ > 32) { - cout << "Error in config file <" << config_file_ - << ">. Error parsing vhost ip-address from <" + cout << "Error in config file <" << config_file_ + << ">. Error parsing vhost ip-address from <" << opt_str.get() << ">\n"; } } if (opt_str = tree_.get_optional("VIRTUAL-HOST-INTERFACE.gateway")) { if (GetIpAddress(opt_str.get(), &vhost_.gw_) == false) { - cout << "Error in config file <" << config_file_ - << ">. Error parsing vhost gateway address from <" + cout << "Error in config file <" << config_file_ + << ">. Error parsing vhost gateway address from <" << opt_str.get() << ">\n"; } } @@ -297,7 +297,7 @@ void AgentParam::ParseVirtualHost() { void AgentParam::ParseDiscovery() { ParseIp("DISCOVERY.server", &dss_server_); - GetValueFromTree(xmpp_instance_count_, + GetValueFromTree(xmpp_instance_count_, "DISCOVERY.max_control_nodes"); } @@ -313,7 +313,7 @@ void AgentParam::ParseHypervisor() { if (opt_str.get() == "xen") { hypervisor_mode_ = AgentParam::MODE_XEN; - GetValueFromTree(xen_ll_.name_, + GetValueFromTree(xen_ll_.name_, "HYPERVISOR.xen_ll_interface"); boost::system::error_code ec; @@ -322,15 +322,15 @@ void AgentParam::ParseHypervisor() { ec = Ip4PrefixParse(opt_str.get(), &xen_ll_.addr_, &xen_ll_.plen_); if (ec != 0 || xen_ll_.plen_ >= 32) { - cout << "Error in config file <" << config_file_ - << ">. Error parsing Xen Link-local ip-address from <" + cout << "Error in config file <" << config_file_ + << ">. Error parsing Xen Link-local ip-address from <" << opt_str.get() << ">\n"; return; } } } else if (opt_str.get() == "vmware") { hypervisor_mode_ = AgentParam::MODE_VMWARE; - GetValueFromTree(vmware_physical_port_, + GetValueFromTree(vmware_physical_port_, "HYPERVISOR.vmware_physical_interface"); } else { hypervisor_mode_ = AgentParam::MODE_KVM; @@ -344,21 +344,21 @@ void AgentParam::ParseHypervisor() { vmware_mode_ = ESXI_NEUTRON; } else { cout << "Error in config file <" << config_file_ << - ">. Error parsing vmware_mode from <" + ">. Error parsing vmware_mode from <" << opt_str.get() << ">\n"; return; } } } -void AgentParam::ParseDefaultSection() { +void AgentParam::ParseDefaultSection() { optional opt_str; optional opt_uint; GetValueFromTree(host_name_, "DEFAULT.hostname"); GetValueFromTree(agent_name_, "DEFAULT.agent_name"); - if (!GetValueFromTree(http_server_port_, + if (!GetValueFromTree(http_server_port_, "DEFAULT.http_server_port")) { http_server_port_ = ContrailPorts::HttpPortAgent(); } @@ -367,11 +367,11 @@ void AgentParam::ParseDefaultSection() { if ((tunnel_type_ != "MPLSoUDP") && (tunnel_type_ != "VXLAN")) tunnel_type_ = "MPLSoGRE"; - if (!GetValueFromTree(flow_cache_timeout_, + if (!GetValueFromTree(flow_cache_timeout_, "DEFAULT.flow_cache_timeout")) { flow_cache_timeout_ = Agent::kDefaultFlowCacheTimeout; } - + if (!GetValueFromTree(log_level_, "DEFAULT.log_level")) { log_level_ = "SYS_DEBUG"; } @@ -414,10 +414,14 @@ void AgentParam::ParseDefaultSection() { } else { log_flow_ = false; } + + if (!GetValueFromTree(log_property_file_, "DEFAULT.log_property_file")) { + log_property_file_ = ""; + } } -void AgentParam::ParseMetadataProxy() { - GetValueFromTree(metadata_shared_secret_, +void AgentParam::ParseMetadataProxy() { + GetValueFromTree(metadata_shared_secret_, "METADATA.metadata_proxy_secret"); } @@ -425,11 +429,11 @@ void AgentParam::ParseFlows() { if (!GetValueFromTree(max_vm_flows_, "FLOWS.max_vm_flows")) { max_vm_flows_ = (float) 100; } - if (!GetValueFromTree(linklocal_system_flows_, + if (!GetValueFromTree(linklocal_system_flows_, "FLOWS.max_system_linklocal_flows")) { linklocal_system_flows_ = Agent::kDefaultMaxLinkLocalOpenFds; } - if (!GetValueFromTree(linklocal_vm_flows_, + if (!GetValueFromTree(linklocal_vm_flows_, "FLOWS.max_vm_linklocal_flows")) { linklocal_vm_flows_ = Agent::kDefaultMaxLinkLocalOpenFds; } @@ -522,7 +526,7 @@ void AgentParam::ParseVirtualHostArguments void AgentParam::ParseDiscoveryArguments (const boost::program_options::variables_map &var_map) { ParseIpArgument(var_map, dss_server_, "DISCOVERY.server"); - GetOptValue(var_map, xmpp_instance_count_, + GetOptValue(var_map, xmpp_instance_count_, "DISCOVERY.max_control_nodes"); } @@ -534,33 +538,33 @@ void AgentParam::ParseNetworksArguments void AgentParam::ParseHypervisorArguments (const boost::program_options::variables_map &var_map) { boost::system::error_code ec; - if (var_map.count("HYPERVISOR.type") && + if (var_map.count("HYPERVISOR.type") && !var_map["HYPERVISOR.type"].defaulted()) { if (var_map["HYPERVISOR.type"].as() == "xen") { hypervisor_mode_ = AgentParam::MODE_XEN; - GetOptValue(var_map, xen_ll_.name_, + GetOptValue(var_map, xen_ll_.name_, "HYPERVISOR.xen_ll_interface"); if (var_map.count("HYPERVISOR.xen_ll_ip")) { string ip = var_map["HYPERVISOR.xen_ll_ip"].as(); ec = Ip4PrefixParse(ip, &xen_ll_.addr_, &xen_ll_.plen_); if (ec != 0 || xen_ll_.plen_ >= 32) { - cout << "Error in argument <" << config_file_ - << ">. Error parsing Xen Link-local ip-address from <" + cout << "Error in argument <" << config_file_ + << ">. Error parsing Xen Link-local ip-address from <" << ip << ">\n"; exit(EINVAL); } } } else if (var_map["HYPERVISOR.type"].as() == "vmware") { hypervisor_mode_ = AgentParam::MODE_VMWARE; - GetOptValue(var_map, vmware_physical_port_, + GetOptValue(var_map, vmware_physical_port_, "HYPERVISOR.vmware_physical_interface"); } else { hypervisor_mode_ = AgentParam::MODE_KVM; } } - if (var_map.count("HYPERVISOR.vmware_mode") && + if (var_map.count("HYPERVISOR.vmware_mode") && !var_map["HYPERVISOR.vmware_mode"].defaulted()) { cout << " vmware_mode is " << var_map["HYPERVISOR.vmware_mode"].as() << endl; if (var_map["HYPERVISOR.vmware_mode"].as() == "vcenter") { @@ -569,7 +573,7 @@ void AgentParam::ParseHypervisorArguments "esxi_neutron") { vmware_mode_ = ESXI_NEUTRON; } else { - cout << "Error in parsing arguement for HYPERVISOR.vmware_mode <" + cout << "Error in parsing arguement for HYPERVISOR.vmware_mode <" << var_map["HYPERVISOR.vmware_mode"].as() << endl; return; } @@ -578,11 +582,11 @@ void AgentParam::ParseHypervisorArguments void AgentParam::ParseDefaultSectionArguments (const boost::program_options::variables_map &var_map) { - GetOptValue(var_map, flow_cache_timeout_, + GetOptValue(var_map, flow_cache_timeout_, "DEFAULT.flow_cache_timeout"); GetOptValue(var_map, host_name_, "DEFAULT.hostname"); GetOptValue(var_map, agent_name_, "DEFAULT.agent_name"); - GetOptValue(var_map, http_server_port_, + GetOptValue(var_map, http_server_port_, "DEFAULT.http_server_port"); GetOptValue(var_map, log_category_, "DEFAULT.log_category"); GetOptValue(var_map, log_file_, "DEFAULT.log_file"); @@ -613,7 +617,7 @@ void AgentParam::ParseMetadataProxyArguments void AgentParam::ParseFlowArguments (const boost::program_options::variables_map &var_map) { GetOptValue(var_map, max_vm_flows_, "FLOWS.max_vm_flows"); - GetOptValue(var_map, linklocal_system_flows_, + GetOptValue(var_map, linklocal_system_flows_, "FLOWS.max_system_linklocal_flows"); GetOptValue(var_map, linklocal_vm_flows_, "FLOWS.max_vm_linklocal_flows"); @@ -686,10 +690,10 @@ void AgentParam::InitFromConfig() { try { read_ini(config_file_, tree_); } catch (exception &e) { - cout << "Error reading config file <" << config_file_ + cout << "Error reading config file <" << config_file_ << ">. INI format error??? <" << e.what() << ">\n"; return; - } + } ParseCollector(); ParseVirtualHost(); @@ -716,7 +720,7 @@ void AgentParam::InitFromConfig() { void AgentParam::InitFromArguments() { ParseCollectorArguments(var_map_); ParseVirtualHostArguments(var_map_); - ParseServerListArguments(var_map_, xmpp_server_1_, xmpp_server_2_, + ParseServerListArguments(var_map_, xmpp_server_1_, xmpp_server_2_, "CONTROL-NODE.server"); ParseServerListArguments(var_map_, &dns_server_1_, &dns_port_1_, &dns_server_2_, &dns_port_2_, "DNS.server"); @@ -897,7 +901,7 @@ void AgentParam::Init(const string &config_file, const string &program_name) { void AgentParam::LogConfig() const { LOG(DEBUG, "vhost interface name : " << vhost_.name_); - LOG(DEBUG, "vhost IP Address : " << vhost_.addr_.to_string() + LOG(DEBUG, "vhost IP Address : " << vhost_.addr_.to_string() << "/" << vhost_.plen_); LOG(DEBUG, "vhost gateway : " << vhost_.gw_.to_string()); LOG(DEBUG, "Ethernet port : " << eth_port_); @@ -1017,11 +1021,11 @@ AgentParam::AgentParam(Agent *agent, bool enable_flow_options, boost::program_options::options_description generic("Generic options"); generic.add_options() ("help", "help message") - ("config_file", - opt::value()->default_value(agent->config_file()), + ("config_file", + opt::value()->default_value(agent->config_file()), "Configuration file") ("version", "Display version information") - ("CONTROL-NODE.server", + ("CONTROL-NODE.server", opt::value >()->multitoken(), "IP addresses of control nodes." " Max of 2 Ip addresses can be configured") @@ -1029,25 +1033,25 @@ AgentParam::AgentParam(Agent *agent, bool enable_flow_options, opt::value >()->multitoken(), "Collector server list") ("DEFAULT.debug", "Enable debug logging") - ("DEFAULT.flow_cache_timeout", + ("DEFAULT.flow_cache_timeout", opt::value()->default_value(agent->kDefaultFlowCacheTimeout), "Flow aging time in seconds") - ("DEFAULT.hostname", opt::value(), + ("DEFAULT.hostname", opt::value(), "Hostname of compute-node") ("DEFAULT.headless_mode", opt::value(), "Run compute-node in headless mode") ("DEFAULT.dhcp_relay_mode", opt::value(), "Enable / Disable DHCP relay of DHCP packets from virtual instance") - ("DEFAULT.http_server_port", - opt::value()->default_value(ContrailPorts::HttpPortAgent()), + ("DEFAULT.http_server_port", + opt::value()->default_value(ContrailPorts::HttpPortAgent()), "Sandesh HTTP listener port") ("DEFAULT.tunnel_type", opt::value()->default_value("MPLSoGRE"), "Tunnel Encapsulation type ") ("DEFAULT.agent_mode", opt::value(), "Run agent in vrouter / tsn / tor mode") - ("DISCOVERY.server", opt::value(), + ("DISCOVERY.server", opt::value(), "IP address of discovery server") - ("DISCOVERY.max_control_nodes", opt::value(), + ("DISCOVERY.max_control_nodes", opt::value(), "Maximum number of control node info to be provided by discovery " "service <1|2>") ("DNS.server", opt::value >()->multitoken(), @@ -1063,7 +1067,7 @@ AgentParam::AgentParam(Agent *agent, bool enable_flow_options, log.add_options() ("DEFAULT.log_category", opt::value()->default_value("*"), "Category filter for local logging of sandesh messages") - ("DEFAULT.log_file", + ("DEFAULT.log_file", opt::value()->default_value(agent->log_file()), "Filename for the logs to be written to") ("DEFAULT.log_files_count", opt::value()->default_value(10), @@ -1083,11 +1087,11 @@ AgentParam::AgentParam(Agent *agent, bool enable_flow_options, if (enable_flow_options_) { opt::options_description flow("Flow options"); flow.add_options() - ("FLOWS.max_vm_flows", opt::value(), + ("FLOWS.max_vm_flows", opt::value(), "Maximum flows allowed per VM - given as \% of maximum system flows") - ("FLOWS.max_system_linklocal_flows", opt::value(), + ("FLOWS.max_system_linklocal_flows", opt::value(), "Maximum number of link-local flows allowed across all VMs") - ("FLOWS.max_vm_linklocal_flows", opt::value(), + ("FLOWS.max_vm_linklocal_flows", opt::value(), "Maximum number of link-local flows allowed per VM") ; options_.add(flow); @@ -1096,16 +1100,16 @@ AgentParam::AgentParam(Agent *agent, bool enable_flow_options, if (enable_hypervisor_options_) { opt::options_description hypervisor("Hypervisor specific options"); hypervisor.add_options() - ("HYPERVISOR.type", opt::value()->default_value("kvm"), + ("HYPERVISOR.type", opt::value()->default_value("kvm"), "Type of hypervisor ") - ("HYPERVISOR.xen_ll_interface", opt::value(), + ("HYPERVISOR.xen_ll_interface", opt::value(), "Port name on host for link-local network") ("HYPERVISOR.xen_ll_ip", opt::value(), "IP Address and prefix or the link local port in ip/prefix format") ("HYPERVISOR.vmware_physical_port", opt::value(), "Physical port used to connect to VMs in VMWare environment") ("HYPERVISOR.vmware_mode", - opt::value()->default_value("esxi_neutron"), + opt::value()->default_value("esxi_neutron"), "VMWare mode ") ; options_.add(hypervisor); @@ -1116,11 +1120,11 @@ AgentParam::AgentParam(Agent *agent, bool enable_flow_options, vhost.add_options() ("VIRTUAL-HOST-INTERFACE.name", opt::value(), "Name of virtual host interface") - ("VIRTUAL-HOST-INTERFACE.ip", opt::value(), + ("VIRTUAL-HOST-INTERFACE.ip", opt::value(), "IP address and prefix in ip/prefix_len format") - ("VIRTUAL-HOST-INTERFACE.gateway", opt::value(), + ("VIRTUAL-HOST-INTERFACE.gateway", opt::value(), "Gateway IP address for virtual host") - ("VIRTUAL-HOST-INTERFACE.physical_interface", opt::value(), + ("VIRTUAL-HOST-INTERFACE.physical_interface", opt::value(), "Physical interface name to which virtual host interface maps to") ("VIRTUAL-HOST-INTERFACE.compute_node_address", opt::value >()->multitoken(), diff --git a/src/vnsw/agent/init/agent_param.h b/src/vnsw/agent/init/agent_param.h index a3205c59365..e8533263c5d 100644 --- a/src/vnsw/agent/init/agent_param.h +++ b/src/vnsw/agent/init/agent_param.h @@ -126,6 +126,7 @@ class AgentParam { bool log_flow() const { return log_flow_; } const std::string &log_level() const { return log_level_; } const std::string &log_category() const { return log_category_; } + const std::string &log_property_file() const { return log_property_file_; } const bool use_syslog() const { return use_syslog_; } const std::string syslog_facility() const { return syslog_facility_; } const std::vector collector_server_list() const { @@ -320,6 +321,7 @@ class AgentParam { std::string log_file_; int log_files_count_; long log_file_size_; + std::string log_property_file_; bool log_local_; bool log_flow_;