OpenSDN source code
contrail_init_common.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
6 #include <base/logging.h>
7 
8 #include <cmn/agent_cmn.h>
9 #include <init/agent_init.h>
10 #include <cmn/agent_factory.h>
11 #include <init/agent_param.h>
12 
13 #include <cfg/cfg_init.h>
14 
15 #include <oper/operdb_init.h>
16 #include <oper/vrf.h>
19 #include <pkt/pkt_init.h>
20 #include <services/services_init.h>
23 #include <uve/agent_uve.h>
24 #include <pkt/proto_handler.h>
25 #include <diag/diag.h>
26 #include <vgw/cfg_vgw.h>
27 #include <vgw/vgw.h>
29 
30 #include "contrail_init_common.h"
31 
33  ksync_enable_(true), services_enable_(true), packet_enable_(true),
34  uve_enable_(true), vgw_enable_(true), router_id_dep_enable_(true) {
35 }
36 
38  vgw_.reset();
39  ksync_.reset();
40  uve_.reset();
41 
42  diag_table_.reset();
43  services_.reset();
44  pkt_.reset();
45  mac_learning_module_.reset();
46 }
47 
49  (const std::string &config_file, const std::string &program_name) {
51 }
52 
54  return AgentInit::Start(logging);
55 }
56 
57 /****************************************************************************
58  * Initialization routines
59  ***************************************************************************/
61  pkt_.reset(new PktModule(agent()));
62  agent()->set_pkt(pkt_.get());
63 
64  if (services_enable_) {
65  services_.reset
66  (new ServicesModule(agent(), agent_param()->metadata_shared_secret()));
67  agent()->set_services(services_.get());
68  }
69  if (vgw_enable_) {
70  vgw_.reset(new VirtualGateway(agent()));
71  agent()->set_vgw(vgw_.get());
72  }
73 
76 }
77 
79  if (agent()->uve()) {
80  agent()->uve()->RegisterDBClients();
81  }
82 
83  if (agent()->ksync()) {
84  agent()->ksync()->RegisterDBClients(agent()->db());
85  }
86 
87  if (agent()->vgw()) {
88  agent()->vgw()->RegisterDBClients();
89  }
90 
91  if (agent()->flow_stats_manager()) {
93  }
94 }
95 
97 
98  if(agent()->params()->cat_is_dpdk_mocked()) {
99  ksync_enable_= false;
100  }
101 
102  if (agent()->pkt()) {
103  agent()->pkt()->Init(ksync_enable());
104  }
105 
106  if (agent()->services()) {
107  agent()->services()->Init(ksync_enable());
108  }
109 
110  if (agent()->uve()) {
111  agent()->uve()->Init();
112  }
113 
114  if (agent()->ksync()) {
115  agent()->ksync()->Init(create_vhost_);
116  }
117 
118  if (agent()->mac_learning_module()) {
120  }
121 
122  if (agent()->flow_stats_manager()) {
123  agent()->flow_stats_manager()->Init(agent()->params()->flow_stats_interval(),
124  agent()->params()->flow_cache_timeout());
125  }
126 }
127 
129  VrfTable *vrf_table = agent()->vrf_table();
130 
131  if (agent()->isXenMode()) {
132  vrf_table->CreateStaticVrf(agent()->linklocal_vrf_name());
133  }
134 
135  // Create VRF for VGw
136  if (agent()->vgw()) {
137  agent()->vgw()->CreateVrf();
138  }
139 }
140 
141 static PhysicalInterface::EncapType ComputeEncapType(const string &encap) {
142  if (encap == "none") {
144  }
146 }
147 
149  InetUnicastAgentRouteTable *rt_table =
151 
152  const AgentParam::AddressList &addr_list =
153  param->compute_node_address_list();
154  AgentParam::AddressList::const_iterator it = addr_list.begin();
155  while (it != addr_list.end()) {
157  boost::uuids::nil_uuid(),
158  param->vhost_name());
159  rt_table->AddVHostRecvRouteReq(agent()->local_peer(),
160  agent()->fabric_vrf_name(),
161  vmi_key, *it, 32,
162  agent()->fabric_vn_name(), false,
163  true);
164  it++;
165  }
166 
167  // If compute_node_address are specified, it will mean user wants
168  // to run services such as metadata on an IP different than vhost.
169  // Set compute_node_ip_ to vhost_addr if no compute_node_address are
170  // specified. Else, pick first address to run in compute_node_address_list
171  //
172  // The compute_node_ip is used only in adding Flow NAT rules.
173  if (param->compute_node_address_list().size()) {
175  }
176 }
177 
179  InterfaceTable *table = agent()->interface_table();
181 
184  if (agent_param()->vrouter_on_host_dpdk()) {
185  //TODO : transport type for vhost interface should
186  //be set to KNI
187  vhost_transport = Interface::TRANSPORT_PMD;
188  physical_transport = Interface::TRANSPORT_PMD;
189  }
190 
191  if (agent_param()->vrouter_on_nic_mode()) {
192  vhost_transport = Interface::TRANSPORT_PMD;
193  physical_transport = Interface::TRANSPORT_PMD;
194  }
195 
196  Interface *physical_intf = NULL;
198  InetUnicastAgentRouteTable *rt_table =
200  type = ComputeEncapType(agent_param()->eth_port_encap_type());
201  for (std::size_t i = 0; i != agent_param()->eth_port_list().size(); ++i) {
202  PhysicalInterface::Create(table, agent_param()->eth_port_list()[i],
203  agent()->fabric_vrf_name(),
205  agent_param()->eth_port_no_arp(),
206  boost::uuids::nil_uuid(),
207  agent()->is_l3mh() ?
208  agent_param()->eth_port_addr_list()[i] :
209  agent_param()->vhost_addr(),
210  physical_transport);
211  PhysicalInterfaceKey physical_key(agent_param()->eth_port_list()[i]);
212  assert(table->FindActiveEntry(&physical_key));
213  physical_intf =
214  static_cast<Interface *>(table->FindActiveEntry(&physical_key));
215 
216  // Add L2 receive routes for physical interface MACs to both vrf 0 and 1.
218  agent()->fabric_vrf_name(), 0,
219  physical_intf->mac(), "");
222  physical_intf->mac(), "");
223 
224  if (agent()->is_l3mh()) {
226  boost::uuids::nil_uuid(),
227  agent()->params()->vhost_name());
228  // Receive route for physical interface IP address assigned
229  rt_table->AddVHostRecvRouteReq(agent()->local_peer(),
230  agent()->fabric_vrf_name(), vmi_key,
231  agent_param()->eth_port_addr_list()[i], 32,
232  agent()->fabric_vn_name(), false, true);
233  // Receive route for the sub-net broadcast address
234  rt_table->AddVHostSubnetRecvRoute(agent()->local_peer(),
235  agent()->fabric_vrf_name(), vmi_key,
237  agent_param()->eth_port_addr_list()[i],
238  agent_param()->eth_port_plen_list()[i]),
239  32, agent()->fabric_vn_name(), false);
240  // Add resolve route for physical interface ip-addr to vrf 0
241  rt_table->AddResolveRoute(agent()->local_peer(),
242  agent()->fabric_vrf_name(),
243  agent_param()->eth_port_addr_list()[i],
244  agent_param()->eth_port_plen_list()[i],
245  physical_key, MplsTable::kInvalidLabel,
246  false, agent()->fabric_vn_name(),
248  }
249  }
250 
251  if (agent()->is_l3mh()) {
252  agent()->set_router_id(agent_param()->loopback_ip());
253  } else {
254  agent()->set_router_id(agent_param()->vhost_addr());
255  agent()->set_vhost_prefix(agent_param()->vhost_prefix());
256  agent()->set_vhost_prefix_len(agent_param()->vhost_plen());
257  agent()->set_vhost_default_gateway(agent_param()->gateway_list());
258  }
259  if (agent_param()->crypt_port() != "") {
260  type = ComputeEncapType(agent_param()->crypt_port_encap_type());
261  PhysicalInterface::Create(table, agent_param()->crypt_port(),
262  agent()->fabric_vrf_name(),
264  agent_param()->crypt_port_no_arp(),
265  boost::uuids::nil_uuid(),
266  agent_param()->vhost_addr(),
267  physical_transport);
268  PhysicalInterfaceKey physical_key(agent()->crypt_interface_name());
270  (static_cast<Interface *>(table->FindActiveEntry(&physical_key)));
271  assert(agent()->crypt_interface());
272  }
273 
274  //Add the interface
275  table->CreateVhost();
276  //Trigger explicit change to sync the configuration
277  table->CreateVhost();
278  if (agent()->tsn_enabled()) {
279  InetInterfaceKey key(agent()->vhost_interface_name());
281  (static_cast<Interface *>(table->FindActiveEntry(&key)));
282  } else {
283  VmInterfaceKey key(AgentKey::ADD_DEL_CHANGE, boost::uuids::nil_uuid(),
284  agent()->vhost_interface_name());
286  (static_cast<Interface *>(table->FindActiveEntry(&key)));
287  }
288  assert(agent()->vhost_interface());
289 
290  // Add vhost labelled inet route
291  InetUnicastAgentRouteTable *inet_mpls_table =
292  static_cast<InetUnicastAgentRouteTable *>
294  inet_mpls_table->AddVhostMplsRoute(agent()->is_l3mh() ?
295  agent()->params()->loopback_ip() :
296  agent()->params()->vhost_addr(),
298 
299  /* Add Receive route for agent loopback incase of l3mh */
300  if (agent()->is_l3mh()) {
301  InetUnicastAgentRouteTable *rt_table =
303 
305  boost::uuids::nil_uuid(),
306  agent()->params()->vhost_name());
307  rt_table->AddVHostRecvRouteReq(agent()->local_peer(),
308  agent()->fabric_vrf_name(),
309  vmi_key, agent()->params()->loopback_ip(), 32,
310  agent()->fabric_vn_name(), false,
311  true);
312  }
313 
315  if (agent_param()->isVmwareMode()) {
316  PhysicalInterface::Create(agent()->interface_table(),
317  agent_param()->vmware_physical_port(),
318  agent()->fabric_vrf_name(),
321  boost::uuids::nil_uuid(), Ip4Address(0),
322  physical_transport);
323 
324  PhysicalInterfaceKey vmware_pk(agent_param()->vmware_physical_port());
325  const Interface *vmware_intf =
326  static_cast<const Interface *>(table->FindActiveEntry(&vmware_pk));
328  agent()->fabric_vrf_name(), 0,
329  vmware_intf->mac(), "");
332  vmware_intf->mac(), "");
333  }
334 
335  if (agent()->pkt()) {
336  agent()->pkt()->CreateInterfaces();
337  }
338 
339  if (agent()->vgw()) {
340  agent()->vgw()->CreateInterfaces(vhost_transport);
341  }
342 
344 }
345 
347  //Open up mirror socket
349 
350  if (agent()->services()) {
351  agent()->services()->ConfigInit();
352  }
353 
354  // Diag module needs PktModule
355  if (agent()->pkt()) {
356  diag_table_.reset(new DiagTable(agent()));
357  agent()->set_diag_table(diag_table_.get());
358  }
359 
360  if (create_vhost_) {
361  //Update mac address of vhost interface with
362  //that of ethernet interface
363  agent()->ksync()->UpdateVhostMac();
364  }
365 
366  if (ksync_enable_) {
368  }
369 
370  if (agent()->pkt()) {
371  agent()->pkt()->InitDone();
372  }
373 
374  if (agent()->uve()) {
375  agent()->uve()->InitDone();
376  }
377 
378  if (agent()->ksync()) {
379  agent()->ksync()->InitDone();
380  }
381 
382  if (agent()->oper_db()) {
383  agent()->oper_db()->InitDone();
384  }
385 }
386 
387 /****************************************************************************
388  * Shutdown routines
389  ***************************************************************************/
391  if (agent()->pkt())
392  agent()->pkt()->IoShutdown();
393 
394  if (agent()->services())
395  agent()->services()->IoShutdown();
396 }
397 
399  if (agent()->pkt())
400  agent()->pkt()->FlushFlows();
401 }
402 
404  if (agent()->services())
405  agent()->services()->Shutdown();
406 
407  if (agent()->mac_learning_module()) {
409  }
410 }
411 
413  if (agent()->pkt()) {
414  agent()->pkt()->Shutdown();
415  }
416 }
417 
419  if (agent()->diag_table()) {
420  agent()->diag_table()->Shutdown();
421  }
422 }
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:15
Ip4Address GetIp4SubnetBroadcastAddress(const Ip4Address &ip_prefix, uint16_t plen)
std::vector< uint64_t > TagList
Definition: agent.h:203
std::vector< int > SecurityGroupList
Definition: agent.h:202
AgentDBEntry * FindActiveEntry(const DBEntry *key)
Definition: agent_db.cc:111
virtual void ProcessOptions(const std::string &config_file, const std::string &program_name)
Definition: agent_init.cc:53
AgentParam * agent_param() const
Definition: agent_init.h:31
virtual int Start(Logging &logging)
Definition: agent_init.cc:94
Agent * agent() const
Definition: agent_init.h:29
const std::string & vhost_name() const
Definition: agent_param.h:183
const Ip4Address & vhost_addr() const
Definition: agent_param.h:184
std::vector< Ip4Address > AddressList
Definition: agent_param.h:118
const Ip4Address & loopback_ip() const
Definition: agent_param.h:576
const std::vector< std::string > & eth_port_list() const
Definition: agent_param.h:205
const AddressList & compute_node_address_list() const
Definition: agent_param.h:393
virtual void RegisterDBClients()
virtual void InitDone()
InterfaceTable * interface_table() const
Definition: agent.h:468
ServicesModule * services() const
Definition: agent.cc:977
VirtualGateway * vgw() const
Definition: agent.cc:993
OperDB * oper_db() const
Definition: agent.cc:1017
BridgeAgentRouteTable * fabric_l2_unicast_table() const
Definition: agent.h:621
void set_vhost_prefix(const Ip4Address &addr)
Definition: agent.h:652
MacLearningModule * mac_learning_module() const
Definition: agent.h:1016
void set_crypt_interface(const Interface *interface)
Definition: agent.h:1147
FlowStatsManager * flow_stats_manager() const
Definition: agent.cc:929
AgentParam * params() const
Definition: agent.h:1227
void InitXenLinkLocalIntf()
Definition: agent.cc:679
void set_mac_learning_module(MacLearningModule *mac_learning_module)
Definition: agent.h:1020
const std::string & fabric_policy_vrf_name() const
Definition: agent.h:911
MirrorTable * mirror_table() const
Definition: agent.h:528
void set_vhost_default_gateway(const AddressList &addr_list)
Definition: agent.h:660
VrfTable * vrf_table() const
Definition: agent.h:488
AgentUveBase * uve() const
Definition: agent.cc:913
void set_vhost_prefix_len(uint32_t plen)
Definition: agent.h:657
const Peer * fabric_rt_export_peer() const
Definition: agent.h:1040
const Peer * local_vm_peer() const
Definition: agent.h:1026
void set_pkt(PktModule *pkt)
Definition: agent.cc:973
bool is_l3mh() const
Definition: agent.h:728
void set_diag_table(DiagTable *table)
Definition: agent.cc:881
KSync * ksync() const
Definition: agent.cc:905
void set_router_id(const Ip4Address &addr)
Definition: agent.h:674
void set_vgw(VirtualGateway *vgw)
Definition: agent.cc:997
VrfEntry * fabric_vrf() const
Definition: agent.h:918
void set_services(ServicesModule *services)
Definition: agent.cc:981
void set_vhost_interface(const Interface *intrface)
Definition: agent.h:941
InetUnicastAgentRouteTable * fabric_inet4_unicast_table() const
Definition: agent.h:581
void set_compute_node_ip(const Ip4Address &addr)
Definition: agent.h:685
DiagTable * diag_table() const
Definition: agent.cc:877
const std::string & fabric_vrf_name() const
Definition: agent.h:906
PktModule * pkt() const
Definition: agent.cc:969
static void AddBridgeReceiveRoute(const Peer *peer, const std::string &vrf_name, const MacAddress &mac, const std::string &vn_name, const std::string &interface, bool policy)
std::unique_ptr< DiagTable > diag_table_
void ProcessOptions(const std::string &config_file, const std::string &program_name)
std::unique_ptr< AgentUveBase > uve_
std::unique_ptr< KSync > ksync_
std::unique_ptr< MacLearningModule > mac_learning_module_
std::unique_ptr< PktModule > pkt_
std::unique_ptr< ServicesModule > services_
void ProcessComputeAddress(AgentParam *param)
virtual void ModulesShutdown()
std::unique_ptr< VirtualGateway > vgw_
int Start(Logging &logging)
void Shutdown()
Definition: diag.cc:128
void Init(uint64_t flow_stats_interval, uint64_t flow_cache_timeout)
static void AddResolveRoute(const Peer *peer, const string &vrf_name, const Ip4Address &ip, const uint8_t plen, const InterfaceKey &intf_key, const uint32_t label, bool policy, const std::string &vn_name, const SecurityGroupList &sg_list, const TagList &tag_list)
static void AddVHostRecvRouteReq(const Peer *peer, const string &vrf, const InterfaceKey &interface, const IpAddress &addr, uint8_t plen, const string &vn_name, bool policy, bool native_encap)
static void AddVHostSubnetRecvRoute(const Peer *peer, const string &vrf, const InterfaceKey &interface, const Ip4Address &addr, uint8_t plen, const std::string &vn_name, bool policy)
void AddVhostMplsRoute(const IpAddress &vhost_addr, const Peer *peer)
void CreateVhost()
Definition: interface.cc:426
const MacAddress & mac() const
Definition: interface.h:134
@ TRANSPORT_PMD
Definition: interface.h:70
@ TRANSPORT_ETHERNET
Definition: interface.h:68
void UpdateVhostMac()
Definition: ksync_init.cc:455
virtual void RegisterDBClients(DB *db)
Definition: ksync_init.cc:107
virtual void Init(bool create_vhost)
Definition: ksync_init.cc:122
virtual void InitDone()
Definition: ksync_init.cc:140
void VnswInterfaceListenerInit()
Definition: ksync_init.cc:411
A class providing basic control over logging capabilities in OpenSDN control plane.
Definition: logging.h:44
void MirrorSockInit(void)
static const uint32_t kInvalidLabel
Definition: mpls.h:102
void InitDone()
Definition: operdb_init.cc:343
static void Create(InterfaceTable *table, const std::string &ifname, const std::string &vrf_name, SubType subtype, EncapType encap, bool no_arp, const boost::uuids::uuid &device_uuid, const Ip4Address &ip, Interface::Transport transport_)
void InitDone()
Definition: pkt_init.cc:51
void Init(bool run_with_vrouter)
Definition: pkt_init.cc:31
void FlushFlows()
Definition: pkt_init.cc:80
void Shutdown()
Definition: pkt_init.cc:59
void CreateInterfaces()
Definition: pkt_init.cc:84
void IoShutdown()
Definition: pkt_init.cc:76
void Init(bool run_with_vrouter)
void CreateVrf()
Definition: vgw.cc:102
void RegisterDBClients()
Definition: vgw.cc:96
void CreateInterfaces(Interface::Transport transport)
Definition: vgw.cc:123
InetUnicastAgentRouteTable * GetInet4MplsUnicastRouteTable() const
Definition: vrf.cc:324
Definition: vrf.h:272
void CreateStaticVrf(const string &name)
Definition: vrf.cc:996
static PhysicalInterface::EncapType ComputeEncapType(const string &encap)
uint8_t type
Definition: load_balance.h:2
string program_name(string filename)
@ ADD_DEL_CHANGE
Definition: agent_db.h:101