Skip to main content

NS2 Installation in Ubuntu 22.04

Flying Adhoc Network Simulation (FANET) using NS3

In this post, we will see how to simulation a Flying Adhoc Network (FANET) simulation using NS3. 

Its actually MANET with 3D mobility Model called Gauss Markov Mobility Model. 

See the following video for more details and explanation:

So all the nodes are flying in a 3D Fashion with X axis, Y Axis and Z Axis 

The default values of the three axes are 
X axis can be (-100m, 100m)
Y axis can be (-100m, 100m)
Z axis can be (0m, 100m)

We will take the following example for experimenting the Flying Adhoc Networks. To begin with, We use the following parameters for Simulation:
The name of the File is fanetex.cc
#include "ns3/point-to-point-module.h"
#include "ns3/ipv4-global-routing-helper.h"
#include <fstream>
#include <string>
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/applications-module.h"
#include "ns3/mobility-module.h"
#include "ns3/config-store-module.h"
#include "ns3/wifi-module.h"

#include "ns3/aodv-helper.h"
#include "ns3/internet-module.h"
#include "ns3/netanim-module.h"

using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("Mob");

int main (int argc, char *argv[])
{
  CommandLine cmd;
  cmd.Parse (argc, argv);
 
  NodeContainer c;
  c.Create (20); //20 wireless nodes

 WifiHelper wifi;
wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
//80211a, 80211b, 80211n, 2.4g and 5G, 80211ac, 80211ax is also supported.80211p (VANETs, WAVE)

  WifiMacHelper mac;
  mac.SetType ("ns3::AdhocWifiMac");
  //AdhocWifiMac, StaWifiMac, ApWifiMac
  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
                                "DataMode", StringValue ("OfdmRate54Mbps"));
  YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
  wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
  wifiChannel.AddPropagationLoss ("ns3::FriisPropagationLossModel");
  wifiPhy.SetChannel (wifiChannel.Create ());
  NetDeviceContainer cDevices = wifi.Install (wifiPhy, mac, c);
 //
  NS_LOG_INFO ("Enabling AODV routing on all backbone nodes");
  AodvHelper aodv;
  //AODV protocol is being using FANETs.
  InternetStackHelper internet;
  internet.SetRoutingHelper (aodv); // has effect on the next Install ()
  internet.Install (c);

  //
  // Assign IPv4 addresses to the device drivers (actually to the associated
  // IPv4 interfaces) we just created.
  //
  Ipv4AddressHelper ipAddrs;
  ipAddrs.SetBase ("192.168.0.0", "255.255.255.0");
  Ipv4InterfaceContainer cInterfaces;
  cInterfaces=ipAddrs.Assign (cDevices);
  
 /*
//Mobility Model - 2D
MobilityHelper mobility;

mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
  "MinX", DoubleValue (0.0),
  "MinY", DoubleValue (0.0),
  "DeltaX", DoubleValue (5.0),
  "DeltaY", DoubleValue (10.0),
  "GridWidth", UintegerValue (3),
  "LayoutType", StringValue ("RowFirst"));

mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",  "Bounds", RectangleValue (Rectangle (-100, 100, -100, 100)));
mobility.Install (c);
 */
 
 //Mobility Model -3D
 MobilityHelper mobility;
mobility.SetMobilityModel ("ns3::GaussMarkovMobilityModel",
  "Bounds", BoxValue (Box (0, 100, 0, 100, 0, 100)),
  "TimeStep", TimeValue (Seconds (0.5)),
  "Alpha", DoubleValue (0.85),
  "MeanVelocity", StringValue ("ns3::UniformRandomVariable[Min=800|Max=1200]"),
  "MeanDirection", StringValue ("ns3::UniformRandomVariable[Min=0|Max=6.283185307]"),
  "MeanPitch", StringValue ("ns3::UniformRandomVariable[Min=0.05|Max=0.05]"),
  "NormalVelocity", StringValue ("ns3::NormalRandomVariable[Mean=0.0|Variance=0.0|Bound=0.0]"),
  "NormalDirection", StringValue ("ns3::NormalRandomVariable[Mean=0.0|Variance=0.2|Bound=0.4]"),
  "NormalPitch", StringValue ("ns3::NormalRandomVariable[Mean=0.0|Variance=0.02|Bound=0.04]"));
