about multi-hop networks &OLSR

255 views
Skip to first unread message

Zhongxu Yang

unread,
Jul 15, 2020, 7:04:28 AM7/15/20
to ns-3-users
Hi everyone, I am trying to experiment with a multi hop wireless network (wireless mesh) and am using ad-hoc mac along with OLSR routing. However it seems whenever the destination is more than 2 hops away the routing fails and I am having trouble finding out why.  here is an 8 nodes example in a grid mode .Nodes 3 is out of the range of one hop. and it fail to establish Tcp connect. In wireshark ,node 3 just has ARP broadcast without reply.


Here is my simulation scenario (sorry for the length):




//#include <qos-wifi-mac-helper.h>
#include <fstream>
#include <iostream>
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/applications-module.h"
#include "ns3/wifi-module.h"
#include "ns3/mobility-module.h"
#include "ns3/internet-module.h"
 #include "ns3/netanim-module.h"
#include "ns3/olsr-module.h"
#include "ns3/flow-monitor-module.h"
#include "ns3/dsdv-module.h"
#include "ns3/ipv4-global-routing-helper.h"

using namespace ns3;
 
NS_LOG_COMPONENT_DEFINE ("AdHocExample");
 
int
main(int argc,char *argv[])
{
Time::SetResolution (Time::NS);
 
Config::SetDefault("ns3::TcpL4Protocol::SocketType", StringValue("ns3::TcpNewReno"));
LogComponentEnable ("AdHocExample", LOG_LEVEL_INFO);
// LogComponentEnable ("TcpL4Protocol", LOG_LEVEL_INFO);
LogComponentEnable ("PacketSink", LOG_LEVEL_ALL);
 
uint32_t nAdHoc=8;
int nodeSpeed = 17; //in m/s
uint32_t acessPoint = 0;
uint32_t SentPackets =0;
    uint32_t ReceivedPackets =0;
    uint32_t LostPackets =0;
CommandLine cmd;
 
cmd.AddValue ("nAdHoc", "Number of wifi ad devices", nAdHoc);
 
cmd.Parse (argc,argv);
 
NodeContainer AdHocNode;
AdHocNode.Create(nAdHoc);
 //set a wifi
WifiHelper wifi;
wifi.SetStandard(WIFI_PHY_STANDARD_80211a); //
wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager","DataMode",StringValue("OfdmRate6Mbps"));
 
//wifichannle & wifiphy
  YansWifiChannelHelper wifiChannel ;
  wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
  wifiChannel.AddPropagationLoss ("ns3::TwoRayGroundPropagationLossModel",
                  "SystemLoss", DoubleValue(5),
                "HeightAboveZ", DoubleValue(15));
  YansWifiPhyHelper wifiPhy =  YansWifiPhyHelper::Default ();
 // trasmission power
    wifiPhy.Set ("TxPowerStart", DoubleValue(40));
    wifiPhy.Set ("TxPowerEnd", DoubleValue(40));
    wifiPhy.Set ("TxPowerLevels", UintegerValue(1));
    wifiPhy.Set ("TxGain", DoubleValue(0));
    wifiPhy.Set ("RxGain", DoubleValue(0));
    wifiPhy.Set ("EnergyDetectionThreshold", DoubleValue(-61.8));
    wifiPhy.Set ("CcaMode1Threshold", DoubleValue(-64.8));
    wifiPhy.Set ("ChannelWidth",UintegerValue(40));
    //wifiPhy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11);
    wifiPhy.SetChannel (wifiChannel.Create ());
  // Add a non-QoS upper mac
   WifiMacHelper wifiMac;
  // NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
   wifiMac.SetType ("ns3::AdhocWifiMac");
 
NetDeviceContainer AdHocDevices;
AdHocDevices = wifi.Install(wifiPhy,wifiMac,AdHocNode);
 
   //Enable OLSR
    OlsrHelper olsr;
   // Install the routing protocol
    Ipv4ListRoutingHelper list;
    list.Add (olsr, 100);  
//1 hop range 230m   
MobilityHelper mobility;
mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
                                 "MinX", DoubleValue (0.0),
                                 "MinY", DoubleValue (0.0),
                                 "DeltaX", DoubleValue (100.0),
                                 "DeltaY", DoubleValue (100.0),
                                 "GridWidth", UintegerValue (4),
                                 "LayoutType", StringValue ("RowFirst"));
 
