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

Support to read & write Register by PI #376

Open
MaoJianwei opened this issue Jun 9, 2018 · 26 comments
Open

Support to read & write Register by PI #376

MaoJianwei opened this issue Jun 9, 2018 · 26 comments

Comments

@MaoJianwei
Copy link
Contributor

MaoJianwei commented Jun 9, 2018

Updated status as of 2024-Nov-20:

So far no one has volunteered (nor been paid) to implement this feature. If you are interested in implementing it, please let us know by replying in a comment on this issue.

Note: To implement this fully generally would require supporting many P4 types of values as the element type of a P4 register array in the P4Runtime API, e.g. not just elements of type bit<W>, but also many other P4 types such as int<W>, enum values (both serializable and non-serializable kinds of enums), header types, struct types, header_union types, etc.

However, it would be quite useful if the implementation supported only type bit<W> as the element type of a register array -- that would be more than the implementation supports now, which is no types at all.

As a suggestion for a sequence that successive more general implementations might support, from smallest subset and easier, to larger subsets and more work:

  • Type bit<W> only - This would be a great starting point on which to build.
  • All of the above types plus type int<W>
  • All of the above types plus serializable enums
  • All of the above types plus non-serializable enums
  • All of the above types plus structs that contain members of any of the above types, but no nesting of structs within a struct
  • All of the above, plus nesting of structs inside of structs
  • All of the above, plus header types

In short, if you think you would be interested in implementing only the first one or two of these possibilities, but not the rest, that would be far more useful than the current state of affairs, where none are supported.


Original issue text created on 2018-Jun-08 by MaoJianwei:

Hi,
I found PI doesn't support to read & write Register.
Are there something blocking this work, and Is any team doing this work?
Thanks

@MaoJianwei
Copy link
Contributor Author

13d4953

@MaoJianwei
Copy link
Contributor Author

😃 Can I make a pull request if I finish this function?

@cc10512
Copy link

cc10512 commented Jun 10, 2018

Go for it! Please note that you must be a member of P4.org for us to accept your contribution.

@MaoJianwei
Copy link
Contributor Author

Thanks, @cc10512

I found this work is a little hard, Is there anyone going to do this work?

BTW, how to become a member of P4.org?

Thanks
Mao

@cc10512
Copy link

cc10512 commented Jun 11, 2018

Feel free to ask for guidance if you need help. Use the p4-dev mailing list or the Slack channel and people will be happy to help.

To become a member, see https://p4.org/join/

@jurijnota
Copy link

Hi, I am trying to read and write the registers of a p4 switch (which uses the Behavioral Model) from an external Python controller through P4Runtime. Although this issue is still open, given that two years have passed since then, I was wondering if nowadays there is a way of doing this or I should still rely on thrift to modify registers. What is the best way to write a control plane program that needs access to registers while using the P4Runtime? Should I go hybrid?
Thanks!

@jafingerhut
Copy link
Contributor

This issue is still open, because no one has implemented the feature. Volunteers are welcome. It isn't necessarily easy to understand the source code without some skill, patience, and time.

Another possibility is to inject packets from the controller with headers that your P4 program has been written so that it writes and/or reads the desired registers, and if reading is then sent back to the controller with the read data in it.

@MaoJianwei
Copy link
Contributor Author

MaoJianwei commented Mar 14, 2021

For ONOS controller, I have developed a draft version for Read & Write P4 register (BMv2).

For your reference:
https://gerrit.onosproject.org/c/onos/+/18581
https://jira.onosproject.org/browse/ONOS-7697

Welcome to coorperate and contribute, and we can sign our name and e-mails to this feature.

@MaoJianwei @jafingerhut @jurijnota @cc10512 @grg

@jafingerhut
Copy link
Contributor

@MaoJianwei The open source p4c compiler today will include instances of register extern objects in the P4Info files that it generates. See for example this test program: https://github.com/p4lang/p4c/blob/master/testdata/p4_16_samples/flowlet_switching-bmv2.p4

and its expected p4info output file: https://github.com/p4lang/p4c/blob/master/testdata/p4_16_samples_outputs/flowlet_switching-bmv2.p4.p4info.txt

That file was last modified in 2020-Apr, and I believe that p4c back end writing registers to p4info files has been working for longer than that.

I may not understand all of your descriptions of problems at the links you give, but wanted to ensure that you knew that at least that part has been working well for quite some time now.

The main part missing with the latest versions of the open source P4 development tools (but I have no knowledge of what ONOS requires), is the support for P4Runtime API register read/write messages.

@jfingerh
Copy link

jfingerh commented Jul 9, 2021

FYI, for anyone interested in developing changes to the code that add this feature, there is an every-2-weeks "PSA implementation status" meeting where developers interested in adding features and fixing issues in the open source P4 development tools meet to share status and ask questions of each other. Announcements of meeting times are sent to the p4-arch email list, which you can join here: https://lists.p4.org/list/p4-arch.lists.p4.org

