66#include < string>
77#include < vector>
88
9+ #include " acltable.h"
910#include " p4orch/p4orch_util.h"
1011#include " return_code.h"
1112extern " C"
@@ -17,11 +18,6 @@ extern "C"
1718namespace 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.
2622enum 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
160156struct 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
177173struct 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>;
260256using acl_packet_action_lookup_t = std::map<std::string, sai_packet_action_t >;
261257using acl_packet_color_lookup_t = std::map<std::string, sai_packet_color_t >;
262258using 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
733736bool 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
773776ReturnCode 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
777783bool 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
784790ReturnCode 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
790800bool 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.
799810ReturnCode 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
0 commit comments