Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 1 | .. _forwarding strategies: |
Alexander Afanasyev | e74cc1c | 2012-11-21 13:10:03 -0800 | [diff] [blame] | 2 | |
| 3 | Forwarding Strategies |
| 4 | ===================== |
| 5 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 6 | ndnSIM through its integration with NFD provides simple ways to experiment with the custom |
| 7 | Interest/Data forwarding strategies of NFD. |
| 8 | |
| 9 | A new forwarding strategy can be implement completely different processing or override just |
| 10 | specific actions/events of the :nfd:`forwarding strategy interface <nfd::fw::Strategy>`. NFD |
| 11 | offers the maximum flexibility by allowing per-namespace selection of each specific forwarding |
| 12 | strategy. |
| 13 | |
| 14 | Please refer to :nfd:`API documentation <nfd::fw::Strategy>` of the forwarding strategy |
| 15 | interface, which lists all default actions/events. For a more detailed specification, you can |
| 16 | read `NFD Developer's Guide |
| 17 | <http://named-data.net/wp-content/uploads/2014/07/NFD-developer-guide.pdf>`_, section 5. |
Alexander Afanasyev | e74cc1c | 2012-11-21 13:10:03 -0800 | [diff] [blame] | 18 | |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 19 | Available forwarding strategies |
| 20 | +++++++++++++++++++++++++++++++ |
| 21 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 22 | +--------------------------------------------+----------------------------------------------------------------------------------------------+ |
| 23 | | Strategy Name | Description | |
| 24 | +============================================+==============================================================================================+ |
| 25 | | ``/localhost/nfd/strategy/best-route`` | :nfd:`Best Route Strategy <nfd::fw::BestRouteStrategy2>` **(default)** | |
| 26 | | | | |
| 27 | | | The best route strategy forwards an Interest to the | |
| 28 | | | upstream with lowest routing cost. | |
| 29 | +--------------------------------------------+----------------------------------------------------------------------------------------------+ |
| 30 | +--------------------------------------------+----------------------------------------------------------------------------------------------+ |
| 31 | | ``/localhost/nfd/strategy/ncc`` | :nfd:`NCC Strategy <nfd::fw::NccStrategy>` | |
| 32 | | | | |
| 33 | | | The NCC strategy is an reimplementation of CCNx 0.7.2 | |
| 34 | | | default strategy. It has similar algorithm but is not | |
| 35 | | | guaranteed to be equivalent. | |
| 36 | +--------------------------------------------+----------------------------------------------------------------------------------------------+ |
| 37 | +--------------------------------------------+----------------------------------------------------------------------------------------------+ |
Alexander Afanasyev | c3c7f04 | 2015-08-21 11:38:00 -0700 | [diff] [blame^] | 38 | | ``/localhost/nfd/strategy/multicast`` | :nfd:`Multicast Strategy <nfd::fw::MulticastStrategy>` | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 39 | | | | |
Alexander Afanasyev | c3c7f04 | 2015-08-21 11:38:00 -0700 | [diff] [blame^] | 40 | | | The multicast strategy forwards every Interest to all | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 41 | | | upstreams, indicated by the supplied FIB entry. | |
| 42 | +--------------------------------------------+----------------------------------------------------------------------------------------------+ |
| 43 | +--------------------------------------------+----------------------------------------------------------------------------------------------+ |
| 44 | | ``/localhost/nfd/strategy/client-control`` | :nfd:`Client Control Strategy <nfd::fw::ClientControlStrategy>` | |
| 45 | | | | |
| 46 | | | The client control strategy allows a local consumer | |
| 47 | | | application to choose the outgoing face of each Interest. | |
| 48 | +--------------------------------------------+----------------------------------------------------------------------------------------------+ |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 49 | |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 50 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 51 | .. note:: |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 52 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 53 | ndnSIM 2.0 exactly like NFD allows different namespaces to be associated with different |
| 54 | forwarding strategies. By default, the following forwarding strategy configuration is |
| 55 | defined: |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 56 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 57 | +--------------------+-----------------------------------------------+ |
| 58 | | Namespace | Strategy Name | |
| 59 | +====================+===============================================+ |
| 60 | | ``/`` | ``/localhost/nfd/strategy/best-route`` | |
| 61 | +--------------------+-----------------------------------------------+ |
Alexander Afanasyev | c3c7f04 | 2015-08-21 11:38:00 -0700 | [diff] [blame^] | 62 | | ``/localhost`` | ``/localhost/nfd/strategy/multicast`` | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 63 | +--------------------+-----------------------------------------------+ |
| 64 | | ``/localhost/nfd`` | ``/localhost/nfd/strategy/best-route`` | |
| 65 | +--------------------+-----------------------------------------------+ |
Alexander Afanasyev | c3c7f04 | 2015-08-21 11:38:00 -0700 | [diff] [blame^] | 66 | | ``/ndn/multicast`` | ``/localhost/nfd/strategy/multicast`` | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 67 | +--------------------+-----------------------------------------------+ |
| 68 | |
| 69 | |
| 70 | |
| 71 | Examples: |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 72 | |
| 73 | .. code-block:: c++ |
| 74 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 75 | StrategyChoiceHelper::Install(nodes, prefix, |
Alexander Afanasyev | c3c7f04 | 2015-08-21 11:38:00 -0700 | [diff] [blame^] | 76 | "/localhost/nfd/strategy/multicast"); |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 77 | |
Alexander Afanasyev | e685212 | 2013-01-21 11:54:47 -0800 | [diff] [blame] | 78 | |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 79 | .. _Writing your own custom strategy: |
| 80 | |
Alexander Afanasyev | e74cc1c | 2012-11-21 13:10:03 -0800 | [diff] [blame] | 81 | Writing your own custom strategy |
| 82 | ++++++++++++++++++++++++++++++++ |
| 83 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 84 | One of the objectives and features of ndnSIM 2.0 is that it uses NFD codebase for packet |
| 85 | forwarding. Therefore, writing strategy in ndnSIM is almost exactly the same process as |
| 86 | outlined in `Section 5.3 of the NFD Developer's Guide |
| 87 | <http://named-data.net/wp-content/uploads/2014/07/NFD-developer-guide.pdf>`_. |
Alexander Afanasyev | e74cc1c | 2012-11-21 13:10:03 -0800 | [diff] [blame] | 88 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 89 | The purpose of the strategy is to decides how to forward Interests and it is not intended to |
| 90 | override any processing steps in the forwarding pipelines of NFD. If it is desired to support |
| 91 | a new packet type (other than Interest and Data), a new field in Interest or Data packets, or |
| 92 | override some actions in the pipelines (e.g., disable ContentStore lookup), it can be |
| 93 | accomplished by modification of the forwarding pipelines in :nfd:`nfd::Forwarder` class. |
Alexander Afanasyev | e74cc1c | 2012-11-21 13:10:03 -0800 | [diff] [blame] | 94 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 95 | The initial step in creating a new strategy is to create a class, say ``MyStrategy`` that is |
| 96 | derived from :nfd:`nfd::fw::Strategy`. This subclass must at least override the triggers that are |
| 97 | marked pure virtual and may override other available triggers that are marked just virtual. |
| 98 | |
| 99 | If the strategy needs to store information, it is needed to decide whether the information |
| 100 | is related to a namespace or an Interest. Information related to a namespace but not |
| 101 | specific to an Interest should be stored in Measurements entries; information related to an |
| 102 | Interest should be stored in PIT entries, PIT downstream records, or PIT upstream records. |
| 103 | After this decision is made, a data structure derived from StrategyInfo class needs to be |
| 104 | declared. In the existing implementation, such data structures are declared as nested |
| 105 | classes as it provides natural grouping and scope protection of the strategy-specific |
| 106 | entity, but it is not required to follow the same model. If timers are needed, EventId |
| 107 | fields needs to be added to such data structure(s). |
| 108 | |
| 109 | .. image:: _static/nfd-forwarding-overview.png |
| 110 | :alt: Packet processing in NFD/ndnSIM is broken into a number of small “pipelines” and |
| 111 | strategy callbacks |
| 112 | |
| 113 | The final step is to implement one or more of the triggers with the desired strategy logic. |
| 114 | These triggers are listed below: |
| 115 | |
| 116 | - :nfd:`After Receive Interest Trigger <nfd::fw::Strategy::afterReceiveInterest()>` |
| 117 | |
| 118 | When an Interest is received, passes necessary checks, and needs to be forwarded, Incoming |
| 119 | Interest pipeline (Section 4.2.1) invokes this trigger with the PIT entry, incoming Interest |
| 120 | packet, and FIB entry. At that time, the following conditions hold for the Interest: |
| 121 | |
| 122 | - The Interest does not violate ``/localhost`` scope. |
| 123 | - The Interest is not looped. |
| 124 | - The Interest cannot be satisfied by ContentStore. |
| 125 | - The Interest is under a namespace managed by this strategy. |
| 126 | |
| 127 | After being triggered, the strategy should decide whether and where to forward this |
| 128 | Interest. If the strategy decides to forward this Interest, it should invoke send Interest |
| 129 | action at least once. If the strategy concludes that this Interest cannot be forwarded, it |
| 130 | should invoke reject pending Interest action, so that the PIT entry will be deleted |
| 131 | shortly. |
| 132 | |
| 133 | - :nfd:`Before Satisfy Interest Trigger <nfd::fw::Strategy::beforeSatisfyInterest()>` |
| 134 | |
| 135 | This method will be triggered just before the pending Interest is being satisfied. It may |
| 136 | be useful override this method, e.g., to measure data plane performance. |
| 137 | |
| 138 | - :nfd:`Before Expire Interest Trigger <nfd::fw::Strategy::beforeExpirePendingInterest()>` |
| 139 | |
| 140 | This method will be triggered just before the pending Interest is timed out. Same as with |
| 141 | the before satisfy interest trigger, this method may be useful o measure data plane |
| 142 | performance. |
| 143 | |
| 144 | Example |
| 145 | ^^^^^^^ |
| 146 | |
| 147 | The following code implements a random load balancing forwarding strategy. This strategy |
| 148 | was created by Steve DiBenedetto and was found in one of his `GitHub repository |
| 149 | <https://github.com/dibenede/ndn-tutorial-gec21>`_. |
| 150 | |
| 151 | .. literalinclude:: ../../examples/ndn-load-balancer/random-load-balancer-strategy.hpp |
Alexander Afanasyev | e74cc1c | 2012-11-21 13:10:03 -0800 | [diff] [blame] | 152 | :language: c++ |
| 153 | :linenos: |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 154 | :lines: 26- |
Alexander Afanasyev | e74cc1c | 2012-11-21 13:10:03 -0800 | [diff] [blame] | 155 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 156 | .. literalinclude:: ../../examples/ndn-load-balancer/random-load-balancer-strategy.cpp |
Alexander Afanasyev | e74cc1c | 2012-11-21 13:10:03 -0800 | [diff] [blame] | 157 | :language: c++ |
| 158 | :linenos: |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 159 | :lines: 26- |
Alexander Afanasyev | e74cc1c | 2012-11-21 13:10:03 -0800 | [diff] [blame] | 160 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 161 | This forwarding strategy can be enabled for a specific name prefix when developing the |
| 162 | simulation scenario as follows: |
Alexander Afanasyev | e74cc1c | 2012-11-21 13:10:03 -0800 | [diff] [blame] | 163 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 164 | .. code-block:: c++ |
Alexander Afanasyev | e74cc1c | 2012-11-21 13:10:03 -0800 | [diff] [blame] | 165 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 166 | #include "random-load-balancer-strategy.hpp" |
Alexander Afanasyev | e74cc1c | 2012-11-21 13:10:03 -0800 | [diff] [blame] | 167 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 168 | ... |
Alexander Afanasyev | e74cc1c | 2012-11-21 13:10:03 -0800 | [diff] [blame] | 169 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 170 | StrategyChoiceHelper::Install<nfd::fw::RandomLoadBalancerStrategy>(nodes, prefix); |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 171 | |
| 172 | Example of using custom strategy |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 173 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 174 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 175 | Please refer to :ref:`6-node topology with custom NFD forwarding strategy` . |