# Interface bound doesn't work

**URL:** <https://forum.p4.org/t/interface-bound-doesnt-work/1145>\
**Category:** Architecture Working Group\
**Created:** [March 26, 2024, 11:29am UTC](https://forum.p4.org/t/interface-bound-doesnt-work/1145 "2024-03-26T11:29:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jared](https://avatars.discourse-cdn.com/v4/letter/j/848f3c/32.png) [@Jared](https://forum.p4.org/u/Jared)\
**Post date:** [March 26, 2024, 11:29am UTC](https://forum.p4.org/t/interface-bound-doesnt-work/1145/1 "2024-03-26T11:29:41Z")

</div>

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`.

---

<div class="post-metadata">

**Author:** ![DavideS](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.p4.org/davides/32/120_2.png) [@DavideS](https://forum.p4.org/u/DavideS)\
**Post date:** [March 26, 2024, 1:37pm UTC](https://forum.p4.org/t/interface-bound-doesnt-work/1145/2 "2024-03-26T13:37:13Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![andyfingerhut](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.p4.org/andyfingerhut/32/17_2.png) [@andyfingerhut](https://forum.p4.org/u/andyfingerhut)\
**Post date:** [March 26, 2024, 4:39pm UTC](https://forum.p4.org/t/interface-bound-doesnt-work/1145/3 "2024-03-26T16:39:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Jared](https://avatars.discourse-cdn.com/v4/letter/j/848f3c/32.png) [@Jared](https://forum.p4.org/u/Jared)\
**Post date:** [March 26, 2024, 5:11pm UTC](https://forum.p4.org/t/interface-bound-doesnt-work/1145/4 "2024-03-26T17:11:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![DavideS](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.p4.org/davides/32/120_2.png) [@DavideS](https://forum.p4.org/u/DavideS)\
**Post date:** [March 26, 2024, 5:27pm UTC](https://forum.p4.org/t/interface-bound-doesnt-work/1145/5 "2024-03-26T17:27:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Jared](https://avatars.discourse-cdn.com/v4/letter/j/848f3c/32.png) [@Jared](https://forum.p4.org/u/Jared)\
**Post date:** [March 26, 2024, 5:29pm UTC](https://forum.p4.org/t/interface-bound-doesnt-work/1145/6 "2024-03-26T17:29:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![andyfingerhut](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.p4.org/andyfingerhut/32/17_2.png) [@andyfingerhut](https://forum.p4.org/u/andyfingerhut)\
**Post date:** [March 26, 2024, 8:40pm UTC](https://forum.p4.org/t/interface-bound-doesnt-work/1145/7 "2024-03-26T20:40:27Z")

</div>

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.
