Skip to content

Instantly share code, notes, and snippets.

@thiteixeira
Last active May 22, 2018 18:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thiteixeira/8c4fd1deb884b548d1f071ebb1bee043 to your computer and use it in GitHub Desktop.
Save thiteixeira/8c4fd1deb884b548d1f071ebb1bee043 to your computer and use it in GitHub Desktop.
See:
https://umass.box.com/s/s9qql8vo1kjy170qm8ijxcm6181ioip4
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2011-2015 Regents of the University of California.
*
* This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
* contributors.
*
* ndnSIM is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* ndnSIM 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
* ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
**/
/**
* This code currently crashes at 2099 seconds with error message
* Command ['/home/vagrant/ndnSIM/ns-3/build/scratch/ndn-debug-scenario'] terminated with signal SIGSEGV. Run it under a debugger to get more information (./waf --run <program> --command-template="gdb --args %s <args>").
**/
#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"
#include "ns3/point-to-point-helper.h"
namespace ns3{
NS_LOG_COMPONENT_DEFINE ("NDN-Offloading");
int
main(int argc, char* argv[])
{
uint16_t numberOfNodes = 49; // 7x7 grid
double simTime = 4000.0;
double gridSpace = 100.0; //spacing between nodes
// 802.11 Parameters
double m_txp = 15.0;
std::string phyMode = "ErpOfdmRate6Mbps";
// Command line arguments
CommandLine cmd;
cmd.AddValue("numberOfNodes", "Number of nodes", numberOfNodes);
cmd.AddValue("simTime", "Total duration of the simulation [s])", simTime);
cmd.Parse(argc, argv);
// 802.11 configuration
Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200"));
Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200"));
Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", StringValue (phyMode));
// Set maximum value of RTO to 4 seconds
//Config::SetDefault ("ns3::ndn::RttEstimator::MaxRTO", TimeValue (Seconds (1.0)));
NodeContainer nodes;
nodes.Create(numberOfNodes);
// Create ground station
NodeContainer gsNodes;
gsNodes.Create(1);
// Create a gateway
NodeContainer gwNodes;
gwNodes.Create(1);
// Create a single RemoteHost (Producer)
NodeContainer remoteHostNodes;
remoteHostNodes.Create (1);
//
// Configure PHY layer
//
WifiHelper wifi; // = WifiHelper::Default();
wifi.SetStandard (WIFI_PHY_STANDARD_80211g);
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
"DataMode", StringValue (phyMode),
"ControlMode", StringValue (phyMode));
YansWifiChannelHelper wifiChannel; // = YansWifiChannelHelper::Default ();
wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
wifiChannel.AddPropagationLoss("ns3::LogDistancePropagationLossModel",
"Exponent", DoubleValue (3.0));
YansWifiPhyHelper wifiPhyHelper = YansWifiPhyHelper::Default();
wifiPhyHelper.SetChannel (wifiChannel.Create ());
wifiPhyHelper.Set("ChannelNumber",UintegerValue(6));
wifiPhyHelper.Set("TxPowerStart", DoubleValue(m_txp)); //Minimum available transmission level (dbm)
wifiPhyHelper.Set("TxPowerEnd", DoubleValue(m_txp)); //Maximum available transmission level (dbm)
// Configure MAC layer
NqosWifiMacHelper wifiMacHelper = NqosWifiMacHelper::Default();
wifiMacHelper.SetType ("ns3::AdhocWifiMac"); // Set to adhoc mode
// Install WiFi on nodes
NetDeviceContainer wifiNetDevices = wifi.Install(wifiPhyHelper, wifiMacHelper, nodes);
PointToPointHelper p2ph;
p2ph.SetDeviceAttribute ("DataRate", StringValue ("25Mbps"));
p2ph.SetChannelAttribute ("Delay", StringValue ("50ms"));
NodeContainer nc;
NetDeviceContainer netDevC;
for (uint32_t i = 0; i < nodes.GetN() - 1; i++){
nc = NodeContainer (nodes.Get (i), gsNodes.Get (0));
netDevC = p2ph.Install (nc);
}
// P2P links between GS, GW, and RemoteHost (Producer)
Ptr<Node> remoteHost = remoteHostNodes.Get (0);
Ptr<Node> gw = gwNodes.Get (0);
Ptr<Node> gs = gsNodes.Get (0);
PointToPointHelper p2p;
p2p.SetDeviceAttribute ("DataRate", DataRateValue (DataRate ("100Gb/s")));
p2p.SetDeviceAttribute ("Mtu", UintegerValue (1500));
p2p.SetChannelAttribute ("Delay", TimeValue (Seconds (0.050)));
NetDeviceContainer baseDevices = p2p.Install (gw, remoteHost);
baseDevices = p2p.Install (gw, gs);
//
// Install NDN stack on nodes
//
ndn::StackHelper ndnHelper;
ndnHelper.SetOldContentStore("ns3::ndn::cs::Lru", "MaxSize", "1000");
ndnHelper.SetDefaultRoutes(true);
ndnHelper.InstallAll();
// Choosing forwarding strategy
ndn::StrategyChoiceHelper::InstallAll("/", "/localhost/nfd/strategy/multicast");
//
// Configure Nodes position
//
MobilityHelper mobility;
// Install Mobility Model in the UE
mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
"MinX", DoubleValue (0.0),
"MinY", DoubleValue (0.0),
"DeltaX", DoubleValue (gridSpace),
"DeltaY", DoubleValue (gridSpace),
"GridWidth", UintegerValue (7),
"LayoutType", StringValue ("RowFirst"));
mobility.Install(nodes);
// Install Mobility Model on the ground station
Ptr<ListPositionAllocator> gsPositionAlloc = CreateObject<ListPositionAllocator> ();
mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
gsPositionAlloc->Add (Vector(300.0, 300.0, 0.0));
mobility.SetPositionAllocator(gsPositionAlloc);
mobility.Install(gsNodes);
// Install Mobility Model on the gateway
Ptr<ListPositionAllocator> gwPositionAlloc = CreateObject<ListPositionAllocator> ();
mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
gwPositionAlloc->Add (Vector(300.0, 310.0, 0.0));
mobility.SetPositionAllocator(gwPositionAlloc);
mobility.Install(gwNodes);
// Install Mobility Model on the RemoteHost
Ptr<ListPositionAllocator> remHostPositionAlloc = CreateObject<ListPositionAllocator> ();
mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
remHostPositionAlloc->Add (Vector(300.0, 320.0, 0.0));
mobility.SetPositionAllocator(remHostPositionAlloc);
mobility.Install(remoteHostNodes);
//
// Install NDN applications
//
std::string ndnPrefix = "/ndn/prefix";
// Consumers
ndn::AppHelper consumerHelper("ns3::ndn::ConsumerZipfMandelbrot");
consumerHelper.SetAttribute("Frequency", StringValue("50")); // interests requests per second
consumerHelper.SetAttribute("NumberOfContents", StringValue ("40000"));
consumerHelper.SetPrefix(ndnPrefix);
for (uint32_t i = 0; i < nodes.GetN(); i++){
consumerHelper.Install(nodes.Get(i));
}
// Producer
ndn::AppHelper producerHelper("ns3::ndn::Producer");
producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
producerHelper.SetPrefix(ndnPrefix);
producerHelper.Install(remoteHost);
Simulator::Stop(Seconds(simTime));
// Tracers
ndn::AppDelayTracer::InstallAll("./scratch/app-delays-trace.txt");
//ndn::L3RateTracer::InstallAll("./scratch/consumerL3Trace.txt", Seconds(1.0));
Simulator::Run();
Simulator::Destroy();
return 0;
}
} // namespace ns3
int
main(int argc, char* argv[])
{
return ns3::main(argc, argv);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment