12
12
#include " routeorch.h"
13
13
#include " crmorch.h"
14
14
#include " bufferorch.h"
15
+ #include " directory.h"
16
+ #include " vnetorch.h"
15
17
16
18
extern sai_object_id_t gVirtualRouterId ;
19
+ extern Directory<Orch*> gDirectory ;
17
20
18
21
extern sai_router_interface_api_t * sai_router_intfs_api;
19
22
extern sai_route_api_t * sai_route_api;
@@ -27,8 +30,8 @@ extern BufferOrch *gBufferOrch;
27
30
28
31
const int intfsorch_pri = 35 ;
29
32
30
- IntfsOrch::IntfsOrch (DBConnector *db, string tableName) :
31
- Orch(db, tableName, intfsorch_pri)
33
+ IntfsOrch::IntfsOrch (DBConnector *db, string tableName, VRFOrch *vrf_orch ) :
34
+ Orch(db, tableName, intfsorch_pri), m_vrfOrch(vrf_orch)
32
35
{
33
36
SWSS_LOG_ENTER ();
34
37
}
@@ -113,20 +116,65 @@ void IntfsOrch::doTask(Consumer &consumer)
113
116
114
117
vector<string> keys = tokenize (kfvKey (t), ' :' );
115
118
string alias (keys[0 ]);
116
- IpPrefix ip_prefix (kfvKey (t).substr (kfvKey (t).find (' :' )+1 ));
119
+ IpPrefix ip_prefix;
120
+ bool ip_prefix_in_key = false ;
121
+
122
+ if (keys.size () > 1 )
123
+ {
124
+ ip_prefix = kfvKey (t).substr (kfvKey (t).find (' :' )+1 );
125
+ ip_prefix_in_key = true ;
126
+ }
127
+
128
+ const vector<FieldValueTuple>& data = kfvFieldsValues (t);
129
+ string vrf_name = " " , vnet_name = " " ;
130
+
131
+ for (auto idx : data)
132
+ {
133
+ const auto &field = fvField (idx);
134
+ const auto &value = fvValue (idx);
135
+ if (field == " vrf_name" )
136
+ {
137
+ vrf_name = value;
138
+ }
139
+ else if (field == " vnet_name" )
140
+ {
141
+ vnet_name = value;
142
+ }
143
+ }
117
144
118
145
if (alias == " eth0" || alias == " docker0" )
119
146
{
120
147
it = consumer.m_toSync .erase (it);
121
148
continue ;
122
149
}
123
150
151
+ sai_object_id_t vrf_id = gVirtualRouterId ;
152
+ if (!vnet_name.empty ())
153
+ {
154
+ VNetOrch* vnet_orch = gDirectory .get <VNetOrch*>();
155
+ if (!vnet_orch->isVnetExists (vnet_name))
156
+ {
157
+ it++;
158
+ continue ;
159
+ }
160
+ vrf_id = vnet_orch->getVRid (vnet_name);
161
+ }
162
+ else if (!vrf_name.empty ())
163
+ {
164
+ if (m_vrfOrch->isVRFexists (vrf_name))
165
+ {
166
+ it++;
167
+ continue ;
168
+ }
169
+ vrf_id = m_vrfOrch->getVRFid (vrf_name);
170
+ }
171
+
124
172
string op = kfvOp (t);
125
173
if (op == SET_COMMAND)
126
174
{
127
175
if (alias == " lo" )
128
176
{
129
- addIp2MeRoute (ip_prefix);
177
+ addIp2MeRoute (vrf_id, ip_prefix);
130
178
it = consumer.m_toSync .erase (it);
131
179
continue ;
132
180
}
@@ -149,7 +197,7 @@ void IntfsOrch::doTask(Consumer &consumer)
149
197
auto it_intfs = m_syncdIntfses.find (alias);
150
198
if (it_intfs == m_syncdIntfses.end ())
151
199
{
152
- if (addRouterIntfs (port))
200
+ if (addRouterIntfs (vrf_id, port))
153
201
{
154
202
IntfsEntry intfs_entry;
155
203
intfs_entry.ref_count = 0 ;
@@ -162,9 +210,10 @@ void IntfsOrch::doTask(Consumer &consumer)
162
210
}
163
211
}
164
212
165
- if (m_syncdIntfses[alias].ip_addresses .count (ip_prefix))
213
+ vrf_id = port.m_vr_id ;
214
+ if (!ip_prefix_in_key || m_syncdIntfses[alias].ip_addresses .count (ip_prefix))
166
215
{
167
- /* Duplicate entry */
216
+ /* Request to create router interface, no prefix present or Duplicate entry */
168
217
it = consumer.m_toSync .erase (it);
169
218
continue ;
170
219
}
@@ -198,7 +247,7 @@ void IntfsOrch::doTask(Consumer &consumer)
198
247
}
199
248
200
249
addSubnetRoute (port, ip_prefix);
201
- addIp2MeRoute (ip_prefix);
250
+ addIp2MeRoute (vrf_id, ip_prefix);
202
251
203
252
if (port.m_type == Port::VLAN && ip_prefix.isV4 ())
204
253
{
@@ -212,7 +261,7 @@ void IntfsOrch::doTask(Consumer &consumer)
212
261
{
213
262
if (alias == " lo" )
214
263
{
215
- removeIp2MeRoute (ip_prefix);
264
+ removeIp2MeRoute (vrf_id, ip_prefix);
216
265
it = consumer.m_toSync .erase (it);
217
266
continue ;
218
267
}
@@ -225,12 +274,13 @@ void IntfsOrch::doTask(Consumer &consumer)
225
274
continue ;
226
275
}
227
276
277
+ vrf_id = port.m_vr_id ;
228
278
if (m_syncdIntfses.find (alias) != m_syncdIntfses.end ())
229
279
{
230
280
if (m_syncdIntfses[alias].ip_addresses .count (ip_prefix))
231
281
{
232
282
removeSubnetRoute (port, ip_prefix);
233
- removeIp2MeRoute (ip_prefix);
283
+ removeIp2MeRoute (vrf_id, ip_prefix);
234
284
if (port.m_type == Port::VLAN && ip_prefix.isV4 ())
235
285
{
236
286
removeDirectedBroadcast (port, ip_prefix.getBroadcastIp ());
@@ -262,7 +312,7 @@ void IntfsOrch::doTask(Consumer &consumer)
262
312
}
263
313
}
264
314
265
- bool IntfsOrch::addRouterIntfs (Port &port)
315
+ bool IntfsOrch::addRouterIntfs (sai_object_id_t vrf_id, Port &port)
266
316
{
267
317
SWSS_LOG_ENTER ();
268
318
@@ -279,7 +329,7 @@ bool IntfsOrch::addRouterIntfs(Port &port)
279
329
vector<sai_attribute_t > attrs;
280
330
281
331
attr.id = SAI_ROUTER_INTERFACE_ATTR_VIRTUAL_ROUTER_ID;
282
- attr.value .oid = gVirtualRouterId ;
332
+ attr.value .oid = vrf_id ;
283
333
attrs.push_back (attr);
284
334
285
335
attr.id = SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS;
@@ -334,6 +384,8 @@ bool IntfsOrch::addRouterIntfs(Port &port)
334
384
throw runtime_error (" Failed to create router interface." );
335
385
}
336
386
387
+ port.m_vr_id = vrf_id;
388
+
337
389
gPortsOrch ->setPort (port.m_alias , port);
338
390
339
391
SWSS_LOG_NOTICE (" Create router interface %s MTU %u" , port.m_alias .c_str (), port.m_mtu );
@@ -359,6 +411,7 @@ bool IntfsOrch::removeRouterIntfs(Port &port)
359
411
}
360
412
361
413
port.m_rif_id = 0 ;
414
+ port.m_vr_id = 0 ;
362
415
gPortsOrch ->setPort (port.m_alias , port);
363
416
364
417
SWSS_LOG_NOTICE (" Remove router interface for port %s" , port.m_alias .c_str ());
@@ -370,7 +423,7 @@ void IntfsOrch::addSubnetRoute(const Port &port, const IpPrefix &ip_prefix)
370
423
{
371
424
sai_route_entry_t unicast_route_entry;
372
425
unicast_route_entry.switch_id = gSwitchId ;
373
- unicast_route_entry.vr_id = gVirtualRouterId ;
426
+ unicast_route_entry.vr_id = port. m_vr_id ;
374
427
copy (unicast_route_entry.destination , ip_prefix);
375
428
subnet (unicast_route_entry.destination , unicast_route_entry.destination );
376
429
@@ -413,7 +466,7 @@ void IntfsOrch::removeSubnetRoute(const Port &port, const IpPrefix &ip_prefix)
413
466
{
414
467
sai_route_entry_t unicast_route_entry;
415
468
unicast_route_entry.switch_id = gSwitchId ;
416
- unicast_route_entry.vr_id = gVirtualRouterId ;
469
+ unicast_route_entry.vr_id = port. m_vr_id ;
417
470
copy (unicast_route_entry.destination , ip_prefix);
418
471
subnet (unicast_route_entry.destination , unicast_route_entry.destination );
419
472
@@ -441,11 +494,11 @@ void IntfsOrch::removeSubnetRoute(const Port &port, const IpPrefix &ip_prefix)
441
494
gRouteOrch ->notifyNextHopChangeObservers (ip_prefix, IpAddresses (), false );
442
495
}
443
496
444
- void IntfsOrch::addIp2MeRoute (const IpPrefix &ip_prefix)
497
+ void IntfsOrch::addIp2MeRoute (sai_object_id_t vrf_id, const IpPrefix &ip_prefix)
445
498
{
446
499
sai_route_entry_t unicast_route_entry;
447
500
unicast_route_entry.switch_id = gSwitchId ;
448
- unicast_route_entry.vr_id = gVirtualRouterId ;
501
+ unicast_route_entry.vr_id = vrf_id ;
449
502
copy (unicast_route_entry.destination , ip_prefix.getIp ());
450
503
451
504
sai_attribute_t attr;
@@ -481,11 +534,11 @@ void IntfsOrch::addIp2MeRoute(const IpPrefix &ip_prefix)
481
534
}
482
535
}
483
536
484
- void IntfsOrch::removeIp2MeRoute (const IpPrefix &ip_prefix)
537
+ void IntfsOrch::removeIp2MeRoute (sai_object_id_t vrf_id, const IpPrefix &ip_prefix)
485
538
{
486
539
sai_route_entry_t unicast_route_entry;
487
540
unicast_route_entry.switch_id = gSwitchId ;
488
- unicast_route_entry.vr_id = gVirtualRouterId ;
541
+ unicast_route_entry.vr_id = vrf_id ;
489
542
copy (unicast_route_entry.destination , ip_prefix.getIp ());
490
543
491
544
sai_status_t status = sai_route_api->remove_route_entry (&unicast_route_entry);
0 commit comments