blob: 91bcf4d3aa7ddc2eafeb2977d062780f0f241272 [file] [log] [blame]
Alexander Afanasyev6315ef72012-06-01 20:56:31 -07001ndnSIM helpers
2==============
3
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -08004Helpers are very important components of ndnSIM, especially for writing simulation
5scenarios. The following summarizes helpers and their basic usage.
Alexander Afanasyev6315ef72012-06-01 20:56:31 -07006
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -08007NDN Stack Helpers
8-----------------
Alexander Afanasyev6315ef72012-06-01 20:56:31 -07009
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080010:ndnsim:`StackHelper` is used to install ndnSIM network stack on requested nodes, as well
11 to provide a simple way configure several important parameters of NDN simulation.
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070012
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -080013Example:
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070014
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -080015.. code-block:: c++
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070016
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080017 StackHelper ndnHelper;
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -080018 NodeContainer nodes;
19 ...
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080020 ndnHelper.Install(nodes);
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070021
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -080022Routing
23+++++++
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070024
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080025All forwarding strategies require knowledge of where Interests can be forwarded
26(Forwarding Information Base).
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070027
28.. note::
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080029 By default, all nodes have empty FIB. You need either to manually configure routes,
30 use global routing controller, or (not recommended) enable default routes.
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070031
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080032Manually routes (FIB Helper)
33^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070034
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080035The :ndnsim:`FIB helper <FibHelper>` interacts with the FIB manager of NFD by sending
36special Interest commands to the manager in order to add/remove a next hop from FIB
37entries or add routes to the FIB manually (manual configuration of FIB).
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070038
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080039Adding a route to the FIB manually:
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070040
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080041 .. code-block:: c++
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070042
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080043 Ptr<Node> node = ... // some node
44 std::string prefix = ... // some prefix
45 Ptr<ndn::Face> face = ... // NDN face that belongs to the node and through which prefix is accessible
46 int32_t metric = ... // some routing metric
47 FibHelper::AddRoute(node, prefix, face, metric);
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070048
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080049:ndnsim:`FIB helper <FibHelper>` has few other AddRoute overloads that may be easier to
50 use. For example, when setting up manual routes between nodes connected with
51 PointToPointNetDevice's, it is simpler to use the overload that accepts two nodes
52 (face will be automatically determined by the helper).
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070053
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080054.. @todo Implement RemoveRoute and add documentation about it
55
56..
57 Adding a next hop to a FIB entry (if any) that matches a given name prefix for a topology node:
58
59 .. code-block:: c++
60
61 Ptr<Node> node = .. // Get the desired node
62 FibHelper::AddRoute(parameters, node);
63
64..
65 Removing a next hop from a FIB entry (if any) that matches a given name prefix for a topology node:
66
67 .. code-block:: c++
68
69 Ptr<Node> node = // Get the desired node
70 nfd::ControlParameters parameters;
71 parameters.setName(prefix);
72 FibHelper::RemoveNextHop(parameters, node);
73
74
75Automatic Shortest Path Routes (Global Routing Helper)
76^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
77
78To simplify FIB management in large topologies, ndnSIM contains a global routing
79controller (:ndnsim:`helper <GlobalRoutingHelper>` and :ndnsim:`special interface
80<GlobalRouter>`), similar in spirit to ``Ipv4GlobalRoutingHelper``.
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070081
82There are several necessary steps, in order to take advantage of the global routing controller:
83
Alexander Afanasyevf6807a52012-08-10 18:11:43 -070084* install :ndnsim:`special interfaces <GlobalRouter>` on nodes
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070085
86 .. code-block:: c++
Alexander Afanasyeve6852122013-01-21 11:54:47 -080087
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070088 NodeContainer nodes;
89 ...
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080090 GlobalRoutingHelper ndnGlobalRoutingHelper;
91 ndnGlobalRoutingHelper.Install(nodes);
Alexander Afanasyeve6852122013-01-21 11:54:47 -080092
Alexander Afanasyevf6807a52012-08-10 18:11:43 -070093* specify which node exports which prefix using :ndnsim:`GlobalRoutingHelper::AddOrigins`
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070094
95 .. code-block:: c++
Alexander Afanasyeve6852122013-01-21 11:54:47 -080096
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070097 Ptr<Node> producer; // producer node that exports prefix
98 std::string prefix; // exported prefix
99 ...
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800100 ndnGlobalRoutingHelper.AddOrigins(prefix, producer);
Alexander Afanasyeve6852122013-01-21 11:54:47 -0800101
Alexander Afanasyevf6807a52012-08-10 18:11:43 -0700102* calculate and install FIBs on every node using :ndnsim:`GlobalRoutingHelper::CalculateRoutes`
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700103
104 .. code-block:: c++
Alexander Afanasyeve6852122013-01-21 11:54:47 -0800105
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800106 GlobalRoutingHelper::CalculateRoutes();
Alexander Afanasyeve6852122013-01-21 11:54:47 -0800107
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800108Forwarding Strategy
109+++++++++++++++++++
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800110
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800111ndnSIM 2.0 exactly like NFD allows different namespaces to be associated with different
112forwarding strategies. By default, the following forwarding strategy configuration is defined:
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800113
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800114+--------------------+------------------------------+-----------------------------------------------+
115| Namespace | Strategy | Strategy Name |
116+====================+==============================+===============================================+
117| ``/`` | :nfd:`fw::BestRouteStrategy` | ``/localhost/nfd/strategy/best-route`` |
118+--------------------+------------------------------+-----------------------------------------------+
119| ``/localhost`` | :nfd:`fw::BroadcastStrategy` | ``/localhost/nfd/strategy/broadcast`` |
120+--------------------+------------------------------+-----------------------------------------------+
121| ``/localhost/nfd`` | :nfd:`fw::BestRouteStrategy` | ``/localhost/nfd/strategy/best-route`` |
122+--------------------+------------------------------+-----------------------------------------------+
123| ``/ndn/broadcast`` | :nfd:`fw::BroadcastStrategy` | ``/localhost/nfd/strategy/broadcast`` |
124+--------------------+------------------------------+-----------------------------------------------+
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800125
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800126
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800127
128
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800129The :ndnsim:`Strategy Choice helper <StrategyChoiceHelper>` interacts with the Strategy
130Choice manager of NFD by sending special Interest commands to the manager in order to
131specify the desired per-name prefix forwarding strategy for one, more or all the nodes of a topology.
132
133This helper should be used as follows:
134
135 .. code-block:: c++
136
137 StrategyChoiceHelper::Install(nodes, prefix, strategyName);
138
139or (for a forwarding strategy to be installed in all the topology nodes):
140
141 .. code-block:: c++
142
143 StrategyChoiceHelper::InstallAll(prefix, strategyName);
144
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800145Content Store
146+++++++++++++
147
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800148ndnSIM uses NFD's content store implementation, maximum size of which can be controlled using
149:ndnsim:`StackHelper::setCsSize()`:
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800150
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800151 .. code-block:: c++
152
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800153 ndnHelper.setCsSize(<max-size-in-packets>);
154 ...
155 ndnHelper.Install(nodes);
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800156
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800157.. note::
158
159 Unless specified in the simulation scenario, default maximum size of the content store is
160 100 Data packets.
161
162.. note::
163
164 NFD's content store implementation takes full consideration of Interest selectors, however
165 is not yet flexible when it comes to cache replacement policies. Feature to extend CS
166 flexibility is currently in active development (refer to `Issue #2219 on NFD Redmine
167 <http://redmine.named-data.net/issues/2219>`_) and for the time being, we have ported the
168 old ndnSIM 1.0 content store implementations to the new code base. These implementations
169 feature different cache replacement policies, but have very limited support for Interest
170 selectors. If your scenario relies on proper selector processing, do not use these
171 implementations as the simulation results most likely be incorrect.
172
173 To select old content store implementations, use :ndnsim:`SetOldContentStore
174 <StackHelper::SetOldContentStore>` StackHelper method:
175
176 .. code-block:: c++
177
178 ndnHelper.SetOldContentStore("<content store implementation>",
179 ["<optional parameter>", "<optional parameter's value>" [, ...]]);
180 ...
181 ndnHelper.Install (nodes);
182
183 In simulation scenarios it is possible to select one of :ref:`the existing implementations
184 of the content store or implement your own <content store>`.
Alexander Afanasyevf4a03592012-12-10 16:12:34 -0800185
186
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800187Application Helper
188------------------
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800189
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800190:ndnsim:`AppHelper` simplifies task of creating, configuring, and installing ndnSIM
191applications.
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700192
193
Alexander Afanasyevf6807a52012-08-10 18:11:43 -0700194The basic usage of the :ndnsim:`AppHelper`:
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700195
196* Create helper for specific applications class:
197
198 .. code-block:: c++
199
200 // Create helper for the consumer generating Interests with constant rate
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800201 AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700202
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800203* Assign prefix on which application operates (either generating Interests using this name
204 or satisfying Interests for this name) using :ndnsim:`AppHelper::SetPrefix`:
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700205
206 .. code-block:: c++
207
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800208 consumerHelper.SetPrefix(prefix);
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700209
Alexander Afanasyevf6807a52012-08-10 18:11:43 -0700210* Assign application-specific attributes using :ndnsim:`AppHelper::SetAttribute`:
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700211
212 .. code-block:: c++
213
214 // Set frequency parameter
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800215 consumerHelper.SetAttribute("Frequency", StringValue ("10")); // 10 interests a second
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700216
217* Install application on one or more nodes:
218
219 .. code-block:: c++
220
221 NodeContainer nodes;
222 ...
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800223 consumerHelper.Install(nodes)
224
225.. _Link Control Helper:
226
227Link Control Helper
228-------------------
229
230Some scenarios require failing certain links between NDN nodes at certain times. NS-3 does not
231provide ability to actually "break" the link between nodes. However, it provides facility to
232set up a loss model to simulate packet drops in the channel. Using the properly set up loss
233model on both sides of the point-to-point link, it is possible to emulate link breakage.
234
235To simplify these operations, ndnSIM includes :ndnsim:`ndn::LinkControlHelper` that allows
236scheduling of link failures and failure recoveries:
Alexander Afanasyeve6852122013-01-21 11:54:47 -0800237
238
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800239 .. code-block:: c++
240
241 #include "ns3/ndnSIM/helper/ndn-link-control-helper.hpp"
242
243 ...
244
245 Simulator::Schedule(Seconds(10.0), ndn::LinkControlHelper::FailLink, node1, node2);
246 Simulator::Schedule(Seconds(15.0), ndn::LinkControlHelper::UpLink, node1, node2);
247
248Usage of this helper is demonstrated in :ref:`Simple scenario with link failures`.