Read counter via P4runtime shell script

Hey there,

I’m wondering how to get the counter value via P4runtime shell API in my controller which is written in Python. Is there any example to show the reading process? Thanks in advance!

Best regards,
Mel

If you mean that you are using the p4runtime-shell project as your means of interacting with the network device using the P4Runtime API, then there are several documents in the ‘docs’ directory of that project’s Github repo that I have found helpful, including this one especially relevant to your question: p4runtime-shell/read_table_entry_counter.md at main · p4lang/p4runtime-shell · GitHub

There is also a tested-working PTF test written in Python using the p4runtime-shell Python module that reads counters here: p4-guide/demo2.py at master · jafingerhut/p4-guide · GitHub

Really thanks for your answer, and sorry for my late reply.

I looked through the two examples in your reply. It seems they use the direct counter associated with match-action tables, whereas I use the indexed counters in my P4 program to extract some traffic statistics, like count the number of incoming packet.

Previously I use this API p4runtime_lib to establish the connection between controller and switch. The p4runtime_lib API supports read counter value by giving counter name and index. Is there also a method in P4runtime shell to support read the value of indexed counter?

As far as I know, a possible solution is using PacketIO to read the counter value, but it makes the project a little bit complicated.

@andyfingerhut : Do we have a mechanism to read the hardware statistics/counters from P4Runtime shell through a target specific extern ? For example, to dump all the available counters from NIC block . Could you point me to the relevant example or documentation for the same ?

Target-specific externs are just that: target-specific. What control plane APIs they support depends upon who implemented them. If you have a particular example in mind from an Intel product, feel free to give more details at john.andy.fingerhut@intel.com and I’ll see what I can find out. If you have a particular example in mind from another company’s product, I would recommend asking whoever supports the product. If you have an open source project in mind, feel free to ask here, giving the specific project and extern you have in mind, and perhaps someone here can answer.