Skip to content

Commit

Permalink
[libsai] Re-implement APIs create/remove (#653)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
jimmyzhai authored Jan 8, 2025
1 parent 65b42a8 commit 88a4771
Show file tree
Hide file tree
Showing 8 changed files with 582 additions and 384 deletions.
320 changes: 284 additions & 36 deletions dash-pipeline/SAI/src/dashsai.cpp

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions dash-pipeline/SAI/src/dashsai.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,29 @@ namespace dash
_Inout_ sai_attribute_t *attr_list);

// QUAD api implementation, using p4 meta table
sai_status_t create(
_In_ const P4MetaTable &meta_table,
_In_ sai_object_type_t objectType,
_Out_ sai_object_id_t* objectId,
_In_ sai_object_id_t switchId,
_In_ uint32_t attr_count,
_In_ const sai_attribute_t *attr_list);

sai_status_t create(
_In_ const P4MetaTable &meta_table,
_In_ sai_object_type_t objectType,
_Inout_ std::shared_ptr<p4::v1::TableEntry> matchActionEntry,
_In_ uint32_t attr_count,
_In_ const sai_attribute_t *attr_list);

sai_status_t remove(
_In_ const P4MetaTable &meta_table,
_In_ sai_object_id_t objectId);

sai_status_t remove(
_In_ const P4MetaTable &meta_table,
_Inout_ std::shared_ptr<p4::v1::TableEntry> matchActionEntry);

sai_status_t set(
_In_ const P4MetaTable &meta_table,
_In_ sai_object_id_t objectId,
Expand Down Expand Up @@ -126,6 +149,14 @@ namespace dash
_In_ sai_object_id_t id,
_Out_ std::shared_ptr<p4::v1::TableEntry> &entry);

private: // private helper methods

void mutateSiblingTablesEntry(
_In_ const P4MetaTable &meta_table,
_In_ std::shared_ptr<p4::v1::TableEntry>,
_In_ p4::v1::Update_Type updateType,
_In_ uint32_t action_id = 0);

public: // default attributes helper

static std::vector<sai_attribute_t> populateDefaultAttributes(
Expand Down
Loading

0 comments on commit 88a4771

Please sign in to comment.