Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 1 | ndnSIM helpers |
| 2 | ============== |
| 3 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 4 | Helpers are very important components of ndnSIM, especially for writing simulation |
| 5 | scenarios. The following summarizes helpers and their basic usage. |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 6 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 7 | NDN Stack Helpers |
| 8 | ----------------- |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 9 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 10 | :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 Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 12 | |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 13 | Example: |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 14 | |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 15 | .. code-block:: c++ |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 16 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 17 | StackHelper ndnHelper; |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 18 | NodeContainer nodes; |
| 19 | ... |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 20 | ndnHelper.Install(nodes); |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 21 | |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 22 | Routing |
| 23 | +++++++ |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 24 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 25 | All forwarding strategies require knowledge of where Interests can be forwarded |
| 26 | (Forwarding Information Base). |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 27 | |
| 28 | .. note:: |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 29 | 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 Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 31 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 32 | Manually routes (FIB Helper) |
| 33 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 34 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 35 | The :ndnsim:`FIB helper <FibHelper>` interacts with the FIB manager of NFD by sending |
| 36 | special Interest commands to the manager in order to add/remove a next hop from FIB |
| 37 | entries or add routes to the FIB manually (manual configuration of FIB). |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 38 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 39 | Adding a route to the FIB manually: |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 40 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 41 | .. code-block:: c++ |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 42 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 43 | 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 Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 48 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 49 | :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 Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 53 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 54 | .. @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 | |
| 75 | Automatic Shortest Path Routes (Global Routing Helper) |
| 76 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 77 | |
| 78 | To simplify FIB management in large topologies, ndnSIM contains a global routing |
| 79 | controller (:ndnsim:`helper <GlobalRoutingHelper>` and :ndnsim:`special interface |
| 80 | <GlobalRouter>`), similar in spirit to ``Ipv4GlobalRoutingHelper``. |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 81 | |
| 82 | There are several necessary steps, in order to take advantage of the global routing controller: |
| 83 | |
Alexander Afanasyev | f6807a5 | 2012-08-10 18:11:43 -0700 | [diff] [blame] | 84 | * install :ndnsim:`special interfaces <GlobalRouter>` on nodes |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 85 | |
| 86 | .. code-block:: c++ |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 87 | |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 88 | NodeContainer nodes; |
| 89 | ... |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 90 | GlobalRoutingHelper ndnGlobalRoutingHelper; |
| 91 | ndnGlobalRoutingHelper.Install(nodes); |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 92 | |
Alexander Afanasyev | f6807a5 | 2012-08-10 18:11:43 -0700 | [diff] [blame] | 93 | * specify which node exports which prefix using :ndnsim:`GlobalRoutingHelper::AddOrigins` |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 94 | |
| 95 | .. code-block:: c++ |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 96 | |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 97 | Ptr<Node> producer; // producer node that exports prefix |
| 98 | std::string prefix; // exported prefix |
| 99 | ... |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 100 | ndnGlobalRoutingHelper.AddOrigins(prefix, producer); |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 101 | |
Alexander Afanasyev | f6807a5 | 2012-08-10 18:11:43 -0700 | [diff] [blame] | 102 | * calculate and install FIBs on every node using :ndnsim:`GlobalRoutingHelper::CalculateRoutes` |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 103 | |
| 104 | .. code-block:: c++ |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 105 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 106 | GlobalRoutingHelper::CalculateRoutes(); |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 107 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 108 | Forwarding Strategy |
| 109 | +++++++++++++++++++ |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 110 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 111 | ndnSIM 2.0 exactly like NFD allows different namespaces to be associated with different |
| 112 | forwarding strategies. By default, the following forwarding strategy configuration is defined: |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 113 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 114 | +--------------------+------------------------------+-----------------------------------------------+ |
| 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 Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 125 | |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 126 | |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 127 | |
| 128 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 129 | The :ndnsim:`Strategy Choice helper <StrategyChoiceHelper>` interacts with the Strategy |
| 130 | Choice manager of NFD by sending special Interest commands to the manager in order to |
| 131 | specify the desired per-name prefix forwarding strategy for one, more or all the nodes of a topology. |
| 132 | |
| 133 | This helper should be used as follows: |
| 134 | |
| 135 | .. code-block:: c++ |
| 136 | |
| 137 | StrategyChoiceHelper::Install(nodes, prefix, strategyName); |
| 138 | |
| 139 | or (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 Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 145 | Content Store |
| 146 | +++++++++++++ |
| 147 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 148 | ndnSIM uses NFD's content store implementation, maximum size of which can be controlled using |
| 149 | :ndnsim:`StackHelper::setCsSize()`: |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 150 | |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 151 | .. code-block:: c++ |
| 152 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 153 | ndnHelper.setCsSize(<max-size-in-packets>); |
| 154 | ... |
| 155 | ndnHelper.Install(nodes); |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 156 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 157 | .. 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 Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 185 | |
| 186 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 187 | Application Helper |
| 188 | ------------------ |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 189 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 190 | :ndnsim:`AppHelper` simplifies task of creating, configuring, and installing ndnSIM |
| 191 | applications. |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 192 | |
| 193 | |
Alexander Afanasyev | f6807a5 | 2012-08-10 18:11:43 -0700 | [diff] [blame] | 194 | The basic usage of the :ndnsim:`AppHelper`: |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 195 | |
| 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 Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 201 | AppHelper consumerHelper("ns3::ndn::ConsumerCbr"); |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 202 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 203 | * Assign prefix on which application operates (either generating Interests using this name |
| 204 | or satisfying Interests for this name) using :ndnsim:`AppHelper::SetPrefix`: |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 205 | |
| 206 | .. code-block:: c++ |
| 207 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 208 | consumerHelper.SetPrefix(prefix); |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 209 | |
Alexander Afanasyev | f6807a5 | 2012-08-10 18:11:43 -0700 | [diff] [blame] | 210 | * Assign application-specific attributes using :ndnsim:`AppHelper::SetAttribute`: |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 211 | |
| 212 | .. code-block:: c++ |
| 213 | |
| 214 | // Set frequency parameter |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 215 | consumerHelper.SetAttribute("Frequency", StringValue ("10")); // 10 interests a second |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 216 | |
| 217 | * Install application on one or more nodes: |
| 218 | |
| 219 | .. code-block:: c++ |
| 220 | |
| 221 | NodeContainer nodes; |
| 222 | ... |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 223 | consumerHelper.Install(nodes) |
| 224 | |
| 225 | .. _Link Control Helper: |
| 226 | |
| 227 | Link Control Helper |
| 228 | ------------------- |
| 229 | |
| 230 | Some scenarios require failing certain links between NDN nodes at certain times. NS-3 does not |
| 231 | provide ability to actually "break" the link between nodes. However, it provides facility to |
| 232 | set up a loss model to simulate packet drops in the channel. Using the properly set up loss |
| 233 | model on both sides of the point-to-point link, it is possible to emulate link breakage. |
| 234 | |
| 235 | To simplify these operations, ndnSIM includes :ndnsim:`ndn::LinkControlHelper` that allows |
| 236 | scheduling of link failures and failure recoveries: |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 237 | |
| 238 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 239 | .. 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 | |
| 248 | Usage of this helper is demonstrated in :ref:`Simple scenario with link failures`. |