Skip to content

Commit 9b1e3b8

Browse files
committed
Apply PR of Dynamic port configuration - add port buffer cfg to the port ref counter sonic-net#2022
1 parent d7b5ff7 commit 9b1e3b8

2 files changed

Lines changed: 125 additions & 1 deletion

File tree

orchagent/bufferorch.cpp

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ map<string, string> buffer_to_ref_table_map = {
4242
{buffer_profile_list_field_name, APP_BUFFER_PROFILE_TABLE_NAME}
4343
};
4444

45+
std::map<string, std::map<size_t, string>> pg_port_flags;
46+
std::map<string, std::map<size_t, string>> queue_port_flags;
47+
4548
BufferOrch::BufferOrch(DBConnector *applDb, DBConnector *confDb, DBConnector *stateDb, vector<string> &tableNames) :
4649
Orch(applDb, tableNames),
4750
m_flexCounterDb(new DBConnector("FLEX_COUNTER_DB", 0)),
@@ -949,6 +952,38 @@ task_process_status BufferOrch::processQueue(KeyOpFieldsValuesTuple &tuple)
949952
}
950953
}
951954
}
955+
956+
/* when we apply buffer configuration we need to increase the ref counter of this port
957+
* or decrease the ref counter for this port when we remove buffer cfg
958+
* so for each priority cfg in each port we will increase/decrease the ref counter
959+
* also we need to know when the set command is for creating a buffer cfg or modifying buffer cfg -
960+
* we need to increase ref counter only on create flow.
961+
* so we added a map that will help us to know what was the last command for this port and priority -
962+
* if the last command was set command then it is a modify command and we dont need to increase the buffer counter
963+
* all other cases (no last command exist or del command was the last command) it means that we need to increase the ref counter */
964+
if (op == SET_COMMAND)
965+
{
966+
if (queue_port_flags[port_name][ind] != SET_COMMAND)
967+
{
968+
/* if the last operation was not "set" then it's create and not modify - need to increase ref counter */
969+
gPortsOrch->increasePortRefCount(port_name);
970+
}
971+
}
972+
else if (op == DEL_COMMAND)
973+
{
974+
if (queue_port_flags[port_name][ind] == SET_COMMAND) {
975+
/* we need to decrease ref counter only if the last operation was "SET_COMMAND" */
976+
gPortsOrch->decreasePortRefCount(port_name);
977+
}
978+
}
979+
else
980+
{
981+
SWSS_LOG_ERROR("operation value is not SET or DEL (op = %s)", op.c_str());
982+
return task_process_status::task_invalid_entry;
983+
}
984+
/* save the last command (set or delete) */
985+
queue_port_flags[port_name][ind] = op;
986+
952987
}
953988
}
954989

@@ -1007,7 +1042,7 @@ task_process_status BufferOrch::processPriorityGroup(KeyOpFieldsValuesTuple &tup
10071042
if (op == SET_COMMAND)
10081043
{
10091044
ref_resolve_status resolve_result = resolveFieldRefValue(m_buffer_type_maps, buffer_profile_field_name,
1010-
buffer_to_ref_table_map.at(buffer_profile_field_name), tuple,
1045+
buffer_to_ref_table_map.at(buffer_profile_field_name), tuple,
10111046
sai_buffer_profile, buffer_profile_name);
10121047
if (ref_resolve_status::success != resolve_result)
10131048
{
@@ -1089,6 +1124,39 @@ task_process_status BufferOrch::processPriorityGroup(KeyOpFieldsValuesTuple &tup
10891124
}
10901125
}
10911126
}
1127+
1128+
/* when we apply buffer configuration we need to increase the ref counter of this port
1129+
* or decrease the ref counter for this port when we remove buffer cfg
1130+
* so for each priority cfg in each port we will increase/decrease the ref counter
1131+
* also we need to know when the set command is for creating a buffer cfg or modifying buffer cfg -
1132+
* we need to increase ref counter only on create flow.
1133+
* so we added a map that will help us to know what was the last command for this port and priority -
1134+
* if the last command was set command then it is a modify command and we dont need to increase the buffer counter
1135+
* all other cases (no last command exist or del command was the last command) it means that we need to increase the ref counter */
1136+
if (op == SET_COMMAND)
1137+
{
1138+
if (pg_port_flags[port_name][ind] != SET_COMMAND)
1139+
{
1140+
/* if the last operation was not "set" then it's create and not modify - need to increase ref counter */
1141+
gPortsOrch->increasePortRefCount(port_name);
1142+
}
1143+
}
1144+
else if (op == DEL_COMMAND)
1145+
{
1146+
if (pg_port_flags[port_name][ind] == SET_COMMAND)
1147+
{
1148+
/* we need to decrease ref counter only if the last operation was "SET_COMMAND" */
1149+
gPortsOrch->decreasePortRefCount(port_name);
1150+
}
1151+
}
1152+
else
1153+
{
1154+
SWSS_LOG_ERROR("operation value is not SET or DEL (op = %s)", op.c_str());
1155+
return task_process_status::task_invalid_entry;
1156+
}
1157+
/* save the last command (set or delete) */
1158+
pg_port_flags[port_name][ind] = op;
1159+
10921160
}
10931161
if (portUpdated)
10941162
{

tests/test_port_add_remove.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import pytest
2+
import time
3+
from dvslib.dvs_common import PollingConfig
4+
5+
# the port to be removed and add
6+
PORT = "Ethernet0"
7+
8+
class TestPortAddRemove(object):
9+
10+
def test_remove_port_with_buffer_cfg(self, dvs, testlog):
11+
config_db = dvs.get_config_db()
12+
asic_db = dvs.get_asic_db()
13+
14+
# get port info
15+
port_info = config_db.get_entry("PORT", PORT)
16+
17+
# get the number of ports before removal
18+
num_of_ports = len(asic_db.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_PORT"))
19+
20+
# try to remove this port
21+
config_db.delete_entry('PORT', PORT)
22+
num = asic_db.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_PORT",
23+
num_of_ports-1,
24+
polling_config = PollingConfig(polling_interval = 1, timeout = 5.00, strict = False))
25+
26+
# verify that the port wasn't removed since we still have buffer cfg
27+
assert len(num) == num_of_ports
28+
29+
# remove buffer pg cfg for the port
30+
pgs = config_db.get_keys('BUFFER_PG')
31+
for key in pgs:
32+
if PORT in key:
33+
config_db.delete_entry('BUFFER_PG', key)
34+
35+
num = asic_db.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_PORT",
36+
num_of_ports-1,
37+
polling_config = PollingConfig(polling_interval = 1, timeout = 5.00, strict = False))
38+
39+
# verify that the port wasn't removed since we still have buffer cfg
40+
assert len(num) == num_of_ports
41+
42+
# modify buffer queue entry to egress_lossless_profile instead of egress_lossy_profile
43+
config_db.update_entry("BUFFER_QUEUE", "%s|0-2"%PORT, {"profile": "egress_lossless_profile"})
44+
45+
# remove buffer queue cfg for the port
46+
pgs = config_db.get_keys('BUFFER_QUEUE')
47+
for key in pgs:
48+
if PORT in key:
49+
config_db.delete_entry('BUFFER_QUEUE', key)
50+
51+
num = asic_db.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_PORT",
52+
num_of_ports-1,
53+
polling_config = PollingConfig(polling_interval = 1, timeout = 5.00, strict = True))
54+
55+
# verify that the port was removed properly since all buffer configuration was removed also
56+
assert len(num) == num_of_ports - 1

0 commit comments

Comments
 (0)