/****************************************************/ /* Tento program je prilohou k diplomovej praci */ /* Bezdrotove siete pre velmi hustu prevadzku */ /* */ /* Autor: Veronika Marasova, CVUT FEL, Praha 2017 */ /* */ /****************************************************/ #include "ns3/core-module.h" #include "ns3/mobility-module.h" #include "ns3/applications-module.h" #include "ns3/wifi-module.h" #include "ns3/csma-module.h" #include "ns3/network-module.h" #include "ns3/internet-module.h" #include "ns3/bridge-helper.h" #include "ns3/flow-monitor-module.h" #include "ns3/netanim-module.h" #include "ns3/spectrum-module.h" #include "ns3/ipv4-global-routing-helper.h" #include #include #include #include #include using namespace ns3; double g_signalDbmAvg; double g_noiseDbmAvg; uint32_t g_samples; uint16_t g_channelNumber; uint32_t g_rate; void MonitorSniffRx (Ptr packet, uint16_t channelFreqMhz, uint16_t channelNumber, uint32_t rate, WifiPreamble preamble, WifiTxVector txVector, struct mpduInfo aMpdu, struct signalNoiseDbm signalNoise) { g_samples++; g_signalDbmAvg += ((signalNoise.signal - g_signalDbmAvg) / g_samples); g_noiseDbmAvg += ((signalNoise.noise - g_noiseDbmAvg) / g_samples); g_rate = rate; g_channelNumber = channelNumber; } NS_LOG_COMPONENT_DEFINE ("coverage"); int main (int argc, char *argv[]) { std::string dataRate = "2Mbps"; std::string wifPhy = "Spectrum"; std::string mcs = "VhtMcs0"; uint32_t packetSize =1472; uint32_t chWidth = 40; uint32_t nStreams = 2; uint8_t tos = 0x70; int X=60, Y=60, k, l; // rozmery miestnosti, riadiace premenne cyklu int step=1; bool udp = true; bool shrtGI = true; double appStartTime = 1.0; double appStopTime = 10.0; double simulationStopTime = 10.0; CommandLine cmd; cmd.AddValue ("chWidth", "Channel width: 20, 40, 80 or 160 MHz", chWidth); cmd.AddValue ("nStreams", "Number of spatial streams of a STA devices (1-2)", nStreams); cmd.AddValue ("shrtGI", "Short GuardInterval enabled", shrtGI); cmd.AddValue ("dataRate", "The rate of data transmission (with Mbps/kbps)", dataRate); cmd.AddValue ("MCS", "Modulation and Coding Scheme", mcs); cmd.AddValue ("packetSize", "Size of a data packet", packetSize); cmd.AddValue ("ToS", "Type of Service: 0x28 AC_BK; 0x70 AC_BE; 0xb8 AC_VI; 0xc0 AC_VO", tos); cmd.AddValue ("udp", "UDP if set to 1, TCP otherwise", udp); cmd.Parse (argc,argv); std::cout << "Simulation parameters: X=" << X << ", Y=" << Y << ", MCS:" << mcs << ", Channel: "<< chWidth << " MHz, " << dataRate << ", STA type 2x2:2" << '\n'; std::cout << "X" << "\t\t" << "Y" << "\t\t" << "SNR" << "\t\t" << "Signal" << "\t\t" << "Throughput" << '\n'; l = 0; k = 0; while (l<=Y){ while (k<=X){ NodeContainer wifiStaNode; wifiStaNode.Create (1); NodeContainer wifiApNode; wifiApNode.Create (1); int chann, freq; double edt, cca; if (chWidth == 20) { chann = 36; freq = 5180; edt= -82; cca = -62; } else if (chWidth == 40) { chann = 38; freq = 5190; edt= -79; cca = -59; } else if (chWidth == 80) { chann = 42; freq = 5210; edt= -76; cca = -56; } else if (chWidth == 160) { chann = 50; freq = 5250; edt= -73; } WifiHelper wifi; wifi.SetStandard (WIFI_PHY_STANDARD_80211ac); wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", StringValue (mcs), "ControlMode", StringValue (mcs)); SpectrumWifiPhyHelper phy; Ptr spectrumChannel; spectrumChannel = CreateObject (); Ptr lossModel = CreateObject (); spectrumChannel->AddPropagationLossModel (lossModel); Ptr delayModel = CreateObject (); spectrumChannel->SetPropagationDelayModel (delayModel); phy.SetChannel(spectrumChannel); phy.SetPcapDataLinkType (SpectrumWifiPhyHelper::DLT_IEEE802_11_RADIO); phy.Set ("ChannelNumber", UintegerValue(chann)); phy.Set ("Frequency", UintegerValue (freq)); phy.Set ("ShortGuardEnabled", BooleanValue (shrtGI)); phy.SetErrorRateModel("ns3::NistErrorRateModel"); phy.SetPcapDataLinkType(YansWifiPhyHelper::DLT_IEEE802_11_RADIO); phy.Set("EnergyDetectionThreshold", DoubleValue (edt)); if (chWidth != 160){ phy.Set("CcaMode1Threshold", DoubleValue (cca)); } phy.Set ("TxPowerStart", DoubleValue (15)); phy.Set ("TxPowerEnd", DoubleValue (15)); phy.Set ("TxGain", DoubleValue (-2)); phy.Set ("RxGain", DoubleValue (-2)); phy.Set ("TxAntennas", UintegerValue (nStreams)); phy.Set ("RxAntennas", UintegerValue (nStreams)); Ssid ssid = Ssid ("HighDensity"); VhtWifiMacHelper mac; mac.SetType ("ns3::StaWifiMac", "Ssid", SsidValue (ssid), "ActiveProbing", BooleanValue (false)); NetDeviceContainer staDevice; staDevice = wifi.Install (phy, mac, wifiStaNode); phy.Set ("TxPowerStart", DoubleValue (20)); phy.Set ("TxPowerEnd", DoubleValue (20)); phy.Set ("TxGain", DoubleValue (0)); phy.Set ("RxGain", DoubleValue (0)); phy.Set ("TxAntennas", UintegerValue (4)); phy.Set ("RxAntennas", UintegerValue (4)); mac.SetType ("ns3::ApWifiMac", "Ssid", SsidValue (ssid), "QosSupported", BooleanValue (true), "BeaconGeneration", BooleanValue (true), "BeaconInterval", TimeValue (MilliSeconds (100))); NetDeviceContainer apDevice; apDevice = wifi.Install (phy, mac, wifiApNode); Config::Set ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::WifiPhy/ChannelNumber", UintegerValue (chann)); // mobility. double sta_X, sta_Y; sta_X = k; sta_Y = l; MobilityHelper mobility; Ptr positionAlloc = CreateObject (); positionAlloc->Add (Vector (X/2, Y/2, 3.5)); positionAlloc->Add (Vector (sta_X, sta_Y, 1.0)); mobility.SetPositionAllocator (positionAlloc); mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); mobility.Install (wifiApNode); mobility.Install (wifiStaNode); // Internet stack InternetStackHelper stack; stack.Install (wifiApNode); stack.Install (wifiStaNode); Ipv4AddressHelper address; address.SetBase ("10.0.1.0", "255.255.255.0"); Ipv4InterfaceContainer staNodeInterface; Ipv4InterfaceContainer apNodeInterface; staNodeInterface = address.Assign (staDevice); apNodeInterface = address.Assign (apDevice); // Setting applications std::string protocol; protocol = "ns3::UdpSocketFactory"; uint16_t port = 8123; InetSocketAddress dest(staNodeInterface.GetAddress (0), port); dest.SetTos(tos); PacketSinkHelper sink (protocol, dest); ApplicationContainer apps_sink = sink.Install (wifiStaNode.Get (0)); apps_sink.Start (Seconds (0.0)); apps_sink.Stop (Seconds (simulationStopTime+1)); OnOffHelper onoff = OnOffHelper (protocol, dest); onoff.SetConstantRate (DataRate (dataRate), packetSize); ApplicationContainer apps = onoff.Install (wifiApNode.Get(0)); apps.Start (Seconds (appStartTime)); apps.Stop (Seconds (appStopTime)); Ipv4GlobalRoutingHelper::PopulateRoutingTables (); Config::ConnectWithoutContext ("/NodeList/*/DeviceList/*/Phy/MonitorSnifferRx", MakeCallback (&MonitorSniffRx)); g_signalDbmAvg = 0; g_noiseDbmAvg = 0; g_samples = 0; g_channelNumber = 0; g_rate = 0; AnimationInterface anim ("surf.xml"); // Mandatory anim.EnablePacketMetadata (); // Install FlowMonitor on all nodes FlowMonitorHelper flowmon; Ptr monitor = flowmon.InstallAll (); Simulator::Stop (Seconds (simulationStopTime)); Simulator::Run (); // Print per flow statistics monitor->CheckForLostPackets (); Ptr classifier = DynamicCast (flowmon.GetClassifier ()); FlowMonitor::FlowStatsContainer stats = monitor->GetFlowStats (); monitor->SerializeToXmlFile("surf.flowmon", true, true); for (std::map::const_iterator i = stats.begin (); i != stats.end (); ++i) { uint32_t duration = appStopTime - appStartTime; std::cout << (k) << "\t\t" << (l) << "\t\t" << (g_signalDbmAvg - g_noiseDbmAvg) << "\t\t" << g_signalDbmAvg << "\t\t" <<(i->second.rxPackets *(packetSize+90)*8.0/duration/1024/1024)<< '\n'; } Simulator::Destroy (); k+=step; } l+=step;k=0; } return 0; }