std::stringstream ssSpeed;
      ssSpeed << "ns3::UniformRandomVariable[Min=10.0|Max=" << nodeSpeed << "]";
mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
                     "Mode",StringValue("Time"),
"Time",StringValue("10s"),
                     "Speed", StringValue (ssSpeed.str ()),
                             "Bounds", RectangleValue (Rectangle (-1000, 1000, -1000, 1000)));
mobility.Install (AdHocNode);
 
InternetStackHelper Internet;
Internet.Install(AdHocNode);
 
Ipv4AddressHelper address;
address.SetBase("195.1.1.0","255.255.255.0");
 
Ipv4InterfaceContainer AdHocIp;
AdHocIp = address.Assign(AdHocDevices);
 
NS_LOG_INFO ("Create Applications.");
uint16_t port = 9999;
OnOffHelper onOff1("ns3::TcpSocketFactory",Address(InetSocketAddress(AdHocIp.GetAddress(0),port)));
onOff1.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
onOff1.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
onOff1.SetAttribute ("DataRate", DataRateValue (DataRate("10Mbps")));
onOff1.SetAttribute ("PacketSize", UintegerValue (2048));
    for (uint32_t i = 0; i < nAdHoc; ++i) {
            if (i != acessPoint) {
            ApplicationContainer apps1 = onOff1.Install(AdHocNode.Get(i));
            apps1.Start(Seconds(1.0));
            apps1.Stop(Seconds(50.0));           
            }
    }
 
PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory", Address(InetSocketAddress (Ipv4Address::GetAny(), port)));
ApplicationContainer apps2 = sinkHelper.Install(AdHocNode.Get(0));
 
apps2.Start(Seconds(0.0));
apps2.Stop(Seconds(50.0));
 
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
 
wifiPhy.SetPcapDataLinkType(WifiPhyHelper::DLT_IEEE802_11_RADIO);
wifiPhy.EnablePcap("accesspoint",AdHocDevices);
 //Install FlowMonitor on all nodes

     FlowMonitorHelper flowmon;
     Ptr<FlowMonitor> monitor = flowmon.InstallAll ();


Simulator::Stop(Seconds(50.0));

    AnimationInterface anim ("1.xml");
    anim.SetMaxPktsPerTraceFile(99999999999999);

