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: |
| 36 | :lines: 20-27,50- |
| 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 | 07b0063 | 2012-06-01 23:46:47 -0700 | [diff] [blame] | 76 | with frequency of 10 Interests per second (see :doc:`applications`). |
| 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: |
| 85 | :lines: 20-27,55- |
| 86 | :emphasize-lines: 30-32,34-37,52-56 |
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 | |
| 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 general-use tool that allows creation of any custom topologies. |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 102 | The based format for the input file the :ndnsim:`AnnotatedTopologyReader` expects: |
Alexander Afanasyev | 6dbacda | 2012-10-23 17:20:18 -0700 | [diff] [blame] | 103 | |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 104 | .. literalinclude:: ../../examples/topologies/topo-grid-3x3.txt |
| 105 | :language: bash |
| 106 | :linenos: |
| 107 | :emphasize-lines: 8,24 |
Alexander Afanasyev | 6dbacda | 2012-10-23 17:20:18 -0700 | [diff] [blame] | 108 | |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 109 | If you save the topology file to `topo-grid-3x3.txt` into ``src/ndnSIM/examples/topology/topo-grid-3x3.txt`` directory, then the following code will duplicate the functionality of :ref:`9-node-grid-example` but with the use of :ndnsim:`AnnotatedTopologyReader`: |
Alexander Afanasyev | 6dbacda | 2012-10-23 17:20:18 -0700 | [diff] [blame] | 110 | |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 111 | .. literalinclude:: ../../examples/ndn-grid-topo-plugin.cc |
| 112 | :language: c++ |
| 113 | :linenos: |
| 114 | :lines: 20-25,53- |
| 115 | :emphasize-lines: 13-15,26-28 |
Alexander Afanasyev | 6dbacda | 2012-10-23 17:20:18 -0700 | [diff] [blame] | 116 | |
| 117 | As you can see, scenario code became more compact and more readable. |
| 118 | |
| 119 | :ndnsim:`AnnotatedTopologyReader` provides two ways to access topology nodes. |
| 120 | First, you can use the method :ndnsim:`AnnotatedTopologyReader::GetNodes` which returns NodeContainer. |
| 121 | |
| 122 | Alternatively, nodes can be accessed by name using `Names::Find<Node> ("nodename")` call, as in the above example. |
| 123 | For this purpose,:ndnsim:`AnnotatedTopologyReader` automatically registers all created nodes with names specified in topology file. |
| 124 | For more information about `Names` class, please refer to `NS-3 documentation <.. http://www.nsnam.org/doxygen/classns3_1_1_names.html>`_ |
| 125 | . |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 126 | |
| 127 | If the topology file is placed into ``src/ndnSIM/examples/topology/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):: |
| 128 | |
| 129 | NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-grid-topo-plugin |
| 130 | |
| 131 | |
| 132 | 6-node topology |
| 133 | --------------- |
| 134 | |
| 135 | This scenario can be used for congestion-related scenarios |
| 136 | |
| 137 | .. aafig:: |
| 138 | :aspect: 60 |
| 139 | :scale: 120 |
| 140 | |
| 141 | /------\ /------\ |
| 142 | | Src1 |<--+ +-->| Dst1 | |
| 143 | \------/ \ / \------/ |
| 144 | \ / |
| 145 | +-->/------\ "bottleneck" /------\<-+ |
| 146 | | Rtr1 |<===============>| Rtr2 | |
| 147 | +-->\------/ \------/<-+ |
| 148 | / \ |
| 149 | /------\ / \ /------\ |
| 150 | | Src2 |<--+ +-->| Dst2 | |
| 151 | \------/ \------/ |
| 152 | |
| 153 | .. literalinclude:: ../../examples/topologies/topo-6-node.txt |
| 154 | :language: bash |
| 155 | :emphasize-lines: 3,13 |
| 156 | |
| 157 | .. literalinclude:: ../../examples/ndn-congestion-topo-plugin.cc |
| 158 | :language: c++ |
| 159 | :linenos: |
| 160 | |
| 161 | .. :lines: 20-25,53- |
| 162 | .. :emphasize-lines: 13-15,26-28 |