1
1
#include " syncd.h"
2
2
#include " syncd_saiswitch.h"
3
3
#include " sairedis.h"
4
+ #include " syncd_pfc_watchdog.h"
4
5
#include " swss/tokenize.h"
5
6
#include < limits.h>
6
7
@@ -2330,6 +2331,62 @@ sai_status_t processEvent(
2330
2331
return status;
2331
2332
}
2332
2333
2334
+ void processPfcWdEvent (
2335
+ _In_ swss::ConsumerStateTable &consumer)
2336
+ {
2337
+ std::lock_guard<std::mutex> lock (g_mutex);
2338
+
2339
+ SWSS_LOG_ENTER ();
2340
+
2341
+ swss::KeyOpFieldsValuesTuple kco;
2342
+ consumer.pop (kco);
2343
+
2344
+ const auto &key = kfvKey (kco);
2345
+ const auto &op = kfvOp (kco);
2346
+
2347
+ sai_object_id_t queueVid = SAI_NULL_OBJECT_ID;
2348
+ sai_deserialize_object_id (key, queueVid);
2349
+ sai_object_id_t queueId = translate_vid_to_rid (queueVid);
2350
+
2351
+ const auto values = kfvFieldsValues (kco);
2352
+ for (const auto & valuePair : values)
2353
+ {
2354
+ const auto field = fvField (valuePair);
2355
+ const auto value = fvValue (valuePair);
2356
+
2357
+ if (op == DEL_COMMAND)
2358
+ {
2359
+ PfcWatchdog::removeQueue (queueVid);
2360
+ continue ;
2361
+ }
2362
+
2363
+ auto idStrings = swss::tokenize (value, ' ,' );
2364
+
2365
+ if (field == PFC_WD_PORT_COUNTER_ID_LIST)
2366
+ {
2367
+ std::vector<sai_port_stat_t > portCounterIds;
2368
+ for (const auto &str : idStrings)
2369
+ {
2370
+ sai_port_stat_t stat;
2371
+ sai_deserialize_port_stat (str, stat);
2372
+ portCounterIds.push_back (stat);
2373
+ }
2374
+ PfcWatchdog::setPortCounterList (queueVid, queueId, portCounterIds);
2375
+ }
2376
+ else if (field == PFC_WD_QUEUE_COUNTER_ID_LIST)
2377
+ {
2378
+ std::vector<sai_queue_stat_t > queueCounterIds;
2379
+ for (const auto &str : idStrings)
2380
+ {
2381
+ sai_queue_stat_t stat;
2382
+ sai_deserialize_queue_stat (str, stat);
2383
+ queueCounterIds.push_back (stat);
2384
+ }
2385
+ PfcWatchdog::setQueueCounterList (queueVid, queueId, queueCounterIds);
2386
+ }
2387
+ }
2388
+ }
2389
+
2333
2390
void printUsage ()
2334
2391
{
2335
2392
std::cout << " Usage: syncd [-N] [-d] [-p profile] [-i interval] [-t [cold|warm|fast]] [-h] [-u] [-S]" << std::endl;
@@ -2901,21 +2958,23 @@ int main(int argc, char **argv)
2901
2958
}
2902
2959
#endif // SAITHRIFT
2903
2960
2904
- std::shared_ptr<swss::DBConnector> db = std::make_shared<swss::DBConnector>(ASIC_DB, swss::DBConnector::DEFAULT_UNIXSOCKET, 0 );
2961
+ std::shared_ptr<swss::DBConnector> dbAsic = std::make_shared<swss::DBConnector>(ASIC_DB, swss::DBConnector::DEFAULT_UNIXSOCKET, 0 );
2905
2962
std::shared_ptr<swss::DBConnector> dbNtf = std::make_shared<swss::DBConnector>(ASIC_DB, swss::DBConnector::DEFAULT_UNIXSOCKET, 0 );
2963
+ std::shared_ptr<swss::DBConnector> dbPfcWatchdog = std::make_shared<swss::DBConnector>(PFC_WD_DB, swss::DBConnector::DEFAULT_UNIXSOCKET, 0 );
2906
2964
2907
- g_redisClient = std::make_shared<swss::RedisClient>(db .get ());
2965
+ g_redisClient = std::make_shared<swss::RedisClient>(dbAsic .get ());
2908
2966
2909
- std::shared_ptr<swss::ConsumerTable> asicState = std::make_shared<swss::ConsumerTable>(db.get (), ASIC_STATE_TABLE);
2910
- std::shared_ptr<swss::NotificationConsumer> restartQuery = std::make_shared<swss::NotificationConsumer>(db.get (), " RESTARTQUERY" );
2967
+ std::shared_ptr<swss::ConsumerTable> asicState = std::make_shared<swss::ConsumerTable>(dbAsic.get (), ASIC_STATE_TABLE);
2968
+ std::shared_ptr<swss::NotificationConsumer> restartQuery = std::make_shared<swss::NotificationConsumer>(dbAsic.get (), " RESTARTQUERY" );
2969
+ std::shared_ptr<swss::ConsumerStateTable> pfcWdState = std::make_shared<swss::ConsumerStateTable>(dbPfcWatchdog.get (), PFC_WD_STATE_TABLE);
2911
2970
2912
2971
/*
2913
2972
* At the end we cant use producer consumer concept since if one proces
2914
2973
* will restart there may be something in the queue also "remove" from
2915
2974
* response queue will also trigger another "response".
2916
2975
*/
2917
2976
2918
- getResponse = std::make_shared<swss::ProducerTable>(db .get (), " GETRESPONSE" );
2977
+ getResponse = std::make_shared<swss::ProducerTable>(dbAsic .get (), " GETRESPONSE" );
2919
2978
notifications = std::make_shared<swss::NotificationProducer>(dbNtf.get (), " NOTIFICATIONS" );
2920
2979
2921
2980
g_veryFirstRun = isVeryFirstRun ();
@@ -3003,6 +3062,7 @@ int main(int argc, char **argv)
3003
3062
3004
3063
s.addSelectable (asicState.get ());
3005
3064
s.addSelectable (restartQuery.get ());
3065
+ s.addSelectable (pfcWdState.get ());
3006
3066
3007
3067
SWSS_LOG_NOTICE (" starting main loop" );
3008
3068
@@ -3027,8 +3087,11 @@ int main(int argc, char **argv)
3027
3087
warmRestartHint = handleRestartQuery (*restartQuery);
3028
3088
break ;
3029
3089
}
3030
-
3031
- if (result == swss::Select::OBJECT)
3090
+ else if (sel == pfcWdState.get ())
3091
+ {
3092
+ processPfcWdEvent (*(swss::ConsumerStateTable*)sel);
3093
+ }
3094
+ else if (result == swss::Select::OBJECT)
3032
3095
{
3033
3096
processEvent (*(swss::ConsumerTable*)sel);
3034
3097
}
0 commit comments