Sunday, November 20, 2016

Installation of netanim in ns3 and testing on first file

Installation of netanim in ns3 and testing on first file 

before install the NetAnim we should install these packages
  1. yum install mercurial
  2. yum install qt4
  3. yum install qt4-devel

Downloading NetAnim

hg clone http://code.nsnam.org/netanim
 

Building and Starting NetAnim

cd netanim
make clean
 qmake NetAnim.pro (For MAC Users: qmake -spec macx-g++ NetAnim.pro)
make

then you can see netanim-3.105 version in your ns-allinone-3.21 directory

 













 then you want to go inside the ns-allinone-3.21 and you want to go inside the netanim-3.105 then you should check NetAnim.pro inside that folder













after that you can run the netanim using this command
[root@localhost netanim-3.105]# ./NetAnim

after run this code you can see this interface















it means you are ready use Netanim

then want to get first.cc file and modify the code. here is the modified code

/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation;
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
#include "ns3/netanim-module.h"
using namespace ns3;

NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");

int
main (int argc, char *argv[])
{
  Time::SetResolution (Time::NS);
  LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
  LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);

  NodeContainer nodes;
  nodes.Create (2);

  PointToPointHelper pointToPoint;
  pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
  pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));

  NetDeviceContainer devices;
  devices = pointToPoint.Install (nodes);

  InternetStackHelper stack;
  stack.Install (nodes);

  Ipv4AddressHelper address;
  address.SetBase ("10.1.1.0", "255.255.255.0");

  Ipv4InterfaceContainer interfaces = address.Assign (devices);

  UdpEchoServerHelper echoServer (9);

  ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
  serverApps.Start (Seconds (1.0));
  serverApps.Stop (Seconds (10.0));

  UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);
  echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
  echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
  echoClient.SetAttribute ("PacketSize", UintegerValue (1024));

  ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
  clientApps.Start (Seconds (2.0));
  clientApps.Stop (Seconds (10.0));





AnimationInterface anim ("anim1.xml");
anim.SetConstantPosition(nodes.Get(0), 1.0, 2.0); 
anim.SetConstantPosition(nodes.Get(1), 2.0, 3.0); 

  Simulator::Run ();
  Simulator::Destroy ();
  return 0;
}


after modify this code save it in the scratch folder compiled it in the inside the root@localhost ns-3.21] directory
here is the comand
./waf --run first

if you type the right code you get this out put













then you should run the netanim. For that first go to the netanim-3.105 directory and run the netanim
./NetAnim

after that you can the the interface previously i explained.then go to the open file folder in the netanim interface and open the anim1.xml file that we created and finaly simulated. then you can see how nodes are communicate
 

Run first.cc file

 Here is the First.cc file


#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"

using namespace ns3;

NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");

intmain (int argc, char *argv[])
{
  Time::SetResolution (Time::NS);
  LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
  LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);

  NodeContainer nodes;
  nodes.Create (2);

  PointToPointHelper pointToPoint;
  pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
  pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));

  NetDeviceContainer devices;
  devices = pointToPoint.Install (nodes);

  InternetStackHelper stack;
  stack.Install (nodes);

  Ipv4AddressHelper address;
  address.SetBase ("10.1.1.0", "255.255.255.0");

  Ipv4InterfaceContainer interfaces = address.Assign (devices);

  UdpEchoServerHelper echoServer (9);

  ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
  serverApps.Start (Seconds (1.0));
  serverApps.Stop (Seconds (10.0));

  UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);
  echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
  echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
  echoClient.SetAttribute ("PacketSize", UintegerValue (1024));

  ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
  clientApps.Start (Seconds (2.0));
  clientApps.Stop (Seconds (10.0));

  Simulator::Run ();
  Simulator::Destroy ();
  return 0;
}

it is inside the workspace/ns-allinone-3.21/ns-3.21/examples/tutorial

When we are going to run this program first we must copy this file in to scratch folder.
we can do it with this command.

$ cp [options] source dest

then you can  run the first.cc file using this command

./waf --run first 

here is the out put
Likewise you can try the other file in the example folder (second.cc, third.cc)



Starting NS 3

Downloading ns-3 Using a Tarball

$ cd
$ mkdir workspace
$ cd workspace
$ wget http://www.nsnam.org/release/ns-allinone-3.26.tar.bz2
$ tar xjf ns-allinone-3.26.tar.bz2
 
If you change into the directory ns-allinone-3.26 you should see a
number of files and directories:
 
$ ls
bake      constants.py   ns-3.26                            README
build.py  netanim-3.107  pybindgen-0.17.0.post57+nga6376f2  util.py
 

Downloading ns-3 Using Bake

$ cd
$ mkdir workspace
$ cd workspace
$ hg clone http://code.nsnam.org/bake


As the hg (Mercurial) command executes, you should see something like the following displayed,

destination directory: bake
requesting all changes
adding changesets
adding manifests
adding file changes
added 339 changesets with 796 changes to 63 files
updating to branch default
45 files updated, 0 files merged, 0 files removed, 0 files unresolved
 
 
After the clone command completes, you should have a directory called bake, the contents of which should look something like the following:

