Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 1 | .. _applications: |
| 2 | |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 3 | ndnSIM applications |
| 4 | =================== |
| 5 | |
| 6 | ndnSIM includes a few reference applications that can be used as a base for NDN simulations. |
| 7 | |
| 8 | Reference applications |
| 9 | ++++++++++++++++++++++ |
| 10 | |
Alexander Afanasyev | 5b054aa | 2012-08-13 18:56:17 -0700 | [diff] [blame] | 11 | ConsumerCbr |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 12 | ^^^^^^^^^^^ |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 13 | |
Alexander Afanasyev | 5b054aa | 2012-08-13 18:56:17 -0700 | [diff] [blame] | 14 | :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] | 15 | |
| 16 | .. code-block:: c++ |
| 17 | |
| 18 | // Create application using the app helper |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 19 | AppHelper helper("ns3::ndn::ConsumerCbr"); |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 20 | |
| 21 | This applications has the following attributes: |
| 22 | |
Alexander Afanasyev | 1380010 | 2012-12-25 00:30:31 -0800 | [diff] [blame] | 23 | * ``Frequency`` |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 24 | |
| 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 Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 33 | helper.SetAttribute("Frequency", DoubleValue (1.0)); |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 34 | |
Alexander Afanasyev | 1380010 | 2012-12-25 00:30:31 -0800 | [diff] [blame] | 35 | * ``Randomize`` |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 36 | |
| 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 Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 41 | |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 42 | - ``"none"``: no randomization |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 43 | |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 44 | - ``"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 Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 51 | helper.SetAttribute("Randomize", StringValue("uniform")); |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 52 | |
Alexander Afanasyev | 1380010 | 2012-12-25 00:30:31 -0800 | [diff] [blame] | 53 | ConsumerZipfMandelbrot |
| 54 | ^^^^^^^^^^^^^^^^^^^^^^ |
| 55 | |
| 56 | .. note:: |
| 57 | Author: Xiaoke Jiang |
| 58 | |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 59 | An app that requests contents (names in the requests) following Zipf-Mandelbrot distribution (number of Content frequency Distribution). |
Alexander Afanasyev | 1380010 | 2012-12-25 00:30:31 -0800 | [diff] [blame] | 60 | This class is a subclass of :ndnsim:`ConsumerCbr`. |
| 61 | |
| 62 | .. code-block:: c++ |
| 63 | |
| 64 | // Create application using the app helper |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 65 | ndn::AppHelper helper("ns3::ndn::ConsumerZipfMandelbrot"); |
Alexander Afanasyev | 1380010 | 2012-12-25 00:30:31 -0800 | [diff] [blame] | 66 | |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 67 | ``Frequency`` and ``Randomize`` attributes can be used in the same way as in the base :ndnsim:`ConsumerCbr` applications. |
Alexander Afanasyev | 1380010 | 2012-12-25 00:30:31 -0800 | [diff] [blame] | 68 | |
| 69 | Additional 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 | |
| 79 | 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) |
| 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 Afanasyev | 5b054aa | 2012-08-13 18:56:17 -0700 | [diff] [blame] | 94 | ConsumerBatches |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 95 | ^^^^^^^^^^^^^^^^^^^ |
| 96 | |
Alexander Afanasyev | 5b054aa | 2012-08-13 18:56:17 -0700 | [diff] [blame] | 97 | :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] | 98 | |
| 99 | .. code-block:: c++ |
| 100 | |
| 101 | // Create application using the app helper |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 102 | ndn::AppHelper consumerHelper("ns3::ndn::ConsumerBatches"); |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 103 | |
| 104 | This applications has the following attributes: |
| 105 | |
Alexander Afanasyev | 1380010 | 2012-12-25 00:30:31 -0800 | [diff] [blame] | 106 | * ``Batches`` |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 107 | |
| 108 | .. note:: |
| 109 | default: Empty |
| 110 | |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 111 | Specify exact pattern of Interest packets, specifying when and how many Interest packets should be sent. |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 112 | The following example defines that 1 Interest should be requested at time 1s, 5 Interests at time 5s, and 2 Interests at time 10s.: |
| 113 | |
| 114 | .. code-block:: c++ |
| 115 | |
| 116 | // Set attribute using the app helper |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 117 | helper.SetAttribute("Batches", StringValue("1s 1 2s 5 10s 2")); |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 118 | |
| 119 | |
Alexander Afanasyev | 5b054aa | 2012-08-13 18:56:17 -0700 | [diff] [blame] | 120 | ConsumerWindow |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 121 | ^^^^^^^^^^^^^^^^^^ |
| 122 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 123 | :ndnsim:`ConsumerWindow` is an application generating a variable rate Interest traffic. It implements a simple sliding-window-based Interest generation mechanism. |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 124 | |
| 125 | .. code-block:: c++ |
| 126 | |
| 127 | // Create application using the app helper |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 128 | AppHelper consumerHelper("ns3::ndn::ConsumerWindow"); |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 129 | |
| 130 | |
| 131 | This applications has the following attributes: |
| 132 | |
Alexander Afanasyev | 1380010 | 2012-12-25 00:30:31 -0800 | [diff] [blame] | 133 | * ``Window`` |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 134 | |
| 135 | .. note:: |
| 136 | default: ``1`` |
| 137 | |
| 138 | Initial number of Interests that will be send out without waiting for the data (number of outstanding Interests) |
| 139 | |
Alexander Afanasyev | 1380010 | 2012-12-25 00:30:31 -0800 | [diff] [blame] | 140 | * ``PayloadSize`` |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 141 | |
| 142 | .. note:: |
| 143 | default: ``1040`` |
| 144 | |
| 145 | Expected size of the Data payload (necessary only when Size is specified) |
| 146 | |
Alexander Afanasyev | 1380010 | 2012-12-25 00:30:31 -0800 | [diff] [blame] | 147 | * ``Size`` |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 148 | |
| 149 | .. note:: |
| 150 | default: ``-1`` |
| 151 | |
| 152 | Amount of data to be requested (will stop issuing Interests after ``Size`` data is received) |
| 153 | |
Alexander Afanasyev | d4e97b3 | 2012-06-04 15:09:50 -0700 | [diff] [blame] | 154 | 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] | 155 | |
Alexander Afanasyev | 5b054aa | 2012-08-13 18:56:17 -0700 | [diff] [blame] | 156 | Producer |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 157 | ^^^^^^^^^^^^ |
| 158 | |
Alexander Afanasyev | 5b054aa | 2012-08-13 18:56:17 -0700 | [diff] [blame] | 159 | :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] | 160 | |
| 161 | .. code-block:: c++ |
| 162 | |
| 163 | // Create application using the app helper |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 164 | AppHelper consumerHelper("ns3::ndn::Producer"); |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 165 | |
Alexander Afanasyev | 71278d4 | 2012-12-12 19:16:54 -0800 | [diff] [blame] | 166 | .. _Custom applications: |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 167 | |
| 168 | Custom applications |
| 169 | +++++++++++++++++++ |
| 170 | |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 171 | Applications interact with the core of the system using :ndnsim:`AppFace` realization of Face abstraction. |
Alexander Afanasyev | 5b054aa | 2012-08-13 18:56:17 -0700 | [diff] [blame] | 172 | 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] | 173 | |
Alexander Afanasyev | 5b054aa | 2012-08-13 18:56:17 -0700 | [diff] [blame] | 174 | .. Base App class |
Alexander Afanasyev | d4e97b3 | 2012-06-04 15:09:50 -0700 | [diff] [blame] | 175 | .. ^^^^^^^^^^^^^^^^^^ |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 176 | |
| 177 | |
Alexander Afanasyev | 6dbacda | 2012-10-23 17:20:18 -0700 | [diff] [blame] | 178 | Customer example |
| 179 | ^^^^^^^^^^^^^^^^ |
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 | 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] | 182 | |
Alexander Afanasyev | 71278d4 | 2012-12-12 19:16:54 -0800 | [diff] [blame] | 183 | When this application starts it sets "interest filter" (install FIB entry) for /prefix/sub, as well as sends Interest for this prefix. |
| 184 | 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] | 185 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 186 | For 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 Afanasyev | d4e97b3 | 2012-06-04 15:09:50 -0700 | [diff] [blame] | 187 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 188 | Header file ``examples/ndn-custom-apps/custom-app.hpp``: |
Alexander Afanasyev | d4e97b3 | 2012-06-04 15:09:50 -0700 | [diff] [blame] | 189 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 190 | .. literalinclude:: ../../examples/ndn-custom-apps/custom-app.hpp |
Alexander Afanasyev | 71278d4 | 2012-12-12 19:16:54 -0800 | [diff] [blame] | 191 | :language: c++ |
| 192 | :linenos: |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 193 | :lines: 20-28,39- |
Alexander Afanasyev | d4e97b3 | 2012-06-04 15:09:50 -0700 | [diff] [blame] | 194 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 195 | Source file ``examples/ndn-custom-apps/custom-app.cpp``: |
Alexander Afanasyev | d4e97b3 | 2012-06-04 15:09:50 -0700 | [diff] [blame] | 196 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 197 | .. literalinclude:: ../../examples/ndn-custom-apps/custom-app.cpp |
Alexander Afanasyev | 71278d4 | 2012-12-12 19:16:54 -0800 | [diff] [blame] | 198 | :language: c++ |
| 199 | :linenos: |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 200 | :lines: 20- |
Alexander Afanasyev | d4e97b3 | 2012-06-04 15:09:50 -0700 | [diff] [blame] | 201 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 202 | Example how to use custom app in a scenario (``ndn-simple-with-custom-app.cpp``): |
Alexander Afanasyev | d4e97b3 | 2012-06-04 15:09:50 -0700 | [diff] [blame] | 203 | |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 204 | .. * +------+ <-----> (CustomApp1) |
| 205 | .. * | Node | |
Alexander Afanasyev | 71278d4 | 2012-12-12 19:16:54 -0800 | [diff] [blame] | 206 | .. * +------+ <-----> (CustomApp2) |
| 207 | .. * |
Alexander Afanasyev | d4e97b3 | 2012-06-04 15:09:50 -0700 | [diff] [blame] | 208 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 209 | .. literalinclude:: ../../examples/ndn-custom-apps.cpp |
Alexander Afanasyev | 71278d4 | 2012-12-12 19:16:54 -0800 | [diff] [blame] | 210 | :language: c++ |
| 211 | :linenos: |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 212 | :lines: 20-27,37- |
Alexander Afanasyev | 71278d4 | 2012-12-12 19:16:54 -0800 | [diff] [blame] | 213 | |
| 214 | To run this scenario, use the following command:: |
| 215 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 216 | NS_LOG=CustomApp ./waf --run=ndn-custom-apps |
Alexander Afanasyev | 71278d4 | 2012-12-12 19:16:54 -0800 | [diff] [blame] | 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 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 224 | Header file ``examples/ndn-custom-apps/hijacker.hpp``: |
Alexander Afanasyev | 6dbacda | 2012-10-23 17:20:18 -0700 | [diff] [blame] | 225 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 226 | .. literalinclude:: ../../examples/ndn-custom-apps/hijacker.hpp |
Alexander Afanasyev | 71278d4 | 2012-12-12 19:16:54 -0800 | [diff] [blame] | 227 | :language: c++ |
| 228 | :linenos: |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 229 | :lines: 20- |
Alexander Afanasyev | 71278d4 | 2012-12-12 19:16:54 -0800 | [diff] [blame] | 230 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 231 | Source file ``examples/ndn-custom-apps/hijacker.cpp``: |
Alexander Afanasyev | 71278d4 | 2012-12-12 19:16:54 -0800 | [diff] [blame] | 232 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 233 | .. literalinclude:: ../../examples/ndn-custom-apps/hijacker.cpp |
Alexander Afanasyev | 71278d4 | 2012-12-12 19:16:54 -0800 | [diff] [blame] | 234 | :language: c++ |
| 235 | :linenos: |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 236 | :lines: 20- |
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 | ... |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 244 | ndn::AppHelper producerHelper("Hijacker"); |
| 245 | producerHelper.Install(producerNode); |
Alexander Afanasyev | 6dbacda | 2012-10-23 17:20:18 -0700 | [diff] [blame] | 246 | ... |