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.