@hyoukaLaw
Copy link

Can we now read values from registers through PI?
I'm now working with bmv2 + Mininet. I want to read values from registers and write values to registers but fail. However, when I read P4Runtime specifications, it says that "Registers are stateful memories that can be read and written by data plane during packet forwarding. Te control plane can also access registers at runtime".
Anyone can help?

@antoninbas
Copy link
Member

This issue is still open, it has not been implemented

@rickycraft
Copy link

Are there any updates on the state of this?

@jfingerh
Copy link

jfingerh commented Mar 8, 2022

If someone had either volunteered in their free time, or been paid to as part of their job, to implement this, I am pretty sure this issue would have been updated and/or closed as completed. To my knowledge no one has chosen to implement this yet.

@jfingerh
Copy link

jfingerh commented Mar 8, 2022

@rickycraft If this might be an issue you would be interested in volunteering to implement, please ask if you are looking for technical tips on going about it.

If you are interested in a workaround of the lack of this feature, one that uses PacketIn and PacketOut packets that perform the register reads/writes on behalf of the controller, and return read results in packets from the switch back to the controller, see this example P4 program and PTF test: https://github.com/jafingerhut/p4-guide/tree/master/ptf-tests/registeraccess

@rickycraft
Copy link

@jafingerhut unfortunatly i don't have the knoledge to implement this feature nor the time to learn how to do it.

Regarding the workaround, i will probably send a digest to the controller when is necessary, for my usecase is more efficient than a packet in/out.
Thank you for the update and the suggestions.

@ShivamPatelShivamPatel
Copy link

@jafingerhut Im interested in giving it a try. Been working with p4 for the past few months for school and have gotten ok at it, Im thinking this will be a nice summer project. Maybe tinker with it here and there until then in between my coursework and give it full attention starting mid May. Whatever tips and info you can provide I appreciate, I dont know what I dont know yet so throw at me what you think is relevant.

I found this question because I wanted to populate a register of powers of 10 without having to manually type it out in my p4 code, i.e. load it at runtime from the cli with some generated shell/python commands. And then I found this.

@jafingerhut
Copy link
Contributor

I am not sure, but I suspect that this talk by Antonin Bas on the open source implementation of the P4Runtime API in simple_switch / behavioral-model could be a good introduction: “P4 Runtime implementation in P4.org projects”: https://www.youtube.com/watch?v=YGdcZ6PYiUo

@MaoJianwei
Copy link
Contributor Author

MaoJianwei commented Jun 22, 2022

Hi, @ShivamPatelShivamPatel , you are welcome to implement this feature, and I have implemented a prototype here:
https://gerrit.onosproject.org/c/onos/+/18581
https://jira.onosproject.org/browse/ONOS-7697

As mentioned here: #376 (comment)

@Johnny-dai-git
Copy link

Hi,

After reading this thread, I am still wondering whether the support for write/read operation of p4runtime to the register complete ?

Or we need to implement by ourself follow the example provide by @MaoJianwei ?

I actually find the read support from the p4runtime_lib. However, I did not see any write support API.

Best Regards,

@jfingerh
Copy link

As far as I know, the code changes described by this issue have not been completed by anyone.

@Johnny-dai-git
Copy link

HI,

There may be another way to reset the register via the thrift port.

I have been discussing it with my advisor and we decided to make an example
for it.

Our code will be published once our research project is published.

The easiest way is that we use the simple_switch_cli to connect to the
simple_switch_grpc via the thrift port. We can do it remotely.

P4 Runtime and the simple_switch_cli can run at the same time. However, it
needs an extra process to run on the system.

Best Regards,

@dpinedaa
Copy link

Hello!
Can we now read values from registers through PI?
I'm currently working the P4 Stratum BMV2 and ONOS controller. I can add flows, look at indirect counter, but no luck with reading registers from the switch

@jafingerhut
Copy link
Contributor

No change in status -- as far as I know, no one has made the decision to implement this feature yet.

@dpinedaa
Copy link

Thank you for the prompt response. I tested my code with smple_switch and used the Simple_switch_cli and I was able to read the registers. Is there something similar to the simple_switch_CLI tool that works for P4 stratum?

@jafingerhut
Copy link
Contributor

simple_switch_CLI makes a TCP connection to the simple_switch_grpc process on a port where simple_switch_grpc communicates via a Thrift-based protocol that is custom to simple_switch_grpc, not using the P4Runtime API.

If you connect to the simple_switch_grpc process on a TCP port where it is listening as a P4Runtime API server, then even though there are P4Runtime API messages defined to read and write P4 register externs via the P4Runtime API protocol, the simple_switch_grpc process does not implement the correct behavior for responding to those messages. That is why this issue exists, and has not been closed.

If you want to make a Thrift connection to simple_switch_grpc, and send the same Thrift-based messages used by simple_switch_CLI to read and write registers, yes, you should be able to read and write registers that way.

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