by Agus Kurniawan
1. November 2010 10:22
On the previous article I wrote how to deploy NS3 on Ubuntu 10.10. Now I would like to share how to build and to run your network simulator program into NS3.
Development Tools
As we know, NS3 support development programming C++ and Python. There are many C++/Python development tools so you choice a tool you have experiences about development.
Getting Started
We start to create folder test on NS3 build folder
Create file hello-world-ns3.cc and write code below ( this code I copy paste from NS3 sample codes, main-simple.cc)
#include <iostream>
#include "ns3/core-module.h"
#include "ns3/helper-module.h"
#include "ns3/node-module.h"
#include "ns3/simulator-module.h"
using namespace ns3;
static void
GenerateTraffic (Ptr<Socket> socket, uint32_t size)
{
std::cout << "at=" << Simulator::Now ().GetSeconds () << "s, tx bytes=" << size << std::endl;
socket->Send (Create<Packet> (size));
if (size > 0)
{
Simulator::Schedule (Seconds (0.5), &GenerateTraffic, socket, size - 50);
}
else
{
socket->Close ();
}
}
static void
SocketPrinter (Ptr<Socket> socket)
{
Ptr<Packet> packet;
while (packet = socket->Recv ())
{
std::cout << "at=" << Simulator::Now ().GetSeconds () << "s, rx bytes=" << packet->GetSize () << std::endl;
}
}
static void
PrintTraffic (Ptr<Socket> socket)
{
socket->SetRecvCallback (MakeCallback (&SocketPrinter));
}
void
RunSimulation (void)
{
NodeContainer c;
c.Create (1);
InternetStackHelper internet;
internet.Install (c);
TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
Ptr<Socket> sink = Socket::CreateSocket (c.Get (0), tid);
InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 80);
sink->Bind (local);
Ptr<Socket> source = Socket::CreateSocket (c.Get (0), tid);
InetSocketAddress remote = InetSocketAddress (Ipv4Address::GetLoopback (), 80);
source->Connect (remote);
GenerateTraffic (source, 500);
PrintTraffic (sink);
Simulator::Run ();
Simulator::Destroy ();
}
int main (int argc, char *argv[])
{
RunSimulation ();
return 0;
}
Create wscript file and write this script
## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
def build(bld):
env = bld.env_of_name('default')
if not env['ENABLE_EXAMPLES']:
return;
obj = bld.create_ns3_program('hello-world-ns3',
['core', 'simulator'])
obj.source = 'hello-world-ns3.cc'
Create waf file and write this script
exec "`dirname "$0"`"/../waf "$@"
Compile and Run
You can compile and run using ./waf . Make sure you ‘re in test folder and run this script
./waf --run "hello-world-ns3"
Sample of output program you can see picture below
Done. This is a simple program for NS3. If you have question let me know.
by Agus Kurniawan
1. November 2010 09:37
NS3 or Network simulation version 3 is a kind of technology that simulates the network behavior through mathematical modeling and statistical analysis method and then obtains the specific parameters which reflect the characteristics of the network. NS is one of the most famous network simulation software which was developed by LBNL network research group at UC Berkeley in the USA.
Now I would like to introduce how to deploy NS3 on Ubuntu Linux 10.10
Prerequisites
The following list of packages should be accurate for Ubuntu 10.10 release.
requirements for C++ (release)
sudo apt-get install gcc g++ python
requirements for Python (release)
sudo apt-get install gcc g++ python python-dev
Mercurial:
sudo apt-get install mercurial
python bindings:
sudo apt-get install bzr
Debugging
sudo apt-get install gdb valgrind
GNU Scientific Library (GSL):
sudo apt-get install gsl-bin libgsl0-dev libgsl0ldbl
The Network Simulation Cradle (nsc):
sudo apt-get install flex bison
To read pcap packet traces:
sudo apt-get install tcpdump
Sqlite for statistics framework
sudo apt-get install sqlite sqlite3 libsqlite3-dev
Xml-based version of the config store
sudo apt-get install libxml2 libxml2-dev
A GTK-based
sudo apt-get install libgtk2.0-0 libgtk2.0-dev
To experiment with virtual machines and ns-3
sudo apt-get install vtun lxc
utils/check-style.py code style check program
sudo apt-get install uncrustify
Doxygen
sudo apt-get install doxygen graphviz imagemagick
sudo apt-get install texlive texlive-latex-extra texlive-generic-extra texlive-generic recommended
Texinfo
sudo apt-get install texinfo dia texlive texlive-latex-extra texlive-extra-utils texlive-generic-recommended texi2html
ustavo Carneiro's ns-3-pyviz visualizer
sudo apt-get install python-pygraphviz python-kiwi python-pygoocanvas libgoocanvas-dev
Installation
Now we can start to install NS3. Firstly we download ns-allinone-3.9.tar.bz2 file and put on a specific folder such as repos
wget http://www.nsnam.org/releases/ns-allinone-3.9.tar.bz2
Extract ns-allinone-3.9.tar.bz2
tar xjf ns-allinone-3.9.tar.bz2
Change to directory ns-allinone-3.9 and build NS3
./build.py
If success, you can see output messages displayed as below
'build' finished successfully (..)
Leaving directory './ns-3.9'
ns-3.9 is a folder of NS3 codes and scripts
Testing
After installation, you can test that your NS3 works or not.
Change to directory NS build ( in my case, ns-3.9) and run test script as below
./test.py
If success, you can see picture as below
Then you can develop NS3 program for simulating .