-
Notifications
You must be signed in to change notification settings - Fork 390
/
contrail_agent_init.cc
148 lines (124 loc) · 4.75 KB
/
contrail_agent_init.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#include <cmn/agent_cmn.h>
#include <cmn/agent_factory.h>
#include <init/agent_param.h>
#include <cfg/cfg_init.h>
#include <oper/operdb_init.h>
#include <controller/controller_init.h>
#include <vrouter/ksync/ksync_init.h>
#include <uve/agent_uve.h>
#include <uve/agent_uve_stats.h>
#include <vrouter/stats_collector/agent_stats_collector.h>
#include <vrouter/flow_stats/flow_stats_collector.h>
#include <openstack/instance_service_server.h>
#include <port_ipc/rest_server.h>
#include <port_ipc/port_ipc_handler.h>
#include "contrail_agent_init.h"
ContrailAgentInit::ContrailAgentInit() : ContrailInitCommon() {
}
ContrailAgentInit::~ContrailAgentInit() {
ksync_.reset();
uve_.reset();
stats_collector_.reset();
flow_stats_collector_.reset();
}
void ContrailAgentInit::ProcessOptions
(const std::string &config_file, const std::string &program_name) {
ContrailInitCommon::ProcessOptions(config_file, program_name);
}
/****************************************************************************
* Initialization routines
****************************************************************************/
void ContrailAgentInit::FactoryInit() {
if (agent()->tsn_enabled() == false) {
AgentObjectFactory::Register<AgentUveBase>
(boost::factory<AgentUveStats *>());
} else {
AgentObjectFactory::Register<AgentUveBase>
(boost::factory<AgentUve *>());
}
if (agent_param()->vrouter_on_nic_mode() || agent_param()->vrouter_on_host_dpdk()) {
AgentObjectFactory::Register<KSync>(boost::factory<KSyncTcp *>());
} else {
AgentObjectFactory::Register<KSync>(boost::factory<KSync *>());
}
AgentObjectFactory::Register<FlowTable>(boost::factory<FlowTable *>());
}
void ContrailAgentInit::CreateModules() {
ContrailInitCommon::CreateModules();
if (agent_param()->vrouter_on_host_dpdk()) {
pkt0_.reset(new Pkt0Socket("unix",
agent()->event_manager()->io_service()));
} else if (agent_param()->vrouter_on_nic_mode()) {
pkt0_.reset(new Pkt0RawInterface("pkt0",
agent()->event_manager()->io_service()));
} else {
pkt0_.reset(new Pkt0Interface("pkt0",
agent()->event_manager()->io_service()));
}
agent()->pkt()->set_control_interface(pkt0_.get());
uve_.reset(AgentObjectFactory::Create<AgentUveBase>
(agent(), AgentUveBase::kBandwidthInterval,
AgentUveBase::kDefaultInterval,
AgentUveBase::kIncrementalInterval));
agent()->set_uve(uve_.get());
if (agent()->tsn_enabled() == false) {
stats_collector_.reset(new AgentStatsCollector(
*(agent()->event_manager()->io_service()),
agent()));
agent()->set_stats_collector(stats_collector_.get());
flow_stats_collector_.reset(new FlowStatsCollector(
*(agent()->event_manager()->io_service()),
agent()->params()->flow_stats_interval(),
agent()->params()->flow_cache_timeout(),
uve_.get()));
agent()->set_flow_stats_collector(flow_stats_collector_.get());
}
ksync_.reset(AgentObjectFactory::Create<KSync>(agent()));
agent()->set_ksync(ksync_.get());
rest_server_.reset(new RESTServer(agent()));
agent()->set_rest_server(rest_server_.get());
}
void ContrailAgentInit::ConnectToController() {
InstanceInfoServiceServerInit(agent());
}
/****************************************************************************
* Shutdown routines
***************************************************************************/
void ContrailAgentInit::KSyncShutdown() {
if (agent()->ksync()) {
agent()->ksync()->Shutdown();
}
}
void ContrailAgentInit::UveShutdown() {
if (agent()->uve()) {
agent()->uve()->Shutdown();
}
}
void ContrailAgentInit::StatsCollectorShutdown() {
if (agent()->stats_collector()) {
agent()->stats_collector()->Shutdown();
}
}
void ContrailAgentInit::FlowStatsCollectorShutdown() {
if (agent()->flow_stats_collector()) {
agent()->flow_stats_collector()->Shutdown();
}
}
void ContrailAgentInit::WaitForIdle() {
sleep(5);
}
void ContrailAgentInit::InitDone() {
ContrailInitCommon::InitDone();
/* Reads and processes port information written by nova-compute */
PortIpcHandler pih(agent(), PortIpcHandler::kPortsDir, true);
pih.ReloadAllPorts();
}
void ContrailAgentInit::ModulesShutdown() {
ContrailInitCommon::ModulesShutdown();
if (agent()->rest_server()) {
agent()->rest_server()->Shutdown();
}
}