Alexander Afanasyev | 4d32516 | 2012-06-01 12:28:50 -0700 | [diff] [blame] | 1 | Examples |
| 2 | ======== |
| 3 | |
Alexander Afanasyev | 6dbacda | 2012-10-23 17:20:18 -0700 | [diff] [blame] | 4 | .. _simple-scenario: |
| 5 | |
Alexander Afanasyev | 4d32516 | 2012-06-01 12:28:50 -0700 | [diff] [blame] | 6 | Simple scenario |
| 7 | --------------- |
| 8 | |
Alexander Afanasyev | b8d14ad | 2012-08-09 13:19:37 -0700 | [diff] [blame] | 9 | The first example (``ndn-simple.cc``) shows very basics of ndnSIM. In the simulated |
Alexander Afanasyev | 4d32516 | 2012-06-01 12:28:50 -0700 | [diff] [blame] | 10 | topology there are 3 nodes, connected with point-to-point links, one |
Alexander Afanasyev | 07b0063 | 2012-06-01 23:46:47 -0700 | [diff] [blame] | 11 | NDN consumer, and one NDN producer: |
Alexander Afanasyev | 4d32516 | 2012-06-01 12:28:50 -0700 | [diff] [blame] | 12 | |
Alexander Afanasyev | 07b0063 | 2012-06-01 23:46:47 -0700 | [diff] [blame] | 13 | .. aafig:: |
| 14 | :aspect: 60 |
| 15 | :scale: 120 |
Alexander Afanasyev | 4d32516 | 2012-06-01 12:28:50 -0700 | [diff] [blame] | 16 | |
Alexander Afanasyev | 07b0063 | 2012-06-01 23:46:47 -0700 | [diff] [blame] | 17 | +----------+ +--------+ +----------+ |
| 18 | | | 1Mbps | | 1Mbps | | |
| 19 | | Consumer |<-------------->| Router |<-------------->| Producer | |
| 20 | | | 10ms | | 10ms | | |
| 21 | +----------+ +--------+ +----------+ |
Alexander Afanasyev | 4d32516 | 2012-06-01 12:28:50 -0700 | [diff] [blame] | 22 | |
Alexander Afanasyev | f6807a5 | 2012-08-10 18:11:43 -0700 | [diff] [blame] | 23 | Consumer is simulated using :ndnsim:`ConsumerCbr` reference application and generates Interests towards the producer |
Alexander Afanasyev | 07b0063 | 2012-06-01 23:46:47 -0700 | [diff] [blame] | 24 | with frequency of 10 Interests per second (see :doc:`applications`). |
| 25 | |
Alexander Afanasyev | f6807a5 | 2012-08-10 18:11:43 -0700 | [diff] [blame] | 26 | Producer is simulated using :ndnsim:`Producer` class, which is used to satisfy all incoming Interests with virtual payload data (1024 bytes). |
Alexander Afanasyev | 07b0063 | 2012-06-01 23:46:47 -0700 | [diff] [blame] | 27 | |
| 28 | FIB on every node is populated using default routes (see :doc:`helpers`). |
Alexander Afanasyev | 4d32516 | 2012-06-01 12:28:50 -0700 | [diff] [blame] | 29 | |
| 30 | The following code represents all that is necessary to run such a |
| 31 | simple scenario |
| 32 | |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 33 | .. literalinclude:: ../../examples/ndn-simple.cc |
| 34 | :language: c++ |
| 35 | :linenos: |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 36 | :lines: 20-27,48- |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 37 | :emphasize-lines: 30-33,37-49 |
Alexander Afanasyev | 07b0063 | 2012-06-01 23:46:47 -0700 | [diff] [blame] | 38 | |
Alexander Afanasyev | b8d14ad | 2012-08-09 13:19:37 -0700 | [diff] [blame] | 39 | If this code is placed into ``scratch/ndn-simple.cc`` and NS-3 is compiled in debug mode, you can run and see progress of the |
Alexander Afanasyev | 07b0063 | 2012-06-01 23:46:47 -0700 | [diff] [blame] | 40 | simulation using the following command (in optimized mode nothing will be printed out):: |
| 41 | |
Alexander Afanasyev | f6807a5 | 2012-08-10 18:11:43 -0700 | [diff] [blame] | 42 | NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-simple |
Alexander Afanasyev | 07b0063 | 2012-06-01 23:46:47 -0700 | [diff] [blame] | 43 | |
| 44 | |
Alexander Afanasyev | 6dbacda | 2012-10-23 17:20:18 -0700 | [diff] [blame] | 45 | .. _9-node-grid-example: |
| 46 | |
Alexander Afanasyev | 07b0063 | 2012-06-01 23:46:47 -0700 | [diff] [blame] | 47 | 9-node grid example |
| 48 | ------------------- |
| 49 | |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 50 | This scenario (``ndn-grid.cc``) simulates a grid topology, which is constructed using PointToPointLayout NS-3 module |
Alexander Afanasyev | 07b0063 | 2012-06-01 23:46:47 -0700 | [diff] [blame] | 51 | |
| 52 | .. aafig:: |
| 53 | :aspect: 60 |
| 54 | :scale: 120 |
| 55 | |
| 56 | /--------\ /-\ /-\ |
| 57 | |Consumer|<---->| |<------->| | |
| 58 | \--------/ \-/ \-/ |
| 59 | ^ ^ ^ |
| 60 | | | | 1Mbps/10ms delay |
| 61 | v v v |
| 62 | /-\ /-\ /-\ |
| 63 | | |<-------->| |<------->| | |
| 64 | \-/ \-/ \-/ |
| 65 | ^ ^ ^ |
| 66 | | | | |
| 67 | v v v |
| 68 | /-\ /-\ /--------\ |
| 69 | | |<-------->| |<---->|Producer| |
| 70 | \-/ \-/ \--------/ |
| 71 | |
| 72 | |
Alexander Afanasyev | f6807a5 | 2012-08-10 18:11:43 -0700 | [diff] [blame] | 73 | FIB is populated using :ndnsim:`GlobalRoutingHelper` (see :doc:`helpers`). |
Alexander Afanasyev | 07b0063 | 2012-06-01 23:46:47 -0700 | [diff] [blame] | 74 | |
Alexander Afanasyev | f6807a5 | 2012-08-10 18:11:43 -0700 | [diff] [blame] | 75 | Consumer is simulated using :ndnsim:`ConsumerCbr` reference application and generates Interests towards the producer |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 76 | with frequency of 100 interests per second (see :doc:`applications`). |
Alexander Afanasyev | 07b0063 | 2012-06-01 23:46:47 -0700 | [diff] [blame] | 77 | |
Alexander Afanasyev | f6807a5 | 2012-08-10 18:11:43 -0700 | [diff] [blame] | 78 | Producer is simulated using :ndnsim:`Producer` class, which is used to satisfy all incoming Interests with virtual payload data (1024 bytes). |
Alexander Afanasyev | 07b0063 | 2012-06-01 23:46:47 -0700 | [diff] [blame] | 79 | |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 80 | The following code represents all that is necessary to run such a simple scenario |
Alexander Afanasyev | 07b0063 | 2012-06-01 23:46:47 -0700 | [diff] [blame] | 81 | |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 82 | .. literalinclude:: ../../examples/ndn-grid.cc |
| 83 | :language: c++ |
| 84 | :linenos: |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 85 | :lines: 20-27,53- |
| 86 | :emphasize-lines: 28,31-33,35-38,53-57 |
Alexander Afanasyev | 4d32516 | 2012-06-01 12:28:50 -0700 | [diff] [blame] | 87 | |
Alexander Afanasyev | 4d32516 | 2012-06-01 12:28:50 -0700 | [diff] [blame] | 88 | |
Alexander Afanasyev | b8d14ad | 2012-08-09 13:19:37 -0700 | [diff] [blame] | 89 | If this code is placed into ``scratch/ndn-grid.cc`` and NS-3 is compiled in debug mode, you can run and see progress of the |
Alexander Afanasyev | 07b0063 | 2012-06-01 23:46:47 -0700 | [diff] [blame] | 90 | simulation using the following command (in optimized mode nothing will be printed out):: |
| 91 | |
Alexander Afanasyev | f6807a5 | 2012-08-10 18:11:43 -0700 | [diff] [blame] | 92 | NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-grid |
Alexander Afanasyev | 07b0063 | 2012-06-01 23:46:47 -0700 | [diff] [blame] | 93 | |
Alexander Afanasyev | 6dbacda | 2012-10-23 17:20:18 -0700 | [diff] [blame] | 94 | .. _9-node-grid-example-using-topology-plugin: |
| 95 | |
| 96 | 9-node grid example using topology plugin |
| 97 | ----------------------------------------- |
| 98 | |
| 99 | Instead of defining topology directly as in :ref:`simple-scenario` or using specialized helpers as in :ref:`9-node-grid-example`, ndnSIM provides experimental extended versions of TopologyReader classes: :ndnsim:`AnnotatedTopologyReader` and :ndnsim:`RocketfuelWeightsReader`. |
| 100 | |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 101 | While :ndnsim:`RocketfuelWeightsReader` is a specialized version intended to be used with `Rocketfuel <http://www.cs.washington.edu/research/networking/rocketfuel/>`_ topology and link weights files (examples will be provided later), :ndnsim:`AnnotatedTopologyReader` is a more general-use class that uses simple user-readable format. |
| 102 | |
| 103 | :ndnsim:`AnnotatedTopologyReader` expects the following format: |
Alexander Afanasyev | 6dbacda | 2012-10-23 17:20:18 -0700 | [diff] [blame] | 104 | |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 105 | .. literalinclude:: ../../examples/topologies/topo-grid-3x3.txt |
| 106 | :language: bash |
| 107 | :linenos: |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 108 | :lines: 1-2,19- |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 109 | :emphasize-lines: 8,24 |
Alexander Afanasyev | 6dbacda | 2012-10-23 17:20:18 -0700 | [diff] [blame] | 110 | |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 111 | |
| 112 | This scenario (``ndn-grid-topo-plugin.cc``) duplicates the functionality of :ref:`9-node-grid-example` but with the use of :ndnsim:`AnnotatedTopologyReader`. |
| 113 | |
| 114 | .. aafig:: |
| 115 | :aspect: 60 |
| 116 | :scale: 120 |
| 117 | |
| 118 | /--------\ /-\ /-\ |
| 119 | |Consumer|<---->| |<------->| | |
| 120 | \--------/ \-/ \-/ |
| 121 | ^ ^ ^ |
| 122 | | | | 1Mbps/10ms delay |
| 123 | v v v |
| 124 | /-\ /-\ /-\ |
| 125 | | |<-------->| |<------->| | |
| 126 | \-/ \-/ \-/ |
| 127 | ^ ^ ^ |
| 128 | | | | |
| 129 | v v v |
| 130 | /-\ /-\ /--------\ |
| 131 | | |<-------->| |<---->|Producer| |
| 132 | \-/ \-/ \--------/ |
Alexander Afanasyev | 6dbacda | 2012-10-23 17:20:18 -0700 | [diff] [blame] | 133 | |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 134 | .. literalinclude:: ../../examples/ndn-grid-topo-plugin.cc |
| 135 | :language: c++ |
| 136 | :linenos: |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 137 | :lines: 20-26,51- |
| 138 | :emphasize-lines: 14-16,20,27-30 |
Alexander Afanasyev | 6dbacda | 2012-10-23 17:20:18 -0700 | [diff] [blame] | 139 | |
| 140 | As you can see, scenario code became more compact and more readable. |
| 141 | |
| 142 | :ndnsim:`AnnotatedTopologyReader` provides two ways to access topology nodes. |
| 143 | First, you can use the method :ndnsim:`AnnotatedTopologyReader::GetNodes` which returns NodeContainer. |
| 144 | |
| 145 | Alternatively, nodes can be accessed by name using `Names::Find<Node> ("nodename")` call, as in the above example. |
| 146 | For this purpose,:ndnsim:`AnnotatedTopologyReader` automatically registers all created nodes with names specified in topology file. |
| 147 | For more information about `Names` class, please refer to `NS-3 documentation <.. http://www.nsnam.org/doxygen/classns3_1_1_names.html>`_ |
| 148 | . |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 149 | |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 150 | If the topology file is placed into ``src/ndnSIM/examples/topologies/topo-grid-3x3.txt`` and the code is placed into ``scratch/ndn-grid-topo-plugin.cc``, you can run and see progress of the simulation using the following command (in optimized mode nothing will be printed out):: |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 151 | |
| 152 | NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-grid-topo-plugin |
| 153 | |
| 154 | |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 155 | 6-node bottleneck topology |
| 156 | -------------------------- |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 157 | |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 158 | This scenario (``ndn-congestion-topo-plugin.cc``) can be used for congestion-related scenarios |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 159 | |
| 160 | .. aafig:: |
| 161 | :aspect: 60 |
| 162 | :scale: 120 |
| 163 | |
| 164 | /------\ /------\ |
| 165 | | Src1 |<--+ +-->| Dst1 | |
| 166 | \------/ \ / \------/ |
| 167 | \ / |
| 168 | +-->/------\ "bottleneck" /------\<-+ |
| 169 | | Rtr1 |<===============>| Rtr2 | |
| 170 | +-->\------/ \------/<-+ |
| 171 | / \ |
| 172 | /------\ / \ /------\ |
| 173 | | Src2 |<--+ +-->| Dst2 | |
| 174 | \------/ \------/ |
| 175 | |
| 176 | .. literalinclude:: ../../examples/topologies/topo-6-node.txt |
| 177 | :language: bash |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 178 | :linenos: |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 179 | :lines: 1-2,15- |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 180 | :emphasize-lines: 3,13 |
| 181 | |
| 182 | .. literalinclude:: ../../examples/ndn-congestion-topo-plugin.cc |
| 183 | :language: c++ |
| 184 | :linenos: |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 185 | :lines: 20-26,47- |
| 186 | :emphasize-lines: 15,21-22,29-34,41-47,52-62 |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 187 | |
| 188 | .. :lines: 20-25,53- |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 189 | |
| 190 | To run this scenario and see what is happening, use the following command:: |
| 191 | |
| 192 | NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-congestion-topo-plugin |
| 193 | |
| 194 | .. _11-node 2-bottleneck topology with custom forwarding strategy: |
| 195 | |
| 196 | 11-node 2-bottleneck topology with custom forwarding strategy |
| 197 | ------------------------------------------------------------- |
| 198 | |
| 199 | To effectively use the example :ref:`custom strategy <Writing your own custom strategy>`, we need to make sure that FIB entries contain at least two entries. |
| 200 | In the current version of ndnSIM, this can be accomplished using manual route configuration. |
| 201 | |
| 202 | The following example illustrates how the strategy can be used in simulation scenario. |
| 203 | |
| 204 | Let us first define a meaningful topology: |
| 205 | |
| 206 | .. aafig:: |
| 207 | :aspect: 60 |
| 208 | :scale: 120 |
| 209 | |
| 210 | /------\ 0 0 /------\ |
| 211 | | c1 |<-----+ +----->| p1 | |
| 212 | \------/ \ / \------/ |
| 213 | \ /-----\ / |
| 214 | /------\ 0 \ +==>| r12 |<==+ / 0 /------\ |
| 215 | | c2 |<--+ \ / \-----/ \ / +-->| p2 | |
| 216 | \------/ \ \ | | / / \------/ |
| 217 | \ | | 1Mbps links | | / |
| 218 | \ 1 v0 v5 1v 2v 3 / |
| 219 | +->/------\ /------\<-+ |
| 220 | 2| r1 |<===============>| r2 |4 |
| 221 | +->\------/4 0\------/<-+ |
| 222 | / 3^ ^5 \ |
| 223 | / | | \ |
| 224 | /------\ 0 / / \ \ 0 /------\ |
| 225 | | c3 |<--+ / \ +-->| p3 | |
| 226 | \------/ / \ \------/ |
| 227 | / "All consumer-router and" \ |
| 228 | /------\ 0 / "router-producer links are" \ 0 /------\ |
| 229 | | c4 |<-----+ "10Mbps" +---->| p4 | |
| 230 | \------/ \------/ |
| 231 | |
| 232 | "Numbers near nodes denote face IDs. Face ID is assigned based on the order of link" |
| 233 | "definitions in the topology file" |
| 234 | |
| 235 | The corresponding topology file (``topo-11-node-two-bottlenecks.txt``): |
| 236 | |
| 237 | .. literalinclude:: ../../examples/topologies/topo-11-node-two-bottlenecks.txt |
| 238 | :language: bash |
| 239 | :linenos: |
| 240 | :lines: 1-2,28- |
| 241 | |
| 242 | Example simulation (``ndn-congestion-alt-topo-plugin.cc``) scenario that utilizes CustomStrategy forwarding strategy: |
| 243 | |
| 244 | .. literalinclude:: ../../examples/ndn-congestion-alt-topo-plugin.cc |
| 245 | :language: c++ |
| 246 | :linenos: |
| 247 | :lines: 21-28,61- |
| 248 | :emphasize-lines: 16,21,49-50,65-79 |
| 249 | |
| 250 | |
| 251 | To run this scenario and see what is happening, use the following command:: |
| 252 | |
| 253 | NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-congestion-alt-topo-plugin |
| 254 | |
| 255 | You can also run using visualizer module to verify that both bottleneck links are utilized:: |
| 256 | |
| 257 | ./waf --run=ndn-congestion-alt-topo-plugin --visualize |
Alexander Afanasyev | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 258 | |
| 259 | .. _trace example: |
| 260 | |
| 261 | Example of using trace helpers |
| 262 | ------------------------------ |
| 263 | |
| 264 | This example (``ndn-tree-tracers.cc``) demonstrates basic usage of :ref:`trace classes`. |
| 265 | |
| 266 | In this scenario we will use a tree-like topology, where consumers are installed on leaf nodes and producer is in the root of the tree: |
| 267 | |
| 268 | .. aafig:: |
| 269 | :aspect: 60 |
| 270 | :scale: 120 |
| 271 | |
| 272 | /--------\ /--------\ /--------\ /--------\ |
| 273 | |"leaf-1"| |"leaf-2"| |"leaf-3"| |"leaf-4"| |
| 274 | \--------/ \--------/ \--------/ \--------/ |
| 275 | ^ ^ ^ ^ |
| 276 | | | | | |
| 277 | \ / \ / |
| 278 | \ / \ / 10Mbps / 1ms |
| 279 | \ / \ / |
| 280 | | | | | |
| 281 | v v v v |
| 282 | /-------\ /-------\ |
| 283 | |"rtr-1"| |"rtr-2"| |
| 284 | \-------/ \-------/ |
| 285 | ^ ^ |
| 286 | | | |
| 287 | \ / 10 Mpbs / 1ms |
| 288 | +--------\ /--------+ |
| 289 | | | |
| 290 | v v |
| 291 | /--------\ |
| 292 | | "root" | |
| 293 | \--------/ |
| 294 | |
| 295 | The corresponding topology file (``topo-tree.txt``): |
| 296 | |
| 297 | .. literalinclude:: ../../examples/topologies/topo-tree.txt |
| 298 | :language: bash |
| 299 | :linenos: |
| 300 | :lines: 1-2,27- |
| 301 | |
| 302 | Example simulation (``ndn-tree-tracers.cc``) scenario that utilizes trace helpers: |
| 303 | |
| 304 | .. literalinclude:: ../../examples/ndn-tree-tracers.cc |
| 305 | :language: c++ |
| 306 | :linenos: |
| 307 | :lines: 21-34,67- |
| 308 | :emphasize-lines: 7-11,63-67 |
| 309 | |
| 310 | |
| 311 | To run this scenario, use the following command:: |
| 312 | |
| 313 | ./waf --run=ndn-tree-tracers |
| 314 | |
| 315 | The successful run will create ``rate-trace.txt`` and ``aggregate-trace.txt`` files in the current directly, which can be analyzed manually or used as input to some graph/stats packages. |
| 316 | |
| 317 | For example, the following `R script <http://www.r-project.org/>`_ will build a number of nice graphs: |
| 318 | |
| 319 | .. image:: _static/root-rates.png |
| 320 | :alt: Interest/Data packet rates at the root node |
| 321 | :align: right |
| 322 | |
| 323 | .. image:: _static/root-5sec-counts.png |
| 324 | :alt: Interest/Data packet counts at the root node in 5-second intervals |
| 325 | :align: right |
| 326 | |
| 327 | .. literalinclude:: ../../examples/graphs/rate-graph.R |
| 328 | :language: r |
| 329 | :linenos: |
| 330 | |
| 331 | For more information about R and ggplot2, please refer to `R language manual <http://cran.r-project.org/manuals.html>`_, `ggplot2 module manual <http://docs.ggplot2.org/current/>`_. |