Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libsai] Implement APIs set/get attribute #651

Merged
merged 4 commits into from
Dec 23, 2024

Conversation

jimmyzhai
Copy link
Collaborator

@jimmyzhai jimmyzhai commented Dec 16, 2024

Following #648, continue to refactor libsai implementation for easier read and maintenance:

  1. Avoid using compilated j2 template as best
  2. Use c++ code directly to express the logic of API implementation, based on p4 table metadata info (p4meta.[h, cpp])
  3. Implement APIs set/get attribute by using common DashSai::set and DashSai::get, which fix the issue dash libsai does not support APIs set/get attribute of SAI object/entry #650
  4. Update libsai test (vnet_out.cpp) to cover sanity test of APIs set/get attribute

Note: To refactor APIs create/remove with current approach in next PR.

The generated sample code of APIs set/get attribute is as below:

  • SAI object objectID
    image
    p4meta outbound_routing_group_meta_table definition
    image

  • SAI object entry
    image
    p4meta outbound_routing_entry_meta_table definition
    image

@mssonicbld
Copy link

/azp run

Copy link

Commenter does not have sufficient privileges for PR 651 in repo sonic-net/DASH

@jimmyzhai jimmyzhai requested a review from r12f December 16, 2024 16:17
@r12f
Copy link
Collaborator

r12f commented Dec 18, 2024

Hi Junhua, do you mind to update the PR description on how the generated code looks like? It will help people to understand this PR better.


template<typename T>
static inline
void get_value(
Copy link
Collaborator

Choose a reason for hiding this comment

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

better rename the functions. the names are too vague.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed. Update functions to have a meaningful name.

_In_ const p4::v1::FieldMatch_LPM *t,
_Out_ sai_attribute_value_t &value)
{
assert (field == "ipPrefix");
Copy link
Collaborator

Choose a reason for hiding this comment

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

move non-template to p4meta.cpp

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed.

2. Move non-template function implementations to p4meta.cpp
@mssonicbld
Copy link

/azp run

Copy link

Commenter does not have sufficient privileges for PR 651 in repo sonic-net/DASH

@jimmyzhai
Copy link
Collaborator Author

Hi Junhua, do you mind to update the PR description on how the generated code looks like? It will help people to understand this PR better.

Added generated sample code in PR description

@r12f
Copy link
Collaborator

r12f commented Dec 19, 2024

Hi Junhua, do you mind to update the PR description on how the generated code looks like? It will help people to understand this PR better.

Added generated sample code in PR description

Thanks for sharing the details out! This makes the review much easier!

Copy link
Collaborator

@r12f r12f left a comment

Choose a reason for hiding this comment

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

looks good to me! commends can be solved in the next PR, all minor and non-blocking.

{
DASH_LOG_ENTER();

if (!m_apiInitialized)
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe add another macro here, say DASH_CHECK_API_INITIALIZED_RET(retcode)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fix it at #653


MUTEX;

auto range = m_tableEntryMap.equal_range(id);
Copy link
Collaborator

Choose a reason for hiding this comment

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

emmmm, do we really need a multi-map here? each object id should be unique with the object id encoding, am I right? @kcudnik

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@r12f , map is enough. fix it at #653

return pair_key;
}

std::pair<p4::v1::Action_Param*, p4::v1::Action_Param*> get_action_param_pair_from_p4_table_entry(
Copy link
Collaborator

Choose a reason for hiding this comment

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

get_action_param_with_is_v6_flag_from_p4_table_entry

Copy link
Collaborator

Choose a reason for hiding this comment

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

also use out parameter will be more explicit, the pair.second is very unintuitive to read.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fix it at #653

return pair_param;
}

bool string_has_suffix(const std::string &str, const std::string &suffix)
Copy link
Collaborator

Choose a reason for hiding this comment

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

string_ends_with

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fix it at #653

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@r12f , string::ends_with is since c++20. Anyway, let's name it our string_ends_with.

@r12f r12f merged commit 65b42a8 into sonic-net:main Dec 23, 2024
4 checks passed
r12f pushed a commit that referenced this pull request Jan 8, 2025
Following #651, refactor APIs
create/remove for easier read and maintenance:

1. Use common code `DashSai::create` and `DashSai::remove` to implement
them for all SAI objects/entries
2. Fix issue #436, now only 1
SAI object is created for multiple bmv2 objects (each bmv2 object as a
p4 table entry in p4 table for each stage).
3. Fix issue #654

The generated sample code of APIs create/remove attribute is as below:

- SAI object objectID

![image](https://github.com/user-attachments/assets/1f300b7a-7750-43df-89e2-71570801cd06)

- SAI object entry

![image](https://github.com/user-attachments/assets/d16a3bcc-0a41-4fd1-a23a-6f6663761a67)

For the case of acl rule object, one acl rule is inserted into multiple
p4 tables in different stages. These p4 stage tables are same and the
only difference is `table id` and `table action id` in table entry,
captured in struct P4MetaSiblingTable:

```
    struct P4MetaSiblingTable
    {
        uint32_t id;
        // action enum id -> p4 action id
        std::map<uint32_t, uint32_t> actions;
    };
```
The generated code of sibling tables for acl rule is as below:

![image](https://github.com/user-attachments/assets/4dbf0725-1ca5-488f-bf08-62b032c2f66a)
@jimmyzhai jimmyzhai deleted the libsai_set_get branch January 13, 2025 12:36
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