Hi everyone,
I am trying to write a P4 program and I want to use the ‘meter_array_set_rates’ command. However, I am not sure how to call it from within my P4 program. Can anyone explain to me how to do this?
Thanks in advance!
Hi everyone,
I am trying to write a P4 program and I want to use the ‘meter_array_set_rates’ command. However, I am not sure how to call it from within my P4 program. Can anyone explain to me how to do this?
Thanks in advance!
I am guessing you are referring to the command meter_array_set_rates
that can be used from inside of the simple_switch_CLI
program. That program is an interactive controller, that can make changes to the configuration of P4 objects from a controller perspective. Such changes can be made from a control plane program, which can be written in any general purpose programming language, e.g. Python, Java, C++, etc. Control plane APIs cannot be called from within the P4 program.
Thanks for your response, @andyfingerhut . I now understand that the ‘meter_array_set_rates’ command cannot be called directly from within the P4 program. However, I am still interested in learning how to set meter rates within the P4 program. Specifically, I am interested in how to change the meter rates over time within the P4 program. Can you provide any guidance on this? Thank you.
You can write any kind of control plane program you want, that changes configurations of P4 objects like meters under any conditions you can imagine. I would start simple, e.g. pick a general purpose language you are comfortable writing in such as Python, C++, or Java, and learn how to send messages to the simple_switch or simple_switch_grpc process that make the configuration changes you are interested in. Some very simple Python programs that add simple table entries are available in this directly, particularly those described in README-p4runtime.md and ptf/demo1.py inside the demo1 directory here: p4-guide/demo1 at master · jafingerhut/p4-guide · GitHub
There are also example small Python control plane programs as part of the tutorials repository here: GitHub - p4lang/tutorials: P4 language tutorials
I am not aware of any that already show examples of configuring meter rates, but if not, hopefully by trying out the existing examples, and looking at the ways to configure meters in the P4Runtime API specification, you might be able to learn how to create the necessary write request messages that configure meter rates.
Thank you so much for your helpful guidance, @andyfingerhut I will definitely make use of the resources you provided and try out the example control plane programs to learn how to configure meter rates in the P4 program. Your assistance is greatly appreciated.