blob: 4fb13d066c48bd88150350072d9ed2a03e377a06 [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 Afanasyevfc9d9e12013-08-10 14:17:49 -070017.. sidebar:: Topology
18
19 .. aafig::
20 :aspect: 60
21 :scale: 90
22
23 +----------+ +--------+ +----------+
24 | | 1Mbps | | 1Mbps | |
25 | Consumer |<-------------->| Router |<-------------->| Producer |
26 | | 10ms | | 10ms | |
27 +----------+ +--------+ +----------+
28
Alexander Afanasyevb8d14ad2012-08-09 13:19:37 -070029The first example (``ndn-simple.cc``) shows very basics of ndnSIM. In the simulated
Alexander Afanasyev4d325162012-06-01 12:28:50 -070030topology there are 3 nodes, connected with point-to-point links, one
Alexander Afanasyev07b00632012-06-01 23:46:47 -070031NDN consumer, and one NDN producer:
Alexander Afanasyev4d325162012-06-01 12:28:50 -070032
Alexander Afanasyevf6807a52012-08-10 18:11:43 -070033Consumer is simulated using :ndnsim:`ConsumerCbr` reference application and generates Interests towards the producer
Alexander Afanasyev07b00632012-06-01 23:46:47 -070034with frequency of 10 Interests per second (see :doc:`applications`).
35
Alexander Afanasyevf6807a52012-08-10 18:11:43 -070036Producer 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 -070037
38FIB on every node is populated using default routes (see :doc:`helpers`).
Alexander Afanasyev4d325162012-06-01 12:28:50 -070039
40The following code represents all that is necessary to run such a
41simple scenario
42
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080043.. literalinclude:: ../../examples/ndn-simple.cc
44 :language: c++
45 :linenos:
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -080046 :lines: 20-27,48-
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080047 :emphasize-lines: 30-33,37-49
Alexander Afanasyev07b00632012-06-01 23:46:47 -070048
Alexander Afanasyevb8d14ad2012-08-09 13:19:37 -070049If 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 -070050simulation using the following command (in optimized mode nothing will be printed out)::
51
Alexander Afanasyevf6807a52012-08-10 18:11:43 -070052 NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-simple
Alexander Afanasyev07b00632012-06-01 23:46:47 -070053
Alexander Afanasyev0fb80b92013-07-20 08:20:50 -070054.. note::
55 If you compiled ndnSIM with examples (``./waf configure --enable-examples``) you can directly run the example without putting scenario into ``scratch/`` folder.
56
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -070057.. _9-node-grid-example:
Alexander Afanasyev6cf83432013-02-15 16:02:04 -080058
Alexander Afanasyev07b00632012-06-01 23:46:47 -0700599-node grid example
60-------------------
61
Alexander Afanasyevfc9d9e12013-08-10 14:17:49 -070062.. sidebar:: Topology
63
64 .. aafig::
65 :aspect: 60
66 :scale: 120
67
68 /--------\ /-\ /-\
69 |Consumer|<---->| |<------->| |
70 \--------/ \-/ \-/
71 ^ ^ ^
72 | | | 1Mbps/10ms delay
73 v v v
74 /-\ /-\ /-\
75 | |<-------->| |<------->| |
76 \-/ \-/ \-/
77 ^ ^ ^
78 | | |
79 v v v
80 /-\ /-\ /--------\
81 | |<-------->| |<---->|Producer|
82 \-/ \-/ \--------/
83
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080084This scenario (``ndn-grid.cc``) simulates a grid topology, which is constructed using PointToPointLayout NS-3 module
Alexander Afanasyev07b00632012-06-01 23:46:47 -070085
Alexander Afanasyevf6807a52012-08-10 18:11:43 -070086FIB is populated using :ndnsim:`GlobalRoutingHelper` (see :doc:`helpers`).
Alexander Afanasyev07b00632012-06-01 23:46:47 -070087
Alexander Afanasyevf6807a52012-08-10 18:11:43 -070088Consumer is simulated using :ndnsim:`ConsumerCbr` reference application and generates Interests towards the producer
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -080089with frequency of 100 interests per second (see :doc:`applications`).
Alexander Afanasyev07b00632012-06-01 23:46:47 -070090
Alexander Afanasyevf6807a52012-08-10 18:11:43 -070091Producer 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 -070092
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080093The following code represents all that is necessary to run such a simple scenario
Alexander Afanasyev07b00632012-06-01 23:46:47 -070094
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080095.. literalinclude:: ../../examples/ndn-grid.cc
96 :language: c++
97 :linenos:
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -080098 :lines: 20-27,53-
99 :emphasize-lines: 28,31-33,35-38,53-57
Alexander Afanasyev6cf83432013-02-15 16:02:04 -0800100
Alexander Afanasyev4d325162012-06-01 12:28:50 -0700101
Alexander Afanasyevb8d14ad2012-08-09 13:19:37 -0700102If 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 -0700103simulation using the following command (in optimized mode nothing will be printed out)::
104
Alexander Afanasyevf6807a52012-08-10 18:11:43 -0700105 NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-grid
Alexander Afanasyev07b00632012-06-01 23:46:47 -0700106
Alexander Afanasyev0fb80b92013-07-20 08:20:50 -0700107.. note::
108 If you compiled ndnSIM with examples (``./waf configure --enable-examples``) you can directly run the example without putting scenario into ``scratch/`` folder.
109
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -0700110.. _9-node-grid-example-using-topology-plugin:
111
1129-node grid example using topology plugin
113-----------------------------------------
114
Alexander Afanasyevfc9d9e12013-08-10 14:17:49 -0700115.. sidebar:: Topology
116
117 .. aafig::
118 :aspect: 60
119 :scale: 120
120
121 /--------\ /-\ /-\
122 |Consumer|<---->| |<------->| |
123 \--------/ \-/ \-/
124 ^ ^ ^
125 | | | 1Mbps/10ms delay
126 v v v
127 /-\ /-\ /-\
128 | |<-------->| |<------->| |
129 \-/ \-/ \-/
130 ^ ^ ^
131 | | |
132 v v v
133 /-\ /-\ /--------\
134 | |<-------->| |<---->|Producer|
135 \-/ \-/ \--------/
136
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -0700137Instead 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`.
138
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800139While :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.
140
141:ndnsim:`AnnotatedTopologyReader` expects the following format:
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -0700142
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800143.. literalinclude:: ../../examples/topologies/topo-grid-3x3.txt
144 :language: bash
145 :linenos:
Alexander Afanasyeve97c6072012-11-21 23:51:12 -0800146 :lines: 1-2,19-
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800147 :emphasize-lines: 8,24
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -0700148
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800149
150This scenario (``ndn-grid-topo-plugin.cc``) duplicates the functionality of :ref:`9-node-grid-example` but with the use of :ndnsim:`AnnotatedTopologyReader`.
151
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800152.. literalinclude:: ../../examples/ndn-grid-topo-plugin.cc
153 :language: c++
154 :linenos:
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800155 :lines: 20-26,51-
156 :emphasize-lines: 14-16,20,27-30
Alexander Afanasyev6cf83432013-02-15 16:02:04 -0800157
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -0700158As you can see, scenario code became more compact and more readable.
159
Alexander Afanasyev6cf83432013-02-15 16:02:04 -0800160:ndnsim:`AnnotatedTopologyReader` provides two ways to access topology nodes.
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -0700161First, you can use the method :ndnsim:`AnnotatedTopologyReader::GetNodes` which returns NodeContainer.
162
163Alternatively, nodes can be accessed by name using `Names::Find<Node> ("nodename")` call, as in the above example.
164For this purpose,:ndnsim:`AnnotatedTopologyReader` automatically registers all created nodes with names specified in topology file.
165For more information about `Names` class, please refer to `NS-3 documentation <.. http://www.nsnam.org/doxygen/classns3_1_1_names.html>`_
166.
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800167
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800168If 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 -0800169
170 NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-grid-topo-plugin
171
Alexander Afanasyev0fb80b92013-07-20 08:20:50 -0700172.. note::
173 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 -0800174
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -08001756-node bottleneck topology
176--------------------------
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800177
Alexander Afanasyevfc9d9e12013-08-10 14:17:49 -0700178.. sidebar:: Topology
179
180 .. aafig::
181 :aspect: 60
182 :scale: 90
183
184 /------\ /------\
185 | Src1 |<--+ +-->| Dst1 |
186 \------/ \ / \------/
187 \ /
188 +-->/------\ "bottleneck" /------\<-+
189 | Rtr1 |<===============>| Rtr2 |
190 +-->\------/ \------/<-+
191 / \
192 /------\ / \ /------\
193 | Src2 |<--+ +-->| Dst2 |
194 \------/ \------/
195
Alexander Afanasyev6cf83432013-02-15 16:02:04 -0800196This scenario (``ndn-congestion-topo-plugin.cc``) can be used for congestion-related scenarios
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800197
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800198.. literalinclude:: ../../examples/topologies/topo-6-node.txt
199 :language: bash
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800200 :linenos:
Alexander Afanasyeve97c6072012-11-21 23:51:12 -0800201 :lines: 1-2,15-
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800202 :emphasize-lines: 3,13
Alexander Afanasyev6cf83432013-02-15 16:02:04 -0800203
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800204.. literalinclude:: ../../examples/ndn-congestion-topo-plugin.cc
205 :language: c++
206 :linenos:
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800207 :lines: 20-26,47-
208 :emphasize-lines: 15,21-22,29-34,41-47,52-62
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800209
210.. :lines: 20-25,53-
Alexander Afanasyeve97c6072012-11-21 23:51:12 -0800211
212To run this scenario and see what is happening, use the following command::
213
214 NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-congestion-topo-plugin
215
Alexander Afanasyev0fb80b92013-07-20 08:20:50 -0700216.. note::
217 If you compiled ndnSIM with examples (``./waf configure --enable-examples``) you can directly run the example without putting scenario into ``scratch/`` folder.
218
Alexander Afanasyeve97c6072012-11-21 23:51:12 -0800219.. _11-node 2-bottleneck topology with custom forwarding strategy:
220
22111-node 2-bottleneck topology with custom forwarding strategy
222-------------------------------------------------------------
223
Alexander Afanasyevfc9d9e12013-08-10 14:17:49 -0700224.. sidebar:: Topology
225
226 .. aafig::
227 :aspect: 60
228 :scale: 90
229
230 /------\ 0 0 /------\
231 | c1 |<-----+ +----->| p1 |
232 \------/ \ / \------/
233 \ /-----\ /
234 /------\ 0 \ +==>| r12 |<==+ / 0 /------\
235 | c2 |<--+ \ / \-----/ \ / +-->| p2 |
236 \------/ \ \ | | / / \------/
237 \ | | 1Mbps links | | /
238 \ 1 v0 v5 1v 2v 3 /
239 +->/------\ /------\<-+
240 2| r1 |<===============>| r2 |4
241 +->\------/4 0\------/<-+
242 / 3^ ^5 \
243 / | | \
244 /------\ 0 / / \ \ 0 /------\
245 | c3 |<--+ / \ +-->| p3 |
246 \------/ / \ \------/
247 / "All consumer-router and" \
248 /------\ 0 / "router-producer links are" \ 0 /------\
249 | c4 |<-----+ "10Mbps" +---->| p4 |
250 \------/ \------/
251
252 "Numbers near nodes denote face IDs. Face ID is assigned based on the order of link"
253 "definitions in the topology file"
254
Alexander Afanasyeve97c6072012-11-21 23:51:12 -0800255To 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.
256In the current version of ndnSIM, this can be accomplished using manual route configuration.
257
258The following example illustrates how the strategy can be used in simulation scenario.
259
260Let us first define a meaningful topology:
261
Alexander Afanasyeve97c6072012-11-21 23:51:12 -0800262
263The corresponding topology file (``topo-11-node-two-bottlenecks.txt``):
264
265.. literalinclude:: ../../examples/topologies/topo-11-node-two-bottlenecks.txt
266 :language: bash
267 :linenos:
268 :lines: 1-2,28-
269
270Example simulation (``ndn-congestion-alt-topo-plugin.cc``) scenario that utilizes CustomStrategy forwarding strategy:
271
272.. literalinclude:: ../../examples/ndn-congestion-alt-topo-plugin.cc
273 :language: c++
274 :linenos:
275 :lines: 21-28,61-
276 :emphasize-lines: 16,21,49-50,65-79
277
278
279To run this scenario and see what is happening, use the following command::
280
281 NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-congestion-alt-topo-plugin
282
283You can also run using visualizer module to verify that both bottleneck links are utilized::
284
285 ./waf --run=ndn-congestion-alt-topo-plugin --visualize
Alexander Afanasyev59314802012-11-26 14:56:04 -0800286
Alexander Afanasyev0fb80b92013-07-20 08:20:50 -0700287.. note::
288 If you compiled ndnSIM with examples (``./waf configure --enable-examples``) you can directly run the example without putting scenario into ``scratch/`` folder.
289
Alexander Afanasyevf4a03592012-12-10 16:12:34 -08002903-level binary tree with packet-level trace helpers
291---------------------------------------------------
Alexander Afanasyev59314802012-11-26 14:56:04 -0800292
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800293:ref:`packet trace helper example`
Alexander Afanasyev59314802012-11-26 14:56:04 -0800294
Alexander Afanasyevf4a03592012-12-10 16:12:34 -0800295
2963-level binary tree with content store trace helper
297---------------------------------------------------
298
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800299:ref:`cs trace helper example`
Alexander Afanasyevf4a03592012-12-10 16:12:34 -0800300
Alexander Afanasyevf4a03592012-12-10 16:12:34 -0800301
Alexander Afanasyev27e365b2013-01-18 18:03:43 -08003023-level binary tree with application-level Interest-Data delay tracer
303----------------------------------------------------------------------
304
305:ref:`app delay trace helper example`
306
307
Alexander Afanasyev71278d42012-12-12 19:16:54 -08003083-node topology with Content Store respecting freshness field of ContentObjects
309-------------------------------------------------------------------------------
310
311:ref:`Content Store respecting freshness field of ContentObjects`
312
3131-node topology with custom application
314---------------------------------------
315
316:ref:`Custom applications`
317
Alexander Afanasyev1ab1aad2013-02-28 11:32:21 -0800318Simple scenario with pcap dump
319------------------------------
320
321The following example (``ndn-simple-with-pcap.cc``) demonstrates how to dump all simulated traffic
322in pcap-formatted data, which can be used for later analysis by conventional tools, like tcpdump and wireshark.
323
324.. literalinclude:: ../../examples/ndn-simple-with-pcap.cc
325 :language: c++
326 :linenos:
327 :lines: 20-
328 :emphasize-lines: 7-29,70-72
329
330If 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
331simulation using the following command (in optimized mode nothing will be printed out)::
332
333 NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-simple-with-pcap
334
335This will generate ``ndn-simple-trace.pcap``, which can be fed to tcpdump::
336
337 tcpdump -r ndn-simple-trace.pcap
Alexander Afanasyevb99cb6c2013-03-12 13:58:30 -0700338
Alexander Afanasyev0fb80b92013-07-20 08:20:50 -0700339.. note::
340 If you compiled ndnSIM with examples (``./waf configure --enable-examples``) you can directly run the example without putting scenario into ``scratch/`` folder.
341
342.. _Simple scenario with link failures:
343
344Simple scenario with link failures
345----------------------------------
346
347The following example (``ndn-simple-with-link-failure.cc``) shows how to "fail" links in ndnSIM simulation.
348The basic idea is to set ndn::Faces that correspond to the failed link to DOWN state.
349ndnSIM now includes a simple helper that simplifies this process.
350
351.. literalinclude:: ../../examples/ndn-simple-with-link-failure.cc
352 :language: c++
353 :linenos:
354 :lines: 21-31,52-
355 :emphasize-lines: 54-56
356
357If 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
358simulation using the following command (in optimized mode nothing will be printed out)::
359
360 NS_LOG=ndn.Consumer:ndn.Producer:ndn.LinkControlHelper ./waf --run=ndn-simple-with-link-failure
361
362.. note::
363 If you compiled ndnSIM with examples (``./waf configure --enable-examples``) you can directly run the example without putting scenario into ``scratch/`` folder.
364
365
Alexander Afanasyev27370c52013-03-12 13:54:08 -070036625-node tree topology with L2Tracer
367-----------------------------------
368
369:ref:`Example of packet drop tracer (L2Tracer)`
Alexander Afanasyevb5e77d82013-04-10 15:55:26 -0700370
3713-node topology with periodic tracing of PIT
372--------------------------------------------
373
374:ref:`periodic tracing of Pending Interest Table (PIT) size`