Skip to content

Commit 5ab6779

Browse files
mint570divyagayathri-hcl
authored andcommitted
[P4Orch] Add ACL action list during ACL table creation if they are mandatory.
Signed-off-by: mint570 <[email protected]>
1 parent bb691a5 commit 5ab6779

11 files changed

Lines changed: 1073 additions & 769 deletions

orchagent/p4orch/acl_rule_manager.cpp

Lines changed: 288 additions & 303 deletions
Large diffs are not rendered by default.

orchagent/p4orch/acl_rule_manager.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,16 @@ class AclRuleManager : public ObjectManagerInterface
116116
P4AclRule &acl_rule);
117117

118118
// Validate and set a match attribute in an ACL rule.
119-
ReturnCode setMatchValue(const acl_entry_attr_union_t attr_name, const std::string &attr_value,
120-
sai_attribute_value_t *value, P4AclRule *acl_rule,
121-
const std::string &ip_type_bit_type = EMPTY_STRING);
119+
ReturnCode setMatchValue(
120+
const sai_acl_entry_attr_t attr_name, const std::string& attr_value,
121+
sai_attribute_value_t* value, P4AclRule* acl_rule,
122+
const std::string& ip_type_bit_type = EMPTY_STRING);
122123

123124
// Validate and set an action attribute in an ACL rule.
124-
ReturnCode setActionValue(const acl_entry_attr_union_t attr_name, const std::string &attr_value,
125-
sai_attribute_value_t *value, P4AclRule *acl_rule);
125+
ReturnCode setActionValue(const sai_acl_entry_attr_t attr_name,
126+
const std::string& attr_value,
127+
sai_attribute_value_t* value,
128+
P4AclRule* acl_rule);
126129

127130
// Get port object id by name for redirect action.
128131
ReturnCode getRedirectActionPortOid(const std::string &target, sai_object_id_t *rediect_oid);

orchagent/p4orch/acl_table_manager.cpp

Lines changed: 219 additions & 168 deletions
Large diffs are not rendered by default.

orchagent/p4orch/acl_table_manager.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,11 @@ class AclTableManager : public ObjectManagerInterface
103103
const P4AclTableDefinition *acl_table);
104104

105105
// Verifies ASIC DB for an entry.
106-
std::string verifyStateAsicDb(const P4AclTableDefinition *acl_table);
106+
std::string verifyStateAsicDb(P4AclTableDefinition* acl_table);
107107

108108
// Returns ACl table SAI attributes.
109-
ReturnCodeOr<std::vector<sai_attribute_t>> getTableSaiAttrs(const P4AclTableDefinition &acl_table);
109+
ReturnCodeOr<std::vector<sai_attribute_t>> getTableSaiAttrs(
110+
P4AclTableDefinition& acl_table);
110111

111112
// Returns UDF SAI attributes.
112113
ReturnCodeOr<std::vector<sai_attribute_t>> getUdfSaiAttrs(const P4UdfField &udf_field);
@@ -117,9 +118,6 @@ class AclTableManager : public ObjectManagerInterface
117118
std::deque<swss::KeyOpFieldsValuesTuple> m_entries;
118119
std::map<sai_acl_stage_t, std::vector<std::string>> m_aclTablesByStage;
119120

120-
// Always add counter action in ACL table action list during creation
121-
int32_t m_acl_action_list[1];
122-
123121
friend class p4orch::test::AclManagerTest;
124122
};
125123

orchagent/p4orch/acl_util.cpp

Lines changed: 170 additions & 152 deletions
Large diffs are not rendered by default.

orchagent/p4orch/acl_util.h

Lines changed: 56 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <string>
77
#include <vector>
88

9+
#include "acltable.h"
910
#include "p4orch/p4orch_util.h"
1011
#include "return_code.h"
1112
extern "C"
@@ -17,11 +18,6 @@ extern "C"
1718
namespace p4orch
1819
{
1920

20-
// sai_acl_entry_attr_t or sai_acl_entry_attr_extensions_t
21-
using acl_entry_attr_union_t = int32_t;
22-
// sai_acl_table_attr_t or sai_acl_table_attr_extensions_t
23-
using acl_table_attr_union_t = int32_t;
24-
2521
// Describes the format of a value.
2622
enum Format
2723
{
@@ -138,19 +134,19 @@ struct P4AclRule
138134

139135
sai_uint32_t priority;
140136
std::string p4_action;
141-
std::map<acl_entry_attr_union_t, sai_attribute_value_t> match_fvs;
142-
std::map<acl_entry_attr_union_t, sai_attribute_value_t> action_fvs;
137+
std::map<sai_acl_entry_attr_t, sai_attribute_value_t> match_fvs;
138+
std::map<sai_acl_entry_attr_t, sai_attribute_value_t> action_fvs;
143139
P4AclMeter meter;
144140
P4AclCounter counter;
145141

146142
sai_uint32_t action_qos_queue_num;
147143
std::string action_redirect_nexthop_key;
148144
// SAI_ACL_ENTRY_ATTR_ACTION_MIRROR_INGRESS and
149145
// SAI_ACL_ENTRY_ATTR_ACTION_MIRROR_EGRESS are allowed as key
150-
std::map<acl_entry_attr_union_t, P4AclMirrorSession> action_mirror_sessions;
146+
std::map<sai_acl_entry_attr_t, P4AclMirrorSession> action_mirror_sessions;
151147
// Stores mapping from SAI_ACL_TABLE_ATTR_USER_DEFINED_FIELD_GROUP_{number} to
152148
// udf data and masks pairs in two uin8_t list
153-
std::map<acl_entry_attr_union_t, P4UdfDataMask> udf_data_masks;
149+
std::map<sai_acl_entry_attr_t, P4UdfDataMask> udf_data_masks;
154150
std::vector<std::string> in_ports;
155151
std::vector<std::string> out_ports;
156152
std::vector<sai_object_id_t> in_ports_oids;
@@ -159,14 +155,14 @@ struct P4AclRule
159155

160156
struct SaiActionWithParam
161157
{
162-
acl_entry_attr_union_t action;
163-
std::string param_name;
164-
std::string param_value;
158+
sai_acl_entry_attr_t action;
159+
std::string param_name;
160+
std::string param_value;
165161

166-
bool operator==(const SaiActionWithParam &entry) const
167-
{
168-
return action == entry.action && param_name == entry.param_name && param_value == entry.param_value;
169-
}
162+
bool operator==(const SaiActionWithParam& entry) const {
163+
return action == entry.action && param_name == entry.param_name &&
164+
param_value == entry.param_value;
165+
}
170166

171167
bool operator!=(const SaiActionWithParam &entry) const
172168
{
@@ -176,16 +172,15 @@ struct SaiActionWithParam
176172

177173
struct SaiMatchField
178174
{
179-
acl_entry_attr_union_t entry_attr;
180-
acl_table_attr_union_t table_attr;
181-
uint32_t bitwidth;
182-
Format format;
175+
sai_acl_entry_attr_t entry_attr;
176+
sai_acl_table_attr_t table_attr;
177+
uint32_t bitwidth;
178+
Format format;
183179

184-
bool operator==(const SaiMatchField &entry) const
185-
{
186-
return entry_attr == entry.entry_attr && table_attr == entry.table_attr && bitwidth == entry.bitwidth &&
187-
format == entry.format;
188-
}
180+
bool operator==(const SaiMatchField& entry) const {
181+
return entry_attr == entry.entry_attr && table_attr == entry.table_attr &&
182+
bitwidth == entry.bitwidth && format == entry.format;
183+
}
189184

190185
bool operator!=(const SaiMatchField &entry) const
191186
{
@@ -238,6 +233,7 @@ struct P4AclTableDefinition
238233
std::map<std::string, std::string> ip_type_bit_type_lookup;
239234
std::map<std::string, std::vector<SaiActionWithParam>> rule_action_field_lookup;
240235
std::map<std::string, std::map<sai_policer_attr_t, sai_packet_action_t>> rule_packet_action_color_lookup;
236+
std::vector<sai_acl_action_type_t> acl_action_type_list;
241237

242238
P4AclTableDefinition() = default;
243239
P4AclTableDefinition(const std::string &acl_table_name, const sai_acl_stage_t stage, const uint32_t priority,
@@ -254,9 +250,9 @@ struct P4UserDefinedTrapHostifTableEntry
254250
: user_defined_trap(SAI_NULL_OBJECT_ID), hostif_table_entry(SAI_NULL_OBJECT_ID) {};
255251
};
256252

257-
using acl_rule_attr_lookup_t = std::map<std::string, acl_entry_attr_union_t>;
258-
using acl_table_attr_lookup_t = std::map<std::string, acl_table_attr_union_t>;
259-
using acl_table_attr_format_lookup_t = std::map<acl_table_attr_union_t, Format>;
253+
using acl_rule_attr_lookup_t = std::map<std::string, sai_acl_entry_attr_t>;
254+
using acl_table_attr_lookup_t = std::map<std::string, sai_acl_table_attr_t>;
255+
using acl_table_attr_format_lookup_t = std::map<sai_acl_table_attr_t, Format>;
260256
using acl_packet_action_lookup_t = std::map<std::string, sai_packet_action_t>;
261257
using acl_packet_color_lookup_t = std::map<std::string, sai_packet_color_t>;
262258
using acl_packet_color_policer_attr_lookup_t = std::map<std::string, sai_policer_attr_t>;
@@ -728,6 +724,13 @@ static std::map<sai_stat_id_t, std::string> aclCounterStatsIdNameMap = {
728724
{SAI_POLICER_STAT_RED_BYTES, P4_COUNTER_STATS_RED_BYTES},
729725
};
730726

727+
static const std::map<sai_acl_stage_t, acl_stage_type_t>
728+
aclSaiStageAttrToEnumLookup = {
729+
{SAI_ACL_STAGE_INGRESS, ACL_STAGE_INGRESS},
730+
{SAI_ACL_STAGE_EGRESS, ACL_STAGE_EGRESS},
731+
{SAI_ACL_STAGE_PRE_INGRESS, ACL_STAGE_PRE_INGRESS},
732+
};
733+
731734
// Parse ACL table definition APP DB entry action field to P4ActionParamName
732735
// action_list and P4PacketActionWithColor action_color_list
733736
bool parseAclTableAppDbActionField(const std::string &aggr_actions_str, std::vector<P4ActionParamName> *action_list,
@@ -771,8 +774,11 @@ ReturnCode buildAclTableDefinitionMatchFieldValues(const std::map<std::string, s
771774
// Build SaiActionWithParam action map for ACL table definition
772775
// by P4ActionParamName action map
773776
ReturnCode buildAclTableDefinitionActionFieldValues(
774-
const std::map<std::string, std::vector<P4ActionParamName>> &action_field_lookup,
775-
std::map<std::string, std::vector<SaiActionWithParam>> *aggr_sai_actions_lookup);
777+
const std::map<std::string, std::vector<P4ActionParamName>>&
778+
action_field_lookup,
779+
std::map<std::string, std::vector<SaiActionWithParam>>*
780+
aggr_sai_actions_lookup,
781+
std::set<sai_acl_action_type_t>* acl_action_type_set);
776782

777783
bool isSetUserTrapActionInAclTableDefinition(
778784
const std::map<std::string, std::vector<SaiActionWithParam>> &aggr_sai_actions_lookup);
@@ -782,34 +788,43 @@ bool isSetUserTrapActionInAclTableDefinition(
782788
// P4PacketActionWithColor action map. If packet color is empty, then the
783789
// packet action should add as a SaiActionWithParam
784790
ReturnCode buildAclTableDefinitionActionColorFieldValues(
785-
const std::map<std::string, std::vector<P4PacketActionWithColor>> &action_color_lookup,
786-
std::map<std::string, std::vector<SaiActionWithParam>> *aggr_sai_actions_lookup,
787-
std::map<std::string, std::map<sai_policer_attr_t, sai_packet_action_t>> *aggr_sai_action_color_lookup);
791+
const std::map<std::string, std::vector<P4PacketActionWithColor>>&
792+
action_color_lookup,
793+
std::map<std::string, std::vector<SaiActionWithParam>>*
794+
aggr_sai_actions_lookup,
795+
std::map<std::string, std::map<sai_policer_attr_t, sai_packet_action_t>>*
796+
aggr_sai_action_color_lookup,
797+
std::set<sai_acl_action_type_t>* acl_action_type_set);
788798

789799
// Set IP_TYPE in match field
790800
bool setMatchFieldIpType(const std::string &attr_value, sai_attribute_value_t *value,
791801
const std::string &ip_type_bit_type);
792802

793803
// Set composite match field with sai_field type. Currently only ACL entry
794804
// attributes listed in aclCompositeMatchTableAttrLookup are supported
795-
ReturnCode setCompositeSaiMatchValue(const acl_entry_attr_union_t attr_name, const std::string &attr_value,
796-
sai_attribute_value_t *value);
805+
ReturnCode setCompositeSaiMatchValue(const sai_acl_entry_attr_t attr_name,
806+
const std::string& attr_value,
807+
sai_attribute_value_t* value);
797808

798809
// Set composite match field with sai_field type.
799810
ReturnCode setUdfMatchValue(const P4UdfField &udf_field, const std::string &attr_value, sai_attribute_value_t *value,
800811
P4UdfDataMask *udf_data_mask, uint16_t bytes_offset);
801812

802813
// Compares the action value difference if the action field is present in
803814
// both new and old ACL rules. Returns true if action values are different.
804-
bool isDiffActionFieldValue(const acl_entry_attr_union_t attr_name, const sai_attribute_value_t &value,
805-
const sai_attribute_value_t &old_value, const P4AclRule &acl_rule,
806-
const P4AclRule &old_acl_rule);
815+
bool isDiffActionFieldValue(const sai_acl_entry_attr_t attr_name,
816+
const sai_attribute_value_t& value,
817+
const sai_attribute_value_t& old_value,
818+
const P4AclRule& acl_rule,
819+
const P4AclRule& old_acl_rule);
807820

808821
// Compares the match value difference if the match field is present in
809822
// both new and old ACL rules. Returns true if match values are different.
810823
// This method is used in state verification only.
811-
bool isDiffMatchFieldValue(const acl_entry_attr_union_t attr_name, const sai_attribute_value_t &value,
812-
const sai_attribute_value_t &old_value, const P4AclRule &acl_rule,
813-
const P4AclRule &old_acl_rule);
824+
bool isDiffMatchFieldValue(const sai_acl_entry_attr_t attr_name,
825+
const sai_attribute_value_t& value,
826+
const sai_attribute_value_t& old_value,
827+
const P4AclRule& acl_rule,
828+
const P4AclRule& old_acl_rule);
814829

815830
} // namespace p4orch

orchagent/p4orch/tests/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ p4orch_tests_SOURCES = $(ORCHAGENT_DIR)/orch.cpp \
6060
fake_subscriberstatetable.cpp \
6161
fake_notificationconsumer.cpp \
6262
fake_table.cpp \
63+
fake_aclorch.cpp \
6364
p4oidmapper_test.cpp \
6465
p4orch_test.cpp \
6566
p4orch_util_test.cpp \

0 commit comments

Comments
 (0)