Skip to content

Commit abe328d

Browse files
committed
Fix review comments
1 parent ac63f6f commit abe328d

File tree

4 files changed

+84
-90
lines changed

4 files changed

+84
-90
lines changed

orchagent/intfsorch.cpp

Lines changed: 46 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,11 @@ static const vector<sai_router_interface_stat_t> rifStatIds =
5757
SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_OCTETS,
5858
};
5959

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-
6760
// 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 =
6962
{
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},
7265
};
7366

7467
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)
430423
return true;
431424
}
432425

433-
bool IntfsOrch::setIntfLoopbackAction(const Port &port)
426+
bool IntfsOrch::setIntfLoopbackAction(const Port &port, string actionStr)
434427
{
435428
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+
}
438435

439-
string action_str = getIntfLoopbackActionStr(port.m_loopback_action);
436+
attr.id = SAI_ROUTER_INTERFACE_ATTR_LOOPBACK_PACKET_ACTION;
437+
attr.value.s32 = action;
440438

441439
sai_status_t status = sai_router_intfs_api->set_router_interface_attribute(port.m_rif_id, &attr);
442440
if (status != SAI_STATUS_SUCCESS)
443441
{
444442
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);
446444

447445
task_process_status handle_status = handleSaiSetStatus(SAI_API_ROUTER_INTERFACE, status);
448446
if (handle_status != task_success)
@@ -452,40 +450,10 @@ bool IntfsOrch::setIntfLoopbackAction(const Port &port)
452450
}
453451

454452
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());
456454
return true;
457455
}
458456

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-
489457
set<IpPrefix> IntfsOrch:: getSubnetRoutes()
490458
{
491459
SWSS_LOG_ENTER();
@@ -504,19 +472,18 @@ set<IpPrefix> IntfsOrch:: getSubnetRoutes()
504472
}
505473

506474
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)
508476

509477
{
510478
SWSS_LOG_ENTER();
511479

512480
Port port;
513481
gPortsOrch->getPort(alias, port);
514-
port.m_loopback_action = loopbackAction;
515482

516483
auto it_intfs = m_syncdIntfses.find(alias);
517484
if (it_intfs == m_syncdIntfses.end())
518485
{
519-
if (!ip_prefix && addRouterIntfs(vrf_id, port))
486+
if (!ip_prefix && addRouterIntfs(vrf_id, port, loopbackAction))
520487
{
521488
gPortsOrch->increasePortRefCount(alias);
522489
IntfsEntry intfs_entry;
@@ -738,7 +705,7 @@ void IntfsOrch::doTask(Consumer &consumer)
738705
string inband_type = "";
739706
bool mpls = false;
740707
string vlan = "";
741-
loopback_action_e loopbackAction = LOOPBACK_ACTION_NONE;
708+
string loopbackAction = "";
742709

743710
for (auto idx : data)
744711
{
@@ -833,10 +800,7 @@ void IntfsOrch::doTask(Consumer &consumer)
833800
}
834801
else if (field == "loopback_action")
835802
{
836-
if(!getIntfLoopbackAction(value, loopbackAction))
837-
{
838-
continue;
839-
}
803+
loopbackAction = value;
840804
}
841805
}
842806

@@ -990,11 +954,11 @@ void IntfsOrch::doTask(Consumer &consumer)
990954
}
991955

992956
/* Set loopback action */
993-
if ((loopbackAction != LOOPBACK_ACTION_NONE) and (port.m_loopback_action != loopbackAction))
957+
if ((!loopbackAction.empty()) && (port.m_loopback_action != loopbackAction))
994958
{
995-
port.m_loopback_action = loopbackAction;
996-
if(setIntfLoopbackAction(port))
959+
if (setIntfLoopbackAction(port, loopbackAction))
997960
{
961+
port.m_loopback_action = loopbackAction;
998962
gPortsOrch->setPort(alias, port);
999963
}
1000964
}
@@ -1139,7 +1103,22 @@ void IntfsOrch::doTask(Consumer &consumer)
11391103
}
11401104
}
11411105

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)
11431122
{
11441123
SWSS_LOG_ENTER();
11451124

@@ -1159,11 +1138,15 @@ bool IntfsOrch::addRouterIntfs(sai_object_id_t vrf_id, Port &port)
11591138
attr.value.oid = vrf_id;
11601139
attrs.push_back(attr);
11611140

1162-
if(port.m_loopback_action != LOOPBACK_ACTION_NONE)
1141+
if (!loopbackActionStr.empty())
11631142
{
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+
}
11671150
}
11681151

