Following is the configuration of my simulation.
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;
}