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; |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 31 | namespace ns3 { |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 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 |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 37 | // communicating directly over AdHoc channel. |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 38 | // |
| 39 | |
| 40 | // Ptr<ndn::NetDeviceFace> |
| 41 | // MyNetDeviceFaceCallback (Ptr<Node> node, Ptr<ndn::L3Protocol> ndn, Ptr<NetDevice> device) |
| 42 | // { |
| 43 | // // NS_LOG_DEBUG ("Create custom network device " << node->GetId ()); |
| 44 | // Ptr<ndn::NetDeviceFace> face = CreateObject<ndn::MyNetDeviceFace> (node, device); |
| 45 | // ndn->AddFace (face); |
| 46 | // return face; |
| 47 | // } |
| 48 | |
| 49 | int |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 50 | main(int argc, char* argv[]) |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 51 | { |
| 52 | // disable fragmentation |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 53 | Config::SetDefault("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue("2200")); |
| 54 | Config::SetDefault("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue("2200")); |
| 55 | Config::SetDefault("ns3::WifiRemoteStationManager::NonUnicastMode", |
| 56 | StringValue("OfdmRate24Mbps")); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 57 | |
| 58 | CommandLine cmd; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 59 | cmd.Parse(argc, argv); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 60 | |
| 61 | ////////////////////// |
| 62 | ////////////////////// |
| 63 | ////////////////////// |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 64 | WifiHelper wifi = WifiHelper::Default(); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 65 | // wifi.SetRemoteStationManager ("ns3::AarfWifiManager"); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 66 | wifi.SetStandard(WIFI_PHY_STANDARD_80211a); |
| 67 | wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager", "DataMode", |
| 68 | StringValue("OfdmRate24Mbps")); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 69 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 70 | YansWifiChannelHelper wifiChannel; // = YansWifiChannelHelper::Default (); |
| 71 | wifiChannel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel"); |
| 72 | wifiChannel.AddPropagationLoss("ns3::ThreeLogDistancePropagationLossModel"); |
| 73 | wifiChannel.AddPropagationLoss("ns3::NakagamiPropagationLossModel"); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 74 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 75 | // YansWifiPhy wifiPhy = YansWifiPhy::Default(); |
| 76 | YansWifiPhyHelper wifiPhyHelper = YansWifiPhyHelper::Default(); |
| 77 | wifiPhyHelper.SetChannel(wifiChannel.Create()); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 78 | wifiPhyHelper.Set("TxPowerStart", DoubleValue(5)); |
| 79 | wifiPhyHelper.Set("TxPowerEnd", DoubleValue(5)); |
| 80 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 81 | NqosWifiMacHelper wifiMacHelper = NqosWifiMacHelper::Default(); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 82 | wifiMacHelper.SetType("ns3::AdhocWifiMac"); |
| 83 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 84 | Ptr<UniformRandomVariable> randomizer = CreateObject<UniformRandomVariable>(); |
| 85 | randomizer->SetAttribute("Min", DoubleValue(10)); |
| 86 | randomizer->SetAttribute("Max", DoubleValue(100)); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 87 | |
| 88 | MobilityHelper mobility; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 89 | mobility.SetPositionAllocator("ns3::RandomBoxPositionAllocator", "X", PointerValue(randomizer), |
| 90 | "Y", PointerValue(randomizer), "Z", PointerValue(randomizer)); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 91 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 92 | mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel"); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 93 | |
| 94 | NodeContainer nodes; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 95 | nodes.Create(2); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 96 | |
| 97 | //////////////// |
| 98 | // 1. Install Wifi |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 99 | NetDeviceContainer wifiNetDevices = wifi.Install(wifiPhyHelper, wifiMacHelper, nodes); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 100 | |
| 101 | // 2. Install Mobility model |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 102 | mobility.Install(nodes); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 103 | |
| 104 | // 3. Install NDN stack |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 105 | NS_LOG_INFO("Installing NDN stack"); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 106 | ndn::StackHelper ndnHelper; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 107 | // ndnHelper.AddNetDeviceFaceCreateCallback (WifiNetDevice::GetTypeId (), MakeCallback |
| 108 | // (MyNetDeviceFaceCallback)); |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 109 | ndnHelper.SetContentStoreChoice(false); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 110 | ndnHelper.SetContentStore("ns3::ndn::cs::Lru", "MaxSize", "1000"); |
| 111 | ndnHelper.SetDefaultRoutes(true); |
| 112 | ndnHelper.Install(nodes); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 113 | |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 114 | // Set BestRoute strategy |
| 115 | ndn::StrategyChoiceHelper::Install(nodes, "/", "/localhost/nfd/strategy/best-route"); |
| 116 | |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 117 | // 4. Set up applications |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 118 | NS_LOG_INFO("Installing Applications"); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 119 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 120 | ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr"); |
| 121 | consumerHelper.SetPrefix("/test/prefix"); |
| 122 | consumerHelper.SetAttribute("Frequency", DoubleValue(10.0)); |
| 123 | consumerHelper.Install(nodes.Get(0)); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 124 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 125 | ndn::AppHelper producerHelper("ns3::ndn::Producer"); |
| 126 | producerHelper.SetPrefix("/"); |
| 127 | producerHelper.SetAttribute("PayloadSize", StringValue("1200")); |
| 128 | producerHelper.Install(nodes.Get(1)); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 129 | |
| 130 | //////////////// |
| 131 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 132 | Simulator::Stop(Seconds(30.0)); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 133 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 134 | Simulator::Run(); |
| 135 | Simulator::Destroy(); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 136 | |
| 137 | return 0; |
| 138 | } |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 139 | |
| 140 | } // namespace ns3 |
| 141 | |
| 142 | int |
| 143 | main(int argc, char* argv[]) |
| 144 | { |
| 145 | return ns3::main(argc, argv); |
| 146 | } |