blob: bef7395aa89745237042012d31dadd2684682eb0 [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
21* Frequency
22
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
33* Randomize
34
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 Afanasyev5b054aa2012-08-13 18:56:17 -070051ConsumerBatches
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070052^^^^^^^^^^^^^^^^^^^
53
Alexander Afanasyev5b054aa2012-08-13 18:56:17 -070054: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 -070055
56.. code-block:: c++
57
58 // Create application using the app helper
Alexander Afanasyev5b054aa2012-08-13 18:56:17 -070059 ndn::AppHelper consumerHelper ("ns3::ndn::ConsumerBatches");
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070060
61This applications has the following attributes:
62
63* Batches
64
65 .. note::
66 default: Empty
67
68 Specify exact pattern of Interest packets, specifying when and how many Interest packets should be sent.
69 The following example defines that 1 Interest should be requested at time 1s, 5 Interests at time 5s, and 2 Interests at time 10s.:
70
71 .. code-block:: c++
72
73 // Set attribute using the app helper
74 helper.SetAttribute ("Batches", StringValue ("1s 1 2s 5 10s 2"));
75
76
Alexander Afanasyev5b054aa2012-08-13 18:56:17 -070077ConsumerWindow
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070078^^^^^^^^^^^^^^^^^^
79
Alexander Afanasyev5b054aa2012-08-13 18:56:17 -070080: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 -070081
82.. code-block:: c++
83
84 // Create application using the app helper
Alexander Afanasyev5b054aa2012-08-13 18:56:17 -070085 ndn::AppHelper consumerHelper ("ns3::ndn::ConsumerWindow");
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070086
87
88This applications has the following attributes:
89
90* Window
91
92 .. note::
93 default: ``1``
94
95 Initial number of Interests that will be send out without waiting for the data (number of outstanding Interests)
96
97* PayloadSize
98
99 .. note::
100 default: ``1040``
101
102 Expected size of the Data payload (necessary only when Size is specified)
103
104* Size
105
106 .. note::
107 default: ``-1``
108
109 Amount of data to be requested (will stop issuing Interests after ``Size`` data is received)
110
Alexander Afanasyevd4e97b32012-06-04 15:09:50 -0700111 If ``Size`` is set to -1, Interests will be requested till the end of the simulation.
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700112
Alexander Afanasyev5b054aa2012-08-13 18:56:17 -0700113Producer
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700114^^^^^^^^^^^^
115
Alexander Afanasyev5b054aa2012-08-13 18:56:17 -0700116: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 -0700117
118.. code-block:: c++
119
120 // Create application using the app helper
Alexander Afanasyev5b054aa2012-08-13 18:56:17 -0700121 ndn::AppHelper consumerHelper ("ns3::ndn::Producer");
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700122
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800123.. _Custom applications:
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700124
125Custom applications
126+++++++++++++++++++
127
Alexander Afanasyev5b054aa2012-08-13 18:56:17 -0700128Applications interact with the core of the system using :ndnsim:`AppFace` realization of Face abstraction.
129To 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 -0700130
Alexander Afanasyev5b054aa2012-08-13 18:56:17 -0700131.. Base App class
Alexander Afanasyevd4e97b32012-06-04 15:09:50 -0700132.. ^^^^^^^^^^^^^^^^^^
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700133
134
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -0700135Customer example
136^^^^^^^^^^^^^^^^
Alexander Afanasyevd4e97b32012-06-04 15:09:50 -0700137
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800138The 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 -0700139
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800140When this application starts it sets "interest filter" (install FIB entry) for /prefix/sub, as well as sends Interest for this prefix.
141When an Interest is received, it is replied with a ContentObject with 1024-byte fake payload.
Alexander Afanasyevd4e97b32012-06-04 15:09:50 -0700142
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800143For 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 -0700144
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800145Header file ``examples/custom-apps/custom-app.h``:
Alexander Afanasyevd4e97b32012-06-04 15:09:50 -0700146
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800147.. literalinclude:: ../../examples/custom-apps/custom-app.h
148 :language: c++
149 :linenos:
150 :lines: 21-29,40-
Alexander Afanasyevd4e97b32012-06-04 15:09:50 -0700151
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800152Source file ``examples/custom-apps/custom-app.cc``:
Alexander Afanasyevd4e97b32012-06-04 15:09:50 -0700153
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800154.. literalinclude:: ../../examples/custom-apps/custom-app.cc
155 :language: c++
156 :linenos:
157 :lines: 21-
Alexander Afanasyevd4e97b32012-06-04 15:09:50 -0700158
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800159Example how to use custom app in a scenario (``ndn-simple-with-custom-app.cc``):
Alexander Afanasyevd4e97b32012-06-04 15:09:50 -0700160
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800161 .. * +------+ <-----> (CustomApp1)
162 .. * | Node |
163 .. * +------+ <-----> (CustomApp2)
164 .. *
Alexander Afanasyevd4e97b32012-06-04 15:09:50 -0700165
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800166.. literalinclude:: ../../examples/ndn-simple-with-custom-app.cc
167 :language: c++
168 :linenos:
169 :lines: 21-28,39-
170 :emphasize-lines: 26-31
171
172
173To run this scenario, use the following command::
174
175 NS_LOG=CustomApp ./waf --run=ndn-simple-with-custom-app
176
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -0700177
178Producer example (Interest hijacker)
179^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
180
181The following code demonstrates how to implement a basic producer application that "hijacks" all incoming Interests.
182
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800183Header file ``examples/custom-apps/hijacker.h``:
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -0700184
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800185.. literalinclude:: ../../examples/custom-apps/hijacker.h
186 :language: c++
187 :linenos:
188 :lines: 21-
189
190Source file ``examples/custom-apps/hijacker.cc``:
191
192.. literalinclude:: ../../examples/custom-apps/hijacker.cc
193 :language: c++
194 :linenos:
195 :lines: 21-
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -0700196
197
198After defining this class, you can use it with :ndnsim:`ndn::AppHelper`. For example:
199
200.. code-block:: c++
201
202 ...
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800203 ndn::AppHelper producerHelper ("Hijacker");
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -0700204 producerHelper.Install (producerNode);
205 ...
206
Alexander Afanasyev71278d42012-12-12 19:16:54 -0800207Dumb requester
208^^^^^^^^^^^^^^
209
210This application continually requests the same Data packet.
211
212Header file ``examples/custom-apps/dumb-requester.h``:
213
214.. literalinclude:: ../../examples/custom-apps/dumb-requester.h
215 :language: c++
216 :linenos:
217 :lines: 21-
218
219Source file ``examples/custom-apps/dumb-requester.cc``:
220
221.. literalinclude:: ../../examples/custom-apps/dumb-requester.cc
222 :language: c++
223 :linenos:
224 :lines: 21-
225