From f1dfa5cecd90fc8bcedf1ce22d98d105469c89ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Apitzsch?= Date: Wed, 7 Jun 2023 16:24:58 +0200 Subject: [PATCH] fd-net-device,tap-bridge: Replace brctl, tunctl and ifconfig by ip `tunctl` isn't easily available on every Linux distribution, `brctl` is obsolete[1] and `ifconfig` has been deprecated by many Linux distributions[2], so replace these commands by `ip` from iproute2. [1] https://www.man7.org/linux/man-pages/man8/brctl.8.html#NOTES [2] https://lwn.net/Articles/710533/ --- src/fd-net-device/examples/fd-emu-ping.cc | 2 +- src/tap-bridge/doc/tap.rst | 26 +++++++++---------- src/tap-bridge/examples/tap-wifi-dumbbell.cc | 21 ++++++++------- .../examples/virtual-network-setup.sh | 20 +++++++------- .../examples/virtual-network-teardown.sh | 20 +++++++------- src/tap-bridge/model/tap-bridge.cc | 26 +++++++++---------- 6 files changed, 58 insertions(+), 57 deletions(-) diff --git a/src/fd-net-device/examples/fd-emu-ping.cc b/src/fd-net-device/examples/fd-emu-ping.cc index 3b9449d1b..5693248c9 100644 --- a/src/fd-net-device/examples/fd-emu-ping.cc +++ b/src/fd-net-device/examples/fd-emu-ping.cc @@ -50,7 +50,7 @@ // 1') If you run emulation in dpdk mode, use device address (eg. 0000:00.1f.6) // as device name. This address can be obtained by running `lspci` // 2) The host device must be set to promiscuous mode -// (e.g. "sudo ifconfig eth0 promisc") +// (e.g. "sudo ip link set eth0 promisc on") // 2') If you run emulation in netmap or dpdk mode, you need before to load // the netmap.ko or dpdk modules. The user is in charge to configure and // build netmap/dpdk separately. diff --git a/src/tap-bridge/doc/tap.rst b/src/tap-bridge/doc/tap.rst index cafd1002a..afc0f5254 100644 --- a/src/tap-bridge/doc/tap.rst +++ b/src/tap-bridge/doc/tap.rst @@ -147,9 +147,9 @@ completely outside the scope of the ns-3 simulation using something like: .. sourcecode:: bash - $ sudo tunctl -t tap0 - $ sudo ifconfig tap0 hw ether 08:00:2e:00:00:01 - $ sudo ifconfig tap0 10.1.1.1 netmask 255.255.255.0 up + $ sudo ip tuntap add mode tap tap0 + $ sudo ip address add 10.1.1.1/24 dev tap0 + $ sudo ip link set dev tap0 address 08:00:2e:00:00:01 up To tell the TapBridge what is going on, the user will set either directly into the TapBridge or via the TapBridgeHelper, the "DeviceName" attribute. @@ -185,7 +185,7 @@ This is illustrated below: +---------+ +--------+ | bridge | | stack | || || | -------- | | -------- | +--------------------+ | ns-3 | | ns-3 | - | OS (brctl) Bridge | | net | | net | + | OS Bridge | | net | | net | +--------------------+ | device | | device | +----------+ +----------+ || || @@ -215,13 +215,13 @@ configure the bridge and tap completely outside ns-3: .. sourcecode:: bash - $ sudo brctl addbr mybridge - $ sudo tunctl -t mytap - $ sudo ifconfig mytap hw ether 00:00:00:00:00:01 - $ sudo ifconfig mytap 0.0.0.0 up - $ sudo brctl addif mybridge mytap - $ sudo brctl addif mybridge ... - $ sudo ifconfig mybridge 10.1.1.1 netmask 255.255.255.0 up + $ sudo ip link add mybridge type bridge + $ sudo ip address add 10.1.1.1/24 dev mybridge + $ sudo ip tuntap add mode tap mytap + $ sudo ip link set dev mytap address 00:00:00:00:00:01 up + $ sudo ip link set dev mytap master mybridge + $ sudo ip link set dev ... master mybridge + $ sudo ip link set dev mybridge up To tell the TapBridge what is going on, the user will set either directly into the TapBridge or via the TapBridgeHelper, the "DeviceName" attribute. @@ -390,8 +390,8 @@ found in the packet. In the other direction, a packet received by an ns-3 net device is hooked via callback to the TapBridge. This must be done in promiscuous mode since -the goal is to bridge the ns-3 net device onto the OS (brctl) bridge of -which the TAP device is a part. +the goal is to bridge the ns-3 net device onto the OS bridge of which the +TAP device is a part. For these reasons, only ns-3 net devices that support SendFrom() and have a hookable promiscuous receive callback are allowed to participate in UseBridge diff --git a/src/tap-bridge/examples/tap-wifi-dumbbell.cc b/src/tap-bridge/examples/tap-wifi-dumbbell.cc index 16953fac6..3ac1e6e83 100644 --- a/src/tap-bridge/examples/tap-wifi-dumbbell.cc +++ b/src/tap-bridge/examples/tap-wifi-dumbbell.cc @@ -61,7 +61,7 @@ // item). // // ./ns3 run tap-wifi-dumbbell& -// sudo route add -net 10.1.3.0 netmask 255.255.255.0 dev thetap gw 10.1.1.2 +// sudo ip route add 10.1.3.0/24 dev thetap via 10.1.1.2 // ping 10.1.3.4 // // Take a look at the pcap traces and note that the timing reflects the @@ -77,21 +77,22 @@ // traffic data rate and watch the ping timing change dramatically. // // ./ns3 run "tap-wifi-dumbbell --ns3::OnOffApplication::DataRate=100kb/s"& -// sudo route add -net 10.1.3.0 netmask 255.255.255.0 dev thetap gw 10.1.1.2 +// sudo ip route add 10.1.3.0/24 dev thetap via 10.1.1.2 // ping 10.1.3.4 // // 4) Try to run this in UseBridge mode. This allows you to bridge an ns-3 // simulation to an existing pre-configured bridge. This uses tap devices // just for illustration, you can create your own bridge if you want. // -// sudo tunctl -t mytap1 -// sudo ifconfig mytap1 0.0.0.0 promisc up -// sudo tunctl -t mytap2 -// sudo ifconfig mytap2 0.0.0.0 promisc up -// sudo brctl addbr mybridge -// sudo brctl addif mybridge mytap1 -// sudo brctl addif mybridge mytap2 -// sudo ifconfig mybridge 10.1.1.5 netmask 255.255.255.0 up +// sudo ip tuntap add mode tap mytap1 +// sudo ip link set mytap1 promisc on up +// sudo ip tuntap add mode tap mytap2 +// sudo ip link set mytap2 promisc on up +// sudo ip link add mybridge type bridge +// sudo ip link set dev mytap1 master mybridge +// sudo ip link set dev mytap2 master mybridge +// sudo ip address add 10.1.1.5/24 dev mybridge +// sudo ip link set dev mybridge up // ./ns3 run "tap-wifi-dumbbell --mode=UseBridge --tapName=mytap2"& // ping 10.1.1.3 diff --git a/src/tap-bridge/examples/virtual-network-setup.sh b/src/tap-bridge/examples/virtual-network-setup.sh index 51c182a0e..794dc7f2a 100755 --- a/src/tap-bridge/examples/virtual-network-setup.sh +++ b/src/tap-bridge/examples/virtual-network-setup.sh @@ -1,14 +1,14 @@ #!/bin/bash -brctl addbr br-left -brctl addbr br-right -tunctl -t tap-left -tunctl -t tap-right -ifconfig tap-left 0.0.0.0 promisc up -ifconfig tap-right 0.0.0.0 promisc up -brctl addif br-left tap-left -ifconfig br-left up -brctl addif br-right tap-right -ifconfig br-right up +ip link add br-left type bridge +ip link add br-right type bridge +ip tuntap add mode tap tap-left +ip tuntap add mode tap tap-right +ip link set tap-left promisc on up +ip link set tap-right promisc on up +ip link set dev tap-left master br-left +ip link set dev br-left up +ip link set dev tap-right master br-right +ip link set dev br-right up # Note: you also need to have loaded br_netfilter module # ('modprobe br_netfilter') to enable /proc/sys/net/bridge pushd /proc/sys/net/bridge diff --git a/src/tap-bridge/examples/virtual-network-teardown.sh b/src/tap-bridge/examples/virtual-network-teardown.sh index d31cc945e..41d72699d 100755 --- a/src/tap-bridge/examples/virtual-network-teardown.sh +++ b/src/tap-bridge/examples/virtual-network-teardown.sh @@ -3,13 +3,13 @@ lxc-stop -n left lxc-stop -n right lxc-destroy -n left lxc-destroy -n right -ifconfig br-left down -ifconfig br-right down -brctl delif br-left tap-left -brctl delif br-right tap-right -brctl delbr br-left -brctl delbr br-right -ifconfig tap-left down -ifconfig tap-right down -tunctl -d tap-left -tunctl -d tap-right +ip link set dev br-left down +ip link set dev br-right down +ip link set dev tap-left nomaster +ip link set dev tap-right nomaster +ip link del br-left +ip link del br-right +ip link set dev tap-left down +ip link set dev tap-right down +ip tuntap del mode tap tap-left +ip tuntap del mode tap tap-right diff --git a/src/tap-bridge/model/tap-bridge.cc b/src/tap-bridge/model/tap-bridge.cc index cd14f68ad..13b6b7e03 100644 --- a/src/tap-bridge/model/tap-bridge.cc +++ b/src/tap-bridge/model/tap-bridge.cc @@ -282,9 +282,9 @@ TapBridge::CreateTap() // be configuring a tap device outside the scope of the ns-3 simulation and // will be expecting us to work with it. The user will do something like: // - // sudo tunctl -t tap0 - // sudo ifconfig tap0 hw ether 00:00:00:00:00:01 - // sudo ifconfig tap0 10.1.1.1 netmask 255.255.255.0 up + // sudo ip tuntap add mode tap tap0 + // sudo ip address add 10.1.1.1/24 dev tap0 + // sudo ip link set dev tap0 address 00:00:00:00:00:01 up // // The user will then set the "Mode" Attribute of the TapBridge to "UseLocal" // and the "DeviceName" Attribute to "tap0" in this case. @@ -300,13 +300,13 @@ TapBridge::CreateTap() // net device and logically add it to the existing bridge. We expect that // the user has done something like: // - // sudo brctl addbr mybridge - // sudo tunctl -t mytap - // sudo ifconfig mytap hw ether 00:00:00:00:00:01 - // sudo ifconfig mytap 0.0.0.0 up - // sudo brctl addif mybridge mytap - // sudo brctl addif mybridge ... - // sudo ifconfig mybridge 10.1.1.1 netmask 255.255.255.0 up + // sudo ip link add mybridge type bridge + // sudo ip tuntap add mode tap mytap + // sudo ip link set dev mytap address 00:00:00:00:00:01 up + // sudo ip link set dev mytap master mybridge + // sudo ip link set dev ... master mybridge + // sudo ip address add 10.1.1.1/24 dev mybridge + // sudo ip link set dev mybridge up // // The bottom line at this point is that we want to either create or use a // tap device on the host based on the verb part "Use" or "Configure" of the @@ -833,9 +833,9 @@ TapBridge::ForwardToBridgedDevice(uint8_t* buf, ssize_t len) // In Linux, "Other Device" and "Tap Device" are bridged together. By this // we mean that a user has sone something in Linux like: // - // brctl addbr mybridge - // brctl addif other-device - // brctl addif tap-device + // ip link add mybridge type bridge + // ip link set dev other-device master mybridge + // ip link set dev tap-device master mybridge // // In USE_BRIDGE mode, we want to logically extend this Linux behavior to the // simulated ns3 device and make it appear as if it is connected to the Linux