@@ -14,6 +14,8 @@ extern sai_policer_api_t* sai_policer_api;
1414extern sai_switch_api_t * sai_switch_api;
1515extern sai_object_id_t gSwitchId ;
1616
17+ #define MLNX_PLATFORM_SUBSTRING " mlnx"
18+
1719map<string, sai_meter_type_t > policer_meter_map = {
1820 {" packets" , SAI_METER_TYPE_PACKETS},
1921 {" bytes" , SAI_METER_TYPE_BYTES}
@@ -87,33 +89,37 @@ CoppOrch::CoppOrch(DBConnector *db, string tableName) :
8789 Orch(db, tableName)
8890{
8991 SWSS_LOG_ENTER ();
90- initDefaultHostTable ();
92+
93+ initDefaultHostIntfTable ();
9194 initDefaultTrapGroup ();
9295 initDefaultTrapIds ();
9396};
9497
95- void CoppOrch::initDefaultHostTable ()
98+ void CoppOrch::initDefaultHostIntfTable ()
9699{
97100 SWSS_LOG_ENTER ();
98101
99- sai_object_id_t host_table_entry[ 4 ] ;
100- vector<sai_attribute_t > sai_if_channel_attrs ;
102+ sai_object_id_t default_hostif_table_id ;
103+ vector<sai_attribute_t > attrs ;
101104
102- sai_attribute_t sai_if_channel_attr ;
103- sai_if_channel_attr .id = SAI_HOSTIF_TABLE_ENTRY_ATTR_TYPE;
104- sai_if_channel_attr .value .s32 = SAI_HOSTIF_TABLE_ENTRY_TYPE_WILDCARD;
105- sai_if_channel_attrs .push_back (sai_if_channel_attr );
105+ sai_attribute_t attr ;
106+ attr .id = SAI_HOSTIF_TABLE_ENTRY_ATTR_TYPE;
107+ attr .value .s32 = SAI_HOSTIF_TABLE_ENTRY_TYPE_WILDCARD;
108+ attrs .push_back (attr );
106109
107- sai_if_channel_attr .id = SAI_HOSTIF_TABLE_ENTRY_ATTR_CHANNEL_TYPE;
108- sai_if_channel_attr .value .s32 = SAI_HOSTIF_TABLE_ENTRY_CHANNEL_TYPE_NETDEV_PHYSICAL_PORT;
109- sai_if_channel_attrs .push_back (sai_if_channel_attr );
110+ attr .id = SAI_HOSTIF_TABLE_ENTRY_ATTR_CHANNEL_TYPE;
111+ attr .value .s32 = SAI_HOSTIF_TABLE_ENTRY_CHANNEL_TYPE_NETDEV_PHYSICAL_PORT;
112+ attrs .push_back (attr );
110113
111114 sai_status_t status = sai_hostif_api->create_hostif_table_entry (
112- &host_table_entry[ 0 ] , gSwitchId , (uint32_t )sai_if_channel_attrs .size (), sai_if_channel_attrs .data ());
115+ &default_hostif_table_id , gSwitchId , (uint32_t )attrs .size (), attrs .data ());
113116 if (status != SAI_STATUS_SUCCESS)
114117 {
115- SWSS_LOG_ERROR (" Failed to create hostif table entry, rc=%d" , status);
118+ SWSS_LOG_ERROR (" Failed to create default host interface table, rv:%d" , status);
119+ throw " CoppOrch initialization failure" ;
116120 }
121+
122+ SWSS_LOG_NOTICE (" Create default host interface table" );
117123}
118124
119125void CoppOrch::initDefaultTrapIds ()
@@ -131,9 +137,19 @@ void CoppOrch::initDefaultTrapIds()
131137 attr.value .oid = m_trap_group_map[default_trap_group];
132138 trap_id_attrs.push_back (attr);
133139
140+ /* Mellanox platform doesn't support trap priority setting */
141+ char *platform = getenv (" platform" );
142+ if (!platform || !strstr (platform, MLNX_PLATFORM_SUBSTRING))
143+ {
144+ attr.id = SAI_HOSTIF_TRAP_ATTR_TRAP_PRIORITY;
145+ attr.value .u32 = 0 ;
146+ trap_id_attrs.push_back (attr);
147+ }
148+
134149 if (!applyAttributesToTrapIds (m_trap_group_map[default_trap_group], default_trap_ids, trap_id_attrs))
135150 {
136151 SWSS_LOG_ERROR (" Failed to set attributes to default trap IDs" );
152+ throw " CoppOrch initialization failure" ;
137153 }
138154
139155 SWSS_LOG_INFO (" Set attributes to default trap IDs" );
@@ -149,7 +165,8 @@ void CoppOrch::initDefaultTrapGroup()
149165 sai_status_t status = sai_switch_api->get_switch_attribute (gSwitchId , 1 , &attr);
150166 if (status != SAI_STATUS_SUCCESS)
151167 {
152- SWSS_LOG_ERROR (" Failed to get default trap group, rc=%d" , status);
168+ SWSS_LOG_ERROR (" Failed to get default trap group, rv:%d" , status);
169+ throw " CoppOrch initialization failure" ;
153170 }
154171
155172 SWSS_LOG_INFO (" Get default trap group" );
@@ -173,52 +190,25 @@ bool CoppOrch::applyAttributesToTrapIds(sai_object_id_t trap_group_id,
173190 const vector<sai_hostif_trap_type_t > &trap_id_list,
174191 vector<sai_attribute_t > &trap_id_attribs)
175192{
176- sai_status_t status;
177-
178- vector<sai_attribute_t > attrs (1 );
179- attrs[0 ].id = SAI_HOSTIF_TRAP_ATTR_TRAP_TYPE;
180-
181193 for (auto trap_id : trap_id_list)
182194 {
183- auto found = m_trap_type_map.find (trap_id);
184- if (found == m_trap_type_map.end ())
185- {
186- // Reuse the first element in attrs list
187- attrs.resize (1 );
188- attrs[0 ].value .s32 = trap_id;
189- attrs.insert (attrs.end (), trap_id_attribs.begin (), trap_id_attribs.end ());
190-
191- sai_object_id_t hostif_trap_id;
192- status = sai_hostif_api->create_hostif_trap (&hostif_trap_id, gSwitchId , (uint32_t )attrs.size (), attrs.data ());
193- if (status != SAI_STATUS_SUCCESS)
194- {
195- SWSS_LOG_ERROR (" Failed to create trap %d, rc=%d" , trap_id, status);
196- return false ;
197- }
198- m_syncdTrapIds[trap_id] = hostif_trap_id;
199- }
200- else
195+ sai_attribute_t attr;
196+ vector<sai_attribute_t > attrs;
197+
198+ attr.id = SAI_HOSTIF_TRAP_ATTR_TRAP_TYPE;
199+ attr.value .s32 = trap_id;
200+ attrs.push_back (attr);
201+
202+ attrs.insert (attrs.end (), trap_id_attribs.begin (), trap_id_attribs.end ());
203+
204+ sai_object_id_t hostif_trap_id;
205+ sai_status_t status = sai_hostif_api->create_hostif_trap (&hostif_trap_id, gSwitchId , (uint32_t )attrs.size (), attrs.data ());
206+ if (status != SAI_STATUS_SUCCESS)
201207 {
202- // Set caller provided attributes
203- for (auto attr : trap_id_attribs)
204- {
205- status = sai_hostif_api->set_hostif_trap_attribute (trap_id, &attr);
206- if (status != SAI_STATUS_SUCCESS)
207- {
208- SWSS_LOG_ERROR (" Failed to set attribute %d to trap %d, rc=%d" , attr.id , trap_id, status);
209- return false ;
210- }
211- }
212- // Set the trap group attribute
213- status = sai_hostif_api->set_hostif_trap_attribute (trap_id, &attrs[1 ]);
214- if (status != SAI_STATUS_SUCCESS)
215- {
216- SWSS_LOG_ERROR (" Failed to set trap group attribute to trap %d, rc=%d" , trap_id, status);
217- return false ;
218- }
208+ SWSS_LOG_ERROR (" Failed to create trap %d, rv:%d" , trap_id, status);
209+ return false ;
219210 }
220-
221- m_syncdTrapIds[trap_id] = trap_group_id;
211+ m_syncdTrapIds[trap_id] = hostif_trap_id;
222212 }
223213
224214 return true ;
@@ -227,6 +217,7 @@ bool CoppOrch::applyAttributesToTrapIds(sai_object_id_t trap_group_id,
227217bool CoppOrch::applyTrapIds (sai_object_id_t trap_group, vector<string> &trap_id_name_list, vector<sai_attribute_t > &trap_id_attribs)
228218{
229219 SWSS_LOG_ENTER ();
220+
230221 vector<sai_hostif_trap_type_t > trap_id_list;
231222
232223 getTrapIdList (trap_id_name_list, trap_id_list);
@@ -345,53 +336,58 @@ task_process_status CoppOrch::processCoppRule(Consumer& consumer)
345336 {
346337 for (auto i = kfvFieldsValues (tuple).begin (); i != kfvFieldsValues (tuple).end (); i++)
347338 {
348- SWSS_LOG_DEBUG (" field:%s, value:%s" , fvField (*i).c_str (), fvValue (*i).c_str ());
349339 sai_attribute_t attr;
340+
350341 if (fvField (*i) == copp_trap_id_list)
351342 {
352343 trap_id_list = tokenize (fvValue (*i), list_item_delimiter);
353344 }
354345 else if (fvField (*i) == copp_queue_field)
355346 {
356- queue_ind = fvValue (*i);
357- SWSS_LOG_DEBUG (" queue data:%s" , queue_ind.c_str ());
358347 attr.id = SAI_HOSTIF_TRAP_GROUP_ATTR_QUEUE;
359- attr.value .u32 = (uint32_t )stoul (queue_ind );
348+ attr.value .u32 = (uint32_t )stoul (fvValue (*i) );
360349 trap_gr_attribs.push_back (attr);
361350 }
362351 //
363- // Trap id related attributes
352+ // Trap related attributes
364353 //
365354 else if (fvField (*i) == copp_trap_action_field)
366355 {
367- SWSS_LOG_DEBUG (" trap action:%s" , fvValue (*i).c_str ());
368356 sai_packet_action_t trap_action = packet_action_map.at (fvValue (*i));
369357 attr.id = SAI_HOSTIF_TRAP_ATTR_PACKET_ACTION;
370358 attr.value .s32 = trap_action;
371359 trap_id_attribs.push_back (attr);
372360 }
361+ else if (fvField (*i) == copp_trap_priority_field)
362+ {
363+ /* Mellanox platform doesn't support trap priority setting */
364+ char *platform = getenv (" platform" );
365+ if (!platform || !strstr (platform, MLNX_PLATFORM_SUBSTRING))
366+ {
367+ attr.id = SAI_HOSTIF_TRAP_ATTR_TRAP_PRIORITY,
368+ attr.value .u32 = stoul (fvValue (*i));
369+ trap_id_attribs.push_back (attr);
370+ }
371+ }
373372 //
374373 // process policer attributes
375374 //
376375 else if (fvField (*i) == copp_policer_meter_type_field)
377376 {
378- SWSS_LOG_DEBUG (" policer meter:%s" , fvValue (*i).c_str ());
379377 sai_meter_type_t meter_value = policer_meter_map.at (fvValue (*i));
380378 attr.id = SAI_POLICER_ATTR_METER_TYPE;
381379 attr.value .s32 = meter_value;
382380 policer_attribs.push_back (attr);
383381 }
384382 else if (fvField (*i) == copp_policer_mode_field)
385383 {
386- SWSS_LOG_DEBUG (" policer mode:%s" , fvValue (*i).c_str ());
387384 sai_policer_mode_t mode = policer_mode_map.at (fvValue (*i));
388385 attr.id = SAI_POLICER_ATTR_MODE;
389386 attr.value .s32 = mode;
390387 policer_attribs.push_back (attr);
391388 }
392389 else if (fvField (*i) == copp_policer_color_field)
393390 {
394- SWSS_LOG_DEBUG (" policer color mode:%s" , fvValue (*i).c_str ());
395391 sai_policer_color_source_t color = policer_color_aware_map.at (fvValue (*i));
396392 attr.id = SAI_POLICER_ATTR_COLOR_SOURCE;
397393 attr.value .s32 = color;
@@ -402,48 +398,41 @@ task_process_status CoppOrch::processCoppRule(Consumer& consumer)
402398 attr.id = SAI_POLICER_ATTR_CBS;
403399 attr.value .u64 = stoul (fvValue (*i));
404400 policer_attribs.push_back (attr);
405- SWSS_LOG_DEBUG (" obtained cbs:%lu" , attr.value .u64 );
406401 }
407402 else if (fvField (*i) == copp_policer_cir_field)
408403 {
409404 attr.id = SAI_POLICER_ATTR_CIR;
410405 attr.value .u64 = stoul (fvValue (*i));
411406 policer_attribs.push_back (attr);
412- SWSS_LOG_DEBUG (" obtained cir:%lu" , attr.value .u64 );
413407 }
414408 else if (fvField (*i) == copp_policer_pbs_field)
415409 {
416410 attr.id = SAI_POLICER_ATTR_PBS;
417411 attr.value .u64 = stoul (fvValue (*i));
418412 policer_attribs.push_back (attr);
419- SWSS_LOG_DEBUG (" obtained pbs:%lu" , attr.value .u64 );
420413 }
421414 else if (fvField (*i) == copp_policer_pir_field)
422415 {
423416 attr.id = SAI_POLICER_ATTR_PIR;
424417 attr.value .u64 = stoul (fvValue (*i));
425418 policer_attribs.push_back (attr);
426- SWSS_LOG_DEBUG (" obtained pir:%lu" , attr.value .u64 );
427419 }
428420 else if (fvField (*i) == copp_policer_action_green_field)
429421 {
430- SWSS_LOG_DEBUG (" green action:%s" , queue_ind.c_str ());
431422 sai_packet_action_t policer_action = packet_action_map.at (fvValue (*i));
432423 attr.id = SAI_POLICER_ATTR_GREEN_PACKET_ACTION;
433424 attr.value .s32 = policer_action;
434425 policer_attribs.push_back (attr);
435426 }
436427 else if (fvField (*i) == copp_policer_action_red_field)
437428 {
438- SWSS_LOG_DEBUG (" red action:%s" , queue_ind.c_str ());
439429 sai_packet_action_t policer_action = packet_action_map.at (fvValue (*i));
440430 attr.id = SAI_POLICER_ATTR_RED_PACKET_ACTION;
441431 attr.value .s32 = policer_action;
442432 policer_attribs.push_back (attr);
443433 }
444434 else if (fvField (*i) == copp_policer_action_yellow_field)
445435 {
446- SWSS_LOG_DEBUG (" yellowaction:%s" , queue_ind.c_str ());
447436 sai_packet_action_t policer_action = packet_action_map.at (fvValue (*i));
448437 attr.id = SAI_POLICER_ATTR_YELLOW_PACKET_ACTION;
449438 attr.value .s32 = policer_action;
0 commit comments