Simulator::Run();
    //this is the code shows the result
    Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier>(flowmon.GetClassifier());
    std::map<FlowId,FlowMonitor::FlowStats> stats = monitor->GetFlowStats();

    int j=0;
      float AvgThroughput = 0;
      Time Delay;
      Time Jitter;

         NS_LOG_UNCOND("--------Results out put ID wise--------" <<std::endl);
    for(std::map <FlowId,FlowMonitor::FlowStats> ::const_iterator iter = stats.begin();iter != stats.end();++iter)
    {
     Ipv4FlowClassifier::FiveTuple t = classifier -> FindFlow(iter->first);
     NS_LOG_UNCOND("-------Flow ID:"<< iter-> first);
     NS_LOG_UNCOND("Src Addr"<< t.sourceAddress << "Dst Addr"<< t.destinationAddress);
     NS_LOG_UNCOND("Sent Packets ="<< iter->second.txPackets);
     NS_LOG_UNCOND("Received Packets =" << iter -> second.rxPackets);
     NS_LOG_UNCOND("Lost Packets =" <<iter->second.txPackets-iter->second.rxPackets);
     NS_LOG_UNCOND("Packet delivery ratio =" <<iter->second.rxPackets*100/iter->second.txPackets << "%");
     NS_LOG_UNCOND("Packet loss ratio =" << (iter->second.txPackets-iter->second.rxPackets)*100/iter->second.txPackets << "%");
     NS_LOG_UNCOND("Delay =" << iter -> second.delaySum );
     NS_LOG_UNCOND("Jitter =" <<iter->second.jitterSum);
     NS_LOG_UNCOND("Throughput = " << iter -> second.rxBytes * 8.0 / (iter -> second.timeLastRxPacket.GetSeconds()-iter-> second.timeFirstTxPacket.GetSeconds())/ 1024 << " Kbps ");

 //this valuable hold the value for total results
    SentPackets = SentPackets +(iter -> second.txPackets);
    ReceivedPackets = ReceivedPackets +(iter -> second.rxPackets);
    LostPackets = LostPackets + (iter->second.txPackets-iter->second.rxPackets);
    AvgThroughput = AvgThroughput + (iter -> second.rxBytes* 8.0 /(iter -> second.timeLastRxPacket.GetSeconds()-iter-> second.timeFirstTxPacket.GetSeconds()) / 1024);
      Delay = Delay + (iter -> second.delaySum);
      Jitter = Jitter + (iter->second.jitterSum);
    j=j+1;// for flow id increase

    }
     AvgThroughput = AvgThroughput/j;
     Delay = Delay / ReceivedPackets ;
    NS_LOG_UNCOND("---------Total Results of the simulation-----"<<std::endl);
    NS_LOG_UNCOND("Total Send Packets = " << SentPackets);
    NS_LOG_UNCOND("Total Received Packets = " << ReceivedPackets);
    NS_LOG_UNCOND("Total Lost Packets =" << LostPackets);
    NS_LOG_UNCOND("Packet Loss ratio =" << ((LostPackets*100)/SentPackets)<< "%");
    NS_LOG_UNCOND("Packet delivery ratio =" << ((ReceivedPackets*100)/SentPackets)<< "%");
    NS_LOG_UNCOND("Average Throughput = " << AvgThroughput);
    NS_LOG_UNCOND("Delay = " << Delay);
    NS_LOG_UNCOND("End to End Jitter delay =" << Jitter);

    NS_LOG_UNCOND("Total Flow ID =" << j);  

    monitor->SerializeToXmlFile("TEXT.xml", true, true);
    Simulator::Destroy();
return 0;
 
}

SheikhMuhammadSaleh Farooqui

unread,
Jul 15, 2020, 7:14:01 AM7/15/20
to ns-3-...@googlegroups.com
Hi
Subnet mask doesn’t seems matching with the ip and try to increase the hop range
Thanks

--
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 the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ns-3-users/85d0f513-d85d-4111-a879-dca052751e24o%40googlegroups.com.

Zhongxu Yang

unread,
Jul 15, 2020, 1:38:43 PM7/15/20
to ns-3-users
i have changed the ip but it doesn't work. here is my .cc file .
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-...@googlegroups.com.
demo.cc

SheikhMuhammadSaleh Farooqui

unread,
Jul 15, 2020, 2:41:54 PM7/15/20
to ns-3-...@googlegroups.com
Hi
Have you tried my extending the hop range
Thanks

To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ns-3-users/237114c1-9319-461b-a696-158cebaa00b8o%40googlegroups.com.

Zhongxu Yang

unread,
Jul 15, 2020, 11:40:31 PM7/15/20
to ns-3-users
HI,how to extend the hop range ?Just like using chain topology,n0--------n1--------n2-------n3------n4 to get more hops,I have tried the chain topology,but i still can‘’t work. I simulated 4 nodes in a line,but the node n4 out of the range of one hop don't work, they cant establish the tcp connection with n0 which is set as server.By  analyzing the pcap file of the node4 ,it just sends the arp broadcast without receiving any reply. The flowmonitor shows that n4 have 100% packet loss rate. can you give me more suggestion about this simulation?
Thanks
Reply all
Reply to author
Forward
0 new messages