blob: f0911e8e7fb0ae6a2b917e760d7f0a370e40c054 [file] [log] [blame]
Spyridon Mastorakis4909d0a2014-11-27 22:17:41 -08001// 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
8using namespace ns3;
9using ns3::ndn::StackHelper;
10using ns3::ndn::AppHelper;
11using ns3::ndn::GlobalRoutingHelper;
12using ns3::ndn::StrategyChoiceHelper;
13;
14
15/**
16 * This scenario simulates a grid topology (using PointToPointGrid module)
17 *
18 * In this scenario, thanks to NFD, we can choose a different forwarding
19 * strategy for each prefix in each node.
20 *
21 * (consumer) -- ( ) -- (producer)
22 * | | |
23 * ( ) ------ ( ) ----- ( )
24 * | | |
25 * (consumer) -- ( ) -- (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-different-strategy-per-prefix
40 */
41
42int
43main(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
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 pointers to the producer/consumer nodes
68 Ptr<Node> producer1 = grid.GetNode(2, 2);
69 Ptr<Node> producer2 = grid.GetNode(0, 2);
70 Ptr<Node> consumer1 = grid.GetNode(0, 0);
71 Ptr<Node> consumer2 = grid.GetNode(2, 0);
72
73 // Define two name prefixes
74 std::string prefix1 = "/prefix1";
75 std::string prefix2 = "/prefix2";
76
77 // Install different forwarding strategies for prefix1, prefix2
78 StrategyChoiceHelper strategyChoiceHelper;
79 strategyChoiceHelper.InstallAll(prefix1, "/localhost/nfd/strategy/broadcast");
80 strategyChoiceHelper.InstallAll(prefix2, "/localhost/nfd/strategy/best-route");
81
82 // Install NDN applications
83 AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
84 consumerHelper.SetPrefix(prefix1);
85 consumerHelper.SetAttribute("Frequency", StringValue("100")); // 100 interests a second
86 consumerHelper.Install(consumer1);
87
88 consumerHelper.SetPrefix(prefix2);
89 consumerHelper.Install(consumer2);
90
91 AppHelper producerHelper("ns3::ndn::Producer");
92 producerHelper.SetPrefix(prefix1);
93 producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
94 producerHelper.Install(producer1);
95
96 producerHelper.SetPrefix(prefix2);
97 producerHelper.Install(producer2);
98
99 // Add /prefix1 and /prefix2 origins to ndn::GlobalRouter
100 ndnGlobalRoutingHelper.AddOrigins(prefix1, producer1);
101 ndnGlobalRoutingHelper.AddOrigins(prefix2, producer2);
102
103 // Calculate and install FIBs
104 GlobalRoutingHelper::CalculateRoutes();
105
106 Simulator::Stop(Seconds(20.0));
107 Simulator::Run();
108 Simulator::Destroy();
109
110 return 0;
111}