OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
inet4_multicast_route.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #include <boost/uuid/uuid_io.hpp>
6 
7 #include <cmn/agent_cmn.h>
8 #include <route/route.h>
9 
10 #include <oper/route_common.h>
11 #include <oper/vrf.h>
12 #include <oper/tunnel_nh.h>
13 #include <oper/mpls.h>
14 #include <oper/vxlan.h>
15 #include <oper/mirror_table.h>
16 #include <oper/multicast.h>
20 #include <oper/agent_sandesh.h>
21 
22 using namespace std;
23 using namespace boost::asio;
24 
25 static void MulticastTableEnqueue(Agent *agent, DBRequest *req) {
27  if (table) {
28  table->Enqueue(req);
29  }
30 }
31 
32 static void MulticastTableProcess(Agent *agent, const string &vrf_name,
33  DBRequest &req) {
34  AgentRouteTable *table =
35  agent->vrf_table()->GetInet4MulticastRouteTable(vrf_name);
36  if (table) {
37  table->Process(req);
38  }
39 }
40 
42  const std::string &name) {
43  AgentRouteTable *table = new Inet4MulticastAgentRouteTable(db, name);
44  table->Init();
45  //table->InitRouteTable(db, table, name, Agent::INET4_MULTICAST);
46  return table;
47 }
48 
49 void
51  const string &vn_name,
52  const Ip4Address &src_addr,
53  const Ip4Address &grp_addr,
55  &component_nh_key_list) {
56  DBRequest nh_req;
57  NextHopKey *nh_key;
58  CompositeNHData *nh_data;
59 
60  nh_key = new CompositeNHKey(Composite::L3COMP, true, component_nh_key_list,
61  vrf_name);
63  nh_req.key.reset(nh_key);
64  nh_data = new CompositeNHData();
65  nh_req.data.reset(nh_data);
66 
67  DBRequest req;
69  Inet4MulticastRouteKey *rt_key = new Inet4MulticastRouteKey(vrf_name,
70  grp_addr,
71  src_addr);
72  MulticastRoute *data = new MulticastRoute(vn_name,
76  nh_req, Composite::L3COMP, 0);
77  req.key.reset(rt_key);
78  req.data.reset(data);
80 }
81 
82 void
84  const string &vrf_name,
85  const Ip4Address &src_addr,
86  const Ip4Address &grp_addr,
87  uint32_t ethernet_tag,
88  AgentRouteData *data) {
89 
90  DBRequest req;
92  Inet4MulticastRouteKey *rt_key = new Inet4MulticastRouteKey(peer, vrf_name,
93  grp_addr, src_addr, ethernet_tag);
94  req.key.reset(rt_key);
95  req.data.reset(data);
97 }
98 
99 void
101  const string &interface_name,
102  const Ip4Address &addr,
103  bool policy)
104 {
105  DBRequest req;
106 
108  Inet4MulticastRouteKey *rt_key = new Inet4MulticastRouteKey(vm_vrf, addr);
109  req.key.reset(rt_key);
111  boost::uuids::nil_uuid(), interface_name);
112  ReceiveRoute *data =
114  TunnelType::AllType(), policy,
115  Agent::GetInstance()->fabric_vn_name());
116  //data->SetMulticast(true);
117  req.data.reset(data);
119 }
120 
121 void
123  const Ip4Address &src_addr,
124  const Ip4Address &grp_addr)
125 {
126  DBRequest req;
127 
129  Inet4MulticastRouteKey *rt_key = new Inet4MulticastRouteKey(vrf_name,
130  grp_addr,
131  src_addr);
132 
133  req.key.reset(rt_key);
134  req.data.reset(NULL);
136 }
137 
138 void
140  const string &vrf_name,
141  const Ip4Address &src_addr,
142  const Ip4Address &grp_addr,
143  uint32_t ethernet_tag,
145 
147  Inet4MulticastRouteKey *rt_key = new Inet4MulticastRouteKey(peer, vrf_name,
148  grp_addr, src_addr, ethernet_tag);
149  req.key.reset(rt_key);
150 
151  DBRequest nh_req;
152  const BgpPeer *bgp_peer = dynamic_cast<const BgpPeer *>(peer);
153  if (bgp_peer) {
154  req.data.reset(new MulticastRoute("", 0, ethernet_tag,
155  TunnelType::AllType(), nh_req, type,
156  bgp_peer->sequence_number()));
157  } else {
158  req.data.reset(new MulticastRoute("", 0, ethernet_tag,
159  TunnelType::AllType(), nh_req, type, 0));
160  }
161 
163 }
164 
165 void Inet4MulticastAgentRouteTable::Delete(const string &vrf_name,
166  const Ip4Address &src_addr,
167  const Ip4Address &grp_addr) {
169  req.key.reset(new Inet4MulticastRouteKey(vrf_name, grp_addr, src_addr));
170  req.data.reset(NULL);
171  MulticastTableProcess(Agent::GetInstance(), vrf_name, req);
172 }
173 
174 AgentRoute *
175 Inet4MulticastRouteKey::AllocRouteEntry(VrfEntry *vrf, bool is_multicast) const
176 {
177  Inet4MulticastRouteEntry * entry = new Inet4MulticastRouteEntry(vrf, dip_,
178  sip_);
179  return static_cast<AgentRoute *>(entry);
180 }
181 
183  return (new Inet4MulticastRouteKey(vrf_name_, dip_, sip_));
184 }
185 
188  const Ip4Address &src_addr) {
189 
190  Inet4MulticastRouteEntry entry(vrf_entry(), grp_addr, src_addr);
191  return static_cast<Inet4MulticastRouteEntry *>(FindActiveEntry(&entry));
192 }
193 
195  ostringstream str;
196  str << "Group:";
197  str << dip_.to_string();
198  str << " Src:";
199  str << sip_.to_string();
200  return str.str();
201 }
202 
204  ostringstream str;
205  str << "Group:";
206  str << dst_addr_.to_string();
207  str << " Src:";
208  str << src_addr_.to_string();
209  return str.str();
210 }
211 
213  const Inet4MulticastRouteEntry &a =
214  static_cast<const Inet4MulticastRouteEntry &>(rhs);
215 
216  if (src_addr_ < a.src_addr_)
217  return -1;
218 
219  if (src_addr_ > a.src_addr_)
220  return 1;
221 
222  if (dst_addr_ < a.dst_addr_)
223  return -1;
224 
225  if (dst_addr_ > a.dst_addr_)
226  return 1;
227 
228  return 0;
229 }
230 
233  new Inet4MulticastRouteKey(vrf()->GetName(), dst_addr_,
234  src_addr_);
235  return DBEntryBase::KeyPtr(key);
236 }
237 
239  const Inet4MulticastRouteKey *k =
240  static_cast<const Inet4MulticastRouteKey *>(key);
241  SetVrf(Agent::GetInstance()->vrf_table()->FindVrfFromName(k->vrf_name()));
242  Ip4Address grp(k->dest_ip_addr());
243  Ip4Address src(k->src_ip_addr());
244  set_dest_ip_addr(grp);
245  set_src_ip_addr(src);
246 }
247 
249  return ReComputeMulticastPaths(path, false);
250 }
251 
253  return ReComputeMulticastPaths(path, true);
254 }
255 
256 bool Inet4MulticastRouteEntry::DBEntrySandesh(Sandesh *sresp, bool stale) const {
257  Inet4McRouteResp *resp = static_cast<Inet4McRouteResp *>(sresp);
258 
259  RouteMcSandeshData data;
260  data.set_src(src_ip_addr().to_string());
261  data.set_grp(dest_ip_addr().to_string());
263  FindGroupObject(vrf()->GetName(), Ip4Address(), dest_ip_addr());
264  Agent *agent = (static_cast<AgentRouteTable *>(get_table()))->agent();
265  const NextHop *anh = GetActiveNextHop();
266  if (!stale || anh || (mc_obj && (mc_obj->peer_identifier() != agent->controller()->
267  multicast_sequence_number()))) {
268  anh->SetNHSandeshData(data.nh);
269  }
270 
271  std::vector<RouteMcSandeshData> &list =
272  const_cast<std::vector<RouteMcSandeshData>&>(resp->get_route_list());
273  list.push_back(data);
274  return true;
275 }
276 
278  const Ip4Address &src_addr,
279  const Ip4Address &dst_addr,
280  bool stale) const {
281 
282  if (src_addr_ == src_addr && dst_addr_ == dst_addr) {
283  return DBEntrySandesh(sresp, stale);
284  }
285 
286  return false;
287 }
288 
289 void Inet4McRouteReq::HandleRequest() const {
290  VrfEntry *vrf =
291  Agent::GetInstance()->vrf_table()->FindVrfFromId(get_vrf_index());
292  if (!vrf) {
293  ErrorResp *resp = new ErrorResp();
294  resp->set_context(context());
295  resp->Response();
296  return;
297  }
298 
299  AgentSandeshPtr sand(new AgentInet4McRtSandesh(vrf, context(), "",
300  get_stale()));
301  boost::system::error_code ec;
302  Ip4Address zero_addr = IpAddress::from_string("0.0.0.0", ec).to_v4();
303  Ip4Address src_ip, grp_ip;
304  if (get_src_ip().empty()) {
305  src_ip = zero_addr;
306  } else {
307  src_ip = Ip4Address::from_string(get_src_ip(), ec);
308  }
309  if (get_grp_ip().empty()) {
310  sand.reset(new AgentInet4McRtSandesh(vrf, context(), "", get_stale()));
311  } else {
312  grp_ip = Ip4Address::from_string(get_grp_ip(), ec);
313  sand.reset(new AgentInet4McRtSandesh(vrf, context(), "", src_ip,
314  grp_ip, get_stale()));
315  }
316  sand->DoSandesh(sand);
317 }
318 
320 (const AgentSandeshArguments *args, const std::string &context) {
321  return AgentSandeshPtr(new AgentInet4McRtSandesh(vrf_entry(), context, "",
322  false));
323 }
virtual bool ReComputePathDeletion(AgentPath *path)
const Ip4Address & dest_ip_addr() const
static Agent * GetInstance()
Definition: agent.h:436
Definition: vrf.h:86
virtual AgentRouteKey * Clone() const
Agent supports multiple route tables - Inet-unicast (IPv4/IPv6), Inet-multicast, bridge, EVPN (Type2/Type5). This base class contains common code for all types of route tables.
Definition: agent_route.h:109
virtual AgentSandeshPtr GetAgentSandesh(const AgentSandeshArguments *args, const std::string &context)
Definition: route.h:14
std::unique_ptr< DBRequestData > data
Definition: db_table.h:49
virtual KeyPtr GetDBRequestKey() const
bool Enqueue(DBRequest *req)
Definition: db_table.cc:194
static void Delete(const string &vrf_name, const Ip4Address &src_addr, const Ip4Address &grp_addr)
std::unique_ptr< DBRequestKey > KeyPtr
Definition: db_entry.h:25
void SetNHSandeshData(NhSandeshData &data) const
Definition: nexthop.cc:3172
Base class for all Route entries in agent.
Definition: agent_route.h:224
std::vector< ComponentNHKeyPtr > ComponentNHKeyList
Definition: nexthop.h:1641
Inet4MulticastRouteEntry * FindRoute(const Ip4Address &grp_addr, const Ip4Address &src_addr)
void AddVHostRecvRoute(const string &vm_vrf, const string &interface_name, const Ip4Address &addr, bool policy)
Definition: db.h:24
void Init()
Definition: db_table.cc:387
static void MulticastTableProcess(Agent *agent, const string &vrf_name, DBRequest &req)
virtual string ToString() const
VrfEntry * FindVrfFromId(size_t index)
Definition: vrf.cc:884
static const uint32_t kInvalidvxlan_id
Definition: vxlan.h:141
uint8_t type
Definition: load_balance.h:109
Definition: agent.h:358
virtual bool ReComputePathAdd(AgentPath *path)
VNController * controller() const
Definition: agent.cc:981
std::unique_ptr< DBRequestKey > key
Definition: db_table.h:48
DBOperation oper
Definition: db_table.h:42
static TypeBmap AllType()
Definition: nexthop.h:321
uint64_t sequence_number() const
Definition: peer.h:94
static void DeleteMulticastRoute(const string &vrf_name, const Ip4Address &src_addr, const Ip4Address &grp_addr)
virtual bool DBEntrySandesh(Sandesh *sresp, bool stale) const
class boost::shared_ptr< AgentSandesh > AgentSandeshPtr
Definition: agent_db.h:18
Definition: peer.h:44
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:14
virtual string ToString() const
static const uint32_t kInvalidLabel
Definition: mpls.h:101
VrfTable * vrf_table() const
Definition: agent.h:485
virtual void SetKey(const DBRequestKey *key)
static void MulticastTableEnqueue(Agent *agent, DBRequest *req)
const Ip4Address & src_ip_addr() const
uint64_t peer_identifier()
Definition: multicast.h:144
AgentRouteTable * GetInet4MulticastRouteTable(const std::string &vrf_name)
Definition: vrf.cc:909
#define COMPOSITETYPE
Definition: nexthop.h:1600
const std::string & vrf_name() const
Definition: agent_route.h:46
virtual int CompareTo(const Route &rhs) const
static DBTableBase * CreateTable(DB *db, const std::string &name)
void Process(DBRequest &req)
Definition: agent_route.cc:186
static void AddMulticastRoute(const string &vn_name, const string &vrf_name, const Ip4Address &src_addr, const Ip4Address &grp_addr, ComponentNHKeyList &component_nh_key_list)
static MulticastHandler * GetInstance()
Definition: multicast.h:369
Inet4MulticastAgentRouteTable * fabric_inet4_multicast_table() const
Definition: agent.h:600
virtual AgentRoute * AllocRouteEntry(VrfEntry *vrf, bool is_multicast) const