@@ -380,6 +380,14 @@ static map<sai_acl_counter_attr_t, sai_acl_counter_attr_t> aclCounterLookup =
380
380
{SAI_ACL_COUNTER_ATTR_ENABLE_PACKET_COUNT, SAI_ACL_COUNTER_ATTR_PACKETS},
381
381
};
382
382
383
+ static map<AclObjectStatus, string> aclObjectStatusLookup =
384
+ {
385
+ {AclObjectStatus::ACTIVE, " Active" },
386
+ {AclObjectStatus::INACTIVE, " Inactive" },
387
+ {AclObjectStatus::PENDING_CREATION, " Pending creation" },
388
+ {AclObjectStatus::PENDING_REMOVAL, " Pending removal" }
389
+ };
390
+
383
391
static sai_acl_table_attr_t AclEntryFieldToAclTableField (sai_acl_entry_attr_t attr)
384
392
{
385
393
if (!IS_ATTR_ID_IN_RANGE (attr, ACL_ENTRY, FIELD))
@@ -2911,6 +2919,10 @@ void AclOrch::init(vector<TableConnector>& connectors, PortsOrch *portOrch, Mirr
2911
2919
{
2912
2920
SWSS_LOG_ENTER ();
2913
2921
2922
+ // Clear ACL_TABLE and ACL_RULE status from STATE_DB
2923
+ removeAllAclTableStatus ();
2924
+ removeAllAclRuleStatus ();
2925
+
2914
2926
// TODO: Query SAI to get mirror table capabilities
2915
2927
// Right now, verified platforms that support mirroring IPv6 packets are
2916
2928
// Broadcom and Mellanox. Virtual switch is also supported for testing
@@ -3416,6 +3428,8 @@ AclOrch::AclOrch(vector<TableConnector>& connectors, DBConnector* stateDb, Switc
3416
3428
PortsOrch *portOrch, MirrorOrch *mirrorOrch, NeighOrch *neighOrch, RouteOrch *routeOrch, DTelOrch *dtelOrch) :
3417
3429
Orch(connectors),
3418
3430
m_aclStageCapabilityTable(stateDb, STATE_ACL_STAGE_CAPABILITY_TABLE_NAME),
3431
+ m_aclTableStateTable(stateDb, STATE_ACL_TABLE_TABLE_NAME),
3432
+ m_aclRuleStateTable(stateDb, STATE_ACL_RULE_TABLE_NAME),
3419
3433
m_switchOrch(switchOrch),
3420
3434
m_mirrorOrch(mirrorOrch),
3421
3435
m_neighOrch(neighOrch),
@@ -4239,6 +4253,8 @@ void AclOrch::doAclTableTask(Consumer &consumer)
4239
4253
{
4240
4254
SWSS_LOG_NOTICE (" Successfully updated existing ACL table %s" ,
4241
4255
table_id.c_str ());
4256
+ // Mark ACL table as ACTIVE
4257
+ setAclTableStatus (table_id, AclObjectStatus::ACTIVE);
4242
4258
it = consumer.m_toSync .erase (it);
4243
4259
}
4244
4260
else
@@ -4251,24 +4267,41 @@ void AclOrch::doAclTableTask(Consumer &consumer)
4251
4267
else
4252
4268
{
4253
4269
if (addAclTable (newTable))
4270
+ {
4271
+ // Mark ACL table as ACTIVE
4272
+ setAclTableStatus (table_id, AclObjectStatus::ACTIVE);
4254
4273
it = consumer.m_toSync .erase (it);
4274
+ }
4255
4275
else
4276
+ {
4277
+ setAclTableStatus (table_id, AclObjectStatus::PENDING_CREATION);
4256
4278
it++;
4279
+ }
4257
4280
}
4258
4281
}
4259
4282
else
4260
4283
{
4261
4284
it = consumer.m_toSync .erase (it);
4285
+ // Mark the ACL table as inactive if the configuration is invalid
4286
+ setAclTableStatus (table_id, AclObjectStatus::INACTIVE);
4262
4287
SWSS_LOG_ERROR (" Failed to create ACL table %s, invalid configuration" ,
4263
4288
table_id.c_str ());
4264
4289
}
4265
4290
}
4266
4291
else if (op == DEL_COMMAND)
4267
4292
{
4268
4293
if (removeAclTable (table_id))
4294
+ {
4295
+ // Remove ACL table status from STATE_DB
4296
+ removeAclTableStatus (table_id);
4269
4297
it = consumer.m_toSync .erase (it);
4298
+ }
4270
4299
else
4300
+ {
4301
+ // Set the status of ACL_TABLE to pending removal if removeAclTable returns error
4302
+ setAclTableStatus (table_id, AclObjectStatus::PENDING_REMOVAL);
4271
4303
it++;
4304
+ }
4272
4305
}
4273
4306
else
4274
4307
{
@@ -4408,22 +4441,37 @@ void AclOrch::doAclRuleTask(Consumer &consumer)
4408
4441
if (bAllAttributesOk && newRule->validate ())
4409
4442
{
4410
4443
if (addAclRule (newRule, table_id))
4444
+ {
4445
+ setAclRuleStatus (table_id, rule_id, AclObjectStatus::ACTIVE);
4411
4446
it = consumer.m_toSync .erase (it);
4447
+ }
4412
4448
else
4449
+ {
4450
+ setAclRuleStatus (table_id, rule_id, AclObjectStatus::PENDING_CREATION);
4413
4451
it++;
4452
+ }
4414
4453
}
4415
4454
else
4416
4455
{
4417
4456
it = consumer.m_toSync .erase (it);
4457
+ // Mark the rule inactive if the configuration is invalid
4458
+ setAclRuleStatus (table_id, rule_id, AclObjectStatus::INACTIVE);
4418
4459
SWSS_LOG_ERROR (" Failed to create ACL rule. Rule configuration is invalid" );
4419
4460
}
4420
4461
}
4421
4462
else if (op == DEL_COMMAND)
4422
4463
{
4423
4464
if (removeAclRule (table_id, rule_id))
4465
+ {
4466
+ removeAclRuleStatus (table_id, rule_id);
4424
4467
it = consumer.m_toSync .erase (it);
4468
+ }
4425
4469
else
4470
+ {
4471
+ // Mark pending removal status if removeAclRule returns error
4472
+ setAclRuleStatus (table_id, rule_id, AclObjectStatus::PENDING_REMOVAL);
4426
4473
it++;
4474
+ }
4427
4475
}
4428
4476
else
4429
4477
{
@@ -4781,3 +4829,55 @@ bool AclOrch::getAclBindPortId(Port &port, sai_object_id_t &port_id)
4781
4829
4782
4830
return true ;
4783
4831
}
4832
+
4833
+ // Set the status of ACL table in STATE_DB
4834
+ void AclOrch::setAclTableStatus (string table_name, AclObjectStatus status)
4835
+ {
4836
+ vector<FieldValueTuple> fvVector;
4837
+ fvVector.emplace_back (" status" , aclObjectStatusLookup[status]);
4838
+ m_aclTableStateTable.set (table_name, fvVector);
4839
+ }
4840
+
4841
+ // Remove the status record of given ACL table from STATE_DB
4842
+ void AclOrch::removeAclTableStatus (string table_name)
4843
+ {
4844
+ m_aclTableStateTable.del (table_name);
4845
+ }
4846
+
4847
+ // Set the status of ACL rule in STATE_DB
4848
+ void AclOrch::setAclRuleStatus (string table_name, string rule_name, AclObjectStatus status)
4849
+ {
4850
+ vector<FieldValueTuple> fvVector;
4851
+ fvVector.emplace_back (" status" , aclObjectStatusLookup[status]);
4852
+ m_aclRuleStateTable.set (table_name + string (" |" ) + rule_name, fvVector);
4853
+ }
4854
+
4855
+ // Remove the status record of given ACL rule from STATE_DB
4856
+ void AclOrch::removeAclRuleStatus (string table_name, string rule_name)
4857
+ {
4858
+ m_aclRuleStateTable.del (table_name + string (" |" ) + rule_name);
4859
+ }
4860
+
4861
+ // Remove all ACL table status from STATE_DB
4862
+ void AclOrch::removeAllAclTableStatus ()
4863
+ {
4864
+ vector<string> keys;
4865
+ m_aclTableStateTable.getKeys (keys);
4866
+
4867
+ for (auto key : keys)
4868
+ {
4869
+ m_aclTableStateTable.del (key);
4870
+ }
4871
+ }
4872
+
4873
+ // Remove all ACL rule status from STATE_DB
4874
+ void AclOrch::removeAllAclRuleStatus ()
4875
+ {
4876
+ vector<string> keys;
4877
+ m_aclRuleStateTable.getKeys (keys);
4878
+ for (auto key : keys)
4879
+ {
4880
+ m_aclRuleStateTable.del (key);
4881
+ }
4882
+ }
4883
+
0 commit comments