blob: 47d4a65455ea5ec126a4a91996c0381cb3a815b3 [file] [log] [blame]
Alexander Afanasyev4d325162012-06-01 12:28:50 -07001Examples
2========
3
Alexander Afanasyev6cf83432013-02-15 16:02:04 -08004.. role:: red
5
6.. note::
7 :red:`!!! This page only shows up examples of how to config topology and perform basic operations in ndnSIM (an example equivalent to "Hello, world1") !!! These are **NOT** examples of real experimentations (just like "Hello, world!" is not a real program).`
8
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -07009.. _simple-scenario:
10
Alexander Afanasyev4d325162012-06-01 12:28:50 -070011Simple scenario
12---------------
13
Alexander Afanasyevb8d14ad2012-08-09 13:19:37 -070014The first example (``ndn-simple.cc``) shows very basics of ndnSIM. In the simulated
Alexander Afanasyev4d325162012-06-01 12:28:50 -070015topology there are 3 nodes, connected with point-to-point links, one
Alexander Afanasyev07b00632012-06-01 23:46:47 -070016NDN consumer, and one NDN producer:
Alexander Afanasyev4d325162012-06-01 12:28:50 -070017
Alexander Afanasyev07b00632012-06-01 23:46:47 -070018.. aafig::
19 :aspect: 60
20 :scale: 120
Alexander Afanasyev4d325162012-06-01 12:28:50 -070021
Alexander Afanasyev07b00632012-06-01 23:46:47 -070022 +----------+ +--------+ +----------+
23 | | 1Mbps | | 1Mbps | |
24 | Consumer |<-------------->| Router |<-------------->| Producer |
25 | | 10ms | | 10ms | |
26 +----------+ +--------+ +----------+
Alexander Afanasyev4d325162012-06-01 12:28:50 -070027
Alexander Afanasyevf6807a52012-08-10 18:11:43 -070028Consumer is simulated using :ndnsim:`ConsumerCbr` reference application and generates Interests towards the producer
Alexander Afanasyev07b00632012-06-01 23:46:47 -070029with frequency of 10 Interests per second (see :doc:`applications`).
30
Alexander Afanasyevf6807a52012-08-10 18:11:43 -070031Producer 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 -070032
33FIB on every node is populated using default routes (see :doc:`helpers`).
Alexander Afanasyev4d325162012-06-01 12:28:50 -070034
35The following code represents all that is necessary to run such a
36simple scenario
37
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080038.. literalinclude:: ../../examples/ndn-simple.cc
39 :language: c++
40 :linenos:
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -080041 :lines: 20-27,48-
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080042 :emphasize-lines: 30-33,37-49
Alexander Afanasyev07b00632012-06-01 23:46:47 -070043
Alexander Afanasyevb8d14ad2012-08-09 13:19:37 -070044If 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 -070045simulation using the following command (in optimized mode nothing will be printed out)::
46
Alexander Afanasyevf6807a52012-08-10 18:11:43 -070047 NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-simple
Alexander Afanasyev07b00632012-06-01 23:46:47 -070048
49
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -070050.. _9-node-grid-example:
Alexander Afanasyev6cf83432013-02-15 16:02:04 -080051
Alexander Afanasyev07b00632012-06-01 23:46:47 -0700529-node grid example
53-------------------
54
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080055This scenario (``ndn-grid.cc``) simulates a grid topology, which is constructed using PointToPointLayout NS-3 module
Alexander Afanasyev07b00632012-06-01 23:46:47 -070056
57.. aafig::
58 :aspect: 60
59 :scale: 120
60
61 /--------\ /-\ /-\
62 |Consumer|<---->| |<------->| |
63 \--------/ \-/ \-/
64 ^ ^ ^
65 | | | 1Mbps/10ms delay
66 v v v
67 /-\ /-\ /-\
68 | |<-------->| |<------->| |
69 \-/ \-/ \-/
70 ^ ^ ^
71 | | |
72 v v v
73 /-\ /-\ /--------\
74 | |<-------->| |<---->|Producer|
75 \-/ \-/ \--------/
76
77
Alexander Afanasyevf6807a52012-08-10 18:11:43 -070078FIB is populated using :ndnsim:`GlobalRoutingHelper` (see :doc:`helpers`).
Alexander Afanasyev07b00632012-06-01 23:46:47 -070079
Alexander Afanasyevf6807a52012-08-10 18:11:43 -070080Consumer is simulated using :ndnsim:`ConsumerCbr` reference application and generates Interests towards the producer
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -080081with frequency of 100 interests per second (see :doc:`applications`).
Alexander Afanasyev07b00632012-06-01 23:46:47 -070082
Alexander Afanasyevf6807a52012-08-10 18:11:43 -070083Producer 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 -070084
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080085The following code represents all that is necessary to run such a simple scenario
Alexander Afanasyev07b00632012-06-01 23:46:47 -070086
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080087.. literalinclude:: ../../examples/ndn-grid.cc
88 :language: c++
89 :linenos:
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -080090 :lines: 20-27,53-
91 :emphasize-lines: 28,31-33,35-38,53-57
Alexander Afanasyev6cf83432013-02-15 16:02:04 -080092
Alexander Afanasyev4d325162012-06-01 12:28:50 -070093
Alexander Afanasyevb8d14ad2012-08-09 13:19:37 -070094If 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 -070095simulation using the following command (in optimized mode nothing will be printed out)::
96
Alexander Afanasyevf6807a52012-08-10 18:11:43 -070097 NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-grid
Alexander Afanasyev07b00632012-06-01 23:46:47 -070098
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -070099.. _9-node-grid-example-using-topology-plugin:
100
1019-node grid example using topology plugin
102-----------------------------------------
103
104Instead 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`.
105
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800106While :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.
107
108:ndnsim:`AnnotatedTopologyReader` expects the following format:
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -0700109
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800110.. literalinclude:: ../../examples/topologies/topo-grid-3x3.txt
111 :language: bash
112 :linenos:
Alexander Afanasyeve97c6072012-11-21 23:51:12 -0800113 :lines: 1-2,19-
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800114 :emphasize-lines: 8,24
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -0700115
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800116
117This scenario (``ndn-grid-topo-plugin.cc``) duplicates the functionality of :ref:`9-node-grid-example` but with the use of :ndnsim:`AnnotatedTopologyReader`.
118
119.. aafig::
120 :aspect: 60
121 :scale: 120
122
123 /--------\ /-\ /-\
124 |Consumer|<---->| |<------->| |
125 \--------/ \-/ \-/
126 ^ ^ ^
127 | | | 1Mbps/10ms delay
128 v v v
129 /-\ /-\ /-\
130 | |<-------->| |<------->| |
131 \-/ \-/ \-/
132 ^ ^ ^
133 | | |
134 v v v
135 /-\ /-\ /--------\
136 | |<-------->| |<---->|Producer|
137 \-/ \-/ \--------/
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -0700138
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800139.. literalinclude:: ../../examples/ndn-grid-topo-plugin.cc
140 :language: c++
141 :linenos:
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800142 :lines: 20-26,51-
143 :emphasize-lines: 14-16,20,27-30
Alexander Afanasyev6cf83432013-02-15 16:02:04 -0800144
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -0700145As you can see, scenario code became more compact and more readable.
146
Alexander Afanasyev6cf83432013-02-15 16:02:04 -0800147:ndnsim:`AnnotatedTopologyReader` provides two ways to access topology nodes.
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -0700148First, you can use the method :ndnsim:`AnnotatedTopologyReader::GetNodes` which returns NodeContainer.
149
150Alternatively, nodes can be accessed by name using `Names::Find<Node> ("nodename")` call, as in the above example.
151For this purpose,:ndnsim:`AnnotatedTopologyReader` automatically registers all created nodes with names specified in topology file.
152For more information about `Names` class, please refer to `NS-3 documentation <.. http://www.nsnam.org/doxygen/classns3_1_1_names.html>`_
153.
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800154
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800155If 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 -0800156
157 NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-grid-topo-plugin
158
159
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -08001606-node bottleneck topology
161--------------------------
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800162
Alexander Afanasyev6cf83432013-02-15 16:02:04 -0800163This scenario (``ndn-congestion-topo-plugin.cc``) can be used for congestion-related scenarios
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800164
165.. aafig::
166 :aspect: 60
167 :scale: 120
168
169 /------\ /------\
170 | Src1 |<--+ +-->| Dst1 |
171 \------/ \ / \------/
Alexander Afanasyev6cf83432013-02-15 16:02:04 -0800172 \ /
173 +-->/------\ "bottleneck" /------\<-+
174 | Rtr1 |<===============>| Rtr2 |
175 +-->\------/ \------/<-+
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800176 / \
177 /------\ / \ /------\
178 | Src2 |<--+ +-->| Dst2 |
179 \------/ \------/
180
181.. literalinclude:: ../../examples/topologies/topo-6-node.txt
182 :language: bash
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800183 :linenos:
Alexander Afanasyeve97c6072012-11-21 23:51:12 -0800184 :lines: 1-2,15-
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800185 :emphasize-lines: 3,13
Alexander Afanasyev6cf83432013-02-15 16:02:04 -0800186
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800187.. literalinclude:: ../../examples/ndn-congestion-topo-plugin.cc
188 :language: c++
189 :linenos:
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800190 :lines: 20-26,47-
191 :emphasize-lines: 15,21-22,29-34,41-47,52-62
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800192
193.. :lines: 20-25,53-
Alexander Afanasyeve97c6072012-11-21 23:51:12 -0800194
195To run this scenario and see what is happening, use the following command::
196
197 NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-congestion-topo-plugin
198
199.. _11-node 2-bottleneck topology with custom forwarding strategy:
200
20111-node 2-bottleneck topology with custom forwarding strategy
202-------------------------------------------------------------
203
204To 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.
205In the current version of ndnSIM, this can be accomplished using manual route configuration.
206
207The following example illustrates how the strategy can be used in simulation scenario.
208
209Let us first define a meaningful topology:
210
211.. aafig::
212 :aspect: 60
213 :scale: 120
Alexander Afanasyev6cf83432013-02-15 16:02:04 -0800214
Alexander Afanasyeve97c6072012-11-21 23:51:12 -0800215 /------\ 0 0 /------\
216 | c1 |<-----+ +----->| p1 |
217 \------/ \ / \------/
Alexander Afanasyev6cf83432013-02-15 16:02:04 -0800218 \ /-----\ /
Alexander Afanasyeve97c6072012-11-21 23:51:12 -0800219 /------\ 0 \ +==>| r12 |<==+ / 0 /------\
220 | c2 |<--+ \ / \-----/ \ / +-->| p2 |
221 \------/ \ \ | | / / \------/
Alexander Afanasyev6cf83432013-02-15 16:02:04 -0800222 \ | | 1Mbps links | | /
223 \ 1 v0 v5 1v 2v 3 /
224 +->/------\ /------\<-+
225 2| r1 |<===============>| r2 |4
226 +->\------/4 0\------/<-+
227 / 3^ ^5 \
228 / | | \
Alexander Afanasyeve97c6072012-11-21 23:51:12 -0800229 /------\ 0 / / \ \ 0 /------\
230 | c3 |<--+ / \ +-->| p3 |
231 \------/ / \ \------/
Alexander Afanasyev6cf83432013-02-15 16:02:04 -0800232 / "All consumer-router and" \
Alexander Afanasyeve97c6072012-11-21 23:51:12 -0800233 /------\ 0 / "router-producer links are" \ 0 /------\
234 | c4 |<-----+ "10Mbps" +---->| p4 |
235 \------/ \------/
Alexander Afanasyev6cf83432013-02-15 16:02:04 -0800236
Alexander Afanasyeve97c6072012-11-21 23:51:12 -0800237 "Numbers near nodes denote face IDs. Face ID is assigned based on the order of link"
238 "definitions in the topology file"
239
240The corresponding topology file (``topo-11-node-two-bottlenecks.txt``):
241
242.. literalinclude:: ../../examples/topologies/topo-11-node-two-bottlenecks.txt
243 :language: bash
244 :linenos:
245 :lines: 1-2,28-
246
247Example simulation (``ndn-congestion-alt-topo-plugin.cc``) scenario that utilizes CustomStrategy forwarding strategy:
248
249.. literalinclude:: ../../examples/ndn-congestion-alt-topo-plugin.cc
250 :language: c++
251 :linenos:
252 :lines: 21-28,61-
253 :emphasize-lines: 16,21,49-50,65-79
254
255
256To run this scenario and see what is happening, use the following command::
257
258 NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-congestion-alt-topo-plugin
259
260You can also run using visualizer module to verify that both bottleneck links are utilized::
261
262 ./waf --run=ndn-congestion-alt-topo-plugin --visualize
Alexander Afanasyev59314802012-11-26 14:56:04 -0800263
Alexander Afanasyevf4a03592012-12-10 16:12:34 -08002643-level binary tree with packet-level trace helpers
265---------------------------------------------------
Alexander Afanasyev59314802012-11-26 14:56:04 -0800266
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800267:ref:`packet trace helper example`
Alexander Afanasyev59314802012-11-26 14:56:04 -0800268
Alexander Afanasyevf4a03592012-12-10 16:12:34 -0800269
2703-level binary tree with content store trace helper
271---------------------------------------------------
272
Alexander Afanasyevdb64ff12013-01-18 16:37:31 -0800273:ref:`cs trace helper example`
Alexander Afanasyevf4a03592012-12-10 16:12:34 -0800274
Alexander Afanasyevf4a03592012-12-10 16:12:34 -0800275
Alexander Afanasyev27e365b2013-01-18 18:03:43 -08002763-level binary tree with application-level Interest-Data delay tracer
277----------------------------------------------------------------------
278
279:ref:`app delay trace helper example`
280
281
Alexander Afanasyev71278d42012-12-12 19:16:54 -08002823-node topology with Content Store respecting freshness field of ContentObjects
283-------------------------------------------------------------------------------
284
285:ref:`Content Store respecting freshness field of ContentObjects`
286
2871-node topology with custom application
288---------------------------------------
289
290:ref:`Custom applications`
291