Spyridon Mastorakis | 41fbfe1 | 2014-11-24 23:26:09 -0800 | [diff] [blame^] | 1 | // ndn-multiple-strategies.cc |
| 2 | #include "ns3/core-module.h" |
| 3 | #include "ns3/network-module.h" |
| 4 | #include "ns3/point-to-point-module.h" |
| 5 | #include "ns3/point-to-point-layout-module.h" |
| 6 | #include "ns3/ndnSIM-module.h" |
| 7 | |
| 8 | using namespace ns3; |
| 9 | using ns3::ndn::StackHelper; |
| 10 | using ns3::ndn::AppHelper; |
| 11 | using ns3::ndn::GlobalRoutingHelper; |
| 12 | using ns3::ndn::StrategyChoiceHelper; |
| 13 | ; |
| 14 | |
| 15 | /** |
| 16 | * This scenario simulates a grid topology (using PointToPointGrid module) |
| 17 | * |
| 18 | * The first six nodes use the best route forwarding strategy, whereas |
| 19 | * the three remaining nodes use the broadcast forwarding strategy. |
| 20 | * |
| 21 | * (consumer) -- ( ) ----- ( ) |
| 22 | * | | | |
| 23 | * ( ) ------ ( ) ----- ( ) |
| 24 | * | | | |
| 25 | * ( ) ------ ( ) -- (producer) |
| 26 | * |
| 27 | * All links are 1Mbps with propagation 10ms delay. |
| 28 | * |
| 29 | * FIB is populated using NdnGlobalRoutingHelper. |
| 30 | * |
| 31 | * Consumer requests data from producer with frequency 100 interests per second |
| 32 | * (interests contain constantly increasing sequence number). |
| 33 | * |
| 34 | * For every received interest, producer replies with a data packet, containing |
| 35 | * 1024 bytes of virtual payload. |
| 36 | * |
| 37 | * To run scenario and see what is happening, use the following command: |
| 38 | * |
| 39 | * NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-multiple-strategies |
| 40 | */ |
| 41 | |
| 42 | int |
| 43 | main(int argc, char* argv[]) |
| 44 | { |
| 45 | // Setting default parameters for PointToPoint links and channels |
| 46 | Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("1Mbps")); |
| 47 | Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms")); |
| 48 | Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("10")); |
| 49 | |
| 50 | // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize |
| 51 | CommandLine cmd; |
| 52 | cmd.Parse(argc, argv); |
| 53 | |
| 54 | // Creating 3x3 topology |
| 55 | PointToPointHelper p2p; |
| 56 | PointToPointGridHelper grid(3, 3, p2p); |
| 57 | grid.BoundingBox(100, 100, 200, 200); |
| 58 | |
| 59 | // Install NDN stack on all nodes |
| 60 | StackHelper ndnHelper; |
| 61 | ndnHelper.InstallAll(); |
| 62 | |
| 63 | // Installing global routing interface on all nodes |
| 64 | GlobalRoutingHelper ndnGlobalRoutingHelper; |
| 65 | ndnGlobalRoutingHelper.InstallAll(); |
| 66 | |
| 67 | // Getting containers for the consumer/producer |
| 68 | Ptr<Node> producer = grid.GetNode(2, 2); |
| 69 | NodeContainer consumerNodes; |
| 70 | consumerNodes.Add(grid.GetNode(0, 0)); |
| 71 | |
| 72 | // Install NDN applications |
| 73 | std::string prefix = "/prefix"; |
| 74 | |
| 75 | // Install different forwarding strategies |
| 76 | StrategyChoiceHelper strategyChoiceHelper; |
| 77 | for (int row = 0; row < 3; row++) { |
| 78 | for (int column = 0; column < 3; column++) { |
| 79 | if (row < 2) |
| 80 | strategyChoiceHelper.Install(grid.GetNode(row, column), "/prefix", |
| 81 | "/localhost/nfd/strategy/best-route"); |
| 82 | else |
| 83 | strategyChoiceHelper.Install(grid.GetNode(row, column), "/prefix", |
| 84 | "/localhost/nfd/strategy/broadcast"); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | AppHelper consumerHelper("ns3::ndn::ConsumerCbr"); |
| 89 | consumerHelper.SetPrefix(prefix); |
| 90 | consumerHelper.SetAttribute("Frequency", StringValue("100")); // 100 interests a second |
| 91 | consumerHelper.Install(consumerNodes); |
| 92 | |
| 93 | AppHelper producerHelper("ns3::ndn::Producer"); |
| 94 | producerHelper.SetPrefix(prefix); |
| 95 | producerHelper.SetAttribute("PayloadSize", StringValue("1024")); |
| 96 | producerHelper.Install(producer); |
| 97 | |
| 98 | // Add /prefix origins to ndn::GlobalRouter |
| 99 | ndnGlobalRoutingHelper.AddOrigins(prefix, producer); |
| 100 | |
| 101 | // Calculate and install FIBs |
| 102 | GlobalRoutingHelper::CalculateRoutes(); |
| 103 | |
| 104 | Simulator::Stop(Seconds(20.0)); |
| 105 | Simulator::Run(); |
| 106 | Simulator::Destroy(); |
| 107 | |
| 108 | return 0; |
| 109 | } |