@@ -57,18 +57,11 @@ static const vector<sai_router_interface_stat_t> rifStatIds =
57
57
SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_OCTETS,
58
58
};
59
59
60
- // Translation of loopback action from string to sai type
61
- const unordered_map<string, loopback_action_e> IntfsOrch::m_loopback_action_map =
62
- {
63
- {" drop" , LOOPBACK_ACTION_DROP},
64
- {" forward" , LOOPBACK_ACTION_FORWARD},
65
- };
66
-
67
60
// Translation of loopback action from sonic to sai type
68
- const unordered_map<loopback_action_e , sai_packet_action_t > IntfsOrch::m_sai_loopback_action_map =
61
+ const unordered_map<string , sai_packet_action_t > IntfsOrch::m_sai_loopback_action_map =
69
62
{
70
- {LOOPBACK_ACTION_DROP , SAI_PACKET_ACTION_DROP},
71
- {LOOPBACK_ACTION_FORWARD , SAI_PACKET_ACTION_FORWARD},
63
+ {" drop " , SAI_PACKET_ACTION_DROP},
64
+ {" forward " , SAI_PACKET_ACTION_FORWARD},
72
65
};
73
66
74
67
IntfsOrch::IntfsOrch (DBConnector *db, string tableName, VRFOrch *vrf_orch, DBConnector *chassisAppDb) :
@@ -430,19 +423,24 @@ bool IntfsOrch::setIntfProxyArp(const string &alias, const string &proxy_arp)
430
423
return true ;
431
424
}
432
425
433
- bool IntfsOrch::setIntfLoopbackAction (const Port &port)
426
+ bool IntfsOrch::setIntfLoopbackAction (const Port &port, string actionStr )
434
427
{
435
428
sai_attribute_t attr;
436
- attr.id = SAI_ROUTER_INTERFACE_ATTR_LOOPBACK_PACKET_ACTION;
437
- attr.value .s32 = m_sai_loopback_action_map.at (port.m_loopback_action );
429
+ sai_packet_action_t action;
430
+
431
+ if (!getSaiLoopbackAction (actionStr, action))
432
+ {
433
+ return false ;
434
+ }
438
435
439
- string action_str = getIntfLoopbackActionStr (port.m_loopback_action );
436
+ attr.id = SAI_ROUTER_INTERFACE_ATTR_LOOPBACK_PACKET_ACTION;
437
+ attr.value .s32 = action;
440
438
441
439
sai_status_t status = sai_router_intfs_api->set_router_interface_attribute (port.m_rif_id , &attr);
442
440
if (status != SAI_STATUS_SUCCESS)
443
441
{
444
442
SWSS_LOG_ERROR (" Loopback action [%s] set failed, interface [%s], rc [%d]" ,
445
- action_str .c_str (), port.m_alias .c_str (), status);
443
+ actionStr .c_str (), port.m_alias .c_str (), status);
446
444
447
445
task_process_status handle_status = handleSaiSetStatus (SAI_API_ROUTER_INTERFACE, status);
448
446
if (handle_status != task_success)
@@ -452,40 +450,10 @@ bool IntfsOrch::setIntfLoopbackAction(const Port &port)
452
450
}
453
451
454
452
SWSS_LOG_NOTICE (" Loopback action [%s] set success, interface [%s]" ,
455
- action_str .c_str (), port.m_alias .c_str ());
453
+ actionStr .c_str (), port.m_alias .c_str ());
456
454
return true ;
457
455
}
458
456
459
- bool IntfsOrch::getIntfLoopbackAction (const std::string &actionStr, loopback_action_e &action)
460
- {
461
- auto it = m_loopback_action_map.find (actionStr);
462
- if (it != m_loopback_action_map.end ())
463
- {
464
- action = m_loopback_action_map.at (actionStr);
465
- return true ;
466
- }
467
- else
468
- {
469
- SWSS_LOG_WARN (" Unsupported loopback action [%s]" , actionStr.c_str ());
470
- return false ;
471
- }
472
- }
473
-
474
- string IntfsOrch::getIntfLoopbackActionStr (loopback_action_e action)
475
- {
476
- for (auto it = m_loopback_action_map.begin (); it != m_loopback_action_map.end (); ++it)
477
- {
478
- if (it->second == action)
479
- {
480
- return it->first ;
481
- }
482
- }
483
-
484
- SWSS_LOG_WARN (" Failed to fetch action as string for action [%u]" , action);
485
- return string ();
486
- }
487
-
488
-
489
457
set<IpPrefix> IntfsOrch:: getSubnetRoutes()
490
458
{
491
459
SWSS_LOG_ENTER ();
@@ -504,19 +472,18 @@ set<IpPrefix> IntfsOrch:: getSubnetRoutes()
504
472
}
505
473
506
474
bool IntfsOrch::setIntf (const string& alias, sai_object_id_t vrf_id, const IpPrefix *ip_prefix,
507
- const bool adminUp, const uint32_t mtu, loopback_action_e loopbackAction)
475
+ const bool adminUp, const uint32_t mtu, string loopbackAction)
508
476
509
477
{
510
478
SWSS_LOG_ENTER ();
511
479
512
480
Port port;
513
481
gPortsOrch ->getPort (alias, port);
514
- port.m_loopback_action = loopbackAction;
515
482
516
483
auto it_intfs = m_syncdIntfses.find (alias);
517
484
if (it_intfs == m_syncdIntfses.end ())
518
485
{
519
- if (!ip_prefix && addRouterIntfs (vrf_id, port))
486
+ if (!ip_prefix && addRouterIntfs (vrf_id, port, loopbackAction ))
520
487
{
521
488
gPortsOrch ->increasePortRefCount (alias);
522
489
IntfsEntry intfs_entry;
@@ -738,7 +705,7 @@ void IntfsOrch::doTask(Consumer &consumer)
738
705
string inband_type = " " ;
739
706
bool mpls = false ;
740
707
string vlan = " " ;
741
- loopback_action_e loopbackAction = LOOPBACK_ACTION_NONE ;
708
+ string loopbackAction = " " ;
742
709
743
710
for (auto idx : data)
744
711
{
@@ -833,10 +800,7 @@ void IntfsOrch::doTask(Consumer &consumer)
833
800
}
834
801
else if (field == " loopback_action" )
835
802
{
836
- if (!getIntfLoopbackAction (value, loopbackAction))
837
- {
838
- continue ;
839
- }
803
+ loopbackAction = value;
840
804
}
841
805
}
842
806
@@ -990,11 +954,11 @@ void IntfsOrch::doTask(Consumer &consumer)
990
954
}
991
955
992
956
/* Set loopback action */
993
- if ((loopbackAction != LOOPBACK_ACTION_NONE) and (port.m_loopback_action != loopbackAction))
957
+ if ((!loopbackAction. empty ()) && (port.m_loopback_action != loopbackAction))
994
958
{
995
- port.m_loopback_action = loopbackAction;
996
- if (setIntfLoopbackAction (port))
959
+ if (setIntfLoopbackAction (port, loopbackAction))
997
960
{
961
+ port.m_loopback_action = loopbackAction;
998
962
gPortsOrch ->setPort (alias, port);
999
963
}
1000
964
}
@@ -1139,7 +1103,22 @@ void IntfsOrch::doTask(Consumer &consumer)
1139
1103
}
1140
1104
}
1141
1105
1142
- bool IntfsOrch::addRouterIntfs (sai_object_id_t vrf_id, Port &port)
1106
+ bool IntfsOrch::getSaiLoopbackAction (const string &actionStr, sai_packet_action_t &action)
1107
+ {
1108
+ auto it = m_sai_loopback_action_map.find (actionStr);
1109
+ if (it != m_sai_loopback_action_map.end ())
1110
+ {
1111
+ action = m_sai_loopback_action_map.at (actionStr);
1112
+ return true ;
1113
+ }
1114
+ else
1115
+ {
1116
+ SWSS_LOG_WARN (" Unsupported loopback action [%s]" , actionStr.c_str ());
1117
+ return false ;
1118
+ }
1119
+ }
1120
+
1121
+ bool IntfsOrch::addRouterIntfs (sai_object_id_t vrf_id, Port &port, string loopbackActionStr)
1143
1122
{
1144
1123
SWSS_LOG_ENTER ();
1145
1124
@@ -1159,11 +1138,15 @@ bool IntfsOrch::addRouterIntfs(sai_object_id_t vrf_id, Port &port)
1159
1138
attr.value .oid = vrf_id;
1160
1139
attrs.push_back (attr);
1161
1140
1162
- if (port. m_loopback_action != LOOPBACK_ACTION_NONE )
1141
+ if (!loopbackActionStr. empty () )
1163
1142
{
1164
- attr.id = SAI_ROUTER_INTERFACE_ATTR_LOOPBACK_PACKET_ACTION;
1165
- attr.value .s32 = m_sai_loopback_action_map.at (port.m_loopback_action );
1166
- attrs.push_back (attr);
1143
+ sai_packet_action_t loopbackAction;
1144
+ if (getSaiLoopbackAction (loopbackActionStr, loopbackAction))
1145
+ {
1146
+ attr.id = SAI_ROUTER_INTERFACE_ATTR_LOOPBACK_PACKET_ACTION;
1147
+ attr.value .s32 = loopbackAction;
1148
+ attrs.push_back (attr);
1149
+ }
1167
1150
}
1168
1151
1169
1152
attr.id = SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS;
@@ -1276,6 +1259,7 @@ bool IntfsOrch::addRouterIntfs(sai_object_id_t vrf_id, Port &port)
1276
1259
}
1277
1260
1278
1261
port.m_vr_id = vrf_id;
1262
+ port.m_loopback_action = loopbackActionStr;
1279
1263
1280
1264
gPortsOrch ->setPort (port.m_alias , port);
1281
1265
m_rifsToAdd.push_back (port);
0 commit comments