[P4-dev] Does simple router support user-defined p4 source file? If so, how to use it correctly?

Wu, Xiaoban Xiaoban_Wu at student.uml.edu
Thu Aug 10 22:43:29 EDT 2017

Hi Antonin,

Thanks very much for your reply.

After I read the link https://github.com/p4lang/behavioral-model/commit/2106979fb700792dca1a3aed7351899acae7a696, I realize that there is a mismatch between the simple_router.cpp and my forward.p4 file.

In the simple_router.cpp it uses the egress_port, while egress_spec in the forward.p4. After I replace the egress_spec with egress_port in my forward.p4, it works perfectly.

Warm regards,


From: Antonin Bas <antonin at barefootnetworks.com>
Sent: Thursday, August 10, 2017 2:45:55 PM
To: Wu, Xiaoban
Cc: p4-dev at lists.p4.org
Subject: Re: [P4-dev] Does simple router support user-defined p4 source file? If so, how to use it correctly?


For the vast majority of people, simple_switch is the only bmv2 target they want to be using. You CAN write your own P4 programs for simple_router but they MAY not be compatible with simple_switch. In other words, a P4 program that runs correctly on simple_router may not run correctly on simple_switch, and vice-versa.
simple_router should be ignored by most people. It is just meant as an example to demonstrate how bmv2 can be used to implement different switch architectures. P4 programs written for a given architecture are generally not compatible with other architectures. I would recommend running the P4_16 specification (https://p4lang.github.io/p4-spec/docs/P4-16-v1.0.0-spec.html) if you are not familiar with the notion of architecture.

About your specific problem:
simple_router was updated in bmv2 version 1.6 to be more compatible with simple_switch (https://github.com/p4lang/behavioral-model/commit/2106979fb700792dca1a3aed7351899acae7a696), since the differences between the 2 were confusing for a lot of people. If you update to a more recent version (1.5 is pretty old), you may be able to run your forward.p4 program on both targets. However, I would not recommend it, stick to simple_switch unless you have a very good reason to use simple_router.



On Wed, Aug 9, 2017 at 10:13 PM, Wu, Xiaoban <Xiaoban_Wu at student.uml.edu<mailto:Xiaoban_Wu at student.uml.edu>> wrote:


I am trying to run the behavioral model simple router https://github.com/p4lang/behavioral-model/tree/master/targets/simple_router, it is of version 1.5.0, but I am facing an unknown issue.

Traffic flow: eth1 at machine1-->eth1 at machine2-->eth2 at machine2-->eth2 at machine1

The simple router is running on machine2, with "sudo ./simple_router -i 0 at eth1 -i 1 at eth2 forward.json", where the forward.json is generated by "python /p4c-bm/p4c_bm/__main__.py --json forward.json forward.p4". The p4c-bm is also of version 1.5.0. The forward.p4 is in the attached.

After the simple router is running, I open another terminal on machine2 and run "./runtime_CLI < commands.txt", where the commands.txt in the attached.

Then I use scapy on machine1 to send packet out of interface eth1,

p = Ether(dst="aa:bb:cc:dd:ee:ff", src="aa:bb:cc:dd:ee:ff") / IP(src="", dst="") / TCP() / "aaaaaaaaaaaaaaaaaaa"

sendp(p, iface = "eth1")

Then on machine1, I use "tcpdump -i eth2" to monitor the traffic. However, I see nothing.

Some debugging info,

(1) I have tested the attached forward.p4 and commands.txt in the simple_switch, it works just fine.

(2)In the function "transmit_thread" of the simple_router.cpp

    1.The "packet->get_egress_port()" always return 0.

    2. If I manually change it with 1, then "transmit_fn(1, packet->data(), packet->get_data_size())" just works fine, since I can see the traffic with "tcpdump -i eth2" on machine2. This means all the connections are good.

Hence I am wondering if some issues are in the ingress match-action pipeline, but I could not find a clue. Hence I am wondering if the simple router support user-defined p4 source file?

Can anybody please explain what are the main differences between simple_router and simple_switch? I could not understand why forward.p4 works fine in simple_switch but not the simple_router.

Thank you very for your help.

Warm regards,


P4-dev mailing list
P4-dev at lists.p4.org<mailto:P4-dev at lists.p4.org>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.p4.org/pipermail/p4-dev_lists.p4.org/attachments/20170811/f7c76248/attachment-0002.html>

More information about the P4-dev mailing list