UDP and TCP traffic on Olsr Routing Protocol

458 views
Skip to first unread message

ENAKHSI JANA

unread,
Jun 13, 2016, 11:46:14 AM6/13/16
to ns-3-users
Hi,
  Following is the configuration of my simulation.

n1----------n2----------n3----------n4-----------n5-----------n6

I want to send UDP and TCP packet from n6 to n1. For my simulation for both TCP and UDP only n2 can send packet to n1. But when I am installing UDP and TCP packet at any of the node n3,n4,n5,n6 no packet is reaching to n1. I kept around 50 sec for Olsr protocol to populate routing table. Please look at my code. If am doing wrong in traffic installation please point me. Any help is highly appreciated. 



#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/internet-module.h"
#include <iostream>
#include <cmath>
#include "ns3/flow-monitor-module.h" 
#include "ns3/netanim-module.h"
#include "ns3/dsdv-module.h"
#include "ns3/olsr-module.h"
#include "ns3/aodv-module.h"
#include <iostream>
#include <string>
#include <stdio.h>
#include "ns3/stats-module.h"

#include "ns3/internet-apps-module.h"
using namespace ns3;
int n_nodes=6;  // total number of nodes
int udp=0;
int totalTime=80;
int start_time=50;
double distance=70;
int main (int argc, char *argv[])
{
  NodeContainer nodes;
  nodes.Create (n_nodes);

  WifiHelper wifi;// = WifiHelper::Default ();
  wifi.SetStandard (WIFI_PHY_STANDARD_80211a);
  NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
  YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
  YansWifiChannelHelper wifiChannel;
  wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
  wifiChannel.AddPropagationLoss ("ns3::OkumuraHataPropagationLossModel");
  wifiMac.SetType ("ns3::AdhocWifiMac");
  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
                              "DataMode", StringValue ("OfdmRate54Mbps"));
  wifiPhy.SetChannel (wifiChannel.Create ());
  NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, nodes);
  MobilityHelper mobility;
  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
  
  for(int i=0;i<n_nodes;i++)
     positionAlloc->Add (Vector (distance*i,0,15));  
  mobility.SetPositionAllocator (positionAlloc);
  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
  mobility.Install (nodes);

  InternetStackHelper stack;
  OlsrHelper olsr;
  stack.SetRoutingHelper (olsr);
  for(int i=0;i<n_nodes;i++)
      stack.Install (nodes.Get(i));   
  Ipv4AddressHelper address;
  Ipv4InterfaceContainer interfaces;  
  address.SetBase ("210.0.0.0", "255.255.128.0");
  interfaces = address.Assign (devices);
  
  uint32_t payloadSize; //1500 byte IP packet
  if (udp)
    {
      payloadSize = 1472; //bytes
    }
  else
    {
      payloadSize = 1448; //bytes
      Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (payloadSize));
    }
  ApplicationContainer serverApp, sinkApp;
  if (udp)
  {
    //UDP flow
    UdpServerHelper myServer (9);
    serverApp = myServer.Install (nodes.Get (0));
    serverApp.Start (Seconds (start_time));
    serverApp.Stop (Seconds (totalTime + 1));

    UdpClientHelper myClient (interfaces.GetAddress (0), 9);
    myClient.SetAttribute ("MaxPackets", UintegerValue (4294967295u));
    myClient.SetAttribute ("Interval", TimeValue (Time ("0.001"))); //packets/s
    myClient.SetAttribute ("PacketSize", UintegerValue (payloadSize));

    ApplicationContainer clientApp = myClient.Install (nodes.Get (5));
    clientApp.Start (Seconds (start_time));
    clientApp.Stop (Seconds (totalTime + 1));
  }
  else
  {
    
    uint16_t port = 50000;
    Address apLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port));
    PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", apLocalAddress);
    sinkApp = packetSinkHelper.Install (nodes.Get (0));

    sinkApp.Start (Seconds (start_time));
    sinkApp.Stop (Seconds (totalTime + 1));

    OnOffHelper onoff ("ns3::TcpSocketFactory",Ipv4Address::GetAny ());
    onoff.SetAttribute ("OnTime",  StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
    onoff.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
    onoff.SetAttribute ("PacketSize", UintegerValue (payloadSize));
    onoff.SetAttribute ("DataRate", DataRateValue (1000000)); //bit/s
    ApplicationContainer apps;

    AddressValue remoteAddress (InetSocketAddress (interfaces.GetAddress (0), port));
    onoff.SetAttribute ("Remote", remoteAddress);
    apps.Add (onoff.Install (nodes.Get (5)));
    apps.Start (Seconds (start_time));
    apps.Stop (Seconds (totalTime + 1));
  }   

  Simulator::Stop (Seconds (totalTime+1));   
  Ptr<FlowMonitor> flowMonitor;
  FlowMonitorHelper flowHelper;
  flowMonitor = flowHelper.InstallAll();   
  Simulator::Run ();
  std::cout <<std::endl<<"Tx\t\tRx\t\tTxPkt\tRxPkt\tThput\tPkt Loss(%)\n----------------------------------------------------------------------------\n";
  flowMonitor->CheckForLostPackets (); 
  Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier> (flowHelper.GetClassifier ());
  std::map<FlowId, FlowMonitor::FlowStats> stats = flowMonitor->GetFlowStats ();

  for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator i = stats.begin (); i != stats.end (); ++i)
  {   
    Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow (i->first);
    std::cout << t.sourceAddress << "\t";
    std::cout << t.destinationAddress << "\t";
    std::cout << i->second.txPackets << "\t";
    std::cout << i->second.rxPackets << "\t";
    std::cout << (i->second.rxPackets*8.0*1025)/(1024*1024)/(totalTime - start_time)<< " \t"<<std::endl;
          
  } 
