GlobalRouting Error in combining wireless networks and point to point connection

454 views
Skip to first unread message

SUBIN JOSEPH

unread,
Jul 11, 2016, 9:22:41 AM7/11/16
to ns-3-users
I am trying to create a network topology of n wireless networks and attach a single node to each of the wifi-ap nodes(as point to point connection) of all wireless networks.
I created an echo application also to send datas between the single node(remote node) and one of the wifi nodes.
But I am getting an error as below when i try to run this code/

assert failed. cond="w_lsa", file=../src/internet/model/global-route-manager-impl.cc, line=809
terminate called without an active exception

I am new to ns3. Could some please go through the code and tell me how to solve this problem?

#include "ns3/core-module.h"
#include "ns3/mobility-module.h"
#include "ns3/applications-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/wifi-module.h"
#include "ns3/network-module.h"
#include "ns3/csma-module.h"
#include "ns3/internet-module.h"
#include "ns3/bridge-helper.h"
#include "ns3/netanim-module.h"
#include <vector>
#include <stdint.h>
#include <sstream>
#include <fstream>

using namespace ns3;

int main (int argc, char *argv[])
{
  uint32_t nWifis = 2;
  uint32_t nStas = 2;
  bool sendIp = true;
  bool writeMobility = false;

  CommandLine cmd;
  cmd.AddValue ("nWifis", "Number of wifi networks", nWifis);
  cmd.AddValue ("nStas", "Number of stations per wifi network", nStas);
  cmd.AddValue ("SendIp", "Send Ipv4 or raw packets", sendIp);
  cmd.AddValue ("writeMobility", "Write mobility trace", writeMobility);
  cmd.Parse (argc, argv);

  NodeContainer backboneNodes;
  NetDeviceContainer backboneDevices;
  Ipv4InterfaceContainer backboneInterfaces;
  std::vector<NodeContainer> staNodes;
  std::vector<NetDeviceContainer> staDevices;
  std::vector<NetDeviceContainer> apDevices;
  std::vector<Ipv4InterfaceContainer> staInterfaces;
  std::vector<Ipv4InterfaceContainer> apInterfaces;

  InternetStackHelper stack;
  CsmaHelper csma;
  Ipv4AddressHelper ip;
  ip.SetBase ("192.168.0.0", "255.255.255.0");

  backboneNodes.Create (nWifis);
  stack.Install (backboneNodes);

  backboneDevices = csma.Install (backboneNodes);

  double wifiX = 0.0;

  YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
  wifiPhy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO); 

  for (uint32_t i = 0; i < nWifis; ++i)
    {
      // calculate ssid for wifi subnetwork
      std::ostringstream oss;
      oss << "wifi-default-" << i;
      Ssid ssid = Ssid (oss.str ());

      NodeContainer remoteHost;
      remoteHost.Create(1);
      Ptr<Node> remote=remoteHost.Get(0);
      Ptr<Node> apnode=backboneNodes.Get(i);
      PointToPointHelper p2p;
      p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
      p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
      NetDeviceContainer p2pDevices = p2p.Install(apnode,remote);
      //setup remotenode
      stack.Install (remoteHost);

      // assign AP IP address to bridge, not wifi
      //Ipv4InterfaceContainer

      NodeContainer sta;
      NetDeviceContainer staDev;
      NetDeviceContainer apDev;
      Ipv4InterfaceContainer staInterface;
      Ipv4InterfaceContainer apInterface;
      Ipv4InterfaceContainer remoteInterface;
      MobilityHelper mobility;
      BridgeHelper bridge;
      WifiHelper wifi;
      WifiMacHelper wifiMac;
      YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
      wifiPhy.SetChannel (wifiChannel.Create ());

      sta.Create (nStas);
      mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
                                     "MinX", DoubleValue (wifiX),
                                     "MinY", DoubleValue (0.0),
                                     "DeltaX", DoubleValue (5.0),
                                     "DeltaY", DoubleValue (5.0),
                                     "GridWidth", UintegerValue (1),
                                     "LayoutType", StringValue ("RowFirst"));


      // setup the AP.
      mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
      mobility.Install (remoteHost);
      mobility.Install (backboneNodes.Get (i));
      wifiMac.SetType ("ns3::ApWifiMac",
                       "Ssid", SsidValue (ssid));
      apDev = wifi.Install (wifiPhy, wifiMac, backboneNodes.Get (i));

      NetDeviceContainer bridgeDev;
      bridgeDev = bridge.Install (backboneNodes.Get (i), NetDeviceContainer (apDev, backboneDevices.Get (i)));

      // assign AP IP address to bridge, not wifi
      apInterface = ip.Assign (bridgeDev);
      remoteInterface = ip.Assign (p2pDevices);

      // setup the STAs
      stack.Install (sta);
      mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
      mobility.Install (sta);
      wifiMac.SetType ("ns3::StaWifiMac",
                       "Ssid", SsidValue (ssid),
                       "ActiveProbing", BooleanValue (false));
      staDev = wifi.Install (wifiPhy, wifiMac, sta);
      staInterface = ip.Assign (staDev);

      //creating udp applications

      UdpEchoServerHelper echoServer (9);

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

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

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

      // save everything in containers.
      staNodes.push_back (sta);
      apDevices.push_back (apDev);
      apInterfaces.push_back (apInterface);
      staDevices.push_back (staDev);
      staInterfaces.push_back (staInterface);

      wifiX += 20.0;
    }
    Ipv4GlobalRoutingHelper::PopulateRoutingTables ();

 /* Address dest;
  std::string protocol;
  if (sendIp)
    {
      dest = InetSocketAddress (staInterfaces[1].GetAddress (1), 1025);
      protocol = "ns3::UdpSocketFactory";
    }
  else
    {
      PacketSocketAddress tmp;
      tmp.SetSingleDevice (staDevices[0].Get (0)->GetIfIndex ());
      tmp.SetPhysicalAddress (staDevices[1].Get (0)->GetAddress ());
      tmp.SetProtocol (0x807);
      dest = tmp;
      protocol = "ns3::PacketSocketFactory";
    }

  OnOffHelper onoff = OnOffHelper (protocol, dest);
  onoff.SetConstantRate (DataRate ("500kb/s"));
  ApplicationContainer apps = onoff.Install (staNodes[0].Get (0));
  apps.Start (Seconds (0.5));
  apps.Stop (Seconds (3.0));

  wifiPhy.EnablePcap ("wifi-wired-bridging", apDevices[0]);
  wifiPhy.EnablePcap ("wifi-wired-bridging", apDevices[1]);*/

  if (writeMobility)
    {
      AsciiTraceHelper ascii;
      MobilityHelper::EnableAsciiAll (ascii.CreateFileStream ("wifi-wired-bridging.mob"));
    }

  AnimationInterface anim("edgecomp2.xml");
  Simulator::Stop (Seconds (5.0));
  Simulator::Run ();
  Simulator::Destroy ();
}


