blob: 9010d266bba516fc56409345f5dc39c5f3ad1fab [file] [log] [blame]
Alexander Afanasyev0d584e32013-08-13 10:41:42 -07001/* -*- 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
30using namespace std;
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080031namespace ns3 {
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070032
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080033NS_LOG_COMPONENT_DEFINE("ndn.WifiExample");
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070034
35//
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080036// DISCLAIMER: Note that this is an extremely simple example, containing just 2 wifi nodes
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080037// communicating directly over AdHoc channel.
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070038//
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
49int
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080050main(int argc, char* argv[])
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070051{
52 // disable fragmentation
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080053 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 Afanasyev0d584e32013-08-13 10:41:42 -070057
58 CommandLine cmd;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080059 cmd.Parse(argc, argv);
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070060
61 //////////////////////
62 //////////////////////
63 //////////////////////
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080064 WifiHelper wifi = WifiHelper::Default();
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070065 // wifi.SetRemoteStationManager ("ns3::AarfWifiManager");
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080066 wifi.SetStandard(WIFI_PHY_STANDARD_80211a);
67 wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager", "DataMode",
68 StringValue("OfdmRate24Mbps"));
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070069
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080070 YansWifiChannelHelper wifiChannel; // = YansWifiChannelHelper::Default ();
71 wifiChannel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel");
72 wifiChannel.AddPropagationLoss("ns3::ThreeLogDistancePropagationLossModel");
73 wifiChannel.AddPropagationLoss("ns3::NakagamiPropagationLossModel");
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070074
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080075 // YansWifiPhy wifiPhy = YansWifiPhy::Default();
76 YansWifiPhyHelper wifiPhyHelper = YansWifiPhyHelper::Default();
77 wifiPhyHelper.SetChannel(wifiChannel.Create());
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070078 wifiPhyHelper.Set("TxPowerStart", DoubleValue(5));
79 wifiPhyHelper.Set("TxPowerEnd", DoubleValue(5));
80
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080081 NqosWifiMacHelper wifiMacHelper = NqosWifiMacHelper::Default();
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070082 wifiMacHelper.SetType("ns3::AdhocWifiMac");
83
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080084 Ptr<UniformRandomVariable> randomizer = CreateObject<UniformRandomVariable>();
85 randomizer->SetAttribute("Min", DoubleValue(10));
86 randomizer->SetAttribute("Max", DoubleValue(100));
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070087
88 MobilityHelper mobility;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080089 mobility.SetPositionAllocator("ns3::RandomBoxPositionAllocator", "X", PointerValue(randomizer),
90 "Y", PointerValue(randomizer), "Z", PointerValue(randomizer));
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070091
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080092 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070093
94 NodeContainer nodes;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080095 nodes.Create(2);
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070096
97 ////////////////
98 // 1. Install Wifi
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080099 NetDeviceContainer wifiNetDevices = wifi.Install(wifiPhyHelper, wifiMacHelper, nodes);
Alexander Afanasyev0d584e32013-08-13 10:41:42 -0700100
101 // 2. Install Mobility model
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800102 mobility.Install(nodes);
Alexander Afanasyev0d584e32013-08-13 10:41:42 -0700103
104 // 3. Install NDN stack
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800105 NS_LOG_INFO("Installing NDN stack");
Alexander Afanasyev0d584e32013-08-13 10:41:42 -0700106 ndn::StackHelper ndnHelper;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800107 // ndnHelper.AddNetDeviceFaceCreateCallback (WifiNetDevice::GetTypeId (), MakeCallback
108 // (MyNetDeviceFaceCallback));
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -0800109 ndnHelper.SetContentStoreChoice(false);
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800110 ndnHelper.SetContentStore("ns3::ndn::cs::Lru", "MaxSize", "1000");
111 ndnHelper.SetDefaultRoutes(true);
112 ndnHelper.Install(nodes);
Alexander Afanasyev0d584e32013-08-13 10:41:42 -0700113
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -0800114 // Set BestRoute strategy
115 ndn::StrategyChoiceHelper::Install(nodes, "/", "/localhost/nfd/strategy/best-route");
116
Alexander Afanasyev0d584e32013-08-13 10:41:42 -0700117 // 4. Set up applications
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800118 NS_LOG_INFO("Installing Applications");
Alexander Afanasyev0d584e32013-08-13 10:41:42 -0700119
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800120 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 Afanasyev0d584e32013-08-13 10:41:42 -0700124
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800125 ndn::AppHelper producerHelper("ns3::ndn::Producer");
126 producerHelper.SetPrefix("/");
127 producerHelper.SetAttribute("PayloadSize", StringValue("1200"));
128 producerHelper.Install(nodes.Get(1));
Alexander Afanasyev0d584e32013-08-13 10:41:42 -0700129
130 ////////////////
131
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800132 Simulator::Stop(Seconds(30.0));
Alexander Afanasyev0d584e32013-08-13 10:41:42 -0700133
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800134 Simulator::Run();
135 Simulator::Destroy();
Alexander Afanasyev0d584e32013-08-13 10:41:42 -0700136
137 return 0;
138}
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -0800139
140} // namespace ns3
141
142int
143main(int argc, char* argv[])
144{
145 return ns3::main(argc, argv);
146}