blob: db54c93d0471e08b8b49810540292c693da64650 [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
33NS_LOG_COMPONENT_DEFINE ("ndn.WifiExample");
34
35//
36// DISCLAIMER: Note that this is an extremely simple example, containing just 2 wifi nodes communicating
37// directly over AdHoc channel.
38//
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
50main (int argc, char *argv[])
51{
52 // disable fragmentation
53 Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200"));
54 Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200"));
55 Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", StringValue ("OfdmRate24Mbps"));
56
57 CommandLine cmd;
58 cmd.Parse (argc,argv);
59
60 //////////////////////
61 //////////////////////
62 //////////////////////
63 WifiHelper wifi = WifiHelper::Default ();
64 // wifi.SetRemoteStationManager ("ns3::AarfWifiManager");
65 wifi.SetStandard (WIFI_PHY_STANDARD_80211a);
66 wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
67 "DataMode", StringValue ("OfdmRate24Mbps"));
68
69 YansWifiChannelHelper wifiChannel;// = YansWifiChannelHelper::Default ();
70 wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
71 wifiChannel.AddPropagationLoss ("ns3::ThreeLogDistancePropagationLossModel");
72 wifiChannel.AddPropagationLoss ("ns3::NakagamiPropagationLossModel");
73
74 //YansWifiPhy wifiPhy = YansWifiPhy::Default();
75 YansWifiPhyHelper wifiPhyHelper = YansWifiPhyHelper::Default ();
76 wifiPhyHelper.SetChannel (wifiChannel.Create ());
77 wifiPhyHelper.Set("TxPowerStart", DoubleValue(5));
78 wifiPhyHelper.Set("TxPowerEnd", DoubleValue(5));
79
80
81 NqosWifiMacHelper wifiMacHelper = NqosWifiMacHelper::Default ();
82 wifiMacHelper.SetType("ns3::AdhocWifiMac");
83
84 Ptr<UniformRandomVariable> randomizer = CreateObject<UniformRandomVariable> ();
85 randomizer->SetAttribute ("Min", DoubleValue (10));
86 randomizer->SetAttribute ("Max", DoubleValue (100));
87
88 MobilityHelper mobility;
89 mobility.SetPositionAllocator ("ns3::RandomBoxPositionAllocator",
90 "X", PointerValue (randomizer),
91 "Y", PointerValue (randomizer),
92 "Z", PointerValue (randomizer));
93
94 mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
95
96 NodeContainer nodes;
97 nodes.Create (2);
98
99 ////////////////
100 // 1. Install Wifi
101 NetDeviceContainer wifiNetDevices = wifi.Install (wifiPhyHelper, wifiMacHelper, nodes);
102
103 // 2. Install Mobility model
104 mobility.Install (nodes);
105
106 // 3. Install NDN stack
107 NS_LOG_INFO ("Installing NDN stack");
108 ndn::StackHelper ndnHelper;
109 // ndnHelper.AddNetDeviceFaceCreateCallback (WifiNetDevice::GetTypeId (), MakeCallback (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);
114
115 // 4. Set up applications
116 NS_LOG_INFO ("Installing Applications");
117
118 ndn::AppHelper consumerHelper ("ns3::ndn::ConsumerCbr");
119 consumerHelper.SetPrefix ("/test/prefix");
120 consumerHelper.SetAttribute ("Frequency", DoubleValue (10.0));
121 consumerHelper.Install (nodes.Get (0));
122
123 ndn::AppHelper producerHelper ("ns3::ndn::Producer");
124 producerHelper.SetPrefix ("/");
125 producerHelper.SetAttribute ("PayloadSize", StringValue("1200"));
126 producerHelper.Install (nodes.Get (1));
127
128 ////////////////
129
130 Simulator::Stop (Seconds (30.0));
131
132 Simulator::Run ();
133 Simulator::Destroy ();
134
135 return 0;
136}