Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 1 | ndnSIM helpers |
| 2 | ============== |
| 3 | |
| 4 | Helpers are very important components of ndnSIM, especially for writing simulation scenarios. |
| 5 | The following summarizes helpers and their basic usage. |
| 6 | |
Alexander Afanasyev | f6807a5 | 2012-08-10 18:11:43 -0700 | [diff] [blame] | 7 | StackHelper |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 8 | --------------- |
| 9 | |
Alexander Afanasyev | f6807a5 | 2012-08-10 18:11:43 -0700 | [diff] [blame] | 10 | :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 Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 11 | |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 12 | Example: |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 13 | |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 14 | .. code-block:: c++ |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 15 | |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 16 | ndn::StackHelper ndnHelper; |
| 17 | NodeContainer nodes; |
| 18 | ... |
| 19 | ndnHelper.Install (nodes); |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 20 | |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 21 | Routing |
| 22 | +++++++ |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 23 | |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 24 | All forwarding strategies require knowledge of where Interests can be forwarded (Forwarding Information Base). |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 25 | Unlike 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 Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 26 | |
| 27 | .. note:: |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 28 | 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 Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 29 | |
| 30 | Manually routes |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 31 | ^^^^^^^^^^^^^^^ |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 32 | |
Alexander Afanasyev | f6807a5 | 2012-08-10 18:11:43 -0700 | [diff] [blame] | 33 | Routes can be configured manually using :ndnsim:`StackHelper::AddRoute` static methods of :ndnsim:`StackHelper`. |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 34 | |
| 35 | These routes **should** be created **after** installing NDN stack on a node: |
| 36 | |
| 37 | .. code-block:: c++ |
| 38 | |
Alexander Afanasyev | b8d14ad | 2012-08-09 13:19:37 -0700 | [diff] [blame] | 39 | ndnHelper.Install (nodes); |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 40 | ... |
| 41 | Ptr<Node> node = ... // FIB entry will be added to FIB on this node |
| 42 | std::string prefix = ... // some prefix |
Alexander Afanasyev | f6807a5 | 2012-08-10 18:11:43 -0700 | [diff] [blame] | 43 | Ptr<ndn::Face> face = ... // NDN face that belongs to the node and through which prefix is accessible |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 44 | int32_t metric = ... // some routing metric |
Alexander Afanasyev | f6807a5 | 2012-08-10 18:11:43 -0700 | [diff] [blame] | 45 | ndn::StackHelper::AddRoute (node, prefix, face, metric); |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 46 | |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 47 | Global routing controller |
| 48 | ^^^^^^^^^^^^^^^^^^^^^^^^^ |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 49 | |
Alexander Afanasyev | f6807a5 | 2012-08-10 18:11:43 -0700 | [diff] [blame] | 50 | To 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 Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 51 | |
| 52 | There are several necessary steps, in order to take advantage of the global routing controller: |
| 53 | |
Alexander Afanasyev | f6807a5 | 2012-08-10 18:11:43 -0700 | [diff] [blame] | 54 | * install :ndnsim:`special interfaces <GlobalRouter>` on nodes |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 55 | |
| 56 | .. code-block:: c++ |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 57 | |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 58 | NodeContainer nodes; |
| 59 | ... |
Alexander Afanasyev | f6807a5 | 2012-08-10 18:11:43 -0700 | [diff] [blame] | 60 | ndn::GlobalRoutingHelper ndnGlobalRoutingHelper; |
Alexander Afanasyev | b8d14ad | 2012-08-09 13:19:37 -0700 | [diff] [blame] | 61 | ndnGlobalRoutingHelper.Install (nodes); |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 62 | |
Alexander Afanasyev | f6807a5 | 2012-08-10 18:11:43 -0700 | [diff] [blame] | 63 | * specify which node exports which prefix using :ndnsim:`GlobalRoutingHelper::AddOrigins` |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 64 | |
| 65 | .. code-block:: c++ |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 66 | |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 67 | Ptr<Node> producer; // producer node that exports prefix |
| 68 | std::string prefix; // exported prefix |
| 69 | ... |
Alexander Afanasyev | b8d14ad | 2012-08-09 13:19:37 -0700 | [diff] [blame] | 70 | ndnGlobalRoutingHelper.AddOrigins (prefix, producer); |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 71 | |
Alexander Afanasyev | f6807a5 | 2012-08-10 18:11:43 -0700 | [diff] [blame] | 72 | * calculate and install FIBs on every node using :ndnsim:`GlobalRoutingHelper::CalculateRoutes` |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 73 | |
| 74 | .. code-block:: c++ |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 75 | |
Alexander Afanasyev | b8d14ad | 2012-08-09 13:19:37 -0700 | [diff] [blame] | 76 | cdnGlobalRoutingHelper.CalculateRoutes (); |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 77 | |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 78 | Default routes |
| 79 | ^^^^^^^^^^^^^^ |
| 80 | |
| 81 | In simple topologies, like in :doc:`examples <examples>`, or when |
| 82 | simulating broadcast environment, it is possible to set up *default* |
| 83 | FIB entries using :ndnsim:`StackHelper::SetDefaultRoutes` call. |
| 84 | More specifically, every installed NDN stack will have a FIB entry to ``/`` prefix, containing all available faces. |
| 85 | |
| 86 | The 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 | |
| 95 | Content Store |
| 96 | +++++++++++++ |
| 97 | |
| 98 | ndnSIM comes with several different in-memory :ndnsim:`content store <ndn::ContentStore>` implementations, featuring different cache replacement policies. |
| 99 | |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 100 | To select a particular content store and configure its capacity, use :ndnsim:`SetContentStore <ndn::StackHelper::SetContentStore>` helper method: |
| 101 | |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 102 | .. code-block:: c++ |
| 103 | |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 104 | ndnHelper.SetContentStore ("<content store implementation>", |
| 105 | ["<optional parameter>", "<optional parameter's value>" [, ...]]); |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 106 | ... |
| 107 | ndnHelper.Install (nodes); |
| 108 | |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 109 | In simulation scenarios it is possible to select one of :ref:`the existing implementations of the content store or implement your own <content store>`. |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 110 | |
| 111 | |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 112 | Pending Interest Table |
| 113 | ++++++++++++++++++++++ |
| 114 | |
| 115 | The 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). |
| 116 | |
| 117 | To select a particular PIT implementation and configure its policies, use :ndnsim:`SetPit <ndn::StackHelper::SetPit>` helper method: |
| 118 | |
| 119 | - :ndnsim:`persistent <ndn::pit::Persistent>` (default): |
| 120 | |
| 121 | New entries will be rejected if PIT size reached its limit |
| 122 | |
| 123 | .. code-block:: c++ |
| 124 | |
| 125 | ndnHelper.SetPit ("ns3::ndn::pit::Persistent", |
| 126 | "MaxSize", "0"); |
| 127 | ... |
| 128 | ndnHelper.Install (nodes); |
| 129 | |
| 130 | - :ndnsim:`random <ndn::pit::Random>`: |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 131 | |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 132 | when PIT reaches its limit, random entry (could be the newly created one) will be removed from PIT; |
| 133 | |
| 134 | .. code-block:: c++ |
| 135 | |
| 136 | ndnHelper.SetPit ("ns3::ndn::pit::Random", |
| 137 | "MaxSize", "0"); |
| 138 | ... |
| 139 | ndnHelper.Install (nodes); |
| 140 | |
| 141 | - :ndnsim:`least-recently-used <ndn::pit::Lru>`: |
| 142 | |
| 143 | the least recently used entry (the oldest entry with minimum number of incoming faces) will be removed when PIT size reached its limit. |
| 144 | |
| 145 | .. code-block:: c++ |
| 146 | |
| 147 | ndnHelper.SetPit ("ns3::ndn::pit::Lru", |
| 148 | "MaxSize", "0"); |
| 149 | ... |
| 150 | ndnHelper.Install (nodes); |
| 151 | |
| 152 | Forwarding strategy |
| 153 | +++++++++++++++++++ |
| 154 | |
| 155 | A desired :ndnsim:`forwarding strategy <ForwardingStrategy>` parameter need to be set before installing stack on a node. |
| 156 | |
Alexander Afanasyev | dc794a3 | 2013-09-26 14:34:18 -0700 | [diff] [blame] | 157 | To select a particular forwarding strategy implementation and configure its parameters, use :ndnsim:`SetForwardingStrategy <ndn::StackHelper::SetForwardingStrategy>` helper method: |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 158 | |
| 159 | .. code-block:: c++ |
| 160 | |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 161 | ndnHelper.SetForwardingStrategy ("<forwarding strategy implementation>", |
| 162 | ["<optional parameter>", "<optional parameter's value>" [, ...]]); |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 163 | ... |
| 164 | ndnHelper.Install (nodes); |
| 165 | |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 166 | In simulation scenarios it is possible to select one of :ref:`the existing implementations of the forwarding strategy or implement your own <forwarding strategies>`. |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 167 | |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 168 | |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 169 | .. Currently, there are following forwarding strategies that can be used in simulations: |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 170 | |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 171 | .. - :ndnsim:`Flooding` (default) |
| 172 | |
| 173 | .. Interests will be forwarded to all available faces available for a route (FIB entry). |
| 174 | .. If there are no available GREEN or YELLOW faces, interests is dropped. |
| 175 | |
| 176 | .. .. code-block:: c++ |
| 177 | |
| 178 | .. ndnHelper.SetForwardingStrategy ("ns3::ndn::fw::Flooding"); |
| 179 | .. ... |
| 180 | .. ndnHelper.Install (nodes); |
| 181 | |
| 182 | |
| 183 | .. - :ndnsim:`SmartFlooding` |
| 184 | |
| 185 | .. If GREEN face is available, Interest will be sent to the highest-ranked GREEN face. |
| 186 | .. If not, Interest will be forwarded to all available faces available for a route (FIB entry)/ |
| 187 | .. If there are no available GREEN or YELLOW faces, interests is dropped. |
| 188 | |
| 189 | .. .. code-block:: c++ |
| 190 | |
| 191 | .. ndnHelper.SetForwardingStrategy ("ns3::ndn::fw::SmartFlooding"); |
| 192 | .. ... |
| 193 | .. ndnHelper.Install (nodes); |
| 194 | |
| 195 | .. - :ndnsim:`BestRoute` |
| 196 | |
| 197 | .. If GREEN face is available, Interest will be sent to the highest-ranked GREEN face. |
| 198 | .. If not, Interest will be forwarded to the highest-ranked YELLOW face. |
| 199 | .. If there are no available GREEN or YELLOW faces, interests is dropped. |
| 200 | |
| 201 | .. .. code-block:: c++ |
| 202 | |
| 203 | .. ndnHelper.SetForwardingStrategy ("ns3::ndn::fw::BestRoute"); |
| 204 | .. ... |
| 205 | .. ndnHelper.Install (nodes); |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 206 | |
| 207 | |
| 208 | |
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 | AppHelper |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 211 | --------------- |
| 212 | |
Alexander Afanasyev | f6807a5 | 2012-08-10 18:11:43 -0700 | [diff] [blame] | 213 | :ndnsim:`AppHelper` simplifies task of creating, configuring, and installing ndnSIM applications. |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 214 | |
| 215 | |
Alexander Afanasyev | f6807a5 | 2012-08-10 18:11:43 -0700 | [diff] [blame] | 216 | The basic usage of the :ndnsim:`AppHelper`: |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 217 | |
| 218 | * Create helper for specific applications class: |
| 219 | |
| 220 | .. code-block:: c++ |
| 221 | |
| 222 | // Create helper for the consumer generating Interests with constant rate |
Alexander Afanasyev | f6807a5 | 2012-08-10 18:11:43 -0700 | [diff] [blame] | 223 | ndn::AppHelper consumerHelper ("ns3::ndn::ConsumerCbr"); |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 224 | |
Alexander Afanasyev | f6807a5 | 2012-08-10 18:11:43 -0700 | [diff] [blame] | 225 | * Assign prefix on which application operates (either generating Interests using this name or satisfying Interests for this name) using :ndnsim:`AppHelper::SetPrefix`: |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 226 | |
| 227 | .. code-block:: c++ |
| 228 | |
| 229 | consumerHelper.SetPrefix (prefix); |
| 230 | |
Alexander Afanasyev | f6807a5 | 2012-08-10 18:11:43 -0700 | [diff] [blame] | 231 | * Assign application-specific attributes using :ndnsim:`AppHelper::SetAttribute`: |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 232 | |
| 233 | .. code-block:: c++ |
| 234 | |
| 235 | // Set frequency parameter |
| 236 | consumerHelper.SetAttribute ("Frequency", StringValue ("10")); // 10 interests a second |
| 237 | |
| 238 | * Install application on one or more nodes: |
| 239 | |
| 240 | .. code-block:: c++ |
| 241 | |
| 242 | NodeContainer nodes; |
| 243 | ... |
| 244 | consumerHelper.Install (nodes) |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 245 | |
| 246 | |
| 247 | In simulation scenarios it is possible to select one of :ref:`the existing applications or implement your own <applications>`. |