Skip to first unread message

Faiza Firdousi

unread,
Oct 3, 2017, 10:56:49 AM10/3/17
to ns-3-users
Hi, I'm trying to change the transmission range of nodes in aodv.cc. The problem that I am facing is that if I use the default settings and code of aodv.cc, then the transmission range is covering all the nodes, and there is no need if intermediate nodes, as the source can directly deliver packets to the destination nodes. I need the intermediate nodes to participate in the routing as well. So I reduced the transmission range of the nodes by changing the "Propagation loss Model" to "Range Propagation Loss", and changing the value of MaxRange to be 10 meters. In this way the far away nodes won't be accessible through the source node, and so intermediate nodes will have to deliver the packets. But I'm not quite getting the desired results. The hop count of the nodes in the routing table is still mostly 1, with a few exceptions. Can anyone tell me how to address this problem? I want the hop counts of most of the nodes to be more than 1. This is the code that I am using :

[aodv.cc]:
class AodvExample 
{
public:
  AodvExample ();
  /// Configure script parameters, \return true on successful configuration
  bool Configure (int argc, char **argv);
  /// Run simulation
  void Run ();
  /// Report results
  void Report (std::ostream & os);

private:

  // parameters
  /// Number of nodes
  uint32_t size;
  /// Distance between nodes, meters
  double step;
  /// Simulation time, seconds
  double totalTime;
  /// Write per-device PCAP traces if true
  bool pcap;
  /// Print routes if true
  bool printRoutes;

  // network
  NodeContainer nodes;
  NetDeviceContainer devices;
  Ipv4InterfaceContainer interfaces;

private:
  void CreateNodes ();
  void CreateDevices ();
  void InstallInternetStack ();
  void InstallApplications ();
};

int main (int argc, char **argv)
{
  AodvExample test;
  if (!test.Configure (argc, argv))
    NS_FATAL_ERROR ("Configuration failed. Aborted.");

  test.Run ();
  test.Report (std::cout);
  return 0;
}

//-----------------------------------------------------------------------------
AodvExample::AodvExample () :
  size (18),
  step (6),
  totalTime (40),
  pcap (true),
  printRoutes (true)
{
}

bool
AodvExample::Configure (int argc, char **argv)
{
  // Enable AODV logs by default. Comment this if too noisy
  // LogComponentEnable("AodvRoutingProtocol", LOG_LEVEL_ALL);

  SeedManager::SetSeed (12345);
  
//Config::SetDefault("ns3::RangePropagationLossModel::MaxRange",UintegerValue(30));
  CommandLine cmd;

  cmd.AddValue ("pcap", "Write PCAP traces.", pcap);
  cmd.AddValue ("printRoutes", "Print routing table dumps.", printRoutes);
  cmd.AddValue ("size", "Number of nodes.", size);
  cmd.AddValue ("time", "Simulation time, s.", totalTime);
  cmd.AddValue ("step", "Grid step, m", step);

  cmd.Parse (argc, argv);
  return true;
}

void
AodvExample::Run ()
{
//  Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", UintegerValue (1)); // enable rts cts all the time.
  CreateNodes ();
  CreateDevices ();
  InstallInternetStack ();
  InstallApplications ();

  std::cout << "Starting simulation for " << totalTime << " s ...\n";


  

  Simulator::Stop (Seconds (totalTime));
  AnimationInterface anim ("aodvnew.xml");
  Simulator::Run ();
  Simulator::Destroy ();
}

void
AodvExample::Report (std::ostream &)
}

void
AodvExample::CreateNodes ()
{
  std::cout << "Creating " << (unsigned)size << " nodes " << step << " m apart.\n";
  nodes.Create (18);
  // Name nodes
  for (uint32_t i = 0; i < size; ++i)
    {
      std::ostringstream os;
      os << "node-" << i;
      Names::Add (os.str (), nodes.Get (i));
    }
  // Create static grid
  MobilityHelper mobility;
  mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
                                 "MinX", DoubleValue (10.0),
                                 "MinY", DoubleValue (10.0),
                                 "DeltaX", DoubleValue (step),
                                 "DeltaY", DoubleValue (10.0),
                                 "GridWidth", UintegerValue (6),
                                 "LayoutType", StringValue ("RowFirst"));
  
  mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
                             "Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));
//mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
  mobility.Install (nodes);
}

void
AodvExample::CreateDevices ()
{
  WifiMacHelper wifiMac;
  wifiMac.SetType ("ns3::AdhocWifiMac");
  YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
  //YansWifiChannelHelper wifiChannel;
  //wifiChannel.AddPropagationLoss("ns3::RangePropagationLossModel","MaxRange",StringValue("15"));
  //wifiChannel.AddPropagationLoss(&RangePropagationLossModel::m_range(15));
  wifiPhy.SetChannel (wifiChannel.Create ());
  WifiHelper wifi;
  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", StringValue ("OfdmRate6Mbps"), "RtsCtsThreshold", UintegerValue (0));
  devices = wifi.Install (wifiPhy, wifiMac, nodes); 

  if (pcap)
    {
      wifiPhy.EnablePcapAll (std::string ("aodv"));
    }
}

