Skip to content

Commit

Permalink
Make ifmap parameters configurable in control-node and dnsd
Browse files Browse the repository at this point in the history
Closes-Bug: #1586201

Conflicts:
	src/control-node/options.h
	src/dns/cmn/dns_options.cc
	src/dns/cmn/dns_options.h
	src/ifmap/client/ifmap_channel.cc

(cherry picked from commit 2dbd557)
Change-Id: Id5843e9ee6db736747af152ef605ab03c478fa42
  • Loading branch information
tkarwa committed Jun 23, 2016
1 parent 720977c commit a554729
Show file tree
Hide file tree
Showing 19 changed files with 452 additions and 134 deletions.
3 changes: 3 additions & 0 deletions src/control-node/contrail-control.conf
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@ sandesh_send_rate_limit=100
# password=control-node
# server_url= # Provided by discovery server, e.g. https://127.0.0.1:8443
# user=control-node
# stale_entries_cleanup_timeout=10 # in seconds
# end_of_rib_timeout=10 # in seconds
# peer_response_wait_time=60 # in seconds

3 changes: 1 addition & 2 deletions src/control-node/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -633,8 +633,7 @@ int main(int argc, char *argv[]) {
// 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(),
options.ifmap_config_options(),
boost::bind(
&IFMapServerParser::Receive, ifmap_parser, &config_db, _1, _2, _3),
evm.io_service());
Expand Down
32 changes: 25 additions & 7 deletions src/control-node/options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,17 @@ void Options::Initialize(EventManager &evm,
"Certificates store to use for communication with IFMAP server")
("IFMAP.password", opt::value<string>()->default_value("control-node"),
"IFMAP server password")
("IFMAP.server_url",
opt::value<string>()->default_value(ifmap_server_url_),
"IFMAP server URL")
("IFMAP.server_url", opt::value<string>()->default_value(
ifmap_config_options_.server_url), "IFMAP server URL")
("IFMAP.user", opt::value<string>()->default_value("control-node"),
"IFMAP server username")
("IFMAP.stale_entries_cleanup_timeout",
opt::value<int>()->default_value(10),
"IFMAP stale entries cleanup timeout")
("IFMAP.end_of_rib_timeout", opt::value<int>()->default_value(10),
"IFMAP end of rib timeout")
("IFMAP.peer_response_wait_time", opt::value<int>()->default_value(60),
"IFMAP peer response wait time")
;

config_file_options_.add(config);
Expand Down Expand Up @@ -273,10 +279,22 @@ bool Options::Process(int argc, char *argv[],
GetOptValue<string>(var_map, discovery_server_, "DISCOVERY.server");


GetOptValue<string>(var_map, ifmap_password_, "IFMAP.password");
GetOptValue<string>(var_map, ifmap_server_url_, "IFMAP.server_url");
GetOptValue<string>(var_map, ifmap_user_, "IFMAP.user");
GetOptValue<string>(var_map, ifmap_certs_store_, "IFMAP.certs_store");
GetOptValue<string>(var_map, ifmap_config_options_.password,
"IFMAP.password");
GetOptValue<string>(var_map, ifmap_config_options_.server_url,
"IFMAP.server_url");
GetOptValue<string>(var_map, ifmap_config_options_.user,
"IFMAP.user");
GetOptValue<string>(var_map, ifmap_config_options_.certs_store,
"IFMAP.certs_store");
GetOptValue<int>(var_map,
ifmap_config_options_.stale_entries_cleanup_timeout,
"IFMAP.stale_entries_cleanup_timeout");
GetOptValue<int>(var_map, ifmap_config_options_.end_of_rib_timeout,
"IFMAP.end_of_rib_timeout");
GetOptValue<int>(var_map,
ifmap_config_options_.peer_response_wait_time,
"IFMAP.peer_response_wait_time");

return true;
}
88 changes: 52 additions & 36 deletions src/control-node/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,66 @@

#include <boost/program_options.hpp>
#include "io/event_manager.h"
#include "ifmap/ifmap_config_options.h"