Tommaso Pecorella

unread,
Jul 11, 2016, 10:38:44 AM7/11/16
to ns-3-users
Hi,

the first thing to do is to give a look at the posing guidelines, there are some useful hints.
The second thing is to search in the group. This issue has been discussed in the past, and a solution is available in the relevant threads.

Cheers,

T.

SUBIN JOSEPH

unread,
Jul 11, 2016, 12:59:12 PM7/11/16
to ns-3-users
Dear Tommaso,
I have read some related threads about this problem especially https://groups.google.com/forum/#!topic/ns-3-users/mKBN1I_6UGQ .But unfortunately I could not find the exact solution for it.Do I have to use static IP routing instead of Global routing?Before attaching the remote node to ap node,It was working fine without using GlobalroutingHelper. Infact I don't know what exactly happens when we add another channel(p2p channel) to the ap node.Does it work without populating the routing trees globally?
Thanks in advance
Subin Joseph

Tommaso Pecorella

unread,
Jul 12, 2016, 4:09:27 AM7/12/16
to ns-3-users

SUBIN JOSEPH

unread,
Jul 13, 2016, 9:32:43 AM7/13/16
to ns-3-users
Dear Tommaso,
Thank you for your reply.I understand that GlobalRouting cannot be applied in wireless networks and I should use static routing instead of it.But I have some doubts regarding it. Do I need to use static routing only for AP node and remote node(here server).?
Here in the following code it creates routing from A to C.But here it is able to specifically mention the address of the destination and next hop.But in a loop,How do i know whats the ip-address of the destination?

