blob: a2b083f77241679d5776a5d725242ee71d55a1b6 [file] [log] [blame]
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2012-2013 University of California, Los Angeles
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
*/
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/applications-module.h"
#include "ns3/wifi-module.h"
#include "ns3/mobility-module.h"
#include "ns3/internet-module.h"
#include "ns3/ndnSIM-module.h"
using namespace std;
using namespace ns3;
NS_LOG_COMPONENT_DEFINE("ndn.WifiExample");
//
// DISCLAIMER: Note that this is an extremely simple example, containing just 2 wifi nodes
// communicating
// directly over AdHoc channel.
//
// Ptr<ndn::NetDeviceFace>
// MyNetDeviceFaceCallback (Ptr<Node> node, Ptr<ndn::L3Protocol> ndn, Ptr<NetDevice> device)
// {
// // NS_LOG_DEBUG ("Create custom network device " << node->GetId ());
// Ptr<ndn::NetDeviceFace> face = CreateObject<ndn::MyNetDeviceFace> (node, device);
// ndn->AddFace (face);
// return face;
// }
int
main(int argc, char* argv[])
{
// disable fragmentation
Config::SetDefault("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue("2200"));
Config::SetDefault("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue("2200"));
Config::SetDefault("ns3::WifiRemoteStationManager::NonUnicastMode",
StringValue("OfdmRate24Mbps"));
CommandLine cmd;
cmd.Parse(argc, argv);
//////////////////////
//////////////////////
//////////////////////
WifiHelper wifi = WifiHelper::Default();
// wifi.SetRemoteStationManager ("ns3::AarfWifiManager");
wifi.SetStandard(WIFI_PHY_STANDARD_80211a);
wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager", "DataMode",
StringValue("OfdmRate24Mbps"));
YansWifiChannelHelper wifiChannel; // = YansWifiChannelHelper::Default ();
wifiChannel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel");
wifiChannel.AddPropagationLoss("ns3::ThreeLogDistancePropagationLossModel");
wifiChannel.AddPropagationLoss("ns3::NakagamiPropagationLossModel");
// YansWifiPhy wifiPhy = YansWifiPhy::Default();
YansWifiPhyHelper wifiPhyHelper = YansWifiPhyHelper::Default();
wifiPhyHelper.SetChannel(wifiChannel.Create());
wifiPhyHelper.Set("TxPowerStart", DoubleValue(5));
wifiPhyHelper.Set("TxPowerEnd", DoubleValue(5));
NqosWifiMacHelper wifiMacHelper = NqosWifiMacHelper::Default();
wifiMacHelper.SetType("ns3::AdhocWifiMac");
Ptr<UniformRandomVariable> randomizer = CreateObject<UniformRandomVariable>();
randomizer->SetAttribute("Min", DoubleValue(10));
randomizer->SetAttribute("Max", DoubleValue(100));
MobilityHelper mobility;
mobility.SetPositionAllocator("ns3::RandomBoxPositionAllocator", "X", PointerValue(randomizer),
"Y", PointerValue(randomizer), "Z", PointerValue(randomizer));
mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
NodeContainer nodes;
nodes.Create(2);
////////////////
// 1. Install Wifi
NetDeviceContainer wifiNetDevices = wifi.Install(wifiPhyHelper, wifiMacHelper, nodes);
// 2. Install Mobility model
mobility.Install(nodes);
// 3. Install NDN stack
NS_LOG_INFO("Installing NDN stack");
ndn::StackHelper ndnHelper;
// ndnHelper.AddNetDeviceFaceCreateCallback (WifiNetDevice::GetTypeId (), MakeCallback
// (MyNetDeviceFaceCallback));
ndnHelper.SetForwardingStrategy("ns3::ndn::fw::BestRoute");
ndnHelper.SetContentStore("ns3::ndn::cs::Lru", "MaxSize", "1000");
ndnHelper.SetDefaultRoutes(true);
ndnHelper.Install(nodes);
// 4. Set up applications
NS_LOG_INFO("Installing Applications");
ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
consumerHelper.SetPrefix("/test/prefix");
consumerHelper.SetAttribute("Frequency", DoubleValue(10.0));
consumerHelper.Install(nodes.Get(0));
ndn::AppHelper producerHelper("ns3::ndn::Producer");
producerHelper.SetPrefix("/");
producerHelper.SetAttribute("PayloadSize", StringValue("1200"));
producerHelper.Install(nodes.Get(1));
////////////////
Simulator::Stop(Seconds(30.0));
Simulator::Run();
Simulator::Destroy();
return 0;
}