// Process command line/configuration file options for control-node.
class Options {
public:
Options();
bool Parse(EventManager &evm, int argc, char **argv);

const std::string bgp_config_file() const { return bgp_config_file_; }
const uint16_t bgp_port() const { return bgp_port_; }
const std::vector<std::string> collector_server_list() const {
std::string bgp_config_file() const { return bgp_config_file_; }
uint16_t bgp_port() const { return bgp_port_; }
std::vector<std::string> collector_server_list() const {
return collector_server_list_;
}
const std::string config_file() const { return config_file_; };
const std::string discovery_server() const { return discovery_server_; }
const uint16_t discovery_port() const { return discovery_port_; }
const std::string hostname() const { return hostname_; }
const std::string host_ip() const { return host_ip_; }
const uint16_t http_server_port() const { return http_server_port_; }
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_; }
const bool log_local() const { return log_local_; }
const bool use_syslog() const { return use_syslog_; }
const std::string syslog_facility() const { return syslog_facility_; }
const std::string ifmap_server_url() const { return ifmap_server_url_; }
const std::string ifmap_password() const { return ifmap_password_; }
const std::string ifmap_user() const { return ifmap_user_; }
const std::string ifmap_certs_store() const { return ifmap_certs_store_; }
const uint16_t xmpp_port() const { return xmpp_port_; }
const bool xmpp_auth_enabled() const { return xmpp_auth_enable_; }
const std::string xmpp_server_cert() const { return xmpp_server_cert_; }
const std::string xmpp_server_key() const { return xmpp_server_key_; }
const bool test_mode() const { return test_mode_; }
const bool collectors_configured() const { return collectors_configured_; }
const int tcp_hold_time() const { return tcp_hold_time_; }
const bool optimize_snat() const { return optimize_snat_; }
const uint32_t sandesh_send_rate_limit() const { return sandesh_ratelimit_; }
std::string config_file() const { return config_file_; };
std::string discovery_server() const { return discovery_server_; }
uint16_t discovery_port() const { return discovery_port_; }
std::string hostname() const { return hostname_; }
std::string host_ip() const { return host_ip_; }
uint16_t http_server_port() const { return http_server_port_; }
std::string log_category() const { return log_category_; }
bool log_disable() const { return log_disable_; }
std::string log_file() const { return log_file_; }
std::string log_property_file() const { return log_property_file_; }
int log_files_count() const { return log_files_count_; }
long log_file_size() const { return log_file_size_; }
std::string log_level() const { return log_level_; }
bool log_local() const { return log_local_; }
bool use_syslog() const { return use_syslog_; }
std::string syslog_facility() const { return syslog_facility_; }
std::string ifmap_server_url() const {
return ifmap_config_options_.server_url;
}
std::string ifmap_password() const {
return ifmap_config_options_.password;
}
std::string ifmap_user() const { return ifmap_config_options_.user; }
std::string ifmap_certs_store() const {
return ifmap_config_options_.certs_store;
}
int ifmap_stale_entries_cleanup_timeout() const {
return ifmap_config_options_.stale_entries_cleanup_timeout;
}
int ifmap_end_of_rib_timeout() const {
return ifmap_config_options_.end_of_rib_timeout;
}
int ifmap_peer_response_wait_time() const {
return ifmap_config_options_.peer_response_wait_time;
}
const IFMapConfigOptions &ifmap_config_options() const {
return ifmap_config_options_;
}
uint16_t xmpp_port() const { return xmpp_port_; }
bool xmpp_auth_enabled() const { return xmpp_auth_enable_; }
std::string xmpp_server_cert() const { return xmpp_server_cert_; }
std::string xmpp_server_key() const { return xmpp_server_key_; }
bool test_mode() const { return test_mode_; }
bool collectors_configured() const { return collectors_configured_; }
int tcp_hold_time() const { return tcp_hold_time_; }
bool optimize_snat() const { return optimize_snat_; }
uint32_t sandesh_send_rate_limit() const { return sandesh_ratelimit_; }

private:

Expand Down Expand Up @@ -83,10 +102,7 @@ class Options {
bool log_local_;
bool use_syslog_;
std::string syslog_facility_;
std::string ifmap_server_url_;
std::string ifmap_password_;
std::string ifmap_user_;
std::string ifmap_certs_store_;
IFMapConfigOptions ifmap_config_options_;
uint16_t xmpp_port_;
bool xmpp_auth_enable_;
std::string xmpp_server_cert_;
Expand Down
95 changes: 94 additions & 1 deletion src/control-node/test/options_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ TEST_F(OptionsTest, NoArguments) {
EXPECT_EQ(options_.ifmap_password(), "control-node");
EXPECT_EQ(options_.ifmap_user(), "control-node");
EXPECT_EQ(options_.ifmap_certs_store(), "");
EXPECT_EQ(options_.ifmap_stale_entries_cleanup_timeout(), 10);
EXPECT_EQ(options_.ifmap_end_of_rib_timeout(), 10);
EXPECT_EQ(options_.ifmap_peer_response_wait_time(), 60);
EXPECT_EQ(options_.xmpp_port(), default_xmpp_port);
EXPECT_EQ(options_.test_mode(), false);
EXPECT_EQ(options_.sandesh_send_rate_limit(), 0);
Expand Down Expand Up @@ -112,6 +115,9 @@ TEST_F(OptionsTest, DefaultConfFile) {
EXPECT_EQ(options_.ifmap_password(), "control-node");
EXPECT_EQ(options_.ifmap_user(), "control-node");
EXPECT_EQ(options_.ifmap_certs_store(), "");
EXPECT_EQ(options_.ifmap_stale_entries_cleanup_timeout(), 10);
EXPECT_EQ(options_.ifmap_end_of_rib_timeout(), 10);
EXPECT_EQ(options_.ifmap_peer_response_wait_time(), 60);
EXPECT_EQ(options_.xmpp_port(), default_xmpp_port);
EXPECT_EQ(options_.test_mode(), false);
EXPECT_EQ(options_.sandesh_send_rate_limit(), 100);
Expand Down Expand Up @@ -227,7 +233,10 @@ TEST_F(OptionsTest, CustomConfigFile) {
"certs_store=test-store\n"
"password=test-password\n"
"server_url=https://127.0.0.1:100\n"
"user=test-user\n";
"user=test-user\n"
"stale_entries_cleanup_timeout=120\n"
"end_of_rib_timeout=110\n"
"peer_response_wait_time=100\n";

ofstream config_file;
config_file.open("./options_test_config_file.conf");
Expand Down Expand Up @@ -270,6 +279,9 @@ TEST_F(OptionsTest, CustomConfigFile) {
EXPECT_EQ(options_.ifmap_password(), "test-password");
EXPECT_EQ(options_.ifmap_user(), "test-user");
EXPECT_EQ(options_.ifmap_certs_store(), "test-store");
EXPECT_EQ(options_.ifmap_stale_entries_cleanup_timeout(), 120);
EXPECT_EQ(options_.ifmap_end_of_rib_timeout(), 110);
EXPECT_EQ(options_.ifmap_peer_response_wait_time(), 100);
EXPECT_EQ(options_.xmpp_port(), 100);
EXPECT_EQ(options_.test_mode(), true);
EXPECT_EQ(options_.optimize_snat(), true);
Expand Down Expand Up @@ -484,6 +496,87 @@ TEST_F(OptionsTest, UnresolvableHostName) {
EXPECT_EQ("", host_ip_);
}

TEST_F(OptionsTest, OverrideIFMapOptionsFromCommandLine) {
int argc = 9;
char *argv[argc];
char argv_0[] = "options_test";
char argv_1[] = "--conf_file=controller/src/control-node/contrail-control.conf";
char argv_2[] = "--IFMAP.server_url=https://66.55.44.33";
char argv_3[] = "--IFMAP.password=mynewpassword";
char argv_4[] = "--IFMAP.user=mynewuser";
char argv_5[] = "--IFMAP.certs_store=mynewcertstore";
char argv_6[] = "--IFMAP.stale_entries_cleanup_timeout=99";
char argv_7[] = "--IFMAP.end_of_rib_timeout=88";
char argv_8[] = "--IFMAP.peer_response_wait_time=77";
argv[0] = argv_0;
argv[1] = argv_1;
argv[2] = argv_2;
argv[3] = argv_3;
argv[4] = argv_4;
argv[5] = argv_5;
argv[6] = argv_6;
argv[7] = argv_7;
argv[8] = argv_8;

options_.Parse(evm_, argc, argv);

EXPECT_EQ(options_.ifmap_server_url(), "https://66.55.44.33");
EXPECT_EQ(options_.ifmap_password(), "mynewpassword");
EXPECT_EQ(options_.ifmap_user(), "mynewuser");
EXPECT_EQ(options_.ifmap_certs_store(), "mynewcertstore");
EXPECT_EQ(options_.ifmap_stale_entries_cleanup_timeout(), 99); // default 10
EXPECT_EQ(options_.ifmap_end_of_rib_timeout(), 88); // default 10
EXPECT_EQ(options_.ifmap_peer_response_wait_time(), 77); // default 60
}

TEST_F(OptionsTest, CustomIFMapConfigFileAndOverrideFromCommandLine) {
string config = ""
"[IFMAP]\n"
"certs_store=test-store\n"
"password=test-password\n"
"server_url=https://127.0.0.1:100\n"
"user=test-user\n"
"stale_entries_cleanup_timeout=120\n"
"end_of_rib_timeout=110\n"
"peer_response_wait_time=100\n";

ofstream config_file;
config_file.open("./options_test_config_file.conf");
config_file << config;
config_file.close();

int argc = 9;
char *argv[argc];
char argv_0[] = "options_test";
char argv_1[] = "--conf_file=./options_test_config_file.conf";
char argv_2[] = "--IFMAP.certs_store=new-test-store";
char argv_3[] = "--IFMAP.password=new-test-password";
char argv_4[] = "--IFMAP.server_url=https://11.10.10.1:100";
char argv_5[] = "--IFMAP.stale_entries_cleanup_timeout=21";
char argv_6[] = "--IFMAP.end_of_rib_timeout=31";
char argv_7[] = "--IFMAP.peer_response_wait_time=41";
char argv_8[] = "--IFMAP.user=new-test-user";
argv[0] = argv_0;
argv[1] = argv_1;
argv[2] = argv_2;
argv[3] = argv_3;
argv[4] = argv_4;
argv[5] = argv_5;
argv[6] = argv_6;
argv[7] = argv_7;
argv[8] = argv_8;

options_.Parse(evm_, argc, argv);

EXPECT_EQ(options_.ifmap_certs_store(), "new-test-store");
EXPECT_EQ(options_.ifmap_password(), "new-test-password");
EXPECT_EQ(options_.ifmap_server_url(), "https://11.10.10.1:100");
EXPECT_EQ(options_.ifmap_stale_entries_cleanup_timeout(), 21);
EXPECT_EQ(options_.ifmap_end_of_rib_timeout(), 31);
EXPECT_EQ(options_.ifmap_peer_response_wait_time(), 41);
EXPECT_EQ(options_.ifmap_user(), "new-test-user");
}

int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
int result = RUN_ALL_TESTS();
Expand Down
37 changes: 27 additions & 10 deletions src/dns/cmn/dns_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,20 @@ void Options::Initialize(EventManager &evm,

("IFMAP.certs_store", opt::value<string>(),
"Certificates store to use for communication with IFMAP server")
("IFMAP.password", opt::value<string>()->default_value(
"dns_user_passwd"),
("IFMAP.password",
opt::value<string>()->default_value("dns_user_passwd"),
"IFMAP server password")
("IFMAP.server_url",
opt::value<string>()->default_value(ifmap_server_url_),
"IFMAP server URL")
("IFMAP.server_url", opt::value<string>()->default_value(
ifmap_config_options_.server_url), "IFMAP server URL")
("IFMAP.user", opt::value<string>()->default_value("dns_user"),
"IFMAP server username")
("IFMAP.stale_entries_cleanup_timeout",
opt::value<int>()->default_value(10),
"IFMAP stale entries cleanup timeout")
("IFMAP.end_of_rib_timeout", opt::value<int>()->default_value(10),
"IFMAP end of rib timeout")
("IFMAP.peer_response_wait_time", opt::value<int>()->default_value(60),
"IFMAP peer response wait time")
;

config_file_options_.add(config);
Expand Down Expand Up @@ -265,9 +271,20 @@ void Options::Process(int argc, char *argv[],
GetOptValue<uint16_t>(var_map, discovery_port_, "DISCOVERY.port");
GetOptValue<string>(var_map, discovery_server_, "DISCOVERY.server");


GetOptValue<string>(var_map, ifmap_password_, "IFMAP.password");
GetOptValue<string>(var_map, ifmap_server_url_, "IFMAP.server_url");
GetOptValue<string>(var_map, ifmap_user_, "IFMAP.user");
GetOptValue<string>(var_map, ifmap_certs_store_, "IFMAP.certs_store");
GetOptValue<string>(var_map, ifmap_config_options_.password,
"IFMAP.password");
GetOptValue<string>(var_map, ifmap_config_options_.server_url,
"IFMAP.server_url");
GetOptValue<string>(var_map, ifmap_config_options_.user,
"IFMAP.user");
GetOptValue<string>(var_map, ifmap_config_options_.certs_store,
"IFMAP.certs_store");
GetOptValue<int>(var_map,
ifmap_config_options_.stale_entries_cleanup_timeout,
"IFMAP.stale_entries_cleanup_timeout");
GetOptValue<int>(var_map, ifmap_config_options_.end_of_rib_timeout,
"IFMAP.end_of_rib_timeout");
GetOptValue<int>(var_map,
ifmap_config_options_.peer_response_wait_time,
"IFMAP.peer_response_wait_time");
}

0 comments on commit a554729

Please sign in to comment.