示例#1
0
int
main(int argc, char* argv[])
{
  // Setting default parameters for PointToPoint links and channels
  Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("1Mbps"));
  Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms"));
  Config::SetDefault("ns3::QueueBase::MaxPackets", UintegerValue(10));

  // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
  CommandLine cmd;
  cmd.Parse(argc, argv);

  // Creating 3x3 topology
  PointToPointHelper p2p;
  PointToPointGridHelper grid(3, 3, p2p);
  grid.BoundingBox(100, 100, 200, 200);

  // Install NDN stack on all nodes
  ndn::StackHelper ndnHelper;
  ndnHelper.InstallAll();

  // Set BestRoute strategy
  ndn::StrategyChoiceHelper::InstallAll("/", "/localhost/nfd/strategy/best-route");

  // Installing global routing interface on all nodes
  ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
  ndnGlobalRoutingHelper.InstallAll();

  // Getting containers for the consumer/producer
  Ptr<Node> producer = grid.GetNode(2, 2);
  NodeContainer consumerNodes;
  consumerNodes.Add(grid.GetNode(0, 0));

  // Install NDN applications
  std::string prefix = "/prefix";

  ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
  consumerHelper.SetPrefix(prefix);
  consumerHelper.SetAttribute("Frequency", StringValue("100")); // 100 interests a second
  consumerHelper.Install(consumerNodes);

  ndn::AppHelper producerHelper("ns3::ndn::Producer");
  producerHelper.SetPrefix(prefix);
  producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
  producerHelper.Install(producer);

  // Add /prefix origins to ndn::GlobalRouter
  ndnGlobalRoutingHelper.AddOrigins(prefix, producer);

  // Calculate and install FIBs
  ndn::GlobalRoutingHelper::CalculateRoutes();

  Simulator::Stop(Seconds(20.0));

  Simulator::Run();
  Simulator::Destroy();

  return 0;
}
示例#2
0
int
main(int argc, char* argv[])
{
  CommandLine cmd;
  cmd.Parse(argc, argv);

  AnnotatedTopologyReader topologyReader("", 1);
  topologyReader.SetFileName("src/ndnSIM/examples/topologies/topo-tree.txt");
  topologyReader.Read();

  // Install NDN stack on all nodes
  ndn::StackHelper ndnHelper;
  ndnHelper.SetOldContentStore("ns3::ndn::cs::Lru", "MaxSize",
                               "100"); // default ContentStore parameters
  ndnHelper.InstallAll();

  // Choosing forwarding strategy
  ndn::StrategyChoiceHelper::InstallAll("/prefix", "/localhost/nfd/strategy/best-route");

  // Installing global routing interface on all nodes
  ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
  ndnGlobalRoutingHelper.InstallAll();

  // Getting containers for the consumer/producer
  Ptr<Node> consumers[4] = {Names::Find<Node>("leaf-1"), Names::Find<Node>("leaf-2"),
                            Names::Find<Node>("leaf-3"), Names::Find<Node>("leaf-4")};
  Ptr<Node> producer = Names::Find<Node>("root");

  for (int i = 0; i < 4; i++) {
    ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
    consumerHelper.SetAttribute("Frequency", StringValue("10")); // 100 interests a second

    // Each consumer will express the same data /root/<seq-no>
    consumerHelper.SetPrefix("/root");
    ApplicationContainer app = consumerHelper.Install(consumers[i]);
    app.Start(Seconds(0.01 * i));
  }

  ndn::AppHelper producerHelper("ns3::ndn::Producer");
  producerHelper.SetAttribute("PayloadSize", StringValue("1024"));

  // Register /root prefix with global routing controller and
  // install producer that will satisfy Interests in /root namespace
  ndnGlobalRoutingHelper.AddOrigins("/root", producer);
  producerHelper.SetPrefix("/root");
  producerHelper.Install(producer);

  // Calculate and install FIBs
  ndn::GlobalRoutingHelper::CalculateRoutes();

  Simulator::Stop(Seconds(20.0));

  ndn::CsTracer::InstallAll("cs-trace.txt", Seconds(1));

  Simulator::Run();
  Simulator::Destroy();

  return 0;
}
int
main(int argc, char* argv[])
{
  // setting default parameters for PointToPoint links and channels
  Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("1Mbps"));
  Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms"));
  Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("20"));

  // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
  CommandLine cmd;
  cmd.Parse(argc, argv);

  // Creating nodes
  NodeContainer nodes;
  nodes.Create(3);

  // Connecting nodes using two links
  PointToPointHelper p2p;
  p2p.Install(nodes.Get(0), nodes.Get(1));
  p2p.Install(nodes.Get(1), nodes.Get(2));

  // Install NDN stack on all nodes
  ndn::StackHelper ndnHelper;
  ndnHelper.SetDefaultRoutes(true);
  ndnHelper.SetOldContentStore(
    "ns3::ndn::cs::Freshness::Lru"); // don't set up max size here, will use default value = 100
  ndnHelper.InstallAll();

  // set up max sizes, after NDN stack is installed
  Config::Set("/NodeList/0/$ns3::ndn::ContentStore/MaxSize",
              UintegerValue(
                1)); // number after nodeList is global ID of the node (= node->GetId ())
  Config::Set("/NodeList/1/$ns3::ndn::ContentStore/MaxSize", UintegerValue(2));
  Config::Set("/NodeList/2/$ns3::ndn::ContentStore/MaxSize", UintegerValue(200));

  // Installing applications

  // Consumer
  ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
  // Consumer will request /prefix/0, /prefix/1, ...
  consumerHelper.SetPrefix("/prefix");
  consumerHelper.SetAttribute("Frequency", StringValue("10")); // 10 interests a second
  consumerHelper.Install(nodes.Get(0));                        // first node

  // Producer
  ndn::AppHelper producerHelper("ns3::ndn::Producer");
  // Producer will reply to all requests starting with /prefix
  producerHelper.SetPrefix("/prefix");
  producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
  producerHelper.Install(nodes.Get(2)); // last node

  Simulator::Stop(Seconds(20.0));

  Simulator::Run();
  Simulator::Destroy();

  return 0;
}
int
main(int argc, char* argv[])
{
  CommandLine cmd;
  cmd.Parse(argc, argv);

  AnnotatedTopologyReader topologyReader("", 1);
  topologyReader.SetFileName("src/ndnSIM/examples/topologies/topo-tree.txt");
  topologyReader.Read();

  // Install CCNx stack on all nodes
  ndn::StackHelper ndnHelper;
  ndnHelper.InstallAll();

  // Choosing forwarding strategy
  ndn::StrategyChoiceHelper::InstallAll("/prefix", "/localhost/nfd/strategy/best-route");

  // Installing global routing interface on all nodes
  ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
  ndnGlobalRoutingHelper.InstallAll();

  // Getting containers for the consumer/producer
  Ptr<Node> consumers[4] = {Names::Find<Node>("leaf-1"), Names::Find<Node>("leaf-2"),
                            Names::Find<Node>("leaf-3"), Names::Find<Node>("leaf-4")};
  Ptr<Node> producer = Names::Find<Node>("root");

  ndn::AppHelper consumerHelper("ns3::ndn::ConsumerBatches");
  consumerHelper.SetPrefix("/root");
  consumerHelper.SetAttribute("Batches", StringValue("1s 1 10s 1"));
  consumerHelper.Install(consumers[0]);

  consumerHelper.SetAttribute("Batches", StringValue("11s 1"));
  consumerHelper.Install(consumers[1]);

  consumerHelper.SetAttribute("Batches", StringValue("11s 1"));
  consumerHelper.Install(consumers[2]);

  ndn::AppHelper producerHelper("ns3::ndn::Producer");
  producerHelper.SetAttribute("PayloadSize", StringValue("1024"));

  // Register /root prefix with global routing controller and
  // install producer that will satisfy Interests in /root namespace
  ndnGlobalRoutingHelper.AddOrigins("/root", producer);
  producerHelper.SetPrefix("/root");
  producerHelper.Install(producer).Start(Seconds(9));

  // Calculate and install FIBs
  ndn::GlobalRoutingHelper::CalculateRoutes();

  Simulator::Stop(Seconds(20.0));

  ndn::AppDelayTracer::InstallAll("app-delays-trace.txt");

  Simulator::Run();
  Simulator::Destroy();

  return 0;
}
int
main(int argc, char* argv[])
{
  // setting default parameters for PointToPoint links and channels
  Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("1Mbps"));
  Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms"));
  Config::SetDefault("ns3::QueueBase::MaxPackets", UintegerValue(20));

  // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
  CommandLine cmd;
  cmd.Parse(argc, argv);

  // Creating nodes
  NodeContainer nodes;
  nodes.Create(3);

  // Connecting nodes using two links
  PointToPointHelper p2p;
  p2p.Install(nodes.Get(0), nodes.Get(1));
  p2p.Install(nodes.Get(1), nodes.Get(2));

  // Install NDN stack on all nodes
  ndn::StackHelper ndnHelper;
  ndnHelper.SetDefaultRoutes(true);
  ndnHelper.InstallAll();

  // Installing applications

  // Consumer
  ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
  // Consumer will request /prefix/0, /prefix/1, ...
  consumerHelper.SetPrefix("/prefix");
  consumerHelper.SetAttribute("Frequency", StringValue("10")); // 10 interests a second
  consumerHelper.Install(nodes.Get(0));                        // first node

  // Producer
  ndn::AppHelper producerHelper("ns3::ndn::Producer");
  // Producer will reply to all requests starting with /prefix
  producerHelper.SetPrefix("/prefix");
  producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
  producerHelper.SetAttribute("Signature", UintegerValue(100));
  producerHelper.SetAttribute("KeyLocator", StringValue("/unique/key/locator"));
  producerHelper.Install(nodes.Get(2)); // last node

  PcapWriter trace("ndn-simple-trace.pcap");
  Config::ConnectWithoutContext("/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/MacTx",
                                MakeCallback(&PcapWriter::TracePacket, &trace));

  Simulator::Stop(Seconds(20.0));

  Simulator::Run();
  Simulator::Destroy();

  return 0;
}
int
main(int argc, char *argv[])
{
  // setting default parameters for PointToPoint links and channels
  Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("1Mbps"));
  Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms"));
  Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("20"));

  // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
  CommandLine cmd;
  cmd.Parse(argc, argv);

  // Creating nodes
  NodeContainer nodes;
  nodes.Create(3);

  // Connecting nodes using two links
  PointToPointHelper p2p;
  p2p.Install(nodes.Get(0), nodes.Get(1));
  p2p.Install(nodes.Get(1), nodes.Get(2));

  // Install NDN stack on all nodes
  StackHelper ndnHelper;
  ndnHelper.InstallAll();

  // Installing global routing interface on all nodes
  ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
  ndnGlobalRoutingHelper.InstallAll();

  // Installing applications

  // Consumer
  ndn::AppHelper consumerHelper("PingClientApp");
  consumerHelper.SetAttribute("Prefix", StringValue("/ping"));
  consumerHelper.SetAttribute("nPings", StringValue("3"));
  consumerHelper.Install(nodes.Get(0)).Start(Seconds(2));

  // Producer
  ndn::AppHelper producerHelper("PingServerApp");
  producerHelper.SetAttribute("Prefix", StringValue("/ping"));
  producerHelper.SetAttribute("nMaxPings", StringValue("3"));
  producerHelper.Install(nodes.Get(2)).Start(Seconds(0.1));

  ndnGlobalRoutingHelper.AddOrigins("/ping", nodes.Get(2));

  // Calculate and install FIBs
  ndn::GlobalRoutingHelper::CalculateRoutes();

  Simulator::Stop(Seconds(20.0));

  Simulator::Run();
  Simulator::Destroy();

  return 0;
}
示例#7
0
int
main(int argc, char* argv[])
{
  // setting default parameters for PointToPoint links and channels
  Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("1Mbps"));
  Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms"));
  Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("20"));

  // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
  CommandLine cmd;
  cmd.Parse(argc, argv);

  // Creating nodes
  NodeContainer nodes;
  nodes.Create(3);

  // Connecting nodes using two links
  PointToPointHelper p2p;
  p2p.Install(nodes.Get(0), nodes.Get(1));
  p2p.Install(nodes.Get(1), nodes.Get(2));

  // Install NDN stack on all nodes
  ndn::StackHelper ndnHelper;
  ndnHelper.SetDefaultRoutes(true);
  ndnHelper.InstallAll();

  // Choosing forwarding strategy
  ndn::StrategyChoiceHelper::InstallAll("/prefix", "/localhost/nfd/strategy/multicast");

  // Installing applications

  // Consumer
  ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
  // Consumer will request /prefix/0, /prefix/1, ...
  consumerHelper.SetPrefix("/prefix");
  consumerHelper.SetAttribute("Frequency", StringValue("1")); // 10 interests a second
  consumerHelper.SetAttribute("MaxSeq",IntegerValue(5));
  consumerHelper.Install(nodes.Get(0));                        // first node

  // Producer
  ndn::AppHelper producerHelper("ns3::ndn::Producer");
  // Producer will reply to all requests starting with /prefix
  producerHelper.SetPrefix("/prefix");
  producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
  producerHelper.Install(nodes.Get(2)); // last node

  Simulator::Stop(Seconds(20.0));

  Simulator::Run();
  Simulator::Destroy();

  return 0;
}
int
main(int argc, char* argv[])
{
  CommandLine cmd;
  cmd.Parse(argc, argv);

  AnnotatedTopologyReader topologyReader("", 25);
  topologyReader.SetFileName("src/ndnSIM/examples/topologies/topo-grid-3x3-red-queues.txt");
  topologyReader.Read();

  // Install NDN stack on all nodes
  ndn::StackHelper ndnHelper;
  ndnHelper.InstallAll();

  ndn::StrategyChoiceHelper::InstallAll("/", "ndn:/localhost/nfd/strategy/best-route");

  // Installing global routing interface on all nodes
  ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
  ndnGlobalRoutingHelper.InstallAll();

  // Getting containers for the consumer/producer
  Ptr<Node> producer = Names::Find<Node>("Node8");
  NodeContainer consumerNodes;
  consumerNodes.Add(Names::Find<Node>("Node0"));

  // Install NDN applications
  std::string prefix = "/prefix";

  ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
  consumerHelper.SetPrefix(prefix);
  consumerHelper.SetAttribute("Frequency", StringValue("100")); // 100 interests a second
  consumerHelper.Install(consumerNodes);

  ndn::AppHelper producerHelper("ns3::ndn::Producer");
  producerHelper.SetPrefix(prefix);
  producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
  producerHelper.Install(producer);

  // Add /prefix origins to ndn::GlobalRouter
  ndnGlobalRoutingHelper.AddOrigins(prefix, producer);

  // Calculate and install FIBs
  ndn::GlobalRoutingHelper::CalculateRoutes();

  Simulator::Stop(Seconds(20.0));

  Simulator::Run();
  Simulator::Destroy();

  return 0;
}
示例#9
0
int
main(int argc, char* argv[])
{
  // LogComponentEnable("ndn.CbisGlobalRoutingHelper", LOG_LEVEL_INFO);
  // Setting default parameters for PointToPoint links and channels
  Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("1Mbps"));
  Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("1ms"));
  Config::SetDefault("ns3::QueueBase::MaxSize", StringValue("10p"));

  // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
  CommandLine cmd;
  cmd.Parse(argc, argv);

  // Creating 3x3 topology
  PointToPointHelper p2p;
  PointToPointGridHelper grid(3, 3, p2p);
  grid.BoundingBox(100, 100, 200, 200);

  // Install CCNx stack on all nodes
  ndn::StackHelper ndnHelper;
  // ndnHelper.SetForwardingStrategy ("ns3::ndn::fw::SmartFlooding");
  // ndnHelper.SetContentStore ("ns3::ndn::cs::Lru", "MaxSize", "10");
  ndnHelper.InstallAll();

  // Choosing forwarding strategy
  ndn::StrategyChoiceHelper::InstallAll("/prefix", "/localhost/nfd/strategy/ncc");

  // Installing global routing interface on all nodes
  // ndn::CbisGlobalRoutingHelper ndnGlobalRoutingHelper;
  ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
  ndnGlobalRoutingHelper.InstallAll();

  // Getting containers for the consumer/producer
  Ptr<Node> producer = grid.GetNode(2, 2);
  NodeContainer consumerNodes;
  consumerNodes.Add(grid.GetNode(0, 0));

  // Install CCNx applications
  std::string prefix = "/prefix";

  ndn::AppHelper consumerHelper("ns3::ndn::ConsumerZipfMandelbrot");
  // ndn::AppHelper consumerHelper ("ns3::ndn::ConsumerCbr");
  consumerHelper.SetPrefix(prefix);
  consumerHelper.SetAttribute("Frequency", StringValue("100"));        // 100 interests a second
  consumerHelper.SetAttribute("NumberOfContents", StringValue("100")); // 10 different contents
  // consumerHelper.SetAttribute ("Randomize", StringValue ("uniform")); // 100 interests a second
  consumerHelper.Install(consumerNodes);

  ndn::AppHelper producerHelper("ns3::ndn::Producer");
  producerHelper.SetPrefix(prefix);
  producerHelper.SetAttribute("PayloadSize", StringValue("100"));
  producerHelper.Install(producer);
  ndnGlobalRoutingHelper.AddOrigins(prefix, producer);

  // Calculate and install FIBs
  ndn::GlobalRoutingHelper::CalculateRoutes();

  Simulator::Stop(Seconds(1.0));

  Simulator::Run();
  Simulator::Destroy();

  return 0;
}
示例#10
0
int
main(int argc, char* argv[])
{
  std::string fof = "fof.txt";
  std::string dropFileName = "drops.txt";
  std::string topologyFile = "src/ndnSIM/examples/topologies/topo-tree.txt";
  std::string appDelayFile = "app-delays-trace.txt";
  std::string rateTraceFile = "rate-trace.txt";
  std::string percentage = "1.0";
  std::string frequency = "1";
  int simulationTime = 1000;

  CommandLine cmd;
  cmd.AddValue("fof", "forwarder overhead file", fof);
  cmd.AddValue("time", "simulation time argument", simulationTime);
  cmd.AddValue("top", "topology file", topologyFile);
  cmd.AddValue("drop", "bead drop file", dropFileName);
  cmd.AddValue("appd", "app delay file", appDelayFile);
  cmd.AddValue("rate", "rate trace file", rateTraceFile);
  cmd.AddValue("percentage", "bead percentage", percentage);
  cmd.AddValue("freq", "bead frequency", frequency);
  cmd.Parse(argc, argv);

  delayFile.open(fof);
  dropFile.open(dropFileName);

  AnnotatedTopologyReader topologyReader("", 1);
  topologyReader.SetFileName(topologyFile);
  topologyReader.Read();

  ndn::StackHelper ndnHelper;
  ndnHelper.InstallAll();

  // Getting containers for the consumer/producer
  Ptr<Node> consumers[4] = {Names::Find<Node>("leaf-1"), Names::Find<Node>("leaf-2"),
                            Names::Find<Node>("leaf-3"), Names::Find<Node>("leaf-4")};
  Ptr<Node> routers[2] = {Names::Find<Node>("rtr-1"), Names::Find<Node>("rtr-2")};
  // Ptr<Node> producers[2] = {Names::Find<Node>("root-1"), Names::Find<Node>("root-2")};
  Ptr<Node> producer = Names::Find<Node>("root-1");

  // Choosing forwarding strategy
  ndn::StrategyChoiceHelper::InstallAll("/root", "/localhost/nfd/strategy/best-route");

  // Installing global routing interface on all nodes
  ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
  ndnGlobalRoutingHelper.InstallAll();

  // Install NDN on routers
  ndn::StackHelper ndnHelperWithCache;
  ndnHelperWithCache.SetDefaultRoutes(true);
  ndnHelperWithCache.SetOldContentStore("ns3::ndn::cs::Freshness::Lru", "MaxSize", "0");
  ndnHelperWithCache.InstallCallback(routers[0], (size_t)&ForwardingDelay, 0);
  ndnHelperWithCache.InstallBeadDropCallback(routers[0], (size_t)&BeadDropCallback, 0);
  ndnHelperWithCache.SetUseHistory(routers[0], 100);
  ndnHelperWithCache.InstallCallback(routers[1], (size_t)&ForwardingDelay, 1);
  ndnHelperWithCache.InstallBeadDropCallback(routers[1], (size_t)&BeadDropCallback, 1);
  ndnHelperWithCache.SetUseHistory(routers[0], 100);


  ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
  // Consumer will request /prefix/0, /prefix/1, ...
  consumerHelper.SetPrefix("/root");
  consumerHelper.SetAttribute("Frequency", StringValue("10")); // 10 interests a second
  consumerHelper.Install(consumers[0]);
  consumerHelper.Install(consumers[1]);
  consumerHelper.Install(consumers[2]);

  ndn::AppHelper producerHelper("ns3::ndn::Producer");
  producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
  producerHelper.SetAttribute("Frequency", StringValue(frequency)); // 1 BEAD every second
  producerHelper.SetAttribute("Percentage", StringValue(percentage));

  // Register /root prefix with global routing controller and
  // install producer that will satisfy Interests in /root namespace
  ndnGlobalRoutingHelper.AddOrigins("/root", producer);
  producerHelper.SetPrefix("/root");
  producerHelper.Install(producer).Start(Seconds(0));
  producerHelper.Install(producer).Start(Seconds(0));
  ndnHelperWithCache.InstallCallback(producer, (size_t)&ForwardingDelay, 2);

  // ndnGlobalRoutingHelper.AddOrigins("/root/nonbead", producers[1]);
  // producerHelper.SetPrefix("/root/nonbead");
  // producerHelper.Install(producers[1]).Start(Seconds(9));

  // Calculate and install FIBs
  ndn::GlobalRoutingHelper::CalculateRoutes();

  Simulator::Stop(Seconds(simulationTime));

  ndn::AppDelayTracer::InstallAll(appDelayFile);
  ndn::L3RateTracer::InstallAll(rateTraceFile, Seconds(0.5));

  Simulator::Run();
  Simulator::Destroy();

  delayFile.flush();
  delayFile.close();

  dropFile.flush();
  dropFile.close();

  return 0;
}
int
main(int argc, char* argv[])
{
  // setting default parameters for PointToPoint links and channels
  Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("10Mbps"));
  Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms"));
  Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("20"));

  // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
  CommandLine cmd;
  cmd.Parse(argc, argv);

  // Creating nodes
  NodeContainer nodes;
  nodes.Create(3); // 3 nodes, connected: 0 <---> 1 <---> 2

  // Connecting nodes using two links
  PointToPointHelper p2p;
  p2p.Install(nodes.Get(0), nodes.Get(1));
  p2p.Install(nodes.Get(1), nodes.Get(2));

  // Install NDN stack on all nodes
  ndn::StackHelper ndnHelper;
  ndnHelper.SetDefaultRoutes(true);
  ndnHelper.setCsSize(0);
  ndnHelper.SetOldContentStore("ns3::ndn::cs::Lru", "MaxSize", "100");
  ndnHelper.InstallAll();

  // Choosing forwarding strategy
  ndn::StrategyChoiceHelper::InstallAll("/myprefix", "/localhost/nfd/strategy/best-route");

  ns3::ndn::AppHelper consumerHelper("ns3::ndn::FileConsumerCbr::MultimediaConsumer");
  consumerHelper.SetAttribute("AllowUpscale", BooleanValue(true));
  consumerHelper.SetAttribute("AllowDownscale", BooleanValue(false));
  consumerHelper.SetAttribute("ScreenWidth", UintegerValue(1920));
  consumerHelper.SetAttribute("ScreenHeight", UintegerValue(1080));
  consumerHelper.SetAttribute("StartRepresentationId", StringValue("auto"));
  consumerHelper.SetAttribute("MaxBufferedSeconds", UintegerValue(30));
  consumerHelper.SetAttribute("StartUpDelay", StringValue("0.1"));

  consumerHelper.SetAttribute("AdaptationLogic", StringValue("dash::player::RateAndBufferBasedAdaptationLogic"));
  consumerHelper.SetAttribute("MpdFileToRequest", StringValue(std::string("/myprefix/AVC/BBB-2s.mpd" )));

  //consumerHelper.SetPrefix (std::string("/Server_" + boost::lexical_cast<std::string>(i%server.size ()) + "/layer0"));
  ApplicationContainer app1 = consumerHelper.Install (nodes.Get(2));

  // Producer responsible for hosting the MPD file
  ndn::AppHelper mpdProducerHelper("ns3::ndn::FileServer");

  // Producer will reply to all requests starting with /myprefix/AVC/ and hosts the mpd file there
  mpdProducerHelper.SetPrefix("/myprefix");
  mpdProducerHelper.SetAttribute("ContentDirectory", StringValue("/home/someuser/multimediaData"));
  mpdProducerHelper.Install(nodes.Get(0)); // install to some node from nodelist

  // Producer responsible for hosting the virtual segments
  ndn::AppHelper fakeSegmentProducerHelper("ns3::ndn::FakeFileServer");

  // Producer will reply to all requests starting with /myprefix/AVC/BBB/ and hosts the virtual segment files there
  fakeSegmentProducerHelper.SetPrefix("/myprefix/AVC/BBB");
  fakeSegmentProducerHelper.SetAttribute("MetaDataFile", StringValue("dash_dataset_avc_bbb.csv"));
  fakeSegmentProducerHelper.Install(nodes.Get(0)); // install to some node from nodelist

  ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
  ndnGlobalRoutingHelper.InstallAll();

  ndnGlobalRoutingHelper.AddOrigins("/myprefix", nodes.Get(0));
  ndn::GlobalRoutingHelper::CalculateRoutes();

  Simulator::Stop(Seconds(1000.0));

  Simulator::Run();
  Simulator::Destroy();

  NS_LOG_UNCOND("Simulation Finished.");

  return 0;
}
示例#12
0
int
main(int argc, char* argv[])
{
  // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
  CommandLine cmd;
  cmd.Parse(argc, argv);

  AnnotatedTopologyReader topologyReader("", 1);
  topologyReader.SetFileName("src/ndnSIM/examples/topologies/Geant2012.txt");
  topologyReader.Read();
//  topologyReader.ApplySettings();
  topologyReader.SaveGraphviz("src/ndnSIM/examples/topologies/GeantGraph.dot");


    // Install NDN stack on all nodes
    ndn::StackHelper ndnHelper;
    ndnHelper.disableRibManager();
    //ndnHelper.disableFaceManager();
    ndnHelper.InstallAll();

    // Choosing forwarding strategy
    ndn::StrategyChoiceHelper::InstallAll("/cs-www.bu.edu/", "/localhost/nfd/strategy/multicast");
    // Choosing forwarding strategy for content adverts
    ndn::StrategyChoiceHelper::InstallAll("/ContentAdVert/", "/localhost/nfd/strategy/multicast");

    // Installing applications

    // Consumer
    ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");

    std:: string path= "/home/ali/GitHub/Datasets/test/firstDir/URLs/";
    ifstream inFile(path + "URLs.con2.cs18.800051214");
    string line;
    if (inFile.is_open())
    {
      //NS_LOG_UNCOND ("salam!");
      while(getline (inFile,line))
        {
          consumerHelper.SetPrefix(line);
          //NS_LOG_UNCOND ("file line = "<<line);

          consumerHelper.SetAttribute("Frequency", StringValue("1")); // 1 interests a second
          //i put first only greece as a consumer
          consumerHelper.Install(Names::Find<Node>("id15")).Start (Seconds(0.005));
        }
    }

    inFile.close();



    // Producer
    ndn::AppHelper producerHelper("ns3::ndn::Producer");
    // Producer will reply to all requests starting with /videos/myvideos/video1
    producerHelper.SetPrefix("/cs-www.bu.edu/");
    producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
    //I put first NO as the only producer
    producerHelper.Install(Names::Find<Node>("id35")).Start (Seconds(0.0));

    //install advertiser app on the server
    consumerHelper.SetPrefix ("/ContentAdVert/cs-www.bu.edu/");
    consumerHelper.SetAttribute("Frequency", StringValue("0.2")); // 1 advert per 5 second
    consumerHelper.Install(Names::Find<Node>("id35")).Start (Seconds(0.0));

  // Getting containers for the consumer/producer
/*  Ptr<Node> consumers[4] = {Names::Find<Node>("id0"), Names::Find<Node>("id1"),
                            Names::Find<Node>("id2"), Names::Find<Node>("id3")};
  Ptr<Node> producers[4] = {Names::Find<Node>("id36"), Names::Find<Node>("id37"),
                            Names::Find<Node>("id38"), Names::Find<Node>("id39")};

  if (consumers[0] == 0 || consumers[1] == 0 || consumers[2] == 0 || consumers[3] == 0
      || producers[0] == 0 || producers[1] == 0 || producers[2] == 0 || producers[3] == 0) {
    NS_FATAL_ERROR("Error in topology: one nodes c1, c2, c3, c4, p1, p2, p3, or p4 is missing");
  }

  for (int i = 0; i < 4; i++) {
    std::string prefix = "/data/" + Names::FindName(producers[i]);

    /////////////////////////////////////////////////////////////////////////////////
    // install consumer app on consumer node c_i to request data from producer p_i //
    /////////////////////////////////////////////////////////////////////////////////

    ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
    consumerHelper.SetAttribute("Frequency", StringValue("10")); // 100 interests a second

    consumerHelper.SetPrefix(prefix);
    ApplicationContainer consumer = consumerHelper.Install(consumers[i]);
    consumer.Start(Seconds(i));     // start consumers at 0s, 1s, 2s, 3s
    consumer.Stop(Seconds(19 - i)); // stop consumers at 19s, 18s, 17s, 16s

    ///////////////////////////////////////////////
    // install producer app on producer node p_i //
    ///////////////////////////////////////////////

    ndn::AppHelper producerHelper("ns3::ndn::Producer");
    producerHelper.SetAttribute("PayloadSize", StringValue("1024"));

    // install producer that will satisfy Interests in /dst1 namespace
    producerHelper.SetPrefix(prefix);
    ApplicationContainer producer = producerHelper.Install(producers[i]);
    // when Start/Stop time is not specified, the application is running throughout the simulation
  }

  // Manually configure FIB routes
  ndn::FibHelper::AddRoute("id0", "/data", "n1", 1); // link to n1
  ndn::FibHelper::AddRoute("id1", "/data", "n1", 1); // link to n1
  ndn::FibHelper::AddRoute("id2", "/data", "n1", 1); // link to n1
  ndn::FibHelper::AddRoute("id3", "/data", "n1", 1); // link to n1

  ndn::FibHelper::AddRoute("n1", "/data", "n2", 1);  // link to n2
  ndn::FibHelper::AddRoute("n1", "/data", "n12", 2); // link to n12

  ndn::FibHelper::AddRoute("n12", "/data", "n2", 1); // link to n2

  ndn::FibHelper::AddRoute("n2", "/data/p1", "id36", 1); // link to p1
  ndn::FibHelper::AddRoute("n2", "/data/p2", "id37", 1); // link to p2
  ndn::FibHelper::AddRoute("n2", "/data/p3", "id38", 1); // link to p3
  ndn::FibHelper::AddRoute("n2", "/data/p4", "id39", 1); // link to p4
*/
  // Schedule simulation time and run the simulation
  Simulator::Stop(Seconds(20.0));
  Simulator::Run();
  Simulator::Destroy();

  return 0;
}
int
main(int argc, char* argv[])
{
  // setting default parameters for PointToPoint links and channels
  Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("10Mbps"));
  Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("1ms"));
  Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("100"));

  uint64_t catalogCardinality = 0;          // Estimated Content Catalog Cardinality.
  double cacheToCatalogRatio = 0.01;        // Cache to Catalog Ratio per each node.
  uint32_t lambda = 1;                      // Request rate per each client.
  double alpha = 1;                         // Zipf's Exponent
  double plateau = 0;                       // q parameter for the ZipfMandelbrot distribution
  std::string simType = "";                 // Simulation Type Description
  uint32_t simDuration = 100;
  uint32_t numReqTot = 10000;               // Total number of requests inside the simulation.

  // Read optional command-line parameters
  CommandLine cmd;
  cmd.AddValue ("catalogCardinality", "Estimated Content Catalog Cardinality.", catalogCardinality);
  cmd.AddValue ("cacheToCatalogRatio", "Cache to Catalog Ratio per each node.", cacheToCatalogRatio);
  cmd.AddValue ("lambda", "Request rate per each client.", lambda);
  cmd.AddValue ("alpha", "Zipf's Exponent", alpha);
  cmd.AddValue ("plateau", "q parameter for the ZipfMandelbrot distribution", plateau);
  cmd.AddValue ("simType", "Simulation Type Description", simType);
  cmd.AddValue ("simDuration", "Length of the simulation, in seconds.", simDuration);
  cmd.AddValue ("numReqTot", "Total number of requests during the simulation", numReqTot);

  cmd.Parse (argc, argv);

  std::string catalogCardinalityStr, lambdaStr, alphaStr, plateauStr,reqStr;
  std::stringstream ss;
  ss << catalogCardinality;
  catalogCardinalityStr = ss.str();
  ss.str("");
  ss << lambda;
  lambdaStr = ss.str();
  ss.str("");
  ss << alpha;
  alphaStr = ss.str();
  ss.str("");
  ss << plateau;
  plateauStr = ss.str();
  ss.str("");
  ss << numReqTot;
  reqStr = ss.str();
  ss.str("");


  // **********   Getting the simulation run   **********
  uint64_t simRun = SeedManager::GetRun();
  uint64_t simRunOut = simRun - 1;
  std::string simRunStr;
  ss << simRun;
  simRunStr = ss.str();
  ss.str("");

  //NS_LOG_UNCOND("M=" << catalogCardinality << "\nC=" << cacheToCatalogRatio << "\nL=" << lambda
  //     << "\nT=" << simType << "\nA=" << alpha << "\nR=" << simRun);


  // **********   Calculate the Cache Size per each cache   ***********
  uint32_t cacheSize = round((double)catalogCardinality * cacheToCatalogRatio);
  ss << cacheSize;
  std::string cacheSizeStr = ss.str();
  ss.str("");

  // Creating nodes
  NodeContainer nodes;
  //nodes.Create(3);
  nodes.Create(1);

  // Connecting nodes using two links
  //PointToPointHelper p2p;
  //p2p.Install(nodes.Get(0), nodes.Get(1));
  //p2p.Install(nodes.Get(1), nodes.Get(2));

  // Install NDN stack on all nodes
  ndn::StackHelper ndnHelper;
  ndnHelper.SetDefaultRoutes(true);
  //ndnHelper.InstallAll();

  //ndnHelper.SetOldContentStore("ns3::ndn::cs::Nocache");
  //ndnHelper.Install(nodes.Get(0)); // Consumer
  //ndnHelper.Install(nodes.Get(2)); // Producer

  ndnHelper.SetOldContentStore("ns3::ndn::cs::Lru", "MaxSize", cacheSizeStr);
  //ndnHelper.Install(nodes.Get(1)); // Router
  ndnHelper.Install(nodes.Get(0)); // Router

  // Choosing forwarding strategy
  ndn::StrategyChoiceHelper::InstallAll("/prefix", "/localhost/nfd/strategy/broadcast");

  // Installing applications

  // Consumer
  ndn::AppHelper consumerHelper("ns3::ndn::ConsumerZipfMandelbrot");
  // Consumer will request /prefix/0, /prefix/1, ...
  consumerHelper.SetPrefix("/prefix");
  consumerHelper.SetAttribute ("Frequency", StringValue(lambdaStr)); // lambda Interest per second
  consumerHelper.SetAttribute ("NumberOfContents", StringValue (catalogCardinalityStr));
  consumerHelper.SetAttribute ("Randomize", StringValue ("exponential"));
  consumerHelper.SetAttribute ("q", StringValue (plateauStr)); // q paremeter
  consumerHelper.SetAttribute ("s", StringValue (alphaStr)); // Zipf's exponent
  
  consumerHelper.Install(nodes.Get(0));                        // first node

  // Producer
  ndn::AppHelper producerHelper("ns3::ndn::Producer");
  // Producer will reply to all requests starting with /prefix
  producerHelper.SetPrefix("/prefix");
  producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
  //producerHelper.Install(nodes.Get(2)); // last node
  producerHelper.Install(nodes.Get(0)); // last node

  Simulator::Stop (Seconds (simDuration));

  Simulator::Run();
  Simulator::Destroy();

  return 0;
}
int
main(int argc, char* argv[])
{
  // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
  CommandLine cmd;
  cmd.Parse(argc, argv);

  NS_LOG_UNCOND("NUMBER OF NODES = "<<ns3::N_NODES<<" , nConsumers = "<<ns3::N_TotalClients<<" , nProducers = "<<ns3::N_PRODUCERS);

  double l = 0;
  double s = ns3::N_GEANT_ROUTERS-1;
  Ptr<UniformRandomVariable> uniVar;
  uniVar=CreateObject<UniformRandomVariable> ();
  uniVar->SetAttribute ("Min", DoubleValue (l));
  uniVar->SetAttribute ("Max", DoubleValue (s));

  // setting default parameters for PointToPoint links and channels
  //this is for 56 clients to be attached
  Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue(ns3::CONS_LINK_DATA_RATE));
  Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue(ns3::CONS_LINK_DELAY));
  Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("20"));
  /////////////////////////////////////////////////////////////////////////
  //***IDs 0-55 are consumers, the next "N_PRODUCERS" IDs are producers, //
  //***and the IDs after them are Geant routers                          //
  /////////////////////////////////////////////////////////////////////////
  NodeContainer nodes;
  nodes.Create(ns3::N_TotalClients + ns3::N_PRODUCERS);
  PointToPointHelper p2p;

  //let's first read the Geant topology
  AnnotatedTopologyReader topologyReader("", 1);
  topologyReader.SetFileName("/home/ali/ndnSIM/ns-3/src/ndnSIM/examples/topologies/Geant2012.txt");
  topologyReader.Read();
  //  topologyReader.ApplySettings();
  topologyReader.SaveGraphviz("src/ndnSIM/examples/topologies/GeantGraph.dot");

   RandomizeConsumers (uniVar, "/home/ali/ndnSIM/ns-3/src/ndnSIM/examples/topologies/Geant2012.txt",
                         topologyReader ,nodes, p2p);
  RandomizeProducers(uniVar, "/home/ali/GitHub/Datasets/test/fifty/producers/server_dataset/large_scale/", nodes, p2p);

  MyResultApp resApp;
  resApp.InstallEndpointApp(nodes);
  resApp.InstallRouterApp(topologyReader);

    // Install NDN stack on all nodes
    ndn::StackHelper ndnHelper;
    ndnHelper.disableRibManager();
    //ndnHelper.disableFaceManager();


    //set cache store size
    ndnHelper.setCsSize(ns3::CACHE_SIZE);
    ndnHelper.InstallAll();

    ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
    ndnGlobalRoutingHelper.Install(nodes);
    for (size_t i = 0; i < ns3::N_PRODUCERS; i++) {
      ifstream inFile ((SERVERS_DATASETS_PATH + "server_dataset_"+std::to_string(i)).c_str());
      if(inFile.is_open()){
        std::string line;
        while (getline(inFile, line)){
          ndnGlobalRoutingHelper.AddOrigins (line, nodes.Get (i+ns3::N_TotalClients));
        }
      }
      else{
        NS_LOG_UNCOND("ERROR!!! UNABLE TO OPEN FILE "<<inFile);
      }

    }
    ndn::GlobalRoutingHelper::CalculateRoutes();


    // Choosing forwarding strategy for all
    ndn::StrategyChoiceHelper::InstallAll("/", "/localhost/nfd/strategy/best-route");


    // Installing applications

    ////////////////////////////////////////////////////////////////
    //from 5 file logs, i assign to five consumer each ONE file//
    ///////////////////////////////////////////////////////////////


    NS_LOG_UNCOND("now we've 56 clients attached to some of routers (randomly chosen) and "<<ns3::N_PRODUCERS<<" producers");

    ndn::AppHelper consumerHelper("ns3::ndn::ConsumerZipfMandelbrot");

    consumerHelper.SetAttribute("Frequency", StringValue(ns3::CONSUMER_FREQ));
    consumerHelper.SetAttribute("NumberOfContents", UintegerValue(CONTENT_UNIVERSE));
  //  consumerHelper.SetAttribute("MaxSeq",IntegerValue(MAX_SEQ_NUMBER));
    consumerHelper.SetAttribute("Randomize", StringValue(RANDOMIZE_ATTRIBUTE));
    consumerHelper.SetAttribute("q", DoubleValue(Q));
    consumerHelper.SetAttribute("s", DoubleValue(S));

  //  std:: string consumerPath= "/home/ali/GitHub/Datasets/test/fifty/producers/server_dataset/5F-5C-3P/content_universe_165";

      for(size_t consIndex=0; consIndex<ns3::N_TotalClients;consIndex++){
              consumerHelper.SetPrefix("/");
              consumerHelper.Install(nodes.Get(consIndex))
              .Start (Seconds(CONS_START + uniVar->GetValue(0.0, 0.01)));
      }//for

  // Schedule simulation time and run the simulation
  Simulator::Stop(Seconds(ns3::SIMULATION_TIME));

	ndn::L3RateTracer::InstallAll("rate-trace.txt", Seconds(1.0));
	L2RateTracer::InstallAll("drop-trace.txt", Seconds(0.5));
	//ndn::CsTracer::InstallAll("cs-trace.txt", Seconds(1));
	ndn::AppDelayTracer::InstallAll("app-delays-trace.txt");

  Simulator::Run();

  uint64_t m_totalForwardedInterest=0;
  uint64_t m_totalInterestOverhead=0;
  uint64_t m_totalForwardedData=0;
  uint64_t m_totalDataOverhead=0;
  uint64_t m_totalUnsatisfiedInterests=0;
  uint64_t m_totalSatisfiedInterests=0;
  uint64_t m_totalRetrievedDataAtClients=0;


  ofstream spUnsatisfiedInterestsFile;
  spUnsatisfiedInterestsFile.open("/home/ali/Documents/BFRresults/unsatisfied_Interests/spUnsatisfiedInterestsFile_"+std::to_string(ns3::S)+"_FP = "+std::to_string(ns3::FPP));


  ofstream SPDataOverheadFile;
  SPDataOverheadFile.open("/home/ali/Documents/BFRresults/overhead_files/SPDataOverheadFile_"+std::to_string(ns3::S));
  ofstream SPInterestOverheadFile;
  SPInterestOverheadFile.open("/home/ali/Documents//BFRresults/overhead_files/SPInterestOverheadFile_"+std::to_string(ns3::S)+"_FP = "+std::to_string(ns3::FPP));

  SPDataOverheadFile<<"nodeID"<<"     "<<"lastDataFwd"<<"     "
                  <<"nDataFwd"<<"     "<<"dataOverhead"<<"\n";

  SPInterestOverheadFile<<"nodeID"<<"     "<<"lastInterestFwd"<<"     "
                  <<"nInterestFwd"<<"     "<<"interestOverhead"<<"\n";

  spUnsatisfiedInterestsFile<<"consumerID"<<"     	"<<"NumberOfUnsatisfiedInterests"<<"     	"<<"NumberOfSatisfiedInterests"<<"\n";


  //let's extract results from nodes' apps
  Ptr<MyResultApp> nodeApp;
  for (NodeList::Iterator node = NodeList::Begin(); node != NodeList::End(); node++) {
    nodeApp = CreateObject<ns3::MyResultApp> ();
    if ((*node)->GetId()>=ns3::N_TotalClients && (*node)->GetId()<=ns3::N_TotalClients+ns3::N_PRODUCERS-1){
      nodeApp = (*node)->GetApplication(1)->GetObject<ns3::MyResultApp>();
    }
    else{
      nodeApp = (*node)->GetApplication(0)->GetObject<ns3::MyResultApp>();
    }

    spUnsatisfiedInterestsFile<<(*node)->GetId()<<"     	"<<nodeApp->m_myNumberOfUnsatisfiedInterests<<"     	"<<nodeApp->m_myNumberOfSatisfiedInterests<<"\n";

    if((*node)->GetId()<ns3::N_TotalClients){
      m_totalUnsatisfiedInterests+= nodeApp->m_myNumberOfUnsatisfiedInterests;
      m_totalSatisfiedInterests+= nodeApp->m_myNumberOfSatisfiedInterests;
      m_totalRetrievedDataAtClients+= nodeApp->m_myNumberOfRetrievedData;
    }

    if((*node)->GetId()>=ns3::N_TotalClients){
      SPDataOverheadFile<<nodeApp->GetNode()->GetId()<<"    "<<nodeApp->m_myLastDataForwardTime
	                    <<"     "<<nodeApp->m_nMyForwardedData<<"     "
	                    <<nodeApp->m_myTotalDataOverhead<<"\n";
      m_totalForwardedData += nodeApp->m_nMyForwardedData;
      m_totalDataOverhead += nodeApp->m_myTotalDataOverhead;

    }
    if((*node)->GetId()<=ns3::N_TotalClients-1 || (*node)->GetId()>=ns3::N_TotalClients+ns3::N_PRODUCERS){
      SPInterestOverheadFile<<nodeApp->GetNode()->GetId()<<"    "<<nodeApp->m_myLastInterestForwardTime
	                    <<"     "<<nodeApp->m_nMyForwardedInterest<<"     "
	                    <<nodeApp->m_myTotalInterestOverhead<<"\n";
      m_totalForwardedInterest += nodeApp->m_nMyForwardedInterest;
      m_totalInterestOverhead += nodeApp->m_myTotalInterestOverhead;
    }
  }//for

  //let's write the totals also in interest file:
  SPInterestOverheadFile<<"nTotalForwardedInterest = "<<m_totalForwardedInterest<<"\n";
  SPInterestOverheadFile<<"totalInterestOverhead = "<<m_totalInterestOverhead<<"\n";

  SPInterestOverheadFile<<"nTotalForwardedData = "<<m_totalForwardedData<<"\n";
  SPInterestOverheadFile<<"totalDataOverhead = "<<m_totalDataOverhead<<"\n";
  SPInterestOverheadFile<<"Normalized overhead over interest count = "
                         <<double(m_totalInterestOverhead+m_totalDataOverhead)/(double)m_totalForwardedInterest<<"\n";
  SPInterestOverheadFile<<"Normalized overhead over data count = "
                        <<double(m_totalInterestOverhead+m_totalDataOverhead)/(double)m_totalForwardedData;

  spUnsatisfiedInterestsFile<<"total number of unsatisfied Interests at all the consumers = "<<m_totalUnsatisfiedInterests<<"\n";
  spUnsatisfiedInterestsFile<<"total number of satisfied Interests at all the consumers = "<<m_totalSatisfiedInterests<<"\n";
  spUnsatisfiedInterestsFile<<"Unsatisfaction due to link failure or false positive (METHOD a) = "<<(double)m_totalUnsatisfiedInterests/(m_totalSatisfiedInterests+m_totalUnsatisfiedInterests)<<"\n";
  spUnsatisfiedInterestsFile<<"total number of retrieved data at consumers =  "<<m_totalRetrievedDataAtClients;

  SPInterestOverheadFile.close();
  SPDataOverheadFile.close();
  spUnsatisfiedInterestsFile.close();


  Simulator::Destroy();

  //std::string hitDistanceCompleteFile = "/home/ali/ndnSIM/ns-3/HitDistanceFile"
  //CreateHitDistanceDataset (hitDistanceCompleteFile);

  return 0;
}//ns3::main
/**
 * This scenario simulates a one-node two-custom-app scenario:
 *
 *   +------+ <-----> (CustomApp)
 *   | Node |
 *   +------+ <-----> (Hijacker)
 *
 *     NS_LOG=CustomApp ./waf --run=ndn-custom-apps
 */
