@@ -33,17 +33,100 @@ const map<string, sai_packet_action_t> packet_action_map =
33
33
{" trap" , SAI_PACKET_ACTION_TRAP}
34
34
};
35
35
36
- SwitchOrch::SwitchOrch (DBConnector *db, string tableName , TableConnector switchTable):
37
- Orch(db, tableName ),
36
+ SwitchOrch::SwitchOrch (DBConnector *db, vector<TableConnector>& connectors , TableConnector switchTable):
37
+ Orch(connectors ),
38
38
m_switchTable(switchTable.first, switchTable.second),
39
- m_db(db)
39
+ m_db(db),
40
+ m_stateDb(new DBConnector(STATE_DB, DBConnector::DEFAULT_UNIXSOCKET, 0 )),
41
+ m_asicSensorsTable(new Table(m_stateDb.get(), ASIC_TEMPERATURE_INFO_TABLE_NAME)),
42
+ m_sensorsPollerTimer (new SelectableTimer((timespec { .tv_sec = DEFAULT_ASIC_SENSORS_POLLER_INTERVAL, .tv_nsec = 0 })))
40
43
{
41
44
m_restartCheckNotificationConsumer = new NotificationConsumer (db, " RESTARTCHECK" );
42
45
auto restartCheckNotifier = new Notifier (m_restartCheckNotificationConsumer, this , " RESTARTCHECK" );
43
46
Orch::addExecutor (restartCheckNotifier);
47
+
48
+ initSensorsTable ();
49
+ auto executorT = new ExecutableTimer (m_sensorsPollerTimer, this , " ASIC_SENSORS_POLL_TIMER" );
50
+ Orch::addExecutor (executorT);
44
51
}
45
52
46
- void SwitchOrch::doTask (Consumer &consumer)
53
+ void SwitchOrch::doCfgSensorsTableTask (Consumer &consumer)
54
+ {
55
+ SWSS_LOG_ENTER ();
56
+
57
+ auto it = consumer.m_toSync .begin ();
58
+ while (it != consumer.m_toSync .end ())
59
+ {
60
+ KeyOpFieldsValuesTuple t = it->second ;
61
+ string table_attr = kfvKey (t);
62
+ string op = kfvOp (t);
63
+
64
+ if (op == SET_COMMAND)
65
+ {
66
+ FieldValueTuple fvt = kfvFieldsValues (t)[0 ];
67
+ SWSS_LOG_NOTICE (" ASIC sensors : set %s(%s) to %s" , table_attr.c_str (), fvField (fvt).c_str (), fvValue (fvt).c_str ());
68
+
69
+ if (table_attr == ASIC_SENSORS_POLLER_STATUS)
70
+ {
71
+ if (fvField (fvt) == " admin_status" )
72
+ {
73
+ if (fvValue (fvt) == " enable" && !m_sensorsPollerEnabled)
74
+ {
75
+ m_sensorsPollerTimer->start ();
76
+ m_sensorsPollerEnabled = true ;
77
+ }
78
+ else if (fvValue (fvt) == " disable" )
79
+ {
80
+ m_sensorsPollerEnabled = false ;
81
+ }
82
+ else
83
+ {
84
+ SWSS_LOG_ERROR (" ASIC sensors : unsupported operation for poller state %d" ,m_sensorsPollerEnabled);
85
+ }
86
+ }
87
+ else
88
+ {
89
+ SWSS_LOG_ERROR (" ASIC sensors : unsupported field in attribute %s" , ASIC_SENSORS_POLLER_STATUS);
90
+ }
91
+ }
92
+ else if (table_attr == ASIC_SENSORS_POLLER_INTERVAL)
93
+ {
94
+ uint32_t interval=to_uint<uint32_t >(fvValue (fvt));
95
+
96
+ if (fvField (fvt) == " interval" )
97
+ {
98
+ if (interval != m_sensorsPollerInterval)
99
+ {
100
+ auto intervT = timespec { .tv_sec = interval , .tv_nsec = 0 };
101
+ m_sensorsPollerTimer->setInterval (intervT);
102
+ m_sensorsPollerInterval = interval;
103
+ m_sensorsPollerIntervalChanged = true ;
104
+ }
105
+ else
106
+ {
107
+ SWSS_LOG_INFO (" ASIC sensors : poller interval unchanged : %d seconds" ,m_sensorsPollerInterval);
108
+ }
109
+ }
110
+ else
111
+ {
112
+ SWSS_LOG_ERROR (" ASIC sensors : unsupported field in attribute %s" , ASIC_SENSORS_POLLER_INTERVAL);
113
+ }
114
+ }
115
+ else
116
+ {
117
+ SWSS_LOG_ERROR (" ASIC sensors : unsupported attribute %s" , table_attr.c_str ());
118
+ }
119
+ }
120
+ else
121
+ {
122
+ SWSS_LOG_ERROR (" ASIC sensors : unsupported operation %s" ,op.c_str ());
123
+ }
124
+
125
+ it = consumer.m_toSync .erase (it);
126
+ }
127
+ }
128
+
129
+ void SwitchOrch::doAppSwitchTableTask (Consumer &consumer)
47
130
{
48
131
SWSS_LOG_ENTER ();
49
132
@@ -145,6 +228,26 @@ void SwitchOrch::doTask(Consumer &consumer)
145
228
}
146
229
}
147
230
231
+ void SwitchOrch::doTask (Consumer &consumer)
232
+ {
233
+ SWSS_LOG_ENTER ();
234
+ const string & table_name = consumer.getTableName ();
235
+
236
+ if (table_name == APP_SWITCH_TABLE_NAME)
237
+ {
238
+ doAppSwitchTableTask (consumer);
239
+ }
240
+ else if (table_name == CFG_ASIC_SENSORS_TABLE_NAME)
241
+ {
242
+ doCfgSensorsTableTask (consumer);
243
+ }
244
+ else
245
+ {
246
+ SWSS_LOG_ERROR (" Unknown table : %s" , table_name.c_str ());
247
+ }
248
+
249
+ }
250
+
148
251
void SwitchOrch::doTask (NotificationConsumer& consumer)
149
252
{
150
253
SWSS_LOG_ENTER ();
@@ -209,6 +312,171 @@ bool SwitchOrch::setAgingFDB(uint32_t sec)
209
312
return true ;
210
313
}
211
314
315
+ void SwitchOrch::doTask (SelectableTimer &timer)
316
+ {
317
+ SWSS_LOG_ENTER ();
318
+
319
+ if (&timer == m_sensorsPollerTimer)
320
+ {
321
+ if (m_sensorsPollerIntervalChanged)
322
+ {
323
+ m_sensorsPollerTimer->reset ();
324
+ m_sensorsPollerIntervalChanged = false ;
325
+ }
326
+
327
+ if (!m_sensorsPollerEnabled)
328
+ {
329
+ m_sensorsPollerTimer->stop ();
330
+ return ;
331
+ }
332
+
333
+ sai_attribute_t attr;
334
+ sai_status_t status;
335
+ std::vector<FieldValueTuple> values;
336
+
337
+ if (m_numTempSensors)
338
+ {
339
+ std::vector<int32_t > temp_list (m_numTempSensors);
340
+
341
+ memset (&attr, 0 , sizeof (attr));
342
+ attr.id = SAI_SWITCH_ATTR_TEMP_LIST;
343
+ attr.value .s32list .count = m_numTempSensors;
344
+ attr.value .s32list .list = temp_list.data ();
345
+
346
+ status = sai_switch_api->get_switch_attribute (gSwitchId , 1 , &attr);
347
+ if (status == SAI_STATUS_SUCCESS)
348
+ {
349
+ for (size_t i = 0 ; i < attr.value .s32list .count ; i++) {
350
+ const std::string &fieldName = " temperature_" + std::to_string (i);
351
+ values.emplace_back (fieldName, std::to_string (temp_list[i]));
352
+ }
353
+ m_asicSensorsTable->set (" " ,values);
354
+ }
355
+ else
356
+ {
357
+ SWSS_LOG_ERROR (" ASIC sensors : failed to get SAI_SWITCH_ATTR_TEMP_LIST: %d" , status);
358
+ }
359
+ }
360
+
361
+ if (m_sensorsMaxTempSupported)
362
+ {
363
+ memset (&attr, 0 , sizeof (attr));
364
+ attr.id = SAI_SWITCH_ATTR_MAX_TEMP;
365
+
366
+ status = sai_switch_api->get_switch_attribute (gSwitchId , 1 , &attr);
367
+ if (status == SAI_STATUS_SUCCESS)
368
+ {
369
+ const std::string &fieldName = " maximum_temperature" ;
370
+ values.emplace_back (fieldName, std::to_string (attr.value .s32 ));
371
+ m_asicSensorsTable->set (" " ,values);
372
+ }
373
+ else if (status == SAI_STATUS_NOT_SUPPORTED || status == SAI_STATUS_NOT_IMPLEMENTED)
374
+ {
375
+ m_sensorsMaxTempSupported = false ;
376
+ SWSS_LOG_INFO (" ASIC sensors : SAI_SWITCH_ATTR_MAX_TEMP is not supported" );
377
+ }
378
+ else
379
+ {
380
+ m_sensorsMaxTempSupported = false ;
381
+ SWSS_LOG_ERROR (" ASIC sensors : failed to get SAI_SWITCH_ATTR_MAX_TEMP: %d" , status);
382
+ }
383
+ }
384
+
385
+ if (m_sensorsAvgTempSupported)
386
+ {
387
+ memset (&attr, 0 , sizeof (attr));
388
+ attr.id = SAI_SWITCH_ATTR_AVERAGE_TEMP;
389
+
390
+ status = sai_switch_api->get_switch_attribute (gSwitchId , 1 , &attr);
391
+ if (status == SAI_STATUS_SUCCESS)
392
+ {
393
+ const std::string &fieldName = " average_temperature" ;
394
+ values.emplace_back (fieldName, std::to_string (attr.value .s32 ));
395
+ m_asicSensorsTable->set (" " ,values);
396
+ }
397
+ else if (status == SAI_STATUS_NOT_SUPPORTED || status == SAI_STATUS_NOT_IMPLEMENTED)
398
+ {
399
+ m_sensorsAvgTempSupported = false ;
400
+ SWSS_LOG_INFO (" ASIC sensors : SAI_SWITCH_ATTR_AVERAGE_TEMP is not supported" );
401
+ }
402
+ else
403
+ {
404
+ m_sensorsAvgTempSupported = false ;
405
+ SWSS_LOG_ERROR (" ASIC sensors : failed to get SAI_SWITCH_ATTR_AVERAGE_TEMP: %d" , status);
406
+ }
407
+ }
408
+ }
409
+ }
410
+
411
+ void SwitchOrch::initSensorsTable ()
412
+ {
413
+ SWSS_LOG_ENTER ();
414
+
415
+ sai_attribute_t attr;
416
+ sai_status_t status;
417
+ std::vector<FieldValueTuple> values;
418
+
419
+ if (!m_numTempSensorsInitialized)
420
+ {
421
+ memset (&attr, 0 , sizeof (attr));
422
+ attr.id = SAI_SWITCH_ATTR_MAX_NUMBER_OF_TEMP_SENSORS;
423
+
424
+ status = sai_switch_api->get_switch_attribute (gSwitchId , 1 , &attr);
425
+ if (status == SAI_STATUS_SUCCESS)
426
+ {
427
+ m_numTempSensors = attr.value .u8 ;
428
+ m_numTempSensorsInitialized = true ;
429
+ }
430
+ else if (status == SAI_STATUS_NOT_SUPPORTED || status == SAI_STATUS_NOT_IMPLEMENTED)
431
+ {
432
+ m_numTempSensorsInitialized = true ;
433
+ SWSS_LOG_INFO (" ASIC sensors : SAI_SWITCH_ATTR_MAX_NUMBER_OF_TEMP_SENSORS is not supported" );
434
+ }
435
+ else
436
+ {
437
+ SWSS_LOG_ERROR (" ASIC sensors : failed to get SAI_SWITCH_ATTR_MAX_NUMBER_OF_TEMP_SENSORS: %d" , status);
438
+ }
439
+ }
440
+
441
+ if (m_numTempSensors)
442
+ {
443
+ std::vector<int32_t > temp_list (m_numTempSensors);
444
+
445
+ memset (&attr, 0 , sizeof (attr));
446
+ attr.id = SAI_SWITCH_ATTR_TEMP_LIST;
447
+ attr.value .s32list .count = m_numTempSensors;
448
+ attr.value .s32list .list = temp_list.data ();
449
+
450
+ status = sai_switch_api->get_switch_attribute (gSwitchId , 1 , &attr);
451
+ if (status == SAI_STATUS_SUCCESS)
452
+ {
453
+ for (size_t i = 0 ; i < attr.value .s32list .count ; i++) {
454
+ const std::string &fieldName = " temperature_" + std::to_string (i);
455
+ values.emplace_back (fieldName, std::to_string (0 ));
456
+ }
457
+ m_asicSensorsTable->set (" " ,values);
458
+ }
459
+ else
460
+ {
461
+ SWSS_LOG_ERROR (" ASIC sensors : failed to get SAI_SWITCH_ATTR_TEMP_LIST: %d" , status);
462
+ }
463
+ }
464
+
465
+ if (m_sensorsMaxTempSupported)
466
+ {
467
+ const std::string &fieldName = " maximum_temperature" ;
468
+ values.emplace_back (fieldName, std::to_string (0 ));
469
+ m_asicSensorsTable->set (" " ,values);
470
+ }
471
+
472
+ if (m_sensorsAvgTempSupported)
473
+ {
474
+ const std::string &fieldName = " average_temperature" ;
475
+ values.emplace_back (fieldName, std::to_string (0 ));
476
+ m_asicSensorsTable->set (" " ,values);
477
+ }
478
+ }
479
+
212
480
void SwitchOrch::set_switch_capability (const std::vector<FieldValueTuple>& values)
213
481
{
214
482
m_switchTable.set (" switch" , values);
0 commit comments