@@ -375,6 +375,14 @@ static map<sai_acl_counter_attr_t, sai_acl_counter_attr_t> aclCounterLookup =
375
375
{SAI_ACL_COUNTER_ATTR_ENABLE_PACKET_COUNT, SAI_ACL_COUNTER_ATTR_PACKETS},
376
376
};
377
377
378
+ static map<AclObjectStatus, string> aclObjectStatusLookup =
379
+ {
380
+ {AclObjectStatus::ACTIVE, " Active" },
381
+ {AclObjectStatus::INACTIVE, " Inactive" },
382
+ {AclObjectStatus::PENDING_CREATION, " Pending creation" },
383
+ {AclObjectStatus::PENDING_REMOVAL, " Pending removal" }
384
+ };
385
+
378
386
static sai_acl_table_attr_t AclEntryFieldToAclTableField (sai_acl_entry_attr_t attr)
379
387
{
380
388
if (!IS_ATTR_ID_IN_RANGE (attr, ACL_ENTRY, FIELD))
@@ -2900,6 +2908,10 @@ void AclOrch::init(vector<TableConnector>& connectors, PortsOrch *portOrch, Mirr
2900
2908
{
2901
2909
SWSS_LOG_ENTER ();
2902
2910
2911
+ // Clear ACL_TABLE and ACL_RULE status from STATE_DB
2912
+ removeAllAclTableStatus ();
2913
+ removeAllAclRuleStatus ();
2914
+
2903
2915
// TODO: Query SAI to get mirror table capabilities
2904
2916
// Right now, verified platforms that support mirroring IPv6 packets are
2905
2917
// Broadcom and Mellanox. Virtual switch is also supported for testing
@@ -3407,6 +3419,8 @@ AclOrch::AclOrch(vector<TableConnector>& connectors, DBConnector* stateDb, Switc
3407
3419
PortsOrch *portOrch, MirrorOrch *mirrorOrch, NeighOrch *neighOrch, RouteOrch *routeOrch, DTelOrch *dtelOrch) :
3408
3420
Orch(connectors),
3409
3421
m_aclStageCapabilityTable(stateDb, STATE_ACL_STAGE_CAPABILITY_TABLE_NAME),
3422
+ m_aclTableStateTable(stateDb, STATE_ACL_TABLE_TABLE_NAME),
3423
+ m_aclRuleStateTable(stateDb, STATE_ACL_RULE_TABLE_NAME),
3410
3424
m_switchOrch(switchOrch),
3411
3425
m_mirrorOrch(mirrorOrch),
3412
3426
m_neighOrch(neighOrch),
@@ -4230,6 +4244,8 @@ void AclOrch::doAclTableTask(Consumer &consumer)
4230
4244
{
4231
4245
SWSS_LOG_NOTICE (" Successfully updated existing ACL table %s" ,
4232
4246
table_id.c_str ());
4247
+ // Mark ACL table as ACTIVE
4248
+ setAclTableStatus (table_id, AclObjectStatus::ACTIVE);
4233
4249
it = consumer.m_toSync .erase (it);
4234
4250
}
4235
4251
else
@@ -4242,24 +4258,41 @@ void AclOrch::doAclTableTask(Consumer &consumer)
4242
4258
else
4243
4259
{
4244
4260
if (addAclTable (newTable))
4261
+ {
4262
+ // Mark ACL table as ACTIVE
4263
+ setAclTableStatus (table_id, AclObjectStatus::ACTIVE);
4245
4264
it = consumer.m_toSync .erase (it);
4265
+ }
4246
4266
else
4267
+ {
4268
+ setAclTableStatus (table_id, AclObjectStatus::PENDING_CREATION);
4247
4269
it++;
4270
+ }
4248
4271
}
4249
4272
}
4250
4273
else
4251
4274
{
4252
4275
it = consumer.m_toSync .erase (it);
4276
+ // Mark the ACL table as inactive if the configuration is invalid
4277
+ setAclTableStatus (table_id, AclObjectStatus::INACTIVE);
4253
4278
SWSS_LOG_ERROR (" Failed to create ACL table %s, invalid configuration" ,
4254
4279
table_id.c_str ());
4255
4280
}
4256
4281
}
4257
4282
else if (op == DEL_COMMAND)
4258
4283
{
4259
4284
if (removeAclTable (table_id))
4285
+ {
4286
+ // Remove ACL table status from STATE_DB
4287
+ removeAclTableStatus (table_id);
4260
4288
it = consumer.m_toSync .erase (it);
4289
+ }
4261
4290
else
4291
+ {
4292
+ // Set the status of ACL_TABLE to pending removal if removeAclTable returns error
4293
+ setAclTableStatus (table_id, AclObjectStatus::PENDING_REMOVAL);
4262
4294
it++;
4295
+ }
4263
4296
}
4264
4297
else
4265
4298
{
@@ -4399,22 +4432,37 @@ void AclOrch::doAclRuleTask(Consumer &consumer)
4399
4432
if (bAllAttributesOk && newRule->validate ())
4400
4433
{
4401
4434
if (addAclRule (newRule, table_id))
4435
+ {
4436
+ setAclRuleStatus (table_id, rule_id, AclObjectStatus::ACTIVE);
4402
4437
it = consumer.m_toSync .erase (it);
4438
+ }
4403
4439
else
4440
+ {
4441
+ setAclRuleStatus (table_id, rule_id, AclObjectStatus::PENDING_CREATION);
4404
4442
it++;
4443
+ }
4405
4444
}
4406
4445
else
4407
4446
{
4408
4447
it = consumer.m_toSync .erase (it);
4448
+ // Mark the rule inactive if the configuration is invalid
4449
+ setAclRuleStatus (table_id, rule_id, AclObjectStatus::INACTIVE);
4409
4450
SWSS_LOG_ERROR (" Failed to create ACL rule. Rule configuration is invalid" );
4410
4451
}
4411
4452
}
4412
4453
else if (op == DEL_COMMAND)
4413
4454
{
4414
4455
if (removeAclRule (table_id, rule_id))
4456
+ {
4457
+ removeAclRuleStatus (table_id, rule_id);
4415
4458
it = consumer.m_toSync .erase (it);
4459
+ }
4416
4460
else
4461
+ {
4462
+ // Mark pending removal status if removeAclRule returns error
4463
+ setAclRuleStatus (table_id, rule_id, AclObjectStatus::PENDING_REMOVAL);
4417
4464
it++;
4465
+ }
4418
4466
}
4419
4467
else
4420
4468
{
@@ -4770,3 +4818,55 @@ bool AclOrch::getAclBindPortId(Port &port, sai_object_id_t &port_id)
4770
4818
4771
4819
return true ;
4772
4820
}
4821
+
4822
+ // Set the status of ACL table in STATE_DB
4823
+ void AclOrch::setAclTableStatus (string table_name, AclObjectStatus status)
4824
+ {
4825
+ vector<FieldValueTuple> fvVector;
4826
+ fvVector.emplace_back (" status" , aclObjectStatusLookup[status]);
4827
+ m_aclTableStateTable.set (table_name, fvVector);
4828
+ }
4829
+
4830
+ // Remove the status record of given ACL table from STATE_DB
4831
+ void AclOrch::removeAclTableStatus (string table_name)
4832
+ {
4833
+ m_aclTableStateTable.del (table_name);
4834
+ }
4835
+
4836
+ // Set the status of ACL rule in STATE_DB
4837
+ void AclOrch::setAclRuleStatus (string table_name, string rule_name, AclObjectStatus status)
4838
+ {
4839
+ vector<FieldValueTuple> fvVector;
4840
+ fvVector.emplace_back (" status" , aclObjectStatusLookup[status]);
4841
+ m_aclRuleStateTable.set (table_name + string (" |" ) + rule_name, fvVector);
4842
+ }
4843
+
4844
+ // Remove the status record of given ACL rule from STATE_DB
4845
+ void AclOrch::removeAclRuleStatus (string table_name, string rule_name)
4846
+ {
4847
+ m_aclRuleStateTable.del (table_name + string (" |" ) + rule_name);
4848
+ }
4849
+
4850
+ // Remove all ACL table status from STATE_DB
4851
+ void AclOrch::removeAllAclTableStatus ()
4852
+ {
4853
+ vector<string> keys;
4854
+ m_aclTableStateTable.getKeys (keys);
4855
+
4856
+ for (auto key : keys)
4857
+ {
4858
+ m_aclTableStateTable.del (key);
4859
+ }
4860
+ }
4861
+
4862
+ // Remove all ACL rule status from STATE_DB
4863
+ void AclOrch::removeAllAclRuleStatus ()
4864
+ {
4865
+ vector<string> keys;
4866
+ m_aclRuleStateTable.getKeys (keys);
4867
+ for (auto key : keys)
4868
+ {
4869
+ m_aclRuleStateTable.del (key);
4870
+ }
4871
+ }
4872
+
0 commit comments