void
AodvExample::InstallInternetStack ()
{
  AodvHelper aodv;
  // you can configure AODV attributes here using aodv.Set(name, value)
  InternetStackHelper stack;
  stack.SetRoutingHelper (aodv); // has effect on the next Install ()
  stack.Install (nodes);
  Ipv4AddressHelper address;
  address.SetBase ("10.0.0.0", "255.0.0.0");
  interfaces = address.Assign (devices);

  if (printRoutes)
    {
      Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> ("aodv.routes", std::ios::out);
      aodv.PrintRoutingTableAllAt (Seconds (30), routingStream);
    }
}

void
AodvExample::InstallApplications ()
{
  V4PingHelper ping (interfaces.GetAddress (size - 1));
  ping.SetAttribute ("Verbose", BooleanValue (true));

  ApplicationContainer p = ping.Install (nodes.Get (0));
  p.Start (Seconds (0));
  p.Stop (Seconds (totalTime) - Seconds (0.001));
}

[yans-wifi-helper.cc]:
I changed the default value of YansWifiChannelHelper::AddPropagationLoss to RangePropagationLossModel, in line 46 of yans-wifi-helper.cc

[propagation-loss-model.cc]:
I changed the default value of Attribute: MaxRange from 250m to 10m and so on, on line 900 of propagation-loss-model.cc

This is the result of NetAnim that I am getting at Max transmission Range, MaxRange=10: I get a 90% packet loss with this.


As I increase the MaxRange=15, I get the following result and 77% packet loss:


With MaxRange=30, I get 100% packet loss:

Also the thing that is confusing here is that as one can see in the figure that almost all nodes are accessible through the source, then why am I getting 100% packet loss?? I should get 0% packet loss here. 

MaxRange=50 & 0% packet loss: (If I keep MaxRange > 50, i get this following result:)

At this point, with the above figure, I am getting 0 packets lost. In my understanding, I am using a rectangular grid of 100 x 100 meters ( mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
                             "Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));), so a MaxRange of 50 m is enough to get the packets transmitted to the destination by a node that is in the middle. But still I quite don't get why no packets are being lost here. What concept am I thinking wrong?  

Faiza Firdousi

unread,
Oct 3, 2017, 11:10:09 AM10/3/17
to ns-3-users
Plus, I don't see any intermediate nodes at work here. If the transmission range is covering all the nodes then the source is directly sending packets to dest. But if the range is not covering all nodes, as in figure 1 and 2, the source is simply sending packets to the nodes which are reachable through 1 hops, and not sending packet to the nodes beyond its transmission range Shouldn't it be like this in aodv protocol that all the destination nodes should be sent packets through the intermediate nodes if the dest node is not within transmission range of the source? 

Faiza Firdousi

unread,
Oct 8, 2017, 11:33:49 AM10/8/17
to ns-3-users
Hey can anyone help me to figure out where am I going wrong?? The code is posted below:

#include "ns3/aodv-module.h"
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/mobility-module.h"
#include "ns3/wifi-module.h" 
#include "ns3/v4ping-helper.h"
#include "ns3/netanim-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
#include "ns3/csma-module.h"
#include <iostream>
#include <cmath>

using namespace ns3;

NS_LOG_COMPONENT_DEFINE ("ModifiedAodv");

int
main (int argc, char *argv[])
{
  CommandLine cmd;
  cmd.Parse (argc, argv);
  
  Time::SetResolution (Time::NS);
  LogComponentEnable ("ModifiedAodv", LOG_LEVEL_INFO);

  SeedManager::SetSeed (12345);

  Config::SetDefault("ns3::RangePropagationLossModel::MaxRange",StringValue("15"));

  NodeContainer nodes;
  nodes.Create(4);

  // Name nodes
  for (uint32_t i = 0; i < 4; ++i)
    {
      std::ostringstream os;
      os << "node-" << i;
      Names::Add (os.str (), nodes.Get (i));
    }

  //mobility model

  WifiMacHelper wifiMac;
  wifiMac.SetType ("ns3::AdhocWifiMac");
  YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
 
  YansWifiChannelHelper wifiChannel;
  wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
  wifiChannel.AddPropagationLoss ("ns3::RangePropagationLossModel");
  
  wifiPhy.SetChannel (wifiChannel.Create ());

  WifiHelper wifi;
  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", StringValue ("OfdmRate6Mbps"), "RtsCtsThreshold", UintegerValue (0));
  NetDeviceContainer devices;
  devices = wifi.Install (wifiPhy, wifiMac, nodes); 
  
  AodvHelper aodv;
  InternetStackHelper stack;
  stack.SetRoutingHelper (aodv); // has effect on the next Install ()
  stack.Install (nodes);
  Ipv4AddressHelper address;
  address.SetBase ("10.0.0.0", "255.0.0.0");
  Ipv4InterfaceContainer interfaces;
  interfaces = address.Assign (devices);

  Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> ("mod-aodv.routes", std::ios::out);
  aodv.PrintRoutingTableAllAt (Seconds (10), routingStream);

  //applications
  UdpEchoServerHelper echoServer (9);

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

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

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


  Simulator::Stop (Seconds (30));
  Simulator::Run ();
  Simulator::Destroy ();
  return 0;
}

Please please someone help me. I literally done have a single person to help me. Please experts read and run my code once please!!
Reply all
Reply to author
Forward
0 new messages