nsg-ethz / p4-utils

Extension to Mininet that makes P4 networks easier to build
GNU General Public License v2.0
175 stars 65 forks source link

fix issue table without match key #39

Closed Benature closed 2 years ago

Benature commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago
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.

Benature commented 2 years ago

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.