Sending notification to controller to read the registers

Hello,
I am writing a P4 program in bmv2 and I am using registers. I want to send a notification to a controller after registers are reaching a specific threshold. Then the controller has to read the registers after receiving this notification. I have two questions:

  1. How can I send a notification to the controller. Is there any specific example?
  2. Which controller do I have to use?

Thanks,
Sara

To send a notification to the controller, the two most common techniques in P4 would be:

  • make a copy of the packet that you are processing while the condition to notify is detected, using the clone (also known as mirror) operation. Modify the copy of the packet to add any additional information in a custom to-controller header, so that the controller can easily determine the reason it is receiving this packet, and can respond as you wish. There is a small example P4 program and PTF test that use PacketIn and PacketOut between device and controller you can find here: p4-guide/ptf-tests/packetinout at master ¡ jafingerhut/p4-guide ¡ GitHub
  • use the Digest extern, which is designed to send a “small” message from the device to the controller, with fields that you can customize to whatever you want in your P4 program. I do not have an example handy to send you, but I know that Antonin Bas has sent out links before to a working P4 program and controller software written in Go (I think) that receives and processes Digest messages from the device.

Regarding the question “which controller do I have to use?”, you can write your own custom controller software if you wish, e.g. in Python if ease of development and debugging is your primary concern, and controller performance is lower on your list of concerns, or many other languages like C++, Java, Go, etc.

There are open source NOS (Networking Operating Systems) that you could attempt to adapt to your purposes, but there would be a lot of learning required (unless you are already familiar with them) just to get basic things working first, and then you would need to learn more to see if they support, and how, adding your own custom code to them. I would not recommend that unless it is something you want to invest significant time in (i.e. probably months of learning), or have a colleague working with you on a project who is already an expert on the topic.

1 Like

Thanks for your reply. I am trying to run the packetinout exmapl in p4-guide repository. However, I cannot run the python file, because of this error:

File “packetinout.py”, line 25, in
from google.rpc import code_pb2
ModuleNotFoundError: No module named ‘google.rpc’

I searched about it to find the solution and installed grcpio, and also grcp but it is not working. Can you please let me know what can be the problem?

P.S: I have the same problem with p4.v1
Thanks,
Sara

It depends upon how those Python packages were installed on your system. I do not know how you installed yours, but I do know that if you follow the instructions on this page for installing P4 open source dev tools, or downloading and running a pre-compiled Ubuntu Linux VM, that those programs do run without errors: p4-guide/README-install-troubleshooting.md at master ¡ jafingerhut/p4-guide ¡ GitHub

1 Like