// Create static routes from A to C
  Ptr<Ipv4StaticRouting> staticRoutingA = ipv4RoutingHelper.GetStaticRouting (ipv4A);
  // The ifIndex for this outbound route is 1; the first p2p link added
staticRoutingA->AddHostRouteTo (Ipv4Address ("192.168.1.1"), Ipv4Address ("10.1.1.2"), 1);

Tommaso Pecorella

unread,
Jul 13, 2016, 12:31:56 PM7/13/16
to ns-3-users
Please double check the discussion.
The only nodes where you have to disable GlobalRouting and install a default route (i.e., one to 0.0.0.0) are the STAs.

T.

SUBIN JOSEPH

unread,
Jul 13, 2016, 1:11:38 PM7/13/16
to ns-3-users
Dear Tommaso,
Thanks for your reply.Do you mean that I have to tell explicitly to STAs that it has to send data to remote node through this particular route(suppose STA1--wifi-AP1-------remote node)?Sorry for the naive qn..I don't really understand what does it mean? 

Tommaso Pecorella

unread,
Jul 13, 2016, 1:32:16 PM7/13/16
to ns-3-users
It's not wise to play with routing if you don't know how routing works...
https://en.wikipedia.org/wiki/Default_route

T.

SUBIN JOSEPH

unread,
Aug 1, 2016, 7:19:45 AM8/1/16
to ns-3-users
Dear Tommaso,
 I understood how subnetting and default route works.But I am not sure how to apply default route to many wifi stations at one time.I have seen the following code can be applied for each individual wifi STA.But how can apply it for all created wifi nodes at one time.?

Ptr<Node> Node = your node; 
Ipv4StaticRoutingHelper helper; 
Ptr<Ipv4> ipv4 = Node->GetObject<Ipv4>(); 
Ptr<Ipv4StaticRouting> Ipv4stat = helper.GetStaticRouting(ipv4); 
Ipv4stat->SetDefaultRoute(....) 

Tommaso Pecorella

unread,
Aug 1, 2016, 11:14:34 AM8/1/16
to ns-3-users
What about a loop ?

T.
Message has been deleted

SUBIN JOSEPH

unread,
Aug 1, 2016, 11:45:38 AM8/1/16
to ns-3-users
Dear Tommaso,
Thank you for your reply.Let me try that.But I have another doubt here..Here I am bridging all the wifi networks to one whole network.(please have a look at my code)But I am confused whether we can apply bridging if a point to point network is attached to AP node.If so can we apply the same IP addressing for the point to point network.(Here the addressing starts from 192.168.0.0 and no separate addressing for point to point network.). Is that a problem here??

Tommaso Pecorella

unread,
Aug 1, 2016, 12:07:12 PM8/1/16
to ns-3-users
You're definitely using Bridge in the wrong way.
Perhaps what you're trying to do is possible, but definitely not in this way.
Sadly, 1) I don't know what you're trying to do and 2) it's your job to do it, isn't it ?


Cheers,


T.

SUBIN JOSEPH

unread,
Aug 1, 2016, 1:06:53 PM8/1/16
to ns-3-...@googlegroups.com
Dear Tomasso,
Sorry for not conveying the problem discussion correctly.Here is what I am trying to do. I am trying to create a network topology of n wireless networks and attach a single node(like server) to each of the wifi-ap nodes(as point to point connection) of all wireless networks.Please find the attached topology here with.

Then I need to have a udp communication between any of the wifi stations and server.This is part of my project.
Would it be possble for me to modify the below example to get the proposed topology?

Regards
Subin




--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to a topic in the Google Groups "ns-3-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ns-3-users/ZSy3NzbRTcI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ns-3-users+...@googlegroups.com.
To post to this group, send email to ns-3-...@googlegroups.com.
Visit this group at https://groups.google.com/group/ns-3-users.
For more options, visit https://groups.google.com/d/optout.

wifi.png

Tommaso Pecorella

unread,
Aug 1, 2016, 7:06:47 PM8/1/16
to ns-3-users
Dear Subin,

I think you have to understand what's a bridge first.

