Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 1 | ndnSIM applications |
| 2 | =================== |
| 3 | |
| 4 | ndnSIM includes a few reference applications that can be used as a base for NDN simulations. |
| 5 | |
| 6 | Reference applications |
| 7 | ++++++++++++++++++++++ |
| 8 | |
Alexander Afanasyev | 5b054aa | 2012-08-13 18:56:17 -0700 | [diff] [blame] | 9 | ConsumerCbr |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 10 | ^^^^^^^^^^^^^^^ |
| 11 | |
Alexander Afanasyev | 5b054aa | 2012-08-13 18:56:17 -0700 | [diff] [blame] | 12 | :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 Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 13 | |
| 14 | .. code-block:: c++ |
| 15 | |
| 16 | // Create application using the app helper |
Alexander Afanasyev | 5b054aa | 2012-08-13 18:56:17 -0700 | [diff] [blame] | 17 | ndn::AppHelper helper ("ns3::ndn::ConsumerCbr"); |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 18 | |
| 19 | This applications has the following attributes: |
| 20 | |
Alexander Afanasyev | 1380010 | 2012-12-25 00:30:31 -0800 | [diff] [blame] | 21 | * ``Frequency`` |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 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 | |
Alexander Afanasyev | 1380010 | 2012-12-25 00:30:31 -0800 | [diff] [blame] | 33 | * ``Randomize`` |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 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 Afanasyev | 1380010 | 2012-12-25 00:30:31 -0800 | [diff] [blame] | 51 | ConsumerZipfMandelbrot |
| 52 | ^^^^^^^^^^^^^^^^^^^^^^ |
| 53 | |
| 54 | .. note:: |
| 55 | Author: Xiaoke Jiang |
| 56 | |
| 57 | An app that requests contents (names in the requests) following Zipf-Mandelbrot distribution (number of Content frequency Distribution). |
| 58 | This 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 | |
| 67 | Additional 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 | |
| 77 | THE 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 Afanasyev | 5b054aa | 2012-08-13 18:56:17 -0700 | [diff] [blame] | 92 | ConsumerBatches |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 93 | ^^^^^^^^^^^^^^^^^^^ |
| 94 | |
Alexander Afanasyev | 5b054aa | 2012-08-13 18:56:17 -0700 | [diff] [blame] | 95 | :ndnsim:`ConsumerBatches` is an on-off-style application gen- erating a specified number of Interests at specified points of simulation. |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 96 | |
| 97 | .. code-block:: c++ |
| 98 | |
| 99 | // Create application using the app helper |
Alexander Afanasyev | 5b054aa | 2012-08-13 18:56:17 -0700 | [diff] [blame] | 100 | ndn::AppHelper consumerHelper ("ns3::ndn::ConsumerBatches"); |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 101 | |
| 102 | This applications has the following attributes: |
| 103 | |
Alexander Afanasyev | 1380010 | 2012-12-25 00:30:31 -0800 | [diff] [blame] | 104 | * ``Batches`` |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 105 | |
| 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 Afanasyev | 5b054aa | 2012-08-13 18:56:17 -0700 | [diff] [blame] | 118 | ConsumerWindow |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 119 | ^^^^^^^^^^^^^^^^^^ |
| 120 | |
Alexander Afanasyev | 5b054aa | 2012-08-13 18:56:17 -0700 | [diff] [blame] | 121 | :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 Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 122 | |
| 123 | .. code-block:: c++ |
| 124 | |
| 125 | // Create application using the app helper |
Alexander Afanasyev | 5b054aa | 2012-08-13 18:56:17 -0700 | [diff] [blame] | 126 | ndn::AppHelper consumerHelper ("ns3::ndn::ConsumerWindow"); |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 127 | |
| 128 | |
| 129 | This applications has the following attributes: |
| 130 | |
Alexander Afanasyev | 1380010 | 2012-12-25 00:30:31 -0800 | [diff] [blame] | 131 | * ``Window`` |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 132 | |
| 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 Afanasyev | 1380010 | 2012-12-25 00:30:31 -0800 | [diff] [blame] | 138 | * ``PayloadSize`` |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 139 | |
| 140 | .. note:: |
| 141 | default: ``1040`` |
| 142 | |
| 143 | Expected size of the Data payload (necessary only when Size is specified) |
| 144 | |
Alexander Afanasyev | 1380010 | 2012-12-25 00:30:31 -0800 | [diff] [blame] | 145 | * ``Size`` |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 146 | |
| 147 | .. note:: |
| 148 | default: ``-1`` |
| 149 | |
| 150 | Amount of data to be requested (will stop issuing Interests after ``Size`` data is received) |
| 151 | |
Alexander Afanasyev | d4e97b3 | 2012-06-04 15:09:50 -0700 | [diff] [blame] | 152 | If ``Size`` is set to -1, Interests will be requested till the end of the simulation. |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 153 | |
Alexander Afanasyev | 5b054aa | 2012-08-13 18:56:17 -0700 | [diff] [blame] | 154 | Producer |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 155 | ^^^^^^^^^^^^ |
| 156 | |
Alexander Afanasyev | 5b054aa | 2012-08-13 18:56:17 -0700 | [diff] [blame] | 157 | :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 Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 158 | |
| 159 | .. code-block:: c++ |
| 160 | |
| 161 | // Create application using the app helper |
Alexander Afanasyev | 5b054aa | 2012-08-13 18:56:17 -0700 | [diff] [blame] | 162 | ndn::AppHelper consumerHelper ("ns3::ndn::Producer"); |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 163 | |
Alexander Afanasyev | 71278d4 | 2012-12-12 19:16:54 -0800 | [diff] [blame] | 164 | .. _Custom applications: |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 165 | |
| 166 | Custom applications |
| 167 | +++++++++++++++++++ |
| 168 | |
Alexander Afanasyev | 5b054aa | 2012-08-13 18:56:17 -0700 | [diff] [blame] | 169 | Applications interact with the core of the system using :ndnsim:`AppFace` realization of Face abstraction. |
| 170 | To 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 Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 171 | |
Alexander Afanasyev | 5b054aa | 2012-08-13 18:56:17 -0700 | [diff] [blame] | 172 | .. Base App class |
Alexander Afanasyev | d4e97b3 | 2012-06-04 15:09:50 -0700 | [diff] [blame] | 173 | .. ^^^^^^^^^^^^^^^^^^ |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 174 | |
| 175 | |
Alexander Afanasyev | 6dbacda | 2012-10-23 17:20:18 -0700 | [diff] [blame] | 176 | Customer example |
| 177 | ^^^^^^^^^^^^^^^^ |
Alexander Afanasyev | d4e97b3 | 2012-06-04 15:09:50 -0700 | [diff] [blame] | 178 | |
Alexander Afanasyev | 71278d4 | 2012-12-12 19:16:54 -0800 | [diff] [blame] | 179 | The 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 Afanasyev | d4e97b3 | 2012-06-04 15:09:50 -0700 | [diff] [blame] | 180 | |
Alexander Afanasyev | 71278d4 | 2012-12-12 19:16:54 -0800 | [diff] [blame] | 181 | When this application starts it sets "interest filter" (install FIB entry) for /prefix/sub, as well as sends Interest for this prefix. |
| 182 | When an Interest is received, it is replied with a ContentObject with 1024-byte fake payload. |
Alexander Afanasyev | d4e97b3 | 2012-06-04 15:09:50 -0700 | [diff] [blame] | 183 | |
Alexander Afanasyev | 71278d4 | 2012-12-12 19:16:54 -0800 | [diff] [blame] | 184 | For more details refer ``examples/custom-apps/custom-app.h``, ``examples/custom-apps/custom-app.cc`` and API documentation of ndnSIM and NS-3. |
Alexander Afanasyev | d4e97b3 | 2012-06-04 15:09:50 -0700 | [diff] [blame] | 185 | |
Alexander Afanasyev | 71278d4 | 2012-12-12 19:16:54 -0800 | [diff] [blame] | 186 | Header file ``examples/custom-apps/custom-app.h``: |
Alexander Afanasyev | d4e97b3 | 2012-06-04 15:09:50 -0700 | [diff] [blame] | 187 | |
Alexander Afanasyev | 71278d4 | 2012-12-12 19:16:54 -0800 | [diff] [blame] | 188 | .. literalinclude:: ../../examples/custom-apps/custom-app.h |
| 189 | :language: c++ |
| 190 | :linenos: |
| 191 | :lines: 21-29,40- |
Alexander Afanasyev | d4e97b3 | 2012-06-04 15:09:50 -0700 | [diff] [blame] | 192 | |
Alexander Afanasyev | 71278d4 | 2012-12-12 19:16:54 -0800 | [diff] [blame] | 193 | Source file ``examples/custom-apps/custom-app.cc``: |
Alexander Afanasyev | d4e97b3 | 2012-06-04 15:09:50 -0700 | [diff] [blame] | 194 | |
Alexander Afanasyev | 71278d4 | 2012-12-12 19:16:54 -0800 | [diff] [blame] | 195 | .. literalinclude:: ../../examples/custom-apps/custom-app.cc |
| 196 | :language: c++ |
| 197 | :linenos: |
| 198 | :lines: 21- |
Alexander Afanasyev | d4e97b3 | 2012-06-04 15:09:50 -0700 | [diff] [blame] | 199 | |
Alexander Afanasyev | 71278d4 | 2012-12-12 19:16:54 -0800 | [diff] [blame] | 200 | Example how to use custom app in a scenario (``ndn-simple-with-custom-app.cc``): |
Alexander Afanasyev | d4e97b3 | 2012-06-04 15:09:50 -0700 | [diff] [blame] | 201 | |
Alexander Afanasyev | 71278d4 | 2012-12-12 19:16:54 -0800 | [diff] [blame] | 202 | .. * +------+ <-----> (CustomApp1) |
| 203 | .. * | Node | |
| 204 | .. * +------+ <-----> (CustomApp2) |
| 205 | .. * |
Alexander Afanasyev | d4e97b3 | 2012-06-04 15:09:50 -0700 | [diff] [blame] | 206 | |
Alexander Afanasyev | 71278d4 | 2012-12-12 19:16:54 -0800 | [diff] [blame] | 207 | .. 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 | |
| 214 | To run this scenario, use the following command:: |
| 215 | |
| 216 | NS_LOG=CustomApp ./waf --run=ndn-simple-with-custom-app |
| 217 | |
Alexander Afanasyev | 6dbacda | 2012-10-23 17:20:18 -0700 | [diff] [blame] | 218 | |
| 219 | Producer example (Interest hijacker) |
| 220 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 221 | |
| 222 | The following code demonstrates how to implement a basic producer application that "hijacks" all incoming Interests. |
| 223 | |
Alexander Afanasyev | 71278d4 | 2012-12-12 19:16:54 -0800 | [diff] [blame] | 224 | Header file ``examples/custom-apps/hijacker.h``: |
Alexander Afanasyev | 6dbacda | 2012-10-23 17:20:18 -0700 | [diff] [blame] | 225 | |
Alexander Afanasyev | 71278d4 | 2012-12-12 19:16:54 -0800 | [diff] [blame] | 226 | .. literalinclude:: ../../examples/custom-apps/hijacker.h |
| 227 | :language: c++ |
| 228 | :linenos: |
| 229 | :lines: 21- |
| 230 | |
| 231 | Source file ``examples/custom-apps/hijacker.cc``: |
| 232 | |
| 233 | .. literalinclude:: ../../examples/custom-apps/hijacker.cc |
| 234 | :language: c++ |
| 235 | :linenos: |
| 236 | :lines: 21- |
Alexander Afanasyev | 6dbacda | 2012-10-23 17:20:18 -0700 | [diff] [blame] | 237 | |
| 238 | |
| 239 | After defining this class, you can use it with :ndnsim:`ndn::AppHelper`. For example: |
| 240 | |
| 241 | .. code-block:: c++ |
| 242 | |
| 243 | ... |
Alexander Afanasyev | 71278d4 | 2012-12-12 19:16:54 -0800 | [diff] [blame] | 244 | ndn::AppHelper producerHelper ("Hijacker"); |
Alexander Afanasyev | 6dbacda | 2012-10-23 17:20:18 -0700 | [diff] [blame] | 245 | producerHelper.Install (producerNode); |
| 246 | ... |
| 247 | |
Alexander Afanasyev | 71278d4 | 2012-12-12 19:16:54 -0800 | [diff] [blame] | 248 | Dumb requester |
| 249 | ^^^^^^^^^^^^^^ |
| 250 | |
| 251 | This application continually requests the same Data packet. |
| 252 | |
| 253 | Header 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 | |
| 260 | Source 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 Afanasyev | 1380010 | 2012-12-25 00:30:31 -0800 | [diff] [blame] | 267 | |