Get packets in the controller from multiple switches


I have a topology consisting of multiple switches and one controller. I want the switches to send PacketIn to the controller, and then based on the the type of the PacketIn, I want to send some rules to the switch that the packet has come from. I have implemented everything including the packet communication, the P4 program, etc. But my question is how can I wait for PacketIns from multiple switches?
In my controller, I have a while true that is listening for packetIns from s1 for example. How can I get packetIns from all switches? and know what switch sent that packet?

Thank you in advance.

Hi @sougol,

You can send control packets to the interface where the switch is connected to the controller. You can define your own control header end there put some information needed to find/recongnize your switch.

Hello Davide,
Thanks for the prompt reply.
I can send packets to the controller. I want to know if there is any way other than using threads in the controller to get packets from multiple switches at the same time.
And about the second part of my question. What I understand form your response is that there is no way I can get the incoming interface from the packet that I am processing and I have to add some data to the packets, right?

Hi @sougol,

  • You can get packets from multiple switches, but what do you mean when you say at the same time? then you con process them serially or in parallel with threads. In other word you can have one single parser or multiple parser in your controller, to be evaluate how complex is doing it and which are the advantage.

  • So this should be the header for packet IO, p4runtime-shell/usage/ at main · p4lang/p4runtime-shell · GitHub. More in detail, i think that thanks P4runtime connection/sessions the controller is able to recognize the switch but specific informations, retrieved from the dataplane, as to be written in the packets. For example you can think about postcard telemetry.

1 Like

Hello @DavideS ,
Thank you so much. I think I have to use threading to get packets from multiple switches at the same time. Just to give an example of what I am looking for, in Python, you can define a list of ports to sniff packets from. sniff(iface=[eth0,eth1],…) I was wondering if we have such a thing in Controller like s1.PacketIn().
The second part answered my question completely.

Hi @sougol,

I think that depens on how the controller that you are using (ONOS, TeraFlow,Opendaligth,etc). I guess that that kind of function/method is not avaiable in "general purpose"python libraies.

1 Like

As an alternative to Python threads, you can use P4Runtime with asyncio.

The finsy python library can receive PacketIn’s from multiple switches. There are example programs showing how to construct a controller for multiple switches in Python.


Hello @sougol,
I implemented an example that may be a solution for you:

There I have a controller and 3 switches. I hope that helps.