blob: 8230e18b411fe73da44cda3d6dae590f5a7b3c7b [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 Afanasyevbe55cf62014-12-20 17:51:09 -080063 WifiHelper wifi = WifiHelper::Default();
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070064 // wifi.SetRemoteStationManager ("ns3::AarfWifiManager");
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080065 wifi.SetStandard(WIFI_PHY_STANDARD_80211a);
66 wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager", "DataMode",
67 StringValue("OfdmRate24Mbps"));
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070068
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080069 YansWifiChannelHelper wifiChannel; // = YansWifiChannelHelper::Default ();
70 wifiChannel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel");
71 wifiChannel.AddPropagationLoss("ns3::ThreeLogDistancePropagationLossModel");
72 wifiChannel.AddPropagationLoss("ns3::NakagamiPropagationLossModel");
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070073
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080074 // YansWifiPhy wifiPhy = YansWifiPhy::Default();
75 YansWifiPhyHelper wifiPhyHelper = YansWifiPhyHelper::Default();
76 wifiPhyHelper.SetChannel(wifiChannel.Create());
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070077 wifiPhyHelper.Set("TxPowerStart", DoubleValue(5));
78 wifiPhyHelper.Set("TxPowerEnd", DoubleValue(5));
79
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080080 NqosWifiMacHelper wifiMacHelper = NqosWifiMacHelper::Default();
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070081 wifiMacHelper.SetType("ns3::AdhocWifiMac");
82
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080083 Ptr<UniformRandomVariable> randomizer = CreateObject<UniformRandomVariable>();
84 randomizer->SetAttribute("Min", DoubleValue(10));
85 randomizer->SetAttribute("Max", DoubleValue(100));
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070086
87 MobilityHelper mobility;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080088 mobility.SetPositionAllocator("ns3::RandomBoxPositionAllocator", "X", PointerValue(randomizer),
89 "Y", PointerValue(randomizer), "Z", PointerValue(randomizer));
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070090
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080091 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070092
93 NodeContainer nodes;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080094 nodes.Create(2);
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070095
96 ////////////////
97 // 1. Install Wifi
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080098 NetDeviceContainer wifiNetDevices = wifi.Install(wifiPhyHelper, wifiMacHelper, nodes);
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070099
100 // 2. Install Mobility model
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800101 mobility.Install(nodes);
Alexander Afanasyev0d584e32013-08-13 10:41:42 -0700102
103 // 3. Install NDN stack
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800104 NS_LOG_INFO("Installing NDN stack");
Alexander Afanasyev0d584e32013-08-13 10:41:42 -0700105 ndn::StackHelper ndnHelper;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800106 // ndnHelper.AddNetDeviceFaceCreateCallback (WifiNetDevice::GetTypeId (), MakeCallback
107 // (MyNetDeviceFaceCallback));
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -0800108 ndnHelper.SetContentStoreChoice(false);
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800109 ndnHelper.SetContentStore("ns3::ndn::cs::Lru", "MaxSize", "1000");
110 ndnHelper.SetDefaultRoutes(true);
111 ndnHelper.Install(nodes);
Alexander Afanasyev0d584e32013-08-13 10:41:42 -0700112
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -0800113 // Set BestRoute strategy
114 ndn::StrategyChoiceHelper::Install(nodes, "/", "/localhost/nfd/strategy/best-route");
115
Alexander Afanasyev0d584e32013-08-13 10:41:42 -0700116 // 4. Set up applications
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800117 NS_LOG_INFO("Installing Applications");
Alexander Afanasyev0d584e32013-08-13 10:41:42 -0700118
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800119 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 Afanasyev0d584e32013-08-13 10:41:42 -0700123
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800124 ndn::AppHelper producerHelper("ns3::ndn::Producer");
125 producerHelper.SetPrefix("/");
126 producerHelper.SetAttribute("PayloadSize", StringValue("1200"));
127 producerHelper.Install(nodes.Get(1));
Alexander Afanasyev0d584e32013-08-13 10:41:42 -0700128
129 ////////////////
130
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800131 Simulator::Stop(Seconds(30.0));
Alexander Afanasyev0d584e32013-08-13 10:41:42 -0700132
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800133 Simulator::Run();
134 Simulator::Destroy();
Alexander Afanasyev0d584e32013-08-13 10:41:42 -0700135
136 return 0;
137}
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -0800138
139} // namespace ns3
140
141int
142main(int argc, char* argv[])
143{
144 return ns3::main(argc, argv);
145}