[ndnSIM] Topology construction!
Hwang In Chan
neogeoss1 at gmail.com
Wed Sep 14 06:43:53 PDT 2016
Dear All,
I am making a topology of a certain format in a wifi adhoc mode.
[image: 본문 이미지 1]
I am aiming to have a topology like this with NDN SIM.
I was trying to make it visible like the picture above.
In the beginning, I was making use of Grid Position allocator with mobility
class.
However, I soon realized that it is not going to help me.
So I used the manuel allocator mentioned in
https://www.nsnam.org/wiki/MobilityHelper#Manual_Allocation
But there is not much explanation. I am confused whether my approach works.
Do you know anything about position allocation in Wifi Adhoc mode?
#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;
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;
// }
void ReceivePacket (Ptr<Socket> socket)
{
while (socket->Recv ())
{
NS_LOG_UNCOND ("Received one packet!");
}
}
static void GenerateTraffic (Ptr<Socket> socket, uint32_t pktSize,
uint32_t pktCount, Time pktInterval )
{
if (pktCount > 0)
{
socket->Send (Create<Packet> (pktSize));
Simulator::Schedule (pktInterval, &GenerateTraffic,
socket, pktSize,pktCount-1, pktInterval);
}
else
{
socket->Close ();
}
}
int
main(int argc, char* argv[])
{
std::string phyMode ("DsssRate1Mbps");
double distance = 500; // m
uint32_t packetSize = 1000; // bytes
uint32_t numPackets = 1;
uint32_t numNodes = 25; // by default, 5x5
uint32_t sinkNode = 0;
uint32_t sourceNode = 24;
double interval = 1.0; // seconds
bool verbose = false;
bool tracing = false;
CommandLine cmd;
cmd.AddValue ("phyMode", "Wifi Phy mode", phyMode);
cmd.AddValue ("distance", "distance (m)", distance);
cmd.AddValue ("packetSize", "size of application packet sent",
packetSize);
cmd.AddValue ("numPackets", "number of packets generated", numPackets);
cmd.AddValue ("interval", "interval (seconds) between packets", interval);
cmd.AddValue ("verbose", "turn on all WifiNetDevice log components",
verbose);
cmd.AddValue ("tracing", "turn on ascii and pcap tracing", tracing);
cmd.AddValue ("numNodes", "number of nodes", numNodes);
cmd.AddValue ("sinkNode", "Receiver node number", sinkNode);
cmd.AddValue ("sourceNode", "Sender node number", sourceNode);
cmd.Parse (argc, argv);
// Convert to time object
Time interPacketInterval = Seconds (interval);
// disable fragmentation
Config::SetDefault("ns3::WifiRemoteStationManager::FragmentationThreshold",
StringValue("2200"));
Config::SetDefault("ns3::WifiRemoteStationManager::RtsCtsThreshold",
StringValue("2200"));
Config::SetDefault("ns3::WifiRemoteStationManager::NonUnicastMode",
StringValue("DsssRate1Mbps"));
//////////////////////
//////////////////////
//////////////////////
WifiHelper wifi = WifiHelper::Default();
// wifi.SetRemoteStationManager ("ns3::AarfWifiManager");
wifi.SetStandard(WIFI_PHY_STANDARD_80211a);
wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager", "DataMode",
StringValue("DsssRate1Mbps"));
YansWifiChannelHelper wifiChannel; // = YansWifiChannelHelper::Default ();
wifiChannel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel");
wifiChannel.AddPropagationLoss("ns3::FriisPropagationLossModel");
//wifiChannel.AddPropagationLoss("ns3::NakagamiPropagationLossModel");
// YansWifiPhy wifiPhy = YansWifiPhy::Default();
YansWifiPhyHelper wifiPhyHelper = YansWifiPhyHelper::Default();
wifiPhyHelper.Set ("RxGain", DoubleValue (-10) );
// ns-3 supports RadioTap and Prism tracing extensions for 802.11b
wifiPhyHelper.SetPcapDataLinkType
(YansWifiPhyHelper::DLT_IEEE802_11_RADIO);
wifiPhyHelper.SetChannel(wifiChannel.Create());
/*wifiPhyHelper.Set("TxPowerStart", DoubleValue(5));
wifiPhyHelper.Set("TxPowerEnd", DoubleValue(5));*/
NqosWifiMacHelper wifiMacHelper = NqosWifiMacHelper::Default();
wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
"DataMode",StringValue (phyMode),
"ControlMode",StringValue (phyMode));
wifiMacHelper.SetType("ns3::AdhocWifiMac");
/* Ptr<UniformRandomVariable> randomizer =
CreateObject<UniformRandomVariable>();
randomizer->SetAttribute("Min", DoubleValue(10));
randomizer->SetAttribute("Max", DoubleValue(100));*/
MobilityHelper mobility;
Ptr<ListPositionAllocator> initialAlloc =
CreateObject<ListPositionAllocator> ();
initialAlloc->Add(Vector(1, 1., 0.));
initialAlloc->Add(Vector(1, 3., 0.));
initialAlloc->Add(Vector(2, 2., 0.));
initialAlloc->Add(Vector(3, 2., 0.));
initialAlloc->Add(Vector(4, 2., 0.));
initialAlloc->Add(Vector(5, 1., 0.));
initialAlloc->Add(Vector(5, 2., 0.));
initialAlloc->Add(Vector(5, 3., 0.));
mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
mobility.SetPositionAllocator(initialAlloc);
NodeContainer nodes;
nodes.Create(8);
////////////////
// 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.SetOldContentStore("ns3::ndn::cs::Lru", "MaxSize", "1000");
ndnHelper.SetDefaultRoutes(true);
ndnHelper.Install(nodes);
// Set BestRoute strategy
ndn::StrategyChoiceHelper::Install(nodes, "/",
"/localhost/nfd/strategy/best-route");
ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
ndnGlobalRoutingHelper.InstallAll();
// 4. Set up applications
NS_LOG_INFO("Installing Applications");
std::string prefix = "/prefix";
ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
consumerHelper.SetPrefix(prefix);
consumerHelper.SetAttribute("Frequency", DoubleValue(100.0));
consumerHelper.Install(nodes.Get(0));
consumerHelper.Install(nodes.Get(1));
//consumerHelper.Install(nodes.Get());
/* consumerHelper.SetPrefix("/test/prefix1");
consumerHelper.SetAttribute("Frequency", DoubleValue(10.0));
consumerHelper.Install(nodes.Get(1));*/
ndn::AppHelper producerHelper("ns3::ndn::Producer");
producerHelper.SetPrefix(prefix);
producerHelper.SetAttribute("PayloadSize", StringValue("1200"));
producerHelper.Install(nodes.Get(5));
producerHelper.Install(nodes.Get(6));
producerHelper.Install(nodes.Get(7));
/*
producerHelper.SetPrefix("/");
producerHelper.SetAttribute("PayloadSize", StringValue("1200"));
producerHelper.Install(nodes.Get(2));*/
////////////////
ndnGlobalRoutingHelper.AddOrigins(prefix, nodes.Get(7));
ndnGlobalRoutingHelper.AddOrigins(prefix, nodes.Get(6));
ndnGlobalRoutingHelper.AddOrigins(prefix, nodes.Get(5));
// Calculate and install FIBs
ndn::GlobalRoutingHelper::CalculateRoutes();
wifiPhyHelper.EnablePcap ("ndn-simple-adhoc", wifiNetDevices);
Simulator::Stop(Seconds(30.0));
Simulator::Run();
Simulator::Destroy();
return 0;
}
} // namespace ns3
int
main(int argc, char* argv[])
{
return ns3::main(argc, argv);
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.lists.cs.ucla.edu/pipermail/ndnsim/attachments/20160914/92f2605e/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 15379 bytes
Desc: not available
URL: <http://www.lists.cs.ucla.edu/pipermail/ndnsim/attachments/20160914/92f2605e/attachment.png>
More information about the ndnSIM
mailing list