blob: 4595c0b67215b265b5ce30a8d15fb83d530782de [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+--------------------+------------------------------+-----------------------------------------------+
Alexander Afanasyevc3c7f042015-08-21 11:38:00 -0700119| ``/localhost`` | :nfd:`fw::MulticastStrategy` | ``/localhost/nfd/strategy/multicast`` |
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800120+--------------------+------------------------------+-----------------------------------------------+
121| ``/localhost/nfd`` | :nfd:`fw::BestRouteStrategy` | ``/localhost/nfd/strategy/best-route`` |
122+--------------------+------------------------------+-----------------------------------------------+
Alexander Afanasyevc3c7f042015-08-21 11:38:00 -0700123| ``/ndn/multicast`` | :nfd:`fw::MulticastStrategy` | ``/localhost/nfd/strategy/multicast`` |
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800124+--------------------+------------------------------+-----------------------------------------------+
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
spirosmastorakis2c9c0052016-10-31 13:51:14 -0700164 NFD's content store implementation takes full consideration of Interest selectors.
165 In contrast to that, the old ndnSIM 1.0 content store implementations have very limited
166 support for Interest selectors, but features a number of different replacement policies.
167 If your scenario relies on proper selector processing, do not use these implementations as
168 the simulation results most likely be incorrect.
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800169
170 To select old content store implementations, use :ndnsim:`SetOldContentStore
171 <StackHelper::SetOldContentStore>` StackHelper method:
172
173 .. code-block:: c++
174
175 ndnHelper.SetOldContentStore("<content store implementation>",
176 ["<optional parameter>", "<optional parameter's value>" [, ...]]);
177 ...
178 ndnHelper.Install (nodes);
179
180 In simulation scenarios it is possible to select one of :ref:`the existing implementations
181 of the content store or implement your own <content store>`.
Alexander Afanasyevf4a03592012-12-10 16:12:34 -0800182
183
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800184Application Helper
185------------------
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800186
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800187:ndnsim:`AppHelper` simplifies task of creating, configuring, and installing ndnSIM
188applications.
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700189
190
Alexander Afanasyevf6807a52012-08-10 18:11:43 -0700191The basic usage of the :ndnsim:`AppHelper`:
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700192
193* Create helper for specific applications class:
194
195 .. code-block:: c++
196
197 // Create helper for the consumer generating Interests with constant rate
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800198 AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700199
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800200* Assign prefix on which application operates (either generating Interests using this name
201 or satisfying Interests for this name) using :ndnsim:`AppHelper::SetPrefix`:
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700202
203 .. code-block:: c++
204
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800205 consumerHelper.SetPrefix(prefix);
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700206
Alexander Afanasyevf6807a52012-08-10 18:11:43 -0700207* Assign application-specific attributes using :ndnsim:`AppHelper::SetAttribute`:
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700208
209 .. code-block:: c++
210
211 // Set frequency parameter
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800212 consumerHelper.SetAttribute("Frequency", StringValue ("10")); // 10 interests a second
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700213
214* Install application on one or more nodes:
215
216 .. code-block:: c++
217
218 NodeContainer nodes;
219 ...
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800220 consumerHelper.Install(nodes)
221
222.. _Link Control Helper:
223
224Link Control Helper
225-------------------
226
227Some scenarios require failing certain links between NDN nodes at certain times. NS-3 does not
228provide ability to actually "break" the link between nodes. However, it provides facility to
229set up a loss model to simulate packet drops in the channel. Using the properly set up loss
230model on both sides of the point-to-point link, it is possible to emulate link breakage.
231
232To simplify these operations, ndnSIM includes :ndnsim:`ndn::LinkControlHelper` that allows
233scheduling of link failures and failure recoveries:
Alexander Afanasyeve6852122013-01-21 11:54:47 -0800234
235
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800236 .. code-block:: c++
237
238 #include "ns3/ndnSIM/helper/ndn-link-control-helper.hpp"
239
240 ...
241
242 Simulator::Schedule(Seconds(10.0), ndn::LinkControlHelper::FailLink, node1, node2);
243 Simulator::Schedule(Seconds(15.0), ndn::LinkControlHelper::UpLink, node1, node2);
244
245Usage of this helper is demonstrated in :ref:`Simple scenario with link failures`.