Skip to content

[dash]: ACL orchagent#2470

Merged
Pterosaur merged 23 commits intosonic-net:dashfrom
Pterosaur:dash_acl
Jan 5, 2023
Merged

[dash]: ACL orchagent#2470
Pterosaur merged 23 commits intosonic-net:dashfrom
Pterosaur:dash_acl

Conversation

@Pterosaur
Copy link
Contributor

@Pterosaur Pterosaur commented Sep 28, 2022

What I did
Add DASH ACL orchagent implementation.

Why I did it
DASH needs ACL function.

How I verified it

$ sudo pytest -sv --num-ports=2 test_dash_acl.py --pdb
================================ test session starts ================================
platform linux -- Python 3.8.10, pytest-4.6.2, py-1.10.0, pluggy-0.13.1 -- /usr/bin/python3
cachedir: .pytest_cache
plugins: flaky-3.7.0
collected 4 items

test_dash_acl.py::TestAcl::test_acl_flow PASSED
test_dash_acl.py::TestAcl::test_acl_group PASSED
test_dash_acl.py::TestAcl::test_acl_rule PASSED
test_dash_acl.py::test_nonflaky_dummy PASSED

============================= 4 passed in 54.83 seconds =============================

Details if related

@Pterosaur Pterosaur changed the base branch from master to dash September 28, 2022 15:14
@Pterosaur Pterosaur changed the title Dash acl [dash]: ACL orchagent Oct 11, 2022
@Pterosaur Pterosaur marked this pull request as ready for review October 11, 2022 09:37
@Pterosaur Pterosaur requested a review from prsunny as a code owner October 11, 2022 09:37
@Pterosaur Pterosaur changed the base branch from dash to master October 25, 2022 06:04
@Pterosaur Pterosaur changed the base branch from master to dash October 25, 2022 06:04
@Pterosaur Pterosaur force-pushed the dash_acl branch 11 times, most recently from 0cc18b9 to c88ec82 Compare October 25, 2022 18:41
@Pterosaur Pterosaur force-pushed the dash_acl branch 5 times, most recently from 60901af to 2d35a7e Compare October 26, 2022 15:59
attrs.back().id = SAI_DASH_ACL_RULE_ATTR_DASH_ACL_GROUP_ID;
attrs.back().value.oid = acl_group->m_dash_acl_group_id;

acl_rule.m_status = m_dash_acl_rule_bulker.create_entry(&acl_rule.m_dash_acl_rule_id, static_cast<uint32_t>(attrs.size()), attrs.data());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question as above re: bulk operations

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}
else
{
getAclGroup(group_id)->m_rule_count--;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be a good idea to add an error log here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Collaborator

@prsunny prsunny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You would need to maintain a ref count b/w eni and acl group to prevent deleting group while it is already bind to an ENI.

else
{
// Update the ACL group's attributes
for (const auto &attr : attrs)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACL group update is for what scenario? Is this only to set the ip_version, say changing from ipv4 to ipv6? if so, its not a valid case. can you check if this is required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I removed the update block.

// The member rules of group should be removed first
if (acl_group->m_rule_count != 0)
{
SWSS_LOG_WARN("ACL group %s still has %d rules", key.c_str(), acl_group->m_rule_count);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change this to info, else this log will be continuously generated. Please address this for all task_retries.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

// The member rules of group should be removed first
if (acl_group->m_rule_count != 0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should also check if this group is 'bind' to some ENI. If so, we cannot delete the group. User must first unbind the group before deleting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Add a ref count to check that.

auto acl_group = getAclGroup(group_id);
if (acl_group == nullptr)
{
SWSS_LOG_WARN("ACL group %s doesn't exist, waiting for group creating before creating rule %s", group_id.c_str(), rule_id.c_str());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As suggested, please change to INFO

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

// If the attributes don't have default value, just skip and wait for the user to set the value at the next message
if (!acl_rule.m_protocols)
{
const static vector<uint8_t> all_protocols = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is prone to error and hard to see if you missed some value. Suggest generating it through a lambda function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

bool update_action = false;
update_action |= updateValue(data, "action", acl_rule.m_action);
update_action |= updateValue(data, "terminating", acl_rule.m_terminating);
if (update_action || (acl_rule.m_action && acl_rule.m_terminating && !is_existing))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that is_existing is repeated all around? Please move this to a section for new create vs set.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is an optimization I want.
I would always only pass these updated attributes to the SAI. But how can I know which attributes are updated if I move this to another section? I have no idea only if I introduce another repeated code to check and add them one by one to the attrs.

}
else
{
// Update the ACL group's attributes
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACL Rule's attribute -> Typo

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


bool is_existing = acl_rule.m_dash_acl_rule_id != SAI_NULL_OBJECT_ID;

if (!is_existing)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about ref count in this case? do we need to decrement?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, a ACL rule can only be added to only one ACL group. So that the ref count is always one. If yes, why we need a count to record it?

auto eni_entry = m_dash_orch->getEni(eni);
if (eni_entry == nullptr)
{
SWSS_LOG_WARN("eni %s cannot be found", eni.c_str());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to INFO

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

attr.id = getSaiStage(direction, *(acl_group->m_ip_version), stage);
attr.value.oid = acl_group->m_dash_acl_group_id;
}
else
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would be a case where updateValue fails?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the input string isn't valid or the new value equals than the old one.

@Pterosaur Pterosaur marked this pull request as draft December 22, 2022 14:07
@Pterosaur Pterosaur force-pushed the dash_acl branch 9 times, most recently from bbf5032 to 2466354 Compare December 23, 2022 09:08
Signed-off-by: Ze Gan <ganze718@gmail.com>
@Pterosaur Pterosaur force-pushed the dash_acl branch 6 times, most recently from 6fbe409 to 22552e4 Compare December 24, 2022 15:53
Signed-off-by: Ze Gan <ganze718@gmail.com>
else
{
SWSS_LOG_ERROR(
"Unknown task : %s - %s",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be a good idea to include the actual task/key in this message as well to help with debugging

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe all actual tasks/key have been logged in /var/log/swss/swss.rec by lib swsscommon so that we don't need repeated recording.

if (task_status == task_need_retry)
{
SWSS_LOG_DEBUG(
"Task %s - %s need retry",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

{
if (task_status != task_success)
{
SWSS_LOG_WARN("Task %s - %s fail",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

else
{
SWSS_LOG_DEBUG(
"Task %s - %s success",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants