HOWTO use Linux namespaces with ns-3

From Nsnam
Revision as of 08:26, 29 March 2010 by Tgoff (Talk | contribs) (Fetch and install the netns3 code)

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 an Ubuntu 9.10 system. 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.

Setup

The sections below assume an Ubuntu 9.10 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 b5bc10de166d and should work with ns-3.8. 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

Fetch and install RPyC

RPyC is used for communication between the main python script running on the host system and python server processes that run in a separate namespace for each virtual node. Remote procedure calls allow running commands within a namespace context.

See http://rpyc.wikidot.com/ for more information on RPyC. To install RPyC:

 # wget http://sourceforge.net/projects/rpyc/files/main/3.0.7/rpyc-3.0.7.tar.gz/download
 # tar -xvzf rpyc-3.0.7.tar.gz
 # (cd rpyc-3.0.7 && sudo python setup.py install)

Fetch and install the netns3 code

The netns3 code provides a netns python module for namespace management and a low-level python module written in C, _netns, that creates new namespaces.

To install netns3:

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

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

An 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} /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