$ ls
bake                  bakeconf.xml  doc       generate-binary.py  TODO
bake.py               examples      test
 
Then type this one 
 
$ ./bake.py configure -e ns-3.26 

after that check what are the packages we have or not.To look that we want to type
this one
$ ./bake.py check
 
after that You should see something like the following,
 
Python - OK
> GNU C++ compiler - OK
> Mercurial - OK
> CVS - OK
> GIT - OK
> Bazaar - OK
> Tar tool - OK
> Unzip tool - OK
> Unrar tool - is missing
> 7z  data compression utility - OK
> XZ data compression utility - OK
> Make - OK
> cMake - OK
> patch tool - OK
> autoreconf tool - OK

> Path searched for tools: /usr/lib64/qt-3.3/bin /usr/lib64/ccache
/usr/local/bin /bin /usr/bin /usr/local/sbin /usr/sbin /sbin
/home/tomh/bin bin 
 
Assume you haven't some packages then you want to install them for that we use 
 
yum install package name
e.g:- yum install CVS
 
next we want to download software. For that 
$ ./bake.py download
 
should yield something like:
 
>> Downloading gccxml-ns3 (target directory:gccxml) - OK
>> Searching for system dependency python-dev - OK
>> Searching for system dependency pygraphviz - OK
>> Searching for system dependency pygoocanvas - OK
>> Searching for system dependency setuptools - OK
>> Searching for system dependency g++ - OK
>> Searching for system dependency qt4 - OK
>> Downloading pygccxml - OK
>> Downloading netanim-3.107 - OK
>> Downloading pybindgen-0.17.0.post57+nga6376f2 (target directory:pybindgen) - OK
>> Downloading ns-3.26 - OK
 
The above suggests that five sources have been downloaded. Check the source directory now and type ls; one should see:

$ ls
gccxml  netanim-3.107  ns-3.26  pybindgen  pygccxml  pygccxml-1.0.0.zip
 
You are now ready to build the ns-3 distribution.
 

Building ns-3

Building with build.py

If you downloaded using a tarball you should have a directory called something like ns-allinone-3.26 under your ~/workspace directory. Type the following:

$ ./build.py --enable-examples --enable-tests
 
Because we are working with examples and tests in this tutorial, and because they are not built by default in ns-3, the arguments for build.py tells it to build them for us. The program also defaults to building all available modules. Later, you can build ns-3 without examples and tests, or eliminate the modules that are not necessary for your work, if you wish.
You will see lots of typical compiler output messages displayed as the build script builds the various pieces you downloaded. Eventually you should see the following:
 
Waf: Leaving directory `/path/to/workspace/ns-allinone-3.26/ns-3.26/build'
'build' finished successfully (6m25.032s)

Modules built:
antenna                   aodv                      applications
bridge                    buildings                 config-store
core                      csma                      csma-layout
dsdv                      dsr                       energy
fd-net-device             flow-monitor              internet
internet-apps             lr-wpan                   lte
mesh                      mobility                  mpi
netanim (no Python)       network                   nix-vector-routing
olsr                      openflow (no Python)      point-to-point
point-to-point-layout     propagation               sixlowpan
spectrum                  stats                     tap-bridge
test (no Python)          topology-read             traffic-control
uan                       virtual-net-device        visualizer
wave                      wifi                      wimax

Modules not built (see ns-3 tutorial for explanation):
brite                     click
 

Testing ns-3

You can run the unit tests of the ns-3 distribution by running the ./test.py -c core  script: 
$ ./test.py -c core
 
These tests are run in parallel by Waf. You should eventually see a report saying that
92 of 92 tests passed (92 passed, 0 failed, 0 crashed, 0 valgrind errors)
 
This is the important message.
You will also see the summary output from Waf and the test runner executing each test, which will actually look something like:

Waf: Entering directory `/path/to/workspace/ns-3-allinone/ns-3-dev/build'
Waf: Leaving directory `/path/to/workspace/ns-3-allinone/ns-3-dev/build'
'build' finished successfully (1.799s)

Modules built:
aodv                      applications              bridge
click                     config-store              core
csma                      csma-layout               dsdv
emu                       energy                    flow-monitor
internet                  lte                       mesh
mobility                  mpi                       netanim
network                   nix-vector-routing        ns3tcp
ns3wifi                   olsr                      openflow
point-to-point            point-to-point-layout     propagation
spectrum                  stats                     tap-bridge
template                  test                      tools
topology-read             uan                       virtual-net-device
visualizer                wifi                      wimax

PASS: TestSuite ns3-wifi-interference
PASS: TestSuite histogram

...

PASS: TestSuite object
PASS: TestSuite random-number-generators
 

Running a Script

We typically run scripts under the control of Waf. This allows the build system to ensure that the shared library paths are set correctly and that the libraries are available at run time. To run a program, simply use the --run option in Waf. Let’s run the ns-3 equivalent of the ubiquitous hello world program by typing the following:

$ ./waf --run hello-simulator
Waf first checks to make sure that the program is built correctly and executes a build if required. Waf then executes the program, which produces the following output.

Hello Simulator