HOWTO use Linux namespaces with ns-3

From Nsnam
Jump to: navigation, search

Main Page - Current Development - Developer FAQ - Tools - Related Projects - Project Ideas - Summer Projects

Installation - Troubleshooting - User FAQ - HOWTOs - Samples - Models - Education - Contributed Code - Papers

Combining Linux namespaces and ns-3 can provide a framework for network emulation. Native code can then run in real-time and produce and/or consume "live" network traffic. Linux network namespaces (netns) are used as virtual hosts and a virtual network topology is created from ns-3 models running the real-time scheduler.

This page describes one way to use ns-3 for Linux-based network emulation on recent Ubuntu and Fedora systems. This is similar to the approach described in HOWTO Use Linux Containers to set up virtual networks. The main distinctions are:

  • Less isolation between virtual nodes
    • control groups are not used
    • the host filesystem is shared by default
  • Network devices are directly assigned to virtual nodes without using an intermediate bridge

Python is used to create and configure Linux namespaces and ns-3 objects. Python glue also serves as the interface between netns and ns-3 by managing information used by both (e.g., IP addresses).

The sections below give a quick overview of how to setup and run some basic network emulation scenarios.

Contents

Setup

The sections below assume an Ubuntu 9.10 or greater, or Fedora 12 or greater, system that includes ns-3 built with python bindings (see NS-3 Python Bindings). The netns3 code is known to work with ns-3-dev as of changeset f672647cfdb5 (June 17) but does not work with the most recent release of ns-3 (ns-3.8) so you will have to use a recent development version of ns-3-dev. The netns3 example code should not require additional development tools beyond what's needed to build ns-3 with python bindings.

Some of the netns3 examples require additional packages:

 # sudo apt-get install xterm quagga traceroute

Tools for managing virtual nodes

Components of the CORE network emulation tool are used to create and manage virtual nodes.

A version of CORE can be downloaded and installed from http://downloads.pf.itd.nrl.navy.mil/core/. A subset of low-level CORE components is included with the netns3 code and can be used without installing CORE.

Fetch and install the netns3 code

The netns3 tarball provides python code for namespace management and includes low-level python modules from CORE that are used to create and communicate with new namespaces.

These components of CORE are not needed if a version of CORE is already installed. To install the low-level CORE components:

 # wget http://www.tgoff.net/code/netns3.tgz
 # tar -xvzf netns3.tgz
 # (cd netns3/src && make && sudo make install)

Note that the libev development package is required.

Examples

The netns3 examples directory includes several example scenarios. Running each python script with -h gives a short usage message. The python scripts are meant to be run with root privileges from an ns-3 waf shell.

For example:

 # (cd ns-3-dev && sudo ./waf shell)
 # cd ~/netns3/examples
 # ./csma-xterm.py -h

Create a 4 node 802.11a ad hoc network

 # ./wifi-adhoc-xterm.py -n 4

From the xterm for node n3:

 # ping 10.0.0.1

A TCP throughput test example

Use iperf to test TCP throughput performance for various configured CSMA data rates:

 # ./csma-iperf.py 2> /dev/null | \
       awk '/csma rate/ {printf "%s\t", $3} /iperf.*throughput/ {printf "%sMbps\n", $5}'

A dynamic routing protocol example

Use OSPF to establish routes for 5 nodes connected in a line by CSMA networks:

 # ./csma-line-quagga.py -t 180 -n 5

From the xterm for node n4:

 # vtysh -c 'show ip ospf neighbor'

Wait for routes to converge:

 # vtysh -c 'show ip ospf route'
 ...
 # ip route
 # traceroute -n 10.0.0.1


Troubleshooting

Known bad kernels

This requires the underlying Linux kernel to have network namespace support. Unfortunately, the stock kernels distributed with many recent distributions do not uniformly support this.

  • Ubuntu 10.04.{2,3} LTS, x86_64 does not work (as of Sept. 2011)
  • This wiki page has some more information about possible problems.