behavioral-model icon indicating copy to clipboard operation
behavioral-model copied to clipboard

How to verify the functions of my P4 program?

Open KuiWei004 opened this issue 5 years ago • 6 comments

hello, everyone!

I have suceed running my P4 program on simple_switch, but I have no idea how to verify the function. Specifically, I do not know how to send packet to the ports of simple_switch in runtime, also how to capture the packet from the output port. I appreciate your help!

KuiWei004 avatar Aug 31 '20 07:08 KuiWei004

This README walks through using Scapy to construct and send packets to a running simple_switch process, and how to run one tcpdump process per output port to show the contents of packets that are sent to those ports. You can also run tcpdump to record packets to a pcap file, rather than showing them 'live' as they appear on the ports, depending upon your preference.

https://github.com/jafingerhut/p4-guide/blob/master/demo1/README.md

The methods described in that document are reasonable for interactive testing of a P4 program. They are not intended for automated testing of a P4 program without human interaction. Tools like PTF can better serve that purpose, if that is what you want to do: https://github.com/p4lang/ptf. But I would recommend the interactive method first if you are just starting out testing a P4 program.

jafingerhut avatar Aug 31 '20 13:08 jafingerhut

many many thanks ! I will try tomorrow!

KuiWei004 avatar Aug 31 '20 14:08 KuiWei004

@jafingerhut I see the README mentioned above. Now I have another question. For the function 'sendp(pkt, intf)', the pkt will be the input of the intf or the output of it. If the pkt is the output of the intf, how can this pkt be sent to the ingress path of the P4 simple_switch?

KuiWei004 avatar Aug 31 '20 14:08 KuiWei004

When you follow the directions in that README, the sendp() will cause the packet to be sent to the indicated 'veth' interface, which will then become an input packet to simple_switch, and will perform ingress processing with the ingress_port assigned a number equal to the interface number that 'veth' interface is connected to. That port number is defined by the '-i' command line option to simple_switch, not by the '' part of 'veth' interface name.

jafingerhut avatar Aug 31 '20 15:08 jafingerhut

Please follow below steps in order the test your p4 program using simple switch:-

  1. create your on p4 pipeline.
  2. Compile it using p4c.
  3. Start simple_switch with number of veth interfaces along your p4 pipeline.
  4. Add the rules in your routing table.
  5. And then run the traffic on the veth ingress interfaces.

shobhitkumargupta avatar Sep 30 '21 12:09 shobhitkumargupta

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment, or this will be closed in 180 days

github-actions[bot] avatar Sep 01 '22 00:09 github-actions[bot]