OLD | NEW |
(Empty) | |
| 1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2010 Jens Mittag, Stylianos Papanastasiou |
| 4 * |
| 5 * This program is free software; you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 2 as |
| 7 * published by the Free Software Foundation; |
| 8 * |
| 9 * This program is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 14 * You should have received a copy of the GNU General Public License |
| 15 * along with this program; if not, write to the Free Software |
| 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 * |
| 18 * Authors: |
| 19 * Jens Mittag <jens.mittag@kit.edu> |
| 20 * Stylianos Papanastasiou <stylianos@gmail.com> |
| 21 */ |
| 22 |
| 23 #include "ns3/config.h" |
| 24 #include "ns3/test.h" |
| 25 #include "ns3/log.h" |
| 26 #include "ns3/boolean.h" |
| 27 #include "ns3/double.h" |
| 28 #include "ns3/uinteger.h" |
| 29 #include "ns3/string.h" |
| 30 #include "ns3/packet.h" |
| 31 #include "ns3/enum.h" |
| 32 #include "ns3/physim-wifi-helper.h" |
| 33 #include "ns3/random-variable.h" |
| 34 #include "ns3/nqos-wifi-mac-helper.h" |
| 35 #include "ns3/mobility-helper.h" |
| 36 #include "ns3/packet-socket-helper.h" |
| 37 #include "ns3/packet-socket-address.h" |
| 38 #include "ns3/packet-sink-helper.h" |
| 39 #include "ns3/on-off-helper.h" |
| 40 #include "ns3/data-rate.h" |
| 41 #include "ns3/physim-wifi-phy-tag.h" |
| 42 #include "physim-wifi-transmitter-receiver-test.h" |
| 43 |
| 44 NS_LOG_COMPONENT_DEFINE ("PhySimWifiTransmitterReceiverTest"); |
| 45 |
| 46 namespace ns3 { |
| 47 |
| 48 PhySimWifiTransmitterReceiverTest::PhySimWifiTransmitterReceiverTest () |
| 49 : TestCase ("PhySim transmission over perfect channel test case") |
| 50 { |
| 51 } |
| 52 |
| 53 PhySimWifiTransmitterReceiverTest::~PhySimWifiTransmitterReceiverTest () |
| 54 { |
| 55 } |
| 56 |
| 57 bool |
| 58 PhySimWifiTransmitterReceiverTest::DoRun (void) |
| 59 { |
| 60 SetErrorStatus (false); |
| 61 |
| 62 // Provide known seed for predictable results |
| 63 SeedManager::SetSeed (1); |
| 64 |
| 65 std::string modes[] = { "OfdmRate3MbpsBW10MHz","OfdmRate4_5MbpsBW10MHz","OfdmR
ate6MbpsBW10MHz","OfdmRate9MbpsBW10MHz","OfdmRate12MbpsBW10MHz","OfdmRate18MbpsB
W10MHz","OfdmRate24MbpsBW10MHz","OfdmRate27MbpsBW10MHz"}; |
| 66 for (int i = 0; i < 8; ++i) |
| 67 { |
| 68 RunSingle (modes[i]); |
| 69 if (!m_success) |
| 70 { |
| 71 NS_LOG_DEBUG ("FAIL: Frame transmission over a perfect channel test fo
r" << modes[i]); |
| 72 } |
| 73 else |
| 74 { |
| 75 NS_LOG_DEBUG ("PASS: Frame transmission over a perfect channel test fo
r " << modes[i]); |
| 76 } |
| 77 NS_TEST_ASSERT_MSG_EQ ( m_success, true, "Transmitter Receiver test failed
for " << modes[i] << " : frame was not successfully decoded under ideal channel
conditions"); |
| 78 } |
| 79 return false; |
| 80 } |
| 81 |
| 82 |
| 83 bool |
| 84 PhySimWifiTransmitterReceiverTest::RunSingle (std::string wifiMode) |
| 85 { |
| 86 m_success = true; |
| 87 |
| 88 // Disable fragmentation |
| 89 Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", S
tringValue ("2200")); |
| 90 Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringVa
lue ("2200")); |
| 91 |
| 92 // Do not use a fixed scrambler |
| 93 Config::SetDefault ("ns3::PhySimScrambler::UseFixedScrambler", BooleanValue (f
alse) ); |
| 94 |
| 95 // Configure PhySimWifiPhy |
| 96 Config::SetDefault ("ns3::PhySimWifiPhy::TxPowerEnd", DoubleValue (1.0) ); |
| 97 Config::SetDefault ("ns3::PhySimWifiPhy::TxPowerStart", DoubleValue (1.0) ); |
| 98 Config::SetDefault ("ns3::PhySimWifiPhy::TxPowerLevels", UintegerValue (1) ); |
| 99 Config::SetDefault ("ns3::PhySimWifiPhy::TxGain", DoubleValue (0.0) ); |
| 100 Config::SetDefault ("ns3::PhySimWifiPhy::RxGain", DoubleValue (0.0) ); |
| 101 |
| 102 // Set the correct Channel Estimator implementation |
| 103 Config::SetDefault ("ns3::PhySimWifiPhy::ChannelEstimator", StringValue ("ns3:
:PhySimChannelFrequencyOffsetEstimator") ); |
| 104 |
| 105 // Configure PHY layer to reflect IEEE 802.11a 10Mhz OFDM mode |
| 106 Config::SetDefault ("ns3::PhySimWifiPhy::Standard", EnumValue (WIFI_PHY_STANDA
RD_80211_10Mhz)); |
| 107 |
| 108 // Disable Noise for perfect channel |
| 109 Config::SetDefault ("ns3::PhySimInterferenceHelper::DisableNoise", BooleanValu
e (true) ); |
| 110 |
| 111 // Only allow hard decisions |
| 112 Config::SetDefault ("ns3::PhySimConvolutionalEncoder::SoftViterbiDecision", Bo
oleanValue (false)); |
| 113 Config::SetDefault ("ns3::PhySimOFDMSymbolCreator::SoftViterbiDecision", Boole
anValue (false)); |
| 114 |
| 115 // Channel without propagation loss |
| 116 PhySimWifiChannelHelper wifiChannel; |
| 117 wifiChannel.AddPropagationLoss ("ns3::PhySimPropagationLossModel"); |
| 118 |
| 119 // In the future, we can also add more |
| 120 wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel"); |
| 121 |
| 122 PhySimWifiPhyHelper wifiPhy = PhySimWifiPhyHelper::Default (); |
| 123 wifiPhy.SetChannel (wifiChannel.Create ()); |
| 124 |
| 125 WifiHelper wifi = WifiHelper::Default (); |
| 126 NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); |
| 127 wifiMac.SetType ("ns3::AdhocWifiMac"); |
| 128 wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", |
| 129 "DataMode", StringValue (wifiMode), |
| 130 "NonUnicastMode", StringValue (wifiMode)); |
| 131 |
| 132 NodeContainer nodes; |
| 133 nodes.Create (2); |
| 134 |
| 135 // Install WifiPhy and set up mobility |
| 136 wifi.Install (wifiPhy, wifiMac, nodes); |
| 137 |
| 138 MobilityHelper mobility; |
| 139 Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator>
(); |
| 140 positionAlloc->Add (Vector (0.0, 0.0, 0.0)); |
| 141 positionAlloc->Add (Vector (1.0, 0.0, 0.0)); |
| 142 mobility.SetPositionAllocator (positionAlloc); |
| 143 mobility.Install (nodes); |
| 144 |
| 145 // Add packet socket handlers |
| 146 PacketSocketHelper packetSocket; |
| 147 packetSocket.Install (nodes); |
| 148 |
| 149 // Configure packet socket for receiving node 0 |
| 150 PacketSocketAddress socketOn0; |
| 151 socketOn0.SetAllDevices (); |
| 152 socketOn0.SetPhysicalAddress (Mac48Address::GetBroadcast ()); |
| 153 socketOn0.SetProtocol (1); |
| 154 PacketSinkHelper sink ("ns3::PacketSocketFactory", Address (socketOn0)); |
| 155 |
| 156 // Install OnOffApplication on transmitting node 1 |
| 157 // Configure to only send 1 packet |
| 158 PacketSocketAddress socketTo0; |
| 159 socketTo0.SetAllDevices (); |
| 160 socketTo0.SetPhysicalAddress (Mac48Address::GetBroadcast ()); |
| 161 socketTo0.SetProtocol (1); |
| 162 OnOffHelper onOff ("ns3::PacketSocketFactory", Address (socketTo0)); |
| 163 onOff.SetAttribute ("PacketSize", UintegerValue (512)); |
| 164 onOff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1.0))); |
| 165 onOff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0.0))); |
| 166 // Set the data rate |
| 167 onOff.SetAttribute ("DataRate", DataRateValue (DataRate ("4kb/s"))); |
| 168 |
| 169 // Configure start/stop times of the application/sink |
| 170 ApplicationContainer app; |
| 171 app = sink.Install (nodes.Get (1)); |
| 172 app = onOff.Install (nodes.Get (0)); |
| 173 app.Start (Seconds (0.0)); |
| 174 app.Stop (Seconds (2.0)); |
| 175 |
| 176 Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/RxOk", Make
Callback (&PhySimWifiTransmitterReceiverTest::PhyRxOkTrace, this) ); |
| 177 Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/RxError", M
akeCallback (&PhySimWifiTransmitterReceiverTest::PhyRxErrorTrace, this) ); |
| 178 |
| 179 Simulator::Run (); |
| 180 Simulator::Destroy (); |
| 181 |
| 182 return true; |
| 183 } |
| 184 |
| 185 void |
| 186 PhySimWifiTransmitterReceiverTest::PhyRxOkTrace (std::string context, Ptr<const
Packet> p, Ptr<const PhySimWifiPhyTag> tag) |
| 187 { |
| 188 } |
| 189 |
| 190 void |
| 191 PhySimWifiTransmitterReceiverTest::PhyRxErrorTrace (std::string context, Ptr<con
st Packet> p, Ptr<const PhySimWifiPhyTag> tag) |
| 192 { |
| 193 m_success = false; |
| 194 } |
| 195 |
| 196 } // namespace ns3 |
OLD | NEW |