NetDeviceContainer devices = wifi.Install(wifiPhy,wifiMac,nodes);
//Mobility model
MobilityHelper mobility;
Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator>(); /*Allocate positions from a deterministic
list specified by the user */
//reads node's position from file
for(int i=0;i<quantNo;i++)
{
int no;
fscanf(top,"%d %lf %lf",&no,&px,&py);
positionAlloc->Add(Vector(px,py,1.04)); //=> dcross for TwoRay = 109.277m
}
mobility.SetPositionAllocator(positionAlloc);
mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
mobility.Install(nodes);
// TCP/IP configuration
InternetStackHelper internet;
internet.Install(nodes);
Ipv4AddressHelper ipv4;
NS_LOG_INFO("Assign IP Addresses");
ipv4.SetBase("10.1.2.0","255.255.255.0");
Ipv4InterfaceContainer interface = ipv4.Assign(devices);
//Applications
float tempo = 0.01;
for(int i=0; i<=quantEnlace; i++) //só fica aqui até a quantidade de enlaces
{
int from,to;
fscanf(top,"%d %d",&from,&to);
PacketSinkHelper sink("ns3::UdpSocketFactory", InetSocketAddress(interface.GetAddress(to),80));
ApplicationContainer sinkApp = sink.Install(nodes.Get(to));
sinkApp.Start(Seconds(tempo));
sinkApp.Stop(Seconds(60.0));
//install on-off application on main interface
//MyOnOffHelper onOff("ns3::UdpSocketFactory", InetSocketAddress(interface.GetAddress(from),80));
OnOffHelper onOff("ns3::UdpSocketFactory", InetSocketAddress(interface.GetAddress(from),80));
onOff.SetAttribute("OnTime",StringValue ("ns3::ConstantRandomVariable[Constant=1.0]"));
onOff.SetAttribute("OffTime",StringValue ("ns3::ConstantRandomVariable[Constant=0.0]"));
onOff.SetAttribute("PacketSize",UintegerValue(packetSize));
onOff.SetAttribute("Remote",AddressValue(InetSocketAddress(interface.GetAddress(to),80)));
ApplicationContainer udpApp = onOff.Install(nodes.Get(from));
udpApp.Start(Seconds(tempo));
udpApp.Stop(Seconds(60.0));
tempo+=0.2;
}
//Enables the creation of packet tracking files
AsciiTraceHelper ascii;
wifiPhy.EnableAsciiAll(ascii.CreateFileStream("tracing/ascii/
802.11n.tr"));
//Tracks the received packets in the chosen terminal
//Config::Connect("/NodeList/0/DeviceList/*/Phy/State/RxOk",MakeCallback(&PhyRxOkTrace));
//PCAP files
//wifiPhy.EnablePcap("/tracing/pcap/802.11n",devices);
FlowMonitorHelper flowmon;
Ptr<FlowMonitor> monitor = flowmon.InstallAll ();
uint64_t rxBytesByNode[quantNo];
int64x64_t delayMeanByNode[quantNo];
for(int i=0; i<quantNo; i++){
rxBytesByNode[i] = 0;
delayMeanByNode[i] = 0;
}
//run simulation for 60.1 seconds
Simulator::Stop(Seconds(60.1));
Simulator::Run();
//Flow Monitor Code from wifi-hidden-terminal.cc
//Print per flow statistics
double throughput;
int64x64_t delay;
monitor->CheckForLostPackets ();
Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier> (flowmon.GetClassifier ());
std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats ();
for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator i = stats.begin (); i != stats.end (); ++i)
{
Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow (i->first);
//aggregate throughput and aggregate delay
throughput += i->second.rxBytes* 8.0 / 60.1 / 1024 / 1024; /* multipled by 8 to turn to bits, devided by 60.1 because of the time of the
the simulation and divided twice for 1024 to give Mega bits */
//single node throughput
uint8_t addr[4];
t.destinationAddress.Serialize (addr);
int nodeid = addr[3]+0;
rxBytesByNode[nodeid] += i->second.rxBytes;
if (i->second.rxPackets != 0) delayMeanByNode[nodeid] += (i->second.delaySum / (i->second.rxPackets));
//---------------------Cmd output-----------------------------------------------------------------------//
std::cout << "Flow " << i->first << " (" << t.sourceAddress << " -> " << t.destinationAddress << ")\n";
std::cout << " Tx Bytes: " << i->second.txBytes << "\n";
std::cout << " Rx Bytes: " << i->second.rxBytes << "\n";
std::cout << " Throughput: " << i->second.rxBytes * 8.0 / 10.0 / 1024 / 1024 << " Mbps\n";
}
Simulator::Destroy();
std::cout<<"Aggregate Throughput: "<<throughput<<"Mbps\n";
I hope we'll be able to shade some light on this matter.
Thank you!
Best regards,
Larissa.