@@ -19,6 +19,7 @@ extern sai_buffer_api_t *sai_buffer_api;
1919extern PortsOrch *gPortsOrch ;
2020extern Directory<Orch*> gDirectory ;
2121extern sai_object_id_t gSwitchId ;
22+ extern string gMySwitchType ;
2223
2324#define BUFFER_POOL_WATERMARK_FLEX_STAT_COUNTER_POLL_MSECS " 60000"
2425
@@ -103,16 +104,32 @@ void BufferOrch::initBufferReadyLists(DBConnector *applDb, DBConnector *confDb)
103104 Table pg_table (applDb, APP_BUFFER_PG_TABLE_NAME);
104105 initBufferReadyList (pg_table, false );
105106
106- Table queue_table (applDb, APP_BUFFER_QUEUE_TABLE_NAME);
107- initBufferReadyList (queue_table, false );
107+ if (gMySwitchType == " voq" )
108+ {
109+ Table queue_table (applDb, APP_BUFFER_QUEUE_TABLE_NAME);
110+ initVoqBufferReadyList (queue_table, false );
111+ }
112+ else
113+ {
114+ Table queue_table (applDb, APP_BUFFER_QUEUE_TABLE_NAME);
115+ initBufferReadyList (queue_table, false );
116+ }
108117 }
109118 else
110119 {
111120 Table pg_table (confDb, CFG_BUFFER_PG_TABLE_NAME);
112121 initBufferReadyList (pg_table, true );
113122
114- Table queue_table (confDb, CFG_BUFFER_QUEUE_TABLE_NAME);
115- initBufferReadyList (queue_table, true );
123+ if (gMySwitchType == " voq" )
124+ {
125+ Table queue_table (confDb, CFG_BUFFER_QUEUE_TABLE_NAME);
126+ initVoqBufferReadyList (queue_table, true );
127+ }
128+ else
129+ {
130+ Table queue_table (confDb, CFG_BUFFER_QUEUE_TABLE_NAME);
131+ initBufferReadyList (queue_table, true );
132+ }
116133 }
117134}
118135
@@ -149,6 +166,38 @@ void BufferOrch::initBufferReadyList(Table& table, bool isConfigDb)
149166 }
150167}
151168
169+ void BufferOrch::initVoqBufferReadyList (Table& table, bool isConfigDb)
170+ {
171+ SWSS_LOG_ENTER ();
172+
173+ std::vector<std::string> keys;
174+ table.getKeys (keys);
175+
176+ const char dbKeyDelimiter = (isConfigDb ? config_db_key_delimiter : delimiter);
177+
178+ // populate the lists with buffer configuration information
179+ for (const auto & key: keys)
180+ {
181+ auto &&tokens = tokenize (key, dbKeyDelimiter);
182+ if (tokens.size () != 4 )
183+ {
184+ SWSS_LOG_ERROR (" Wrong format of a table '%s' key '%s'. Skip it" , table.getTableName ().c_str (), key.c_str ());
185+ continue ;
186+ }
187+
188+ // We need transform the key from config db format to appl db format
189+ auto appldb_key = tokens[0 ] + config_db_key_delimiter + tokens[1 ] + config_db_key_delimiter + tokens[2 ] + delimiter + tokens[3 ];
190+ m_ready_list[appldb_key] = false ;
191+
192+ auto &&port_names = tokenize (tokens[0 ] + config_db_key_delimiter + tokens[1 ] + config_db_key_delimiter + tokens[2 ], list_item_delimiter);
193+ for (const auto & port_name: port_names)
194+ {
195+ SWSS_LOG_INFO (" Item %s has been inserted into ready list" , appldb_key.c_str ());
196+ m_port_ready_list_ref[port_name].push_back (appldb_key);
197+ }
198+ }
199+ }
200+
152201void BufferOrch::initBufferConstants ()
153202{
154203 sai_status_t status;
@@ -712,7 +761,8 @@ task_process_status BufferOrch::processBufferProfile(KeyOpFieldsValuesTuple &tup
712761}
713762
714763/*
715- Input sample "BUFFER_QUEUE|Ethernet4,Ethernet45|10-15"
764+ Input sample "BUFFER_QUEUE|Ethernet4,Ethernet45|10-15" or
765+ "BUFFER_QUEUE|STG01-0101-0400-01T2-LC6|ASIC0|Ethernet4|10-15"
716766*/
717767task_process_status BufferOrch::processQueue (KeyOpFieldsValuesTuple &tuple)
718768{
@@ -727,15 +777,35 @@ task_process_status BufferOrch::processQueue(KeyOpFieldsValuesTuple &tuple)
727777
728778 SWSS_LOG_DEBUG (" Processing:%s" , key.c_str ());
729779 tokens = tokenize (key, delimiter);
730- if (tokens.size () != 2 )
780+
781+ vector<string> port_names;
782+ if (gMySwitchType == " voq" )
731783 {
732- SWSS_LOG_ERROR (" malformed key:%s. Must contain 2 tokens" , key.c_str ());
733- return task_process_status::task_invalid_entry;
784+ if (tokens.size () != 4 )
785+ {
786+ SWSS_LOG_ERROR (" malformed key:%s. Must contain 4 tokens" , key.c_str ());
787+ return task_process_status::task_invalid_entry;
788+ }
789+
790+ port_names = tokenize (tokens[0 ] + config_db_key_delimiter + tokens[1 ] + config_db_key_delimiter + tokens[2 ], list_item_delimiter);
791+ if (!parseIndexRange (tokens[3 ], range_low, range_high))
792+ {
793+ return task_process_status::task_invalid_entry;
794+ }
734795 }
735- vector<string> port_names = tokenize (tokens[0 ], list_item_delimiter);
736- if (!parseIndexRange (tokens[1 ], range_low, range_high))
796+ else
737797 {
738- return task_process_status::task_invalid_entry;
798+ if (tokens.size () != 2 )
799+ {
800+ SWSS_LOG_ERROR (" malformed key:%s. Must contain 2 tokens" , key.c_str ());
801+ return task_process_status::task_invalid_entry;
802+ }
803+
804+ port_names = tokenize (tokens[0 ], list_item_delimiter);
805+ if (!parseIndexRange (tokens[1 ], range_low, range_high))
806+ {
807+ return task_process_status::task_invalid_entry;
808+ }
739809 }
740810
741811 if (op == SET_COMMAND)
@@ -792,20 +862,35 @@ task_process_status BufferOrch::processQueue(KeyOpFieldsValuesTuple &tuple)
792862 for (size_t ind = range_low; ind <= range_high; ind++)
793863 {
794864 SWSS_LOG_DEBUG (" processing queue:%zd" , ind);
795- if (port.m_queue_ids .size () <= ind)
865+ sai_object_id_t queue_id;
866+
867+ if (gMySwitchType == " voq" )
796868 {
797- SWSS_LOG_ERROR (" Invalid queue index specified:%zd" , ind);
798- return task_process_status::task_invalid_entry;
799- }
800- if (port.m_queue_lock [ind])
869+ std :: vector<sai_object_id_t > queue_ids = gPortsOrch ->getPortVoQIds (port);
870+ if (queue_ids.size () <= ind)
871+ {
872+ SWSS_LOG_ERROR (" Invalid voq index specified:%zd" , ind);
873+ return task_process_status::task_invalid_entry;
874+ }
875+ queue_id = queue_ids[ind];
876+ }
877+ else
801878 {
802- SWSS_LOG_WARN (" Queue %zd on port %s is locked, will retry" , ind, port_name.c_str ());
803- return task_process_status::task_need_retry;
879+ if (port.m_queue_ids .size () <= ind)
880+ {
881+ SWSS_LOG_ERROR (" Invalid queue index specified:%zd" , ind);
882+ return task_process_status::task_invalid_entry;
883+ }
884+ if (port.m_queue_lock [ind])
885+ {
886+ SWSS_LOG_WARN (" Queue %zd on port %s is locked, will retry" , ind, port_name.c_str ());
887+ return task_process_status::task_need_retry;
888+ }
889+ queue_id = port.m_queue_ids [ind];
804890 }
891+
805892 if (need_update_sai)
806893 {
807- sai_object_id_t queue_id;
808- queue_id = port.m_queue_ids [ind];
809894 SWSS_LOG_DEBUG (" Applying buffer profile:0x%" PRIx64 " to queue index:%zd, queue sai_id:0x%" PRIx64, sai_buffer_profile, ind, queue_id);
810895 sai_status_t sai_status = sai_queue_api->set_queue_attribute (queue_id, &attr);
811896 if (sai_status != SAI_STATUS_SUCCESS)
@@ -1258,7 +1343,15 @@ void BufferOrch::doTask(Consumer &consumer)
12581343{
12591344 SWSS_LOG_ENTER ();
12601345
1261- if (!gPortsOrch ->isConfigDone ())
1346+ if (gMySwitchType == " voq" )
1347+ {
1348+ if (!gPortsOrch ->isInitDone ())
1349+ {
1350+ SWSS_LOG_INFO (" Buffer task for %s can't be executed ahead of port config done" , consumer.getTableName ().c_str ());
1351+ return ;
1352+ }
1353+ }
1354+ else if (!gPortsOrch ->isConfigDone ())
12621355 {
12631356 SWSS_LOG_INFO (" Buffer task for %s can't be executed ahead of port config done" , consumer.getTableName ().c_str ());
12641357 return ;
0 commit comments