-
Notifications
You must be signed in to change notification settings - Fork 390
/
inet4_multicast_route.cc
235 lines (201 loc) · 8.09 KB
/
inet4_multicast_route.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#include <boost/uuid/uuid_io.hpp>
#include <cmn/agent_cmn.h>
#include <route/route.h>
#include <oper/route_common.h>
#include <oper/vrf.h>
#include <oper/tunnel_nh.h>
#include <oper/mpls.h>
#include <oper/vxlan.h>
#include <oper/mirror_table.h>
#include <oper/multicast.h>
#include <controller/controller_export.h>
#include <controller/controller_peer.h>
#include <controller/controller_init.h>
#include <oper/agent_sandesh.h>
using namespace std;
using namespace boost::asio;
static void MulticastTableEnqueue(Agent *agent, DBRequest *req) {
AgentRouteTable *table = agent->fabric_inet4_multicast_table();
if (table) {
table->Enqueue(req);
}
}
static void MulticastTableProcess(Agent *agent, const string &vrf_name,
DBRequest &req) {
AgentRouteTable *table =
agent->vrf_table()->GetInet4MulticastRouteTable(vrf_name);
if (table) {
table->Process(req);
}
}
DBTableBase *Inet4MulticastAgentRouteTable::CreateTable(DB *db,
const std::string &name) {
AgentRouteTable *table = new Inet4MulticastAgentRouteTable(db, name);
table->Init();
//table->InitRouteTable(db, table, name, Agent::INET4_MULTICAST);
return table;
}
void
Inet4MulticastAgentRouteTable::AddMulticastRoute(const string &vrf_name,
const string &vn_name,
const Ip4Address &src_addr,
const Ip4Address &grp_addr,
ComponentNHKeyList
&component_nh_key_list) {
DBRequest nh_req;
NextHopKey *nh_key;
CompositeNHData *nh_data;
nh_key = new CompositeNHKey(Composite::L3COMP, true, component_nh_key_list,
vrf_name);
nh_req.oper = DBRequest::DB_ENTRY_ADD_CHANGE;
nh_req.key.reset(nh_key);
nh_data = new CompositeNHData();
nh_req.data.reset(nh_data);
DBRequest req;
req.oper = DBRequest::DB_ENTRY_ADD_CHANGE;
Inet4MulticastRouteKey *rt_key = new Inet4MulticastRouteKey(vrf_name,
grp_addr,
src_addr);
MulticastRoute *data = new MulticastRoute(vn_name,
MplsTable::kInvalidLabel,
VxLanTable::kInvalidvxlan_id,
TunnelType::AllType(),
nh_req, Composite::L3COMP);
req.key.reset(rt_key);
req.data.reset(data);
MulticastTableEnqueue(Agent::GetInstance(), &req);
}
void
Inet4MulticastAgentRouteTable::AddVHostRecvRoute(const string &vm_vrf,
const string &interface_name,
const Ip4Address &addr,
bool policy)
{
DBRequest req;
req.oper = DBRequest::DB_ENTRY_ADD_CHANGE;
Inet4MulticastRouteKey *rt_key = new Inet4MulticastRouteKey(vm_vrf, addr);
req.key.reset(rt_key);
InetInterfaceKey intf_key(Agent::GetInstance()->
vhost_interface_name());
ReceiveRoute *data =
new ReceiveRoute(intf_key, MplsTable::kInvalidLabel,
TunnelType::AllType(), policy,
Agent::GetInstance()->fabric_vn_name());
//data->SetMulticast(true);
req.data.reset(data);
MulticastTableEnqueue(Agent::GetInstance(), &req);
}
void
Inet4MulticastAgentRouteTable::DeleteMulticastRoute(const string &vrf_name,
const Ip4Address &src_addr,
const Ip4Address &grp_addr)
{
DBRequest req;
req.oper = DBRequest::DB_ENTRY_DELETE;
Inet4MulticastRouteKey *rt_key = new Inet4MulticastRouteKey(vrf_name,
grp_addr,
src_addr);
req.key.reset(rt_key);
req.data.reset(NULL);
MulticastTableEnqueue(Agent::GetInstance(), &req);
}
void Inet4MulticastAgentRouteTable::Delete(const string &vrf_name,
const Ip4Address &src_addr,
const Ip4Address &grp_addr) {
DBRequest req(DBRequest::DB_ENTRY_DELETE);
req.key.reset(new Inet4MulticastRouteKey(vrf_name, grp_addr, src_addr));
req.data.reset(NULL);
MulticastTableProcess(Agent::GetInstance(), vrf_name, req);
}
AgentRoute *
Inet4MulticastRouteKey::AllocRouteEntry(VrfEntry *vrf, bool is_multicast) const
{
Inet4MulticastRouteEntry * entry = new Inet4MulticastRouteEntry(vrf, dip_,
sip_);
return static_cast<AgentRoute *>(entry);
}
AgentRouteKey *Inet4MulticastRouteKey::Clone() const {
return (new Inet4MulticastRouteKey(vrf_name_, dip_, sip_));
}
string Inet4MulticastRouteKey::ToString() const {
ostringstream str;
str << "Group:";
str << dip_.to_string();
str << " Src:";
str << sip_.to_string();
return str.str();
}
string Inet4MulticastRouteEntry::ToString() const {
ostringstream str;
str << "Group:";
str << dst_addr_.to_string();
str << " Src:";
str << src_addr_.to_string();
return str.str();
}
int Inet4MulticastRouteEntry::CompareTo(const Route &rhs) const {
const Inet4MulticastRouteEntry &a =
static_cast<const Inet4MulticastRouteEntry &>(rhs);
if (src_addr_ < a.src_addr_)
return -1;
if (src_addr_ > a.src_addr_)
return 1;
if (dst_addr_ < a.dst_addr_)
return -1;
if (dst_addr_ > a.dst_addr_)
return 1;
return 0;
}
DBEntryBase::KeyPtr Inet4MulticastRouteEntry::GetDBRequestKey() const {
Inet4MulticastRouteKey *key =
new Inet4MulticastRouteKey(vrf()->GetName(), dst_addr_,
src_addr_);
return DBEntryBase::KeyPtr(key);
}
void Inet4MulticastRouteEntry::SetKey(const DBRequestKey *key) {
const Inet4MulticastRouteKey *k =
static_cast<const Inet4MulticastRouteKey *>(key);
SetVrf(Agent::GetInstance()->vrf_table()->FindVrfFromName(k->vrf_name()));
Ip4Address grp(k->dest_ip_addr());
Ip4Address src(k->src_ip_addr());
set_dest_ip_addr(grp);
set_src_ip_addr(src);
}
bool Inet4MulticastRouteEntry::DBEntrySandesh(Sandesh *sresp, bool stale) const {
Inet4McRouteResp *resp = static_cast<Inet4McRouteResp *>(sresp);
RouteMcSandeshData data;
data.set_src(src_ip_addr().to_string());
data.set_grp(dest_ip_addr().to_string());
MulticastGroupObject *mc_obj = MulticastHandler::GetInstance()->
FindGroupObject(vrf()->GetName(), dest_ip_addr());
Agent *agent = (static_cast<AgentRouteTable *>(get_table()))->agent();
if (!stale || (mc_obj->peer_identifier() != agent->controller()->
multicast_sequence_number())) {
GetActiveNextHop()->SetNHSandeshData(data.nh);
}
std::vector<RouteMcSandeshData> &list =
const_cast<std::vector<RouteMcSandeshData>&>(resp->get_route_list());
list.push_back(data);
return true;
}
void Inet4McRouteReq::HandleRequest() const {
VrfEntry *vrf =
Agent::GetInstance()->vrf_table()->FindVrfFromId(get_vrf_index());
if (!vrf) {
ErrorResp *resp = new ErrorResp();
resp->set_context(context());
resp->Response();
return;
}
AgentSandeshPtr sand(new AgentInet4McRtSandesh(vrf, context(), "",
get_stale()));
sand->DoSandesh(sand);
}
AgentSandeshPtr Inet4MulticastAgentRouteTable::GetAgentSandesh
(const AgentSandeshArguments *args, const std::string &context) {
return AgentSandeshPtr(new AgentInet4McRtSandesh(vrf_entry(), context, "",
false));
}