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

fix issue table without match key #39

Merged
merged 1 commit into from
Jun 26, 2022
Merged

Conversation

Benature
Copy link
Contributor

fix for issue #38

I found that when p4-utils load p4 json, it ignores the table whose key field is empty. Therefore, I add a condition to add such tables.

@Benature
Copy link
Contributor Author

In p4 json, I found that there are some tables that are not defined by the user (me), like tbl_int313. The user-defined tables are all started with the pipeline name.

For example, my egress name is MyEgress. In this pipeline I define a table named test_tbl, so in json the table's name is MyEgress.test_tbl. So I add a condition to exclude the tables that are not defined by users.

if j_table["name"].startswith(j_pipeline["source_info"]["source_fragment"]+"."):

Here the j_pipeline["source_info"]["source_fragment"] is MyEgress in my example.

@Benature
Copy link
Contributor Author

Here is my test.

After I start p4run, I use simple_switch_CLI to check test_tbl. Its default action is NoAction.

user@v:~$ simple_switch_CLI
Obtaining JSON from switch...
Done
Control utility for runtime P4 table manipulation
RuntimeCmd: table_dump test_tbl
==========
TABLE ENTRIES
==========
Dumping default entry
Action entry: NoAction - 
==========

Then I run a python script with

controller.table_set_default("test_tbl", "test_action", ['1'])

Check this table again, its default action is changed successfully.

user@v:~$ simple_switch_CLI
Obtaining JSON from switch...
Done
Control utility for runtime P4 table manipulation
RuntimeCmd: table_dump test_tbl
==========
TABLE ENTRIES
==========
Dumping default entry
Action entry: MyEgress.test_action - 01
==========

The table defined in p4 is

    action test_action(bit<32> arg) {
        meta.test = arg;
    }
    table test_tbl{
        key = {}
        actions = {
            test_action;
            NoAction;
        }
        default_action = NoAction;
    }

@edgar-costa
Copy link
Collaborator

In p4 json, I found that there are some tables that are not defined by the user (me), like tbl_int313. The user-defined tables are all started with the pipeline name.

For example, my egress name is MyEgress. In this pipeline I define a table named test_tbl, so in json the table's name is MyEgress.test_tbl. So I add a condition to exclude the tables that are not defined by users.

if j_table["name"].startswith(j_pipeline["source_info"]["source_fragment"]+"."):

Here the j_pipeline["source_info"]["source_fragment"] is MyEgress in my example.

Yes, some tables are defined by the compiler. This is a trick they do when you call an action directly in the main control. Basically they wrap it with one of those "non defined" tables.

@edgar-costa
Copy link
Collaborator

edgar-costa commented Jun 26, 2022

j_pipeline["source_info"]["source_fragment"]

What if the tables defined by the compiler also get the form 'MyIngres/Egress' + '.' In the future?

In any case, I think this PR won't hurt anything so I will accept it.

Thanks a lot for providing it.

@edgar-costa edgar-costa merged commit 6348152 into nsg-ethz:master Jun 26, 2022
@Benature
Copy link
Contributor Author

I don't know p4 has the rule to require the compiler to distinguish the user-defined table and compiler-defined table. If not, I think the same as you, usually users don't know the compiler-defined table's name, so they will not change the related fields. Unless there is typo.

Thank you for your acceptance.

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.

2 participants