Skip to content

Commit

Permalink
Send Generator Name from agent in correct format.
Browse files Browse the repository at this point in the history
Send hostname instead of agent_name in InitGenerator
Also send module id as contrail-tor-agent for tor agent instead of TorAgent-<tor-id>

Change-Id: If4de1e659518d9176058d261b89e0c271fc0aabc
Closes-Bug: #1455618
  • Loading branch information
ashoksr committed May 22, 2015
1 parent 17f622d commit e8be8f0
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 18 deletions.
4 changes: 4 additions & 0 deletions src/sandesh/common/vns.sandesh
Expand Up @@ -180,6 +180,7 @@ enum Module {
CONTRAIL_TOPOLOGY,
INVENTORY_AGENT,
ALARM_GENERATOR,
TOR_AGENT,
MAX_MODULE,
}

Expand Down Expand Up @@ -220,6 +221,7 @@ const string MODULE_IPMI_STATS_MGR_NAME = "Ipmi-Stats-mgr"
const string MODULE_CONTRAIL_SNMP_COLLECTOR_NAME = "contrail-snmp-collector"
const string MODULE_CONTRAIL_TOPOLOGY_NAME = "contrail-topology"
const string MODULE_SERVER_INVENTORY_AGENT_NAME = "InventoryAgent"
const string MODULE_TOR_AGENT_NAME = "contrail-tor-agent"

