-
Notifications
You must be signed in to change notification settings - Fork 94
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
Conversation
2. Implement set/get attribute
2. Correctly set/get mask for ternary key
/azp run |
Commenter does not have sufficient privileges for PR 651 in repo sonic-net/DASH |
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. |
dash-pipeline/SAI/src/p4meta.h
Outdated
|
||
template<typename T> | ||
static inline | ||
void get_value( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
dash-pipeline/SAI/src/p4meta.h
Outdated
_In_ const p4::v1::FieldMatch_LPM *t, | ||
_Out_ sai_attribute_value_t &value) | ||
{ | ||
assert (field == "ipPrefix"); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
/azp run |
Commenter does not have sufficient privileges for PR 651 in repo sonic-net/DASH |
Added generated sample code in PR description |
Thanks for sharing the details out! This makes the review much easier! |
There was a problem hiding this 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) |
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return pair_key; | ||
} | ||
|
||
std::pair<p4::v1::Action_Param*, p4::v1::Action_Param*> get_action_param_pair_from_p4_table_entry( |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string_ends_with
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix it at #653
There was a problem hiding this comment.
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.
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)
Following #648, continue to refactor libsai implementation for easier read and maintenance:
DashSai::set
andDashSai::get
, which fix the issue dash libsai does not support APIs set/get attribute of SAI object/entry #650Note: 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
p4meta
outbound_routing_group_meta_table
definitionSAI object entry
p4meta
outbound_routing_entry_meta_table
definition