OLD | NEW |
(Empty) | |
| 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * This program is free software; you can redistribute it and/or modify |
| 4 * it under the terms of the GNU General Public License version 2 as |
| 5 * published by the Free Software Foundation; |
| 6 * |
| 7 * This program is distributed in the hope that it will be useful, |
| 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 * GNU General Public License for more details. |
| 11 * |
| 12 * You should have received a copy of the GNU General Public License |
| 13 * along with this program; if not, write to the Free Software |
| 14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 15 */ |
| 16 |
| 17 // Adaptation of examples/udp/udp-client-server.cc for |
| 18 // Click based nodes running wifi. |
| 19 // |
| 20 // Network topology |
| 21 // |
| 22 // 172.16.1.0/24 |
| 23 // (1.1) (1.2) (1.3) |
| 24 // n0 )) (( n1 )) (( n2 |
| 25 // WLAN |
| 26 // |
| 27 // - UDP flows from n0 to n1 and n2 to n1 |
| 28 // - All nodes are Click based. |
| 29 // - The single ethernet interface that each node |
| 30 // uses is named 'eth0' in the Click file. |
| 31 // |
| 32 |
| 33 #include <fstream> |
| 34 #include "ns3/core-module.h" |
| 35 #include "ns3/simulator-module.h" |
| 36 #include "ns3/helper-module.h" |
| 37 |
| 38 using namespace ns3; |
| 39 |
| 40 NS_LOG_COMPONENT_DEFINE ("NsclickUdpClientServerWifi"); |
| 41 |
| 42 int |
| 43 main (int argc, char *argv[]) |
| 44 { |
| 45 #ifdef NS3_CLICK |
| 46 // |
| 47 // Enable logging for UdpClient and |
| 48 // |
| 49 LogComponentEnable ("NsclickUdpClientWifi", LOG_LEVEL_INFO); |
| 50 LogComponentEnable ("NsclickUdpServerWifi", LOG_LEVEL_INFO); |
| 51 |
| 52 // |
| 53 // Explicitly create the nodes required by the topology (shown above). |
| 54 // |
| 55 NS_LOG_INFO ("Create nodes."); |
| 56 NodeContainer n; |
| 57 n.Create (3); |
| 58 |
| 59 // |
| 60 // Install Click on the nodes |
| 61 // |
| 62 ClickInternetStackHelper clickinternet; |
| 63 clickinternet.SetClickFile (n, "examples/click/nsclick-raw-wlan.click"); |
| 64 clickinternet.SetRoutingTableElement (n, "u/rt"); |
| 65 clickinternet.Install (n); |
| 66 |
| 67 NS_LOG_INFO ("Create channels."); |
| 68 // |
| 69 // Explicitly create the channels required by the topology (shown above). |
| 70 // |
| 71 std::string phyMode ("DsssRate1Mbps"); |
| 72 |
| 73 // disable fragmentation for frames below 2200 bytes |
| 74 Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", S
tringValue ("2200")); |
| 75 // turn off RTS/CTS for frames below 2200 bytes |
| 76 Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringVa
lue ("2200")); |
| 77 // Fix non-unicast data rate to be the same as that of unicast |
| 78 Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", |
| 79 StringValue (phyMode)); |
| 80 |
| 81 WifiHelper wifi; |
| 82 wifi.SetStandard (WIFI_PHY_STANDARD_80211b); |
| 83 |
| 84 YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default (); |
| 85 // This is one parameter that matters when using FixedRssLossModel |
| 86 // set it to zero; otherwise, gain will be added |
| 87 wifiPhy.Set ("RxGain", DoubleValue (0) ); |
| 88 // ns-3 supports RadioTap and Prism tracing extensions for 802.11b |
| 89 wifiPhy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO); |
| 90 |
| 91 YansWifiChannelHelper wifiChannel ; |
| 92 wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel"); |
| 93 // The below FixedRssLossModel will cause the rss to be fixed regardless |
| 94 // of the distance between the two stations, and the transmit power |
| 95 wifiChannel.AddPropagationLoss ("ns3::FixedRssLossModel","Rss",DoubleValue(-80
)); |
| 96 wifiPhy.SetChannel (wifiChannel.Create ()); |
| 97 |
| 98 // Add a non-QoS upper mac, and disable rate control |
| 99 NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); |
| 100 wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", |
| 101 "DataMode",StringValue(phyMode), |
| 102 "ControlMode",StringValue(phyMode)); |
| 103 // Set it to adhoc mode |
| 104 wifiMac.SetType ("ns3::AdhocWifiMac"); |
| 105 NetDeviceContainer d = wifi.Install (wifiPhy, wifiMac, n);· |
| 106 ·· |
| 107 MobilityHelper mobility; |
| 108 Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator>
(); |
| 109 positionAlloc->Add (Vector (0.0, 0.0, 0.0)); |
| 110 positionAlloc->Add (Vector (5.0, 0.0, 0.0)); |
| 111 mobility.SetPositionAllocator (positionAlloc); |
| 112 mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); |
| 113 mobility.Install (n); |
| 114 |
| 115 |
| 116 Ipv4AddressHelper ipv4; |
| 117 // |
| 118 // We've got the "hardware" in place. Now we need to add IP addresses. |
| 119 // |
| 120 NS_LOG_INFO ("Assign IP Addresses."); |
| 121 ipv4.SetBase ("172.16.1.0", "255.255.255.0"); |
| 122 Ipv4InterfaceContainer i = ipv4.Assign (d); |
| 123 |
| 124 NS_LOG_INFO ("Create Applications."); |
| 125 // |
| 126 // Create one udpServer applications on node one. |
| 127 // |
| 128 uint16_t port = 4000; |
| 129 UdpServerHelper server (port); |
| 130 ApplicationContainer apps = server.Install (n.Get(1)); |
| 131 apps.Start (Seconds (1.0)); |
| 132 apps.Stop (Seconds (10.0)); |
| 133 |
| 134 // |
| 135 // Create one UdpClient application to send UDP datagrams from node zero to |
| 136 // node one. |
| 137 // |
| 138 uint32_t MaxPacketSize = 1024; |
| 139 Time interPacketInterval = Seconds (0.05); |
| 140 uint32_t maxPacketCount = 320; |
| 141 UdpClientHelper client (i.GetAddress (1), port); |
| 142 client.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount)); |
| 143 client.SetAttribute ("Interval", TimeValue (interPacketInterval)); |
| 144 client.SetAttribute ("PacketSize", UintegerValue (MaxPacketSize)); |
| 145 apps = client.Install (NodeContainer (n.Get (0), n.Get (2))); |
| 146 apps.Start (Seconds (2.0)); |
| 147 apps.Stop (Seconds (10.0)); |
| 148 |
| 149 wifiPhy.EnablePcap ("nsclick-udp-client-server-wifi", d); |
| 150 |
| 151 // |
| 152 // Now, do the actual simulation. |
| 153 // |
| 154 NS_LOG_INFO ("Run Simulation."); |
| 155 Simulator::Stop (Seconds(20.0)); |
| 156 Simulator::Run (); |
| 157 Simulator::Destroy (); |
| 158 NS_LOG_INFO ("Done."); |
| 159 #else |
| 160 NS_FATAL_ERROR ("Can't use ns-3-click without NSCLICK compiled in"); |
| 161 #endif |
| 162 } |
OLD | NEW |