@@ -415,6 +415,14 @@ static map<sai_acl_counter_attr_t, sai_acl_counter_attr_t> aclCounterLookup =
415
415
{SAI_ACL_COUNTER_ATTR_ENABLE_PACKET_COUNT, SAI_ACL_COUNTER_ATTR_PACKETS},
416
416
};
417
417
418
+ static map<AclObjectStatus, string> aclObjectStatusLookup =
419
+ {
420
+ {AclObjectStatus::ACTIVE, " Active" },
421
+ {AclObjectStatus::INACTIVE, " Inactive" },
422
+ {AclObjectStatus::PENDING_CREATION, " Pending creation" },
423
+ {AclObjectStatus::PENDING_REMOVAL, " Pending removal" }
424
+ };
425
+
418
426
static sai_acl_table_attr_t AclEntryFieldToAclTableField (sai_acl_entry_attr_t attr)
419
427
{
420
428
if (!IS_ATTR_ID_IN_RANGE (attr, ACL_ENTRY, FIELD))
@@ -3006,6 +3014,10 @@ void AclOrch::init(vector<TableConnector>& connectors, PortsOrch *portOrch, Mirr
3006
3014
{
3007
3015
SWSS_LOG_ENTER ();
3008
3016
3017
+ // Clear ACL_TABLE and ACL_RULE status from STATE_DB
3018
+ removeAllAclTableStatus ();
3019
+ removeAllAclRuleStatus ();
3020
+
3009
3021
// TODO: Query SAI to get mirror table capabilities
3010
3022
// Right now, verified platforms that support mirroring IPv6 packets are
3011
3023
// Broadcom and Mellanox. Virtual switch is also supported for testing
@@ -3509,6 +3521,8 @@ AclOrch::AclOrch(vector<TableConnector>& connectors, DBConnector* stateDb, Switc
3509
3521
PortsOrch *portOrch, MirrorOrch *mirrorOrch, NeighOrch *neighOrch, RouteOrch *routeOrch, DTelOrch *dtelOrch) :
3510
3522
Orch(connectors),
3511
3523
m_aclStageCapabilityTable(stateDb, STATE_ACL_STAGE_CAPABILITY_TABLE_NAME),
3524
+ m_aclTableStateTable(stateDb, STATE_ACL_TABLE_TABLE_NAME),
3525
+ m_aclRuleStateTable(stateDb, STATE_ACL_RULE_TABLE_NAME),
3512
3526
m_switchOrch(switchOrch),
3513
3527
m_mirrorOrch(mirrorOrch),
3514
3528
m_neighOrch(neighOrch),
@@ -4332,6 +4346,8 @@ void AclOrch::doAclTableTask(Consumer &consumer)
4332
4346
{
4333
4347
SWSS_LOG_NOTICE (" Successfully updated existing ACL table %s" ,
4334
4348
table_id.c_str ());
4349
+ // Mark ACL table as ACTIVE
4350
+ setAclTableStatus (table_id, AclObjectStatus::ACTIVE);
4335
4351
it = consumer.m_toSync .erase (it);
4336
4352
}
4337
4353
else
@@ -4344,24 +4360,41 @@ void AclOrch::doAclTableTask(Consumer &consumer)
4344
4360
else
4345
4361
{
4346
4362
if (addAclTable (newTable))
4363
+ {
4364
+ // Mark ACL table as ACTIVE
4365
+ setAclTableStatus (table_id, AclObjectStatus::ACTIVE);
4347
4366
it = consumer.m_toSync .erase (it);
4367
+ }
4348
4368
else
4369
+ {
4370
+ setAclTableStatus (table_id, AclObjectStatus::PENDING_CREATION);
4349
4371
it++;
4372
+ }
4350
4373
}
4351
4374
}
4352
4375
else
4353
4376
{
4354
4377
it = consumer.m_toSync .erase (it);
4378
+ // Mark the ACL table as inactive if the configuration is invalid
4379
+ setAclTableStatus (table_id, AclObjectStatus::INACTIVE);
4355
4380
SWSS_LOG_ERROR (" Failed to create ACL table %s, invalid configuration" ,
4356
4381
table_id.c_str ());
4357
4382
}
4358
4383
}
4359
4384
else if (op == DEL_COMMAND)
4360
4385
{
4361
4386
if (removeAclTable (table_id))
4387
+ {
4388
+ // Remove ACL table status from STATE_DB
4389
+ removeAclTableStatus (table_id);
4362
4390
it = consumer.m_toSync .erase (it);
4391
+ }
4363
4392
else
4393
+ {
4394
+ // Set the status of ACL_TABLE to pending removal if removeAclTable returns error
4395
+ setAclTableStatus (table_id, AclObjectStatus::PENDING_REMOVAL);
4364
4396
it++;
4397
+ }
4365
4398
}
4366
4399
else
4367
4400
{
@@ -4501,22 +4534,37 @@ void AclOrch::doAclRuleTask(Consumer &consumer)
4501
4534
if (bAllAttributesOk && newRule->validate ())
4502
4535
{
4503
4536
if (addAclRule (newRule, table_id))
4537
+ {
4538
+ setAclRuleStatus (table_id, rule_id, AclObjectStatus::ACTIVE);
4504
4539
it = consumer.m_toSync .erase (it);
4540
+ }
4505
4541
else
4542
+ {
4543
+ setAclRuleStatus (table_id, rule_id, AclObjectStatus::PENDING_CREATION);
4506
4544
it++;
4545
+ }
4507
4546
}
4508
4547
else
4509
4548
{
4510
4549
it = consumer.m_toSync .erase (it);
4550
+ // Mark the rule inactive if the configuration is invalid
4551
+ setAclRuleStatus (table_id, rule_id, AclObjectStatus::INACTIVE);
4511
4552
SWSS_LOG_ERROR (" Failed to create ACL rule. Rule configuration is invalid" );
4512
4553
}
4513
4554
}
4514
4555
else if (op == DEL_COMMAND)
4515
4556
{
4516
4557
if (removeAclRule (table_id, rule_id))
4558
+ {
4559
+ removeAclRuleStatus (table_id, rule_id);
4517
4560
it = consumer.m_toSync .erase (it);
4561
+ }
4518
4562
else
4563
+ {
4564
+ // Mark pending removal status if removeAclRule returns error
4565
+ setAclRuleStatus (table_id, rule_id, AclObjectStatus::PENDING_REMOVAL);
4519
4566
it++;
4567
+ }
4520
4568
}
4521
4569
else
4522
4570
{
@@ -4874,3 +4922,55 @@ bool AclOrch::getAclBindPortId(Port &port, sai_object_id_t &port_id)
4874
4922
4875
4923
return true ;
4876
4924
}
4925
+
4926
+ // Set the status of ACL table in STATE_DB
4927
+ void AclOrch::setAclTableStatus (string table_name, AclObjectStatus status)
4928
+ {
4929
+ vector<FieldValueTuple> fvVector;
4930
+ fvVector.emplace_back (" status" , aclObjectStatusLookup[status]);
4931
+ m_aclTableStateTable.set (table_name, fvVector);
4932
+ }
4933
+
4934
+ // Remove the status record of given ACL table from STATE_DB
4935
+ void AclOrch::removeAclTableStatus (string table_name)
4936
+ {
4937
+ m_aclTableStateTable.del (table_name);
4938
+ }
4939
+
4940
+ // Set the status of ACL rule in STATE_DB
4941
+ void AclOrch::setAclRuleStatus (string table_name, string rule_name, AclObjectStatus status)
4942
+ {
4943
+ vector<FieldValueTuple> fvVector;
4944
+ fvVector.emplace_back (" status" , aclObjectStatusLookup[status]);
4945
+ m_aclRuleStateTable.set (table_name + string (" |" ) + rule_name, fvVector);
4946
+ }
4947
+
4948
+ // Remove the status record of given ACL rule from STATE_DB
4949
+ void AclOrch::removeAclRuleStatus (string table_name, string rule_name)
4950
+ {
4951
+ m_aclRuleStateTable.del (table_name + string (" |" ) + rule_name);
4952
+ }
4953
+
4954
+ // Remove all ACL table status from STATE_DB
4955
+ void AclOrch::removeAllAclTableStatus ()
4956
+ {
4957
+ vector<string> keys;
4958
+ m_aclTableStateTable.getKeys (keys);
4959
+
4960
+ for (auto key : keys)
4961
+ {
4962
+ m_aclTableStateTable.del (key);
4963
+ }
4964
+ }
4965
+
4966
+ // Remove all ACL rule status from STATE_DB
4967
+ void AclOrch::removeAllAclRuleStatus ()
4968
+ {
4969
+ vector<string> keys;
4970
+ m_aclRuleStateTable.getKeys (keys);
4971
+ for (auto key : keys)
4972
+ {
4973
+ m_aclRuleStateTable.del (key);
4974
+ }
4975
+ }
4976
+
0 commit comments