OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ovsdb_route_peer.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
3  */
6 
7 #include <oper/nexthop.h>
8 #include <oper/tunnel_nh.h>
9 
10 #include <ovsdb_client_idl.h>
11 #include <ovsdb_types.h>
12 
13 OvsPeer::OvsPeer(const IpAddress &peer_ip, uint64_t gen_id,
14  OvsPeerManager *peer_manager) :
15  DynamicPeer(peer_manager->agent(), Peer::OVS_PEER,
16  "OVS-" + peer_ip.to_string(), true),
17  peer_ip_(peer_ip), gen_id_(gen_id), peer_manager_(peer_manager),
18  ha_stale_export_(false) {
19  std::stringstream str;
20  str << "Allocating OVS Peer " << this << " Gen-Id " << gen_id;
21  OVSDB_TRACE(Trace, str.str());
22 }
23 
25  std::stringstream str;
26  str << "Deleting OVS Peer " << this << " Gen-Id " << gen_id_;
27  OVSDB_TRACE(Trace, str.str());
28 }
29 
30 bool OvsPeer::Compare(const Peer *rhs) const {
31  const OvsPeer *rhs_peer = static_cast<const OvsPeer *>(rhs);
32  if (gen_id_ != rhs_peer->gen_id_)
33  return gen_id_ < rhs_peer->gen_id_;
34 
35  return peer_ip_ < rhs_peer->peer_ip_;
36 }
37 
38 bool OvsPeer::AddOvsRoute(const VrfEntry *vrf, uint32_t vxlan_id,
39  const std::string &dest_vn, const MacAddress &mac,
40  Ip4Address &tor_ip) {
41 
42  Agent *agent = peer_manager_->agent();
43 
44  // We dont learn the MAC to IP binding in case of TOR. Populate 0.0.0.0
45  // (unknown ip) for the MAC in EVPN route
46  IpAddress prefix_ip = IpAddress(Ip4Address::from_string("0.0.0.0"));
47 
48  if (vrf == NULL)
49  return false;
50 
51  if (vxlan_id == 0)
52  return false;
53 
54  SecurityGroupList sg_list;
55  BridgeAgentRouteTable *bridge_table =
56  dynamic_cast<BridgeAgentRouteTable *>(vrf->GetBridgeRouteTable());
57  const VmInterface *vmi = bridge_table->FindVmFromDhcpBinding(mac);
58  if (vmi) {
59  vmi->CopySgIdList(&sg_list);
60  }
61  EvpnAgentRouteTable *table = static_cast<EvpnAgentRouteTable *>
62  (vrf->GetEvpnRouteTable());
63  EvpnRouteEntry *route = table->FindRoute(mac, prefix_ip, 32, vxlan_id);
64  uint32_t sequence = 0;
65  if (ha_stale_export_ == false) {
66  // for non-ha-stale route sequence number starts from 1
67  sequence = 1;
68  if (route != NULL) {
69  const AgentPath *path = route->GetActivePath();
70  if (path != NULL) {
71  // if there was already a path existing for this route
72  // bump the sequence number to trigger MAC move
73  sequence = path->sequence() + 1;
74  }
75  }
76  }
77 
78  OvsdbRouteData *data = new OvsdbRouteData(this, vxlan_id,
79  tor_ip, agent->router_id(),
80  agent->fabric_vrf_name(),
81  dest_vn, sg_list,
82  ha_stale_export_, sequence);
83  table->AddRemoteVmRouteReq(this, vrf->GetName(), mac, prefix_ip, 32,
84  vxlan_id, data);
85  return true;
86 }
87 
88 void OvsPeer::DeleteOvsRoute(VrfEntry *vrf, uint32_t vxlan_id,
89  const MacAddress &mac) {
90  if (vrf == NULL)
91  return;
92 
93  if (vxlan_id == 0)
94  return;
95 
96  IpAddress prefix_ip = IpAddress(Ip4Address::from_string("0.0.0.0"));
97  EvpnAgentRouteTable *table = static_cast<EvpnAgentRouteTable *>
98  (vrf->GetEvpnRouteTable());
99  table->DeleteReq(this, vrf->GetName(), mac, prefix_ip, 32, vxlan_id, NULL);
100  return;
101 }
102 
104  uint32_t vxlan_id,
105  const std::string &vn_name,
106  const Ip4Address &tsn_ip,
107  const Ip4Address &tor_ip) {
108  EvpnAgentRouteTable *table = static_cast<EvpnAgentRouteTable *>
109  (vrf->GetEvpnRouteTable());
110  table->AddOvsPeerMulticastRoute(this, vxlan_id, vn_name, tsn_ip, tor_ip,
112 }
113 
115  uint32_t vxlan_id,
116  const Ip4Address &tor_ip) {
117  EvpnAgentRouteTable *table = static_cast<EvpnAgentRouteTable *>
118  (vrf->GetEvpnRouteTable());
119  table->DeleteOvsPeerMulticastRoute(this, vxlan_id, tor_ip);
120 }
121 
123  const AgentPath *path) const {
124  const TunnelNH *nh = dynamic_cast<const TunnelNH *>(path->
125  ComputeNextHop(agent));
126  if (nh == NULL)
127  return agent->router_ip_ptr();
128  return nh->GetDip();
129 }
130 
131 OvsPeerManager::OvsPeerManager(Agent *agent) : gen_id_(0), agent_(agent) {
132 }
133 
135  assert(table_.size() == 0);
136 }
137 
139  OvsPeer *peer = new OvsPeer(peer_ip, gen_id_++, this);
140  table_.insert(peer);
141  return peer;
142 }
143 
145  table_.erase(peer);
146  // Process Delete will internally delete the peer pointer
147  peer->ProcessDelete(peer);
148 }
149 
151  return agent_;
152 }
153 
154 uint32_t OvsPeerManager::Size() const {
155  return table_.size();
156 }
Agent * agent() const
bool ha_stale_export_
EvpnRouteEntry * FindRoute(const MacAddress &mac, const IpAddress &ip_addr, uint32_t plen, uint32_t ethernet_tag)
void DeleteOvsPeerMulticastRoute(const Peer *peer, uint32_t vxlan_id, const Ip4Address &tor_ip)
#define OVSDB_TRACE(obj,...)
void AddOvsPeerMulticastRoute(const Peer *peer, uint32_t vxlan_id, const std::string &vn_name, Ip4Address vtep, Ip4Address tor_ip, bool ha_stale)
Definition: vrf.h:86
AgentRouteTable * GetEvpnRouteTable() const
Definition: vrf.cc:330
bool Compare(const Peer *rhs) const
boost::asio::ip::address IpAddress
Definition: address.h:13
static void DeleteReq(const Peer *peer, const std::string &vrf_name, const MacAddress &mac, const IpAddress &ip_addr, uint32_t plen, uint32_t ethernet_tag, AgentRouteData *data)
OvsPeer * Allocate(const IpAddress &peer_ip)
std::vector< int > SecurityGroupList
Definition: agent.h:201
const Ip4Address * GetDip() const
Definition: tunnel_nh.h:37
OvsPeer(const IpAddress &peer_ip, uint64_t gen_id, OvsPeerManager *manager)
const string & GetName() const
Definition: vrf.h:100
const VmInterface * FindVmFromDhcpBinding(const MacAddress &mac)
const std::string & fabric_vrf_name() const
Definition: agent.h:903
const AgentPath * GetActivePath() const
Definition: agent_route.cc:876
uint64_t gen_id_
Definition: agent.h:358
IpAddress peer_ip_
uint32_t sequence() const
Definition: agent_path.h:328
Ip4Address router_id() const
Definition: agent.h:666
void Free(OvsPeer *peer)
Definition: trace.h:220
OvsPeerTable table_
bool AddOvsRoute(const VrfEntry *vrf, uint32_t vxlan_id, const std::string &dest_vn, const MacAddress &mac, Ip4Address &tor_ip)
AgentRouteTable * GetBridgeRouteTable() const
Definition: vrf.cc:334
Definition: peer.h:44
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:14
OvsPeerManager(Agent *agent)
void AddOvsPeerMulticastRoute(const VrfEntry *vrf, uint32_t vxlan_id, const std::string &vn_name_, const Ip4Address &tsn_ip, const Ip4Address &tor_ip)
OvsPeerManager * peer_manager_
uint32_t Size() const
void DeleteOvsRoute(VrfEntry *vrf, uint32_t vxlan, const MacAddress &mac)
virtual ~OvsPeer()
virtual ~OvsPeerManager()
static void ProcessDelete(DynamicPeer *p)
Definition: peer.cc:63
void CopySgIdList(SecurityGroupList *sg_id_list) const
const Ip4Address * NexthopIp(Agent *agent, const AgentPath *path) const
const Ip4Address * router_ip_ptr() const
Definition: agent.h:668
void DeleteOvsPeerMulticastRoute(const VrfEntry *vrf, uint32_t vxlan_id, const Ip4Address &tor_ip)
static void AddRemoteVmRouteReq(const Peer *peer, const std::string &vrf_name, const MacAddress &mac, const IpAddress &ip_addr, uint32_t plen, uint32_t ethernet_tag, AgentRouteData *data)