Adding custom pmu layer to scapy

Hi, I am new to p4. I want to add a pmu layer to scapy in python(sender and receiver), and use p4 switch to process the packet.

I was able to send the packet with custom layer, but when i received the packet. The layer is shown Raw. I am not sure is something wrong with my or parser in p4. Can someone help me with this issue? Thank you!

Left is Receiver and right is sender

my parser in p4

Dear @nevermoreS,

Welcome to the forum!

Before I attempt to help you, please understand that this Forum is dedicated to P4 language, whereas it looks to me that you have a question about Scapy. In fact, you pretty much indicated this yourself in the subject line. While we do have plenty of people here who know Scapy and use it often, this is not the subject of this Forum.

Another important point is that when you are asking a question (and especially when you want to find out why some code does not behave correctly at runtime), you should at least provide all the source code so that people can recreate your issue. In your particular case, you neglected to provide:

  1. The Scapy code, where you defined the custom pmu layer
  2. The code for your send and receive scripts
  3. The full code for your P4 program
  4. The configuration of your P4 tables and other objects

This is not a very good way to start, isn’t it?

As for your specific problem, you need to make sure that the byte stream can be correctly decoded, meaning that Scapy knows what should be parsed after the UDP layer. Typically this is done by calling the function bind_layers(). There might be other issues, but that would be the first thing I’d check.

I am not sure why would you suspect your P4 program as long as you know that you received the correct packet and it was simply not correctly decoded by Scapy.

Happy hacking,

1 Like