OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
contrail_agent_init.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 // in Boost this macro defaults to 6 but we're using FACTORY_TYPE_N8 so we need to define it manually
6 #define BOOST_FUNCTIONAL_FORWARD_ADAPTER_MAX_ARITY 8
7 
8 #include <boost/functional/forward_adapter.hpp>
9 
10 #include <cmn/agent_cmn.h>
11 #include <init/agent_param.h>
12 
13 #include <cfg/cfg_init.h>
14 #include <oper/instance_manager.h>
15 #include <oper/operdb_init.h>
18 #include <uve/agent_uve.h>
19 #include <uve/agent_uve_stats.h>
23 #include <port_ipc/rest_server.h>
25 
26 #include "contrail_agent_init.h"
27 
28 #include <cmn/agent_factory.h>
29 
31 }
32 
34  ksync_.reset();
35  uve_.reset();
36  stats_collector_.reset();
37  flow_stats_manager_.reset();
38 }
39 
41  (const std::string &config_file, const std::string &program_name) {
42  ContrailInitCommon::ProcessOptions(config_file, program_name);
43 }
44 
45 /****************************************************************************
46  * Initialization routines
47 ****************************************************************************/
48 
51  FlowStatsCollector,
52  boost::asio::io_context &,
53  int,
54  uint32_t,
55  AgentUveBase *,
56  uint32_t,
60 
62  SessionStatsCollector,
63  boost::asio::io_context &,
64  AgentUveBase *,
65  uint32_t,
66  FlowStatsManager *,
68 
69  if (agent()->tsn_enabled() == false) {
71  Agent*, uint64_t, uint32_t, uint32_t>();
72  } else {
74  Agent*, uint64_t, uint32_t, uint32_t>();
75  }
76 
77  #ifdef AGENT_VROUTER_TCP
78  #define AGENT_KSYNC_TCP true
79  #else
80  #define AGENT_KSYNC_TCP false
81  #endif
83 
86  AgentStaticObjectFactory::LinkImpl<KSync, AgentKSyncX, Agent*>();
87  } else {
88  AgentStaticObjectFactory::LinkImpl<KSync, KSync, Agent*>();
89  }
90 }
91 
94  if (agent_param()->cat_is_agent_mocked()) {
95  Pkt0Socket::CreateMockAgent(agent()->AgentGUID());
96  }
97 
98  if (agent_param()->vrouter_on_host_dpdk()) {
99  pkt0_.reset(new Pkt0Socket("unix",
100  agent()->event_manager()->io_service()));
101  } else if (agent_param()->vrouter_on_nic_mode()) {
102  pkt0_.reset(new Pkt0RawInterface("pkt0",
103  agent()->event_manager()->io_service()));
104  } else {
105  pkt0_.reset(new Pkt0Interface("pkt0",
106  agent()->event_manager()->io_service()));
107  }
108  agent()->pkt()->set_control_interface(pkt0_.get());
109 
110 
111  uve_.reset(AgentStaticObjectFactory::Create<AgentUveBase>(
112  agent(),
114  agent()->params()->vmi_vm_vn_uve_interval_msecs(),
116 
117  agent()->set_uve(uve_.get());
118 
119  if (agent()->tsn_enabled() == false) {
121  (*(agent()->event_manager()->io_service()),
122  agent()));
124  }
127 
128 
129  if (agent_param()->cat_is_dpdk_mocked()) {
130  ksync_.reset();
131  } else {
132  ksync_.reset(AgentStaticObjectFactory::Create<KSync>(agent()));
133  agent()->set_ksync(ksync_.get());
134  }
135 
136  std::string newkPortsDir = PortIpcHandler::kPortsDir;
137 
138  if (agent_param()->cat_is_agent_mocked()) {
139  newkPortsDir = "/tmp/" + agent()->AgentGUID() + newkPortsDir;
140  }
141 
143  newkPortsDir));
145 
146  rest_server_.reset(new RestServer(agent()));
148 }
149 
150 /****************************************************************************
151  * Shutdown routines
152  ***************************************************************************/
154  if (agent()->ksync()) {
155  agent()->ksync()->Shutdown();
156  }
157 }
158 
160  if (agent()->uve()) {
161  agent()->uve()->Shutdown();
162  }
163 }
164 
166  if (agent()->stats_collector()) {
168  }
169 }
170 
172  if (agent()->flow_stats_manager()) {
174  }
175 }
176 
178  sleep(5);
179 }
180 
183 
184  if (agent()->port_ipc_handler()) {
186  }
187 
188  if (agent()->rest_server()) {
189  /* Open REST API port for port add/change/deletes */
190  agent()->rest_server()->InitDone();
191  }
192  /* Reads and processes port information written by nova-compute */
194  if (pih) {
195  pih->ReloadAllPorts(!agent_param()->vrouter_on_host_dpdk());
196  }
197 }
198 
201 
202  if (agent()->rest_server()) {
203  agent()->rest_server()->Shutdown();
204  }
205 
206  if (agent()->port_ipc_handler()) {
208  }
209 }
virtual void ModulesShutdown()
bool tsn_enabled() const
Definition: agent.h:1162
std::unique_ptr< AgentStatsCollector > stats_collector_
static const std::string kPortsDir
FlowStatsManager * flow_stats_manager() const
Definition: agent.cc:925
RestServer * rest_server() const
Definition: agent.cc:997
AgentUveBase * uve() const
Definition: agent.cc:909
string program_name(string filename)
void ProcessOptions(const std::string &config_file, const std::string &program_name)
void ProcessOptions(const std::string &config_file, const std::string &program_name)
PortIpcHandler * port_ipc_handler() const
Definition: agent.cc:1005
std::unique_ptr< VrouterControlInterface > pkt0_
bool vrouter_on_host_dpdk() const
Definition: agent_param.h:347
void set_uve(AgentUveBase *uve)
Definition: agent.cc:913
void Shutdown()
Definition: ksync_init.cc:488
void set_rest_server(RestServer *r)
Definition: agent.cc:1001
bool cat_is_dpdk_mocked() const
Definition: agent_param.h:571
std::unique_ptr< FlowStatsManager > flow_stats_manager_
static void CreateMockAgent(const string &)
uint8_t type
Definition: load_balance.h:109
Definition: agent.h:358
std::unique_ptr< KSync > ksync_
void FactoryInit() override
KSync * ksync() const
Definition: agent.cc:901
static const uint64_t kBandwidthInterval
static void LinkImpl()
Definition: factory.h:68
std::unique_ptr< RestServer > rest_server_
bool vrouter_on_nic_mode() const
Definition: agent_param.h:344
virtual void Shutdown()
static const uint32_t kIncrementalInterval
void Shutdown()
Definition: rest_server.cc:343
AgentStatsCollector * stats_collector() const
Definition: agent.cc:917
void set_flow_stats_manager(FlowStatsManager *fsc)
Definition: agent.cc:929
AgentParam * agent_param() const
Definition: agent_init.h:28
std::string AgentGUID() const
Definition: agent.cc:157
void set_port_ipc_handler(PortIpcHandler *r)
Definition: agent.cc:1009
void InitDone()
Definition: rest_server.cc:311
std::unique_ptr< AgentUveBase > uve_
void set_stats_collector(AgentStatsCollector *asc)
Definition: agent.cc:921
std::unique_ptr< PortIpcHandler > port_ipc_handler_
void set_control_interface(ControlInterface *val)
Definition: pkt_init.cc:54
Agent * agent() const
Definition: agent_init.h:26
PktModule * pkt() const
Definition: agent.cc:965
void set_ksync(KSync *ksync)
Definition: agent.cc:905
void ReloadAllPorts(const std::string &dir, bool check_port, bool vm_vn_port)
bool cat_is_agent_mocked() const
Definition: agent_param.h:569