mobility.SetPositionAllocator ("ns3::RandomBoxPositionAllocator",
  "X", StringValue ("ns3::UniformRandomVariable[Min=0|Max=100]"),
  "Y", StringValue ("ns3::UniformRandomVariable[Min=0|Max=100]"),
  "Z", StringValue ("ns3::UniformRandomVariable[Min=0|Max=100]"));
mobility.Install (c);

 UdpEchoServerHelper echoServer (9);

  ApplicationContainer serverApps = echoServer.Install (c.Get(0));
  serverApps.Start (Seconds (1.0));
  serverApps.Stop (Seconds (10.0));

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

  ApplicationContainer clientApps = echoClient.Install (c.Get(1));
  clientApps.Start (Seconds (2.0));
  clientApps.Stop (Seconds (10.0));

wifiPhy.EnablePcapAll ("Fanet3D"); //Packet Capture.
//Network Animation using NetAnim.
AnimationInterface anim("Fanet3D.xml");
//Ascii Trace Metrics can be processed using Tracemetrics Software.
AsciiTraceHelper ascii;
wifiPhy.EnableAsciiAll(ascii.CreateFileStream("Fanet3D.tr"));

  Simulator::Stop (Seconds (10.0));
  Simulator::Run ();
  Simulator::Destroy ();
  return 0;
}
       
The source code above explains the Flying Adhoc Networks in 3D using the Gauss Markov model. The RED code indicates its a 2D model and the BLUE code indicates the 3D mobility model.

How to run this file:
Step 1: Copy the above file in the folder ~ns-3.31/scratch
Step 2: Open the terminal 

$] cd ns-allinone-3.31/ns-3.31/
$] ./waf --run scratch/fanetex

To See the animation:

$] ../netanim-3.108/NetAnim
and do as per the instructions in the video

NetAnim
NetAnim



Comments

  1. Hello Pradeep Thanks for wonderful explanation.

    I want to know about ns-3 implementation of ground to UAV channel model. Please help me

    ReplyDelete
  2. can you pl help me i want to also compare the olsr and aodv throuhput PDR in it how could i pl. send ur mail or contactt

    ReplyDelete
  3. Hello,
    Could you help to evaluate tcp variants in MANET or Flynet in Ns3.33
    Thanks a lot

    ReplyDelete
  4. Sir can you please explain how to change ns2 code of Anthocnet to ns3 code.

    ReplyDelete
  5. Hello Sir, I am implementing same program on NS 3.34 i am getting following error ,could you please help me in this
    [2937/3016] Compiling scratch/WifiAODV.cc
    ../scratch/WifiAODV.cc: In function ‘int main(int, char**)’:
    ../scratch/WifiAODV.cc:32:43: error: ‘virtual void ns3::WifiHelper::SetStandard(ns3::WifiPhyStandard)’ is deprecated [-Werror=deprecated-declarations]
    32 | wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
    | ^
    In file included from ../scratch/WifiAODV.cc:14:
    ./ns3/wifi-helper.h:502:16: note: declared here
    502 | virtual void SetStandard (WifiPhyStandard standard);
    | ^~~~~~~~~~~
    ../scratch/WifiAODV.cc:40:3: error: ‘YansWifiPhyHelper’ was not declared in this scope
    40 | YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
    | ^~~~~~~~~~~~~~~~~
    ../scratch/WifiAODV.cc:41:3: error: ‘YansWifiChannelHelper’ was not declared in this scope
    41 | YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
    | ^~~~~~~~~~~~~~~~~~~~~
    ../scratch/WifiAODV.cc:42:3: error: ‘wifiChannel’ was not declared in this scope
    42 | wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
    | ^~~~~~~~~~~
    ../scratch/WifiAODV.cc:44:3: error: ‘wifiPhy’ was not declared in this scope; did you mean ‘wifi’?
    44 | wifiPhy.SetChannel (wifiChannel.Create ());
    | ^~~~~~~
    | wifi

    ReplyDelete

