blob: 7c8ed0decba831779d66d03d1c78592dc7e59a1a [file] [log] [blame]
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2011-2015 Regents of the University of California.
Alexander Afanasyev0d584e32013-08-13 10:41:42 -07004 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08005 * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
6 * contributors.
Alexander Afanasyev0d584e32013-08-13 10:41:42 -07007 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08008 * 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 Afanasyev0d584e32013-08-13 10:41:42 -070011 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080012 * 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 Afanasyev0d584e32013-08-13 10:41:42 -070015 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080016 * 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 Afanasyev0d584e32013-08-13 10:41:42 -070019
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
29using namespace std;
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080030namespace ns3 {
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070031
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080032NS_LOG_COMPONENT_DEFINE("ndn.WifiExample");
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070033
34//
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080035// DISCLAIMER: Note that this is an extremely simple example, containing just 2 wifi nodes
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080036// communicating directly over AdHoc channel.
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070037//
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
48int
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080049main(int argc, char* argv[])
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070050{
51 // disable fragmentation
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080052 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 Afanasyev0d584e32013-08-13 10:41:42 -070056
57 CommandLine cmd;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080058 cmd.Parse(argc, argv);
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070059
60 //////////////////////
61 //////////////////////
62 //////////////////////
Alexander Afanasyev89b13e22018-05-08 14:03:27 -040063 WifiHelper wifi;
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070064 // wifi.SetRemoteStationManager ("ns3::AarfWifiManager");
Alexander Afanasyevf007a992022-05-05 15:57:08 -040065 wifi.SetStandard(WIFI_STANDARD_80211a);
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080066 wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager", "DataMode",
67 StringValue("OfdmRate24Mbps"));
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070068
Alexander Afanasyevf007a992022-05-05 15:57:08 -040069 YansWifiChannelHelper wifiChannel;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080070 wifiChannel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel");
71 wifiChannel.AddPropagationLoss("ns3::ThreeLogDistancePropagationLossModel");
72 wifiChannel.AddPropagationLoss("ns3::NakagamiPropagationLossModel");
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070073
Alexander Afanasyevf007a992022-05-05 15:57:08 -040074 YansWifiPhyHelper wifiPhyHelper;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080075 wifiPhyHelper.SetChannel(wifiChannel.Create());
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070076 wifiPhyHelper.Set("TxPowerStart", DoubleValue(5));
77 wifiPhyHelper.Set("TxPowerEnd", DoubleValue(5));
78
Alexander Afanasyev89b13e22018-05-08 14:03:27 -040079 WifiMacHelper wifiMacHelper;
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070080 wifiMacHelper.SetType("ns3::AdhocWifiMac");
81
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080082 Ptr<UniformRandomVariable> randomizer = CreateObject<UniformRandomVariable>();
83 randomizer->SetAttribute("Min", DoubleValue(10));
84 randomizer->SetAttribute("Max", DoubleValue(100));
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070085
86 MobilityHelper mobility;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080087 mobility.SetPositionAllocator("ns3::RandomBoxPositionAllocator", "X", PointerValue(randomizer),
88 "Y", PointerValue(randomizer), "Z", PointerValue(randomizer));
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070089
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080090 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070091
92 NodeContainer nodes;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080093 nodes.Create(2);
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070094
95 ////////////////
96 // 1. Install Wifi
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080097 NetDeviceContainer wifiNetDevices = wifi.Install(wifiPhyHelper, wifiMacHelper, nodes);
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070098
99 // 2. Install Mobility model
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800100 mobility.Install(nodes);
Alexander Afanasyev0d584e32013-08-13 10:41:42 -0700101
102 // 3. Install NDN stack
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800103 NS_LOG_INFO("Installing NDN stack");
Alexander Afanasyev0d584e32013-08-13 10:41:42 -0700104 ndn::StackHelper ndnHelper;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800105 // ndnHelper.AddNetDeviceFaceCreateCallback (WifiNetDevice::GetTypeId (), MakeCallback
106 // (MyNetDeviceFaceCallback));
Alexander Afanasyev25e4d8f2019-07-29 13:44:04 -0400107 ndnHelper.setPolicy("nfd::cs::lru");
108 ndnHelper.setCsSize(1000);
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800109 ndnHelper.SetDefaultRoutes(true);
110 ndnHelper.Install(nodes);
Alexander Afanasyev0d584e32013-08-13 10:41:42 -0700111
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -0800112 // Set BestRoute strategy
113 ndn::StrategyChoiceHelper::Install(nodes, "/", "/localhost/nfd/strategy/best-route");
114
Alexander Afanasyev0d584e32013-08-13 10:41:42 -0700115 // 4. Set up applications
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800116 NS_LOG_INFO("Installing Applications");
Alexander Afanasyev0d584e32013-08-13 10:41:42 -0700117
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800118 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 Afanasyev0d584e32013-08-13 10:41:42 -0700122
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800123 ndn::AppHelper producerHelper("ns3::ndn::Producer");
124 producerHelper.SetPrefix("/");
125 producerHelper.SetAttribute("PayloadSize", StringValue("1200"));
126 producerHelper.Install(nodes.Get(1));
Alexander Afanasyev0d584e32013-08-13 10:41:42 -0700127
128 ////////////////
129
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800130 Simulator::Stop(Seconds(30.0));
Alexander Afanasyev0d584e32013-08-13 10:41:42 -0700131
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800132 Simulator::Run();
133 Simulator::Destroy();
Alexander Afanasyev0d584e32013-08-13 10:41:42 -0700134
135 return 0;
136}
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -0800137
138} // namespace ns3
139
140int
141main(int argc, char* argv[])
142{
143 return ns3::main(argc, argv);
144}