Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2011-2015 Regents of the University of California. |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 4 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 5 | * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and |
| 6 | * contributors. |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 7 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 8 | * ndnSIM is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, |
| 10 | * either version 3 of the License, or (at your option) any later version. |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 11 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 12 | * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 15 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | **/ |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 19 | |
| 20 | #include "ns3/core-module.h" |
| 21 | #include "ns3/network-module.h" |
| 22 | #include "ns3/applications-module.h" |
| 23 | #include "ns3/wifi-module.h" |
| 24 | #include "ns3/mobility-module.h" |
| 25 | #include "ns3/internet-module.h" |
| 26 | |
| 27 | #include "ns3/ndnSIM-module.h" |
| 28 | |
| 29 | using namespace std; |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 30 | namespace ns3 { |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 31 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 32 | NS_LOG_COMPONENT_DEFINE("ndn.WifiExample"); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 33 | |
| 34 | // |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 35 | // 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] | 36 | // communicating directly over AdHoc channel. |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 37 | // |
| 38 | |
| 39 | // Ptr<ndn::NetDeviceFace> |
| 40 | // MyNetDeviceFaceCallback (Ptr<Node> node, Ptr<ndn::L3Protocol> ndn, Ptr<NetDevice> device) |
| 41 | // { |
| 42 | // // NS_LOG_DEBUG ("Create custom network device " << node->GetId ()); |
| 43 | // Ptr<ndn::NetDeviceFace> face = CreateObject<ndn::MyNetDeviceFace> (node, device); |
| 44 | // ndn->AddFace (face); |
| 45 | // return face; |
| 46 | // } |
| 47 | |
| 48 | int |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 49 | main(int argc, char* argv[]) |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 50 | { |
| 51 | // disable fragmentation |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 52 | Config::SetDefault("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue("2200")); |
| 53 | Config::SetDefault("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue("2200")); |
| 54 | Config::SetDefault("ns3::WifiRemoteStationManager::NonUnicastMode", |
| 55 | StringValue("OfdmRate24Mbps")); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 56 | |
| 57 | CommandLine cmd; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 58 | cmd.Parse(argc, argv); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 59 | |
| 60 | ////////////////////// |
| 61 | ////////////////////// |
| 62 | ////////////////////// |
Alexander Afanasyev | 89b13e2 | 2018-05-08 14:03:27 -0400 | [diff] [blame] | 63 | WifiHelper wifi; |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 64 | // wifi.SetRemoteStationManager ("ns3::AarfWifiManager"); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 65 | wifi.SetStandard(WIFI_PHY_STANDARD_80211a); |
| 66 | wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager", "DataMode", |
| 67 | StringValue("OfdmRate24Mbps")); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 68 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 69 | YansWifiChannelHelper wifiChannel; // = YansWifiChannelHelper::Default (); |
| 70 | wifiChannel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel"); |
| 71 | wifiChannel.AddPropagationLoss("ns3::ThreeLogDistancePropagationLossModel"); |
| 72 | wifiChannel.AddPropagationLoss("ns3::NakagamiPropagationLossModel"); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 73 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 74 | // YansWifiPhy wifiPhy = YansWifiPhy::Default(); |
| 75 | YansWifiPhyHelper wifiPhyHelper = YansWifiPhyHelper::Default(); |
| 76 | wifiPhyHelper.SetChannel(wifiChannel.Create()); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 77 | wifiPhyHelper.Set("TxPowerStart", DoubleValue(5)); |
| 78 | wifiPhyHelper.Set("TxPowerEnd", DoubleValue(5)); |
| 79 | |
Alexander Afanasyev | 89b13e2 | 2018-05-08 14:03:27 -0400 | [diff] [blame] | 80 | WifiMacHelper wifiMacHelper; |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 81 | wifiMacHelper.SetType("ns3::AdhocWifiMac"); |
| 82 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 83 | Ptr<UniformRandomVariable> randomizer = CreateObject<UniformRandomVariable>(); |
| 84 | randomizer->SetAttribute("Min", DoubleValue(10)); |
| 85 | randomizer->SetAttribute("Max", DoubleValue(100)); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 86 | |
| 87 | MobilityHelper mobility; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 88 | mobility.SetPositionAllocator("ns3::RandomBoxPositionAllocator", "X", PointerValue(randomizer), |
| 89 | "Y", PointerValue(randomizer), "Z", PointerValue(randomizer)); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 90 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 91 | mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel"); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 92 | |
| 93 | NodeContainer nodes; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 94 | nodes.Create(2); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 95 | |
| 96 | //////////////// |
| 97 | // 1. Install Wifi |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 98 | NetDeviceContainer wifiNetDevices = wifi.Install(wifiPhyHelper, wifiMacHelper, nodes); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 99 | |
| 100 | // 2. Install Mobility model |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 101 | mobility.Install(nodes); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 102 | |
| 103 | // 3. Install NDN stack |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 104 | NS_LOG_INFO("Installing NDN stack"); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 105 | ndn::StackHelper ndnHelper; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 106 | // ndnHelper.AddNetDeviceFaceCreateCallback (WifiNetDevice::GetTypeId (), MakeCallback |
| 107 | // (MyNetDeviceFaceCallback)); |
Alexander Afanasyev | 25e4d8f | 2019-07-29 13:44:04 -0400 | [diff] [blame^] | 108 | ndnHelper.setPolicy("nfd::cs::lru"); |
| 109 | ndnHelper.setCsSize(1000); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 110 | ndnHelper.SetDefaultRoutes(true); |
| 111 | ndnHelper.Install(nodes); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 112 | |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 113 | // Set BestRoute strategy |
| 114 | ndn::StrategyChoiceHelper::Install(nodes, "/", "/localhost/nfd/strategy/best-route"); |
| 115 | |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 116 | // 4. Set up applications |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 117 | NS_LOG_INFO("Installing Applications"); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 118 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 119 | ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr"); |
| 120 | consumerHelper.SetPrefix("/test/prefix"); |
| 121 | consumerHelper.SetAttribute("Frequency", DoubleValue(10.0)); |
| 122 | consumerHelper.Install(nodes.Get(0)); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 123 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 124 | ndn::AppHelper producerHelper("ns3::ndn::Producer"); |
| 125 | producerHelper.SetPrefix("/"); |
| 126 | producerHelper.SetAttribute("PayloadSize", StringValue("1200")); |
| 127 | producerHelper.Install(nodes.Get(1)); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 128 | |
| 129 | //////////////// |
| 130 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 131 | Simulator::Stop(Seconds(30.0)); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 132 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 133 | Simulator::Run(); |
| 134 | Simulator::Destroy(); |
Alexander Afanasyev | 0d584e3 | 2013-08-13 10:41:42 -0700 | [diff] [blame] | 135 | |
| 136 | return 0; |
| 137 | } |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 138 | |
| 139 | } // namespace ns3 |
| 140 | |
| 141 | int |
| 142 | main(int argc, char* argv[]) |
| 143 | { |
| 144 | return ns3::main(argc, argv); |
| 145 | } |