Hi Everyone
I am having a problem when I add the any of the propagation loss models to the wifi channel. When I looked at the pcap file there ARP packets dont seem to be transmitted. Can anyone please tell me what the problem is? I have copied my code below
Regards
Vishal
#include "ns3/core-module.h"
#include "ns3/simulator-module.h"
#include "ns3/node-module.h"
#include "ns3/helper-module.h"
#include "ns3/wifi-module.h"
#include "ns3/mobility-module.h"
#include "ns3/flow-monitor-module.h"
//This is a simple example in order to show how 802.11n frame aggregation feature (A-MSDU) works.
//
//Network topology:
//
// Wifi 192.168.1.0
//
// source (sink)AP
// * * *
// | | |
// n1 n2 n3
//
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("SimpleWifiFrameAggregation");
//static uint32_t m_bytesTotal;
/*
static void
Throughput () // in Mbps calculated every 10s
{
double mbps = (((m_bytesTotal * 8.0) / 1000000)/10);
Time time = Simulator::Now ();
m_bytesTotal = 0;
Simulator::Schedule (Seconds (.1), &Throughput);
std::cout << "Time "<< time.GetSeconds() << " Throughput "<< mbps <<"Mbps "<< std::endl;
//std::cout << time.GetSeconds()<<"\t" << mbps << std::endl;
}
void
PhyRxOkTrace (std::string context, Ptr<const Packet> packet, double snr,
WifiMode mode, enum WifiPreamble preamble)
{
Ptr<Packet> m_currentPacket;
WifiMacHeader hdr;
m_currentPacket = packet->Copy();
m_currentPacket->RemoveHeader (hdr);
if (hdr.IsData()){
m_bytesTotal += m_currentPacket->GetSize ();
}
}
*/
int main (int argc, char *argv[])
{
double m_referenceDistance = 1.0; // m
double m_exponent = 1.7;
double m_referenceLoss = 40.178882771; // L0 = 20 log(4 pi feqChann3 / 3 exp8)
double m_EnergyDet = -86.0;
double m_ccath = -99.0;
double m_txpower = 18.0; // dbm
//LogComponentEnable ("EdcaTxopN", LOG_LEVEL_DEBUG);
LogComponentEnable ("MsduAggregator", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
uint32_t nWifi = 1;
CommandLine cmd;
cmd.AddValue ("nWifi", "Number of wifi STA devices", nWifi);
cmd.Parse (argc,argv);
NodeContainer wifiApNode;
wifiApNode.Create (1);
NodeContainer wifiNodes;
wifiNodes.Create (2);
MobilityHelper mobility;
mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
"MinX", DoubleValue (0.0),
"MinY", DoubleValue (0.0),
"DeltaX", DoubleValue (50.0),
"DeltaY", DoubleValue (0.0),
"GridWidth", UintegerValue (3),
"LayoutType", StringValue ("RowFirst"));
mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
"Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));
mobility.Install (wifiNodes);
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (wifiApNode);
YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
channel.AddPropagationLoss ("ns3::LogDistancePropagationLossModel");
YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
phy.Set ("EnergyDetectionThreshold", DoubleValue (m_EnergyDet)); //defulat val is -96dBm
phy.Set ("CcaMode1Threshold", DoubleValue (m_ccath)); //default val is -99dBm
phy.Set ("TxGain", DoubleValue (1.0)); // Use 5.0 to extend range to about 300 meters
phy.Set ("RxGain", DoubleValue (1.0)); // Use 5.0 to extend range to about 300 meters
phy.Set ("TxPowerLevels", UintegerValue (1) );
phy.Set ("TxPowerEnd", DoubleValue (m_txpower) ); //default val is 16.0206dBm
phy.Set ("TxPowerStart", DoubleValue (m_txpower) ); //default val is 16.0206dBm
phy.Set ("RxNoiseFigure", DoubleValue (7.0) ); //defulat val is 7dB
phy.SetChannel (channel.Create ());
WifiHelper wifi = WifiHelper::Default ();
QosWifiMacHelper mac = QosWifiMacHelper::Default ();
wifi.SetRemoteStationManager ("ns3::AarfWifiManager", "FragmentationThreshold", UintegerValue (4000));//2500
Ssid ssid = Ssid ("ns-3-802.11n");
mac.SetType ("ns3::QstaWifiMac",
"Ssid", SsidValue (ssid),
"ActiveProbing", BooleanValue (false));
mac.SetMsduAggregatorForAc (AC_BE, "ns3::MsduStandardAggregator", "MaxAmsduSize", UintegerValue (3839));
NetDeviceContainer staDevices;
staDevices = wifi.Install (phy, mac, wifiNodes);
Config::Set ("/NodeList/0/DeviceList/0/Mac/BE_EdcaTxopN/BlockAckThreshold", UintegerValue (2));
Config::Set ("/NodeList/1/DeviceList/0/Mac/BE_EdcaTxopN/BlockAckThreshold", UintegerValue (2));
mac.SetType ("ns3::QapWifiMac",
"Ssid", SsidValue (ssid));
mac.SetMsduAggregatorForAc (AC_BE, "ns3::MsduStandardAggregator","MaxAmsduSize", UintegerValue (3839));//7935
NetDeviceContainer apDevice;
apDevice = wifi.Install (phy, mac, wifiApNode);
Config::Set ("/NodeList/2/DeviceList/0/Mac/BE_EdcaTxopN/BlockAckThreshold", UintegerValue (2));
/* Internet stack*/
InternetStackHelper stack;
stack.Install (wifiApNode);
stack.Install (wifiNodes);
Ipv4AddressHelper address;
address.SetBase ("192.168.1.0", "255.255.255.0");
Ipv4InterfaceContainer wifiNodesInterfaces;
Ipv4InterfaceContainer apNodeInterface;
wifiNodesInterfaces = address.Assign (staDevices);
apNodeInterface = address.Assign (apDevice);
//Routing
Ipv4StaticRoutingHelper ipv4RoutingHelper;
Ptr<Ipv4> ipv4Node;
Ptr<Ipv4StaticRouting> staticRoutingNode;
//wifiNode 0
ipv4Node = wifiNodes.Get(0)->GetObject<Ipv4> ();
staticRoutingNode = ipv4RoutingHelper.GetStaticRouting (ipv4Node);
//left node
//staticRoutingNode->AddHostRouteTo (ipv4Interfaces.GetAddress (leftNodes), ipv4Interfaces.GetAddress (leftExit), 1);
//right node
//staticRoutingNode->AddHostRouteTo (apNodeInterface.GetAddress (0), apNodeInterface.GetAddress (0), 1);
staticRoutingNode->AddHostRouteTo (wifiNodesInterfaces.GetAddress (1), wifiNodesInterfaces.GetAddress (1), 1);
//wifiNode 0
ipv4Node = wifiNodes.Get(1)->GetObject<Ipv4> ();
staticRoutingNode = ipv4RoutingHelper.GetStaticRouting (ipv4Node);
//left node
staticRoutingNode->AddHostRouteTo (wifiNodesInterfaces.GetAddress (0), wifiNodesInterfaces.GetAddress (0), 1);
//right node
staticRoutingNode->AddHostRouteTo (apNodeInterface.GetAddress (0), apNodeInterface.GetAddress (0), 1);
//apNode 0
ipv4Node = wifiApNode.Get(0)->GetObject<Ipv4> ();
staticRoutingNode = ipv4RoutingHelper.GetStaticRouting (ipv4Node);
//left node
staticRoutingNode->AddHostRouteTo (wifiNodesInterfaces.GetAddress (1), wifiNodesInterfaces.GetAddress (1), 1);
//staticRoutingNode->AddHostRouteTo (wifiNodesInterfaces.GetAddress (0), wifiNodesInterfaces.GetAddress (0), 1);
//right node
//staticRoutingNode->AddHostRouteTo (apNodeInterface.GetAddress (0), apNodeInterface.GetAddress (0), 1);
// Create a packet sink to receive these packets on n2...
uint16_t port = 50000;
PacketSinkHelper sink ("ns3::TcpSocketFactory",InetSocketAddress (Ipv4Address::GetAny (), port));
ApplicationContainer apps = sink.Install (wifiApNode.Get (0));
apps.Start (Seconds (1.0));
apps.Stop (Seconds (7.0));//0.293092,3
//create onoff application
OnOffHelper onOffHelper ("ns3::TcpSocketFactory", InetSocketAddress ("192.168.1.3", port));
// OnOffHelper onOffHelper ("ns3::TcpSocketFactory", InetSocketAddress ("10.0.0.3", port));
// OnOffHelper onOffHelper ("ns3::TcpSocketFactory", InetSocketAddress ("10.0.0.4", port));
onOffHelper.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (100)));
onOffHelper.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
onOffHelper.SetAttribute ("DataRate", DataRateValue (DataRate (1000000)));//3502654
onOffHelper.SetAttribute ("PacketSize", UintegerValue (1000));
//onOffHelper.SetAttribute ("maxBytes", UintegerValue (10000));
ApplicationContainer source;
source.Add (onOffHelper.Install (wifiNodes.Get(0)));
source.Start (Seconds (1.1));
source.Stop (Seconds (10.0));
Simulator::Stop (Seconds (10.0));
// 8. Install FlowMonitor on all nodes
FlowMonitorHelper flowmon;
Ptr<FlowMonitor> monitor = flowmon.InstallAll();
Simulator::Run ();
// 10. Print per flow statistics
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);
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 ();
return 0;
}