A Bridge NetDevice takes n NetDevices (they must be using the same address format, like 802.11 and csma) and it merges them into one NetDevice.
The IP layer will see only the merged NetDevice, and all the packets will flow between the merged netDevices without the IP intervention.
Note that the Bridge NetDevice will allow to merge NetDevices belonging to different nodes, but this is definitely a bad idea.

Now, in your scheme each AP does have 3 interfaces. What you didn't specify is if you want to have all of them bridged or just two. If you bridge them all, then the two servers will be in the same physical subnet. It's up to you to decide if this is fine.
If you bridge only 2 interfaces, then you'll need some routing between the two APs, assuming that you want them to talk to each other.

Anyway, this is your decision, not mine.

Have a nice work,

T.

SUBIN JOSEPH

unread,
Aug 2, 2016, 2:04:13 AM8/2/16
to ns-3-...@googlegroups.com
Dear Tommaso,
Thank you for your reply.I do not want my servers to be in the same subnet. I just want to bridge only 2 interfaces. What routing can we apply between 2 APs here.?Does Global routing works for servers here.
Would it be possible for me to modify the below example to get the proposed topology?


Tommaso Pecorella

unread,
Aug 2, 2016, 2:20:32 AM8/2/16
to ns-3-users
Answers in-line


On Tuesday, August 2, 2016 at 8:04:13 AM UTC+2, SUBIN JOSEPH wrote:
Dear Tommaso,
Thank you for your reply.I do not want my servers to be in the same subnet. I just want to bridge only 2 interfaces. What routing can we apply between 2 APs here.?Does Global routing works for servers here.

Yes, it works. See the above discussion to know what  to do.
 
Would it be possible for me to modify the below example to get the proposed topology?

You can modify any example you want. As a matter of fact "modify" doesn't state how many modifications you need to do. 

T.

SUBIN JOSEPH

unread,
Aug 2, 2016, 8:45:19 AM8/2/16
to ns-3-...@googlegroups.com
Dear Tomasso,
Thank you again for your guidance.I modified mixed-wireless.cc file and included an echo application to send the data from the first wired LAN node on the first wired LAN to the last wireless STA on the last infrastructure net.Here the program ran without an error.But Its not showing the echo application result.Could you please tell me whats the problem here?Please find the attached file here with.
Regards
Subin

#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/csma-module.h"
#include "ns3/olsr-helper.h"
#include "ns3/internet-module.h"
#include "ns3/netanim-module.h"

using namespace ns3;

//
// Define logging keyword for this file
//
NS_LOG_COMPONENT_DEFINE ("MixedWireless");

//
// This function will be used below as a trace sink, if the command-line
// argument or default value "useCourseChangeCallback" is set to true
// 
static void
CourseChangeCallback (std::string path, Ptr<const MobilityModel> model)
{
  Vector position = model->GetPosition ();
  std::cout << "CourseChange " << path << " x=" << position.x << ", y=" << position.y << ", z=" << position.z << std::endl;
}

