blob: c35440ec9748f85a01f5e5a6db3c07cfb49db073 [file] [log] [blame]
Alexander Afanasyeve6852122013-01-21 11:54:47 -08001.. _applications:
2
Alexander Afanasyev6315ef72012-06-01 20:56:31 -07003ndnSIM applications
4===================
5
6ndnSIM includes a few reference applications that can be used as a base for NDN simulations.
7
8Reference applications
9++++++++++++++++++++++
10
Alexander Afanasyev5b054aa2012-08-13 18:56:17 -070011ConsumerCbr
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080012^^^^^^^^^^^
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070013
Alexander Afanasyev5b054aa2012-08-13 18:56:17 -070014: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 -070015
16.. code-block:: c++
17
18 // Create application using the app helper
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080019 AppHelper helper("ns3::ndn::ConsumerCbr");
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070020
21This applications has the following attributes:
22
Alexander Afanasyev13800102012-12-25 00:30:31 -080023* ``Frequency``
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070024
25 .. note::
26 default: ``1.0`` (1 per second)
27
28 Either exact (for contant version) or expected (for randomized version) frequency with which Interests are generated
29
30 .. code-block:: c++
31
32 // Set attribute using the app helper
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080033 helper.SetAttribute("Frequency", DoubleValue (1.0));
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070034
Alexander Afanasyev13800102012-12-25 00:30:31 -080035* ``Randomize``
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070036
37 .. note::
38 default: ``"none"``
39
40 Specify whether to do randomization for inter-Interest gap or not. The following variants are currently supported:
Alexander Afanasyeve6852122013-01-21 11:54:47 -080041
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070042 - ``"none"``: no randomization
Alexander Afanasyeve6852122013-01-21 11:54:47 -080043
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070044 - ``"uniform"``: uniform distribution in range (0, 1/Frequency)
45
46 - ``"exponential"``: exponential distribution with mean 1/Frequency
47
48 .. code-block:: c++
49
50 // Set attribute using the app helper
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080051 helper.SetAttribute("Randomize", StringValue("uniform"));
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070052
Alexander Afanasyev13800102012-12-25 00:30:31 -080053ConsumerZipfMandelbrot
54^^^^^^^^^^^^^^^^^^^^^^
55
56.. note::
57 Author: Xiaoke Jiang
58
Alexander Afanasyeve6852122013-01-21 11:54:47 -080059An app that requests contents (names in the requests) following Zipf-Mandelbrot distribution (number of Content frequency Distribution).
Alexander Afanasyev13800102012-12-25 00:30:31 -080060This class is a subclass of :ndnsim:`ConsumerCbr`.
61
62.. code-block:: c++
63
64 // Create application using the app helper
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080065 ndn::AppHelper helper("ns3::ndn::ConsumerZipfMandelbrot");
Alexander Afanasyev13800102012-12-25 00:30:31 -080066
Alexander Afanasyeve6852122013-01-21 11:54:47 -080067``Frequency`` and ``Randomize`` attributes can be used in the same way as in the base :ndnsim:`ConsumerCbr` applications.
Alexander Afanasyev13800102012-12-25 00:30:31 -080068
69Additional attributes:
70
71* ``NumberOfContents``
72
73 .. note::
74 default: 100
75
76 Number of different content (sequence numbers) that will be requested by the applications
77
78
79THE 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)
80
81.. image:: _static/apps/zipf-n100-frq100-duration10.png
82 :alt: Comparsion between simulation and theory with simulation duration 10 seconds
83
84.. image:: _static/apps/zipf-n100-frq100-duration50.png
85 :alt: Comparsion between simulation and theory with simulation duration 50 seconds
86
87.. image:: _static/apps/zipf-n100-frq100-duration100.png
88 :alt: Comparsion between simulation and theory with simulation duration 100 seconds
89
90.. image:: _static/apps/zipf-n100-frq100-duration1000.png
91 :alt: Comparsion between simulation and theory with simulation duration 1000 seconds
92
93
Alexander Afanasyev5b054aa2012-08-13 18:56:17 -070094ConsumerBatches
Alexander Afanasyeva4915ca2016-01-28 11:03:25 -080095^^^^^^^^^^^^^^^
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070096
Alexander Afanasyeva4915ca2016-01-28 11:03:25 -080097:ndnsim:`ConsumerBatches` is an on-off-style application generating a specified number of Interests at specified points of simulation.
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070098
99.. code-block:: c++
100
101 // Create application using the app helper
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800102 ndn::AppHelper consumerHelper("ns3::ndn::ConsumerBatches");
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700103
104This applications has the following attributes:
105
Alexander Afanasyev13800102012-12-25 00:30:31 -0800106* ``Batches``
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700107
108 .. note::
109 default: Empty
110
Alexander Afanasyeve6852122013-01-21 11:54:47 -0800111 Specify exact pattern of Interest packets, specifying when and how many Interest packets should be sent.
Alexander Afanasyeva4915ca2016-01-28 11:03:25 -0800112 The following example defines that 1 Interest should be requested at time 1s, 5 Interests at time 2s, and 2 Interests at time 10s.
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700113
114 .. code-block:: c++
115
116 // Set attribute using the app helper
Alexander Afanasyeva4915ca2016-01-28 11:03:25 -0800117 consumerHelper.SetAttribute("Batches", StringValue("1s 1 2s 5 10s 2"));
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700118
Alexander Afanasyeva4915ca2016-01-28 11:03:25 -0800119 Note that the specified batch of Interests is not sent out at the specified time at once. :ndnsim:`ConsumerBatches` starts each batch at the specified time, while each Interests is separated in time by the estimated retransmission time. For example, the above could result in following Interest sending timeline::
120
121 1s 0 ndn.Consumer:SendPacket(): [INFO ] > Interest for 0
122 2s 0 ndn.Consumer:SendPacket(): [INFO ] > Interest for 1
123 2s 0 ndn.Consumer:SendPacket(): [INFO ] > Interest for 2
124 2.2s 0 ndn.Consumer:SendPacket(): [INFO ] > Interest for 3
125 2.4s 0 ndn.Consumer:SendPacket(): [INFO ] > Interest for 4
126 2.6s 0 ndn.Consumer:SendPacket(): [INFO ] > Interest for 5
127 10s 0 ndn.Consumer:SendPacket(): [INFO ] > Interest for 6
128 10.2s 0 ndn.Consumer:SendPacket(): [INFO ] > Interest for 7
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700129
Alexander Afanasyev5b054aa2012-08-13 18:56:17 -0700130ConsumerWindow
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700131^^^^^^^^^^^^^^^^^^
132
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800133:ndnsim:`ConsumerWindow` is an application generating a variable rate Interest traffic. It implements a simple sliding-window-based Interest generation mechanism.
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700134
135.. code-block:: c++
136
137 // Create application using the app helper
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800138 AppHelper consumerHelper("ns3::ndn::ConsumerWindow");
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700139
140
141This applications has the following attributes:
142
Alexander Afanasyev13800102012-12-25 00:30:31 -0800143* ``Window``
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700144
145 .. note::
146 default: ``1``
147
148 Initial number of Interests that will be send out without waiting for the data (number of outstanding Interests)
149
Alexander Afanasyev13800102012-12-25 00:30:31 -0800150* ``PayloadSize``
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700151
152 .. note::
153 default: ``1040``
154
155 Expected size of the Data payload (necessary only when Size is specified)
156
Alexander Afanasyev13800102012-12-25 00:30:31 -0800157* ``Size``
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700158
159 .. note::
160 default: ``-1``
161
162 Amount of data to be requested (will stop issuing Interests after ``Size`` data is received)
163
Alexander Afanasyevd4e97b32012-06-04 15:09:50 -0700164 If ``Size`` is set to -1, Interests will be requested till the end of the simulation.
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700165
Eric Newberry8821d3e2018-07-04 16:42:01 -0400166ConsumerPcon
167^^^^^^^^^^^^^^^^
168
169:ndnsim:`ConsumerPcon` is an application generating variable rate Interest traffic. It implements a sliding-window-based Interest generation mechanism that adjusts window size using the PCON congestion control mechanism developed by K. Schneider et al. (https://named-data.net/publications/practical_congestion_control_scheme/). It is derived from :ndnsim:`ConsumerWindow`.
170
171.. code-block:: c++
172
173 // Create application using the app helper
174 AppHelper consumerHelper("ns3::ndn::ConsumerPcon");
175
176The application has the same attributes as :ndnsim:`ConsumerWindow`, in addition to the following:
177
178* ``Beta``
179
180 .. note::
181 default: ``0.5``
182
183 TCP Multiplicative Decrease factor
184
185* ``AddRttSupress``
186
187 .. note::
188 default: ``0.5``
189
190 Minimum number of RTTs (1 + this factor) between window decreases
191
192* ``ShouldReactToCongestionMarks``
193
194 .. note::
195 default: ``true``
196
197 If true, process received congestion marks; otherwise, ignore them
198
199* ``ShouldUseCwa``
200
201 .. note::
202 default: ``true``
203
204 If true, use Conservative Window Adaptation
205
Alexander Afanasyev5b054aa2012-08-13 18:56:17 -0700206Producer
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700207^^^^^^^^^^^^
208
Alexander Afanasyev5b054aa2012-08-13 18:56:17 -0700209: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 -0700210
211.. code-block:: c++
212
213 // Create application using the app helper
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800214 AppHelper consumerHelper("ns3::ndn::Producer");
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700215
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800216.. _Custom applications:
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700217
218Custom applications
219+++++++++++++++++++
220
spirosmastorakisc09bb402016-10-28 19:16:58 -0700221Applications interact with the core of the system using :ndnsim:`AppLinkService` realization of link service abstraction.
222To simplify implementation of specific NDN application, ndnSIM provides a base :ndnsim:`App` class that takes care of creating :ndnsim:`AppLinkService` 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 -0700223
Alexander Afanasyev5b054aa2012-08-13 18:56:17 -0700224.. Base App class
Alexander Afanasyevd4e97b32012-06-04 15:09:50 -0700225.. ^^^^^^^^^^^^^^^^^^
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700226
227
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -0700228Customer example
229^^^^^^^^^^^^^^^^
Alexander Afanasyevd4e97b32012-06-04 15:09:50 -0700230
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800231The 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 -0700232
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800233When this application starts it sets "interest filter" (install FIB entry) for /prefix/sub, as well as sends Interest for this prefix.
234When an Interest is received, it is replied with a ContentObject with 1024-byte fake payload.
Alexander Afanasyevd4e97b32012-06-04 15:09:50 -0700235
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800236For more details refer ``examples/ndn-custom-apps/custom-app.hpp``, ``examples/ndn-custom-apps/custom-app.cpp`` and API documentation of ndnSIM and NS-3.
Alexander Afanasyevd4e97b32012-06-04 15:09:50 -0700237
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800238Header file ``examples/ndn-custom-apps/custom-app.hpp``:
Alexander Afanasyevd4e97b32012-06-04 15:09:50 -0700239
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800240.. literalinclude:: ../../examples/ndn-custom-apps/custom-app.hpp
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800241 :language: c++
242 :linenos:
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800243 :lines: 20-28,39-
Alexander Afanasyevd4e97b32012-06-04 15:09:50 -0700244
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800245Source file ``examples/ndn-custom-apps/custom-app.cpp``:
Alexander Afanasyevd4e97b32012-06-04 15:09:50 -0700246
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800247.. literalinclude:: ../../examples/ndn-custom-apps/custom-app.cpp
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800248 :language: c++
249 :linenos:
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800250 :lines: 20-
Alexander Afanasyevd4e97b32012-06-04 15:09:50 -0700251
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800252Example how to use custom app in a scenario (``ndn-simple-with-custom-app.cpp``):
Alexander Afanasyevd4e97b32012-06-04 15:09:50 -0700253
Alexander Afanasyeve6852122013-01-21 11:54:47 -0800254 .. * +------+ <-----> (CustomApp1)
255 .. * | Node |
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800256 .. * +------+ <-----> (CustomApp2)
257 .. *
Alexander Afanasyevd4e97b32012-06-04 15:09:50 -0700258
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800259.. literalinclude:: ../../examples/ndn-custom-apps.cpp
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800260 :language: c++
261 :linenos:
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800262 :lines: 20-27,37-
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800263
264To run this scenario, use the following command::
265
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800266 NS_LOG=CustomApp ./waf --run=ndn-custom-apps
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800267
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -0700268
269Producer example (Interest hijacker)
270^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
271
272The following code demonstrates how to implement a basic producer application that "hijacks" all incoming Interests.
273
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800274Header file ``examples/ndn-custom-apps/hijacker.hpp``:
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -0700275
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800276.. literalinclude:: ../../examples/ndn-custom-apps/hijacker.hpp
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800277 :language: c++
278 :linenos:
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800279 :lines: 20-
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800280
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800281Source file ``examples/ndn-custom-apps/hijacker.cpp``:
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800282
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800283.. literalinclude:: ../../examples/ndn-custom-apps/hijacker.cpp
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800284 :language: c++
285 :linenos:
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800286 :lines: 20-
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -0700287
288
289After defining this class, you can use it with :ndnsim:`ndn::AppHelper`. For example:
290
291.. code-block:: c++
292
293 ...
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800294 ndn::AppHelper producerHelper("Hijacker");
295 producerHelper.Install(producerNode);
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -0700296 ...