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
 

No comments:

Post a Comment