multiple source nodes to a sink node

1,496 views
Skip to first unread message

omowunmi longe

unread,
Mar 27, 2014, 5:36:45 AM3/27/14
to ns-3-...@googlegroups.com
Hello,
Please I have been trying to modify the wifi-simple-adhoc-grid.cc but I have been challenges in defining multiple source nodes for it since by default it had one source node and sink node. Can you please help out. You asked me to check the applications and helpers and I don't seem to find anyone useful. the bulk-send-helper.cc that I tried didn't work also. Please I'm really new to all these stuffs. Your guidance will be quite appreciated.
Thanks. 

Soumya Banerjee

unread,
Mar 27, 2014, 6:42:56 AM3/27/14
to ns-3-...@googlegroups.com

I needed to do the exact same thing 
here is what i did

Ptr<Socket> sources[numNodes-1] ;   //  declared the source socket as an array of sockets

for (uint32_t id = numNodes-1 ; id >= sourceNode  ; id--){               //and established a connection for each socket in the array
sources[id] = Socket::CreateSocket (c.Get ( id ), tid);
sources[id]->Connect (remote);
Simulator::Schedule (Seconds (30.0), &GenerateTraffic, sources[id], id, numPackets, interPacketInterval);

omowunmi longe

unread,
Mar 28, 2014, 4:38:00 AM3/28/14
to ns-3-...@googlegroups.com
Hi,
Thanks for your response. I tried to include the code you gave but it gave me these errors:

In file included from ./ns3/core-module.h:41:0,

                 from ../scratch/wifi3.cc:72:

./ns3/make-event.h: In member function ‘void ns3::MakeEvent(MEM, OBJ, T1, T2, T3, T4)::EventMemberImpl4::Notify() [with MEM = void (*)(ns3::Ptr<ns3::Socket>, unsigned int, unsigned int, ns3::Time), OBJ = ns3::Ptr<ns3::Socket>, T1 = unsigned int, T2 = unsigned int, T3 = unsigned int, T4 = ns3::Time]’:

../scratch/wifi3.cc:257:1:   instantiated from here

./ns3/make-event.h:223:7: error: ‘((ns3::MakeEvent(MEM, OBJ, T1, T2, T3, T4) [with MEM = void (*)(ns3::Ptr<ns3::Socket>, unsigned int, unsigned int, ns3::Time), OBJ = ns3::Ptr<ns3::Socket>, T1 = unsigned int, T2 = unsigned int, T3 = unsigned int, T4 = ns3::Time]::EventMemberImpl4*)this)->ns3::MakeEvent(MEM, OBJ, T1, T2, T3, T4) [with MEM = void (*)(ns3::Ptr<ns3::Socket>, unsigned int, unsigned int, ns3::Time), OBJ = ns3::Ptr<ns3::Socket>, T1 = unsigned int, T2 = unsigned int, T3 = unsigned int, T4 = ns3::Time]::EventMemberImpl4::m_function’ cannot be used as a member pointer, since it is of type ‘void (*)(ns3::Ptr<ns3::Socket>, unsigned int, unsigned int, ns3::Time)’

Waf: Leaving directory `/home/omowunmi/ns3/ns-allinone-3.16/ns-3.16/build'

Build failed

 -> task in 'wifi3' failed (exit status 1):

            {task 59636560: cxx wifi3.cc -> wifi3.cc.2.o}

['/usr/bin/g++', '-O0', '-ggdb', '-g3', '-Wall', '-Werror', '-Wno-error=deprecated-declarations', '-fstrict-aliasing', '-Wstrict-aliasing', '-pthread', '-Ibuild', '-I.', '-I.', '-I/home/omowunmi/ns3/ns-allinone-3.16', '-DNS3_ASSERT_ENABLE', '-DNS3_LOG_ENABLE', '-DHAVE_PACKET_H=1', '-DHAVE_DL=1', '-DHAVE_IF_TUN_H=1', '../scratch/wifi3.cc', '-c', '-o', 'scratch/wifi3.cc.2.o']

Please what should i do next?

Thanks in advance.

Soumya Banerjee

unread,
Mar 28, 2014, 5:02:14 AM3/28/14
to ns-3-...@googlegroups.com
I'm not too sure but may be the the arguments being passed are not exactly matching the called function. check the mentioned lines .

omowunmi longe

unread,
Mar 28, 2014, 5:42:17 AM3/28/14
to ns-3-...@googlegroups.com
Hi,
I tried to work further on the code and it says:
/scratch/wifi3.cc:259:66: error: name lookup of ‘id’ changed for ISO ‘for’ scoping [-fpermissive]
../scratch/wifi3.cc:259:66: note: (if you use ‘-fpermissive’ G++ will accept your code)

What do you advice?

Thanks

Konstantinos

unread,
Mar 28, 2014, 6:09:38 AM3/28/14
to ns-3-...@googlegroups.com
Do not just copy and paste other people's code into your own. 
Most probably you have defined 'id' variable somewhere else in your code and then used it in the 'for' loop. 

The problem you are getting is not related to NS-3; it is just lack of programming knowledge.

K.

omowunmi longe

unread,
Mar 28, 2014, 8:19:54 AM3/28/14
to ns-3-...@googlegroups.com
Hello,
I'm new to C++ and ns3, so please bear with me. I have tried to further debug the code, it compiled but gave me terminated with signal SIGSEGV fault. So when I run the gdb debugger, I had this report, but I don't understand what it means:

#0  0x00007ffff1013f2e in ns3::Object::CheckLoose (this=0x66e530)
    at ../src/core/model/object.cc:367
#1  0x00007ffff1011e17 in ns3::Object::DoGetObject (this=0x66e530, tid=...)
    at ../src/core/model/object.cc:148
#2  0x00007ffff1411db9 in ns3::Object::GetObject<ns3::SocketFactory> (
    this=0x66e530, tid=...) at ./ns3/object.h:354
#3  0x00007ffff1409dac in ns3::Socket::CreateSocket (node=..., tid=...)
    at ../src/network/model/socket.cc:75
#4  0x000000000040d9e3 in main (argc=2, argv=0x7fffffffdeb8)
    at ../scratch/wifi3.cc:215


PLease find my code below and PLEASE advice. I will appreciate your further guidance. Thanks.

#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/mobility-module.h"
#include "ns3/config-store-module.h"
#include "ns3/wifi-module.h"
#include "ns3/internet-module.h"
#include "ns3/aodv-module.h"
#include "ns3/aodv-helper.h"
#include "ns3/ipv4-static-routing-helper.h"
#include "ns3/ipv4-list-routing-helper.h"

#include "ns3/propagation-module.h"
#include "ns3/flow-monitor-module.h"
#include "ns3/netanim-module.h"

#include <iostream>
#include <fstream>
#include <vector>
#include <string>

NS_LOG_COMPONENT_DEFINE ("wifi3");

using namespace ns3;

void ReceivePacket (Ptr<Socket> socket)
{
  NS_LOG_UNCOND ("Received one packet!");
}

static void GenerateTraffic (Ptr<Socket> socket, uint32_t pktSize,
                             uint32_t pktCount, Time pktInterval )
{
  if (pktCount > 0)
    {
      socket->Send (Create<Packet> (pktSize));
      Simulator::Schedule (pktInterval, &GenerateTraffic,
                           socket, pktSize,pktCount-1, pktInterval);
    }
  else
    {
      socket->Close ();
    }
}


int main (int argc, char *argv[])
{
  std::string phyMode ("DsssRate1Mbps");
  double distance = 500;  // m
  uint32_t packetSize = 1000; // bytes
  uint32_t numPackets = 1;
  uint32_t numNodes = 11;  // by default, 5x5
  uint32_t sinkNode = numNodes;
  uint32_t sourceNode = 1;
  double interval = 1.0; // seconds
  bool verbose = false;
  bool tracing = false;

  CommandLine cmd;

  cmd.AddValue ("phyMode", "Wifi Phy mode", phyMode);
  cmd.AddValue ("distance", "distance (m)", distance);
  cmd.AddValue ("packetSize", "size of application packet sent", packetSize);
  cmd.AddValue ("numPackets", "number of packets generated", numPackets);
  cmd.AddValue ("interval", "interval (seconds) between packets", interval);
  cmd.AddValue ("verbose", "turn on all WifiNetDevice log components", verbose);
  cmd.AddValue ("tracing", "turn on ascii and pcap tracing", tracing);
  cmd.AddValue ("numNodes", "number of nodes", numNodes);
  cmd.AddValue ("sinkNode", "Receiver node number", sinkNode);
  cmd.AddValue ("sourceNode", "Sender node number", sourceNode);

  cmd.Parse (argc, argv);
  // Convert to time object
  Time interPacketInterval = Seconds (interval);

  // disable fragmentation for frames below 2200 bytes
  Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200"));
  // turn off RTS/CTS for frames below 2200 bytes
  Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200"));
  // Fix non-unicast data rate to be the same as that of unicast
  Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode",
                      StringValue (phyMode));

  NodeContainer c;
  c.Create (numNodes);

  // The below set of helpers will help us to put together the wifi NICs we want
  WifiHelper wifi;
  if (verbose)
    {
      wifi.EnableLogComponents ();  // Turn on all Wifi logging
    }

  YansWifiPhyHelper wifiPhy =  YansWifiPhyHelper::Default ();
  // set it to zero; otherwise, gain will be added
  wifiPhy.Set ("RxGain", DoubleValue (-10) );
  // ns-3 supports RadioTap and Prism tracing extensions for 802.11b
  wifiPhy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO);

  YansWifiChannelHelper wifiChannel;
  wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
  wifiChannel.AddPropagationLoss ("ns3::FriisPropagationLossModel");
  wifiPhy.SetChannel (wifiChannel.Create ());

  // Add a non-QoS upper mac, and disable rate control
  NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
  wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
                                "DataMode",StringValue (phyMode),
                                "ControlMode",StringValue (phyMode));
  // Set it to adhoc mode
  wifiMac.SetType ("ns3::AdhocWifiMac");
  NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c);

  MobilityHelper mobility;
  mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
                                 "MinX", DoubleValue (0.0),
                                 "MinY", DoubleValue (0.0),
                                 "DeltaX", DoubleValue (distance),
                                 "DeltaY", DoubleValue (distance),
                                 "GridWidth", UintegerValue (5),
                                 "LayoutType", StringValue ("RowFirst"));
  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
  mobility.Install (c);

  // Enable AODV
  AodvHelper aodv;
  Ipv4StaticRoutingHelper staticRouting;

  Ipv4ListRoutingHelper list;
  list.Add (staticRouting, 0);
  list.Add (aodv, 10);

  InternetStackHelper internet;
  internet.SetRoutingHelper (list); // has effect on the next Install ()
  internet.Install (c);

  Ipv4AddressHelper ipv4;
  NS_LOG_INFO ("Assign IP Addresses.");
  ipv4.SetBase ("10.1.1.0", "255.255.255.0");
  Ipv4InterfaceContainer i = ipv4.Assign (devices);

  TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
  Ptr<Socket> recvSink = Socket::CreateSocket (c.Get (sinkNode), tid);
  InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 80);
  recvSink->Bind (local);
  recvSink->SetRecvCallback (MakeCallback (&ReceivePacket));

  //Ptr<Socket> source = Socket::CreateSocket (c.Get (sourceNode), tid);
  InetSocketAddress remote = InetSocketAddress (i.GetAddress (sinkNode, 0), 80);
  //source->Connect (remote);



  Ptr<Socket> sources[numNodes-1] ;   //  declared the source socket as an array of sockets
  //established a connection for each socket in the array
unsigned int cnt;
  for (cnt = numNodes-2 ; cnt >= 0  ; cnt--)   
    {
      sources[cnt] = Socket::CreateSocket (c.Get ( cnt ), tid);   
      sources[cnt]->Connect (remote);
    }
 


/*uint32_t id;
        InetSocketAddress remote = InetSocketAddress (i.GetAddress (sinkNode, 0), 80);
        Ptr<Socket> sources[numNodes-1];
        for (id = numNodes-1; id >= sourceNode ; id-- )  // establish a connection for each socket in the array

        {    
          sources[id] = Socket::CreateSocket (c.Get ( id ), tid);
          sources[id]->Connect (remote);
        }*/

  if (tracing == true)
    {
      AsciiTraceHelper ascii;
      wifiPhy.EnableAsciiAll (ascii.CreateFileStream ("wifi3.tr"));
      wifiPhy.EnablePcap ("wifi3", devices);
      // Trace routing tables
      Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> ("wifi3.routes", std::ios::out);
      aodv.PrintRoutingTableAllEvery (Seconds (2), routingStream);

      // To do-- enable an IP-level trace that shows forwarding events only
    }

  // Give AODV time to converge-- 30 seconds perhaps
  //Simulator::Schedule (Seconds (30.0), &GenerateTraffic,
                       //source, packetSize, numPackets, interPacketInterval);

  Simulator::Schedule (Seconds (30.0), &GenerateTraffic, sources[cnt], cnt, numPackets, interPacketInterval);

  // Output what we are doing
  NS_LOG_UNCOND ("Testing from node " << sourceNode << " to " << sinkNode << " with grid distance " << distance);

  AnimationInterface anim ("wifi3.xml");
  Simulator::Stop (Seconds (32.0));
  Simulator::Run ();
  Simulator::Destroy ();

  return 0;
}

 
 I will appreciate your further guidance. Thanks.


--
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/PqgALV3gIXM/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 http://groups.google.com/group/ns-3-users.
For more options, visit https://groups.google.com/d/optout.

Tommaso Pecorella

unread,
Mar 27, 2014, 6:22:54 AM3/27/14
to ns-3-...@googlegroups.com
Hi,

can you please describe exactly what is your issue with respect to the issue ?

I mean... There's a source application. There's a sink.
The source application is installed in a node.
Install the application in another node... How can it possibly be simpler than this?

dar...@vspace.in

unread,
Apr 7, 2018, 4:54:28 AM4/7/18
to ns-3-users

how to install 2 device on single node.....like wifi sta and Lte Userenb on same node

Darshan Mhaske

unread,
Apr 7, 2018, 5:02:47 AM4/7/18
to ns-3-users
Reply all
Reply to author
Forward
0 new messages