blob: 5613a6f09b1b8a394c25e5fddd1e7df85bc7232d [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
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800164 In simulation scenarios it is possible to select one of :ref:`the existing implementations
165 of the content store or implement your own <content store>`.
Alexander Afanasyevf4a03592012-12-10 16:12:34 -0800166
167
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800168Application Helper
169------------------
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -0800170
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800171:ndnsim:`AppHelper` simplifies task of creating, configuring, and installing ndnSIM
172applications.
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700173
174
Alexander Afanasyevf6807a52012-08-10 18:11:43 -0700175The basic usage of the :ndnsim:`AppHelper`:
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700176
177* Create helper for specific applications class:
178
179 .. code-block:: c++
180
181 // Create helper for the consumer generating Interests with constant rate
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800182 AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700183
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800184* Assign prefix on which application operates (either generating Interests using this name
185 or satisfying Interests for this name) using :ndnsim:`AppHelper::SetPrefix`:
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700186
187 .. code-block:: c++
188
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800189 consumerHelper.SetPrefix(prefix);
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700190
Alexander Afanasyevf6807a52012-08-10 18:11:43 -0700191* Assign application-specific attributes using :ndnsim:`AppHelper::SetAttribute`:
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700192
193 .. code-block:: c++
194
195 // Set frequency parameter
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800196 consumerHelper.SetAttribute("Frequency", StringValue ("10")); // 10 interests a second
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700197
198* Install application on one or more nodes:
199
200 .. code-block:: c++
201
202 NodeContainer nodes;
203 ...
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800204 consumerHelper.Install(nodes)
205
206.. _Link Control Helper:
207
208Link Control Helper
209-------------------
210
211Some scenarios require failing certain links between NDN nodes at certain times. NS-3 does not
212provide ability to actually "break" the link between nodes. However, it provides facility to
213set up a loss model to simulate packet drops in the channel. Using the properly set up loss
214model on both sides of the point-to-point link, it is possible to emulate link breakage.
215
216To simplify these operations, ndnSIM includes :ndnsim:`ndn::LinkControlHelper` that allows
217scheduling of link failures and failure recoveries:
Alexander Afanasyeve6852122013-01-21 11:54:47 -0800218
219
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -0800220 .. code-block:: c++
221
222 #include "ns3/ndnSIM/helper/ndn-link-control-helper.hpp"
223
224 ...
225
226 Simulator::Schedule(Seconds(10.0), ndn::LinkControlHelper::FailLink, node1, node2);
227 Simulator::Schedule(Seconds(15.0), ndn::LinkControlHelper::UpLink, node1, node2);
228
229Usage of this helper is demonstrated in :ref:`Simple scenario with link failures`.