blob: 867f006636f2dd2f6780ee131c9fb4168a463a27 [file] [log] [blame]
Alexander Afanasyev4d325162012-06-01 12:28:50 -07001Examples
2========
3
4Simple scenario
5---------------
6
7The first example (``ccnx-simple.cc``) shows very basics of ndnSIM. In the simulated
8topology there are 3 nodes, connected with point-to-point links, one
Alexander Afanasyev07b00632012-06-01 23:46:47 -07009NDN consumer, and one NDN producer:
Alexander Afanasyev4d325162012-06-01 12:28:50 -070010
Alexander Afanasyev07b00632012-06-01 23:46:47 -070011.. aafig::
12 :aspect: 60
13 :scale: 120
Alexander Afanasyev4d325162012-06-01 12:28:50 -070014
Alexander Afanasyev07b00632012-06-01 23:46:47 -070015 +----------+ +--------+ +----------+
16 | | 1Mbps | | 1Mbps | |
17 | Consumer |<-------------->| Router |<-------------->| Producer |
18 | | 10ms | | 10ms | |
19 +----------+ +--------+ +----------+
Alexander Afanasyev4d325162012-06-01 12:28:50 -070020
Alexander Afanasyev07b00632012-06-01 23:46:47 -070021Consumer is simulated using :ndnsim:`CcnxConsumerCbr` reference application and generates Interests towards the producer
22with frequency of 10 Interests per second (see :doc:`applications`).
23
24Producer is simulated using :ndnsim:`CcnxProducer` class, which is used to satisfy all incoming Interests with virtual payload data (1024 bytes).
25
26FIB on every node is populated using default routes (see :doc:`helpers`).
Alexander Afanasyev4d325162012-06-01 12:28:50 -070027
28The following code represents all that is necessary to run such a
29simple scenario
30
31.. code-block:: c++
32
33 #include "ns3/core-module.h"
34 #include "ns3/network-module.h"
35 #include "ns3/point-to-point-module.h"
36 #include "ns3/ndnSIM-module.h"
Alexander Afanasyev07b00632012-06-01 23:46:47 -070037
Alexander Afanasyev4d325162012-06-01 12:28:50 -070038 using namespace ns3;
39
Alexander Afanasyev07b00632012-06-01 23:46:47 -070040 int
Alexander Afanasyev4d325162012-06-01 12:28:50 -070041 main (int argc, char *argv[])
42 {
43 // setting default parameters for PointToPoint links and channels
44 Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps"));
45 Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("10ms"));
46 Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("20"));
Alexander Afanasyev07b00632012-06-01 23:46:47 -070047
Alexander Afanasyev4d325162012-06-01 12:28:50 -070048 // Creating nodes
49 NodeContainer nodes;
50 nodes.Create (3);
Alexander Afanasyev07b00632012-06-01 23:46:47 -070051
Alexander Afanasyev4d325162012-06-01 12:28:50 -070052 // Connecting nodes using two links
53 PointToPointHelper p2p;
54 p2p.Install (nodes.Get (0), nodes.Get (1));
55 p2p.Install (nodes.Get (1), nodes.Get (2));
Alexander Afanasyev07b00632012-06-01 23:46:47 -070056
Alexander Afanasyev4d325162012-06-01 12:28:50 -070057 // Install CCNx stack on all nodes
58 CcnxStackHelper ccnxHelper;
59 ccnxHelper.SetDefaultRoutes (true);
60 ccnxHelper.InstallAll ();
61
Alexander Afanasyev07b00632012-06-01 23:46:47 -070062 // Installing applications
Alexander Afanasyev4d325162012-06-01 12:28:50 -070063
64 // Consumer
65 CcnxAppHelper consumerHelper ("ns3::CcnxConsumerCbr");
66 // Consumer will request /prefix/0, /prefix/1, ...
67 consumerHelper.SetPrefix ("/prefix");
68 consumerHelper.SetAttribute ("Frequency", StringValue ("10")); // 10 interests a second
69 consumerHelper.Install (nodes.Get (0)); // first node
Alexander Afanasyev07b00632012-06-01 23:46:47 -070070
Alexander Afanasyev4d325162012-06-01 12:28:50 -070071 // Producer
72 CcnxAppHelper producerHelper ("ns3::CcnxProducer");
73 // Producer will reply to all requests starting with /prefix
74 producerHelper.SetPrefix ("/prefix");
75 producerHelper.SetAttribute ("PayloadSize", StringValue("1024"));
76 producerHelper.Install (nodes.Get (2)); // last node
Alexander Afanasyev07b00632012-06-01 23:46:47 -070077
78 Simulator::Stop (Seconds (20.0));
79
80 Simulator::Run ();
81 Simulator::Destroy ();
82
83 return 0;
84 }
85
86If this code is placed into ``scratch/ccnx-simple.cc`` and NS-3 is compiled in debug mode, you can run and see progress of the
87simulation using the following command (in optimized mode nothing will be printed out)::
88
89 NS_LOG=CcnxConsumer:CcnxProducer ./waf --run=ccnx-simple
90
91
929-node grid example
93-------------------
94
95This scenario (``ccnx-grid.cc``) simulates using a grid topology build with PointToPointGrid NS-3 module
96
97.. aafig::
98 :aspect: 60
99 :scale: 120
100
101 /--------\ /-\ /-\
102 |Consumer|<---->| |<------->| |
103 \--------/ \-/ \-/
104 ^ ^ ^
105 | | | 1Mbps/10ms delay
106 v v v
107 /-\ /-\ /-\
108 | |<-------->| |<------->| |
109 \-/ \-/ \-/
110 ^ ^ ^
111 | | |
112 v v v
113 /-\ /-\ /--------\
114 | |<-------->| |<---->|Producer|
115 \-/ \-/ \--------/
116
117
118FIB is populated using :ndnsim:`CcnxGlobalRoutingHelper` (see :doc:`helpers`).
119
120Consumer is simulated using :ndnsim:`CcnxConsumerCbr` reference application and generates Interests towards the producer
121with frequency of 10 Interests per second (see :doc:`applications`).
122
123Producer is simulated using :ndnsim:`CcnxProducer` class, which is used to satisfy all incoming Interests with virtual payload data (1024 bytes).
124
125
126The following code represents all that is necessary to run such a
127simple scenario
128
129.. code-block:: c++
130
131 #include "ns3/core-module.h"
132 #include "ns3/network-module.h"
133 #include "ns3/point-to-point-module.h"
134 #include "ns3/point-to-point-grid.h"
135 #include "ns3/ndnSIM-module.h"
136
137 using namespace ns3;
138
139 int
140 main (int argc, char *argv[])
141 {
142 // Setting default parameters for PointToPoint links and channels
143 Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps"));
144 Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("10ms"));
145 Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("20"));
146
147 // Creating 3x3 topology
148 PointToPointHelper p2p;
149 PointToPointGridHelper grid (3, 3, p2p);
150 grid.BoundingBox(100,100,200,200);
151
152 // Install CCNx stack on all nodes
153 CcnxStackHelper ccnxHelper;
154 ccnxHelper.InstallAll ();
155
156 // Installing global routing interface on all nodes
157 CcnxGlobalRoutingHelper ccnxGlobalRoutingHelper;
158 ccnxGlobalRoutingHelper.InstallAll ();
159
160 // Getting containers for the consumer/producer
161 Ptr<Node> producer = grid.GetNode (nGrid-1, nGrid-1);
162 NodeContainer consumerNodes;
163 consumerNodes.Add (grid.GetNode (0,0));
164
165 // Install CCNx applications
166 std::string prefix = "/prefix";
167
168 CcnxAppHelper consumerHelper ("ns3::CcnxConsumerCbr");
169 consumerHelper.SetPrefix (prefix);
170 consumerHelper.SetAttribute ("Frequency", StringValue ("10")); // 10 interests a second
171 consumerHelper.Install (consumerNodes);
172
173 CcnxAppHelper producerHelper ("ns3::CcnxProducer");
174 producerHelper.SetPrefix (prefix);
175 producerHelper.SetAttribute ("PayloadSize", StringValue("1024"));
176 producerHelper.Install (producer);
177
178 // Add /prefix origins to CcnxGlobalRouter
179 ccnxGlobalRoutingHelper.AddOrigins (prefix, producer);
180
181 // Calculate and install FIBs
182 ccnxGlobalRoutingHelper.CalculateRoutes ();
Alexander Afanasyev4d325162012-06-01 12:28:50 -0700183
184 Simulator::Stop (Seconds (20.0));
185
186 Simulator::Run ();
187 Simulator::Destroy ();
188
189 return 0;
190 }
191
Alexander Afanasyev4d325162012-06-01 12:28:50 -0700192
Alexander Afanasyev07b00632012-06-01 23:46:47 -0700193If this code is placed into ``scratch/ccnx-grid.cc`` and NS-3 is compiled in debug mode, you can run and see progress of the
194simulation using the following command (in optimized mode nothing will be printed out)::
195
196 NS_LOG=CcnxConsumer:CcnxProducer ./waf --run=ccnx-grid
197