Post a Comment

Popular posts from this blog

Installation of NS2 (ns-2.35) in Ubuntu 20.04

Installation of NS2 (ns-2.35) in Ubuntu 20.04 LTS Step 1: Install the basic libraries like      $] sudo apt install build-essential autoconf automake libxmu-dev Step 2: install gcc-4.8 and g++-4.8 open the file using sudo mode $] sudo nano /etc/apt/sources.list Include the following line deb http://in.archive.ubuntu.com/ubuntu bionic main universe $] sudo apt update $] sudo apt install gcc-4.8 g++-4.8 Step 3:  Unzip the ns2 packages to home folder $] tar zxvf ns-allinone-2.35.tar.gz $] cd ns-allinone-2.35/ns-2.35 Modify the following make files. ~ns-2.35/Makefile.in Change @CC@ to gcc-4.8 change @CXX@ to g++-4.8 ~nam-1.15/Makefile.in ~xgraph-12.2/Makefile.in ~otcl-1.14/Makefile.in Change in all places  @CC@ to gcc-4.8 @CPP@ or @CXX@ to g++-4.8 open the file: ~ns-2.35/linkstate/ls.h Change at the Line no 137  void eraseAll() { erase(baseMap::begin(), baseMap::end()); } to This void eraseAll() { this->erase(baseMap::begin(), baseMap::end()); } All changes made Step 4: Open a new termi

Installing ns3 in Ubuntu 22.04 | Complete Instructions

In this post, we are going to see how to install ns-3.36.1 in Ubuntu 22.04. You can follow the video for complete details Tools used in this simulation: NS3 version ns-3.36.1  OS Used: Ubuntu 22.04 LTS Installation of NS3 (ns-3.36.1) There are some changes in the ns3 installation procedure and the dependencies. So open a terminal and issue the following commands Step 1:  Prerequisites $ sudo apt update In the following packages, all the required dependencies are taken care and you can install all these packages for the complete use of ns3. $ sudo apt install g++ python3 python3-dev pkg-config sqlite3 cmake python3-setuptools git qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools gir1.2-goocanvas-2.0 python3-gi python3-gi-cairo python3-pygraphviz gir1.2-gtk-3.0 ipython3 openmpi-bin openmpi-common openmpi-doc libopenmpi-dev autoconf cvs bzr unrar gsl-bin libgsl-dev libgslcblas0 wireshark tcpdump sqlite sqlite3 libsqlite3-dev  libxml2 libxml2-dev libc6-dev libc6-dev-i386 libclang-dev llvm-

VPL Jail Server Installation | Virtual Programming Laboratory with Moodle

Virtual Programming Laboratory (VPL)  This post tells you how to install VPL Jail Server Installation in Ubuntu 20.04 and how to configure it using Moodle Learning Management System. VPL - Virtual Programming Laboratory  For full installation with complete description, follow the video What is VPL? VPL is Virtual Programming Laboratory which is a tool for programming assignments, evaluation and running of programs. The programming languages supported by VPL is C, C++, Java, Python, Perl, PHP, NodeJS, Verilog, etc. Step 1 - Install  VPN Jail Server Installation  My Server configuration  16GB RAM and 16 Core PRocessor (Intel Xeon)  Virtual Machine  Ubuntu 20.04 (64 bit OS). To download the softwares  https://vpl.dis.ulpgc.es/index.php/home/download  Unzip or untar the above file in the home folder (in my case it is /home/tspradeepkumar/ ) $ cd vpl-jail-system-2.7.2/ $ sudo ./install-vpl-sh VPL Jail Server Installation This will take some time based on your internet connection: To Star