11691152
attr.id = SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS;
@@ -1276,6 +1259,7 @@ bool IntfsOrch::addRouterIntfs(sai_object_id_t vrf_id, Port &port)
12761259
}
12771260

12781261
port.m_vr_id = vrf_id;
1262+
port.m_loopback_action = loopbackActionStr;
12791263

12801264
gPortsOrch->setPort(port.m_alias, port);
12811265
m_rifsToAdd.push_back(port);

orchagent/intfsorch.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,9 @@ class IntfsOrch : public Orch
5454
void addRifToFlexCounter(const string&, const string&, const string&);
5555
void removeRifFromFlexCounter(const string&, const string&);
5656

57-
bool setIntfLoopbackAction(const Port &port);
58-
bool getIntfLoopbackAction(const std::string &action_str, loopback_action_e &action);
59-
string getIntfLoopbackActionStr(loopback_action_e action);
60-
bool setIntf(const string& alias, sai_object_id_t vrf_id = gVirtualRouterId, const IpPrefix *ip_prefix = nullptr, const bool adminUp = true, const uint32_t mtu = 0, loopback_action_e loopbackAction = LOOPBACK_ACTION_NONE);
57+
bool setIntfLoopbackAction(const Port &port, string actionStr);
58+
bool getSaiLoopbackAction(const string &actionStr, sai_packet_action_t &action);
59+
bool setIntf(const string& alias, sai_object_id_t vrf_id = gVirtualRouterId, const IpPrefix *ip_prefix = nullptr, const bool adminUp = true, const uint32_t mtu = 0, string loopbackAction = "");
6160
bool removeIntf(const string& alias, sai_object_id_t vrf_id = gVirtualRouterId, const IpPrefix *ip_prefix = nullptr);
6261

6362
void addIp2MeRoute(sai_object_id_t vrf_id, const IpPrefix &ip_prefix);
@@ -91,12 +90,11 @@ class IntfsOrch : public Orch
9190
unique_ptr<Table> m_vidToRidTable;
9291
unique_ptr<ProducerTable> m_flexCounterTable;
9392
unique_ptr<ProducerTable> m_flexCounterGroupTable;
94-
static const unordered_map<string, loopback_action_e> m_loopback_action_map;
95-
static const unordered_map<loopback_action_e, sai_packet_action_t> m_sai_loopback_action_map;
93+
static const unordered_map<string, sai_packet_action_t> m_sai_loopback_action_map;
9694

9795
std::string getRifFlexCounterTableKey(std::string s);
9896

99-
bool addRouterIntfs(sai_object_id_t vrf_id, Port &port);
97+
bool addRouterIntfs(sai_object_id_t vrf_id, Port &port, string loopbackAction);
10098
bool removeRouterIntfs(Port &port);
10199

102100
void addDirectedBroadcast(const Port &port, const IpPrefix &ip_prefix);

orchagent/port.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,6 @@ struct SystemLagInfo
7171
int32_t spa_id = 0;
7272
};
7373

74-
typedef enum loopback_action
75-
{
76-
LOOPBACK_ACTION_NONE,
77-
LOOPBACK_ACTION_DROP,
78-
LOOPBACK_ACTION_FORWARD,
79-
} loopback_action_e;
80-
8174
class Port
8275
{
8376
public:
@@ -114,7 +107,6 @@ class Port
114107
}
115108

116109
std::string m_alias;
117-
loopback_action_e m_loopback_action;
118110
Type m_type;
119111
int m_index = 0; // PHY_PORT: index
120112
uint32_t m_mtu = DEFAULT_MTU;
@@ -158,6 +150,7 @@ class Port
158150
sai_port_interface_type_t m_interface_type;
159151
std::vector<uint32_t> m_adv_interface_types;
160152
bool m_mpls = false;
153+
std::string m_loopback_action;
161154