// V4PingHelper ping2 (interfaces.GetAddress(5));
  // ping2.SetAttribute ("Verbose", BooleanValue (true));
  // ping2.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
  // ApplicationContainer appPingInternet2 = ping2.Install (nodes.Get(0));
  // appPingInternet2.Start (Seconds (start_time));
  // appPingInternet2.Stop (Seconds (totalTime - 1));
  // Simulator::Stop (Seconds (totalTime));
  // Simulator::Run ();
  // Simulator::Destroy ();
  return 0;
}



thanks,

Enakshi Jana

Tommaso Pecorella

unread,
Jun 13, 2016, 7:09:14 PM6/13/16
to ns-3-users
Hi,

beside the fact that we said countless times to use the attachments to add a script to a message (it's even stated in the posting guidelines)...
Beside this, you didn't do anything wrong with the applications. The problem is in the Wi-Fi setup.

Little known fact: broadcast packets are always sent using the slowest (and most reliable) transmissions mode. If I remember right, it's 6Mbps for 802.11a.
Little known side-effect: broadcast packets are received by more nodes, because the less data rate, the higher SINR, the more distance.

Now, in your setup you did set the transmission rate to 54Mbps, but the broadcast packets will still use 6Mbps.

What is the thing that is sent in broadcast and will trigger an unicast reply ?
Answer: the ARP packets (damn).

To make the long story short: the nodes are benign ARPs and they're not receiving the replies, because they have different transmission range.

How to fix this ?
Well, option 1 is to use 6Mbps data mode. It's slow, but it should work.
Option 2 is to poke the Wi-Fi maintainers and find out if it's possible to force the non-unicast data rate (I guess not, since the standard states is kinda strict on that).

Cheers,

T.


On Monday, June 13, 2016 at 5:46:14 PM UTC+2, ENAKHSI JANA wrote:
Hi,
  Following is the configuration of my simulation.

n1----------n2----------n3----------n4-----------n5-----------n6

I want to send UDP and TCP packet from n6 to n1. For my simulation for both TCP and UDP only n2 can send packet to n1. But when I am installing UDP and TCP packet at any of the node n3,n4,n5,n6 no packet is reaching to n1. I kept around 50 sec for Olsr protocol to populate routing table. Please look at my code. If am doing wrong in traffic installation please point me. Any help is highly appreciated. 

...

thanks,

Enakshi Jana

ENAKHSI JANA

unread,
Jun 13, 2016, 10:56:18 PM6/13/16
to ns-3-users
Hi Tommaso,
   Sorry for pasting the code here itself and thanks for your reply. Now it is working fine when I change the rate to 6Mbps. 

Thanks again!!
Enakshi Jana
Reply all
Reply to author
Forward
0 new messages