blob: 1f4199098ed764a58225d48efe5a2995f970ca62 [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:
36 :lines: 20-27,50-
37 :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 Afanasyev07b00632012-06-01 23:46:47 -070076with frequency of 10 Interests per second (see :doc:`applications`).
77
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:
85 :lines: 20-27,55-
86 :emphasize-lines: 30-32,34-37,52-56
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
101While :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 Afanasyevaa1c4c32012-11-21 16:17:03 -0800102The based format for the input file the :ndnsim:`AnnotatedTopologyReader` expects:
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -0700103
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800104.. literalinclude:: ../../examples/topologies/topo-grid-3x3.txt
105 :language: bash
106 :linenos:
107 :emphasize-lines: 8,24
Alexander Afanasyev6dbacda2012-10-23 17:20:18 -0700108
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800109If 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 Afanasyev6dbacda2012-10-23 17:20:18 -0700110
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800111.. 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 Afanasyev6dbacda2012-10-23 17:20:18 -0700116
117As you can see, scenario code became more compact and more readable.
118
119:ndnsim:`AnnotatedTopologyReader` provides two ways to access topology nodes.
120First, you can use the method :ndnsim:`AnnotatedTopologyReader::GetNodes` which returns NodeContainer.
121
122Alternatively, nodes can be accessed by name using `Names::Find<Node> ("nodename")` call, as in the above example.
123For this purpose,:ndnsim:`AnnotatedTopologyReader` automatically registers all created nodes with names specified in topology file.
124For more information about `Names` class, please refer to `NS-3 documentation <.. http://www.nsnam.org/doxygen/classns3_1_1_names.html>`_
125.
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800126
127If 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
1326-node topology
133---------------
134
135This 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