int 
main (int argc, char *argv[])
{
  //
  // First, we declare and initialize a few local variables that control some 
  // simulation parameters.
  //
  uint32_t backboneNodes = 4;
  uint32_t infraNodes = 3;
  uint32_t lanNodes = 2;
  uint32_t stopTime = 20;
  bool useCourseChangeCallback = false;

  //
  // Simulation defaults are typically set next, before command line
  // arguments are parsed.
  //
  //Config::SetDefault ("ns3::OnOffApplication::PacketSize", StringValue ("1472"));
  //Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("100kb/s"));

  //
  // For convenience, we add the local variables to the command line argument
  // system so that they can be overridden with flags such as 
  // "--backboneNodes=20"
  //
  CommandLine cmd;
  cmd.AddValue ("backboneNodes", "number of backbone nodes", backboneNodes);
  cmd.AddValue ("infraNodes", "number of leaf nodes", infraNodes);
  cmd.AddValue ("lanNodes", "number of LAN nodes", lanNodes);
  cmd.AddValue ("stopTime", "simulation stop time (seconds)", stopTime);
  cmd.AddValue ("useCourseChangeCallback", "whether to enable course change tracing", useCourseChangeCallback);

  //
  // The system global variables and the local values added to the argument
  // system can be overridden by command line arguments by using this call.
  //
  cmd.Parse (argc, argv);

  if (stopTime < 10)
    {
      std::cout << "Use a simulation stop time >= 10 seconds" << std::endl;
      exit (1);
    }
  /////////////////////////////////////////////////////////////////////////// 
  //                                                                       //
  // Construct the backbone                                                //
  //                                                                       //
  /////////////////////////////////////////////////////////////////////////// 

  //
  // Create a container to manage the nodes of the adhoc (backbone) network.
  // Later we'll create the rest of the nodes we'll need.
  //
  NodeContainer backbone;
  backbone.Create (backboneNodes);
  //
  // Create the backbone wifi net devices and install them into the nodes in 
  // our container
  //
  WifiHelper wifi;
  WifiMacHelper mac;
  mac.SetType ("ns3::AdhocWifiMac");
  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
                                "DataMode", StringValue ("OfdmRate54Mbps"));
  YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
  wifiPhy.SetChannel (wifiChannel.Create ());
  NetDeviceContainer backboneDevices = wifi.Install (wifiPhy, mac, backbone);

  // We enable OLSR (which will be consulted at a higher priority than
  // the global routing) on the backbone ad hoc nodes
  NS_LOG_INFO ("Enabling OLSR routing on all backbone nodes");
  OlsrHelper olsr;
  //
  // Add the IPv4 protocol stack to the nodes in our container
  //
  InternetStackHelper internet;
  internet.SetRoutingHelper (olsr); // has effect on the next Install ()
  internet.Install (backbone);

  //
  // 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");
  ipAddrs.Assign (backboneDevices);

  //
  // The ad-hoc network nodes need a mobility model so we aggregate one to 
  // each of the nodes we just finished building.
  //
  MobilityHelper mobility;
  mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
                                 "MinX", DoubleValue (20.0),
                                 "MinY", DoubleValue (20.0),
                                 "DeltaX", DoubleValue (20.0),
                                 "DeltaY", DoubleValue (20.0),
                                 "GridWidth", UintegerValue (5),
                                 "LayoutType", StringValue ("RowFirst"));
  mobility.SetMobilityModel ("ns3::RandomDirection2dMobilityModel",
                             "Bounds", RectangleValue (Rectangle (-500, 500, -500, 500)),
                             "Speed", StringValue ("ns3::ConstantRandomVariable[Constant=2]"),
                             "Pause", StringValue ("ns3::ConstantRandomVariable[Constant=0.2]"));
  mobility.Install (backbone);

  /////////////////////////////////////////////////////////////////////////// 
  //                                                                       //
  // Construct the LANs                                                    //
  //                                                                       //
  /////////////////////////////////////////////////////////////////////////// 

  // Reset the address base-- all of the CSMA networks will be in
  // the "172.16 address space
  ipAddrs.SetBase ("172.16.0.0", "255.255.255.0");


  for (uint32_t i = 0; i < backboneNodes; ++i)
    {
      NS_LOG_INFO ("Configuring local area network for backbone node " << i);
      //
      // Create a container to manage the nodes of the LAN.  We need
      // two containers here; one with all of the new nodes, and one
      // with all of the nodes including new and existing nodes
      //
      NodeContainer newLanNodes;
      newLanNodes.Create (lanNodes - 1);
      // Now, create the container with all nodes on this link
      NodeContainer lan (backbone.Get (i), newLanNodes);
      //
      // Create the CSMA net devices and install them into the nodes in our 
      // collection.
      //
      CsmaHelper csma;
      csma.SetChannelAttribute ("DataRate", 
                                DataRateValue (DataRate (5000000)));
      csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
      NetDeviceContainer lanDevices = csma.Install (lan);
      //
      // Add the IPv4 protocol stack to the new LAN nodes
      //
      internet.Install (newLanNodes);
      //
      // Assign IPv4 addresses to the device drivers (actually to the 
      // associated IPv4 interfaces) we just created.
      //
      ipAddrs.Assign (lanDevices);
      //
      // Assign a new network prefix for the next LAN, according to the
      // network mask initialized above
      //

      ipAddrs.NewNetwork ();
      //
      // The new LAN nodes need a mobility model so we aggregate one
      // to each of the nodes we just finished building.
      //


      MobilityHelper mobilityLan;
      Ptr<ListPositionAllocator> subnetAlloc = 
        CreateObject<ListPositionAllocator> ();
      for (uint32_t j = 0; j < newLanNodes.GetN (); ++j)
        {
          subnetAlloc->Add (Vector (0.0, j*10 + 10, 0.0));
        }
      mobilityLan.PushReferenceMobilityModel (backbone.Get (i));
      mobilityLan.SetPositionAllocator (subnetAlloc);
      mobilityLan.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
      mobilityLan.Install (newLanNodes);
    }

  /////////////////////////////////////////////////////////////////////////// 
  //                                                                       //
  // Construct the mobile networks                                         //
  //                                                                       //
  /////////////////////////////////////////////////////////////////////////// 

  // Reset the address base-- all of the 802.11 networks will be in
  // the "10.0" address space
  ipAddrs.SetBase ("10.0.0.0", "255.255.255.0");

  for (uint32_t i = 0; i < backboneNodes; ++i)
    {
      NS_LOG_INFO ("Configuring wireless network for backbone node " << i);
      //
      // Create a container to manage the nodes of the LAN.  We need
      // two containers here; one with all of the new nodes, and one
      // with all of the nodes including new and existing nodes
      //
      NodeContainer stas;
      stas.Create (infraNodes - 1);
      // Now, create the container with all nodes on this link
      NodeContainer infra (backbone.Get (i), stas);
      //
      // Create an infrastructure network
      //
      WifiHelper wifiInfra;
      WifiMacHelper macInfra;
      wifiPhy.SetChannel (wifiChannel.Create ());
      // Create unique ssids for these networks
      std::string ssidString ("wifi-infra");
      std::stringstream ss;
      ss << i;
      ssidString += ss.str ();
      Ssid ssid = Ssid (ssidString);
      wifiInfra.SetRemoteStationManager ("ns3::ArfWifiManager");
      // setup stas
      macInfra.SetType ("ns3::StaWifiMac",
                        "Ssid", SsidValue (ssid),
                        "ActiveProbing", BooleanValue (false));
      NetDeviceContainer staDevices = wifiInfra.Install (wifiPhy, macInfra, stas);
      // setup ap.
      macInfra.SetType ("ns3::ApWifiMac",
                        "Ssid", SsidValue (ssid),
                        "BeaconGeneration", BooleanValue (true),
                        "BeaconInterval", TimeValue(Seconds(2.5)));
      NetDeviceContainer apDevices = wifiInfra.Install (wifiPhy, macInfra, backbone.Get (i));
      // Collect all of these new devices
      NetDeviceContainer infraDevices (apDevices, staDevices);

      // Add the IPv4 protocol stack to the nodes in our container
      //
      internet.Install (stas);
      //
      // Assign IPv4 addresses to the device drivers (actually to the associated
      // IPv4 interfaces) we just created.
      //
      ipAddrs.Assign (infraDevices);
      //
      // Assign a new network prefix for each mobile network, according to 
      // the network mask initialized above
      //
      ipAddrs.NewNetwork ();
      //
      // The new wireless nodes need a mobility model so we aggregate one 
      // to each of the nodes we just finished building.
      //
      Ptr<ListPositionAllocator> subnetAlloc = 
        CreateObject<ListPositionAllocator> ();
      for (uint32_t j = 0; j < infra.GetN (); ++j)
        {
          subnetAlloc->Add (Vector (0.0, j, 0.0));
        }
      mobility.PushReferenceMobilityModel (backbone.Get (i));
      mobility.SetPositionAllocator (subnetAlloc);
      mobility.SetMobilityModel ("ns3::RandomDirection2dMobilityModel",
                                 "Bounds", RectangleValue (Rectangle (-10, 10, -10, 10)),
                                 "Speed", StringValue ("ns3::ConstantRandomVariable[Constant=3]"),
                                 "Pause", StringValue ("ns3::ConstantRandomVariable[Constant=0.4]"));
      mobility.Install (stas);
    }

  /////////////////////////////////////////////////////////////////////////// 
  //                                                                       //
  // Application configuration                                             //
  //                                                                       //
  /////////////////////////////////////////////////////////////////////////// 

  // Create the OnOff application to send UDP datagrams of size
  // 210 bytes at a rate of 10 Kb/s, between two nodes
  // We'll send data from the first wired LAN node on the first wired LAN
  // to the last wireless STA on the last infrastructure net, thereby
  // causing packets to traverse CSMA to adhoc to infrastructure links

  NS_LOG_INFO ("Create Applications.");
  /*uint16_t port = 9;   // Discard port (RFC 863)

  // Let's make sure that the user does not define too few nodes
  // to make this example work.  We need lanNodes > 1  and infraNodes > 1
  NS_ASSERT (lanNodes > 1 && infraNodes > 1);*/

  // We want the source to be the first node created outside of the backbone
  // Conveniently, the variable "backboneNodes" holds this node index value
  Ptr<Node> appSource = NodeList::GetNode (backboneNodes);
  // We want the sink to be the last node created in the topology.
  uint32_t lastNodeIndex = backboneNodes + backboneNodes*(lanNodes - 1) + backboneNodes*(infraNodes - 1) - 1;
  Ptr<Node> appSink = NodeList::GetNode (lastNodeIndex);
  // Let's fetch the IP address of the last node, which is on Ipv4Interface 1
  Ipv4Address remoteAddr = appSink->GetObject<Ipv4> ()->GetAddress (1, 0).GetLocal ();

  UdpEchoServerHelper echoServer (9);

  ApplicationContainer serverApps = echoServer.Install (appSource);
  serverApps.Start (Seconds (1.0));
  serverApps.Stop (Seconds (10.0));

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

  ApplicationContainer clientApps = echoClient.Install (appSink);
  clientApps.Start (Seconds (2.0));
  clientApps.Stop (Seconds (10.0));

  /////////////////////////////////////////////////////////////////////////// 
  //                                                                       //
  // Tracing configuration                                                 //
  //                                                                       //
  /////////////////////////////////////////////////////////////////////////// 

  NS_LOG_INFO ("Configure Tracing.");
  CsmaHelper csma;

  //
  // Let's set up some ns-2-like ascii traces, using another helper class
  //
  AsciiTraceHelper ascii;
  Ptr<OutputStreamWrapper> stream = ascii.CreateFileStream ("mixed-wireless.tr");
  wifiPhy.EnableAsciiAll (stream);
  csma.EnableAsciiAll (stream);
  internet.EnableAsciiIpv4All (stream);

  // Csma captures in non-promiscuous mode
  csma.EnablePcapAll ("mixed-wireless", false);
  // pcap captures on the backbone wifi devices
  wifiPhy.EnablePcap ("mixed-wireless", backboneDevices, false);
  // pcap trace on the application data sink
  wifiPhy.EnablePcap ("mixed-wireless", appSink->GetId (), 0);

  if (useCourseChangeCallback == true)
    {
      Config::Connect ("/NodeList/*/$ns3::MobilityModel/CourseChange", MakeCallback (&CourseChangeCallback));
    }

  AnimationInterface anim ("wifi-p2p.xml");

  /////////////////////////////////////////////////////////////////////////// 
  //                                                                       //
  // Run simulation                                                        //
  //                                                                       //
  /////////////////////////////////////////////////////////////////////////// 

  NS_LOG_INFO ("Run Simulation.");
  Simulator::Stop (Seconds (10.0));
  Simulator::Run ();
  Simulator::Destroy ();
}
wifi_p2p.cc

