blob: 602b0195889b8684d9d422199ea59b4d91419373 [file] [log] [blame]
Alexander Afanasyev6315ef72012-06-01 20:56:31 -07001ndnSIM helpers
2==============
3
4Helpers are very important components of ndnSIM, especially for writing simulation scenarios.
5The following summarizes helpers and their basic usage.
6
Alexander Afanasyevf6807a52012-08-10 18:11:43 -07007StackHelper
Alexander Afanasyev6315ef72012-06-01 20:56:31 -07008---------------
9
Alexander Afanasyevf6807a52012-08-10 18:11:43 -070010:ndnsim:`StackHelper` is used to install ndnSIM network stack on requested nodes, as well to provide a simple way configure several important parameters of NDN simulation.
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070011
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -080012Example:
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070013
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -080014.. code-block:: c++
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070015
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -080016 ndn::StackHelper ndnHelper;
17 NodeContainer nodes;
18 ...
19 ndnHelper.Install (nodes);
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070020
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -080021Routing
22+++++++
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070023
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -080024All forwarding strategies require knowledge of where Interests can be forwarded (Forwarding Information Base).
25Unlike IP routing, this knowledge may be imprecise, but without such knowledge forwarding strategies will not be able to make any decision and will drop any Interests.
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070026
27.. note::
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -080028 By default, all nodes have empty FIB. You need either to manually configure routes, use global routing controller, or (not recommended) enable default routes.
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070029
30Manually routes
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -080031^^^^^^^^^^^^^^^
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070032
Alexander Afanasyevf6807a52012-08-10 18:11:43 -070033Routes can be configured manually using :ndnsim:`StackHelper::AddRoute` static methods of :ndnsim:`StackHelper`.
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070034
35These routes **should** be created **after** installing NDN stack on a node:
36
37 .. code-block:: c++
38
Alexander Afanasyevb8d14ad2012-08-09 13:19:37 -070039 ndnHelper.Install (nodes);
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070040 ...
41 Ptr<Node> node = ... // FIB entry will be added to FIB on this node
42 std::string prefix = ... // some prefix
Alexander Afanasyevf6807a52012-08-10 18:11:43 -070043 Ptr<ndn::Face> face = ... // NDN face that belongs to the node and through which prefix is accessible
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070044 int32_t metric = ... // some routing metric
Alexander Afanasyevf6807a52012-08-10 18:11:43 -070045 ndn::StackHelper::AddRoute (node, prefix, face, metric);
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070046
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -080047Global routing controller
48^^^^^^^^^^^^^^^^^^^^^^^^^
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070049
Alexander Afanasyevf6807a52012-08-10 18:11:43 -070050To simplify FIB management in large topologies, ndnSIM contains a global routing controller (:ndnsim:`helper <GlobalRoutingHelper>` and :ndnsim:`special interface <GlobalRouter>`), similar in spirit to ``Ipv4GlobalRoutingHelper``.
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070051
52There are several necessary steps, in order to take advantage of the global routing controller:
53
Alexander Afanasyevf6807a52012-08-10 18:11:43 -070054* install :ndnsim:`special interfaces <GlobalRouter>` on nodes
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070055
56 .. code-block:: c++
57
58 NodeContainer nodes;
59 ...
Alexander Afanasyevf6807a52012-08-10 18:11:43 -070060 ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
Alexander Afanasyevb8d14ad2012-08-09 13:19:37 -070061 ndnGlobalRoutingHelper.Install (nodes);
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070062
Alexander Afanasyevf6807a52012-08-10 18:11:43 -070063* specify which node exports which prefix using :ndnsim:`GlobalRoutingHelper::AddOrigins`
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070064
65 .. code-block:: c++
66
67 Ptr<Node> producer; // producer node that exports prefix
68 std::string prefix; // exported prefix
69 ...
Alexander Afanasyevb8d14ad2012-08-09 13:19:37 -070070 ndnGlobalRoutingHelper.AddOrigins (prefix, producer);
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070071
Alexander Afanasyevf6807a52012-08-10 18:11:43 -070072* calculate and install FIBs on every node using :ndnsim:`GlobalRoutingHelper::CalculateRoutes`
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070073
74 .. code-block:: c++
75
Alexander Afanasyevb8d14ad2012-08-09 13:19:37 -070076 cdnGlobalRoutingHelper.CalculateRoutes ();
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070077
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -080078Default routes
79^^^^^^^^^^^^^^
80
81In simple topologies, like in :doc:`examples <examples>`, or when
82simulating broadcast environment, it is possible to set up *default*
83FIB entries using :ndnsim:`StackHelper::SetDefaultRoutes` call.
84More specifically, every installed NDN stack will have a FIB entry to ``/`` prefix, containing all available faces.
85
86The following should be done before installing stack on a node:
87
88 .. code-block:: c++
89
90 ndnHelper.SetDefaultRoutes (true);
91 ...
92 ndnHelper.Install (nodes);
93
94
95Content Store
96+++++++++++++
97
98ndnSIM comes with several different in-memory :ndnsim:`content store <ndn::ContentStore>` implementations, featuring different cache replacement policies.
99
100.. note:
101
102 The default content store uses LRU replacement policity and constrained with 100 cached ContentObjects.
103
104To select a particular content store and configure its capacity, use :ndnsim:`SetContentStore <ndn::StackHelper::SetContentStore>` helper method:
105
106- :ndnsim:`Least Recently Used (LRU) <ndn::cs::Lru>` (default):
107
108 .. code-block:: c++
109
110 ndnHelper.SetContentStore ("ns3::ndn::cs::Lru",
111 "MaxSize", "10000");
112 ...
113 ndnHelper.Install (nodes);
114
Alexander Afanasyevf4a03592012-12-10 16:12:34 -0800115
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800116- :ndnsim:`First-In-First-Out (FIFO) <ndn::cs::Fifo>`:
117
118 .. code-block:: c++
119
120 ndnHelper.SetContentStore ("ns3::ndn::cs::Fifo",
121 "MaxSize", "10000");
122 ...
123 ndnHelper.Install (nodes);
124
125- :ndnsim:`Random <ndn::cs::Random>`:
126
127 .. code-block:: c++
128
129 ndnHelper.SetContentStore ("ns3::ndn::cs::Random",
130 "MaxSize", "10000");
131 ...
132 ndnHelper.Install (nodes);
133
134.. note::
135
136 If ``MaxSize`` parameter is omitted, then will be used a default value (100).
137
138.. note::
139
140 If ``MaxSize`` is set to 0, then no limit on ContentStore will be enforced
141
Alexander Afanasyevf4a03592012-12-10 16:12:34 -0800142
143In order to evaluate lifetime of the content store entries, the special versions of the content store need to be used:
144
145- :ndnsim:`Least Recently Used (LRU) with cache entry lifetime tracking <ndn::cs::Stats::Lru>`:
146
147 .. code-block:: c++
148
149 void
150 CacheEntryRemoved (std::string context, Ptr<const ndn::cs::Entry> entry, Time lifetime)
151 {
152 std::cout << entry->GetName () << " " << lifetime.ToDouble (Time::S) << "s" << std::endl;
153 }
154
155 ...
156
157 ndnHelper.SetContentStore ("ns3::ndn::cs::Stats::Lru",
158 "MaxSize", "10000");
159 ...
160 ndnHelper.Install (nodes);
161
162 // connect to lifetime trace
163 Config::Connect ("/NodeList/*/$ns3::ndn::cs::Stats::Lru/WillRemoveEntry", MakeCallback (CacheEntryRemoved));
164
165
166- :ndnsim:`First-In-First-Out (FIFO) with cache entry lifetime tracking <ndn::cs::Stats::Fifo>`:
167
168 .. code-block:: c++
169
170 void
171 CacheEntryRemoved (std::string context, Ptr<const ndn::cs::Entry> entry, Time lifetime)
172 {
173 std::cout << entry->GetName () << " " << lifetime.ToDouble (Time::S) << "s" << std::endl;
174 }
175
176 ...
177
178 ndnHelper.SetContentStore ("ns3::ndn::cs::Stats::Fifo",
179 "MaxSize", "10000");
180 ...
181 ndnHelper.Install (nodes);
182
183 // connect to lifetime trace
184 Config::Connect ("/NodeList/*/$ns3::ndn::cs::Stats::Fifo/WillRemoveEntry", MakeCallback (CacheEntryRemoved));
185
186- :ndnsim:`Random with cache entry lifetime tracking <ndn::cs::Stats::Random>`:
187
188 .. code-block:: c++
189
190 void
191 CacheEntryRemoved (std::string context, Ptr<const ndn::cs::Entry> entry, Time lifetime)
192 {
193 std::cout << entry->GetName () << " " << lifetime.ToDouble (Time::S) << "s" << std::endl;
194 }
195
196 ...
197
198 ndnHelper.SetContentStore ("ns3::ndn::cs::Stats::Random",
199 "MaxSize", "10000");
200 ...
201 ndnHelper.Install (nodes);
202
203 // connect to lifetime trace
204 Config::Connect ("/NodeList/*/$ns3::ndn::cs::Stats::Random/WillRemoveEntry", MakeCallback (CacheEntryRemoved));
205
206
207
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800208Pending Interest Table
209++++++++++++++++++++++
210
211The current version of ndnSIM provides :ndnsim:`templated realizations <ndn::pit::PitImpl>` of :ndnsim:`PIT abstraction <ndn::Pit>`, allowing optional bounding the number of PIT entries and different replacement policies (i.e., perform different actions when limit on number of PIT entries is reached).
212
213To select a particular PIT implementation and configure its policies, use :ndnsim:`SetPit <ndn::StackHelper::SetPit>` helper method:
214
215- :ndnsim:`persistent <ndn::pit::Persistent>` (default):
216
217 New entries will be rejected if PIT size reached its limit
218
219 .. code-block:: c++
220
221 ndnHelper.SetPit ("ns3::ndn::pit::Persistent",
222 "MaxSize", "0");
223 ...
224 ndnHelper.Install (nodes);
225
226- :ndnsim:`random <ndn::pit::Random>`:
227
228 when PIT reaches its limit, random entry (could be the newly created one) will be removed from PIT;
229
230 .. code-block:: c++
231
232 ndnHelper.SetPit ("ns3::ndn::pit::Random",
233 "MaxSize", "0");
234 ...
235 ndnHelper.Install (nodes);
236
237- :ndnsim:`least-recently-used <ndn::pit::Lru>`:
238
239 the least recently used entry (the oldest entry with minimum number of incoming faces) will be removed when PIT size reached its limit.
240
241 .. code-block:: c++
242
243 ndnHelper.SetPit ("ns3::ndn::pit::Lru",
244 "MaxSize", "0");
245 ...
246 ndnHelper.Install (nodes);
247
248Forwarding strategy
249+++++++++++++++++++
250
251A desired :ndnsim:`forwarding strategy <ForwardingStrategy>` parameter need to be set before installing stack on a node.
252
253 Currently, there are following forwarding strategies that can be used in simulations:
254
255 - :ndnsim:`Flooding` (default)
256
257 Interests will be forwarded to all available faces available for a route (FIB entry).
258 If there are no available GREEN or YELLOW faces, interests is dropped.
259
260 .. code-block:: c++
261
262 ndnHelper.SetForwardingStrategy ("ns3::ndn::fw::Flooding");
263 ...
264 ndnHelper.Install (nodes);
265
266
267 - :ndnsim:`SmartFlooding`
268
269 If GREEN face is available, Interest will be sent to the highest-ranked GREEN face.
270 If not, Interest will be forwarded to all available faces available for a route (FIB entry)/
271 If there are no available GREEN or YELLOW faces, interests is dropped.
272
273 .. code-block:: c++
274
275 ndnHelper.SetForwardingStrategy ("ns3::ndn::fw::SmartFlooding");
276 ...
277 ndnHelper.Install (nodes);
278
279 - :ndnsim:`BestRoute`
280
281 If GREEN face is available, Interest will be sent to the highest-ranked GREEN face.
282 If not, Interest will be forwarded to the highest-ranked YELLOW face.
283 If there are no available GREEN or YELLOW faces, interests is dropped.
284
285 .. code-block:: c++
286
287 ndnHelper.SetForwardingStrategy ("ns3::ndn::fw::BestRoute");
288 ...
289 ndnHelper.Install (nodes);
290
291
292
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700293
Alexander Afanasyevf6807a52012-08-10 18:11:43 -0700294AppHelper
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700295---------------
296
Alexander Afanasyevf6807a52012-08-10 18:11:43 -0700297:ndnsim:`AppHelper` simplifies task of creating, configuring, and installing ndnSIM applications.
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700298
299
Alexander Afanasyevf6807a52012-08-10 18:11:43 -0700300The basic usage of the :ndnsim:`AppHelper`:
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700301
302* Create helper for specific applications class:
303
304 .. code-block:: c++
305
306 // Create helper for the consumer generating Interests with constant rate
Alexander Afanasyevf6807a52012-08-10 18:11:43 -0700307 ndn::AppHelper consumerHelper ("ns3::ndn::ConsumerCbr");
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700308
Alexander Afanasyevf6807a52012-08-10 18:11:43 -0700309* Assign prefix on which application operates (either generating Interests using this name or satisfying Interests for this name) using :ndnsim:`AppHelper::SetPrefix`:
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700310
311 .. code-block:: c++
312
313 consumerHelper.SetPrefix (prefix);
314
Alexander Afanasyevf6807a52012-08-10 18:11:43 -0700315* Assign application-specific attributes using :ndnsim:`AppHelper::SetAttribute`:
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700316
317 .. code-block:: c++
318
319 // Set frequency parameter
320 consumerHelper.SetAttribute ("Frequency", StringValue ("10")); // 10 interests a second
321
322* Install application on one or more nodes:
323
324 .. code-block:: c++
325
326 NodeContainer nodes;
327 ...
328 consumerHelper.Install (nodes)