blob: 45d4f2b2549f7bc019efbdd688692f30f5196288 [file] [log] [blame]
Alexander Afanasyeve6852122013-01-21 11:54:47 -08001.. _forwarding strategies:
Alexander Afanasyeve74cc1c2012-11-21 13:10:03 -08002
3Forwarding Strategies
4=====================
5
Alexander Afanasyeve6852122013-01-21 11:54:47 -08006ndnSIM provides simple ways to experiment with custom Interest/Data forwarding strategies.
Alexander Afanasyeve74cc1c2012-11-21 13:10:03 -08007A new forwarding strategy can be implement completely different processing or override just specific actions/events of the :ndnsim:`forwarding strategy interface <ndn::ForwardingStrategy>`.
8Please refer to :ndnsim:`API documentation <ndn::ForwardingStrategy>` of the forwarding strategy interface, which lists all default actions/events.
9
Alexander Afanasyeve6852122013-01-21 11:54:47 -080010Available forwarding strategies
11+++++++++++++++++++++++++++++++
12
13Basic forwarding strategies
14^^^^^^^^^^^^^^^^^^^^^^^^^^^
15
16Flooding
17########
18
19Interests will be forwarded to all available faces available for a route (FIB entry).
20If there are no available GREEN or YELLOW faces, interests is dropped.
21
22Implementation name: :ndnsim:`ns3::ndn::fw::Flooding` (default)
23
24Usage example:
25
26 .. code-block:: c++
27
28 ndnHelper.SetForwardingStrategy ("ns3::ndn::fw::Flooding");
29 ...
30 ndnHelper.Install (nodes);
31
32SmartFlooding
33#############
34
35If GREEN face is available, Interest will be sent to the highest-ranked GREEN face.
36If not, Interest will be forwarded to all available faces available for a route (FIB entry)/
37If there are no available GREEN or YELLOW faces, interests is dropped.
38
39Implementation name :ndnsim:`ns3::ndn::fw::SmartFlooding`
40
41Usage example:
42
43 .. code-block:: c++
44
45 ndnHelper.SetForwardingStrategy ("ns3::ndn::fw::SmartFlooding");
46 ...
47 ndnHelper.Install (nodes);
48
49BestRoute
50#########
51
52If GREEN face is available, Interest will be sent to the highest-ranked GREEN face.
53If not, Interest will be forwarded to the highest-ranked YELLOW face.
54If there are no available GREEN or YELLOW faces, interests is dropped.
55
56Implementation name: :ndnsim:`ns3::ndn::fw::BestRoute`
57
58Usage example:
59
60 .. code-block:: c++
61
62 ndnHelper.SetForwardingStrategy ("ns3::ndn::fw::BestRoute");
63 ...
64 ndnHelper.Install (nodes);
65
66Strategies with Interest limits
67^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
68
69The following strategies enforce different granularities of Interest limits. Each strategy is an extension of the basic one (custom strategies can also be extended with limits, refer to the source code).
70
71Currently, ndnSIM implements two types of Interest limit enforcements, both based on a Token Bucket approach:
72
73 - :ndnsim:`ns3::ndn::Limits::Window` (default)
74
75 Interest token is borrowed when Interest is send out. The token is returned only when Interest is satisfied or times out.
76
77 - :ndnsim:`ns3::ndn::Limits::Rate`
78
79 Interest token is borrowed when Interest is send out. The token is returned periodically based on link capacity.
80
81In both cases, limit is set according to the following equation:
82
83.. math::
84
85 \mathrm{Interest\ Limit} = Delay\ [s] \cdot
86 \frac{\mathrm{Bandwidth\ [Bytes/s]}}
87 {\mathrm{Data\ packet\ size\ [Bytes]} + \mathrm{Interest\ packet\ size\ [Bytes]}}
88
89To configure packet sizes and delay parameters, use the following :ndnsim:`ndn::StackHelper` method:
90
91 .. code-block:: c++
92
93 // ndnHelper.EnableLimits (true, <delay>, <average interest packet size>, <average data packet size>);
94 ndnHelper.EnableLimits (true, Seconds (0.2), 40, 1100);
95 ...
96 ndnHelper.Install (nodes);
97
98Usage examples
99##############
100
101Per outgoing Face limits
102%%%%%%%%%%%%%%%%%%%%%%%%
103
104- :ndnsim:`ns3::ndn::fw::Flooding::PerOutFaceLimits`
105
106 With :ndnsim:`Limits::Window`:
107
108 .. code-block:: c++
109
110 ndnHelper.SetForwardingStrategy ("ns3::ndn::fw::Flooding::PerOutFaceLimits"
111 "Limit", "ns3::ndn::Limits::Window");
112 ...
113 ndnHelper.Install (nodes);
114
115
116 With :ndnsim:`Limits::Rate`:
117
118 .. code-block:: c++
119
120 ndnHelper.SetForwardingStrategy ("ns3::ndn::fw::Flooding::PerOutFaceLimits"
121 "Limit", "ns3::ndn::Limits::Rate");
122 ...
123 ndnHelper.Install (nodes);
124
125- :ndnsim:`ns3::ndn::fw::SmartFlooding::PerOutFaceLimits`
126
127 With :ndnsim:`Limits::Window`:
128
129 .. code-block:: c++
130
131 ndnHelper.SetForwardingStrategy ("ns3::ndn::fw::SmartFlooding::PerOutFaceLimits"
132 "Limit", "ns3::ndn::Limits::Window");
133 ...
134 ndnHelper.Install (nodes);
135
136
137 With :ndnsim:`Limits::Rate`:
138
139 .. code-block:: c++
140
141 ndnHelper.SetForwardingStrategy ("ns3::ndn::fw::SmartFlooding::PerOutFaceLimits"
142 "Limit", "ns3::ndn::Limits::Rate");
143 ...
144 ndnHelper.Install (nodes);
145
146- :ndnsim:`ns3::ndn::fw::BestRoute::PerOutFaceLimits`
147
148 With :ndnsim:`Limits::Window`:
149
150 .. code-block:: c++
151
152 ndnHelper.SetForwardingStrategy ("ns3::ndn::fw::BestRoute::PerOutFaceLimits"
153 "Limit", "ns3::ndn::Limits::Window");
154 ...
155 ndnHelper.Install (nodes);
156
157
158 With :ndnsim:`Limits::Rate`:
159
160 .. code-block:: c++
161
162 ndnHelper.SetForwardingStrategy ("ns3::ndn::fw::BestRoute::PerOutFaceLimits"
163 "Limit", "ns3::ndn::Limits::Rate");
164 ...
165 ndnHelper.Install (nodes);
166
167
168Per FIB entry, per outgoing face limits
169%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
170
171- :ndnsim:`ns3::ndn::fw::Flooding::PerOutFaceLimits::PerFibLimits`
172
173 With :ndnsim:`Limits::Window`:
174
175 .. code-block:: c++
176
177 ndnHelper.SetForwardingStrategy ("ns3::ndn::fw::Flooding::PerOutFaceLimits::PerFibLimits"
178 "Limit", "ns3::ndn::Limits::Window");
179 ...
180 ndnHelper.Install (nodes);
181
182
183 With :ndnsim:`Limits::Rate`:
184
185 .. code-block:: c++
186
187 ndnHelper.SetForwardingStrategy ("ns3::ndn::fw::Flooding::PerOutFaceLimits::PerFibLimits"
188 "Limit", "ns3::ndn::Limits::Rate");
189 ...
190 ndnHelper.Install (nodes);
191
192- :ndnsim:`ns3::ndn::fw::SmartFlooding::PerOutFaceLimits::PerFibLimits`
193
194 With :ndnsim:`Limits::Window`:
195
196 .. code-block:: c++
197
198 ndnHelper.SetForwardingStrategy ("ns3::ndn::fw::SmartFlooding::PerOutFaceLimits::PerFibLimits"
199 "Limit", "ns3::ndn::Limits::Window");
200 ...
201 ndnHelper.Install (nodes);
202
203
204 With :ndnsim:`Limits::Rate`:
205
206 .. code-block:: c++
207
208 ndnHelper.SetForwardingStrategy ("ns3::ndn::fw::SmartFlooding::PerOutFaceLimits::PerFibLimits"
209 "Limit", "ns3::ndn::Limits::Rate");
210 ...
211 ndnHelper.Install (nodes);
212
213- :ndnsim:`ns3::ndn::fw::BestRoute::PerOutFaceLimits::PerFibLimits`
214
215 With :ndnsim:`Limits::Window`:
216
217 .. code-block:: c++
218
219 ndnHelper.SetForwardingStrategy ("ns3::ndn::fw::BestRoute::PerOutFaceLimits::PerFibLimits"
220 "Limit", "ns3::ndn::Limits::Window");
221 ...
222 ndnHelper.Install (nodes);
223
224
225 With :ndnsim:`Limits::Rate`:
226
227 .. code-block:: c++
228
229 ndnHelper.SetForwardingStrategy ("ns3::ndn::fw::BestRoute::PerOutFaceLimits::PerFibLimits"
230 "Limit", "ns3::ndn::Limits::Rate");
231 ...
232 ndnHelper.Install (nodes);
233
Alexander Afanasyeve97c6072012-11-21 23:51:12 -0800234.. _Writing your own custom strategy:
235
Alexander Afanasyeve74cc1c2012-11-21 13:10:03 -0800236Writing your own custom strategy
237++++++++++++++++++++++++++++++++
238
Alexander Afanasyeve6852122013-01-21 11:54:47 -0800239First step in creating your own strategy is to decide which existing strategy you want to extend. You can either use realize :ndnsim:`forwarding strategy interface <ndn::ForwardingStrategy>` (:ndnsim:`ndn::ForwardingStrategy::DoPropagateInterest` call must be implemented) or extended one of the available forwarding strategies (:ndnsim:`fw::BestRoute` or :ndnsim:`fw::Flooding`).
240The following example assumes that we are realizing :ndnsim:`forwarding strategy interface <ndn::ForwardingStrategy>`.
Alexander Afanasyeve74cc1c2012-11-21 13:10:03 -0800241
242The follwoing are template strategy h/cc files:
243
Alexander Afanasyeve97c6072012-11-21 23:51:12 -0800244.. literalinclude:: ../../examples/custom-strategies/custom-strategy.h
Alexander Afanasyeve74cc1c2012-11-21 13:10:03 -0800245 :language: c++
246 :linenos:
247 :lines: 1-36,51-55,59-
248
Alexander Afanasyeve97c6072012-11-21 23:51:12 -0800249.. literalinclude:: ../../examples/custom-strategies/custom-strategy.cc
Alexander Afanasyeve74cc1c2012-11-21 13:10:03 -0800250 :language: c++
251 :linenos:
252 :lines: 1-40,42-50,75-76,115-
Alexander Afanasyeve97c6072012-11-21 23:51:12 -0800253 :emphasize-lines: 21,27
Alexander Afanasyeve74cc1c2012-11-21 13:10:03 -0800254
Alexander Afanasyeve6852122013-01-21 11:54:47 -0800255After having the template, we can fill the necesasry functionality.
Alexander Afanasyeve74cc1c2012-11-21 13:10:03 -0800256
Alexander Afanasyeve6852122013-01-21 11:54:47 -0800257Let us say, that we want Interest be forwarded to first two best-metric faces specified by FIB.
Alexander Afanasyeve74cc1c2012-11-21 13:10:03 -0800258That is, if node has two or more alternative paths to forward the Interests, this Interest will be forwarded to the best two neighbors.
259The following implementation of CustomStrategy::DoPropagateInterest accomplishes the task:
260
Alexander Afanasyeve97c6072012-11-21 23:51:12 -0800261.. literalinclude:: ../../examples/custom-strategies/custom-strategy.cc
Alexander Afanasyeve74cc1c2012-11-21 13:10:03 -0800262 :language: c++
263 :linenos:
264 :lines: 45-75
265 :emphasize-lines: 7-30
266
267After the compilation, you can use ``"ns3::ndn::fw::CustomStrategy"`` as a parameter to :ndnsim:`ndn::StackHelper::SetForwardingStrategy` helper method.
268
269 .. as well as NS_LOG=ndn.fw.CustomStrategy when running in a debug mode
270
271Extending strategy
272++++++++++++++++++
273
274If you need more customization for the forwarding strategy, there are many forwarding strategy events that can be overriden.
275For example, if we want to perform special logging of all forwarded, timed out, and satisfied Intersts, we can override the following events (for more events, refer to :ndnsim:`ForwardingStrategy API documentation <ForwardingStrategy>`):
276
277- :ndnsim:`DidSendOutInterest <ForwardingStrategy::DidSendOutInterest>`, which fired just after forwarding the Interest
278
279- :ndnsim:`WillEraseTimedOutPendingInterest <ForwardingStrategy::WillEraseTimedOutPendingInterest>`, which fired just before PIT entry is removed by timeout
280
281- :ndnsim:`WillSatisfyPendingInterest <ForwardingStrategy::WillSatisfyPendingInterest>`, which fired just before Interest will be satisfied.
282
283The highlighted ares of the following code demonstrates how it can be impelmented:
284
Alexander Afanasyeve97c6072012-11-21 23:51:12 -0800285.. literalinclude:: ../../examples/custom-strategies/custom-strategy.h
Alexander Afanasyeve74cc1c2012-11-21 13:10:03 -0800286 :language: c++
287 :linenos:
288 :emphasize-lines: 37-50,56-58
289
Alexander Afanasyeve97c6072012-11-21 23:51:12 -0800290.. literalinclude:: ../../examples/custom-strategies/custom-strategy.cc
Alexander Afanasyeve74cc1c2012-11-21 13:10:03 -0800291 :language: c++
292 :linenos:
Alexander Afanasyeve97c6072012-11-21 23:51:12 -0800293 :emphasize-lines: 41,77-114
294
295
296Example of using custom strategy
297++++++++++++++++++++++++++++++++
298
299Please refer to :ref:`this example <11-node 2-bottleneck topology with custom forwarding strategy>`.
300