SUBIN JOSEPH

unread,
Aug 2, 2016, 11:05:05 AM8/2/16
to ns-3-...@googlegroups.com
Dear Tommaso,
I figured out the problem.But now I am able to send the packets only in one direction.(ie from LAN node to the last wireless STA) not vice versa.
The result is as follows At time 2s client sent 1024 bytes to 10.0.3.3 port 9.
I don't understand why server is not able to send data back to client.Please find the update script attached here with or you can have a look on the following script.
int 
main (int argc, char *argv[])
{
  Time::SetResolution (Time::NS);
  LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
  LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);

  if (stopTime < 10)
    {
      std::cout << "Use a simulation stop time >= 10 seconds" << std::endl;
      exit (1);
    }
  /////////////////////////////////////////////////////////////////////////// 
  //                                                                       //
  // Construct the backbone                                                //
  //                                                                       //
  /////////////////////////////////////////////////////////////////////////// 

  //
  // Create a container to manage the nodes of the adhoc (backbone) network.
  // Later we'll create the rest of the nodes we'll need.
  //
  NodeContainer backbone;
  backbone.Create (backboneNodes);
  //
  // Create the backbone wifi net devices and install them into the nodes in 
  // our container
  //
  WifiHelper wifi;
  WifiMacHelper mac;
  mac.SetType ("ns3::AdhocWifiMac");
  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
                                "DataMode", StringValue ("OfdmRate54Mbps"));
  YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
  wifiPhy.SetChannel (wifiChannel.Create ());
  NetDeviceContainer backboneDevices = wifi.Install (wifiPhy, mac, backbone);

  // We enable OLSR (which will be consulted at a higher priority than
  // the global routing) on the backbone ad hoc nodes
  NS_LOG_INFO ("Enabling OLSR routing on all backbone nodes");
  OlsrHelper olsr;
  //
  // Add the IPv4 protocol stack to the nodes in our container
  //
  InternetStackHelper internet;
  internet.SetRoutingHelper (olsr); // has effect on the next Install ()
  internet.Install (backbone);

  //
  // 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");
  ipAddrs.Assign (backboneDevices);

  //
  // The ad-hoc network nodes need a mobility model so we aggregate one to 
  // each of the nodes we just finished building.
  //
  MobilityHelper mobility;
  mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
                                 "MinX", DoubleValue (20.0),
                                 "MinY", DoubleValue (20.0),
                                 "DeltaX", DoubleValue (20.0),
                                 "DeltaY", DoubleValue (20.0),
                                 "GridWidth", UintegerValue (5),
                                 "LayoutType", StringValue ("RowFirst"));
      macInfra.SetType ("ns3::StaWifiMac",
                        "Ssid", SsidValue (ssid),
                        "ActiveProbing", BooleanValue (false));
  //Ipv4Address sourceAddr = appSource->GetObject<Ipv4> ()->GetAddress (1, 0).GetLocal ();

  // We want the sink to be the last node created in the topology.
  uint32_t lastNodeIndex = backboneNodes + backboneNodes*(lanNodes - 1) + backboneNodes*(infraNodes - 1) - 1;
  Ptr<Node> appSink = NodeList::GetNode (lastNodeIndex);
  // Let's fetch the IP address of the last node, which is on Ipv4Interface 1
  Ipv4Address remoteAddr = appSink->GetObject<Ipv4> ()->GetAddress (1, 0).GetLocal ();

  UdpEchoServerHelper echoServer (9);

  ApplicationContainer serverApps = echoServer.Install (appSink);
  serverApps.Start (Seconds (1.0));
  serverApps.Stop (Seconds (10.0));

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

  ApplicationContainer clientApps = echoClient.Install (appSource);
  clientApps.Start (Seconds (2.0));
  clientApps.Stop (Seconds (10.0));

  //AnimationInterface anim("mixedwireless.xml");
  Simulator::Stop (Seconds (10.0));
  Simulator::Run ();
  Simulator::Destroy ();
}

Tommaso Pecorella

unread,
Aug 2, 2016, 5:14:42 PM8/2/16
to ns-3-users
Please do not copy-paste your source code. Use the attachment button.

T.


On Tuesday, August 2, 2016 at 5:05:05 PM UTC+2, SUBIN JOSEPH wrote:
Dear Tommaso,

SUBIN JOSEPH

unread,
Aug 2, 2016, 6:29:20 PM8/2/16
to ns-3-...@googlegroups.com
Dear Tommaso,
Sorry for that.Please find the attache script here with.As mentioned in the previous mail.I am still facing the same problem that I am able to send the packets only in one direction.(ie from LAN node to the last wireless STA or from wireless STA to LAN node) not vice versa.
The result is as follows At time 2s client sent 1024 bytes to 10.0.2.2 port 9.
But the topology seems to be right.But I am not able to find the exact problem.Please help me in this regard
Thanks and Regards
Subin 

wifi_p2p.cc
Reply all
Reply to author
Forward
0 new messages