blob: a2b083f77241679d5776a5d725242ee71d55a1b6 [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;
31using namespace ns3;
32
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
37// communicating
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070038// directly over AdHoc channel.
39//
40
41// Ptr<ndn::NetDeviceFace>
42// MyNetDeviceFaceCallback (Ptr<Node> node, Ptr<ndn::L3Protocol> ndn, Ptr<NetDevice> device)
43// {
44// // NS_LOG_DEBUG ("Create custom network device " << node->GetId ());
45// Ptr<ndn::NetDeviceFace> face = CreateObject<ndn::MyNetDeviceFace> (node, device);
46// ndn->AddFace (face);
47// return face;
48// }
49
50int
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080051main(int argc, char* argv[])
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070052{
53 // disable fragmentation
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080054 Config::SetDefault("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue("2200"));
55 Config::SetDefault("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue("2200"));
56 Config::SetDefault("ns3::WifiRemoteStationManager::NonUnicastMode",
57 StringValue("OfdmRate24Mbps"));
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070058
59 CommandLine cmd;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080060 cmd.Parse(argc, argv);
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070061
62 //////////////////////
63 //////////////////////
64 //////////////////////
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080065 WifiHelper wifi = WifiHelper::Default();
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070066 // wifi.SetRemoteStationManager ("ns3::AarfWifiManager");
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080067 wifi.SetStandard(WIFI_PHY_STANDARD_80211a);
68 wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager", "DataMode",
69 StringValue("OfdmRate24Mbps"));
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070070
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080071 YansWifiChannelHelper wifiChannel; // = YansWifiChannelHelper::Default ();
72 wifiChannel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel");
73 wifiChannel.AddPropagationLoss("ns3::ThreeLogDistancePropagationLossModel");
74 wifiChannel.AddPropagationLoss("ns3::NakagamiPropagationLossModel");
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070075
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080076 // YansWifiPhy wifiPhy = YansWifiPhy::Default();
77 YansWifiPhyHelper wifiPhyHelper = YansWifiPhyHelper::Default();
78 wifiPhyHelper.SetChannel(wifiChannel.Create());
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070079 wifiPhyHelper.Set("TxPowerStart", DoubleValue(5));
80 wifiPhyHelper.Set("TxPowerEnd", DoubleValue(5));
81
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080082 NqosWifiMacHelper wifiMacHelper = NqosWifiMacHelper::Default();
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070083 wifiMacHelper.SetType("ns3::AdhocWifiMac");
84
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080085 Ptr<UniformRandomVariable> randomizer = CreateObject<UniformRandomVariable>();
86 randomizer->SetAttribute("Min", DoubleValue(10));
87 randomizer->SetAttribute("Max", DoubleValue(100));
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070088
89 MobilityHelper mobility;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080090 mobility.SetPositionAllocator("ns3::RandomBoxPositionAllocator", "X", PointerValue(randomizer),
91 "Y", PointerValue(randomizer), "Z", PointerValue(randomizer));
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070092
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080093 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070094
95 NodeContainer nodes;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080096 nodes.Create(2);
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070097
98 ////////////////
99 // 1. Install Wifi
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800100 NetDeviceContainer wifiNetDevices = wifi.Install(wifiPhyHelper, wifiMacHelper, nodes);
Alexander Afanasyev0d584e32013-08-13 10:41:42 -0700101
102 // 2. Install Mobility model
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800103 mobility.Install(nodes);
Alexander Afanasyev0d584e32013-08-13 10:41:42 -0700104
105 // 3. Install NDN stack
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800106 NS_LOG_INFO("Installing NDN stack");
Alexander Afanasyev0d584e32013-08-13 10:41:42 -0700107 ndn::StackHelper ndnHelper;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800108 // ndnHelper.AddNetDeviceFaceCreateCallback (WifiNetDevice::GetTypeId (), MakeCallback
109 // (MyNetDeviceFaceCallback));
110 ndnHelper.SetForwardingStrategy("ns3::ndn::fw::BestRoute");
111 ndnHelper.SetContentStore("ns3::ndn::cs::Lru", "MaxSize", "1000");
112 ndnHelper.SetDefaultRoutes(true);
113 ndnHelper.Install(nodes);
Alexander Afanasyev0d584e32013-08-13 10:41:42 -0700114
115 // 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}