const map<Module, string> ModuleNames = {
Module.CONTROL_NODE : MODULE_CONTROL_NODE_NAME,
Expand Down Expand Up @@ -247,6 +249,7 @@ const map<Module, string> ModuleNames = {
Module.CONTRAIL_TOPOLOGY : MODULE_CONTRAIL_TOPOLOGY_NAME,
Module.INVENTORY_AGENT : MODULE_SERVER_INVENTORY_AGENT_NAME,
Module.ALARM_GENERATOR : MODULE_ALARM_GENERATOR_NAME,
Module.TOR_AGENT : MODULE_TOR_AGENT_NAME,
}

const map<string, Module> ModuleIds = {
Expand Down Expand Up @@ -328,6 +331,7 @@ const map <Module, NodeType> Module2NodeType = {
Module.CONTRAIL_SNMP_COLLECTOR : NodeType.ANALYTICS,
Module.CONTRAIL_TOPOLOGY : NodeType.ANALYTICS,
Module.INVENTORY_AGENT : NodeType.COMPUTE,
Module.TOR_AGENT : NodeType.COMPUTE,
}

const string INSTANCE_ID_DEFAULT = "0"
Expand Down
9 changes: 4 additions & 5 deletions src/vnsw/agent/cfg/discovery_agent.cc
Expand Up @@ -135,11 +135,10 @@ void DiscoveryAgentClient::DiscoverServices() {

//subscribe to collector service
if (param_->collector_server_list().size() == 0) {
Module::type module = Module::VROUTER_AGENT;
Module::type module = static_cast<Module::type>
(agent->module_type());
NodeType::type node_type =
g_vns_constants.Module2NodeType.find(module)->second;
std::string subscriber_name =
agent->discovery_client_name();
std::string node_type_name =
g_vns_constants.NodeTypeNames.find(node_type)->second;

Expand All @@ -148,8 +147,8 @@ void DiscoveryAgentClient::DiscoverServices() {
ds_client, _1, _2, _3);
std::vector<std::string> list;
list.clear();
Sandesh::InitGenerator(subscriber_name,
agent->agent_name(),
Sandesh::InitGenerator(agent->module_name(),
agent->host_name(),
node_type_name,
agent->instance_id(),
agent->event_manager(),
Expand Down
22 changes: 15 additions & 7 deletions src/vnsw/agent/cmn/agent.cc
Expand Up @@ -296,21 +296,21 @@ void Agent::InitCollector() {
* collector. If not we still need to invoke InitGenerator to initialize
* introspect.
*/
Module::type module = Module::VROUTER_AGENT;
Module::type module = static_cast<Module::type>(module_type_);
NodeType::type node_type =
g_vns_constants.Module2NodeType.find(module)->second;
if (params_->collector_server_list().size() != 0) {
Sandesh::InitGenerator(discovery_client_name_,
agent_name(),
Sandesh::InitGenerator(module_name(),
host_name(),
g_vns_constants.NodeTypeNames.find(node_type)->second,
instance_id_,
event_manager(),
params_->http_server_port(), 0,
params_->collector_server_list(),
NULL);
} else {
Sandesh::InitGenerator(discovery_client_name_,
agent_name(),
Sandesh::InitGenerator(module_name(),
host_name(),
g_vns_constants.NodeTypeNames.find(node_type)->second,
instance_id_,
event_manager(),
Expand Down Expand Up @@ -394,7 +394,8 @@ Agent::Agent() :
dns_xmpp_client_(), dns_xmpp_init_(), agent_stale_cleaner_(NULL),
cn_mcast_builder_(NULL), ds_client_(NULL), host_name_(""), agent_name_(""),
prog_name_(""), introspect_port_(0),
instance_id_(g_vns_constants.INSTANCE_ID_DEFAULT), db_(NULL),
instance_id_(g_vns_constants.INSTANCE_ID_DEFAULT),
module_type_(Module::VROUTER_AGENT), db_(NULL),
task_scheduler_(NULL), agent_init_(NULL), intf_table_(NULL),
nh_table_(NULL), uc_rt_table_(NULL), mc_rt_table_(NULL), vrf_table_(NULL),
vm_table_(NULL), vn_table_(NULL), sg_table_(NULL), mpls_table_(NULL),
Expand Down Expand Up @@ -431,7 +432,10 @@ Agent::Agent() :
SetAgentTaskPolicy();
CreateLifetimeManager();

discovery_client_name_ = g_vns_constants.ModuleNames.find(Module::VROUTER_AGENT)->second;
Module::type module = static_cast<Module::type>(module_type_);
module_name_ = g_vns_constants.ModuleNames.find(module)->second;
discovery_client_name_ = BuildDiscoveryClientName(module_name_,
instance_id_);

agent_signal_.reset(
AgentObjectFactory::Create<AgentSignal>(event_mgr_));
Expand Down Expand Up @@ -595,3 +599,7 @@ bool Agent::vrouter_on_host_dpdk() const {
bool Agent::vrouter_on_host() const {
return params_->vrouter_on_host();
}

const string Agent::BuildDiscoveryClientName(string mod_name, string id) {
return (mod_name + ":" + id);
}
10 changes: 10 additions & 0 deletions src/vnsw/agent/cmn/agent.h
Expand Up @@ -554,6 +554,12 @@ class Agent {
const std::string &instance_id() const { return instance_id_; }
void set_instance_id(const std::string &id) { instance_id_ = id; }

const int &module_type() const { return module_type_; }
void set_module_type(int id) { module_type_ = id; }

const std::string &module_name() const { return module_name_; }
void set_module_name(const std::string &name) { module_name_ = name; }

// Multicast related
const std::string &multicast_label_range(uint8_t idx) {
return label_range_[idx];
Expand Down Expand Up @@ -802,6 +808,8 @@ class Agent {
bool vrouter_on_host() const;
void SetAgentTaskPolicy();
void CopyConfig(AgentParam *params);
const std::string BuildDiscoveryClientName(std::string mod_name,
std::string id);

void Init(AgentParam *param);
void InitPeers();
Expand Down Expand Up @@ -852,6 +860,8 @@ class Agent {
std::string prog_name_;
int introspect_port_;
std::string instance_id_;
int module_type_;
std::string module_name_;

// DB handles
DB *db_;
Expand Down
15 changes: 13 additions & 2 deletions src/vnsw/agent/init/agent_init.cc
Expand Up @@ -48,8 +48,12 @@ void AgentInit::ProcessOptions
agent_param_->Init(config_file, program_name);
}

int AgentInit::ModuleType() {
return Module::VROUTER_AGENT;
}

string AgentInit::ModuleName() {
Module::type module = Module::VROUTER_AGENT;
Module::type module = static_cast<Module::type>(ModuleType());
return g_vns_constants.ModuleNames.find(module)->second;
}

Expand All @@ -74,9 +78,16 @@ int AgentInit::Start() {
agent_->CopyConfig(agent_param_);

string module_name = ModuleName();
agent_->set_discovery_client_name(module_name);
/* Discovery client name should have InstanceId as well because multiple
* instances of tor-agent can run on a single node.
*/
string ds_client_name =
agent_->BuildDiscoveryClientName(module_name, InstanceId());
agent_->set_discovery_client_name(ds_client_name);
agent_->set_agent_name(AgentName());
agent_->set_instance_id(InstanceId());
agent_->set_module_type(ModuleType());
agent_->set_module_name(module_name);


std::string log_property_file = agent_param_->log_property_file();
Expand Down
1 change: 1 addition & 0 deletions src/vnsw/agent/init/agent_init.h
Expand Up @@ -39,6 +39,7 @@ class AgentInit {

virtual std::string InstanceId();
virtual std::string ModuleName();
virtual int ModuleType();
virtual std::string AgentName();

// Init has two set of routines
Expand Down
4 changes: 2 additions & 2 deletions src/vnsw/agent/ovs_tor_agent/tor_agent_init.cc
Expand Up @@ -61,8 +61,8 @@ string TorAgentInit::InstanceId() {
return param->tor_id();
}

string TorAgentInit::ModuleName() {
return "TorAgent-" + InstanceId();
int TorAgentInit::ModuleType() {
return Module::TOR_AGENT;
}

void TorAgentInit::FactoryInit() {
Expand Down
2 changes: 1 addition & 1 deletion src/vnsw/agent/ovs_tor_agent/tor_agent_init.h
Expand Up @@ -29,7 +29,7 @@ class TorAgentInit : public AgentInit {
int Start();

virtual std::string InstanceId();
virtual std::string ModuleName();
virtual int ModuleType();
// Initialization virtual methods
void FactoryInit();
void CreatePeers();
Expand Down
2 changes: 1 addition & 1 deletion src/vnsw/agent/uve/agent_uve_base.cc
Expand Up @@ -56,7 +56,7 @@ void AgentUveBase::Shutdown() {
}

void AgentUveBase::Init() {
std::string module_id(agent_->discovery_client_name());
std::string module_id(agent_->module_name());
std::string instance_id(agent_->instance_id());
EventManager *evm = agent_->event_manager();
boost::asio::io_service &io = *evm->io_service();
Expand Down

0 comments on commit e8be8f0

Please sign in to comment.