Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #ifndef NFD_FW_STRATEGY_HPP |
| 8 | #define NFD_FW_STRATEGY_HPP |
| 9 | |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 10 | #include "forwarder.hpp" |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 11 | #include "table/measurements-accessor.hpp" |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 12 | |
| 13 | namespace nfd { |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 14 | namespace fw { |
| 15 | |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 16 | /** \brief represents a forwarding strategy |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 17 | */ |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 18 | class Strategy : public enable_shared_from_this<Strategy>, noncopyable |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 19 | { |
| 20 | public: |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 21 | Strategy(Forwarder& forwarder, const Name& name); |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 22 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 23 | virtual |
| 24 | ~Strategy(); |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 25 | |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 26 | /// a Name that represent the Strategy program |
| 27 | const Name& |
| 28 | getName() const; |
| 29 | |
Junxiao Shi | 679e927 | 2014-02-15 20:10:21 -0700 | [diff] [blame] | 30 | public: // triggers |
| 31 | /** \brief trigger after Interest is received |
| 32 | * |
| 33 | * The Interest: |
| 34 | * - does not violate Scope |
| 35 | * - is not looped |
| 36 | * - cannot be satisfied by ContentStore |
| 37 | * - is under a namespace managed by this strategy |
| 38 | * |
| 39 | * The strategy should decide whether and where to forward this Interest. |
| 40 | * - If the strategy decides to forward this Interest, |
| 41 | * invoke this->sendInterest one or more times, either now or shortly after |
| 42 | * - If strategy concludes that this Interest cannot be forwarded, |
Junxiao Shi | 09498f0 | 2014-02-26 19:41:08 -0700 | [diff] [blame] | 43 | * invoke this->rejectPendingInterest so that PIT entry will be deleted shortly |
Junxiao Shi | 679e927 | 2014-02-15 20:10:21 -0700 | [diff] [blame] | 44 | */ |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 45 | virtual void |
| 46 | afterReceiveInterest(const Face& inFace, |
| 47 | const Interest& interest, |
| 48 | shared_ptr<fib::Entry> fibEntry, |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 49 | shared_ptr<pit::Entry> pitEntry) =0; |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 50 | |
Junxiao Shi | 22be22c | 2014-02-16 22:53:48 -0700 | [diff] [blame] | 51 | /** \brief trigger before PIT entry is satisfied |
| 52 | * |
| 53 | * In this base class this method does nothing. |
| 54 | */ |
| 55 | virtual void |
| 56 | beforeSatisfyPendingInterest(shared_ptr<pit::Entry> pitEntry, |
| 57 | const Face& inFace, const Data& data); |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 58 | |
Junxiao Shi | 679e927 | 2014-02-15 20:10:21 -0700 | [diff] [blame] | 59 | /** \brief trigger before PIT entry expires |
| 60 | * |
| 61 | * PIT entry expires when InterestLifetime has elapsed for all InRecords, |
| 62 | * and it is not satisfied by an incoming Data. |
| 63 | * |
| 64 | * This trigger is not invoked for PIT entry already satisfied. |
| 65 | * |
| 66 | * In this base class this method does nothing. |
| 67 | */ |
| 68 | virtual void |
| 69 | beforeExpirePendingInterest(shared_ptr<pit::Entry> pitEntry); |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 70 | |
Junxiao Shi | 22be22c | 2014-02-16 22:53:48 -0700 | [diff] [blame] | 71 | // /** \brief trigger after FIB entry is being inserted |
| 72 | // * and becomes managed by this strategy |
| 73 | // * |
| 74 | // * In this base class this method does nothing. |
| 75 | // */ |
| 76 | // virtual void |
| 77 | // afterAddFibEntry(shared_ptr<fib::Entry> fibEntry); |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 78 | // |
Junxiao Shi | 22be22c | 2014-02-16 22:53:48 -0700 | [diff] [blame] | 79 | // /** \brief trigger after FIB entry being managed by this strategy is updated |
| 80 | // * |
| 81 | // * In this base class this method does nothing. |
| 82 | // */ |
| 83 | // virtual void |
| 84 | // afterUpdateFibEntry(shared_ptr<fib::Entry> fibEntry); |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 85 | // |
Junxiao Shi | 22be22c | 2014-02-16 22:53:48 -0700 | [diff] [blame] | 86 | // /** \brief trigger before FIB entry ceises to be managed by this strategy |
| 87 | // * or is being deleted |
| 88 | // * |
| 89 | // * In this base class this method does nothing. |
| 90 | // */ |
| 91 | // virtual void |
| 92 | // beforeRemoveFibEntry(shared_ptr<fib::Entry> fibEntry); |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 93 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 94 | protected: // actions |
| 95 | /// send Interest to outFace |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 96 | VIRTUAL_WITH_TESTS void |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 97 | sendInterest(shared_ptr<pit::Entry> pitEntry, |
Alexander Afanasyev | 7e698e6 | 2014-03-07 16:48:35 +0000 | [diff] [blame] | 98 | shared_ptr<Face> outFace); |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 99 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 100 | /** \brief decide that a pending Interest cannot be forwarded |
Junxiao Shi | 679e927 | 2014-02-15 20:10:21 -0700 | [diff] [blame] | 101 | * |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 102 | * This shall not be called if the pending Interest has been |
| 103 | * forwarded earlier, and does not need to be resent now. |
| 104 | */ |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 105 | VIRTUAL_WITH_TESTS void |
Junxiao Shi | 09498f0 | 2014-02-26 19:41:08 -0700 | [diff] [blame] | 106 | rejectPendingInterest(shared_ptr<pit::Entry> pitEntry); |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 107 | |
| 108 | protected: // accessors |
| 109 | MeasurementsAccessor& |
| 110 | getMeasurements(); |
| 111 | |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 112 | shared_ptr<Face> |
| 113 | getFace(FaceId id); |
| 114 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 115 | private: |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 116 | Name m_name; |
| 117 | |
Junxiao Shi | 679e927 | 2014-02-15 20:10:21 -0700 | [diff] [blame] | 118 | /** \brief reference to the forwarder |
| 119 | * |
| 120 | * Triggers can access forwarder indirectly via actions. |
| 121 | */ |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 122 | Forwarder& m_forwarder; |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 123 | |
| 124 | MeasurementsAccessor m_measurements; |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 125 | }; |
| 126 | |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 127 | inline const Name& |
| 128 | Strategy::getName() const |
| 129 | { |
| 130 | return m_name; |
| 131 | } |
| 132 | |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 133 | inline void |
| 134 | Strategy::sendInterest(shared_ptr<pit::Entry> pitEntry, |
| 135 | shared_ptr<Face> outFace) |
| 136 | { |
| 137 | m_forwarder.onOutgoingInterest(pitEntry, *outFace); |
| 138 | } |
| 139 | |
| 140 | inline void |
| 141 | Strategy::rejectPendingInterest(shared_ptr<pit::Entry> pitEntry) |
| 142 | { |
| 143 | m_forwarder.onInterestReject(pitEntry); |
| 144 | } |
| 145 | |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 146 | inline MeasurementsAccessor& |
| 147 | Strategy::getMeasurements() |
| 148 | { |
| 149 | return m_measurements; |
| 150 | } |
| 151 | |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 152 | inline shared_ptr<Face> |
| 153 | Strategy::getFace(FaceId id) |
| 154 | { |
| 155 | return m_forwarder.getFace(id); |
| 156 | } |
| 157 | |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 158 | } // namespace fw |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 159 | } // namespace nfd |
| 160 | |
| 161 | #endif // NFD_FW_STRATEGY_HPP |