Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2012-2013 University of California, Los Angeles |
| 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 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | */ |
| 20 | |
| 21 | #include "ns3/core-module.h" |
| 22 | #include "ns3/network-module.h" |
| 23 | #include "ns3/applications-module.h" |
| 24 | #include "ns3/wifi-module.h" |
| 25 | #include "ns3/mobility-module.h" |
| 26 | #include "ns3/internet-module.h" |
| 27 | |
| 28 | #include "ns3/ndnSIM-module.h" |
| 29 | |
| 30 | using namespace std; |
| 31 | using namespace ns3; |
| 32 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 33 | NS_LOG_COMPONENT_DEFINE("ndn.WifiExample"); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 34 | |
| 35 | // |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 36 | // DISCLAIMER: Note that this is an extremely simple example, containing just 2 wifi nodes |
| 37 | // communicating |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 38 | // directly over AdHoc channel. |
| 39 | // |
| 40 | |
| 41 | // Ptr<ndn::NetDeviceFace> |
| 42 | // MyNetDeviceFaceCallback (Ptr<Node> node, Ptr<ndn::L3Protocol> ndn, Ptr<NetDevice> device) |
| 43 | // { |
| 44 | // // NS_LOG_DEBUG ("Create custom network device " << node->GetId ()); |
| 45 | // Ptr<ndn::NetDeviceFace> face = CreateObject<ndn::MyNetDeviceFace> (node, device); |
| 46 | // ndn->AddFace (face); |
| 47 | // return face; |
| 48 | // } |
| 49 | |
| 50 | int |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 51 | main(int argc, char* argv[]) |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 52 | { |
| 53 | // disable fragmentation |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 54 | Config::SetDefault("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue("2200")); |
| 55 | Config::SetDefault("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue("2200")); |
| 56 | Config::SetDefault("ns3::WifiRemoteStationManager::NonUnicastMode", |
| 57 | StringValue("OfdmRate24Mbps")); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 58 | |
| 59 | CommandLine cmd; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 60 | cmd.Parse(argc, argv); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 61 | |
| 62 | ////////////////////// |
| 63 | ////////////////////// |
| 64 | ////////////////////// |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 65 | WifiHelper wifi = WifiHelper::Default(); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 66 | // wifi.SetRemoteStationManager ("ns3::AarfWifiManager"); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 67 | wifi.SetStandard(WIFI_PHY_STANDARD_80211a); |
| 68 | wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager", "DataMode", |
| 69 | StringValue("OfdmRate24Mbps")); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 70 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 71 | YansWifiChannelHelper wifiChannel; // = YansWifiChannelHelper::Default (); |
| 72 | wifiChannel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel"); |
| 73 | wifiChannel.AddPropagationLoss("ns3::ThreeLogDistancePropagationLossModel"); |
| 74 | wifiChannel.AddPropagationLoss("ns3::NakagamiPropagationLossModel"); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 75 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 76 | // YansWifiPhy wifiPhy = YansWifiPhy::Default(); |
| 77 | YansWifiPhyHelper wifiPhyHelper = YansWifiPhyHelper::Default(); |
| 78 | wifiPhyHelper.SetChannel(wifiChannel.Create()); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 79 | wifiPhyHelper.Set("TxPowerStart", DoubleValue(5)); |
| 80 | wifiPhyHelper.Set("TxPowerEnd", DoubleValue(5)); |
| 81 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 82 | NqosWifiMacHelper wifiMacHelper = NqosWifiMacHelper::Default(); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 83 | wifiMacHelper.SetType("ns3::AdhocWifiMac"); |
| 84 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 85 | Ptr<UniformRandomVariable> randomizer = CreateObject<UniformRandomVariable>(); |
| 86 | randomizer->SetAttribute("Min", DoubleValue(10)); |
| 87 | randomizer->SetAttribute("Max", DoubleValue(100)); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 88 | |
| 89 | MobilityHelper mobility; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 90 | mobility.SetPositionAllocator("ns3::RandomBoxPositionAllocator", "X", PointerValue(randomizer), |
| 91 | "Y", PointerValue(randomizer), "Z", PointerValue(randomizer)); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 92 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 93 | mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel"); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 94 | |
| 95 | NodeContainer nodes; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 96 | nodes.Create(2); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 97 | |
| 98 | //////////////// |
| 99 | // 1. Install Wifi |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 100 | NetDeviceContainer wifiNetDevices = wifi.Install(wifiPhyHelper, wifiMacHelper, nodes); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 101 | |
| 102 | // 2. Install Mobility model |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 103 | mobility.Install(nodes); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 104 | |
| 105 | // 3. Install NDN stack |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 106 | NS_LOG_INFO("Installing NDN stack"); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 107 | ndn::StackHelper ndnHelper; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 108 | // ndnHelper.AddNetDeviceFaceCreateCallback (WifiNetDevice::GetTypeId (), MakeCallback |
| 109 | // (MyNetDeviceFaceCallback)); |
| 110 | ndnHelper.SetForwardingStrategy("ns3::ndn::fw::BestRoute"); |
| 111 | ndnHelper.SetContentStore("ns3::ndn::cs::Lru", "MaxSize", "1000"); |
| 112 | ndnHelper.SetDefaultRoutes(true); |
| 113 | ndnHelper.Install(nodes); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 114 | |
| 115 | // 4. Set up applications |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 116 | NS_LOG_INFO("Installing Applications"); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 117 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 118 | ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr"); |
| 119 | consumerHelper.SetPrefix("/test/prefix"); |
| 120 | consumerHelper.SetAttribute("Frequency", DoubleValue(10.0)); |
| 121 | consumerHelper.Install(nodes.Get(0)); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 122 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 123 | ndn::AppHelper producerHelper("ns3::ndn::Producer"); |
| 124 | producerHelper.SetPrefix("/"); |
| 125 | producerHelper.SetAttribute("PayloadSize", StringValue("1200")); |
| 126 | producerHelper.Install(nodes.Get(1)); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 127 | |
| 128 | //////////////// |
| 129 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 130 | Simulator::Stop(Seconds(30.0)); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 131 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 132 | Simulator::Run(); |
| 133 | Simulator::Destroy(); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 134 | |
| 135 | return 0; |
| 136 | } |