OpenSDN source code
ovsdb_route_data.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 <cmn/agent_cmn.h>
7 
8 #include <oper/route_common.h>
9 #include <oper/vrf.h>
10 #include <oper/tunnel_nh.h>
11 #include <oper/agent_sandesh.h>
12 
15 
16 using namespace std;
17 using namespace boost::asio;
18 
19 OvsdbRouteData::OvsdbRouteData(const Peer *peer, uint32_t vxlan_id,
20  const Ip4Address &tor_ip,
21  const Ip4Address &router_id,
22  const std::string &tor_vrf,
23  const std::string &dest_vn_name,
24  const SecurityGroupList &sg_list,
25  bool ha_stale_export, uint32_t sequence) :
26  AgentRouteData(AgentRouteData::ADD_DEL_CHANGE, false, 0),
27  peer_(peer), vxlan_id_(vxlan_id), tor_ip_(tor_ip),
28  tor_vrf_(tor_vrf), router_id_(router_id), dest_vn_name_(dest_vn_name),
29  sg_list_(sg_list), ha_stale_export_(ha_stale_export), sequence_(sequence) {
30 }
31 
33  AgentRouteData(AgentRouteData::ADD_DEL_CHANGE, false, 0),
34  peer_(peer), vxlan_id_() {
35 }
36 
38 }
39 
40 std::string OvsdbRouteData::ToString() const {
41  return "OVS Route Data";
42 }
43 
45  const AgentRoute *data) {
46  bool ret = false;
47  NextHop *nh = NULL;
48 
49  if (path->vxlan_id() != vxlan_id_) {
50  path->set_vxlan_id(vxlan_id_);
51  ret = true;
52  }
53 
54  if (!path->dest_vn_match(dest_vn_name_)) {
55  VnListType vn_list;
56  vn_list.insert(dest_vn_name_);
57  path->set_dest_vn_list(vn_list);
58  ret = true;
59  }
60 
61  if (path->sg_list() != sg_list_) {
62  path->set_sg_list(sg_list_);
63  ret = true;
64  }
65 
66  uint32_t pref = PathPreference::LOW;
67  // if it is a ha stale export check for path preference to be HA_STALE
68  if (ha_stale_export_) {
70  }
71  PathPreference path_preference(sequence_, pref, false, false);
72  if (path->path_preference() != path_preference) {
73  path->set_path_preference(path_preference);
74  ret = true;
75  }
76 
77  // Create Tunnel-NH first
80  nh_req.key.reset(new TunnelNHKey(tor_vrf_, router_id_, tor_ip_, false,
81  type));
82  nh_req.data.reset(new TunnelNHData());
83  agent->nexthop_table()->Process(nh_req);
84 
85  // Get the NH
87  nh = static_cast<NextHop *>(agent->nexthop_table()->FindActiveEntry(&key));
88 
91 
92  path->set_unresolved(false);
93  if (path->ChangeNH(agent, nh) == true)
94  ret = true;
95 
96  return ret;
97 }
98 
100  AgentRouteData(AgentRouteData::ADD_DEL_CHANGE, false, 0),
101  sg_list_(sg_list) {
102 }
103 
105 }
106 
107 std::string OvsdbRouteResyncData::ToString() const {
108  return "OVS Route Resync";
109 }
110 
112  const AgentRoute *data) {
113  bool ret = false;
114  if (path->sg_list() != sg_list_) {
115  path->set_sg_list(sg_list_);
116  ret = true;
117  }
118 
119  return ret;
120 }
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:15
std::vector< int > SecurityGroupList
Definition: agent.h:202
std::set< std::string > VnListType
Definition: agent.h:213
AgentDBEntry * FindActiveEntry(const DBEntry *key)
Definition: agent_db.cc:111
void set_path_preference(const PathPreference &rp)
Definition: agent_path.h:332
void set_tunnel_bmap(TunnelType::TypeBmap bmap)
Definition: agent_path.h:290
void set_dest_vn_list(const VnListType &dest_vn_list)
Definition: agent_path.h:284
void set_sg_list(const SecurityGroupList &sg)
Definition: agent_path.h:292
void set_vxlan_id(uint32_t vxlan_id)
Definition: agent_path.h:282
const PathPreference & path_preference() const
Definition: agent_path.h:330
const SecurityGroupList & sg_list() const
Definition: agent_path.h:249
uint32_t tunnel_bmap() const
Definition: agent_path.h:268
uint32_t vxlan_id() const
Definition: agent_path.h:266
void set_unresolved(bool unresolved)
Definition: agent_path.h:286
bool dest_vn_match(const std::string &vn) const
Definition: agent_path.cc:1810
bool ChangeNH(Agent *agent, NextHop *nh)
Definition: agent_path.cc:120
void set_tunnel_type(TunnelType::Type type)
Definition: agent_path.h:291
Base class for all Route entries in agent.
Definition: agent_route.h:225
Definition: agent.h:361
NextHopTable * nexthop_table() const
Definition: agent.h:478
void Process(DBRequest &req)
Definition: nexthop.cc:368
virtual std::string ToString() const
Ip4Address router_id_
virtual ~OvsdbRouteData()
std::string tor_vrf_
std::string dest_vn_name_
OvsdbRouteData(const Peer *peer, uint32_t vxlan_id, const Ip4Address &tor_ip, const Ip4Address &router_id, const std::string &tor_vrf, const std::string &dest_vn_name, const SecurityGroupList &sg_list, bool ha_stale_export, uint32_t sequence)
Ip4Address tor_ip_
virtual bool AddChangePathExtended(Agent *agent, AgentPath *path, const AgentRoute *data)
SecurityGroupList sg_list_
SecurityGroupList sg_list_
virtual bool AddChangePathExtended(Agent *agent, AgentPath *path, const AgentRoute *data)
OvsdbRouteResyncData(const SecurityGroupList &sg_list)
virtual std::string ToString() const
Definition: peer.h:45
static TypeBmap VxlanType()
Definition: nexthop.h:312
static Type ComputeType(TypeBmap bmap)
Definition: nexthop.cc:34
uint8_t type
Definition: load_balance.h:2
@ DB_ENTRY_ADD_CHANGE
Definition: db_table.h:39
std::unique_ptr< DBRequestKey > key
Definition: db_table.h:49
std::unique_ptr< DBRequestData > data
Definition: db_table.h:50