blob: c1161d356b43a60d0eba96ea7f56201db164b0bc [file] [log] [blame]
Alexander Afanasyev4d325162012-06-01 12:28:50 -07001Examples
2========
3
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -07004.. _simple-scenario:
5
Alexander Afanasyev4d325162012-06-01 12:28:50 -07006Simple scenario
7---------------
8
Alexander Afanasyevb8d14ad2012-08-09 13:19:37 -07009The first example (``ndn-simple.cc``) shows very basics of ndnSIM. In the simulated
Alexander Afanasyev4d325162012-06-01 12:28:50 -070010topology there are 3 nodes, connected with point-to-point links, one
Alexander Afanasyev07b00632012-06-01 23:46:47 -070011NDN consumer, and one NDN producer:
Alexander Afanasyev4d325162012-06-01 12:28:50 -070012
Alexander Afanasyev07b00632012-06-01 23:46:47 -070013.. aafig::
14 :aspect: 60
15 :scale: 120
Alexander Afanasyev4d325162012-06-01 12:28:50 -070016
Alexander Afanasyev07b00632012-06-01 23:46:47 -070017 +----------+ +--------+ +----------+
18 | | 1Mbps | | 1Mbps | |
19 | Consumer |<-------------->| Router |<-------------->| Producer |
20 | | 10ms | | 10ms | |
21 +----------+ +--------+ +----------+
Alexander Afanasyev4d325162012-06-01 12:28:50 -070022
Alexander Afanasyevf6807a52012-08-10 18:11:43 -070023Consumer is simulated using :ndnsim:`ConsumerCbr` reference application and generates Interests towards the producer
Alexander Afanasyev07b00632012-06-01 23:46:47 -070024with frequency of 10 Interests per second (see :doc:`applications`).
25
Alexander Afanasyevf6807a52012-08-10 18:11:43 -070026Producer is simulated using :ndnsim:`Producer` class, which is used to satisfy all incoming Interests with virtual payload data (1024 bytes).
Alexander Afanasyev07b00632012-06-01 23:46:47 -070027
28FIB on every node is populated using default routes (see :doc:`helpers`).
Alexander Afanasyev4d325162012-06-01 12:28:50 -070029
30The following code represents all that is necessary to run such a
31simple scenario
32
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080033.. literalinclude:: ../../examples/ndn-simple.cc
34 :language: c++
35 :linenos:
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -080036 :lines: 20-27,48-
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080037 :emphasize-lines: 30-33,37-49
Alexander Afanasyev07b00632012-06-01 23:46:47 -070038
Alexander Afanasyevb8d14ad2012-08-09 13:19:37 -070039If 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 Afanasyev07b00632012-06-01 23:46:47 -070040simulation using the following command (in optimized mode nothing will be printed out)::
41
Alexander Afanasyevf6807a52012-08-10 18:11:43 -070042 NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-simple
Alexander Afanasyev07b00632012-06-01 23:46:47 -070043
44
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -070045.. _9-node-grid-example:
46
Alexander Afanasyev07b00632012-06-01 23:46:47 -0700479-node grid example
48-------------------
49
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080050This scenario (``ndn-grid.cc``) simulates a grid topology, which is constructed using PointToPointLayout NS-3 module
Alexander Afanasyev07b00632012-06-01 23:46:47 -070051
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 Afanasyevf6807a52012-08-10 18:11:43 -070073FIB is populated using :ndnsim:`GlobalRoutingHelper` (see :doc:`helpers`).
Alexander Afanasyev07b00632012-06-01 23:46:47 -070074
Alexander Afanasyevf6807a52012-08-10 18:11:43 -070075Consumer is simulated using :ndnsim:`ConsumerCbr` reference application and generates Interests towards the producer
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -080076with frequency of 100 interests per second (see :doc:`applications`).
Alexander Afanasyev07b00632012-06-01 23:46:47 -070077
Alexander Afanasyevf6807a52012-08-10 18:11:43 -070078Producer is simulated using :ndnsim:`Producer` class, which is used to satisfy all incoming Interests with virtual payload data (1024 bytes).
Alexander Afanasyev07b00632012-06-01 23:46:47 -070079
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080080The following code represents all that is necessary to run such a simple scenario
Alexander Afanasyev07b00632012-06-01 23:46:47 -070081
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080082.. literalinclude:: ../../examples/ndn-grid.cc
83 :language: c++
84 :linenos:
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -080085 :lines: 20-27,53-
86 :emphasize-lines: 28,31-33,35-38,53-57
Alexander Afanasyev4d325162012-06-01 12:28:50 -070087
Alexander Afanasyev4d325162012-06-01 12:28:50 -070088
Alexander Afanasyevb8d14ad2012-08-09 13:19:37 -070089If 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 Afanasyev07b00632012-06-01 23:46:47 -070090simulation using the following command (in optimized mode nothing will be printed out)::
91
Alexander Afanasyevf6807a52012-08-10 18:11:43 -070092 NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-grid
Alexander Afanasyev07b00632012-06-01 23:46:47 -070093
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -070094.. _9-node-grid-example-using-topology-plugin:
95
969-node grid example using topology plugin
97-----------------------------------------
98
99Instead 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 Afanasyeve095f0f2012-11-21 17:43:32 -0800101While :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 Afanasyev6dbacda2012-10-23 17:20:18 -0700104
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800105.. literalinclude:: ../../examples/topologies/topo-grid-3x3.txt
106 :language: bash
107 :linenos:
108 :emphasize-lines: 8,24
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -0700109
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800110
111This scenario (``ndn-grid-topo-plugin.cc``) duplicates the functionality of :ref:`9-node-grid-example` but with the use of :ndnsim:`AnnotatedTopologyReader`.
112
113.. aafig::
114 :aspect: 60
115 :scale: 120
116
117 /--------\ /-\ /-\
118 |Consumer|<---->| |<------->| |
119 \--------/ \-/ \-/
120 ^ ^ ^
121 | | | 1Mbps/10ms delay
122 v v v
123 /-\ /-\ /-\
124 | |<-------->| |<------->| |
125 \-/ \-/ \-/
126 ^ ^ ^
127 | | |
128 v v v
129 /-\ /-\ /--------\
130 | |<-------->| |<---->|Producer|
131 \-/ \-/ \--------/
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -0700132
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800133.. literalinclude:: ../../examples/ndn-grid-topo-plugin.cc
134 :language: c++
135 :linenos:
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800136 :lines: 20-26,51-
137 :emphasize-lines: 14-16,20,27-30
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -0700138
139As you can see, scenario code became more compact and more readable.
140
141:ndnsim:`AnnotatedTopologyReader` provides two ways to access topology nodes.
142First, you can use the method :ndnsim:`AnnotatedTopologyReader::GetNodes` which returns NodeContainer.
143
144Alternatively, nodes can be accessed by name using `Names::Find<Node> ("nodename")` call, as in the above example.
145For this purpose,:ndnsim:`AnnotatedTopologyReader` automatically registers all created nodes with names specified in topology file.
146For more information about `Names` class, please refer to `NS-3 documentation <.. http://www.nsnam.org/doxygen/classns3_1_1_names.html>`_
147.
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800148
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800149If 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 Afanasyevaa1c4c32012-11-21 16:17:03 -0800150
151 NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-grid-topo-plugin
152
153
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -08001546-node bottleneck topology
155--------------------------
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800156
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800157This scenario (``ndn-congestion-topo-plugin.cc``) can be used for congestion-related scenarios
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800158
159.. aafig::
160 :aspect: 60
161 :scale: 120
162
163 /------\ /------\
164 | Src1 |<--+ +-->| Dst1 |
165 \------/ \ / \------/
166 \ /
167 +-->/------\ "bottleneck" /------\<-+
168 | Rtr1 |<===============>| Rtr2 |
169 +-->\------/ \------/<-+
170 / \
171 /------\ / \ /------\
172 | Src2 |<--+ +-->| Dst2 |
173 \------/ \------/
174
175.. literalinclude:: ../../examples/topologies/topo-6-node.txt
176 :language: bash
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800177 :linenos:
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800178 :emphasize-lines: 3,13
179
180.. literalinclude:: ../../examples/ndn-congestion-topo-plugin.cc
181 :language: c++
182 :linenos:
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800183 :lines: 20-26,47-
184 :emphasize-lines: 15,21-22,29-34,41-47,52-62
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800185
186.. :lines: 20-25,53-