-
Notifications
You must be signed in to change notification settings - Fork 539
/
intfsorch.cpp
1495 lines (1303 loc) · 45.7 KB
/
intfsorch.cpp
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <cassert>
#include <fstream>
#include <sstream>
#include <map>
#include <net/if.h>
#include <inttypes.h>
#include "sai_serialize.h"
#include "intfsorch.h"
#include "ipprefix.h"
#include "logger.h"
#include "swssnet.h"
#include "tokenize.h"
#include "routeorch.h"
#include "crmorch.h"
#include "bufferorch.h"
#include "directory.h"
#include "vnetorch.h"
#include "subscriberstatetable.h"
extern sai_object_id_t gVirtualRouterId;
extern Directory<Orch*> gDirectory;
extern sai_router_interface_api_t* sai_router_intfs_api;
extern sai_route_api_t* sai_route_api;
extern sai_neighbor_api_t* sai_neighbor_api;
extern sai_switch_api_t* sai_switch_api;
extern sai_vlan_api_t* sai_vlan_api;
extern sai_object_id_t gSwitchId;
extern PortsOrch *gPortsOrch;
extern RouteOrch *gRouteOrch;
extern CrmOrch *gCrmOrch;
extern BufferOrch *gBufferOrch;
extern bool gIsNatSupported;
extern NeighOrch *gNeighOrch;
extern string gMySwitchType;
extern int32_t gVoqMySwitchId;
const int intfsorch_pri = 35;
#define RIF_FLEX_STAT_COUNTER_POLL_MSECS "1000"
#define UPDATE_MAPS_SEC 1
static const vector<sai_router_interface_stat_t> rifStatIds =
{
SAI_ROUTER_INTERFACE_STAT_IN_PACKETS,
SAI_ROUTER_INTERFACE_STAT_IN_OCTETS,
SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS,
SAI_ROUTER_INTERFACE_STAT_IN_ERROR_OCTETS,
SAI_ROUTER_INTERFACE_STAT_OUT_PACKETS,
SAI_ROUTER_INTERFACE_STAT_OUT_OCTETS,
SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS,
SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_OCTETS,
};
IntfsOrch::IntfsOrch(DBConnector *db, string tableName, VRFOrch *vrf_orch, DBConnector *chassisAppDb) :
Orch(db, tableName, intfsorch_pri), m_vrfOrch(vrf_orch)
{
SWSS_LOG_ENTER();
/* Initialize DB connectors */
m_counter_db = shared_ptr<DBConnector>(new DBConnector("COUNTERS_DB", 0));
m_flex_db = shared_ptr<DBConnector>(new DBConnector("FLEX_COUNTER_DB", 0));
m_asic_db = shared_ptr<DBConnector>(new DBConnector("ASIC_DB", 0));
/* Initialize COUNTER_DB tables */
m_rifNameTable = unique_ptr<Table>(new Table(m_counter_db.get(), COUNTERS_RIF_NAME_MAP));
m_rifTypeTable = unique_ptr<Table>(new Table(m_counter_db.get(), COUNTERS_RIF_TYPE_MAP));
m_vidToRidTable = unique_ptr<Table>(new Table(m_asic_db.get(), "VIDTORID"));
auto intervT = timespec { .tv_sec = UPDATE_MAPS_SEC , .tv_nsec = 0 };
m_updateMapsTimer = new SelectableTimer(intervT);
auto executorT = new ExecutableTimer(m_updateMapsTimer, this, "UPDATE_MAPS_TIMER");
Orch::addExecutor(executorT);
/* Initialize FLEX_COUNTER_DB tables */
m_flexCounterTable = unique_ptr<ProducerTable>(new ProducerTable(m_flex_db.get(), FLEX_COUNTER_TABLE));
m_flexCounterGroupTable = unique_ptr<ProducerTable>(new ProducerTable(m_flex_db.get(), FLEX_COUNTER_GROUP_TABLE));
vector<FieldValueTuple> fieldValues;
fieldValues.emplace_back(POLL_INTERVAL_FIELD, RIF_FLEX_STAT_COUNTER_POLL_MSECS);
fieldValues.emplace_back(STATS_MODE_FIELD, STATS_MODE_READ);
m_flexCounterGroupTable->set(RIF_STAT_COUNTER_FLEX_COUNTER_GROUP, fieldValues);
string rifRatePluginName = "rif_rates.lua";
try
{
string rifRateLuaScript = swss::loadLuaScript(rifRatePluginName);
string rifRateSha = swss::loadRedisScript(m_counter_db.get(), rifRateLuaScript);
vector<FieldValueTuple> fieldValues;
fieldValues.emplace_back(RIF_PLUGIN_FIELD, rifRateSha);
fieldValues.emplace_back(POLL_INTERVAL_FIELD, RIF_FLEX_STAT_COUNTER_POLL_MSECS);
fieldValues.emplace_back(STATS_MODE_FIELD, STATS_MODE_READ);
m_flexCounterGroupTable->set(RIF_STAT_COUNTER_FLEX_COUNTER_GROUP, fieldValues);
}
catch (const runtime_error &e)
{
SWSS_LOG_WARN("RIF flex counter group plugins was not set successfully: %s", e.what());
}
if(gMySwitchType == "voq")
{
//Add subscriber to process VOQ system interface
tableName = CHASSIS_APP_SYSTEM_INTERFACE_TABLE_NAME;
Orch::addExecutor(new Consumer(new SubscriberStateTable(chassisAppDb, tableName, TableConsumable::DEFAULT_POP_BATCH_SIZE, 0), this, tableName));
m_tableVoqSystemInterfaceTable = unique_ptr<Table>(new Table(chassisAppDb, CHASSIS_APP_SYSTEM_INTERFACE_TABLE_NAME));
}
}
sai_object_id_t IntfsOrch::getRouterIntfsId(const string &alias)
{
Port port;
gPortsOrch->getPort(alias, port);
return port.m_rif_id;
}
bool IntfsOrch::isPrefixSubnet(const IpPrefix &ip_prefix, const string &alias)
{
if (m_syncdIntfses.find(alias) == m_syncdIntfses.end())
{
return false;
}
for (auto &prefixIt: m_syncdIntfses[alias].ip_addresses)
{
if (prefixIt.getSubnet() == ip_prefix)
{
return true;
}
}
return false;
}
string IntfsOrch::getRouterIntfsAlias(const IpAddress &ip, const string &vrf_name)
{
sai_object_id_t vrf_id = gVirtualRouterId;
if (!vrf_name.empty())
{
vrf_id = m_vrfOrch->getVRFid(vrf_name);
}
for (const auto &it_intfs: m_syncdIntfses)
{
if (it_intfs.second.vrf_id != vrf_id)
{
continue;
}
for (const auto &prefixIt: it_intfs.second.ip_addresses)
{
if (prefixIt.isAddressInSubnet(ip))
{
return it_intfs.first;
}
}
}
return string();
}
void IntfsOrch::increaseRouterIntfsRefCount(const string &alias)
{
SWSS_LOG_ENTER();
m_syncdIntfses[alias].ref_count++;
SWSS_LOG_DEBUG("Router interface %s ref count is increased to %d",
alias.c_str(), m_syncdIntfses[alias].ref_count);
}
void IntfsOrch::decreaseRouterIntfsRefCount(const string &alias)
{
SWSS_LOG_ENTER();
m_syncdIntfses[alias].ref_count--;
SWSS_LOG_DEBUG("Router interface %s ref count is decreased to %d",
alias.c_str(), m_syncdIntfses[alias].ref_count);
}
bool IntfsOrch::setRouterIntfsMtu(const Port &port)
{
SWSS_LOG_ENTER();
sai_attribute_t attr;
attr.id = SAI_ROUTER_INTERFACE_ATTR_MTU;
attr.value.u32 = port.m_mtu;
sai_status_t status = sai_router_intfs_api->
set_router_interface_attribute(port.m_rif_id, &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to set router interface %s MTU to %u, rv:%d",
port.m_alias.c_str(), port.m_mtu, status);
task_process_status handle_status = handleSaiSetStatus(SAI_API_ROUTER_INTERFACE, status);
if (handle_status != task_success)
{
return parseHandleSaiStatusFailure(handle_status);
}
}
SWSS_LOG_NOTICE("Set router interface %s MTU to %u",
port.m_alias.c_str(), port.m_mtu);
return true;
}
bool IntfsOrch::setRouterIntfsMac(const Port &port)
{
SWSS_LOG_ENTER();
sai_attribute_t attr;
attr.id = SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS;
memcpy(attr.value.mac, port.m_mac.getMac(), sizeof(sai_mac_t));
sai_status_t status = sai_router_intfs_api->
set_router_interface_attribute(port.m_rif_id, &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to set router interface %s MAC to %s, rv:%d",
port.m_alias.c_str(), port.m_mac.to_string().c_str(), status);
task_process_status handle_status = handleSaiSetStatus(SAI_API_ROUTER_INTERFACE, status);
if (handle_status != task_success)
{
return parseHandleSaiStatusFailure(handle_status);
}
}
SWSS_LOG_NOTICE("Set router interface %s MAC to %s",
port.m_alias.c_str(), port.m_mac.to_string().c_str());
return true;
}
bool IntfsOrch::setRouterIntfsNatZoneId(Port &port)
{
SWSS_LOG_ENTER();
/* Return true if the router interface is not exists */
if (!port.m_rif_id)
{
SWSS_LOG_WARN("Router interface is not exists on %s",
port.m_alias.c_str());
return true;
}
sai_attribute_t attr;
attr.id = SAI_ROUTER_INTERFACE_ATTR_NAT_ZONE_ID;
attr.value.u32 = port.m_nat_zone_id;
sai_status_t status = sai_router_intfs_api->
set_router_interface_attribute(port.m_rif_id, &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to set router interface %s NAT Zone Id to %u, rv:%d",
port.m_alias.c_str(), port.m_nat_zone_id, status);
task_process_status handle_status = handleSaiSetStatus(SAI_API_ROUTER_INTERFACE, status);
if (handle_status != task_success)
{
return parseHandleSaiStatusFailure(handle_status);
}
}
SWSS_LOG_NOTICE("Set router interface %s NAT Zone Id to %u",
port.m_alias.c_str(), port.m_nat_zone_id);
return true;
}
bool IntfsOrch::setRouterIntfsAdminStatus(const Port &port)
{
SWSS_LOG_ENTER();
sai_attribute_t attr;
attr.value.booldata = port.m_admin_state_up;
attr.id = SAI_ROUTER_INTERFACE_ATTR_ADMIN_V4_STATE;
sai_status_t status = sai_router_intfs_api->
set_router_interface_attribute(port.m_rif_id, &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to set router interface %s V4 admin status to %s, rv:%d",
port.m_alias.c_str(), port.m_admin_state_up == true ? "up" : "down", status);
task_process_status handle_status = handleSaiSetStatus(SAI_API_ROUTER_INTERFACE, status);
if (handle_status != task_success)
{
return parseHandleSaiStatusFailure(handle_status);
}
}
attr.id = SAI_ROUTER_INTERFACE_ATTR_ADMIN_V6_STATE;
status = sai_router_intfs_api->
set_router_interface_attribute(port.m_rif_id, &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to set router interface %s V6 admin status to %s, rv:%d",
port.m_alias.c_str(), port.m_admin_state_up == true ? "up" : "down", status);
task_process_status handle_status = handleSaiSetStatus(SAI_API_ROUTER_INTERFACE, status);
if (handle_status != task_success)
{
return parseHandleSaiStatusFailure(handle_status);
}
}
return true;
}
bool IntfsOrch::setIntfVlanFloodType(const Port &port, sai_vlan_flood_control_type_t vlan_flood_type)
{
SWSS_LOG_ENTER();
if (port.m_type != Port::VLAN)
{
SWSS_LOG_ERROR("VLAN flood type cannot be set for non VLAN interface \"%s\"", port.m_alias.c_str());
return false;
}
sai_attribute_t attr;
attr.id = SAI_VLAN_ATTR_BROADCAST_FLOOD_CONTROL_TYPE;
attr.value.s32 = vlan_flood_type;
sai_status_t status = sai_vlan_api->set_vlan_attribute(port.m_vlan_info.vlan_oid, &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to set flood type for VLAN %u, rv:%d", port.m_vlan_info.vlan_id, status);
task_process_status handle_status = handleSaiSetStatus(SAI_API_VLAN, status);
if (handle_status != task_success)
{
return parseHandleSaiStatusFailure(handle_status);
}
}
return true;
}
bool IntfsOrch::setIntfProxyArp(const string &alias, const string &proxy_arp)
{
SWSS_LOG_ENTER();
if (m_syncdIntfses.find(alias) == m_syncdIntfses.end())
{
SWSS_LOG_ERROR("Interface \"%s\" doesn't exist", alias.c_str());
return false;
}
if (m_syncdIntfses[alias].proxy_arp == (proxy_arp == "enabled" ? true : false))
{
SWSS_LOG_INFO("Proxy ARP is already set to \"%s\" on interface \"%s\"", proxy_arp.c_str(), alias.c_str());
return true;
}
Port port;
if (!gPortsOrch->getPort(alias, port))
{
SWSS_LOG_ERROR("Failed to get port info for the interface \"%s\"", alias.c_str());
return false;
}
if (port.m_type == Port::VLAN)
{
sai_vlan_flood_control_type_t vlan_flood_type;
if (proxy_arp == "enabled")
{
vlan_flood_type = SAI_VLAN_FLOOD_CONTROL_TYPE_NONE;
}
else
{
vlan_flood_type = SAI_VLAN_FLOOD_CONTROL_TYPE_ALL;
}
if (!setIntfVlanFloodType(port, vlan_flood_type))
{
return false;
}
}
m_syncdIntfses[alias].proxy_arp = (proxy_arp == "enabled") ? true : false;
return true;
}
set<IpPrefix> IntfsOrch:: getSubnetRoutes()
{
SWSS_LOG_ENTER();
set<IpPrefix> subnet_routes;
for (auto it = m_syncdIntfses.begin(); it != m_syncdIntfses.end(); it++)
{
for (auto prefix : it->second.ip_addresses)
{
subnet_routes.emplace(prefix);
}
}
return subnet_routes;
}
bool IntfsOrch::setIntf(const string& alias, sai_object_id_t vrf_id, const IpPrefix *ip_prefix, const bool adminUp, const uint32_t mtu)
{
SWSS_LOG_ENTER();
Port port;
gPortsOrch->getPort(alias, port);
auto it_intfs = m_syncdIntfses.find(alias);
if (it_intfs == m_syncdIntfses.end())
{
if (!ip_prefix && addRouterIntfs(vrf_id, port))
{
gPortsOrch->increasePortRefCount(alias);
IntfsEntry intfs_entry;
intfs_entry.ref_count = 0;
intfs_entry.proxy_arp = false;
intfs_entry.vrf_id = vrf_id;
m_syncdIntfses[alias] = intfs_entry;
m_vrfOrch->increaseVrfRefCount(vrf_id);
}
else
{
return false;
}
}
else
{
if (!ip_prefix && port.m_type == Port::SUBPORT)
{
// port represents a sub interface
// Change sub interface config at run time
bool attrChanged = false;
if (mtu && port.m_mtu != mtu)
{
port.m_mtu = mtu;
attrChanged = true;
setRouterIntfsMtu(port);
}
if (port.m_admin_state_up != adminUp)
{
port.m_admin_state_up = adminUp;
attrChanged = true;
setRouterIntfsAdminStatus(port);
}
if (attrChanged)
{
gPortsOrch->setPort(alias, port);
}
}
}
if (!ip_prefix || m_syncdIntfses[alias].ip_addresses.count(*ip_prefix))
{
/* Request to create router interface, no prefix present or Duplicate entry */
return true;
}
/* NOTE: Overlap checking is required to handle ifconfig weird behavior.
* When set IP address using ifconfig command it applies it in two stages.
* On stage one it sets IP address with netmask /8. On stage two it
* changes netmask to specified in command. As DB is async event to
* add IP address with original netmask may come before event to
* delete IP with netmask /8. To handle this we in case of overlap
* we should wait until entry with /8 netmask will be removed.
* Time frame between those event is quite small.*/
/* NOTE: Overlap checking in this interface is not enough.
* So extend to check in all interfaces of this VRF */
bool overlaps = false;
for (const auto &intfsIt: m_syncdIntfses)
{
if (port.m_vr_id != intfsIt.second.vrf_id)
{
continue;
}
for (const auto &prefixIt: intfsIt.second.ip_addresses)
{
if (prefixIt.isAddressInSubnet(ip_prefix->getIp()) ||
ip_prefix->isAddressInSubnet(prefixIt.getIp()))
{
overlaps = true;
SWSS_LOG_NOTICE("Router interface %s IP %s overlaps with %s.", port.m_alias.c_str(),
prefixIt.to_string().c_str(), ip_prefix->to_string().c_str());
break;
}
}
if (overlaps)
{
/* Overlap of IP address network */
return false;
}
}
addIp2MeRoute(port.m_vr_id, *ip_prefix);
if(gMySwitchType == "voq")
{
if(gPortsOrch->isInbandPort(alias))
{
//Need to sync the inband intf neighbor for other asics
gNeighOrch->addInbandNeighbor(alias, ip_prefix->getIp());
}
}
if (port.m_type == Port::VLAN)
{
addDirectedBroadcast(port, *ip_prefix);
}
m_syncdIntfses[alias].ip_addresses.insert(*ip_prefix);
return true;
}
bool IntfsOrch::removeIntf(const string& alias, sai_object_id_t vrf_id, const IpPrefix *ip_prefix)
{
SWSS_LOG_ENTER();
Port port;
if (!gPortsOrch->getPort(alias, port))
{
return false;
}
if (ip_prefix && m_syncdIntfses[alias].ip_addresses.count(*ip_prefix))
{
removeIp2MeRoute(port.m_vr_id, *ip_prefix);
if(gMySwitchType == "voq")
{
if(gPortsOrch->isInbandPort(alias))
{
gNeighOrch->delInbandNeighbor(alias, ip_prefix->getIp());
}
}
if(port.m_type == Port::VLAN)
{
removeDirectedBroadcast(port, *ip_prefix);
}
m_syncdIntfses[alias].ip_addresses.erase(*ip_prefix);
}
if (!ip_prefix)
{
if (m_syncdIntfses[alias].ip_addresses.size() == 0 && removeRouterIntfs(port))
{
gPortsOrch->decreasePortRefCount(alias);
m_syncdIntfses.erase(alias);
m_vrfOrch->decreaseVrfRefCount(vrf_id);
if (port.m_type == Port::SUBPORT)
{
if (!gPortsOrch->removeSubPort(alias))
{
return false;
}
}
return true;
}
else
{
return false;
}
}
return true;
}
void IntfsOrch::doTask(Consumer &consumer)
{
SWSS_LOG_ENTER();
if (!gPortsOrch->allPortsReady())
{
return;
}
string table_name = consumer.getTableName();
auto it = consumer.m_toSync.begin();
while (it != consumer.m_toSync.end())
{
KeyOpFieldsValuesTuple t = it->second;
vector<string> keys = tokenize(kfvKey(t), ':');
string alias(keys[0]);
bool isSubIntf = false;
size_t found = alias.find(VLAN_SUB_INTERFACE_SEPARATOR);
if (found != string::npos)
{
isSubIntf = true;
}
IpPrefix ip_prefix;
bool ip_prefix_in_key = false;
bool is_lo = !alias.compare(0, strlen(LOOPBACK_PREFIX), LOOPBACK_PREFIX);
if (keys.size() > 1)
{
ip_prefix = kfvKey(t).substr(kfvKey(t).find(':')+1);
ip_prefix_in_key = true;
}
if(table_name == CHASSIS_APP_SYSTEM_INTERFACE_TABLE_NAME)
{
if(!isRemoteSystemPortIntf(alias))
{
//Synced local interface. Skip
it = consumer.m_toSync.erase(it);
continue;
}
}
const vector<FieldValueTuple>& data = kfvFieldsValues(t);
string vrf_name = "", vnet_name = "", nat_zone = "";
MacAddress mac;
uint32_t mtu = 0;
bool adminUp = false;
uint32_t nat_zone_id = 0;
string proxy_arp = "";
string inband_type = "";
for (auto idx : data)
{
const auto &field = fvField(idx);
const auto &value = fvValue(idx);
if (field == "vrf_name")
{
vrf_name = value;
}
else if (field == "vnet_name")
{
vnet_name = value;
}
else if (field == "mac_addr")
{
try
{
mac = MacAddress(value);
}
catch (const std::invalid_argument &e)
{
SWSS_LOG_ERROR("Invalid mac argument %s to %s()", value.c_str(), e.what());
continue;
}
}
else if (field == "nat_zone")
{
try
{
nat_zone_id = (uint32_t)stoul(value);
}
catch (...)
{
SWSS_LOG_ERROR("Invalid argument %s for nat zone", value.c_str());
continue;
}
nat_zone = value;
}
else if (field == "mtu")
{
try
{
mtu = static_cast<uint32_t>(stoul(value));
}
catch (const std::invalid_argument &e)
{
SWSS_LOG_ERROR("Invalid argument %s to %s()", value.c_str(), e.what());
continue;
}
catch (const std::out_of_range &e)
{
SWSS_LOG_ERROR("Out of range argument %s to %s()", value.c_str(), e.what());
continue;
}
}
else if (field == "admin_status")
{
if (value == "up")
{
adminUp = true;
}
else
{
adminUp = false;
if (value != "down")
{
SWSS_LOG_WARN("Sub interface %s unknown admin status %s", alias.c_str(), value.c_str());
}
}
}
else if (field == "nat_zone")
{
nat_zone = value;
}
else if (field == "proxy_arp")
{
proxy_arp = value;
}
else if (field == "inband_type")
{
inband_type = value;
}
}
if (alias == "eth0" || alias == "docker0")
{
it = consumer.m_toSync.erase(it);
continue;
}
sai_object_id_t vrf_id = gVirtualRouterId;
if (!vrf_name.empty())
{
if (!m_vrfOrch->isVRFexists(vrf_name))
{
it++;
continue;
}
vrf_id = m_vrfOrch->getVRFid(vrf_name);
}
string op = kfvOp(t);
if (op == SET_COMMAND)
{
if (is_lo)
{
if (!ip_prefix_in_key)
{
if (m_syncdIntfses.find(alias) == m_syncdIntfses.end())
{
IntfsEntry intfs_entry;
intfs_entry.ref_count = 0;
intfs_entry.proxy_arp = false;
intfs_entry.vrf_id = vrf_id;
m_syncdIntfses[alias] = intfs_entry;
m_vrfOrch->increaseVrfRefCount(vrf_id);
}
}
else
{
if (m_syncdIntfses.find(alias) == m_syncdIntfses.end())
{
it++;
continue;
}
if (m_syncdIntfses[alias].ip_addresses.count(ip_prefix) == 0)
{
m_syncdIntfses[alias].ip_addresses.insert(ip_prefix);
addIp2MeRoute(m_syncdIntfses[alias].vrf_id, ip_prefix);
}
}
it = consumer.m_toSync.erase(it);
continue;
}
//Voq Inband interface config processing
if(inband_type.size() && !ip_prefix_in_key)
{
if(!gPortsOrch->setVoqInbandIntf(alias, inband_type))
{
it++;
continue;
}
}
Port port;
if (!gPortsOrch->getPort(alias, port))
{
if (!ip_prefix_in_key && isSubIntf)
{
if (!gPortsOrch->addSubPort(port, alias, adminUp, mtu))
{
it++;
continue;
}
}
else
{
/* TODO: Resolve the dependency relationship and add ref_count to port */
it++;
continue;
}
}
if (m_vnetInfses.find(alias) != m_vnetInfses.end())
{
vnet_name = m_vnetInfses.at(alias);
}
if (!vnet_name.empty())
{
VNetOrch* vnet_orch = gDirectory.get<VNetOrch*>();
if (!vnet_orch->isVnetExists(vnet_name))
{
it++;
continue;
}
if (!vnet_orch->setIntf(alias, vnet_name, ip_prefix_in_key ? &ip_prefix : nullptr, adminUp, mtu))
{
it++;
continue;
}
if (m_vnetInfses.find(alias) == m_vnetInfses.end())
{
m_vnetInfses.emplace(alias, vnet_name);
}
}
else
{
if (!setIntf(alias, vrf_id, ip_prefix_in_key ? &ip_prefix : nullptr, adminUp, mtu))
{
it++;
continue;
}
if (gPortsOrch->getPort(alias, port))
{
/* Set nat zone id */
if ((!nat_zone.empty()) and (port.m_nat_zone_id != nat_zone_id))
{
port.m_nat_zone_id = nat_zone_id;
if (gIsNatSupported)
{
setRouterIntfsNatZoneId(port);
}
else
{
SWSS_LOG_NOTICE("Not set router interface %s NAT Zone Id to %u, as NAT is not supported",
port.m_alias.c_str(), port.m_nat_zone_id);
}
gPortsOrch->setPort(alias, port);
}
}
}
if (mac)
{
/* Get mac information and update mac of the interface*/
sai_attribute_t attr;
attr.id = SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS;
memcpy(attr.value.mac, mac.getMac(), sizeof(sai_mac_t));
/*port.m_rif_id is set in setIntf(), need get port again*/
if (gPortsOrch->getPort(alias, port))
{
sai_status_t status = sai_router_intfs_api->set_router_interface_attribute(port.m_rif_id, &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to set router interface mac %s for port %s, rv:%d",
mac.to_string().c_str(), port.m_alias.c_str(), status);
if (handleSaiSetStatus(SAI_API_ROUTER_INTERFACE, status) == task_need_retry)
{
it++;
continue;
}
}
else
{
SWSS_LOG_NOTICE("Set router interface mac %s for port %s success",
mac.to_string().c_str(), port.m_alias.c_str());
}
}
else
{
SWSS_LOG_ERROR("Failed to set router interface mac %s for port %s, getPort fail",
mac.to_string().c_str(), alias.c_str());
}
}
if (!proxy_arp.empty())
{
setIntfProxyArp(alias, proxy_arp);
}
it = consumer.m_toSync.erase(it);
}
else if (op == DEL_COMMAND)
{
if (is_lo)
{
if (!ip_prefix_in_key)
{
if (m_syncdIntfses.find(alias) != m_syncdIntfses.end())
{
if (m_syncdIntfses[alias].ip_addresses.size() == 0)
{
m_vrfOrch->decreaseVrfRefCount(m_syncdIntfses[alias].vrf_id);
m_syncdIntfses.erase(alias);
}
else
{
it++;
continue;
}
}
}
else
{
if (m_syncdIntfses.find(alias) != m_syncdIntfses.end())
{
if (m_syncdIntfses[alias].ip_addresses.count(ip_prefix))
{
m_syncdIntfses[alias].ip_addresses.erase(ip_prefix);
removeIp2MeRoute(m_syncdIntfses[alias].vrf_id, ip_prefix);
}
}
}
it = consumer.m_toSync.erase(it);
continue;
}
Port port;
/* Cannot locate interface */
if (!gPortsOrch->getPort(alias, port))
{
it = consumer.m_toSync.erase(it);
continue;
}
if (m_syncdIntfses.find(alias) == m_syncdIntfses.end())
{
/* Cannot locate the interface */
it = consumer.m_toSync.erase(it);
continue;
}
if (m_vnetInfses.find(alias) != m_vnetInfses.end())
{
vnet_name = m_vnetInfses.at(alias);
}
if (m_syncdIntfses[alias].proxy_arp)
{
setIntfProxyArp(alias, "disabled");
}
if (!vnet_name.empty())
{
VNetOrch* vnet_orch = gDirectory.get<VNetOrch*>();
if (!vnet_orch->isVnetExists(vnet_name))
{
it++;
continue;
}
if (vnet_orch->delIntf(alias, vnet_name, ip_prefix_in_key ? &ip_prefix : nullptr))
{
m_vnetInfses.erase(alias);
it = consumer.m_toSync.erase(it);
}
else
{
it++;
continue;
}
}
else
{
if (removeIntf(alias, port.m_vr_id, ip_prefix_in_key ? &ip_prefix : nullptr))
{
it = consumer.m_toSync.erase(it);
}
else
{
it++;
continue;
}
}
}
}
}
bool IntfsOrch::addRouterIntfs(sai_object_id_t vrf_id, Port &port)
{
SWSS_LOG_ENTER();
/* Return true if the router interface exists */
if (port.m_rif_id)
{
SWSS_LOG_WARN("Router interface already exists on %s",
port.m_alias.c_str());
return true;
}
/* Create router interface if the router interface doesn't exist */
sai_attribute_t attr;
vector<sai_attribute_t> attrs;
attr.id = SAI_ROUTER_INTERFACE_ATTR_VIRTUAL_ROUTER_ID;
attr.value.oid = vrf_id;
attrs.push_back(attr);
attr.id = SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS;
if (port.m_mac)
{