Skip to content

Commit 910bfd4

Browse files
[ACL] Add default action_list for default ACL table type (sonic-net#2298)
What I did This PR is derived from sonic-net#2205 Fix sonic-net#10425 We were seeing ACL table creation failure on some platform because action_list is mandatory, while the action_list is not provided by aclorch. Apr 1 01:24:11.702608 str2-7050cx3-acs-03 ERR swss#orchagent: :- validate: Action list for table DATAACL is mandatory Apr 1 01:24:11.702608 str2-7050cx3-acs-03 ERR swss#orchagent: :- doAclTableTask: Failed to create ACL table DATAACL, invalid configuration Apr 1 01:24:11.702741 str2-7050cx3-acs-03 ERR swss#orchagent: :- validate: Action list for table EVERFLOW is mandatory Apr 1 01:24:11.702741 str2-7050cx3-acs-03 ERR swss#orchagent: :- doAclTableTask: Failed to create ACL table EVERFLOW, invalid configuration Apr 1 01:24:11.702926 str2-7050cx3-acs-03 ERR swss#orchagent: :- validate: Action list for table EVERFLOWV6 is mandatory Apr 1 01:24:11.702926 str2-7050cx3-acs-03 ERR swss#orchagent: :- doAclTableTask: Failed to create ACL table EVERFLOWV6, invalid configuration This PR fixed the issue by adding default action_list to the default ACL table type if not present. Why I did it Fix the ACL table creation issue. How I verified it Verified by running test_acl and test_everflow on Broadcom TD3 platform Signed-off-by: bingwang <[email protected]> Co-authored-by: syuan <[email protected]>
1 parent 4d6fa42 commit 910bfd4

File tree

3 files changed

+323
-0
lines changed

3 files changed

+323
-0
lines changed

orchagent/aclorch.cpp

+223
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,176 @@ static const acl_capabilities_t defaultAclActionsSupported =
153153
}
154154
};
155155

