Difference between revisions of "HOWTO use Linux namespaces with ns-3"

From Nsnam
Jump to: navigation, search
(An TCP throughput test example)
 
(2 intermediate revisions by one other user not shown)
Line 8: Line 8:
  
 
This page describes one way to use ns-3 for Linux-based network
 
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
+
emulation on recent Ubuntu and Fedora systems.  This is similar to the approach
 
described in [[HOWTO Use Linux Containers to set up virtual networks]].
 
described in [[HOWTO Use Linux Containers to set up virtual networks]].
 
The main distinctions are:
 
The main distinctions are:
Line 25: Line 25:
 
== Setup ==
 
== Setup ==
  
The sections below assume an Ubuntu 9.10 system that includes ns-3
+
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
 
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
+
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
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
 
additional development tools beyond what's needed to build ns-3 with
 
python bindings.
 
python bindings.
Line 36: Line 35:
 
   # sudo apt-get install xterm quagga traceroute
 
   # sudo apt-get install xterm quagga traceroute
  
=== Fetch and install RPyC ===
+
=== Tools for managing virtual nodes ===
  
RPyC is used for communication between the main python script running
+
Components of the [http://cs.itd.nrl.navy.mil/work/core/ CORE] network
on the host system and python server processes that run in a separate
+
emulation tool are used to create and manage virtual nodes.
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
+
A version of CORE can be downloaded and installed from
RPyC:
+
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
  # wget http://sourceforge.net/projects/rpyc/files/main/3.0.7/rpyc-3.0.7.tar.gz/download
+
without installing CORE.
  # tar -xvzf rpyc-3.0.7.tar.gz
+
  # (cd rpyc-3.0.7 && sudo python setup.py install)
+
  
 
=== Fetch and install the netns3 code ===
 
=== Fetch and install the netns3 code ===
  
The netns3 code provides a netns python module for namespace
+
The netns3 tarball provides python code for namespace management and
management and a low-level python module written in C, _netns, that
+
includes low-level python modules from CORE that are used to create
creates new namespaces.
+
and communicate with new namespaces.
  
To install netns3:
+
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
 
   # wget http://www.tgoff.net/code/netns3.tgz
 
   # tar -xvzf netns3.tgz
 
   # tar -xvzf netns3.tgz
 
   # (cd netns3/src && make && sudo make install)
 
   # (cd netns3/src && make && sudo make install)
 +
 +
Note that the libev development package is required.
  
 
== Examples ==
 
== Examples ==
Line 108: Line 106:
 
   # ip route
 
   # ip route
 
   # traceroute -n 10.0.0.1
 
   # 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 [http://code.google.com/p/coreemu/wiki/NamespaceKernels wiki page] has some more information about possible problems.

Latest revision as of 07:00, 31 October 2011

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.

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.