Advertisement
Guest User

ndn topo

a guest
Jan 21st, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.04 KB | None | 0 0
  1. #include "ns3/core-module.h"
  2. #include "ns3/network-module.h"
  3. #include "ns3/ndnSIM-module.h"
  4.  
  5.  
  6. namespace ns3 {
  7.  
  8. /**
  9. * This scenario simulates a grid topology (using topology reader module)
  10. *
  11. * /------\ /------\
  12. * | Src1 |<--+ +-->| Dst1 |
  13. * \------/ \ / \------/
  14. * \ /
  15. * +-->/------\ /------\<-+
  16. * | Rtr1 |<===============>| Rtr2 |
  17. * +-->\------/ \------/<-+
  18. * / \
  19. * /------\ / \ /------\
  20. * | Src2 |<--+ +-->| Dst2 |
  21. * \------/ \------/
  22. *
  23. *
  24. */
  25.  
  26. //Lifetime function
  27. void CacheEntryRemoved(std::string context, Ptr<const ndn::cs::Entry> entry, Time lifetime)
  28. {
  29. std::cout << entry->GetName() << " " << lifetime.ToDouble(Time::S) << "s" << std::endl;
  30. }
  31.  
  32.  
  33.  
  34. int main(int argc, char* argv[])
  35. {
  36. CommandLine cmd;
  37. cmd.Parse(argc, argv);
  38.  
  39. AnnotatedTopologyReader topologyReader("", 25);
  40. topologyReader.SetFileName("../ns-3/src/ndnSIM/examples/topologies/topo-6-node.txt");
  41. //topologyReader.SetFileName("/home/christos/ndn/scenario/extensions/topo6.txt");
  42. topologyReader.Read();
  43.  
  44. // Install NDN stack on all nodes
  45. ndn::StackHelper ndnHelper;
  46. //ndnHelper.SetOldContentStore("nfd:cs:lru", "MaxSize", "10000");
  47. ndnHelper.SetOldContentStore("ns3::ndn::cs::Stats::Fifo", "MaxSize", "50000");
  48. ndnHelper.InstallAll();
  49.  
  50. // connect (each node) to lifetime trace
  51. Config::Connect("/Nodelist/ns3::ndn::cs::Stats::Fifo/WillRemoveEntry", MakeCallback(CacheEntryRemoved));
  52.  
  53. // Choosing forwarding strategy
  54. ndn::StrategyChoiceHelper::InstallAll("/prefix", "/localhost/nfd/strategy/best-route");
  55.  
  56. // Installing global routing interface on all nodes
  57. ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
  58. ndnGlobalRoutingHelper.InstallAll();
  59.  
  60. // Getting containers for the consumer/producer
  61. Ptr<Node> consumer1 = Names::Find<Node>("Src1");
  62. Ptr<Node> consumer2 = Names::Find<Node>("Src2");
  63.  
  64. Ptr<Node> producer1 = Names::Find<Node>("Dst1");
  65. Ptr<Node> producer2 = Names::Find<Node>("Dst2");
  66.  
  67. ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
  68. consumerHelper.SetAttribute("Frequency", StringValue("32")); // 32 interests a second
  69.  
  70. // on the first consumer node install a Consumer application
  71. // that will express interests in /dst1 namespace
  72. consumerHelper.SetPrefix("/dst1");
  73. consumerHelper.Install(consumer1);
  74.  
  75. // on the second consumer node install a Consumer application
  76. // that will express interests in /dst2 namespace
  77. consumerHelper.SetPrefix("/dst2");
  78. consumerHelper.Install(consumer2);
  79.  
  80. ndn::AppHelper producerHelper("ns3::ndn::Producer");
  81. producerHelper.SetAttribute("PayloadSize", StringValue("320000"));
  82.  
  83. // Register /dst1 prefix with global routing controller and
  84. // install producer that will satisfy Interests in /dst1 namespace
  85. ndnGlobalRoutingHelper.AddOrigins("/dst1", producer1);
  86. producerHelper.SetPrefix("/dst1");
  87. producerHelper.Install(producer1);
  88.  
  89. // Register /dst2 prefix with global routing controller and
  90. // install producer that will satisfy Interests in /dst2 namespace
  91. ndnGlobalRoutingHelper.AddOrigins("/dst2", producer2);
  92. producerHelper.SetPrefix("/dst2");
  93. producerHelper.Install(producer2);
  94.  
  95. // Calculate and install FIBs
  96. ndn::GlobalRoutingHelper::CalculateRoutes();
  97.  
  98. Simulator::Stop(Seconds(20.0));
  99. //ndn::L3RateTracer::InstallAll("top_320.txt", Seconds(0.5));
  100. ndn::CsTracer::InstallAll("cs-trace320.txt", Seconds(0.5));
  101. // ndn::AppDelayTracer::InstallAll("delay320.txt");
  102. Simulator::Run();
  103. Simulator::Destroy();
  104.  
  105. return 0;
  106. }
  107.  
  108. } // namespace ns3
  109.  
  110. int
  111. main(int argc, char* argv[])
  112. {
  113. return ns3::main(argc, argv);
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement