16
16
17
17
#include " logger.h"
18
18
#include " schema.h"
19
+ #include " redisapi.h"
19
20
#include " converter.h"
20
21
#include " sai_serialize.h"
21
22
#include " crmorch.h"
@@ -40,6 +41,9 @@ extern BufferOrch *gBufferOrch;
40
41
#define DEFAULT_VLAN_ID 1
41
42
#define PORT_FLEX_STAT_COUNTER_POLL_MSECS " 1000"
42
43
#define QUEUE_FLEX_STAT_COUNTER_POLL_MSECS " 10000"
44
+ #define QUEUE_WATERMARK_FLEX_STAT_COUNTER_POLL_MSECS " 1000"
45
+ #define PG_WATERMARK_FLEX_STAT_COUNTER_POLL_MSECS " 1000"
46
+
43
47
44
48
static map<string, sai_port_fec_mode_t > fec_mode_map =
45
49
{
@@ -105,6 +109,17 @@ static const vector<sai_queue_stat_t> queueStatIds =
105
109
SAI_QUEUE_STAT_DROPPED_BYTES,
106
110
};
107
111
112
+ static const vector<sai_queue_stat_t > queueWatermarkStatIds =
113
+ {
114
+ SAI_QUEUE_STAT_SHARED_WATERMARK_BYTES,
115
+ };
116
+
117
+ static const vector<sai_ingress_priority_group_stat_t > ingressPriorityGroupWatermarkStatIds =
118
+ {
119
+ SAI_INGRESS_PRIORITY_GROUP_STAT_XOFF_ROOM_WATERMARK_BYTES,
120
+ SAI_INGRESS_PRIORITY_GROUP_STAT_SHARED_WATERMARK_BYTES,
121
+ };
122
+
108
123
static char * hostif_vlan_tag[] = {
109
124
[SAI_HOSTIF_VLAN_TAG_STRIP] = " SAI_HOSTIF_VLAN_TAG_STRIP" ,
110
125
[SAI_HOSTIF_VLAN_TAG_KEEP] = " SAI_HOSTIF_VLAN_TAG_KEEP" ,
@@ -141,17 +156,53 @@ PortsOrch::PortsOrch(DBConnector *db, vector<table_name_with_pri_t> &tableNames)
141
156
m_queueIndexTable = unique_ptr<Table>(new Table (m_counter_db.get (), COUNTERS_QUEUE_INDEX_MAP));
142
157
m_queueTypeTable = unique_ptr<Table>(new Table (m_counter_db.get (), COUNTERS_QUEUE_TYPE_MAP));
143
158
159
+ /* Initialize ingress priority group tables */
160
+ m_pgTable = unique_ptr<Table>(new Table (m_counter_db.get (), COUNTERS_PG_NAME_MAP));
161
+ m_pgPortTable = unique_ptr<Table>(new Table (m_counter_db.get (), COUNTERS_PG_PORT_MAP));
162
+ m_pgIndexTable = unique_ptr<Table>(new Table (m_counter_db.get (), COUNTERS_PG_INDEX_MAP));
163
+
144
164
m_flex_db = shared_ptr<DBConnector>(new DBConnector (FLEX_COUNTER_DB, DBConnector::DEFAULT_UNIXSOCKET, 0 ));
145
165
m_flexCounterTable = unique_ptr<ProducerTable>(new ProducerTable (m_flex_db.get (), FLEX_COUNTER_TABLE));
146
166
m_flexCounterGroupTable = unique_ptr<ProducerTable>(new ProducerTable (m_flex_db.get (), FLEX_COUNTER_GROUP_TABLE));
147
167
148
168
vector<FieldValueTuple> fields;
149
169
fields.emplace_back (POLL_INTERVAL_FIELD, PORT_FLEX_STAT_COUNTER_POLL_MSECS);
170
+ fields.emplace_back (STATS_MODE_FIELD, STATS_MODE_READ);
150
171
m_flexCounterGroupTable->set (PORT_STAT_COUNTER_FLEX_COUNTER_GROUP, fields);
151
172
152
173
fields.emplace_back (POLL_INTERVAL_FIELD, QUEUE_FLEX_STAT_COUNTER_POLL_MSECS);
174
+ fields.emplace_back (STATS_MODE_FIELD, STATS_MODE_READ);
153
175
m_flexCounterGroupTable->set (QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP, fields);
154
176
177
+ string queueWmSha, pgWmSha;
178
+ string queueWmPluginName = " watermark_queue.lua" ;
179
+ string pgWmPluginName = " watermark_pg.lua" ;
180
+
181
+ try
182
+ {
183
+ string queueLuaScript = swss::loadLuaScript (queueWmPluginName);
184
+ queueWmSha = swss::loadRedisScript (m_counter_db.get (), queueLuaScript);
185
+
186
+ string pgLuaScript = swss::loadLuaScript (pgWmPluginName);
187
+ pgWmSha = swss::loadRedisScript (m_counter_db.get (), pgLuaScript);
188
+
189
+ vector<FieldValueTuple> fieldValues;
190
+ fieldValues.emplace_back (QUEUE_PLUGIN_FIELD, queueWmSha);
191
+ fieldValues.emplace_back (POLL_INTERVAL_FIELD, QUEUE_WATERMARK_FLEX_STAT_COUNTER_POLL_MSECS);
192
+ fieldValues.emplace_back (STATS_MODE_FIELD, STATS_MODE_READ_AND_CLEAR);
193
+ m_flexCounterGroupTable->set (QUEUE_WATERMARK_STAT_COUNTER_FLEX_COUNTER_GROUP, fieldValues);
194
+
195
+ fieldValues.clear ();
196
+ fieldValues.emplace_back (PG_PLUGIN_FIELD, pgWmSha);
197
+ fieldValues.emplace_back (POLL_INTERVAL_FIELD, PG_WATERMARK_FLEX_STAT_COUNTER_POLL_MSECS);
198
+ fieldValues.emplace_back (STATS_MODE_FIELD, STATS_MODE_READ_AND_CLEAR);
199
+ m_flexCounterGroupTable->set (PG_WATERMARK_STAT_COUNTER_FLEX_COUNTER_GROUP, fieldValues);
200
+ }
201
+ catch (...)
202
+ {
203
+ SWSS_LOG_WARN (" Watermark flex counter groups were not set successfully" );
204
+ }
205
+
155
206
uint32_t i, j;
156
207
sai_status_t status;
157
208
sai_attribute_t attr;
@@ -1248,6 +1299,16 @@ string PortsOrch::getQueueFlexCounterTableKey(string key)
1248
1299
return string (QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP) + " :" + key;
1249
1300
}
1250
1301
1302
+ string PortsOrch::getQueueWatermarkFlexCounterTableKey (string key)
1303
+ {
1304
+ return string (QUEUE_WATERMARK_STAT_COUNTER_FLEX_COUNTER_GROUP) + " :" + key;
1305
+ }
1306
+
1307
+ string PortsOrch::getPriorityGroupWatermarkFlexCounterTableKey (string key)
1308
+ {
1309
+ return string (PG_WATERMARK_STAT_COUNTER_FLEX_COUNTER_GROUP) + " :" + key;
1310
+ }
1311
+
1251
1312
bool PortsOrch::initPort (const string &alias, const set<int > &lane_set)
1252
1313
{
1253
1314
SWSS_LOG_ENTER ();
@@ -1287,7 +1348,7 @@ bool PortsOrch::initPort(const string &alias, const set<int> &lane_set)
1287
1348
for (const auto &id: portStatIds)
1288
1349
{
1289
1350
counters_stream << delimiter << sai_serialize_port_stat (id);
1290
- delimiter = " , " ;
1351
+ delimiter = comma ;
1291
1352
}
1292
1353
1293
1354
fields.clear ();
@@ -2873,20 +2934,37 @@ void PortsOrch::generateQueueMapPerPort(const Port& port)
2873
2934
queueIndexVector.emplace_back (id, to_string (queueRealIndex));
2874
2935
}
2875
2936
2937
+ /* add ordinary Queue stat counters */
2876
2938
string key = getQueueFlexCounterTableKey (id);
2877
2939
2878
2940
std::string delimiter = " " ;
2879
2941
std::ostringstream counters_stream;
2880
2942
for (const auto & it: queueStatIds)
2881
2943
{
2882
2944
counters_stream << delimiter << sai_serialize_queue_stat (it);
2883
- delimiter = " , " ;
2945
+ delimiter = comma ;
2884
2946
}
2885
2947
2886
2948
vector<FieldValueTuple> fieldValues;
2887
2949
fieldValues.emplace_back (QUEUE_COUNTER_ID_LIST, counters_stream.str ());
2888
2950
2889
2951
m_flexCounterTable->set (key, fieldValues);
2952
+
2953
+ /* add watermark queue counters */
2954
+ key = getQueueWatermarkFlexCounterTableKey (id);
2955
+
2956
+ delimiter = " " ;
2957
+ counters_stream.str (" " );
2958
+ for (const auto & it: queueWatermarkStatIds)
2959
+ {
2960
+ counters_stream << delimiter << sai_serialize_queue_stat (it);
2961
+ delimiter = comma;
2962
+ }
2963
+
2964
+ fieldValues.clear ();
2965
+ fieldValues.emplace_back (QUEUE_COUNTER_ID_LIST, counters_stream.str ());
2966
+
2967
+ m_flexCounterTable->set (key, fieldValues);
2890
2968
}
2891
2969
2892
2970
m_queueTable->set (" " , queueVector);
@@ -2897,6 +2975,67 @@ void PortsOrch::generateQueueMapPerPort(const Port& port)
2897
2975
CounterCheckOrch::getInstance ().addPort (port);
2898
2976
}
2899
2977
2978
+ void PortsOrch::generatePriorityGroupMap ()
2979
+ {
2980
+ if (m_isPriorityGroupMapGenerated)
2981
+ {
2982
+ return ;
2983
+ }
2984
+
2985
+ for (const auto & it: m_portList)
2986
+ {
2987
+ if (it.second .m_type == Port::PHY)
2988
+ {
2989
+ generatePriorityGroupMapPerPort (it.second );
2990
+ }
2991
+ }
2992
+
2993
+ m_isPriorityGroupMapGenerated = true ;
2994
+ }
2995
+
2996
+ void PortsOrch::generatePriorityGroupMapPerPort (const Port& port)
2997
+ {
2998
+ /* Create the PG map in the Counter DB */
2999
+ /* Add stat counters to flex_counter */
3000
+ vector<FieldValueTuple> pgVector;
3001
+ vector<FieldValueTuple> pgPortVector;
3002
+ vector<FieldValueTuple> pgIndexVector;
3003
+
3004
+ for (size_t pgIndex = 0 ; pgIndex < port.m_priority_group_ids .size (); ++pgIndex)
3005
+ {
3006
+ std::ostringstream name;
3007
+ name << port.m_alias << " :" << pgIndex;
3008
+
3009
+ const auto id = sai_serialize_object_id (port.m_priority_group_ids [pgIndex]);
3010
+
3011
+ pgVector.emplace_back (name.str (), id);
3012
+ pgPortVector.emplace_back (id, sai_serialize_object_id (port.m_port_id ));
3013
+ pgIndexVector.emplace_back (id, to_string (pgIndex));
3014
+
3015
+ string key = getPriorityGroupWatermarkFlexCounterTableKey (id);
3016
+
3017
+ std::string delimiter = " " ;
3018
+ std::ostringstream counters_stream;
3019
+ /* Add watermark counters to flex_counter */
3020
+ for (const auto & it: ingressPriorityGroupWatermarkStatIds)
3021
+ {
3022
+ counters_stream << delimiter << sai_serialize_ingress_priority_group_stat (it);
3023
+ delimiter = comma;
3024
+ }
3025
+
3026
+ vector<FieldValueTuple> fieldValues;
3027
+ fieldValues.emplace_back (PG_COUNTER_ID_LIST, counters_stream.str ());
3028
+
3029
+ m_flexCounterTable->set (key, fieldValues);
3030
+ }
3031
+
3032
+ m_pgTable->set (" " , pgVector);
3033
+ m_pgPortTable->set (" " , pgPortVector);
3034
+ m_pgIndexTable->set (" " , pgIndexVector);
3035
+
3036
+ CounterCheckOrch::getInstance ().addPort (port);
3037
+ }
3038
+
2900
3039
void PortsOrch::doTask (NotificationConsumer &consumer)
2901
3040
{
2902
3041
SWSS_LOG_ENTER ();
0 commit comments