@@ -14,6 +14,8 @@ extern sai_policer_api_t* sai_policer_api;
14
14
extern sai_switch_api_t * sai_switch_api;
15
15
extern sai_object_id_t gSwitchId ;
16
16
17
+ #define MLNX_PLATFORM_SUBSTRING " mlnx"
18
+
17
19
map<string, sai_meter_type_t > policer_meter_map = {
18
20
{" packets" , SAI_METER_TYPE_PACKETS},
19
21
{" bytes" , SAI_METER_TYPE_BYTES}
@@ -87,33 +89,37 @@ CoppOrch::CoppOrch(DBConnector *db, string tableName) :
87
89
Orch(db, tableName)
88
90
{
89
91
SWSS_LOG_ENTER ();
90
- initDefaultHostTable ();
92
+
93
+ initDefaultHostIntfTable ();
91
94
initDefaultTrapGroup ();
92
95
initDefaultTrapIds ();
93
96
};
94
97
95
- void CoppOrch::initDefaultHostTable ()
98
+ void CoppOrch::initDefaultHostIntfTable ()
96
99
{
97
100
SWSS_LOG_ENTER ();
98
101
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 ;
101
104
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 );
106
109
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 );
110
113
111
114
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 ());
113
116
if (status != SAI_STATUS_SUCCESS)
114
117
{
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" ;
116
120
}
121
+
122
+ SWSS_LOG_NOTICE (" Create default host interface table" );
117
123
}
118
124
119
125
void CoppOrch::initDefaultTrapIds ()
@@ -131,9 +137,19 @@ void CoppOrch::initDefaultTrapIds()
131
137
attr.value .oid = m_trap_group_map[default_trap_group];
132
138
trap_id_attrs.push_back (attr);
133
139
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
+
134
149
if (!applyAttributesToTrapIds (m_trap_group_map[default_trap_group], default_trap_ids, trap_id_attrs))
135
150
{
136
151
SWSS_LOG_ERROR (" Failed to set attributes to default trap IDs" );
152
+ throw " CoppOrch initialization failure" ;
137
153
}
138
154
139
155
SWSS_LOG_INFO (" Set attributes to default trap IDs" );
@@ -149,7 +165,8 @@ void CoppOrch::initDefaultTrapGroup()
149
165
sai_status_t status = sai_switch_api->get_switch_attribute (gSwitchId , 1 , &attr);
150
166
if (status != SAI_STATUS_SUCCESS)
151
167
{
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" ;
153
170
}
154
171
155
172
SWSS_LOG_INFO (" Get default trap group" );
@@ -173,52 +190,25 @@ bool CoppOrch::applyAttributesToTrapIds(sai_object_id_t trap_group_id,
173
190
const vector<sai_hostif_trap_type_t > &trap_id_list,
174
191
vector<sai_attribute_t > &trap_id_attribs)
175
192
{
176
- sai_status_t status;
177
-
178
- vector<sai_attribute_t > attrs (1 );
179
- attrs[0 ].id = SAI_HOSTIF_TRAP_ATTR_TRAP_TYPE;
180
-
181
193
for (auto trap_id : trap_id_list)
182
194
{
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)
201
207
{
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 ;
219
210
}
220
-
221
- m_syncdTrapIds[trap_id] = trap_group_id;
211
+ m_syncdTrapIds[trap_id] = hostif_trap_id;
222
212
}
223
213
224
214
return true ;
@@ -227,6 +217,7 @@ bool CoppOrch::applyAttributesToTrapIds(sai_object_id_t trap_group_id,
227
217
bool CoppOrch::applyTrapIds (sai_object_id_t trap_group, vector<string> &trap_id_name_list, vector<sai_attribute_t > &trap_id_attribs)
228
218
{
229
219
SWSS_LOG_ENTER ();
220
+
230
221
vector<sai_hostif_trap_type_t > trap_id_list;
231
222
232
223
getTrapIdList (trap_id_name_list, trap_id_list);
@@ -345,53 +336,58 @@ task_process_status CoppOrch::processCoppRule(Consumer& consumer)
345
336
{
346
337
for (auto i = kfvFieldsValues (tuple).begin (); i != kfvFieldsValues (tuple).end (); i++)
347
338
{
348
- SWSS_LOG_DEBUG (" field:%s, value:%s" , fvField (*i).c_str (), fvValue (*i).c_str ());
349
339
sai_attribute_t attr;
340
+
350
341
if (fvField (*i) == copp_trap_id_list)
351
342
{
352
343
trap_id_list = tokenize (fvValue (*i), list_item_delimiter);
353
344
}
354
345
else if (fvField (*i) == copp_queue_field)
355
346
{
356
- queue_ind = fvValue (*i);
357
- SWSS_LOG_DEBUG (" queue data:%s" , queue_ind.c_str ());
358
347
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) );
360
349
trap_gr_attribs.push_back (attr);
361
350
}
362
351
//
363
- // Trap id related attributes
352
+ // Trap related attributes
364
353
//
365
354
else if (fvField (*i) == copp_trap_action_field)
366
355
{
367
- SWSS_LOG_DEBUG (" trap action:%s" , fvValue (*i).c_str ());
368
356
sai_packet_action_t trap_action = packet_action_map.at (fvValue (*i));
369
357
attr.id = SAI_HOSTIF_TRAP_ATTR_PACKET_ACTION;
370
358
attr.value .s32 = trap_action;
371
359
trap_id_attribs.push_back (attr);
372
360
}
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 = (uint32_t )stoul (fvValue (*i));
369
+ trap_id_attribs.push_back (attr);
370
+ }
371
+ }
373
372
//
374
373
// process policer attributes
375
374
//
376
375
else if (fvField (*i) == copp_policer_meter_type_field)
377
376
{
378
- SWSS_LOG_DEBUG (" policer meter:%s" , fvValue (*i).c_str ());
379
377
sai_meter_type_t meter_value = policer_meter_map.at (fvValue (*i));
380
378
attr.id = SAI_POLICER_ATTR_METER_TYPE;
381
379
attr.value .s32 = meter_value;
382
380
policer_attribs.push_back (attr);
383
381
}
384
382
else if (fvField (*i) == copp_policer_mode_field)
385
383
{
386
- SWSS_LOG_DEBUG (" policer mode:%s" , fvValue (*i).c_str ());
387
384
sai_policer_mode_t mode = policer_mode_map.at (fvValue (*i));
388
385
attr.id = SAI_POLICER_ATTR_MODE;
389
386
attr.value .s32 = mode;
390
387
policer_attribs.push_back (attr);
391
388
}
392
389
else if (fvField (*i) == copp_policer_color_field)
393
390
{
394
- SWSS_LOG_DEBUG (" policer color mode:%s" , fvValue (*i).c_str ());
395
391
sai_policer_color_source_t color = policer_color_aware_map.at (fvValue (*i));
396
392
attr.id = SAI_POLICER_ATTR_COLOR_SOURCE;
397
393
attr.value .s32 = color;
@@ -402,48 +398,41 @@ task_process_status CoppOrch::processCoppRule(Consumer& consumer)
402
398
attr.id = SAI_POLICER_ATTR_CBS;
403
399
attr.value .u64 = stoul (fvValue (*i));
404
400
policer_attribs.push_back (attr);
405
- SWSS_LOG_DEBUG (" obtained cbs:%lu" , attr.value .u64 );
406
401
}
407
402
else if (fvField (*i) == copp_policer_cir_field)
408
403
{
409
404
attr.id = SAI_POLICER_ATTR_CIR;
410
405
attr.value .u64 = stoul (fvValue (*i));
411
406
policer_attribs.push_back (attr);
412
- SWSS_LOG_DEBUG (" obtained cir:%lu" , attr.value .u64 );
413
407
}
414
408
else if (fvField (*i) == copp_policer_pbs_field)
415
409
{
416
410
attr.id = SAI_POLICER_ATTR_PBS;
417
411
attr.value .u64 = stoul (fvValue (*i));
418
412
policer_attribs.push_back (attr);
419
- SWSS_LOG_DEBUG (" obtained pbs:%lu" , attr.value .u64 );
420
413
}
421
414
else if (fvField (*i) == copp_policer_pir_field)
422
415
{
423
416
attr.id = SAI_POLICER_ATTR_PIR;
424
417
attr.value .u64 = stoul (fvValue (*i));
425
418
policer_attribs.push_back (attr);
426
- SWSS_LOG_DEBUG (" obtained pir:%lu" , attr.value .u64 );
427
419
}
428
420
else if (fvField (*i) == copp_policer_action_green_field)
429
421
{
430
- SWSS_LOG_DEBUG (" green action:%s" , queue_ind.c_str ());
431
422
sai_packet_action_t policer_action = packet_action_map.at (fvValue (*i));
432
423
attr.id = SAI_POLICER_ATTR_GREEN_PACKET_ACTION;
433
424
attr.value .s32 = policer_action;
434
425
policer_attribs.push_back (attr);
435
426
}
436
427
else if (fvField (*i) == copp_policer_action_red_field)
437
428
{
438
- SWSS_LOG_DEBUG (" red action:%s" , queue_ind.c_str ());
439
429
sai_packet_action_t policer_action = packet_action_map.at (fvValue (*i));
440
430
attr.id = SAI_POLICER_ATTR_RED_PACKET_ACTION;
441
431
attr.value .s32 = policer_action;
442
432
policer_attribs.push_back (attr);
443
433
}
444
434
else if (fvField (*i) == copp_policer_action_yellow_field)
445
435
{
446
- SWSS_LOG_DEBUG (" yellowaction:%s" , queue_ind.c_str ());
447
436
sai_packet_action_t policer_action = packet_action_map.at (fvValue (*i));
448
437
attr.id = SAI_POLICER_ATTR_YELLOW_PACKET_ACTION;
449
438
attr.value .s32 = policer_action;
0 commit comments