156+
static acl_table_action_list_lookup_t defaultAclActionList =
157+
{
158+
{
159+
// L3
160+
TABLE_TYPE_L3,
161+
{
162+
{
163+
ACL_STAGE_INGRESS,
164+
{
165+
SAI_ACL_ACTION_TYPE_PACKET_ACTION,
166+
SAI_ACL_ACTION_TYPE_REDIRECT
167+
}
168+
},
169+
{
170+
ACL_STAGE_EGRESS,
171+
{
172+
SAI_ACL_ACTION_TYPE_PACKET_ACTION,
173+
SAI_ACL_ACTION_TYPE_REDIRECT
174+
}
175+
}
176+
}
177+
},
178+
{
179+
// L3V6
180+
TABLE_TYPE_L3V6,
181+
{
182+
{
183+
ACL_STAGE_INGRESS,
184+
{
185+
SAI_ACL_ACTION_TYPE_PACKET_ACTION,
186+
SAI_ACL_ACTION_TYPE_REDIRECT
187+
}
188+
},
189+
{
190+
ACL_STAGE_EGRESS,
191+
{
192+
SAI_ACL_ACTION_TYPE_PACKET_ACTION,
193+
SAI_ACL_ACTION_TYPE_REDIRECT
194+
}
195+
}
196+
}
197+
},
198+
{
199+
// MIRROR
200+
TABLE_TYPE_MIRROR,
201+
{
202+
{
203+
ACL_STAGE_INGRESS,
204+
{
205+
SAI_ACL_ACTION_TYPE_MIRROR_INGRESS
206+
}
207+
},
208+
{
209+
ACL_STAGE_EGRESS,
210+
{
211+
SAI_ACL_ACTION_TYPE_MIRROR_EGRESS
212+
}
213+
}
214+
}
215+
},
216+
{
217+
// MIRRORV6
218+
TABLE_TYPE_MIRRORV6,
219+
{
220+
{
221+
ACL_STAGE_INGRESS,
222+
{
223+
SAI_ACL_ACTION_TYPE_MIRROR_INGRESS
224+
}
225+
},
226+
{
227+
ACL_STAGE_EGRESS,
228+
{
229+
SAI_ACL_ACTION_TYPE_MIRROR_EGRESS
230+
}
231+
}
232+
}
233+
},
234+
{
235+
// MIRROR_DSCP
236+
TABLE_TYPE_MIRROR_DSCP,
237+
{
238+
{
239+
ACL_STAGE_INGRESS,
240+
{
241+
SAI_ACL_ACTION_TYPE_MIRROR_INGRESS
242+
}
243+
},
244+
{
245+
ACL_STAGE_EGRESS,
246+
{
247+
SAI_ACL_ACTION_TYPE_MIRROR_EGRESS
248+
}
249+
}
250+
}
251+
},
252+
{
253+
// TABLE_TYPE_PFCWD
254+
TABLE_TYPE_PFCWD,
255+
{
256+
{
257+
ACL_STAGE_INGRESS,
258+
{
259+
SAI_ACL_ACTION_TYPE_PACKET_ACTION
260+
}
261+
},
262+
{
263+
ACL_STAGE_EGRESS,
264+
{
265+
SAI_ACL_ACTION_TYPE_PACKET_ACTION
266+
}
267+
}
268+
}
269+
},
270+
{
271+
// MCLAG
272+
TABLE_TYPE_MCLAG,
273+
{
274+
{
275+
ACL_STAGE_INGRESS,
276+
{
277+
SAI_ACL_ACTION_TYPE_PACKET_ACTION
278+
}
279+
},
280+
{
281+
ACL_STAGE_EGRESS,
282+
{
283+
SAI_ACL_ACTION_TYPE_PACKET_ACTION
284+
}
285+
}
286+
}
287+
},
288+
{
289+
// MUX
290+
TABLE_TYPE_MUX,
291+
{
292+
{
293+
ACL_STAGE_INGRESS,
294+
{
295+
SAI_ACL_ACTION_TYPE_PACKET_ACTION
296+
}
297+
},
298+
{
299+
ACL_STAGE_EGRESS,
300+
{
301+
SAI_ACL_ACTION_TYPE_PACKET_ACTION
302+
}
303+
}
304+
}
305+
},
306+
{
307+
// DROP
308+
TABLE_TYPE_DROP,
309+
{
310+
{
311+
ACL_STAGE_INGRESS,
312+
{
313+
SAI_ACL_ACTION_TYPE_PACKET_ACTION
314+
}
315+
},
316+
{
317+
ACL_STAGE_EGRESS,
318+
{
319+
SAI_ACL_ACTION_TYPE_PACKET_ACTION
320+
}
321+
}
322+
}
323+
}
324+
};
325+
156326
static acl_ip_type_lookup_t aclIpTypeLookup =
157327
{
158328
{ IP_TYPE_ANY, SAI_ACL_IP_TYPE_ANY },
@@ -301,6 +471,12 @@ const set<sai_acl_action_type_t>& AclTableType::getActions() const
301471
return m_aclAcitons;
302472
}
303473

474+
bool AclTableType::addAction(sai_acl_action_type_t action)
475+
{
476+
m_aclAcitons.insert(action);
477+
return true;
478+
}
479+
304480
AclTableTypeBuilder& AclTableTypeBuilder::withName(string name)
305481
{
306482
m_tableType.m_name = name;
@@ -1808,6 +1984,51 @@ AclTable::AclTable(AclOrch *pAclOrch) noexcept : m_pAclOrch(pAclOrch)
18081984

18091985
}
18101986

