@@ -152,10 +152,6 @@ void DashAclGroupMgr::init(DashAclGroup& group)
152
152
SWSS_LOG_ENTER ();
153
153
group.m_dash_acl_group_id = SAI_NULL_OBJECT_ID;
154
154
155
- for (auto & rule: group.m_dash_acl_rule_table )
156
- {
157
- rule.second .m_dash_acl_rule_id = SAI_NULL_OBJECT_ID;
158
- }
159
155
}
160
156
161
157
void DashAclGroupMgr::create (DashAclGroup& group)
@@ -216,6 +212,7 @@ void DashAclGroupMgr::remove(DashAclGroup& group)
216
212
217
213
CrmResourceType crm_rtype = (group.m_ip_version == SAI_IP_ADDR_FAMILY_IPV4) ?
218
214
CrmResourceType::CRM_DASH_IPV4_ACL_GROUP : CrmResourceType::CRM_DASH_IPV6_ACL_GROUP;
215
+ // Will also delete/zero out ACL rule count for this group, no need to do so separately
219
216
gCrmOrch ->decCrmDashAclUsedCounter (crm_rtype, group.m_dash_acl_group_id );
220
217
221
218
group.m_dash_acl_group_id = SAI_NULL_OBJECT_ID;
@@ -234,12 +231,6 @@ task_process_status DashAclGroupMgr::remove(const string& group_id)
234
231
235
232
auto & group = group_it->second ;
236
233
237
- if (!group.m_dash_acl_rule_table .empty ())
238
- {
239
- SWSS_LOG_ERROR (" ACL group %s still has %zu rules" , group_id.c_str (), group.m_dash_acl_rule_table .size ());
240
- return task_need_retry;
241
- }
242
-
243
234
if (isBound (group))
244
235
{
245
236
SWSS_LOG_ERROR (" ACL group %s still has %zu references" , group_id.c_str (), group.m_in_tables .size () + group.m_out_tables .size ());
@@ -249,6 +240,7 @@ task_process_status DashAclGroupMgr::remove(const string& group_id)
249
240
remove (group);
250
241
251
242
m_groups_table.erase (group_id);
243
+ detachTags (group_id, group.m_tags );
252
244
SWSS_LOG_INFO (" Removed ACL group %s" , group_id.c_str ());
253
245
254
246
return task_success;
@@ -261,121 +253,6 @@ bool DashAclGroupMgr::exists(const string& group_id) const
261
253
return m_groups_table.find (group_id) != m_groups_table.end ();
262
254
}
263
255
264
- task_process_status DashAclGroupMgr::onUpdate (const string& group_id, const string& tag_id, const DashTag& tag)
265
- {
266
- SWSS_LOG_ENTER ();
267
-
268
- auto group_it = m_groups_table.find (group_id);
269
- if (group_it == m_groups_table.end ())
270
- {
271
- return task_success;
272
- }
273
-
274
- auto & group = group_it->second ;
275
- if (isBound (group))
276
- {
277
- // If the group is bound to at least one ENI refresh the full group to update the affected rules.
278
- // When the group is bound to the ENI we need to make sure that the update of the affected rules will be atomic.
279
- SWSS_LOG_INFO (" Update full ACL group %s" , group_id.c_str ());
280
-
281
- return refreshAclGroupFull (group_id);
282
- }
283
-
284
- // If the group is not bound to ENI update the rule immediately.
285
- SWSS_LOG_INFO (" Update ACL group %s" , group_id.c_str ());
286
- for (auto & rule_it: group.m_dash_acl_rule_table )
287
- {
288
- auto & rule_id = rule_it.first ;
289
- auto & rule_info = rule_it.second ;
290
- if (rule_info.isTagUsed (tag_id))
291
- {
292
- DashAclRule rule;
293
- bool found = fetchRule (group_id, rule_id, rule);
294
- if (!found)
295
- {
296
- SWSS_LOG_ERROR (" Failed to fetch group %s rule %s" , group_id.c_str (), rule_id.c_str ());
297
- return task_failed;
298
- }
299
- removeRule (group, rule_info);
300
- rule_info = createRule (group, rule);
301
- }
302
- }
303
-
304
- return task_success;
305
- }
306
-
307
- task_process_status DashAclGroupMgr::refreshAclGroupFull (const string &group_id)
308
- {
309
- SWSS_LOG_ENTER ();
310
-
311
- auto & group = m_groups_table[group_id];
312
-
313
- DashAclGroup new_group = group;
314
- init (new_group);
315
- create (new_group);
316
-
317
- for (auto & rule_it: new_group.m_dash_acl_rule_table )
318
- {
319
- auto & rule_id = rule_it.first ;
320
- auto & rule_info = rule_it.second ;
321
- DashAclRule rule;
322
- bool found = fetchRule (group_id, rule_id, rule);
323
- if (!found)
324
- {
325
- SWSS_LOG_ERROR (" Failed to fetch group %s rule %s" , group_id.c_str (), rule_id.c_str ());
326
- return task_failed;
327
- }
328
-
329
- rule_info = createRule (new_group, rule);
330
- }
331
-
332
- for (const auto & table: new_group.m_in_tables )
333
- {
334
- const auto & eni_id = table.first ;
335
- const auto & stages = table.second ;
336
-
337
- const auto eni = m_dash_orch->getEni (eni_id);
338
- ABORT_IF_NOT (eni != nullptr , " Failed to get ENI %s" , eni_id.c_str ());
339
-
340
- for (const auto & stage: stages)
341
- {
342
- bind (new_group, *eni, DashAclDirection::IN, stage);
343
- }
344
- }
345
-
346
- for (const auto & table: new_group.m_out_tables )
347
- {
348
- const auto & eni_id = table.first ;
349
- const auto & stages = table.second ;
350
-
351
- const auto eni = m_dash_orch->getEni (eni_id);
352
- ABORT_IF_NOT (eni != nullptr , " Failed to get ENI %s" , eni_id.c_str ());
353
-
354
- for (const auto & stage: stages)
355
- {
356
- bind (new_group, *eni, DashAclDirection::OUT, stage);
357
- }
358
- }
359
-
360
- removeAclGroupFull (group);
361
-
362
- group = new_group;
363
-
364
- return task_success;
365
- }
366
-
367
- void DashAclGroupMgr::removeAclGroupFull (DashAclGroup& group)
368
- {
369
- SWSS_LOG_ENTER ();
370
-
371
- for (auto & rule: group.m_dash_acl_rule_table )
372
- {
373
- removeRule (group, rule.second );
374
- }
375
-
376
- remove (group);
377
- }
378
-
379
256
DashAclRuleInfo DashAclGroupMgr::createRule (DashAclGroup& group, DashAclRule& rule)
380
257
{
381
258
SWSS_LOG_ENTER ();
@@ -439,9 +316,9 @@ DashAclRuleInfo DashAclGroupMgr::createRule(DashAclGroup& group, DashAclRule& ru
439
316
for (const auto &tag : rule.m_src_tags )
440
317
{
441
318
const auto & prefixes = m_dash_acl_orch->getDashAclTagMgr ().getPrefixes (tag);
442
-
443
319
src_prefixes.insert (src_prefixes.end (),
444
320
prefixes.begin (), prefixes.end ());
321
+ group.m_tags .insert (tag);
445
322
}
446
323
447
324
for (const auto &tag : rule.m_dst_tags )
@@ -450,6 +327,7 @@ DashAclRuleInfo DashAclGroupMgr::createRule(DashAclGroup& group, DashAclRule& ru
450
327
451
328
dst_prefixes.insert (dst_prefixes.end (),
452
329
prefixes.begin (), prefixes.end ());
330
+ group.m_tags .insert (tag);
453
331
}
454
332
455
333
if (src_prefixes.empty ())
@@ -512,9 +390,6 @@ task_process_status DashAclGroupMgr::createRule(const string& group_id, const st
512
390
}
513
391
auto & group = group_it->second ;
514
392
515
- auto acl_rule_it = group.m_dash_acl_rule_table .find (rule_id);
516
- ABORT_IF_NOT (acl_rule_it == group.m_dash_acl_rule_table .end (), " Failed to create ACL rule %s. Rule already exist in ACL group %s" , rule_id.c_str (), group_id.c_str ());
517
-
518
393
for (const auto & tag_id : rule.m_src_tags )
519
394
{
520
395
if (!m_dash_acl_orch->getDashAclTagMgr ().exists (tag_id))
@@ -535,112 +410,14 @@ task_process_status DashAclGroupMgr::createRule(const string& group_id, const st
535
410
536
411
auto rule_info = createRule (group, rule);
537
412
538
- group.m_dash_acl_rule_table .emplace (rule_id, rule_info);
539
- attachTags (group_id, rule.m_src_tags );
540
- attachTags (group_id, rule.m_dst_tags );
413
+ group.m_rule_count ++;
414
+ attachTags (group_id, group.m_tags );
541
415
542
416
SWSS_LOG_INFO (" Created ACL rule %s:%s" , group_id.c_str (), rule_id.c_str ());
543
417
544
418
return task_success;
545
419
}
546
420
547
- task_process_status DashAclGroupMgr::updateRule (const string& group_id, const string& rule_id, DashAclRule& rule)
548
- {
549
- SWSS_LOG_ENTER ();
550
-
551
- if (ruleExists (group_id, rule_id))
552
- {
553
- removeRule (group_id, rule_id);
554
- }
555
-
556
- createRule (group_id, rule_id, rule);
557
-
558
- return task_success;
559
- }
560
-
561
- void DashAclGroupMgr::removeRule (DashAclGroup& group, DashAclRuleInfo& rule)
562
- {
563
- SWSS_LOG_ENTER ();
564
-
565
- if (rule.m_dash_acl_rule_id == SAI_NULL_OBJECT_ID)
566
- {
567
- return ;
568
- }
569
-
570
- // Remove the ACL group
571
- auto status = sai_dash_acl_api->remove_dash_acl_rule (rule.m_dash_acl_rule_id );
572
- if (status != SAI_STATUS_SUCCESS)
573
- {
574
- SWSS_LOG_ERROR (" Failed to remove ACL rule: %d, %s" , status, sai_serialize_status (status).c_str ());
575
- handleSaiRemoveStatus ((sai_api_t )SAI_API_DASH_ACL, status);
576
- }
577
-
578
- CrmResourceType crm_resource = (group.m_ip_version == SAI_IP_ADDR_FAMILY_IPV4) ?
579
- CrmResourceType::CRM_DASH_IPV4_ACL_RULE : CrmResourceType::CRM_DASH_IPV6_ACL_RULE;
580
- gCrmOrch ->decCrmDashAclUsedCounter (crm_resource, group.m_dash_acl_group_id );
581
-
582
- rule.m_dash_acl_rule_id = SAI_NULL_OBJECT_ID;
583
- }
584
-
585
- task_process_status DashAclGroupMgr::removeRule (const string& group_id, const string& rule_id)
586
- {
587
- SWSS_LOG_ENTER ();
588
-
589
- if (!ruleExists (group_id, rule_id))
590
- {
591
- SWSS_LOG_INFO (" ACL rule %s:%s does not exists" , group_id.c_str (), rule_id.c_str ());
592
- return task_success;
593
- }
594
-
595
- auto & group = m_groups_table[group_id];
596
- if (isBound (group))
597
- {
598
- SWSS_LOG_INFO (" Failed to remove dash ACL rule %s:%s, ACL group is bound to the ENI" , group_id.c_str (), rule_id.c_str ());
599
- return task_need_retry;
600
- }
601
-
602
- auto & rule = group.m_dash_acl_rule_table [rule_id];
603
-
604
- removeRule (group, rule);
605
-
606
- detachTags (group_id, rule.m_src_tags );
607
- detachTags (group_id, rule.m_dst_tags );
608
-
609
- group.m_dash_acl_rule_table .erase (rule_id);
610
-
611
- SWSS_LOG_INFO (" Removed ACL rule %s:%s" , group_id.c_str (), rule_id.c_str ());
612
-
613
- return task_success;
614
- }
615
-
616
- bool DashAclGroupMgr::fetchRule (const std::string &group_id, const std::string &rule_id, DashAclRule &rule)
617
- {
618
- auto key = group_id + " :" + rule_id;
619
- vector<FieldValueTuple> tuples;
620
-
621
- bool exists = m_dash_acl_rules_table->get (key, tuples);
622
- if (!exists)
623
- {
624
- SWSS_LOG_ERROR (" Failed to fetch DASH ACL Rule %s" , key.c_str ());
625
- return false ;
626
- }
627
-
628
- AclRule pb_rule;
629
- if (!parsePbMessage (tuples, pb_rule))
630
- {
631
- SWSS_LOG_ERROR (" Failed to parse PB message for DASH ACL rule" );
632
- return false ;
633
- }
634
-
635
- if (!from_pb (pb_rule, rule))
636
- {
637
- SWSS_LOG_ERROR (" Failed to convert PB DASH ACL Rule" );
638
- return false ;
639
- }
640
-
641
- return true ;
642
- }
643
-
644
421
void DashAclGroupMgr::bind (const DashAclGroup& group, const EniEntry& eni, DashAclDirection direction, DashAclStage stage)
645
422
{
646
423
SWSS_LOG_ENTER ();
@@ -658,19 +435,6 @@ void DashAclGroupMgr::bind(const DashAclGroup& group, const EniEntry& eni, DashA
658
435
}
659
436
}
660
437
661
- bool DashAclGroupMgr::ruleExists (const string& group_id, const string& rule_id) const
662
- {
663
- SWSS_LOG_ENTER ();
664
-
665
- auto group_it = m_groups_table.find (group_id);
666
- if (group_it == m_groups_table.end ())
667
- {
668
- return false ;
669
- }
670
-
671
- return group_it->second .m_dash_acl_rule_table .find (rule_id) != group_it->second .m_dash_acl_rule_table .end ();
672
- }
673
-
674
438
task_process_status DashAclGroupMgr::bind (const string& group_id, const string& eni_id, DashAclDirection direction, DashAclStage stage)
675
439
{
676
440
SWSS_LOG_ENTER ();
@@ -684,7 +448,7 @@ task_process_status DashAclGroupMgr::bind(const string& group_id, const string&
684
448
685
449
auto & group = group_it->second ;
686
450
687
- if (group.m_dash_acl_rule_table . empty () )
451
+ if (group.m_rule_count == 0 )
688
452
{
689
453
SWSS_LOG_INFO (" Failed to bind ACL group %s to ENI %s. ACL group has no rules attached." , group_id.c_str (), eni_id.c_str ());
690
454
return task_failed;
0 commit comments