p4lang / behavioral-model

The reference P4 software switch
Apache License 2.0
531 stars 327 forks source link

how to achieve a timer in bmv2 #1220

Closed againwq closed 8 months ago

againwq commented 8 months ago

I want to achieve a timer to regularly send packets from the switch. The p4 program does not seem to have an implementation. It is possible to achieve it by in bmv2? And will this packets be processed by p4 program?

jafingerhut commented 8 months ago

To my knowledge, the BMv2 software switch does not have such a capability built into it today. One could be added, of course, but it would be a non-trivial effort from someone that already was, or became, at least somewhat knowledgeable of the BMv2 implementation code.

If the rate of packets that you want to regularly send is low enough, you may use P4Runtime API PacketOut messages from a P4Runtime API client to the switch, and have the subset of those packets that you want sent by the switch to some regular port.

antoninbas commented 8 months ago

If P4Runtime doesn't work for you, you can also add a dedicated port on the switch for packet injection and write a program / script to send raw packets on the corresponding veth interface. The packets injected this way will have their own ingress_port number, and you will be able to treat them differently in your P4 program if you want to.

againwq commented 8 months ago

Thanks for your answers, it was very useful for me