1987+
bool AclTable::addMandatoryActions()
1988+
{
1989+
SWSS_LOG_ENTER();
1990+
1991+
if (stage == ACL_STAGE_UNKNOWN)
1992+
{
1993+
return false;
1994+
}
1995+
1996+
if (!m_pAclOrch->isAclActionListMandatoryOnTableCreation(stage))
1997+
{
1998+
// No op if action list is not mandatory on table creation.
1999+
return true;
2000+
}
2001+
if (!type.getActions().empty())
2002+
{
2003+
// No change if action_list is provided
2004+
return true;
2005+
}
2006+
2007+
sai_acl_action_type_t acl_action = SAI_ACL_ACTION_TYPE_COUNTER;
2008+
if (m_pAclOrch->isAclActionSupported(stage, acl_action))
2009+
{
2010+
SWSS_LOG_INFO("Add counter acl action");
2011+
type.addAction(acl_action);
2012+
}
2013+
2014+
if (defaultAclActionList.count(type.getName()) != 0)
2015+
{
2016+
// Add the default action list
2017+
for (auto action : defaultAclActionList[type.getName()][stage])
2018+
{
2019+
if (m_pAclOrch->isAclActionSupported(stage, acl_action))
2020+
{
2021+
SWSS_LOG_INFO("Added default action for table type %s stage %s",
2022+
type.getName().c_str(),
2023+
((stage == ACL_STAGE_INGRESS)? "INGRESS":"EGRESS"));
2024+
type.addAction(action);
2025+
}
2026+
}
2027+
}
2028+
2029+
return true;
2030+
}
2031+
18112032
bool AclTable::validateAddType(const AclTableType &tableType)
18122033
{
18132034
SWSS_LOG_ENTER();
@@ -3949,6 +4170,8 @@ void AclOrch::doAclTableTask(Consumer &consumer)
39494170

39504171
newTable.validateAddType(*tableType);
39514172

4173+
newTable.addMandatoryActions();
4174+
39524175
// validate and create/update ACL Table
39534176
if (bAllAttributesOk && newTable.validate())
39544177
{

orchagent/aclorch.h

+8
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ typedef tuple<sai_acl_range_type_t, int, int> acl_range_properties_t;
113113
typedef map<acl_stage_type_t, AclActionCapabilities> acl_capabilities_t;
114114
typedef map<sai_acl_action_type_t, set<int32_t>> acl_action_enum_values_capabilities_t;
115115

116+
typedef map<acl_stage_type_t, set<sai_acl_action_type_t> > acl_stage_action_list_t;
117+
typedef map<string, acl_stage_action_list_t> acl_table_action_list_lookup_t;
118+
116119
class AclRule;
117120

118121
class AclTableMatchInterface
@@ -156,6 +159,8 @@ class AclTableType
156159
const set<sai_acl_range_type_t>& getRangeTypes() const;
157160
const set<sai_acl_action_type_t>& getActions() const;
158161

162+
bool addAction(sai_acl_action_type_t action);
163+
159164
private:
160165
friend class AclTableTypeBuilder;
161166

@@ -387,6 +392,9 @@ class AclTable
387392
bool validate();
388393
bool create();
389394

395+
// Add actions to ACL table if mandatory action list is required on table creation.
396+
bool addMandatoryActions();
397+
390398
// validate AclRule match attribute against rule and table configuration
391399
bool validateAclRuleMatch(sai_acl_entry_attr_t matchId, const AclRule& rule) const;
392400
// validate AclRule action attribute against rule and table configuration

tests/mock_tests/aclorch_ut.cpp

+92
Original file line numberDiff line numberDiff line change
@@ -1755,4 +1755,96 @@ namespace aclorch_test
17551755
// try to delete non existing acl rule
17561756
ASSERT_TRUE(orch->m_aclOrch->removeAclRule(tableId, ruleId));
17571757
}
1758+
1759+
sai_switch_api_t *old_sai_switch_api;
1760+
1761+
// The following function is used to override SAI API get_switch_attribute to request passing
1762+
// mandatory ACL actions to SAI when creating mirror ACL table.
1763+
sai_status_t getSwitchAttribute(_In_ sai_object_id_t switch_id,_In_ uint32_t attr_count,
1764+
_Inout_ sai_attribute_t *attr_list)
1765+
{
1766+
if (attr_count == 1)
1767+
{
1768+
switch(attr_list[0].id)
1769+
{
1770+
case SAI_SWITCH_ATTR_MAX_ACL_ACTION_COUNT:
1771+
attr_list[0].value.u32 = 2;
1772+
return SAI_STATUS_SUCCESS;
1773+
case SAI_SWITCH_ATTR_ACL_STAGE_INGRESS:
1774+
case SAI_SWITCH_ATTR_ACL_STAGE_EGRESS:
1775+
attr_list[0].value.aclcapability.action_list.count = 2;
1776+
attr_list[0].value.aclcapability.action_list.list[0]= SAI_ACL_ACTION_TYPE_COUNTER;
1777+
attr_list[0].value.aclcapability.action_list.list[1]=
1778+
attr_list[0].id == SAI_SWITCH_ATTR_ACL_STAGE_INGRESS ?
1779+
SAI_ACL_ACTION_TYPE_MIRROR_INGRESS : SAI_ACL_ACTION_TYPE_MIRROR_EGRESS;
1780+
attr_list[0].value.aclcapability.is_action_list_mandatory = true;
1781+
return SAI_STATUS_SUCCESS;
1782+
}
1783+
}
1784+
return old_sai_switch_api->get_switch_attribute(switch_id, attr_count, attr_list);
1785+
}
1786+
1787+
TEST_F(AclOrchTest, AclTableCreationWithMandatoryActions)
1788+
{
1789+
// Override SAI API get_switch_attribute to request passing mandatory ACL actions to SAI
1790+
// when creating mirror ACL table.
1791+
old_sai_switch_api = sai_switch_api;
1792+
sai_switch_api_t new_sai_switch_api = *sai_switch_api;
1793+
sai_switch_api = &new_sai_switch_api;
1794+
sai_switch_api->get_switch_attribute = getSwitchAttribute;
1795+
1796+
// Set platform env to enable support of MIRRORV6 ACL table.
1797+
bool unset_platform_env = false;
1798+
if (!getenv("platform"))
1799+
{
1800+
setenv("platform", VS_PLATFORM_SUBSTRING, 0);
1801+
unset_platform_env = true;
1802+
}
1803+
1804+
auto orch = createAclOrch();
1805+
1806+
for (const auto &acl_table_type : { TABLE_TYPE_MIRROR, TABLE_TYPE_MIRRORV6, TABLE_TYPE_MIRROR_DSCP })
1807+
{
1808+
for (const auto &acl_table_stage : { STAGE_INGRESS, STAGE_EGRESS })
1809+
{
1810+
// Create ACL table.
1811+
string acl_table_id = "mirror_acl_table";
1812+
auto kvfAclTable = deque<KeyOpFieldsValuesTuple>(
1813+
{ { acl_table_id,
1814+
SET_COMMAND,
1815+
{ { ACL_TABLE_DESCRIPTION, acl_table_type },
1816+
{ ACL_TABLE_TYPE, acl_table_type },
1817+
{ ACL_TABLE_STAGE, acl_table_stage },
1818+
{ ACL_TABLE_PORTS, "1,2" } } } });
1819+
orch->doAclTableTask(kvfAclTable);
1820+
auto acl_table = orch->getAclTable(acl_table_id);
1821+
ASSERT_NE(acl_table, nullptr);
1822+
1823+
// Verify mandaotry ACL actions has been added.
1824+
auto acl_actions = acl_table->type.getActions();
1825+
ASSERT_NE(acl_actions.find(SAI_ACL_ACTION_TYPE_COUNTER), acl_actions.end());
1826+
sai_acl_action_type_t action = strcmp(acl_table_stage, STAGE_INGRESS) == 0 ?
1827+
SAI_ACL_ACTION_TYPE_MIRROR_INGRESS : SAI_ACL_ACTION_TYPE_MIRROR_EGRESS;
1828+
ASSERT_NE(acl_actions.find(action), acl_actions.end());
1829+
1830+
// Delete ACL table.
1831+
kvfAclTable = deque<KeyOpFieldsValuesTuple>(
1832+
{ { acl_table_id,
1833+
DEL_COMMAND,
1834+
{} } });
1835+
orch->doAclTableTask(kvfAclTable);
1836+
acl_table = orch->getAclTable(acl_table_id);
1837+
ASSERT_EQ(acl_table, nullptr);
1838+
}
1839+
}
1840+
1841+
// Unset platform env.
1842+
if (unset_platform_env)
1843+
{
1844+
unsetenv("platform");
1845+
}
1846+
1847+
// Restore sai_switch_api.
1848+
sai_switch_api = old_sai_switch_api;
1849+
}
17581850
} // namespace nsAclOrchTest

0 commit comments

Comments
 (0)