blob: 97aa326be9ae460c7abd05c6cc36256daf599392 [file] [log] [blame]
Alexander Afanasyev6315ef72012-06-01 20:56:31 -07001ndnSIM applications
2===================
3
4ndnSIM includes a few reference applications that can be used as a base for NDN simulations.
5
6Reference applications
7++++++++++++++++++++++
8
Alexander Afanasyev5b054aa2012-08-13 18:56:17 -07009ConsumerCbr
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070010^^^^^^^^^^^^^^^
11
Alexander Afanasyev5b054aa2012-08-13 18:56:17 -070012:ndnsim:`ConsumerCbr` an application that generates Interest traffic with predefined pattern (constant frequency, constant average rate with inter-Interest gap distributed uniformly at random, exponentially at random, etc.).
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070013
14.. code-block:: c++
15
16 // Create application using the app helper
Alexander Afanasyev5b054aa2012-08-13 18:56:17 -070017 ndn::AppHelper helper ("ns3::ndn::ConsumerCbr");
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070018
19This applications has the following attributes:
20
Alexander Afanasyev13800102012-12-25 00:30:31 -080021* ``Frequency``
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070022
23 .. note::
24 default: ``1.0`` (1 per second)
25
26 Either exact (for contant version) or expected (for randomized version) frequency with which Interests are generated
27
28 .. code-block:: c++
29
30 // Set attribute using the app helper
31 helper.SetAttribute ("Frequency", DoubleValue (1.0));
32
Alexander Afanasyev13800102012-12-25 00:30:31 -080033* ``Randomize``
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070034
35 .. note::
36 default: ``"none"``
37
38 Specify whether to do randomization for inter-Interest gap or not. The following variants are currently supported:
39
40 - ``"none"``: no randomization
41
42 - ``"uniform"``: uniform distribution in range (0, 1/Frequency)
43
44 - ``"exponential"``: exponential distribution with mean 1/Frequency
45
46 .. code-block:: c++
47
48 // Set attribute using the app helper
49 helper.SetAttribute ("Randomize", StringValue ("uniform"));
50
Alexander Afanasyev13800102012-12-25 00:30:31 -080051ConsumerZipfMandelbrot
52^^^^^^^^^^^^^^^^^^^^^^
53
54.. note::
55 Author: Xiaoke Jiang
56
57An app that requests contents (names in the requests) following Zipf-Mandelbrot distribution (number of Content frequency Distribution).
58This class is a subclass of :ndnsim:`ConsumerCbr`.
59
60.. code-block:: c++
61
62 // Create application using the app helper
63 ndn::AppHelper helper ("ns3::ndn::ConsumerZipfMandelbrot");
64
65``Frequency`` and ``Randomize`` attributes can be used in the same way as in the base :ndnsim:`ConsumerCbr` applications.
66
67Additional attributes:
68
69* ``NumberOfContents``
70
71 .. note::
72 default: 100
73
74 Number of different content (sequence numbers) that will be requested by the applications
75
76
77THE following pictures show basic comparison of the generated stream of Interests versus theoretical `Zipf-Mandelbrot <http://en.wikipedia.org/wiki/Zipf%E2%80%93Mandelbrot_law>`_ function (``NumberOfContents`` set to 100 and ``Frequency`` set to 100)
78
79.. image:: _static/apps/zipf-n100-frq100-duration10.png
80 :alt: Comparsion between simulation and theory with simulation duration 10 seconds
81
82.. image:: _static/apps/zipf-n100-frq100-duration50.png
83 :alt: Comparsion between simulation and theory with simulation duration 50 seconds
84
85.. image:: _static/apps/zipf-n100-frq100-duration100.png
86 :alt: Comparsion between simulation and theory with simulation duration 100 seconds
87
88.. image:: _static/apps/zipf-n100-frq100-duration1000.png
89 :alt: Comparsion between simulation and theory with simulation duration 1000 seconds
90
91
Alexander Afanasyev5b054aa2012-08-13 18:56:17 -070092ConsumerBatches
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070093^^^^^^^^^^^^^^^^^^^
94
Alexander Afanasyev5b054aa2012-08-13 18:56:17 -070095:ndnsim:`ConsumerBatches` is an on-off-style application gen- erating a specified number of Interests at specified points of simulation.
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070096
97.. code-block:: c++
98
99 // Create application using the app helper
Alexander Afanasyev5b054aa2012-08-13 18:56:17 -0700100 ndn::AppHelper consumerHelper ("ns3::ndn::ConsumerBatches");
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700101
102This applications has the following attributes:
103
Alexander Afanasyev13800102012-12-25 00:30:31 -0800104* ``Batches``
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700105
106 .. note::
107 default: Empty
108
109 Specify exact pattern of Interest packets, specifying when and how many Interest packets should be sent.
110 The following example defines that 1 Interest should be requested at time 1s, 5 Interests at time 5s, and 2 Interests at time 10s.:
111
112 .. code-block:: c++
113
114 // Set attribute using the app helper
115 helper.SetAttribute ("Batches", StringValue ("1s 1 2s 5 10s 2"));
116
117
Alexander Afanasyev5b054aa2012-08-13 18:56:17 -0700118ConsumerWindow
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700119^^^^^^^^^^^^^^^^^^
120
Alexander Afanasyev5b054aa2012-08-13 18:56:17 -0700121:ndnsim:`ConsumerWindow` is an application generating a variable rate Interest traffic. It relies on an optional NACK-Interest feature and implements a simple sliding-window-based Interest generation mechanism.
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700122
123.. code-block:: c++
124
125 // Create application using the app helper
Alexander Afanasyev5b054aa2012-08-13 18:56:17 -0700126 ndn::AppHelper consumerHelper ("ns3::ndn::ConsumerWindow");
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700127
128
129This applications has the following attributes:
130
Alexander Afanasyev13800102012-12-25 00:30:31 -0800131* ``Window``
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700132
133 .. note::
134 default: ``1``
135
136 Initial number of Interests that will be send out without waiting for the data (number of outstanding Interests)
137
Alexander Afanasyev13800102012-12-25 00:30:31 -0800138* ``PayloadSize``
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700139
140 .. note::
141 default: ``1040``
142
143 Expected size of the Data payload (necessary only when Size is specified)
144
Alexander Afanasyev13800102012-12-25 00:30:31 -0800145* ``Size``
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700146
147 .. note::
148 default: ``-1``
149
150 Amount of data to be requested (will stop issuing Interests after ``Size`` data is received)
151
Alexander Afanasyevd4e97b32012-06-04 15:09:50 -0700152 If ``Size`` is set to -1, Interests will be requested till the end of the simulation.
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700153
Alexander Afanasyev5b054aa2012-08-13 18:56:17 -0700154Producer
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700155^^^^^^^^^^^^
156
Alexander Afanasyev5b054aa2012-08-13 18:56:17 -0700157:ndnsim:`Producer` a simple Interest-sink application, which replying every incoming Interest with Data packet with a specified size and name same as in Interest.
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700158
159.. code-block:: c++
160
161 // Create application using the app helper
Alexander Afanasyev5b054aa2012-08-13 18:56:17 -0700162 ndn::AppHelper consumerHelper ("ns3::ndn::Producer");
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700163
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800164.. _Custom applications:
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700165
166Custom applications
167+++++++++++++++++++
168
Alexander Afanasyev5b054aa2012-08-13 18:56:17 -0700169Applications interact with the core of the system using :ndnsim:`AppFace` realization of Face abstraction.
170To simplify implementation of specific NDN application, ndnSIM provides a base :ndnsim:`App` class that takes care of creating :ndnsim:`AppFace` and registering it inside the NDN protocol stack, as well as provides default processing for incoming Interest and Data packets.
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700171
Alexander Afanasyev5b054aa2012-08-13 18:56:17 -0700172.. Base App class
Alexander Afanasyevd4e97b32012-06-04 15:09:50 -0700173.. ^^^^^^^^^^^^^^^^^^
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700174
175
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -0700176Customer example
177^^^^^^^^^^^^^^^^
Alexander Afanasyevd4e97b32012-06-04 15:09:50 -0700178
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800179The following code shows how a simple ndnSIM application can be created, and how an application can send Interests and respond with ContentObjects to incoming interests.
Alexander Afanasyevd4e97b32012-06-04 15:09:50 -0700180
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800181When this application starts it sets "interest filter" (install FIB entry) for /prefix/sub, as well as sends Interest for this prefix.
182When an Interest is received, it is replied with a ContentObject with 1024-byte fake payload.
Alexander Afanasyevd4e97b32012-06-04 15:09:50 -0700183
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800184For more details refer ``examples/custom-apps/custom-app.h``, ``examples/custom-apps/custom-app.cc`` and API documentation of ndnSIM and NS-3.
Alexander Afanasyevd4e97b32012-06-04 15:09:50 -0700185
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800186Header file ``examples/custom-apps/custom-app.h``:
Alexander Afanasyevd4e97b32012-06-04 15:09:50 -0700187
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800188.. literalinclude:: ../../examples/custom-apps/custom-app.h
189 :language: c++
190 :linenos:
191 :lines: 21-29,40-
Alexander Afanasyevd4e97b32012-06-04 15:09:50 -0700192
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800193Source file ``examples/custom-apps/custom-app.cc``:
Alexander Afanasyevd4e97b32012-06-04 15:09:50 -0700194
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800195.. literalinclude:: ../../examples/custom-apps/custom-app.cc
196 :language: c++
197 :linenos:
198 :lines: 21-
Alexander Afanasyevd4e97b32012-06-04 15:09:50 -0700199
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800200Example how to use custom app in a scenario (``ndn-simple-with-custom-app.cc``):
Alexander Afanasyevd4e97b32012-06-04 15:09:50 -0700201
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800202 .. * +------+ <-----> (CustomApp1)
203 .. * | Node |
204 .. * +------+ <-----> (CustomApp2)
205 .. *
Alexander Afanasyevd4e97b32012-06-04 15:09:50 -0700206
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800207.. literalinclude:: ../../examples/ndn-simple-with-custom-app.cc
208 :language: c++
209 :linenos:
210 :lines: 21-28,39-
211 :emphasize-lines: 26-31
212
213
214To run this scenario, use the following command::
215
216 NS_LOG=CustomApp ./waf --run=ndn-simple-with-custom-app
217
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -0700218
219Producer example (Interest hijacker)
220^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
221
222The following code demonstrates how to implement a basic producer application that "hijacks" all incoming Interests.
223
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800224Header file ``examples/custom-apps/hijacker.h``:
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -0700225
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800226.. literalinclude:: ../../examples/custom-apps/hijacker.h
227 :language: c++
228 :linenos:
229 :lines: 21-
230
231Source file ``examples/custom-apps/hijacker.cc``:
232
233.. literalinclude:: ../../examples/custom-apps/hijacker.cc
234 :language: c++
235 :linenos:
236 :lines: 21-
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -0700237
238
239After defining this class, you can use it with :ndnsim:`ndn::AppHelper`. For example:
240
241.. code-block:: c++
242
243 ...
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800244 ndn::AppHelper producerHelper ("Hijacker");
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -0700245 producerHelper.Install (producerNode);
246 ...
247
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800248Dumb requester
249^^^^^^^^^^^^^^
250
251This application continually requests the same Data packet.
252
253Header file ``examples/custom-apps/dumb-requester.h``:
254
255.. literalinclude:: ../../examples/custom-apps/dumb-requester.h
256 :language: c++
257 :linenos:
258 :lines: 21-
259
260Source file ``examples/custom-apps/dumb-requester.cc``:
261
262.. literalinclude:: ../../examples/custom-apps/dumb-requester.cc
263 :language: c++
264 :linenos:
265 :lines: 21-
266
Alexander Afanasyev13800102012-12-25 00:30:31 -0800267