OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
contrail_init_common.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #include <base/logging.h>
6 
7 #include <cmn/agent_cmn.h>
8 #include <init/agent_init.h>
9 #include <cmn/agent_factory.h>
10 #include <init/agent_param.h>
11 
12 #include <cfg/cfg_init.h>
13 
14 #include <oper/operdb_init.h>
15 #include <oper/vrf.h>
18 #include <pkt/pkt_init.h>
19 #include <services/services_init.h>
22 #include <uve/agent_uve.h>
23 #include <pkt/proto_handler.h>
24 #include <diag/diag.h>
25 #include <vgw/cfg_vgw.h>
26 #include <vgw/vgw.h>
28 
29 #include "contrail_init_common.h"
30 
32  ksync_enable_(true), services_enable_(true), packet_enable_(true),
33  uve_enable_(true), vgw_enable_(true), router_id_dep_enable_(true) {
34 }
35 
37  vgw_.reset();
38  ksync_.reset();
39  uve_.reset();
40 
41  diag_table_.reset();
42  services_.reset();
43  pkt_.reset();
44  mac_learning_module_.reset();
45 }
46 
48  (const std::string &config_file, const std::string &program_name) {
49  AgentInit::ProcessOptions(config_file, program_name);
50 }
51 
53  return AgentInit::Start();
54 }
55 
56 /****************************************************************************
57  * Initialization routines
58  ***************************************************************************/
60  pkt_.reset(new PktModule(agent()));
61  agent()->set_pkt(pkt_.get());
62 
63  if (services_enable_) {
64  services_.reset
65  (new ServicesModule(agent(), agent_param()->metadata_shared_secret()));
66  agent()->set_services(services_.get());
67  }
68  if (vgw_enable_) {
69  vgw_.reset(new VirtualGateway(agent()));
70  agent()->set_vgw(vgw_.get());
71  }
72 
75 }
76 
78  if (agent()->uve()) {
79  agent()->uve()->RegisterDBClients();
80  }
81 
82  if (agent()->ksync()) {
83  agent()->ksync()->RegisterDBClients(agent()->db());
84  }
85 
86  if (agent()->vgw()) {
87  agent()->vgw()->RegisterDBClients();
88  }
89 
90  if (agent()->flow_stats_manager()) {
92  }
93 }
94 
96 
97  if(agent()->params()->cat_is_dpdk_mocked()) {
98  ksync_enable_= false;
99  }
100 
101  if (agent()->pkt()) {
102  agent()->pkt()->Init(ksync_enable());
103  }
104 
105  if (agent()->services()) {
106  agent()->services()->Init(ksync_enable());
107  }
108 
109  if (agent()->uve()) {
110  agent()->uve()->Init();
111  }
112 
113  if (agent()->ksync()) {
114  agent()->ksync()->Init(create_vhost_);
115  }
116 
117  if (agent()->mac_learning_module()) {
119  }
120 
121  if (agent()->flow_stats_manager()) {
122  agent()->flow_stats_manager()->Init(agent()->params()->flow_stats_interval(),
123  agent()->params()->flow_cache_timeout());
124  }
125 }
126 
128  VrfTable *vrf_table = agent()->vrf_table();
129 
130  if (agent()->isXenMode()) {
131  vrf_table->CreateStaticVrf(agent()->linklocal_vrf_name());
132  }
133 
134  // Create VRF for VGw
135  if (agent()->vgw()) {
136  agent()->vgw()->CreateVrf();
137  }
138 }
139 
140 static PhysicalInterface::EncapType ComputeEncapType(const string &encap) {
141  if (encap == "none") {
143  }
145 }
146 
148  InetUnicastAgentRouteTable *rt_table =
150 
151  const AgentParam::AddressList &addr_list =
152  param->compute_node_address_list();
153  AgentParam::AddressList::const_iterator it = addr_list.begin();
154  while (it != addr_list.end()) {
156  boost::uuids::nil_uuid(),
157  param->vhost_name());
158  rt_table->AddVHostRecvRouteReq(agent()->local_peer(),
159  agent()->fabric_vrf_name(),
160  vmi_key, *it, 32,
161  agent()->fabric_vn_name(), false,
162  true);
163  it++;
164  }
165 
166  // If compute_node_address are specified, it will mean user wants
167  // to run services such as metadata on an IP different than vhost.
168  // Set compute_node_ip_ to vhost_addr if no compute_node_address are
169  // specified. Else, pick first address to run in compute_node_address_list
170  //
171  // The compute_node_ip is used only in adding Flow NAT rules.
172  if (param->compute_node_address_list().size()) {
174  }
175 }
176 
178  InterfaceTable *table = agent()->interface_table();
180 
183  if (agent_param()->vrouter_on_host_dpdk()) {
184  //TODO : transport type for vhost interface should
185  //be set to KNI
186  vhost_transport = Interface::TRANSPORT_PMD;
187  physical_transport = Interface::TRANSPORT_PMD;
188  }
189 
190  if (agent_param()->vrouter_on_nic_mode()) {
191  vhost_transport = Interface::TRANSPORT_PMD;
192  physical_transport = Interface::TRANSPORT_PMD;
193  }
194 
195  Interface *physical_intf = NULL;
197  InetUnicastAgentRouteTable *rt_table =
199  type = ComputeEncapType(agent_param()->eth_port_encap_type());
200  for (std::size_t i = 0; i != agent_param()->eth_port_list().size(); ++i) {
201  PhysicalInterface::Create(table, agent_param()->eth_port_list()[i],
202  agent()->fabric_vrf_name(),
204  agent_param()->eth_port_no_arp(),
205  boost::uuids::nil_uuid(),
206  agent()->is_l3mh() ?
207  agent_param()->eth_port_addr_list()[i] :
208  agent_param()->vhost_addr(),
209  physical_transport);
210  PhysicalInterfaceKey physical_key(agent_param()->eth_port_list()[i]);
211  assert(table->FindActiveEntry(&physical_key));
212  physical_intf =
213  static_cast<Interface *>(table->FindActiveEntry(&physical_key));
214 
215  // Add L2 receive routes for physical interface MACs to both vrf 0 and 1.
216  l2_table->AddBridgeReceiveRoute(agent()->local_vm_peer(),
217  agent()->fabric_vrf_name(), 0,
218  physical_intf->mac(), "");
219  l2_table->AddBridgeReceiveRoute(agent()->local_vm_peer(),
220  agent()->fabric_policy_vrf_name(), 0,
221  physical_intf->mac(), "");
222 
223  if (agent()->is_l3mh()) {
225  boost::uuids::nil_uuid(),
226  agent()->params()->vhost_name());
227  // Receive route for physical interface IP address assigned
228  rt_table->AddVHostRecvRouteReq(agent()->local_peer(),
229  agent()->fabric_vrf_name(), vmi_key,
230  agent_param()->eth_port_addr_list()[i], 32,
231  agent()->fabric_vn_name(), false, true);
232  // Receive route for the sub-net broadcast address
233  rt_table->AddVHostSubnetRecvRoute(agent()->local_peer(),
234  agent()->fabric_vrf_name(), vmi_key,
236  agent_param()->eth_port_addr_list()[i],
237  agent_param()->eth_port_plen_list()[i]),
238  32, agent()->fabric_vn_name(), false);
239  // Add resolve route for physical interface ip-addr to vrf 0
240  rt_table->AddResolveRoute(agent()->local_peer(),
241  agent()->fabric_vrf_name(),
242  agent_param()->eth_port_addr_list()[i],
243  agent_param()->eth_port_plen_list()[i],
244  physical_key, MplsTable::kInvalidLabel,
245  false, agent()->fabric_vn_name(),
247  }
248  }
249 
250  if (agent()->is_l3mh()) {
251  agent()->set_router_id(agent_param()->loopback_ip());
252  } else {
253  agent()->set_router_id(agent_param()->vhost_addr());
254  agent()->set_vhost_prefix(agent_param()->vhost_prefix());
255  agent()->set_vhost_prefix_len(agent_param()->vhost_plen());
256  agent()->set_vhost_default_gateway(agent_param()->gateway_list());
257  }
258  if (agent_param()->crypt_port() != "") {
259  type = ComputeEncapType(agent_param()->crypt_port_encap_type());
260  PhysicalInterface::Create(table, agent_param()->crypt_port(),
261  agent()->fabric_vrf_name(),
263  agent_param()->crypt_port_no_arp(),
264  boost::uuids::nil_uuid(),
265  agent_param()->vhost_addr(),
266  physical_transport);
267  PhysicalInterfaceKey physical_key(agent()->crypt_interface_name());
269  (static_cast<Interface *>(table->FindActiveEntry(&physical_key)));
270  assert(agent()->crypt_interface());
271  }
272 
273  //Add the interface
274  table->CreateVhost();
275  //Trigger explicit change to sync the configuration
276  table->CreateVhost();
277  if (agent()->tsn_enabled()) {
278  InetInterfaceKey key(agent()->vhost_interface_name());
280  (static_cast<Interface *>(table->FindActiveEntry(&key)));
281  } else {
282  VmInterfaceKey key(AgentKey::ADD_DEL_CHANGE, boost::uuids::nil_uuid(),
283  agent()->vhost_interface_name());
285  (static_cast<Interface *>(table->FindActiveEntry(&key)));
286  }
287  assert(agent()->vhost_interface());
288 
289  // Add vhost labelled inet route
290  InetUnicastAgentRouteTable *inet_mpls_table =
291  static_cast<InetUnicastAgentRouteTable *>
293  inet_mpls_table->AddVhostMplsRoute(agent()->is_l3mh() ?
294  agent()->params()->loopback_ip() :
295  agent()->params()->vhost_addr(),
296  agent()->fabric_rt_export_peer());
297 
298  /* Add Receive route for agent loopback incase of l3mh */
299  if (agent()->is_l3mh()) {
300  InetUnicastAgentRouteTable *rt_table =
302 
304  boost::uuids::nil_uuid(),
305  agent()->params()->vhost_name());
306  rt_table->AddVHostRecvRouteReq(agent()->local_peer(),
307  agent()->fabric_vrf_name(),
308  vmi_key, agent()->params()->loopback_ip(), 32,
309  agent()->fabric_vn_name(), false,
310  true);
311  }
312 
314  if (agent_param()->isVmwareMode()) {
315  PhysicalInterface::Create(agent()->interface_table(),
316  agent_param()->vmware_physical_port(),
317  agent()->fabric_vrf_name(),
320  boost::uuids::nil_uuid(), Ip4Address(0),
321  physical_transport);
322 
323  PhysicalInterfaceKey vmware_pk(agent_param()->vmware_physical_port());
324  const Interface *vmware_intf =
325  static_cast<const Interface *>(table->FindActiveEntry(&vmware_pk));
326  l2_table->AddBridgeReceiveRoute(agent()->local_vm_peer(),
327  agent()->fabric_vrf_name(), 0,
328  vmware_intf->mac(), "");
329  l2_table->AddBridgeReceiveRoute(agent()->local_vm_peer(),
330  agent()->fabric_policy_vrf_name(), 0,
331  vmware_intf->mac(), "");
332  }
333 
334  if (agent()->pkt()) {
335  agent()->pkt()->CreateInterfaces();
336  }
337 
338  if (agent()->vgw()) {
339  agent()->vgw()->CreateInterfaces(vhost_transport);
340  }
341 
343 }
344 
346  //Open up mirror socket
348 
349  if (agent()->services()) {
350  agent()->services()->ConfigInit();
351  }
352 
353  // Diag module needs PktModule
354  if (agent()->pkt()) {
355  diag_table_.reset(new DiagTable(agent()));
356  agent()->set_diag_table(diag_table_.get());
357  }
358 
359  if (create_vhost_) {
360  //Update mac address of vhost interface with
361  //that of ethernet interface
362  agent()->ksync()->UpdateVhostMac();
363  }
364 
365  if (ksync_enable_) {
367  }
368 
369  if (agent()->pkt()) {
370  agent()->pkt()->InitDone();
371  }
372 
373  if (agent()->uve()) {
374  agent()->uve()->InitDone();
375  }
376 
377  if (agent()->ksync()) {
378  agent()->ksync()->InitDone();
379  }
380 
381  if (agent()->oper_db()) {
382  agent()->oper_db()->InitDone();
383  }
384 }
385 
386 /****************************************************************************
387  * Shutdown routines
388  ***************************************************************************/
390  if (agent()->pkt())
391  agent()->pkt()->IoShutdown();
392 
393  if (agent()->services())
394  agent()->services()->IoShutdown();
395 }
396 
398  if (agent()->pkt())
399  agent()->pkt()->FlushFlows();
400 }
401 
403  if (agent()->services())
404  agent()->services()->Shutdown();
405 
406  if (agent()->mac_learning_module()) {
408  }
409 }
410 
412  if (agent()->pkt()) {
413  agent()->pkt()->Shutdown();
414  }
415 }
416 
418  if (agent()->diag_table()) {
419  agent()->diag_table()->Shutdown();
420  }
421 }
virtual void ProcessOptions(const std::string &config_file, const std::string &program_name)
Definition: agent_init.cc:52
void CreateInterfaces()
Definition: pkt_init.cc:83
void set_services(ServicesModule *services)
Definition: agent.cc:977
ServicesModule * services() const
Definition: agent.cc:973
void set_router_id(const Ip4Address &addr)
Definition: agent.h:671
virtual void ModulesShutdown()
BridgeAgentRouteTable * fabric_l2_unicast_table() const
Definition: agent.h:618
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)
void FlushFlows()
Definition: pkt_init.cc:79
const std::string & vhost_name() const
Definition: agent_param.h:183
FlowStatsManager * flow_stats_manager() const
Definition: agent.cc:925
std::unique_ptr< DiagTable > diag_table_
Ip4Address GetIp4SubnetBroadcastAddress(const Ip4Address &ip_prefix, uint16_t plen)
VrfEntry * fabric_vrf() const
Definition: agent.h:915
Definition: vrf.h:268
std::unique_ptr< KSync > ksync_
void set_vhost_interface(const Interface *intrface)
Definition: agent.h:938
InetUnicastAgentRouteTable * fabric_inet4_unicast_table() const
Definition: agent.h:578
static PhysicalInterface::EncapType ComputeEncapType(const string &encap)
void RegisterDBClients()
Definition: vgw.cc:95
void Shutdown()
Definition: diag.cc:127
AgentUveBase * uve() const
Definition: agent.cc:909
string program_name(string filename)
bool is_l3mh() const
Definition: agent.h:725
void InitDone()
Definition: operdb_init.cc:342
void CreateInterfaces(Interface::Transport transport)
Definition: vgw.cc:122
virtual void RegisterDBClients(DB *db)
Definition: ksync_init.cc:104
void ProcessOptions(const std::string &config_file, const std::string &program_name)
std::vector< int > SecurityGroupList
Definition: agent.h:201
void InitXenLinkLocalIntf()
Definition: agent.cc:678
AgentDBEntry * FindActiveEntry(const DBEntry *key)
Definition: agent_db.cc:110
InterfaceTable * interface_table() const
Definition: agent.h:465
std::unique_ptr< AgentUveBase > uve_
MacLearningModule * mac_learning_module() const
Definition: agent.h:1013
void Init(bool run_with_vrouter)
Definition: pkt_init.cc:30
InetUnicastAgentRouteTable * GetInet4MplsUnicastRouteTable() const
Definition: vrf.cc:323
std::unique_ptr< ServicesModule > services_
void set_pkt(PktModule *pkt)
Definition: agent.cc:969
std::unique_ptr< MacLearningModule > mac_learning_module_
const MacAddress & mac() const
Definition: interface.h:131
void UpdateVhostMac()
Definition: ksync_init.cc:452
void set_mac_learning_module(MacLearningModule *mac_learning_module)
Definition: agent.h:1017
DiagTable * diag_table() const
Definition: agent.cc:873
virtual void Init(bool create_vhost)
Definition: ksync_init.cc:119
void Init(uint64_t flow_stats_interval, uint64_t flow_cache_timeout)
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)
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)
virtual void InitDone()
Definition: ksync_init.cc:137
MirrorTable * mirror_table() const
Definition: agent.h:525
OperDB * oper_db() const
Definition: agent.cc:1013
const AddressList & compute_node_address_list() const
Definition: agent_param.h:394
void MirrorSockInit(void)
bool ksync_enable() const
void set_crypt_interface(const Interface *interface)
Definition: agent.h:1144
void Shutdown()
Definition: pkt_init.cc:58
void set_vhost_default_gateway(const AddressList &addr_list)
Definition: agent.h:657
uint8_t type
Definition: load_balance.h:109
void AddVhostMplsRoute(const IpAddress &vhost_addr, const Peer *peer)
void set_vhost_prefix(const Ip4Address &addr)
Definition: agent.h:649
void CreateVhost()
Definition: interface.cc:426
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_)
KSync * ksync() const
Definition: agent.cc:901
void InitDone()
Definition: pkt_init.cc:50
virtual int Start()
Definition: agent_init.cc:93
void set_vhost_prefix_len(uint32_t plen)
Definition: agent.h:654
virtual void RegisterDBClients()
void set_vgw(VirtualGateway *vgw)
Definition: agent.cc:993
void CreateStaticVrf(const string &name)
Definition: vrf.cc:995
std::unique_ptr< VirtualGateway > vgw_
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:14
void set_compute_node_ip(const Ip4Address &addr)
Definition: agent.h:682
AgentParam * agent_param() const
Definition: agent_init.h:28
static const uint32_t kInvalidLabel
Definition: mpls.h:101
VrfTable * vrf_table() const
Definition: agent.h:485
virtual void InitDone()
std::vector< Ip4Address > AddressList
Definition: agent_param.h:117
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)
void Init(bool run_with_vrouter)
void VnswInterfaceListenerInit()
Definition: ksync_init.cc:408
VirtualGateway * vgw() const
Definition: agent.cc:989
void set_diag_table(DiagTable *table)
Definition: agent.cc:877
void ProcessComputeAddress(AgentParam *param)
Agent * agent() const
Definition: agent_init.h:26
void IoShutdown()
Definition: pkt_init.cc:75
PktModule * pkt() const
Definition: agent.cc:965
const std::vector< std::string > & eth_port_list() const
Definition: agent_param.h:205
std::unique_ptr< PktModule > pkt_
void CreateVrf()
Definition: vgw.cc:101
std::vector< int > TagList
Definition: agent.h:202