1
1
#include " tokenize.h"
2
2
#include " bufferorch.h"
3
+ #include " directory.h"
3
4
#include " logger.h"
4
5
#include " sai_serialize.h"
5
6
#include " warm_restart.h"
@@ -16,6 +17,7 @@ extern sai_switch_api_t *sai_switch_api;
16
17
extern sai_buffer_api_t *sai_buffer_api;
17
18
18
19
extern PortsOrch *gPortsOrch ;
20
+ extern Directory<Orch*> gDirectory ;
19
21
extern sai_object_id_t gSwitchId ;
20
22
21
23
#define BUFFER_POOL_WATERMARK_FLEX_STAT_COUNTER_POLL_MSECS " 60000"
@@ -42,6 +44,9 @@ map<string, string> buffer_to_ref_table_map = {
42
44
{buffer_profile_list_field_name, APP_BUFFER_PROFILE_TABLE_NAME}
43
45
};
44
46
47
+ std::map<string, std::map<size_t , string>> pg_port_flags;
48
+ std::map<string, std::map<size_t , string>> queue_port_flags;
49
+
45
50
BufferOrch::BufferOrch (DBConnector *applDb, DBConnector *confDb, DBConnector *stateDb, vector<string> &tableNames) :
46
51
Orch(applDb, tableNames),
47
52
m_flexCounterDb(new DBConnector(" FLEX_COUNTER_DB" , 0 )),
@@ -812,7 +817,54 @@ task_process_status BufferOrch::processQueue(KeyOpFieldsValuesTuple &tuple)
812
817
return handle_status;
813
818
}
814
819
}
820
+ // create/remove a port queue counter for the queue buffer
821
+ else
822
+ {
823
+ auto flexCounterOrch = gDirectory .get <FlexCounterOrch*>();
824
+ auto queues = tokens[1 ];
825
+ if (op == SET_COMMAND && flexCounterOrch->getQueueCountersState ())
826
+ {
827
+ gPortsOrch ->createPortBufferQueueCounters (port, queues);
828
+ }
829
+ else if (op == DEL_COMMAND && flexCounterOrch->getQueueCountersState ())
830
+ {
831
+ gPortsOrch ->removePortBufferQueueCounters (port, queues);
832
+ }
833
+ }
834
+ }
835
+
836
+ /* when we apply buffer configuration we need to increase the ref counter of this port
837
+ * or decrease the ref counter for this port when we remove buffer cfg
838
+ * so for each priority cfg in each port we will increase/decrease the ref counter
839
+ * also we need to know when the set command is for creating a buffer cfg or modifying buffer cfg -
840
+ * we need to increase ref counter only on create flow.
841
+ * so we added a map that will help us to know what was the last command for this port and priority -
842
+ * if the last command was set command then it is a modify command and we dont need to increase the buffer counter
843
+ * all other cases (no last command exist or del command was the last command) it means that we need to increase the ref counter */
844
+ if (op == SET_COMMAND)
845
+ {
846
+ if (queue_port_flags[port_name][ind] != SET_COMMAND)
847
+ {
848
+ /* if the last operation was not "set" then it's create and not modify - need to increase ref counter */
849
+ gPortsOrch ->increasePortRefCount (port_name);
850
+ }
851
+ }
852
+ else if (op == DEL_COMMAND)
853
+ {
854
+ if (queue_port_flags[port_name][ind] == SET_COMMAND)
855
+ {
856
+ /* we need to decrease ref counter only if the last operation was "SET_COMMAND" */
857
+ gPortsOrch ->decreasePortRefCount (port_name);
858
+ }
859
+ }
860
+ else
861
+ {
862
+ SWSS_LOG_ERROR (" operation value is not SET or DEL (op = %s)" , op.c_str ());
863
+ return task_process_status::task_invalid_entry;
815
864
}
865
+ /* save the last command (set or delete) */
866
+ queue_port_flags[port_name][ind] = op;
867
+
816
868
}
817
869
}
818
870
@@ -871,7 +923,7 @@ task_process_status BufferOrch::processPriorityGroup(KeyOpFieldsValuesTuple &tup
871
923
if (op == SET_COMMAND)
872
924
{
873
925
ref_resolve_status resolve_result = resolveFieldRefValue (m_buffer_type_maps, buffer_profile_field_name,
874
- buffer_to_ref_table_map.at (buffer_profile_field_name), tuple,
926
+ buffer_to_ref_table_map.at (buffer_profile_field_name), tuple,
875
927
sai_buffer_profile, buffer_profile_name);
876
928
if (ref_resolve_status::success != resolve_result)
877
929
{
@@ -944,8 +996,55 @@ task_process_status BufferOrch::processPriorityGroup(KeyOpFieldsValuesTuple &tup
944
996
return handle_status;
945
997
}
946
998
}
999
+ // create or remove a port PG counter for the PG buffer
1000
+ else
1001
+ {
1002
+ auto flexCounterOrch = gDirectory .get <FlexCounterOrch*>();
1003
+ auto pgs = tokens[1 ];
1004
+ if (op == SET_COMMAND && flexCounterOrch->getPgWatermarkCountersState ())
1005
+ {
1006
+ gPortsOrch ->createPortBufferPgCounters (port, pgs);
1007
+ }
1008
+ else if (op == DEL_COMMAND && flexCounterOrch->getPgWatermarkCountersState ())
1009
+ {
1010
+ gPortsOrch ->removePortBufferPgCounters (port, pgs);
1011
+ }
1012
+ }
947
1013
}
948
1014
}
1015
+
1016
+ /* when we apply buffer configuration we need to increase the ref counter of this port
1017
+ * or decrease the ref counter for this port when we remove buffer cfg
1018
+ * so for each priority cfg in each port we will increase/decrease the ref counter
1019
+ * also we need to know when the set command is for creating a buffer cfg or modifying buffer cfg -
1020
+ * we need to increase ref counter only on create flow.
1021
+ * so we added a map that will help us to know what was the last command for this port and priority -
1022
+ * if the last command was set command then it is a modify command and we dont need to increase the buffer counter
1023
+ * all other cases (no last command exist or del command was the last command) it means that we need to increase the ref counter */
1024
+ if (op == SET_COMMAND)
1025
+ {
1026
+ if (pg_port_flags[port_name][ind] != SET_COMMAND)
1027
+ {
1028
+ /* if the last operation was not "set" then it's create and not modify - need to increase ref counter */
1029
+ gPortsOrch ->increasePortRefCount (port_name);
1030
+ }
1031
+ }
1032
+ else if (op == DEL_COMMAND)
1033
+ {
1034
+ if (pg_port_flags[port_name][ind] == SET_COMMAND)
1035
+ {
1036
+ /* we need to decrease ref counter only if the last operation was "SET_COMMAND" */
1037
+ gPortsOrch ->decreasePortRefCount (port_name);
1038
+ }
1039
+ }
1040
+ else
1041
+ {
1042
+ SWSS_LOG_ERROR (" operation value is not SET or DEL (op = %s)" , op.c_str ());
1043
+ return task_process_status::task_invalid_entry;
1044
+ }
1045
+ /* save the last command (set or delete) */
1046
+ pg_port_flags[port_name][ind] = op;
1047
+
949
1048
}
950
1049
}
951
1050
0 commit comments