int
main(int argc, char* argv[])
{
  // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
  CommandLine cmd;
  cmd.Parse(argc, argv);

  AnnotatedTopologyReader topologyReader("", 1);
//  topologyReader.SetFileName("src/ndnSIM/examples/topologies/topo-custom1.txt");
//  topologyReader.SetFileName("src/ndnSIM/examples/topologies/topo-custom2.txt");
 // topologyReader.SetFileName("src/ndnSIM/examples/topologies/topo-custom3.txt");
//  topologyReader.SetFileName("src/ndnSIM/examples/topologies/topo-project.txt");
  std::cout << "Reading topology file";
  topologyReader.SetFileName("src/ndnSIM/examples/topologies/topo-project_400clients.txt");
  topologyReader.Read();
  
  std::cout << "Adding clients in vector";
  vector<Ptr<Node>> clients;
  for(int i = 1; i <= 400; i++) {
    std::string cli = "client" + std::to_string(i);
    clients.push_back(Names::Find<Node>(cli));    
  }

  std::cout << "Adding Cache servers in vector";
  vector<Ptr<Node>> cacheServers;
  for(int i = 1; i <= 7; i++) {
    std::string cs = "cache" + std::to_string(i);
    cacheServers.push_back(Names::Find<Node>(cs));    
  }
  
  // Creating nodes
//  Ptr<Node> node = CreateObject<Node>();
  // Install Content Store stack on cache node
  ndn::StackHelper ndnHelperCache;
//  ndnHelperCache.SetOldContentStore("ns3::ndn::cs::Lru", "MaxSize", "2");
  //ndnHelperCache.SetOldContentStore("ns3::ndn::cs::Nocache");
//  ndnHelperCache.SetOldContentStore("ns3::ndn::cs::ProbCacheExt::Lru", "MaxSize", "2");
  ndnHelperCache.setCsSize(2); 
  for(int i = 0; i < (int)cacheServers.size(); i++) {
    ndnHelperCache.Install(cacheServers[i]);
  } 

  // Install NDN stack on all nodes
/*  ndn::StackHelper ndnHelper;
  ndnHelper.SetDefaultRoutes(true);
  ndnHelper.InstallAll();*/

// Install NDN stack on rest of the nodes
  ndn::StackHelper ndnHelper;
  for(int i = 0; i < (int)clients.size(); i++) {
    ndnHelper.Install(clients[i]);
  }
//  ndnHelper.Install(Names::Find<Node>("client2"));
//  ndnHelper.Install(Names::Find<Node>("client3"));
  ndnHelper.Install(Names::Find<Node>("originServer"));


// Choosing forwarding strategy
  ndn::StrategyChoiceHelper::InstallAll("/prefix", "/localhost/nfd/strategy/best-route");

//  Ptr<Node> consumers1 = Names::Find<Node>("client1");
//  Ptr<Node> consumers2 = Names::Find<Node>("client2");
//  Ptr<Node> consumers3 = Names::Find<Node>("client3");
//  Ptr<Node> consumers[3] = {Names::Find<Node>("client1"), Names::Find<Node>("client2"), Names::Find<Node>("client3")};
  Ptr<Node> producer = Names::Find<Node>("originServer");

  cout << "Installing Global routing interface on all nodes";

// Installing global routing interface on all nodes
  ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
  ndnGlobalRoutingHelper.InstallAll();

  cout << " Creating app1....";
  // App1
  /*ndn::AppHelper app1("CustomApp");
  app1.SetPrefix("/root");
  app1.Install(consumers1);
  app1.Install(consumers2);
  app1.Install(consumers3);*/
  
//  std::string content[] = {"alpha", "beta", "gamma", "delta", "epsilon"};

//  const int nrolls=100000;  // number of experiments
//  const int nstars=100;    // maximum number of stars to distribute

  std::default_random_engine generator;
  std::lognormal_distribution<double> distribution(0.0,1.0);

  //int p[100]={};

/*  for (int i=0; i<nrolls; ++i) {
    double number = distribution(generator);
    if ((number>=0.0)&&(number<10.0)) ++p[int(number)];
  }*/

  int j = 0;
/*  int alphaCount = 1;
  int betaCount = 2;
  int gammaCount = 3;
  int deltaCount = 4;
  int epsilonCount = 10;  */
  for (int k = 0; k < 1; k++) {
    for (int i = 0; i < 200; i++) {
      for(int l = 0; l < 2; l++) {
      j = int(distribution(generator));
     // j = p[i]*nstars/nrolls;
     //   std::cout << "i: " << i;
      ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
      consumerHelper.SetAttribute("Frequency", StringValue("1")); 
      consumerHelper.SetAttribute("Content", IntegerValue(j)); 
      int temp = 0;
      if(l == 0) {
        temp = i;
      } else {
        temp = i + 200;
      }
      consumerHelper.SetPrefix("/root/" + Names::FindName(clients[temp]));
      ns3::ApplicationContainer ac = consumerHelper.Install(clients[temp]);
      ac.Start(Seconds (double(k * 1000 + ( (i * 10) + 1))));
      ac.Stop(Seconds (double(k * 1000 + ( (i * 10) + 2))));
      }
    /*  if((j % 5) == 0) {
        if(alphaCount == 0) {
          alphaCount++;
        } else {
          alphaCount--;
        }
        j++;
      } else if ((j % 5) == 1) {
        if(betaCount >= 1) {
          betaCount--;
        } else {
          betaCount = 2;
          j++;
        }
      } else if ((j % 5) == 2) {
        if(gammaCount >= 1) {
          gammaCount--;
        } else {
          gammaCount = 3;
          j++;
        }
      } else if ((j % 5) == 3) {
        if(deltaCount >= 1) {
          deltaCount--;
        } else {
          deltaCount = 4;
          j++;
        }
      } else if ((j % 5) == 4) {
        if(epsilonCount >= 1) {
          epsilonCount--;
        } else {
          epsilonCount = 10;
          j++;
        }
      } */  
    }
  }
    
/*    ndn::AppHelper consumerHelper2("ns3::ndn::ConsumerCbr");
    consumerHelper2.SetAttribute("Frequency", StringValue("1")); 
    consumerHelper2.SetPrefix("/root/" + Names::FindName(consumers[1]));
//    consumerHelper.Install(consumers[i]);
    //consumerHelper2.Install(consumers[1]).Start(Seconds (2.0));
    ns3::ApplicationContainer ac2 = consumerHelper2.Install(consumers[1]);
    ac2.Start(Seconds (2.0));
    ac2.Stop(Seconds (3.0));
    //consumerHelper2.Install(consumers[0]).Stop(Seconds (3.0));
    
    ndn::AppHelper consumerHelper3("ns3::ndn::ConsumerCbr");
    consumerHelper3.SetAttribute("Frequency", StringValue("1")); 
    consumerHelper3.SetPrefix("/root/" + Names::FindName(consumers[2]));
//    consumerHelper.Install(consumers[i]);
    //consumerHelper3.Install(consumers[2]).Start(Seconds (3.0));
    ns3::ApplicationContainer ac3 = consumerHelper3.Install(consumers[2]);
    ac3.Start(Seconds (3.0));
    ac3.Stop(Seconds (4.0)); */
    //consumerHelper3.Install(consumers[0]).Stop(Seconds (4.0));

  // App2
  //ndn::AppHelper app2("Hijacker");
  //app2.Install(producer); // last node

  cout << " Creating Producer";

  ndn::AppHelper producerHelper("ns3::ndn::Producer");
  // Producer will reply to all requests starting with /prefix
  producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
  producerHelper.SetAttribute("Freshness", TimeValue (Seconds (2.0)));
  ndnGlobalRoutingHelper.AddOrigins("/root", producer);
  producerHelper.SetPrefix("/root");
  producerHelper.Install(producer);

  // Calculate and install FIBs
  ndn::GlobalRoutingHelper::CalculateRoutes();

  Simulator::Stop(Seconds(2004.0));
//  Simulator::Stop(Seconds(9993.0));

  Simulator::Run();
  Simulator::Destroy();

  return 0;
}
示例#16
0
int
main(int argc, char* argv[])
{

  AnnotatedTopologyReader topologyReader("", 1);
  topologyReader.SetFileName("src/ndnSIM/examples/topologies/Geant2012.txt");
  topologyReader.Read();
  
  // setting default parameters for PointToPoint links and channels
  Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("1Mbps"));
  Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms"));
  Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("20"));

  // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
  CommandLine cmd;
  cmd.Parse(argc, argv);

  // Creating nodes
  NodeContainer nodes;
  size_t nNode=3;
  nodes.Create(nNode);

  // Connecting nodes using two links
  PointToPointHelper p2p;
  p2p.Install(nodes.Get(0), nodes.Get(1));
  p2p.Install(nodes.Get(1), nodes.Get(2));

  // Install NDN stack on all nodes
  ndn::StackHelper ndnHelper;
  //ndnHelper.SetDefaultRoutes(true);
  ndnHelper.disableRibManager();
  //ndnHelper.disableFaceManager();
  ndnHelper.InstallAll();



  // Choosing forwarding strategy
  ndn::StrategyChoiceHelper::InstallAll("/cs-www.bu.edu/", "/localhost/nfd/strategy/multicast");

  // Installing applications

  // Consumer
  ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");


  ifstream inFile("URLs.con2.cs18.800051214");
  string line;
  if (inFile.is_open())
  {
    //NS_LOG_UNCOND ("salam!");
    while(getline (inFile,line))
      {
        consumerHelper.SetPrefix(line);
        //NS_LOG_UNCOND ("file line = "<<line);

        consumerHelper.SetAttribute("Frequency", StringValue("1")); // 1 interests a second
        consumerHelper.Install(nodes.Get(0)).Start (Seconds(2));
      }
  }

  inFile.close();



  // Producer
  ndn::AppHelper producerHelper("ns3::ndn::Producer");
  // Producer will reply to all requests starting with /videos/myvideos/video1
  producerHelper.SetPrefix("/cs-www.bu.edu/");
  producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
  producerHelper.Install(nodes.Get(2)).Start (Seconds(0.0)); // last node


  // Choosing forwarding strategy for content adverts
  ndn::StrategyChoiceHelper::InstallAll("/ContentAdVert/", "/localhost/nfd/strategy/multicast");


  //install advertiser app on the server
  consumerHelper.SetPrefix ("/ContentAdVert/cs-www.bu.edu/");
  consumerHelper.SetAttribute("Frequency", StringValue("0.2")); // 1 advert per 5 second
  consumerHelper.Install(nodes.Get(2)).Start (Seconds(0.0));

  Simulator::Stop(Seconds(10.0));

  Simulator::Run();
  Simulator::Destroy();

  return 0;
}
示例#17
0
int
main(int argc, char* argv[])
{
  // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
  CommandLine cmd;
  cmd.Parse(argc, argv);

  AnnotatedTopologyReader topologyReader("", 1);
  topologyReader.SetFileName("src/ndnSIM/examples/topologies/Geant2012.txt");
  topologyReader.Read();
//  topologyReader.ApplySettings();
  topologyReader.SaveGraphviz("src/ndnSIM/examples/topologies/GeantGraph.dot");


    // Install NDN stack on all nodes
    ndn::StackHelper ndnHelper;
    ndnHelper.disableRibManager();
    //ndnHelper.disableFaceManager();
    ndnHelper.InstallAll();

    // Choosing forwarding strategy for all
    ndn::StrategyChoiceHelper::InstallAll("/", "/localhost/nfd/strategy/multicast");

    // Installing applications

    ////////////////////////////////////////////////////////////////
    //from 5 file logs, i assign to five consumer each ONE file//
    ///////////////////////////////////////////////////////////////
    size_t nConsumers = 5;
    // Consumer (DE-4, DK-2, CH-8, NL-0, CZ-5)
    std::string consArray[] ={"id4", "id2", "id8", "id0", "id5"} ;

    NS_LOG_UNCOND ("The "<<nConsumers<<" consumers are: ");
    for (size_t i = 0; i < nConsumers; i++) {
      NS_LOG_UNCOND (consArray[i]);
    }

    // Producers (FI-37, ES-25, GR-15)
    size_t nProducers = 3;
    string prodArray[] = {"id37", "id25", "id15"};

      NS_LOG_UNCOND ("The "<<nProducers<<" producers are: ");
      for (size_t i = 0; i < nProducers; i++) {
        NS_LOG_UNCOND (prodArray[i]);
      }


    ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");

    std:: string consumerPath= "/home/ali/GitHub/Datasets/test/fifty/consumers/5F-5C-3P/";

    size_t consIndex=0;
    size_t fileCounter=0;
    DIR *dir;
    struct dirent *ent;

    //This is to avoid collision !
    double l = 0;
    double s = 0.01;
    Ptr<UniformRandomVariable> uniVar;
    uniVar=CreateObject<UniformRandomVariable> ();
    uniVar->SetAttribute ("Min", DoubleValue (l));
    uniVar->SetAttribute ("Max", DoubleValue (s));

    if ((dir = opendir (consumerPath.c_str())) != NULL) {
          /* Go read each of files in this directory */
          const char* invalidFileName1 = ".";
          const char* invalidFileName2 = "..";
          while ((ent = readdir (dir)) != NULL) {
            if (ent->d_name != invalidFileName1 && ent->d_name != invalidFileName2){

              //avoid . and ..
              std::string str1 = ent->d_name;
              if (str1[0]!='U'){
                continue;
              }

              std::string path = consumerPath + ent->d_name;
              //NS_LOG_UNCOND("path.c_str() = "<<path.c_str());
              ifstream inFile(path.c_str());
              NS_LOG_UNCOND ("for node "<<consArray[consIndex]<<", inFile is "<< path.c_str());
                string line;
                if (inFile.is_open())
                {
                    //NS_LOG_UNCOND ("salam!");
                    while(getline (inFile,line))
                      {
                        consumerHelper.SetPrefix(line);
                        //NS_LOG_UNCOND ("file line = "<<line);

                        consumerHelper.SetAttribute("Frequency", StringValue("1")); // 1 interests per five second

                        //we care about collision!
                        consumerHelper.Install(Names::Find<Node>(consArray[consIndex])).Start (Seconds(consStart + uniVar->GetValue(0.0, 0.01)));
                      }//while
                  inFile.close();
                  consIndex++;
                  ++fileCounter;
                  if(fileCounter==5){
                    break;
                  }
                }
                else{
                  NS_LOG_UNCOND("UNABLE TO OPEN FILE "<<ent->d_name);
                }
            }

          }//Dirent while
      }//dirent

    // Producers (FI-37, ES-25, GR-15)
    std:: string producerPath= "/home/ali/GitHub/Datasets/test/fifty/producers/server_dataset/5F-5C-3P/";
    ndn::AppHelper producerHelper("ns3::ndn::Producer");
    // Producer will reply to all requests starting with /videos/myvideos/video1
    producerHelper.SetPrefix("/");
    producerHelper.SetAttribute("PayloadSize", StringValue("1024"));

    producerHelper.Install(Names::Find<Node>(prodArray[0])).Start (Seconds(prodStart));
    producerHelper.Install(Names::Find<Node>(prodArray[1])).Start (Seconds(prodStart));
    producerHelper.Install(Names::Find<Node>(prodArray[2])).Start (Seconds(prodStart));


    //install advertiser app on the server
    consumerHelper.SetAttribute("Frequency", StringValue("0.2")); // 1 advert per 5 second

    consumerHelper.SetPrefix ("/ContentAdVert/FE");
    consumerHelper.Install(Names::Find<Node>(prodArray[0])).Start (Seconds(advertStart));


    consumerHelper.SetPrefix ("/ContentAdVert/ES");
    consumerHelper.Install(Names::Find<Node>(prodArray[1])).Start (Seconds(advertStart + uniVar->GetValue(0.0, 0.001)));

    consumerHelper.SetPrefix ("/ContentAdVert/GR");
    consumerHelper.Install(Names::Find<Node>(prodArray[2])).Start (Seconds(advertStart + uniVar->GetValue(0.0, 0.001)));


  // Schedule simulation time and run the simulation
  Simulator::Stop(Seconds(simulationTime));
  Simulator::Run();
  Simulator::Destroy();

  return 0;
}//ns3::main
int
main(int argc, char* argv[])
{
  // setting default parameters for PointToPoint links and channels
  Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("1Mbps"));
  Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms"));
  Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("20"));

  // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
  CommandLine cmd;
  cmd.Parse(argc, argv);

  // Creating nodes
  NodeContainer nodes;
  nodes.Create(5); // 5 nodes (3 clients), connected like this: {0,1,2} <---> 3 <---> 4

  // Connecting nodes using two links
  PointToPointHelper p2p;
  p2p.Install(nodes.Get(0), nodes.Get(3));
  p2p.Install(nodes.Get(1), nodes.Get(3));
  p2p.Install(nodes.Get(2), nodes.Get(3));

  p2p.Install(nodes.Get(3), nodes.Get(4));

  // Install NDN stack on all nodes
  ndn::StackHelper ndnHelper;
  ndnHelper.SetDefaultRoutes(true);
  ndnHelper.InstallAll();

  // Choosing forwarding strategy
  ndn::StrategyChoiceHelper::InstallAll("/myprefix", "/localhost/nfd/strategy/best-route");

  // Consumer
  ndn::AppHelper consumerHelper("ns3::ndn::FileConsumerCbr");
  
  consumerHelper.SetAttribute("FileToRequest", StringValue("/myprefix/file1.img"));
  consumerHelper.Install(nodes.Get(0));

  consumerHelper.SetAttribute("FileToRequest", StringValue("/myprefix/file2.img"));
  consumerHelper.Install(nodes.Get(1));

  consumerHelper.SetAttribute("FileToRequest", StringValue("/myprefix/file3.img"));
  consumerHelper.Install(nodes.Get(2));

  // Connect Tracers
  Config::ConnectWithoutContext("/NodeList/*/ApplicationList/*/FileDownloadFinished",
                               MakeCallback(&FileDownloadedTrace));
  Config::ConnectWithoutContext("/NodeList/*/ApplicationList/*/ManifestReceived",
                               MakeCallback(&FileDownloadedManifestTrace));
  Config::ConnectWithoutContext("/NodeList/*/ApplicationList/*/FileDownloadStarted",
                               MakeCallback(&FileDownloadStartedTrace));

  // Producer
  ndn::AppHelper producerHelper("ns3::ndn::FakeFileServer");

  // Producer will reply to all requests starting with /prefix
  producerHelper.SetPrefix("/myprefix");
  producerHelper.SetAttribute("MetaDataFile", StringValue("fake.csv"));
  producerHelper.Install(nodes.Get(4)); // install to some node from nodelist

  ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
  ndnGlobalRoutingHelper.InstallAll();

  ndnGlobalRoutingHelper.AddOrigins("/myprefix", nodes.Get(4));
  ndn::GlobalRoutingHelper::CalculateRoutes();

  ndn::AppDelayTracer::InstallAll("app-delays-trace.txt");

  ndn::FileConsumerLogTracer::InstallAll("file-consumer-log-trace.txt");

  Simulator::Stop(Seconds(600.0));

  Simulator::Run();
  Simulator::Destroy();

  NS_LOG_UNCOND("Simulation Finished.");

  return 0;
}
int
main(int argc, char* argv[])
{
  // setting default parameters for PointToPoint links and channels
  Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("10Mbps"));
  Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms"));
  Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("20"));

  // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
  CommandLine cmd;
  cmd.Parse(argc, argv);

  // Creating nodes
  NodeContainer nodes;
  nodes.Create(3); // 3 nodes, connected: 0 <---> 1 <---> 2

  // Connecting nodes using two links
  PointToPointHelper p2p;
  p2p.Install(nodes.Get(0), nodes.Get(1));
  p2p.Install(nodes.Get(1), nodes.Get(2));

  // Install NDN stack on all nodes
  ndn::StackHelper ndnHelper;
  ndnHelper.SetDefaultRoutes(true);
  ndnHelper.setCsSize(0);
  ndnHelper.SetOldContentStore("ns3::ndn::cs::Lru", "MaxSize", "100");
  ndnHelper.InstallAll();

  // Choosing forwarding strategy
  ndn::StrategyChoiceHelper::InstallAll("/myprefix", "/localhost/nfd/strategy/best-route");

  ns3::ndn::AppHelper consumerHelper("ns3::ndn::FileConsumerCbr::MultimediaConsumer");
  consumerHelper.SetAttribute("AllowUpscale", BooleanValue(true));
  consumerHelper.SetAttribute("AllowDownscale", BooleanValue(false));
  consumerHelper.SetAttribute("ScreenWidth", UintegerValue(1920));
  consumerHelper.SetAttribute("ScreenHeight", UintegerValue(1080));
  consumerHelper.SetAttribute("StartRepresentationId", StringValue("auto"));
  consumerHelper.SetAttribute("MaxBufferedSeconds", UintegerValue(30));
  consumerHelper.SetAttribute("StartUpDelay", StringValue("0.1"));

  consumerHelper.SetAttribute("AdaptationLogic", StringValue("dash::player::RateAndBufferBasedAdaptationLogic"));
  consumerHelper.SetAttribute("MpdFileToRequest", StringValue(std::string("/myprefix/FakeVid1/vid1.mpd" )));

  //consumerHelper.SetPrefix (std::string("/Server_" + boost::lexical_cast<std::string>(i%server.size ()) + "/layer0"));
  ApplicationContainer app1 = consumerHelper.Install (nodes.Get(2));

  ndn::AppHelper fakeDASHProducerHelper("ns3::ndn::FakeMultimediaServer");

  // This fake multimedia producer will reply to all requests starting with /myprefix/FakeVid1
  fakeDASHProducerHelper.SetPrefix("/myprefix/FakeVid1");
  fakeDASHProducerHelper.SetAttribute("MetaDataFile", StringValue("representations/netflix_vid1.csv"));
  // We just give the MPD file a name that makes it unique
  fakeDASHProducerHelper.SetAttribute("MPDFileName", StringValue("vid1.mpd"));

  fakeDASHProducerHelper.Install(nodes.Get(0));

  // We can install more then one fake multimedia producer on one node:

  // This fake multimedia producer will reply to all requests starting with /myprefix/FakeVid2
  fakeDASHProducerHelper.SetPrefix("/myprefix/FakeVid2");
  fakeDASHProducerHelper.SetAttribute("MetaDataFile", StringValue("representations/netflix_vid2.csv"));
  // We just give the MPD file a name that makes it unique
  fakeDASHProducerHelper.SetAttribute("MPDFileName", StringValue("vid2.mpd"));


  // This fake multimedia producer will reply to all requests starting with /myprefix/FakeVid3
  fakeDASHProducerHelper.SetPrefix("/myprefix/FakeVid3");
  fakeDASHProducerHelper.SetAttribute("MetaDataFile", StringValue("representations/netflix_vid3.csv"));
  // We just give the MPD file a name that makes it unique
  fakeDASHProducerHelper.SetAttribute("MPDFileName", StringValue("vid3.mpd"));

  ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
  ndnGlobalRoutingHelper.InstallAll();

  ndnGlobalRoutingHelper.AddOrigins("/myprefix", nodes.Get(0));
  ndn::GlobalRoutingHelper::CalculateRoutes();

  Simulator::Stop(Seconds(60.0));

  Simulator::Run();
  Simulator::Destroy();

  NS_LOG_UNCOND("Simulation Finished.");

  return 0;
}
int
main(int argc, char* argv[])
{
  // setting default parameters for Wifi
  // enable rts cts all the time.
  Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("0"));
  // disable fragmentation
  Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200"));
  Config::SetDefault("ns3::WifiRemoteStationManager::NonUnicastMode",
                     StringValue("OfdmRate24Mbps"));

  // setting default parameters for PointToPoint links and channels
  Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("1Mbps"));
  Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms"));
  Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("20"));


  std::uint32_t max_routers = 1;
  std::string cSize = "100";
  std::string cSplit = "75";

  // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
  CommandLine cmd;
  cmd.AddValue("cSize", "Cache Size", cSize);
  cmd.AddValue("cSplit", "Cache Split", cSplit);
  cmd.AddValue("routers", "number of routers", max_routers);
  cmd.Parse(argc, argv);


  Packet::EnablePrinting ();

  // Wifi config

  WifiHelper wifi = WifiHelper::Default ();


  // Nodes
  NodeContainer sta_consumers;
  NodeContainer sta_mobile_consumers;
  NodeContainer ap;
  NodeContainer routers;
  NodeContainer producers;

  // ??
  NetDeviceContainer staDevs;
  PacketSocketHelper packetSocket;

  // 5 stationary consumers, 5 mobile, 4 APs and 1 router
  sta_consumers.Create(3*max_routers);
  sta_mobile_consumers.Create(7*max_routers);
  ap.Create (5*max_routers);
  routers.Create(max_routers);
  producers.Create(1);

  // give packet socket powers to nodes.
  packetSocket.Install(sta_mobile_consumers);
  packetSocket.Install(sta_consumers);
  packetSocket.Install (ap);

  // Wifi Config
  NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
  YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
  wifiPhy.SetChannel (wifiChannel.Create ());
  wifiPhy.Set("TxPowerStart", DoubleValue(5));
  wifiPhy.Set("TxPowerEnd", DoubleValue(5));
  Ssid ssid = Ssid ("wifi-default");
  wifi.SetRemoteStationManager ("ns3::ArfWifiManager");
  // setup stas.
  wifiMac.SetType ("ns3::StaWifiMac",
                   "Ssid", SsidValue (ssid),
                   "ActiveProbing", BooleanValue (false));
  // install wifi
  wifi.Install(wifiPhy, wifiMac, sta_mobile_consumers);
  wifi.Install(wifiPhy, wifiMac, sta_consumers);
  // setup ap.
  wifiMac.SetType ("ns3::ApWifiMac",
                   "Ssid", SsidValue (ssid));
  wifi.Install (wifiPhy, wifiMac, ap);


  // Mobility config -- Change max_routers value to change size of sim
  int number_rows = sqrt(max_routers);
  int x = 0;
  int y = 0;
  int pos_counter = 0;
  Ptr<UniformRandomVariable> randomizerX = CreateObject<UniformRandomVariable>();
  Ptr<UniformRandomVariable> randomizerY = CreateObject<UniformRandomVariable>();

  MobilityHelper stationary_mobility;
  stationary_mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");

  MobilityHelper mobility;
  mobility.SetMobilityModel("ns3::GaussMarkovMobilityModel", "Bounds", BoxValue(Box (0, number_rows*10, 0, number_rows*10, 0, 0)), 
	  "TimeStep", TimeValue(Seconds(1)));

  // Place router in center of box
  randomizerX->SetAttribute("Min", DoubleValue(5));
  randomizerX->SetAttribute("Max", DoubleValue(5));
  randomizerY->SetAttribute("Min", DoubleValue(5));
  randomizerY->SetAttribute("Max", DoubleValue(5));
  stationary_mobility.SetPositionAllocator("ns3::RandomBoxPositionAllocator", "X", PointerValue(randomizerX),
	  "Y", PointerValue(randomizerY));

  // Install on routers
  stationary_mobility.Install(producers.Get(0));

  // p2p helper
  PointToPointHelper p2p;
  // for each row
  for (int i=0; i < number_rows; i++)
  {
	  x = i * 10 + 5;
	  // for each column
	  for (int j=0; j < number_rows; j++)
	  {
		  y = j * 10 + 5;

		  // Place router in center of box
		  randomizerX->SetAttribute("Min", DoubleValue(x));
		  randomizerX->SetAttribute("Max", DoubleValue(x));
		  randomizerY->SetAttribute("Min", DoubleValue(y));
		  randomizerY->SetAttribute("Max", DoubleValue(y));
		  stationary_mobility.SetPositionAllocator("ns3::RandomBoxPositionAllocator", "X", PointerValue(randomizerX),
			  "Y", PointerValue(randomizerY));

		  // Install on routers
		  stationary_mobility.Install(routers.Get(pos_counter));

		  // Set box (center +/-5)
		  randomizerX->SetAttribute("Min", DoubleValue(x-5));
		  randomizerX->SetAttribute("Max", DoubleValue(x+5));
		  randomizerY->SetAttribute("Min", DoubleValue(y-5));
		  randomizerY->SetAttribute("Max", DoubleValue(y+5));
		  // Connect router to previous if not 1
		  if (pos_counter == 0)
		  {
			  p2p.Install(routers.Get(0), producers.Get(0));
		  }
		  else  // Otherwise connect to router behind you
		  {
			  p2p.Install(routers.Get(pos_counter), routers.Get(pos_counter-1));
		  }
		  // APs
		  for (int k=0; k < 5; k++)
		  {
			  stationary_mobility.SetPositionAllocator("ns3::RandomBoxPositionAllocator", "X", PointerValue(randomizerX),
				  "Y", PointerValue(randomizerY));
			  stationary_mobility.Install(ap.Get(pos_counter * 5 + k));
			  p2p.Install(routers.Get(pos_counter), ap.Get(pos_counter * 5 + k));

		  }

		  // Consumers (stationary)
		  for (int l=0; l < 3; l++)
		  {
			  stationary_mobility.SetPositionAllocator("ns3::RandomBoxPositionAllocator", "X", PointerValue(randomizerX),
				  "Y", PointerValue(randomizerY));
			  stationary_mobility.Install(sta_consumers.Get(pos_counter * 3 + l));
		  }

		  // Consumers (Mobile)
		  for (int m=0; m < 7; m++)
		  {
			  mobility.SetPositionAllocator("ns3::RandomBoxPositionAllocator", "X", PointerValue(randomizerX),
				  "Y", PointerValue(randomizerY));
			  mobility.Install(sta_mobile_consumers.Get(pos_counter * 7 + m));
		  }
	  // Keep track of overall position
	  pos_counter++;
	  }
  }
  // Install NDN stack on all nodes
  ndn::StackHelper ndnHelper;
  ndnHelper.SetDefaultRoutes(true);
  
  ndnHelper.SetOldContentStore("ns3::ndn::cs::Splitcache",
							   "NormalPolicy", "ns3::ndn::cs::Lru", 
							   "SpecialPolicy", "ns3::ndn::cs::Lfu", 
							   "TotalCacheSize", cSize, 
							   "Configure", cSplit); 
  //                       Percentage Special^
  
  //ndnHelper.SetOldContentStore("ns3::ndn::cs::Lru");

  ndnHelper.Install(ap);
  ndnHelper.Install(routers);
  ndnHelper.SetOldContentStore("ns3::ndn::cs::Nocache");
  ndnHelper.Install(sta_consumers);
  ndnHelper.Install(sta_mobile_consumers);
  ndnHelper.Install(producers);

  // Choosing forwarding strategy
  ndn::StrategyChoiceHelper::Install(sta_consumers, "/", "/localhost/nfd/strategy/best-route");
  ndn::StrategyChoiceHelper::Install(sta_mobile_consumers, "/", "/localhost/nfd/strategy/best-route");
  ndn::StrategyChoiceHelper::Install(ap, "/", "/localhost/nfd/strategy/best-route");
  ndn::StrategyChoiceHelper::Install(routers, "/", "/localhost/nfd/strategy/best-route");
  ndn::StrategyChoiceHelper::Install(producers, "/", "/localhost/nfd/strategy/best-route");

  // Installing applications

  // Consumer (basic and special data)
  ndn::AppHelper consumerHelper("ns3::ndn::ConsumerZipfMandelbrot");
  consumerHelper.SetAttribute("NumberOfContents", StringValue("100")); // 10 different contents
  // Consumer will request /prefix/0, /prefix/1, ...

  // Basic consumers request basic data (and pumpkin spice coffee)
  consumerHelper.SetPrefix("data/basic");
  consumerHelper.SetAttribute("Frequency", StringValue("10")); // 1 interests a second
  consumerHelper.Install(sta_consumers);   

  // Mobile consumers request special data only
  consumerHelper.SetPrefix("data/special");
  consumerHelper.SetAttribute("Frequency", StringValue("10")); //  2 interests a second
  consumerHelper.Install(sta_mobile_consumers);



  // Producer
  ndn::AppHelper producerHelper("ns3::ndn::Producer");
  // Producer will reply to all requests starting with /prefix
  producerHelper.SetPrefix("/data");
  producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
  producerHelper.SetAttribute("Freshness", TimeValue(Seconds(-1.0))); // unlimited freshness
  producerHelper.Install(producers); 

  // Tracers 'n stuff
  //AthstatsHelper athstats;
  //athstats.EnableAthstats("athstats-sta", sta_mobile_consumers);
  //athstats.EnableAthstats("athstats-sta", sta_consumers);
  //athstats.EnableAthstats ("athstats-ap", ap);

  ndn::AppDelayTracer::Install(sta_consumers, "app-delays-trace-stationary-03.txt");
  ndn::AppDelayTracer::Install(sta_mobile_consumers, "app-delays-trace-mobile-03.txt");
  ndn::CsTracer::Install(ap, "cs-trace-ap-03.txt", Seconds(1));
  ndn::CsTracer::Install(routers, "cs-trace-routers-03.txt", Seconds(1));

  // 10 min
  Simulator::Stop(Seconds(600.0));

  Simulator::Run();
  Simulator::Destroy();

  return 0;
}