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

how can I CRUD to p4 tables #34

Open
ghost opened this issue Mar 2, 2020 · 1 comment
Open

how can I CRUD to p4 tables #34

ghost opened this issue Mar 2, 2020 · 1 comment

Comments

@ghost
Copy link

ghost commented Mar 2, 2020

I want to filter an entry from tables, ,the only way I know is te.read() .then add an lambda function to match the key. Is there any way to read and filter an entry object?

And I also want to update one of parameter of action rather than override all parameters.
I can't find an elegant way to do this using p4rumtime-shell

@antoninbas
Copy link
Member

Your approach is pretty good, but I assume you want to filter entries on the server side instead - to avoid having to send all the entries from the server to the client.

The different server-side filtering issues are described in the P4Runtime spec: https://p4.org/p4runtime/spec/v1.1.0/P4Runtime-Spec.html#sec-table-wildcard-reads. If you just want to "match the key", it is very easy, just set the match key in the request and it will return either 0 (no match) or 1 entry (one entry has the provided key). Unfortunately, the other filtering options described in the spec (e.g. on the action id) are currently not supported by the reference P4Runtime server implementation. See this TODO.


Regarding your second question (update an action parameter). This is not supported by the P4Runtime protocol, i.e. the full action specification needs to be sent to the P4Runtime server and your entry will be "overwritten". However, I don't understand what you mean by "I can't find an elegant way to do this using p4runtime-shell". The following looks pretty elegant to me:

t = table_entry['<table_name>'](action='<action_name>')
# match fields
t.match['<f1>'] = ...
...
t.match['<fN>'] = ...
# action parameters
t.action['<p1>'] = ...
...
t.action['<pM>'] = ...
# insert the entry
t.insert
# modify one action parameter
t.action['<p1>'] = <new value>
t.modify

The above should work (please let me know if it doesn't), even though behind the scene it will "overwrite" the full entry. By which I mean that the full entry will be sent to the P4Runtime server, and , in the case of bmv2 at least, the entry will be overwritten (not just the memory area storing the action parameter).

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

No branches or pull requests

1 participant