Interface bound doesn't work

I’m trying to implement a P4 switch on Ubuntu PC without mininet(called pc1). I use simple_switch -i 0@nic0 to bound the bmv2 interface to physical interface, and the P4 program is simple which want to drop all packets. I use another PC(called pc2) of the LAN to send udp to pc1. In this way, the log of P4 indicates that the switch receive all packets and hit at Drop action.
However, pc2 can also receive the return packets. which means the packets didn’t be droped.

  1. So,why?
    I guess that the bound command, the underlying of which is libpacp, is just responsible for monitor and copy. The packet are not processed by bmv2.

  2. How can I relize P4 swich on a Ubuntu PC? I have researched and found that maybe TUN can be used to implement it. I tried but I don’t know how to set up routing to have packets handled by bmv2 similar to TUN.

@Jared seems that you didn’t have properly configured your flow rules. So if you enable the bmv2 logs you should be able to see which tables and actions are hit by the packet.
I suppose that you have drop because it’s the default action for a certain table, so the packet does not hit any flow rules and is treated via the default action.

Note: I have not tried to use simple_switch to bind to physical interfaces on a system before, so I am doing a bit of guess-work here. Hopefully someone else may read this to confirm based on actual experience making this scenario work.

If the physical interfaces have IPv4 and/or IPv6 addresses configured on them, then quite likely this will cause the Linux kernel to route packets received on them, independently of what simple_switch does with the packet, and in addition to what simple_switch does with the packet. simple_switch is just “snooping” or “sniffing” packets on the interfaces it is bound to, but does not automatically prevent the kernel from processing the packets as it is configured to do.

Hi, DavideS. Thanks for your advice. In fact, I have the bmv2 logs and I observed that all packets hit the default action(Drop) because I didn’t add rules in table. Maybe bmv2 dropped the duplicate of packets, however, the kernel of ubuntu did not.

Assuming the interface is in promiscuous mode, meaning packets are handled by the bmv2 switch. To properly forward a packet, you have to insert the correct flow rule/s to apply the desired action/s to the packet.

Hi, Andy. Thanks for your reply. I’m doing the same guess-work that simple_switch will not prevent the kernel from processing the packets as it is configured to do.

As far as I know, realize a P4 on PC is never a new work ( I have seen some related discussions in forum). It’s not surprising for a veteran like you to implement such a P4 switch
However, I have met some problems of realizing a P4-switch on PC. I hope that someone could give me some advices like virtual interface TUN.

Perhaps I should turn to DPDK if someone tell me this can be successful.

I would recommend trying what you are currently doing with simple_switch, but remove all IPv4 and IPv6 address configuration from the interfaces that you are trying to use with simple_switch.

Before running simple_switch, try sending packets to one of those interfaces, and see if it is forwarded to another interface. If it is, then likely the kernel is causing that to happen (because simple_switch is not running yet), and if you were to start simple_switch, the kernel would continue to do that packet forwarding, regardless of what P4 code you load into simple_switch.