Installing Network Namespaces and Network Topology - nps-ros2/ns3_testbed GitHub Wiki

Network namespaces allow multiple separate networks to exist on one system.

Install network namespaces and their virtual network devices by running the nns_setup.py script as root:

cd ~/gits/ns3_testbed/scripts
sudo ./nns_setup.py setup

Network namespaces are named nns1, nns2, nns3, ... . The IP for each is 10.0.0.1, 10.0.0.4, etc, respectively. The default number of namespaces created is 30. The maximum is 84, which could be increased by changing the netmask. To uninstall, type sudo ./nns_setup.py teardown or reboot.

You can check that your network namespaces and devices are installed by typing:

sudo ip netns list
ip a

Here is a simplified drawing of four network namespaces and their associated ports:

nns with 4 Wifi

As is, these ports are not connected to anything. The ns-3 program connects these ports by attaching to the network Tap devices.

Technical Details

nns and Network Setup

Script nns_setup.py installs network namespaces and network interfaces:

  • Network namespaces (nns)
  • Loopback
  • Wifi network

Here is the setup for two namespaces:

nns detail

nns

ip netns add nns1
ip netns add nns2

Loopback

ip netns exec nns1 ip link set dev lo up
ip netns exec nns2 ip link set dev lo up

Wifi Network

Setup for nns1:

ip link add wifi_veth1 type veth peer name wifi_vethb1
ip address add 10.0.0.2/24 dev wifi_vethb1
ip link set wifi_veth1 netns nns1
ip netns exec nns1 ip addr add 10.0.0.1/24  dev wifi_veth1
ip link add name wifi_br1 type bridge
ip link set wifi_br1 up
ip link set wifi_vethb1 up
ip netns exec nns1 ip link set wifi_veth1 up
ip link set wifi_vethb1 master wifi_br1
ip tuntap add wifi_tap1 mode tap
ip addr flush dev wifi_tap1
ip address add 10.0.0.3/24 dev wifi_tap1
ip link set wifi_tap1 up
ip link set wifi_tap1 master wifi_br1

Setup for nns2:

ip link add wifi_veth2 type veth peer name wifi_vethb2
ip address add 10.0.0.5/24 dev wifi_vethb2
ip link set wifi_veth2 netns nns2
ip netns exec nns2 ip addr add 10.0.0.4/24  dev wifi_veth2
ip link add name wifi_br2 type bridge
ip link set wifi_br2 up
ip link set wifi_vethb2 up
ip netns exec nns2 ip link set wifi_veth2 up
ip link set wifi_vethb2 master wifi_br2
ip tuntap add wifi_tap2 mode tap
ip addr flush dev wifi_tap2
ip address add 10.0.0.6/24 dev wifi_tap2
ip link set wifi_tap2 up
ip link set wifi_tap2 master wifi_br2

Examine network setup

See local network devices and devices on network namespace nns1:

ip a
ip netns exec nns1 ip a