@@ -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+
4548BufferOrch::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 {
0 commit comments