--- a/examples/wireless/wifi-spectrum-dot11g.cc Sun May 03 11:05:49 2015 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,250 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2011 Dean Armstrong
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author: Dean Armstrong <deanarm@gmail.com>
- */
-#include "ns3/core-module.h"
-#include "ns3/network-module.h"
-#include "ns3/mobility-module.h"
-#include "ns3/wifi-module.h"
-#include "ns3/internet-module.h"
-#include "ns3/spectrum-module.h"
-#include "ns3/applications-module.h"
-
-#include <iostream>
-#include <fstream>
-#include <string>
-
-NS_LOG_COMPONENT_DEFINE ("WifiSpectrumDot11g");
-
-using namespace ns3;
-
-class LoggedUDPStream
-{
-public:
- LoggedUDPStream (const char *filename, Time reportInterval,
- Ptr<Node> source, Ptr<Node> sink,
- Ipv4Address sinkAddr, uint16_t udpPort,
- DataRate dataRate,
- unsigned packetSize = 1470,
- UserPriority up = UP_BE) {
- // Open the log file
- m_logFile.open (filename, std::ios::out | std::ios::trunc);
- if (!m_logFile.is_open ())
- {
- NS_FATAL_ERROR ("Could not open file " << filename << " for output");
- }
-
- // Get a plain old packet sink installed in the right place. We'll
- // periodically query this to see how many octets it has sunk. We
- // also clear our counter of octets received.
- PacketSinkHelper sinkHelper ("ns3::UdpSocketFactory",
- InetSocketAddress (Ipv4Address::GetAny (),
- udpPort));
- m_sinkApp = sinkHelper.Install (sink);
- m_lastOctetsReceived = 0;
-
- // We use an on-off source which is permanently set on to give our
- // source of UDP datagrams. Data rate and packet size are tailored
- // to the requirements that are specified as arguments to this
- // constructor.
- OnOffHelper sourceHelper ("ns3::UdpSocketFactory",
- InetSocketAddress (sinkAddr, udpPort));
- sourceHelper.SetAttribute ("DataRate",
- DataRateValue (dataRate));
- sourceHelper.SetAttribute ("PacketSize",
- UintegerValue (packetSize));
- m_sourceApp = sourceHelper.Install (source);
-
- // We want to QoS tag the packets and so note the UP that we are
- // to use, and setup a callback on the event of the packet source
- // generating a frame for transmission
- m_up = up;
- m_sourceApp.Get (0)->
- TraceConnectWithoutContext ("Tx",
- MakeCallback (&LoggedUDPStream::QosTagPacket,
- this));
-
- // Note the report interval and schedule the first logging event
- // (which'll reschedule itself) for now.
- m_reportInterval = reportInterval;
- Simulator::Schedule(Simulator::Now (),
- &LoggedUDPStream::LogThroughput, this);
- }
-
- ~LoggedUDPStream () {
- m_logFile.close ();
- }
-
- void Start (Time time) {
- m_sourceApp.Start (time);
- m_sinkApp.Start (time);
- }
-
- void Stop (Time time) {
- m_sourceApp.Stop (time);
- }
-
-private:
- void LogThroughput (void) {
- uint32_t thisOctetsReceived =
- DynamicCast<PacketSink>(m_sinkApp.Get (0))->GetTotalRx ();
-
- m_logFile << Simulator::Now().GetSeconds () << " "
- << (8.0 * (thisOctetsReceived - m_lastOctetsReceived)
- / m_reportInterval.GetSeconds ()) << std::endl;
-
- m_lastOctetsReceived = thisOctetsReceived;
-
- // Schedule next throughput logging event
- Simulator::Schedule(m_reportInterval,
- &LoggedUDPStream::LogThroughput, this);
- }
-
- void QosTagPacket (Ptr<const Packet> packet) {
- QosTag qosTag;
- qosTag.SetUserPriority (m_up);
- packet->AddPacketTag (qosTag);
- }
-
- uint32_t m_lastOctetsReceived;
- std::ofstream m_logFile;
- Time m_reportInterval;
- UserPriority m_up;
-
- // Packet sink objects
- ApplicationContainer m_sourceApp, m_sinkApp;
-};
-
-int main (int argc, char *argv[])
-{
- WifiHelper wifi = WifiHelper::Default ();
- QosWifiMacHelper wifiMac = QosWifiMacHelper::Default ();
-
- SpectrumWifiPhyHelper wifiPhy = SpectrumWifiPhyHelper::Default ();
- SingleModelSpectrumChannel channel;
- Ptr<FriisSpectrumPropagationLossModel> lossModel
- = CreateObject<FriisSpectrumPropagationLossModel> ();
- channel.AddSpectrumPropagationLossModel (lossModel);
-
- Ptr<ConstantSpeedPropagationDelayModel> delayModel
- = CreateObject<ConstantSpeedPropagationDelayModel> ();
- channel.SetPropagationDelayModel (delayModel);
-
- wifiPhy.SetChannel(&channel);
- // Operate on (arbitrarily chosen) channel 6.
- wifiPhy.SetChannelNumber (6);
-
- Ssid ssid = Ssid ("wifi-spectrum-dot11g");
- wifi.SetStandard (WIFI_PHY_STANDARD_80211g);
-
- // Fix transmit rate for all STAs at 54 Mbps
- std::string phyMode ("ErpOfdmRate54Mbps");
- wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
- "DataMode", StringValue (phyMode),
- "ControlMode", StringValue (phyMode)
- );
-
- // Setup the AP, which will be the sink for traffic in this test.
- NodeContainer ap;
- ap.Create (1);
- wifiMac.SetType ("ns3::ApWifiMac",
- "QosSupported", BooleanValue (true),
- "Ssid", SsidValue (ssid),
- "BeaconGeneration", BooleanValue (true),
- "BeaconInterval", TimeValue (MilliSeconds (102.4)));
- NetDeviceContainer apDev = wifi.Install (wifiPhy, wifiMac, ap);
-
- // Add the DSSS/CCK rates as the basic rates of our AP
- Ptr<WifiRemoteStationManager> apStationManager =
- DynamicCast<WifiNetDevice>(apDev.Get (0))->GetRemoteStationManager ();
- apStationManager->AddBasicMode (WifiMode ("DsssRate1Mbps"));
- apStationManager->AddBasicMode (WifiMode ("DsssRate2Mbps"));
- apStationManager->AddBasicMode (WifiMode ("DsssRate5_5Mbps"));
- apStationManager->AddBasicMode (WifiMode ("DsssRate11Mbps"));
-
- // Setup one STA, which will be the source for traffic in this test.
- NodeContainer sta;
- sta.Create (3);
- wifiMac.SetType ("ns3::StaWifiMac",
- "QosSupported", BooleanValue (true),
- "Ssid", SsidValue (ssid),
- "ActiveProbing", BooleanValue (false));
- NetDeviceContainer staDev = wifi.Install (wifiPhy, wifiMac, sta);
-
- // Our devices will have fixed positions and we use a grid position
- // allocator
- MobilityHelper mobility;
- mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
- mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
- "MinX", DoubleValue (0.0),
- "MinY", DoubleValue (0.0),
- "DeltaX", DoubleValue (5.0),
- "DeltaY", DoubleValue (10.0),
- "GridWidth", UintegerValue (2),
- "LayoutType", StringValue ("RowFirst"));
- mobility.Install (sta);
- mobility.Install (ap);
-
- // Now we install internet stacks on our devices
- InternetStackHelper stack;
- stack.Install (ap);
- stack.Install (sta);
-
- Ipv4AddressHelper address;
- address.SetBase ("192.168.0.0", "255.255.255.0");
- Ipv4InterfaceContainer staNodeInterface, apNodeInterface;
- staNodeInterface = address.Assign (staDev);
- apNodeInterface = address.Assign (apDev);
-
- // Create three UDP streams for which throughput is logged to a file
- // every 100ms. Stagger the starts.
- LoggedUDPStream stream1 ("stream1.log", Seconds (0.1),
- sta.Get (0), ap.Get (0),
- apNodeInterface.GetAddress (0), 50000,
- DataRate ("20Mbps"), 1470, UP_VI);
- stream1.Start (Seconds (1));
- stream1.Stop (Seconds (4));
-
- LoggedUDPStream stream2 ("stream2.log", Seconds (0.1),
- sta.Get (1), ap.Get (0),
- apNodeInterface.GetAddress (0), 50001,
- DataRate ("20Mbps"), 1470, UP_VI);
- stream2.Start (Seconds (2));
- stream2.Stop (Seconds (4));
-
- LoggedUDPStream stream3 ("stream3.log", Seconds (0.1),
- sta.Get (2), ap.Get (0),
- apNodeInterface.GetAddress (0), 50002,
- DataRate ("20Mbps"), 1400, UP_VI);
- stream3.Start (Seconds (3));
- stream3.Stop (Seconds (4));
-
- // Enable PCAP tracing with radiotap headers at each node in our
- // simulated topology
- wifiPhy.SetPcapDataLinkType (SpectrumWifiPhyHelper::DLT_IEEE802_11_RADIO);
- wifiPhy.EnablePcap ("wifi-spectrum-dot11g", ap.Get (0)->GetId (), 0);
- wifiPhy.EnablePcap ("wifi-spectrum-dot11g", sta.Get (0)->GetId (), 0);
- wifiPhy.EnablePcap ("wifi-spectrum-dot11g", sta.Get (1)->GetId (), 0);
- wifiPhy.EnablePcap ("wifi-spectrum-dot11g", sta.Get (2)->GetId (), 0);
-
- Simulator::Stop (Seconds (5));
- Simulator::Run ();
- Simulator::Destroy ();
-
- return 0;
-}