Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame^] | 3 | * Copyright (c) 2014 Regents of the University of California, |
| 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology |
| 9 | * |
| 10 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 11 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 12 | * |
| 13 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 14 | * of the GNU General Public License as published by the Free Software Foundation, |
| 15 | * either version 3 of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 18 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 19 | * PURPOSE. See the GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License along with |
| 22 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 23 | **/ |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 24 | |
| 25 | #ifndef NFD_FW_STRATEGY_HPP |
| 26 | #define NFD_FW_STRATEGY_HPP |
| 27 | |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 28 | #include "forwarder.hpp" |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 29 | #include "table/measurements-accessor.hpp" |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 30 | |
| 31 | namespace nfd { |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 32 | namespace fw { |
| 33 | |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 34 | /** \brief represents a forwarding strategy |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 35 | */ |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 36 | class Strategy : public enable_shared_from_this<Strategy>, noncopyable |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 37 | { |
| 38 | public: |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 39 | Strategy(Forwarder& forwarder, const Name& name); |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 40 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 41 | virtual |
| 42 | ~Strategy(); |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 43 | |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 44 | /// a Name that represent the Strategy program |
| 45 | const Name& |
| 46 | getName() const; |
| 47 | |
Junxiao Shi | 679e927 | 2014-02-15 20:10:21 -0700 | [diff] [blame] | 48 | public: // triggers |
| 49 | /** \brief trigger after Interest is received |
| 50 | * |
| 51 | * The Interest: |
| 52 | * - does not violate Scope |
| 53 | * - is not looped |
| 54 | * - cannot be satisfied by ContentStore |
| 55 | * - is under a namespace managed by this strategy |
| 56 | * |
| 57 | * The strategy should decide whether and where to forward this Interest. |
| 58 | * - If the strategy decides to forward this Interest, |
| 59 | * invoke this->sendInterest one or more times, either now or shortly after |
| 60 | * - If strategy concludes that this Interest cannot be forwarded, |
Junxiao Shi | 09498f0 | 2014-02-26 19:41:08 -0700 | [diff] [blame] | 61 | * invoke this->rejectPendingInterest so that PIT entry will be deleted shortly |
Junxiao Shi | 679e927 | 2014-02-15 20:10:21 -0700 | [diff] [blame] | 62 | */ |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 63 | virtual void |
| 64 | afterReceiveInterest(const Face& inFace, |
| 65 | const Interest& interest, |
| 66 | shared_ptr<fib::Entry> fibEntry, |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 67 | shared_ptr<pit::Entry> pitEntry) =0; |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 68 | |
Junxiao Shi | 22be22c | 2014-02-16 22:53:48 -0700 | [diff] [blame] | 69 | /** \brief trigger before PIT entry is satisfied |
| 70 | * |
| 71 | * In this base class this method does nothing. |
| 72 | */ |
| 73 | virtual void |
| 74 | beforeSatisfyPendingInterest(shared_ptr<pit::Entry> pitEntry, |
| 75 | const Face& inFace, const Data& data); |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 76 | |
Junxiao Shi | 679e927 | 2014-02-15 20:10:21 -0700 | [diff] [blame] | 77 | /** \brief trigger before PIT entry expires |
| 78 | * |
| 79 | * PIT entry expires when InterestLifetime has elapsed for all InRecords, |
| 80 | * and it is not satisfied by an incoming Data. |
| 81 | * |
| 82 | * This trigger is not invoked for PIT entry already satisfied. |
| 83 | * |
| 84 | * In this base class this method does nothing. |
| 85 | */ |
| 86 | virtual void |
| 87 | beforeExpirePendingInterest(shared_ptr<pit::Entry> pitEntry); |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 88 | |
Junxiao Shi | 22be22c | 2014-02-16 22:53:48 -0700 | [diff] [blame] | 89 | // /** \brief trigger after FIB entry is being inserted |
| 90 | // * and becomes managed by this strategy |
| 91 | // * |
| 92 | // * In this base class this method does nothing. |
| 93 | // */ |
| 94 | // virtual void |
| 95 | // afterAddFibEntry(shared_ptr<fib::Entry> fibEntry); |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 96 | // |
Junxiao Shi | 22be22c | 2014-02-16 22:53:48 -0700 | [diff] [blame] | 97 | // /** \brief trigger after FIB entry being managed by this strategy is updated |
| 98 | // * |
| 99 | // * In this base class this method does nothing. |
| 100 | // */ |
| 101 | // virtual void |
| 102 | // afterUpdateFibEntry(shared_ptr<fib::Entry> fibEntry); |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 103 | // |
Junxiao Shi | 22be22c | 2014-02-16 22:53:48 -0700 | [diff] [blame] | 104 | // /** \brief trigger before FIB entry ceises to be managed by this strategy |
| 105 | // * or is being deleted |
| 106 | // * |
| 107 | // * In this base class this method does nothing. |
| 108 | // */ |
| 109 | // virtual void |
| 110 | // beforeRemoveFibEntry(shared_ptr<fib::Entry> fibEntry); |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 111 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 112 | protected: // actions |
| 113 | /// send Interest to outFace |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 114 | VIRTUAL_WITH_TESTS void |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 115 | sendInterest(shared_ptr<pit::Entry> pitEntry, |
Alexander Afanasyev | 7e698e6 | 2014-03-07 16:48:35 +0000 | [diff] [blame] | 116 | shared_ptr<Face> outFace); |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 117 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 118 | /** \brief decide that a pending Interest cannot be forwarded |
Junxiao Shi | 679e927 | 2014-02-15 20:10:21 -0700 | [diff] [blame] | 119 | * |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 120 | * This shall not be called if the pending Interest has been |
| 121 | * forwarded earlier, and does not need to be resent now. |
| 122 | */ |
Junxiao Shi | 727ed29 | 2014-02-19 23:26:45 -0700 | [diff] [blame] | 123 | VIRTUAL_WITH_TESTS void |
Junxiao Shi | 09498f0 | 2014-02-26 19:41:08 -0700 | [diff] [blame] | 124 | rejectPendingInterest(shared_ptr<pit::Entry> pitEntry); |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 125 | |
| 126 | protected: // accessors |
| 127 | MeasurementsAccessor& |
| 128 | getMeasurements(); |
| 129 | |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 130 | shared_ptr<Face> |
| 131 | getFace(FaceId id); |
| 132 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 133 | private: |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 134 | Name m_name; |
| 135 | |
Junxiao Shi | 679e927 | 2014-02-15 20:10:21 -0700 | [diff] [blame] | 136 | /** \brief reference to the forwarder |
| 137 | * |
| 138 | * Triggers can access forwarder indirectly via actions. |
| 139 | */ |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 140 | Forwarder& m_forwarder; |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 141 | |
| 142 | MeasurementsAccessor m_measurements; |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 143 | }; |
| 144 | |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 145 | inline const Name& |
| 146 | Strategy::getName() const |
| 147 | { |
| 148 | return m_name; |
| 149 | } |
| 150 | |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 151 | inline void |
| 152 | Strategy::sendInterest(shared_ptr<pit::Entry> pitEntry, |
| 153 | shared_ptr<Face> outFace) |
| 154 | { |
| 155 | m_forwarder.onOutgoingInterest(pitEntry, *outFace); |
| 156 | } |
| 157 | |
| 158 | inline void |
| 159 | Strategy::rejectPendingInterest(shared_ptr<pit::Entry> pitEntry) |
| 160 | { |
| 161 | m_forwarder.onInterestReject(pitEntry); |
| 162 | } |
| 163 | |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 164 | inline MeasurementsAccessor& |
| 165 | Strategy::getMeasurements() |
| 166 | { |
| 167 | return m_measurements; |
| 168 | } |
| 169 | |
Junxiao Shi | 2d9bdc8 | 2014-03-02 20:55:42 -0700 | [diff] [blame] | 170 | inline shared_ptr<Face> |
| 171 | Strategy::getFace(FaceId id) |
| 172 | { |
| 173 | return m_forwarder.getFace(id); |
| 174 | } |
| 175 | |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 176 | } // namespace fw |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 177 | } // namespace nfd |
| 178 | |
| 179 | #endif // NFD_FW_STRATEGY_HPP |