162155
/*
163156
* Following two bit vectors are used to lock

tests/test_interface.py

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2213,13 +2213,11 @@ def set_loopback_action(self, interface, action):
22132213
tbl.set(interface, fvs)
22142214
time.sleep(1)
22152215

2216-
def loopback_action_test(self, iface):
2216+
def loopback_action_test(self, iface, action):
22172217
# create interface
22182218
self.create_l3_intf(iface, "")
22192219

2220-
# set interface loopback action in config database
2221-
action_map = {"drop": "SAI_PACKET_ACTION_DROP", "forward": "SAI_PACKET_ACTION_FORWARD"}
2222-
action = random.choice(list(action_map.keys()))
2220+
# set interface loopback action in config db
22232221
self.set_loopback_action(iface, action)
22242222

22252223
# check application database
@@ -2234,10 +2232,11 @@ def loopback_action_test(self, iface):
22342232
assert fv[1] == action
22352233
assert action_found == True
22362234

2237-
# check asic database
2235+
# check asic db
22382236
tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE")
22392237
intf_entries = tbl.getKeys()
22402238

2239+
action_map = {"drop": "SAI_PACKET_ACTION_DROP", "forward": "SAI_PACKET_ACTION_FORWARD"}
22412240
action_found = False
22422241
for key in intf_entries:
22432242
(status, fvs) = tbl.get(key)
@@ -2252,25 +2251,45 @@ def loopback_action_test(self, iface):
22522251
# remove interface
22532252
self.remove_l3_intf(iface)
22542253

2255-
def test_interfaceLoopbackAction(self, dvs, testlog):
2254+
def test_interfaceLoopbackActionDrop(self, dvs, testlog):
2255+
self.setup_db(dvs)
2256+
self.loopback_action_test("Ethernet8", "drop")
2257+
2258+
def test_interfaceLoopbackActionForward(self, dvs, testlog):
22562259
self.setup_db(dvs)
2257-
self.loopback_action_test("Ethernet8")
2260+
self.loopback_action_test("Ethernet8", "forward")
22582261

2259-
def test_subInterfaceLoopbackAction(self, dvs, testlog):
2262+
def test_subInterfaceLoopbackActionDrop(self, dvs, testlog):
22602263
self.setup_db(dvs)
2261-
self.loopback_action_test("Ethernet8.1")
2264+
self.loopback_action_test("Ethernet8.1", "drop")
2265+
2266+
def test_subInterfaceLoopbackActionForward(self, dvs, testlog):
2267+
self.setup_db(dvs)
2268+
self.loopback_action_test("Ethernet8.1", "forward")
22622269

2263-
def test_vlanInterfaceLoopbackAction(self, dvs, testlog):
2270+
def test_vlanInterfaceLoopbackActionDrop(self, dvs, testlog):
22642271
self.setup_db(dvs)
22652272
self.create_vlan("10")
2266-
self.loopback_action_test("Vlan10")
2273+
self.loopback_action_test("Vlan10", "drop")
22672274
self.remove_vlan("10")
2275+
2276+
def test_vlanInterfaceLoopbackActionForward(self, dvs, testlog):
2277+
self.setup_db(dvs)
2278+
self.create_vlan("20")
2279+
self.loopback_action_test("Vlan20", "forward")
2280+
self.remove_vlan("20")
22682281

2269-
def test_portChannelInterfaceLoopbackAction(self, dvs, testlog):
2282+
def test_portChannelInterfaceLoopbackActionDrop(self, dvs, testlog):
22702283
self.setup_db(dvs)
22712284
self.create_port_channel("PortChannel009")
2272-
self.loopback_action_test("PortChannel009")
2285+
self.loopback_action_test("PortChannel009", "drop")
22732286
self.remove_port_channel("PortChannel009")
2287+
2288+
def test_portChannelInterfaceLoopbackActionForward(self, dvs, testlog):
2289+
self.setup_db(dvs)
2290+
self.create_port_channel("PortChannel010")
2291+
self.loopback_action_test("PortChannel010", "forward")
2292+
self.remove_port_channel("PortChannel010")
22742293

22752294
# Add Dummy always-pass test at end as workaroud
22762295
# for issue when Flaky fail on final test it invokes module tear-down before retrying

0 commit comments

Comments
 (0)