blob: 41142c96ee8785fe084590126cffc8ef3dafaf92 [file] [log] [blame]
Alexander Afanasyev4d325162012-06-01 12:28:50 -07001Examples
2========
3
Alexander Afanasyev6cf83432013-02-15 16:02:04 -08004.. role:: red
5
6.. note::
7 :red:`!!! This page only shows up examples of how to config topology and perform basic operations in ndnSIM (an example equivalent to "Hello, world1") !!! These are **NOT** examples of real experimentations (just like "Hello, world!" is not a real program).`
8
Alexander Afanasyev0fb80b92013-07-20 08:20:50 -07009.. note::
10 If you compiled ndnSIM with examples (``./waf configure --enable-examples``) you can directly run the example without putting scenario into ``scratch/`` folder.
11
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -070012.. _simple-scenario:
13
Alexander Afanasyev4d325162012-06-01 12:28:50 -070014Simple scenario
15---------------
16
Alexander Afanasyevb8d14ad2012-08-09 13:19:37 -070017The first example (``ndn-simple.cc``) shows very basics of ndnSIM. In the simulated
Alexander Afanasyev4d325162012-06-01 12:28:50 -070018topology there are 3 nodes, connected with point-to-point links, one
Alexander Afanasyev07b00632012-06-01 23:46:47 -070019NDN consumer, and one NDN producer:
Alexander Afanasyev4d325162012-06-01 12:28:50 -070020
Alexander Afanasyev07b00632012-06-01 23:46:47 -070021.. aafig::
22 :aspect: 60
23 :scale: 120
Alexander Afanasyev4d325162012-06-01 12:28:50 -070024
Alexander Afanasyev07b00632012-06-01 23:46:47 -070025 +----------+ +--------+ +----------+
26 | | 1Mbps | | 1Mbps | |
27 | Consumer |<-------------->| Router |<-------------->| Producer |
28 | | 10ms | | 10ms | |
29 +----------+ +--------+ +----------+
Alexander Afanasyev4d325162012-06-01 12:28:50 -070030
Alexander Afanasyevf6807a52012-08-10 18:11:43 -070031Consumer is simulated using :ndnsim:`ConsumerCbr` reference application and generates Interests towards the producer
Alexander Afanasyev07b00632012-06-01 23:46:47 -070032with frequency of 10 Interests per second (see :doc:`applications`).
33
Alexander Afanasyevf6807a52012-08-10 18:11:43 -070034Producer is simulated using :ndnsim:`Producer` class, which is used to satisfy all incoming Interests with virtual payload data (1024 bytes).
Alexander Afanasyev07b00632012-06-01 23:46:47 -070035
36FIB on every node is populated using default routes (see :doc:`helpers`).
Alexander Afanasyev4d325162012-06-01 12:28:50 -070037
38The following code represents all that is necessary to run such a
39simple scenario
40
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080041.. literalinclude:: ../../examples/ndn-simple.cc
42 :language: c++
43 :linenos:
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -080044 :lines: 20-27,48-
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080045 :emphasize-lines: 30-33,37-49
Alexander Afanasyev07b00632012-06-01 23:46:47 -070046
Alexander Afanasyevb8d14ad2012-08-09 13:19:37 -070047If this code is placed into ``scratch/ndn-simple.cc`` and NS-3 is compiled in debug mode, you can run and see progress of the
Alexander Afanasyev07b00632012-06-01 23:46:47 -070048simulation using the following command (in optimized mode nothing will be printed out)::
49
Alexander Afanasyevf6807a52012-08-10 18:11:43 -070050 NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-simple
Alexander Afanasyev07b00632012-06-01 23:46:47 -070051
Alexander Afanasyev0fb80b92013-07-20 08:20:50 -070052.. note::
53 If you compiled ndnSIM with examples (``./waf configure --enable-examples``) you can directly run the example without putting scenario into ``scratch/`` folder.
54
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -070055.. _9-node-grid-example:
Alexander Afanasyev6cf83432013-02-15 16:02:04 -080056
Alexander Afanasyev07b00632012-06-01 23:46:47 -0700579-node grid example
58-------------------
59
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080060This scenario (``ndn-grid.cc``) simulates a grid topology, which is constructed using PointToPointLayout NS-3 module
Alexander Afanasyev07b00632012-06-01 23:46:47 -070061
62.. aafig::
63 :aspect: 60
64 :scale: 120
65
66 /--------\ /-\ /-\
67 |Consumer|<---->| |<------->| |
68 \--------/ \-/ \-/
69 ^ ^ ^
70 | | | 1Mbps/10ms delay
71 v v v
72 /-\ /-\ /-\
73 | |<-------->| |<------->| |
74 \-/ \-/ \-/
75 ^ ^ ^
76 | | |
77 v v v
78 /-\ /-\ /--------\
79 | |<-------->| |<---->|Producer|
80 \-/ \-/ \--------/
81
82
Alexander Afanasyevf6807a52012-08-10 18:11:43 -070083FIB is populated using :ndnsim:`GlobalRoutingHelper` (see :doc:`helpers`).
Alexander Afanasyev07b00632012-06-01 23:46:47 -070084
Alexander Afanasyevf6807a52012-08-10 18:11:43 -070085Consumer is simulated using :ndnsim:`ConsumerCbr` reference application and generates Interests towards the producer
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -080086with frequency of 100 interests per second (see :doc:`applications`).
Alexander Afanasyev07b00632012-06-01 23:46:47 -070087
Alexander Afanasyevf6807a52012-08-10 18:11:43 -070088Producer is simulated using :ndnsim:`Producer` class, which is used to satisfy all incoming Interests with virtual payload data (1024 bytes).
Alexander Afanasyev07b00632012-06-01 23:46:47 -070089
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080090The following code represents all that is necessary to run such a simple scenario
Alexander Afanasyev07b00632012-06-01 23:46:47 -070091
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080092.. literalinclude:: ../../examples/ndn-grid.cc
93 :language: c++
94 :linenos:
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -080095 :lines: 20-27,53-
96 :emphasize-lines: 28,31-33,35-38,53-57
Alexander Afanasyev6cf83432013-02-15 16:02:04 -080097
Alexander Afanasyev4d325162012-06-01 12:28:50 -070098
Alexander Afanasyevb8d14ad2012-08-09 13:19:37 -070099If this code is placed into ``scratch/ndn-grid.cc`` and NS-3 is compiled in debug mode, you can run and see progress of the
Alexander Afanasyev07b00632012-06-01 23:46:47 -0700100simulation using the following command (in optimized mode nothing will be printed out)::
101
Alexander Afanasyevf6807a52012-08-10 18:11:43 -0700102 NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-grid
Alexander Afanasyev07b00632012-06-01 23:46:47 -0700103
Alexander Afanasyev0fb80b92013-07-20 08:20:50 -0700104.. note::
105 If you compiled ndnSIM with examples (``./waf configure --enable-examples``) you can directly run the example without putting scenario into ``scratch/`` folder.
106
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -0700107.. _9-node-grid-example-using-topology-plugin:
108
1099-node grid example using topology plugin
110-----------------------------------------
111
112Instead of defining topology directly as in :ref:`simple-scenario` or using specialized helpers as in :ref:`9-node-grid-example`, ndnSIM provides experimental extended versions of TopologyReader classes: :ndnsim:`AnnotatedTopologyReader` and :ndnsim:`RocketfuelWeightsReader`.
113
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800114While :ndnsim:`RocketfuelWeightsReader` is a specialized version intended to be used with `Rocketfuel <http://www.cs.washington.edu/research/networking/rocketfuel/>`_ topology and link weights files (examples will be provided later), :ndnsim:`AnnotatedTopologyReader` is a more general-use class that uses simple user-readable format.
115
116:ndnsim:`AnnotatedTopologyReader` expects the following format:
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -0700117
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800118.. literalinclude:: ../../examples/topologies/topo-grid-3x3.txt
119 :language: bash
120 :linenos:
Alexander Afanasyeve97c6072012-11-21 23:51:12 -0800121 :lines: 1-2,19-
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800122 :emphasize-lines: 8,24
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -0700123
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800124
125This scenario (``ndn-grid-topo-plugin.cc``) duplicates the functionality of :ref:`9-node-grid-example` but with the use of :ndnsim:`AnnotatedTopologyReader`.
126
127.. aafig::
128 :aspect: 60
129 :scale: 120
130
131 /--------\ /-\ /-\
132 |Consumer|<---->| |<------->| |
133 \--------/ \-/ \-/
134 ^ ^ ^
135 | | | 1Mbps/10ms delay
136 v v v
137 /-\ /-\ /-\
138 | |<-------->| |<------->| |
139 \-/ \-/ \-/
140 ^ ^ ^
141 | | |
142 v v v
143 /-\ /-\ /--------\
144 | |<-------->| |<---->|Producer|
145 \-/ \-/ \--------/
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -0700146
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800147.. literalinclude:: ../../examples/ndn-grid-topo-plugin.cc
148 :language: c++
149 :linenos:
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800150 :lines: 20-26,51-
151 :emphasize-lines: 14-16,20,27-30
Alexander Afanasyev6cf83432013-02-15 16:02:04 -0800152
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -0700153As you can see, scenario code became more compact and more readable.
154
Alexander Afanasyev6cf83432013-02-15 16:02:04 -0800155:ndnsim:`AnnotatedTopologyReader` provides two ways to access topology nodes.
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -0700156First, you can use the method :ndnsim:`AnnotatedTopologyReader::GetNodes` which returns NodeContainer.
157
158Alternatively, nodes can be accessed by name using `Names::Find<Node> ("nodename")` call, as in the above example.
159For this purpose,:ndnsim:`AnnotatedTopologyReader` automatically registers all created nodes with names specified in topology file.
160For more information about `Names` class, please refer to `NS-3 documentation <.. http://www.nsnam.org/doxygen/classns3_1_1_names.html>`_
161.
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800162
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800163If the topology file is placed into ``src/ndnSIM/examples/topologies/topo-grid-3x3.txt`` and the code is placed into ``scratch/ndn-grid-topo-plugin.cc``, you can run and see progress of the simulation using the following command (in optimized mode nothing will be printed out)::
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800164
165 NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-grid-topo-plugin
166
Alexander Afanasyev0fb80b92013-07-20 08:20:50 -0700167.. note::
168 If you compiled ndnSIM with examples (``./waf configure --enable-examples``) you can directly run the example without putting scenario into ``scratch/`` folder.
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800169
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -08001706-node bottleneck topology
171--------------------------
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800172
Alexander Afanasyev6cf83432013-02-15 16:02:04 -0800173This scenario (``ndn-congestion-topo-plugin.cc``) can be used for congestion-related scenarios
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800174
175.. aafig::
176 :aspect: 60
177 :scale: 120
178
179 /------\ /------\
180 | Src1 |<--+ +-->| Dst1 |
181 \------/ \ / \------/
Alexander Afanasyev6cf83432013-02-15 16:02:04 -0800182 \ /
183 +-->/------\ "bottleneck" /------\<-+
184 | Rtr1 |<===============>| Rtr2 |
185 +-->\------/ \------/<-+
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800186 / \
187 /------\ / \ /------\
188 | Src2 |<--+ +-->| Dst2 |
189 \------/ \------/
190
191.. literalinclude:: ../../examples/topologies/topo-6-node.txt
192 :language: bash
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800193 :linenos:
Alexander Afanasyeve97c6072012-11-21 23:51:12 -0800194 :lines: 1-2,15-
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800195 :emphasize-lines: 3,13
Alexander Afanasyev6cf83432013-02-15 16:02:04 -0800196
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800197.. literalinclude:: ../../examples/ndn-congestion-topo-plugin.cc
198 :language: c++
199 :linenos:
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800200 :lines: 20-26,47-
201 :emphasize-lines: 15,21-22,29-34,41-47,52-62
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800202
203.. :lines: 20-25,53-
Alexander Afanasyeve97c6072012-11-21 23:51:12 -0800204
205To run this scenario and see what is happening, use the following command::
206
207 NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-congestion-topo-plugin
208
Alexander Afanasyev0fb80b92013-07-20 08:20:50 -0700209.. note::
210 If you compiled ndnSIM with examples (``./waf configure --enable-examples``) you can directly run the example without putting scenario into ``scratch/`` folder.
211
Alexander Afanasyeve97c6072012-11-21 23:51:12 -0800212.. _11-node 2-bottleneck topology with custom forwarding strategy:
213
21411-node 2-bottleneck topology with custom forwarding strategy
215-------------------------------------------------------------
216
217To effectively use the example :ref:`custom strategy <Writing your own custom strategy>`, we need to make sure that FIB entries contain at least two entries.
218In the current version of ndnSIM, this can be accomplished using manual route configuration.
219
220The following example illustrates how the strategy can be used in simulation scenario.
221
222Let us first define a meaningful topology:
223
224.. aafig::
225 :aspect: 60
226 :scale: 120
Alexander Afanasyev6cf83432013-02-15 16:02:04 -0800227
Alexander Afanasyeve97c6072012-11-21 23:51:12 -0800228 /------\ 0 0 /------\
229 | c1 |<-----+ +----->| p1 |
230 \------/ \ / \------/
Alexander Afanasyev6cf83432013-02-15 16:02:04 -0800231 \ /-----\ /
Alexander Afanasyeve97c6072012-11-21 23:51:12 -0800232 /------\ 0 \ +==>| r12 |<==+ / 0 /------\
233 | c2 |<--+ \ / \-----/ \ / +-->| p2 |
234 \------/ \ \ | | / / \------/
Alexander Afanasyev6cf83432013-02-15 16:02:04 -0800235 \ | | 1Mbps links | | /
236 \ 1 v0 v5 1v 2v 3 /
237 +->/------\ /------\<-+
238 2| r1 |<===============>| r2 |4
239 +->\------/4 0\------/<-+
240 / 3^ ^5 \
241 / | | \
Alexander Afanasyeve97c6072012-11-21 23:51:12 -0800242 /------\ 0 / / \ \ 0 /------\
243 | c3 |<--+ / \ +-->| p3 |
244 \------/ / \ \------/
Alexander Afanasyev6cf83432013-02-15 16:02:04 -0800245 / "All consumer-router and" \
Alexander Afanasyeve97c6072012-11-21 23:51:12 -0800246 /------\ 0 / "router-producer links are" \ 0 /------\
247 | c4 |<-----+ "10Mbps" +---->| p4 |
248 \------/ \------/
Alexander Afanasyev6cf83432013-02-15 16:02:04 -0800249
Alexander Afanasyeve97c6072012-11-21 23:51:12 -0800250 "Numbers near nodes denote face IDs. Face ID is assigned based on the order of link"
251 "definitions in the topology file"
252
253The corresponding topology file (``topo-11-node-two-bottlenecks.txt``):
254
255.. literalinclude:: ../../examples/topologies/topo-11-node-two-bottlenecks.txt
256 :language: bash
257 :linenos:
258 :lines: 1-2,28-
259
260Example simulation (``ndn-congestion-alt-topo-plugin.cc``) scenario that utilizes CustomStrategy forwarding strategy:
261
262.. literalinclude:: ../../examples/ndn-congestion-alt-topo-plugin.cc
263 :language: c++
264 :linenos:
265 :lines: 21-28,61-
266 :emphasize-lines: 16,21,49-50,65-79
267
268
269To run this scenario and see what is happening, use the following command::
270
271 NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-congestion-alt-topo-plugin
272
273You can also run using visualizer module to verify that both bottleneck links are utilized::
274
275 ./waf --run=ndn-congestion-alt-topo-plugin --visualize
Alexander Afanasyev59314802012-11-26 14:56:04 -0800276
Alexander Afanasyev0fb80b92013-07-20 08:20:50 -0700277.. note::
278 If you compiled ndnSIM with examples (``./waf configure --enable-examples``) you can directly run the example without putting scenario into ``scratch/`` folder.
279
Alexander Afanasyevf4a03592012-12-10 16:12:34 -08002803-level binary tree with packet-level trace helpers
281---------------------------------------------------
Alexander Afanasyev59314802012-11-26 14:56:04 -0800282
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800283:ref:`packet trace helper example`
Alexander Afanasyev59314802012-11-26 14:56:04 -0800284
Alexander Afanasyevf4a03592012-12-10 16:12:34 -0800285
2863-level binary tree with content store trace helper
287---------------------------------------------------
288
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800289:ref:`cs trace helper example`
Alexander Afanasyevf4a03592012-12-10 16:12:34 -0800290
Alexander Afanasyevf4a03592012-12-10 16:12:34 -0800291
Alexander Afanasyev27e365b2013-01-18 18:03:43 -08002923-level binary tree with application-level Interest-Data delay tracer
293----------------------------------------------------------------------
294
295:ref:`app delay trace helper example`
296
297
Alexander Afanasyev71278d42012-12-12 19:16:54 -08002983-node topology with Content Store respecting freshness field of ContentObjects
299-------------------------------------------------------------------------------
300
301:ref:`Content Store respecting freshness field of ContentObjects`
302
3031-node topology with custom application
304---------------------------------------
305
306:ref:`Custom applications`
307
Alexander Afanasyev1ab1aad2013-02-28 11:32:21 -0800308Simple scenario with pcap dump
309------------------------------
310
311The following example (``ndn-simple-with-pcap.cc``) demonstrates how to dump all simulated traffic
312in pcap-formatted data, which can be used for later analysis by conventional tools, like tcpdump and wireshark.
313
314.. literalinclude:: ../../examples/ndn-simple-with-pcap.cc
315 :language: c++
316 :linenos:
317 :lines: 20-
318 :emphasize-lines: 7-29,70-72
319
320If this code is placed into ``scratch/ndn-simple-with-pcap.cc`` and NS-3 is compiled in debug mode, you can run and see progress of the
321simulation using the following command (in optimized mode nothing will be printed out)::
322
323 NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-simple-with-pcap
324
325This will generate ``ndn-simple-trace.pcap``, which can be fed to tcpdump::
326
327 tcpdump -r ndn-simple-trace.pcap
Alexander Afanasyevb99cb6c2013-03-12 13:58:30 -0700328
Alexander Afanasyev0fb80b92013-07-20 08:20:50 -0700329.. note::
330 If you compiled ndnSIM with examples (``./waf configure --enable-examples``) you can directly run the example without putting scenario into ``scratch/`` folder.
331
332.. _Simple scenario with link failures:
333
334Simple scenario with link failures
335----------------------------------
336
337The following example (``ndn-simple-with-link-failure.cc``) shows how to "fail" links in ndnSIM simulation.
338The basic idea is to set ndn::Faces that correspond to the failed link to DOWN state.
339ndnSIM now includes a simple helper that simplifies this process.
340
341.. literalinclude:: ../../examples/ndn-simple-with-link-failure.cc
342 :language: c++
343 :linenos:
344 :lines: 21-31,52-
345 :emphasize-lines: 54-56
346
347If this code is placed into ``scratch/ndn-simple-with-link-failure.cc`` and NS-3 is compiled in debug mode, you can run and see progress of the
348simulation using the following command (in optimized mode nothing will be printed out)::
349
350 NS_LOG=ndn.Consumer:ndn.Producer:ndn.LinkControlHelper ./waf --run=ndn-simple-with-link-failure
351
352.. note::
353 If you compiled ndnSIM with examples (``./waf configure --enable-examples``) you can directly run the example without putting scenario into ``scratch/`` folder.
354
355
Alexander Afanasyev27370c52013-03-12 13:54:08 -070035625-node tree topology with L2Tracer
357-----------------------------------
358
359:ref:`Example of packet drop tracer (L2Tracer)`
Alexander Afanasyevb5e77d82013-04-10 15:55:26 -0700360
3613-node topology with periodic tracing of PIT
362--------------------------------------------
363
364:ref:`periodic tracing of Pending Interest Table (PIT) size`