@@ -115,6 +115,20 @@ static acl_stage_type_lookup_t aclStageLookUp =
115
115
{STAGE_EGRESS, ACL_STAGE_EGRESS }
116
116
};
117
117
118
+ static const acl_capabilities_t defaultAclActionsSupported =
119
+ {
120
+ {
121
+ ACL_STAGE_INGRESS,
122
+ {
123
+ SAI_ACL_ACTION_TYPE_PACKET_ACTION,
124
+ SAI_ACL_ACTION_TYPE_MIRROR_INGRESS
125
+ }
126
+ },
127
+ {
128
+ ACL_STAGE_EGRESS, {}
129
+ }
130
+ };
131
+
118
132
static acl_ip_type_lookup_t aclIpTypeLookup =
119
133
{
120
134
{ IP_TYPE_ANY, SAI_ACL_IP_TYPE_ANY },
@@ -2129,68 +2143,59 @@ void AclOrch::queryAclActionCapability()
2129
2143
sai_status_t status {SAI_STATUS_FAILURE};
2130
2144
sai_attribute_t attr;
2131
2145
vector<int32_t > action_list;
2132
- vector<FieldValueTuple> fvVector;
2133
2146
2134
2147
attr.id = SAI_SWITCH_ATTR_MAX_ACL_ACTION_COUNT;
2135
2148
status = sai_switch_api->get_switch_attribute (gSwitchId , 1 , &attr);
2136
- if (status != SAI_STATUS_SUCCESS)
2137
- {
2138
- SWSS_LOG_THROW (" AclOrch initialization failed: "
2139
- " failed to query maximum ACL action count" );
2140
- }
2141
-
2142
- const auto max_action_count = attr.value .u32 ;
2143
-
2144
- for (auto stage_attr: {SAI_SWITCH_ATTR_ACL_STAGE_INGRESS, SAI_SWITCH_ATTR_ACL_STAGE_EGRESS})
2149
+ if (status == SAI_STATUS_SUCCESS)
2145
2150
{
2146
- auto stage = (stage_attr == SAI_SWITCH_ATTR_ACL_STAGE_INGRESS ? ACL_STAGE_INGRESS : ACL_STAGE_EGRESS);
2147
- auto stage_str = (stage_attr == SAI_SWITCH_ATTR_ACL_STAGE_INGRESS ? STAGE_INGRESS : STAGE_EGRESS);
2148
- action_list.resize (static_cast <size_t >(max_action_count));
2149
-
2150
- attr.id = stage_attr;
2151
- attr.value .aclcapability .action_list .list = action_list.data ();
2152
- attr.value .aclcapability .action_list .count = max_action_count;
2151
+ const auto max_action_count = attr.value .u32 ;
2153
2152
2154
- status = sai_switch_api->get_switch_attribute (gSwitchId , 1 , &attr);
2155
- if (status != SAI_STATUS_SUCCESS)
2153
+ for (auto stage_attr: {SAI_SWITCH_ATTR_ACL_STAGE_INGRESS, SAI_SWITCH_ATTR_ACL_STAGE_EGRESS})
2156
2154
{
2157
- SWSS_LOG_THROW ( " AclOrch initialization failed: "
2158
- " failed to query supported %s ACL actions " , stage_str );
2159
- }
2155
+ auto stage = (stage_attr == SAI_SWITCH_ATTR_ACL_STAGE_INGRESS ? ACL_STAGE_INGRESS : ACL_STAGE_EGRESS);
2156
+ auto stage_str = (stage_attr == SAI_SWITCH_ATTR_ACL_STAGE_INGRESS ? STAGE_INGRESS : STAGE_EGRESS );
2157
+ action_list. resize ( static_cast < size_t >(max_action_count));
2160
2158
2161
- SWSS_LOG_INFO (" Supported %s action count %d:" , stage_str,
2162
- attr.value .aclcapability .action_list .count );
2159
+ attr.id = stage_attr;
2160
+ attr.value .aclcapability .action_list .list = action_list.data ();
2161
+ attr.value .aclcapability .action_list .count = max_action_count;
2163
2162
2164
- for (size_t i = 0 ; i < static_cast <size_t >(attr.value .aclcapability .action_list .count ); i++)
2165
- {
2166
- auto action = static_cast <sai_acl_action_type_t >(action_list[i]);
2167
- m_aclCapabilities[stage].insert (action);
2168
- SWSS_LOG_INFO (" %s" , sai_serialize_enum (action, &sai_metadata_enum_sai_acl_action_type_t ).c_str ());
2169
- }
2170
-
2171
- // put capabilities in state DB
2163
+ status = sai_switch_api->get_switch_attribute (gSwitchId , 1 , &attr);
2164
+ if (status == SAI_STATUS_SUCCESS)
2165
+ {
2172
2166
2173
- auto field = std::string ( " ACL_ACTIONS " ) + ' | ' + stage_str;
2174
- auto & acl_action_set = m_aclCapabilities[stage] ;
2167
+ SWSS_LOG_INFO ( " Supported %s action count %d: " , stage_str,
2168
+ attr. value . aclcapability . action_list . count ) ;
2175
2169
2176
- string delimiter;
2177
- ostringstream acl_action_value_stream;
2178
-
2179
- for (const auto & action_map: {aclL3ActionLookup, aclMirrorStageLookup, aclDTelActionLookup})
2180
- {
2181
- for (const auto & it: action_map)
2182
- {
2183
- auto saiAction = getAclActionFromAclEntry (it.second );
2184
- if (acl_action_set.find (saiAction) != acl_action_set.cend ())
2170
+ for (size_t i = 0 ; i < static_cast <size_t >(attr.value .aclcapability .action_list .count ); i++)
2185
2171
{
2186
- acl_action_value_stream << delimiter << it.first ;
2187
- delimiter = comma;
2172
+ auto action = static_cast <sai_acl_action_type_t >(action_list[i]);
2173
+ m_aclCapabilities[stage].insert (action);
2174
+ SWSS_LOG_INFO (" %s" , sai_serialize_enum (action, &sai_metadata_enum_sai_acl_action_type_t ).c_str ());
2188
2175
}
2189
2176
}
2190
- }
2177
+ else
2178
+ {
2179
+ SWSS_LOG_WARN (" Failed to query ACL %s action capabilities - "
2180
+ " API assumed to be not implemented, using defaults" ,
2181
+ stage_str);
2182
+ initDefaultAclActionCapabilities (stage);
2183
+ }
2191
2184
2192
- fvVector.emplace_back (field, acl_action_value_stream.str ());
2193
- m_switchTable.set (" switch" , fvVector);
2185
+ // put capabilities in state DB
2186
+ putAclActionCapabilityInDB (stage);
2187
+ }
2188
+ }
2189
+ else
2190
+ {
2191
+ SWSS_LOG_WARN (" Failed to query maximum ACL action count - "
2192
+ " API assumed to be not implemented, using defaults capabilities for both %s and %s" ,
2193
+ STAGE_INGRESS, STAGE_EGRESS);
2194
+ for (auto stage: {ACL_STAGE_INGRESS, ACL_STAGE_EGRESS})
2195
+ {
2196
+ initDefaultAclActionCapabilities (stage);
2197
+ putAclActionCapabilityInDB (stage);
2198
+ }
2194
2199
}
2195
2200
2196
2201
/* For those ACL action entry attributes for which acl parameter is enumeration (metadata->isenum == true)
@@ -2209,6 +2214,50 @@ void AclOrch::queryAclActionCapability()
2209
2214
aclDTelFlowOpTypeLookup);
2210
2215
}
2211
2216
2217
+ void AclOrch::putAclActionCapabilityInDB (acl_stage_type_t stage)
2218
+ {
2219
+ vector<FieldValueTuple> fvVector;
2220
+ auto stage_str = (stage == ACL_STAGE_INGRESS ? STAGE_INGRESS : STAGE_EGRESS);
2221
+
2222
+ auto field = std::string (" ACL_ACTIONS" ) + ' |' + stage_str;
2223
+ auto & acl_action_set = m_aclCapabilities[stage];
2224
+
2225
+ string delimiter;
2226
+ ostringstream acl_action_value_stream;
2227
+
2228
+ for (const auto & action_map: {aclL3ActionLookup, aclMirrorStageLookup, aclDTelActionLookup})
2229
+ {
2230
+ for (const auto & it: action_map)
2231
+ {
2232
+ auto saiAction = getAclActionFromAclEntry (it.second );
2233
+ if (acl_action_set.find (saiAction) != acl_action_set.cend ())
2234
+ {
2235
+ acl_action_value_stream << delimiter << it.first ;
2236
+ delimiter = comma;
2237
+ }
2238
+ }
2239
+ }
2240
+
2241
+ fvVector.emplace_back (field, acl_action_value_stream.str ());
2242
+ m_switchTable.set (" switch" , fvVector);
2243
+ }
2244
+
2245
+ void AclOrch::initDefaultAclActionCapabilities (acl_stage_type_t stage)
2246
+ {
2247
+ m_aclCapabilities[stage] = defaultAclActionsSupported.at (stage);
2248
+
2249
+ SWSS_LOG_INFO (" Assumed %s %zu actions to be supported:" ,
2250
+ stage == ACL_STAGE_INGRESS ? STAGE_INGRESS : STAGE_EGRESS,
2251
+ m_aclCapabilities[stage].size ());
2252
+
2253
+ for (auto action: m_aclCapabilities[stage])
2254
+ {
2255
+ SWSS_LOG_INFO (" %s" , sai_serialize_enum (action, &sai_metadata_enum_sai_acl_action_type_t ).c_str ());
2256
+ }
2257
+ // put capabilities in state DB
2258
+ putAclActionCapabilityInDB (stage);
2259
+ }
2260
+
2212
2261
template <typename AclActionAttrLookupT>
2213
2262
void AclOrch::queryAclActionAttrEnumValues (const string &action_name,
2214
2263
const acl_rule_attr_lookup_t & ruleAttrLookupMap,
@@ -2251,15 +2300,23 @@ void AclOrch::queryAclActionAttrEnumValues(const string &action_name,
2251
2300
SAI_OBJECT_TYPE_ACL_ENTRY,
2252
2301
acl_attr,
2253
2302
&values);
2254
- if (status ! = SAI_STATUS_SUCCESS)
2303
+ if (status = = SAI_STATUS_SUCCESS)
2255
2304
{
2256
- SWSS_LOG_THROW (" sai_query_attribute_enum_values_capability failed for %s" ,
2257
- action_name.c_str ());
2305
+ for (size_t i = 0 ; i < values.count ; i++)
2306
+ {
2307
+ m_aclEnumActionCapabilities[acl_action].insert (values.list [i]);
2308
+ }
2258
2309
}
2259
-
2260
- for (size_t i = 0 ; i < values.count ; i++)
2310
+ else
2261
2311
{
2262
- m_aclEnumActionCapabilities[acl_action].insert (values.list [i]);
2312
+ SWSS_LOG_WARN (" Failed to query enum values supported for ACL action %s - " ,
2313
+ " API is not implemented, assuming all values are supported for this action" ,
2314
+ action_name.c_str ());
2315
+ /* assume all enum values are supported */
2316
+ for (size_t i = 0 ; i < meta->enummetadata ->valuescount ; i++)
2317
+ {
2318
+ m_aclEnumActionCapabilities[acl_action].insert (meta->enummetadata ->values [i]);
2319
+ }
2263
2320
}
2264
2321
#else
2265
2322
/* assume all enum values are supported untill sai object api is available */
0 commit comments