1717#define FABRIC_PORT_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS 10000
1818#define FABRIC_QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP " FABRIC_QUEUE_STAT_COUNTER"
1919#define FABRIC_QUEUE_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS 100000
20- #define FABRIC_PORT_TABLE_NAME " FABRIC_PORT_TABLE_NAME"
21- #define FABRIC_COUNTERS_QUEUE_NAME_MAP " FABRIC_COUNTERS_QUEUE_NAME_MAP"
22- #define FABRIC_COUNTERS_QUEUE_PORT_MAP " FABRIC_COUNTERS_QUEUE_PORT_MAP"
23- #define FABRIC_COUNTERS_QUEUE_INDEX_MAP " FABRIC_COUNTERS_QUEUE_INDEX_MAP"
24- #define FABRIC_COUNTERS_QUEUE_TYPE_MAP " FABRIC_COUNTERS_QUEUE_TYPE_MAP"
25- #define FABRIC_COUNTERS_PORT_NAME_MAP " FABRIC_COUNTERS_PORT_NAME_MAP"
20+ #define FABRIC_PORT_TABLE " FABRIC_PORT_TABLE"
2621
2722extern sai_object_id_t gSwitchId ;
2823extern sai_switch_api_t *sai_switch_api;
2924extern sai_port_api_t *sai_port_api;
30- extern sai_queue_api_t *sai_queue_api;
3125
3226const vector<sai_port_stat_t > port_stat_ids =
3327{
@@ -57,20 +51,18 @@ FabricPortsOrch::FabricPortsOrch(DBConnector *appl_db, vector<table_name_with_pr
5751 m_timer(new SelectableTimer(timespec { .tv_sec = FABRIC_POLLING_INTERVAL_DEFAULT, .tv_nsec = 0 }))
5852{
5953 SWSS_LOG_ENTER ();
54+
6055 SWSS_LOG_NOTICE ( " FabricPortsOrch constructor" );
6156
6257 m_state_db = shared_ptr<DBConnector>(new DBConnector (" STATE_DB" , 0 ));
63- m_stateTable = unique_ptr<Table>(new Table (m_state_db.get (), FABRIC_PORT_TABLE_NAME ));
58+ m_stateTable = unique_ptr<Table>(new Table (m_state_db.get (), FABRIC_PORT_TABLE ));
6459
6560 m_counter_db = shared_ptr<DBConnector>(new DBConnector (" COUNTERS_DB" , 0 ));
66- m_portNameQueueCounterTable = unique_ptr<Table>(new Table (m_counter_db.get (), FABRIC_COUNTERS_QUEUE_NAME_MAP));
67- m_queuePortCounterTable = unique_ptr<Table>(new Table (m_counter_db.get (), FABRIC_COUNTERS_QUEUE_PORT_MAP));
68- m_queueIndexCounterTable = unique_ptr<Table>(new Table (m_counter_db.get (), FABRIC_COUNTERS_QUEUE_INDEX_MAP));
69- m_queueTypeCounterTable = unique_ptr<Table>(new Table (m_counter_db.get (), FABRIC_COUNTERS_QUEUE_TYPE_MAP));
70- m_portNamePortCounterTable = unique_ptr<Table>(new Table (m_counter_db.get (), FABRIC_COUNTERS_PORT_NAME_MAP));
61+ m_laneQueueCounterTable = unique_ptr<Table>(new Table (m_counter_db.get (), COUNTERS_QUEUE_NAME_MAP));
62+ m_lanePortCounterTable = unique_ptr<Table>(new Table (m_counter_db.get (), COUNTERS_QUEUE_PORT_MAP));
7163
7264 m_flex_db = shared_ptr<DBConnector>(new DBConnector (" FLEX_COUNTER_DB" , 0 ));
73- m_flexCounterTable = unique_ptr<ProducerTable>(new ProducerTable (m_flex_db.get (), FABRIC_PORT_TABLE_NAME ));
65+ m_flexCounterTable = unique_ptr<ProducerTable>(new ProducerTable (m_flex_db.get (), FABRIC_PORT_TABLE ));
7466
7567 getFabricPortList ();
7668
@@ -82,7 +74,6 @@ FabricPortsOrch::FabricPortsOrch(DBConnector *appl_db, vector<table_name_with_pr
8274int FabricPortsOrch::getFabricPortList ()
8375{
8476 SWSS_LOG_ENTER ();
85- SWSS_LOG_NOTICE (" Get fabric port list done %d" , m_getFabricPortListDone == true ? 1 : 0 );
8677
8778 if (m_getFabricPortListDone) {
8879 return FABRIC_PORT_SUCCESS;
@@ -126,13 +117,14 @@ int FabricPortsOrch::getFabricPortList()
126117 }
127118 int lane = attr.value .u32list .list [0 ];
128119 m_fabricLanePortMap[lane] = fabric_port_list[i];
129- SWSS_LOG_NOTICE (" Get fabric port pid: %" PRIx64 " lanes: %d" , fabric_port_list[i], lane);
130120 }
131121
132122 generatePortStats ();
133123
134124 m_getFabricPortListDone = true ;
135125
126+ updateFabricPortState ();
127+
136128 return FABRIC_PORT_SUCCESS;
137129}
138130
@@ -143,127 +135,32 @@ bool FabricPortsOrch::allPortsReady()
143135
144136void FabricPortsOrch::generatePortStats ()
145137{
146- SWSS_LOG_NOTICE (" Generate fabric port stats" );
147-
148- vector<FieldValueTuple> portNamePortCounterMap;
149- for (auto p : m_fabricLanePortMap)
150- {
151- int lane = p.first ;
152- sai_object_id_t port = p.second ;
153-
154- std::ostringstream portName;
155- portName << " FabricPort" << lane;
156- portNamePortCounterMap.emplace_back (portName.str (), sai_serialize_object_id (port));
157-
158- // Install flex counters for port stats
159- std::unordered_set<std::string> counter_stats;
160- for (const auto & it: port_stat_ids)
161- {
162- counter_stats.emplace (sai_serialize_port_stat (it));
163- }
164- port_stat_manager.setCounterIdList (port, CounterType::PORT, counter_stats);
165- }
166- m_portNamePortCounterTable->set (" " , portNamePortCounterMap);
138+ // FIX_ME: This function installs flex counters for port stats
139+ // on fabric ports for fabric asics and voq asics (that connect
140+ // to fabric asics via fabric ports). These counters will be
141+ // installed in FLEX_COUNTER_DB, and queried by syncd and updated
142+ // to COUNTERS_DB.
143+ // However, currently BCM SAI doesn't update its code to query
144+ // port stats (metrics in list port_stat_ids) yet.
145+ // Also, BCM sets too low value for "Max logical port count" (256),
146+ // causing syncd to crash on voq asics that now include regular front
147+ // panel ports, fabric ports, and multiple logical ports.
148+ // So, this function will just do nothing for now, and we will readd
149+ // code to install port stats counters when BCM completely supports.
167150}
168151
169152void FabricPortsOrch::generateQueueStats ()
170153{
171154 if (m_isQueueStatsGenerated) return ;
172155 if (!m_getFabricPortListDone) return ;
173156
174- SWSS_LOG_NOTICE (" Generate queue map for fabric ports" );
175-
176- sai_status_t status;
177- sai_attribute_t attr;
178- sai_attribute_t queue_attrs[2 ];
179-
180- for (auto p : m_fabricLanePortMap)
181- {
182- int lane = p.first ;
183- sai_object_id_t port = p.second ;
184-
185- attr.id = SAI_PORT_ATTR_QOS_NUMBER_OF_QUEUES;
186- status = sai_port_api->get_port_attribute (port, 1 , &attr);
187- if (status != SAI_STATUS_SUCCESS)
188- {
189- throw runtime_error (" FabricPortsOrch get port queue number failure" );
190- }
191- int num_queues = attr.value .u32 ;
192-
193- if (num_queues > 0 )
194- {
195- vector<sai_object_id_t > m_queue_ids;
196- m_queue_ids.resize (num_queues);
197-
198- attr.id = SAI_PORT_ATTR_QOS_QUEUE_LIST;
199- attr.value .objlist .count = (uint32_t ) num_queues;
200- attr.value .objlist .list = m_queue_ids.data ();
201-
202- status = sai_port_api->get_port_attribute (port, 1 , &attr);
203- if (status != SAI_STATUS_SUCCESS)
204- {
205- throw runtime_error (" FabricPortsOrch get port queue list failure" );
206- }
207-
208- // Maintain queue map and install flex counters for queue stats
209- vector<FieldValueTuple> portNameQueueMap;
210- vector<FieldValueTuple> queuePortMap;
211- vector<FieldValueTuple> queueTypeMap;
212- vector<FieldValueTuple> queueIndexMap;
213-
214- for (size_t q = 0 ; q < m_queue_ids.size (); q ++)
215- {
216- std::ostringstream portName;
217- portName << " FabricPort" << lane << " :" << q;
218- const auto queue = sai_serialize_object_id (m_queue_ids[q]);
219-
220- portNameQueueMap.emplace_back (portName.str (), queue);
221- queuePortMap.emplace_back (queue, sai_serialize_object_id (port));
222-
223- queue_attrs[0 ].id = SAI_QUEUE_ATTR_TYPE;
224- queue_attrs[1 ].id = SAI_QUEUE_ATTR_INDEX;
225- status = sai_queue_api->get_queue_attribute (m_queue_ids[q], 2 , queue_attrs);
226- if (status == SAI_STATUS_SUCCESS)
227- {
228- string queueType;
229- string queueIndex;
230- switch (queue_attrs[0 ].value .s32 )
231- {
232- case SAI_QUEUE_TYPE_ALL:
233- queueType = " SAI_QUEUE_TYPE_ALL" ;
234- break ;
235- case SAI_QUEUE_TYPE_UNICAST:
236- queueType = " SAI_QUEUE_TYPE_UNICAST" ;
237- break ;
238- case SAI_QUEUE_TYPE_MULTICAST:
239- queueType = " SAI_QUEUE_TYPE_MULTICAST" ;
240- break ;
241- default :
242- throw runtime_error (" Got unsupported queue type" );
243- }
244- queueTypeMap.emplace_back (queue, queueType);
245- queueIndex = to_string (queue_attrs[1 ].value .u8 );
246- queueIndexMap.emplace_back (queue, queueIndex);
247- }
248- else
249- {
250- SWSS_LOG_NOTICE (" FabricPortsOrch cannot get fabric port queue type and index" );
251- }
252-
253- std::unordered_set<string> counter_stats;
254- for (const auto & it: queue_stat_ids)
255- {
256- counter_stats.emplace (sai_serialize_queue_stat (it));
257- }
258- queue_stat_manager.setCounterIdList (m_queue_ids[q], CounterType::QUEUE, counter_stats);
259- }
260-
261- m_portNameQueueCounterTable->set (" " , portNameQueueMap);
262- m_queuePortCounterTable->set (" " , queuePortMap);
263- m_queueTypeCounterTable->set (" " , queueTypeMap);
264- m_queueIndexCounterTable->set (" " , queueIndexMap);
265- }
266- }
157+ // FIX_ME: Similar to generatePortStats(), generateQueueStats() installs
158+ // flex counters for queue stats on fabric ports for fabric asics and voq asics.
159+ // However, currently BCM SAI doesn't fully support queue stats query.
160+ // Query on queue type and index is not supported for fabric asics while
161+ // voq asics are not completely supported.
162+ // So, this function will just do nothing for now, and we will readd
163+ // code to install queue stats counters when BCM completely supports.
267164
268165 m_isQueueStatsGenerated = true ;
269166}
@@ -299,14 +196,16 @@ void FabricPortsOrch::updateFabricPortState()
299196 status = sai_port_api->get_port_attribute (port, 1 , &attr);
300197 if (status != SAI_STATUS_SUCCESS)
301198 {
302- throw runtime_error (" FabricPortsOrch get port status failure" );
199+ // Port may not be ready for query
200+ SWSS_LOG_ERROR (" Failed to get fabric port (%d) status, rv:%d" , lane, status);
201+ return ;
303202 }
304203
305204 if (m_portStatus.find (lane) != m_portStatus.end () &&
306- m_portStatus[lane] != attr.value .booldata )
205+ m_portStatus[lane] && ! attr.value .booldata )
307206 {
308- m_portFlappingCount [lane] ++;
309- m_portFlappingSeenLastTime [lane] = now;
207+ m_portDownCount [lane] ++;
208+ m_portDownSeenLastTime [lane] = now;
310209 }
311210 m_portStatus[lane] = attr.value .booldata ;
312211
@@ -335,11 +234,11 @@ void FabricPortsOrch::updateFabricPortState()
335234 values.emplace_back (" REMOTE_MOD" , to_string (remote_peer));
336235 values.emplace_back (" REMOTE_PORT" , to_string (remote_port));
337236 }
338- if (m_portFlappingCount [lane] > 0 )
237+ if (m_portDownCount [lane] > 0 )
339238 {
340- values.emplace_back (" PORT_FLAPPING_COUNT " , to_string (m_portFlappingCount [lane]));
341- values.emplace_back (" PORT_FLAPPING_SEEN_LAST_TIME " ,
342- to_string (m_portFlappingSeenLastTime [lane]));
239+ values.emplace_back (" PORT_DOWN_COUNT " , to_string (m_portDownCount [lane]));
240+ values.emplace_back (" PORT_DOWN_SEEN_LAST_TIME " ,
241+ to_string (m_portDownSeenLastTime [lane]));
343242 }
344243 m_stateTable->set (key, values);
345244 }
@@ -355,6 +254,8 @@ void FabricPortsOrch::doTask(Consumer &consumer)
355254
356255void FabricPortsOrch::doTask (swss::SelectableTimer &timer)
357256{
257+ SWSS_LOG_ENTER ();
258+
358259 if (!m_getFabricPortListDone)
359260 {
360261 getFabricPortList ();
0 commit comments