Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame^] | 3 | * Copyright (c) 2014-2017, Regents of the University of California, |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 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 | * The University of Memphis. |
| 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | */ |
| 25 | |
| 26 | #ifndef NFD_DAEMON_FW_ACCESS_STRATEGY_HPP |
| 27 | #define NFD_DAEMON_FW_ACCESS_STRATEGY_HPP |
| 28 | |
| 29 | #include "strategy.hpp" |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame^] | 30 | #include "core/rtt-estimator.hpp" |
Junxiao Shi | a788e25 | 2015-01-28 17:06:25 -0700 | [diff] [blame] | 31 | #include "retx-suppression-fixed.hpp" |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 32 | #include <unordered_set> |
| 33 | #include <unordered_map> |
| 34 | |
| 35 | namespace nfd { |
| 36 | namespace fw { |
| 37 | |
| 38 | /** \brief Access Router Strategy version 1 |
| 39 | * |
| 40 | * This strategy is designed for the last hop on the NDN testbed, |
| 41 | * where each nexthop connects to a laptop, links are lossy, and FIB is mostly correct. |
| 42 | * |
| 43 | * 1. Multicast the first Interest to all nexthops. |
| 44 | * 2. When Data comes back, remember last working nexthop of the prefix; |
| 45 | * the granularity of this knowledge is the parent of Data Name. |
| 46 | * 3. Forward subsequent Interests to the last working nexthop. |
| 47 | * If it doesn't respond, multicast again. |
| 48 | */ |
| 49 | class AccessStrategy : public Strategy |
| 50 | { |
| 51 | public: |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 52 | explicit |
Junxiao Shi | 037f4ab | 2016-12-13 04:27:06 +0000 | [diff] [blame] | 53 | AccessStrategy(Forwarder& forwarder, const Name& name = getStrategyName()); |
| 54 | |
| 55 | static const Name& |
| 56 | getStrategyName(); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 57 | |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 58 | public: // triggers |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame^] | 59 | void |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 60 | afterReceiveInterest(const Face& inFace, const Interest& interest, |
| 61 | const shared_ptr<pit::Entry>& pitEntry) override; |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 62 | |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame^] | 63 | void |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 64 | beforeSatisfyInterest(const shared_ptr<pit::Entry>& pitEntry, |
Davide Pesavento | b84bd3a | 2016-04-22 02:21:45 +0200 | [diff] [blame] | 65 | const Face& inFace, const Data& data) override; |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 66 | |
| 67 | private: // StrategyInfo |
| 68 | /** \brief StrategyInfo on PIT entry |
| 69 | */ |
| 70 | class PitInfo : public StrategyInfo |
| 71 | { |
| 72 | public: |
| 73 | static constexpr int |
| 74 | getTypeId() |
| 75 | { |
| 76 | return 1010; |
| 77 | } |
| 78 | |
| 79 | public: |
| 80 | scheduler::ScopedEventId rtoTimer; |
| 81 | }; |
| 82 | |
| 83 | /** \brief StrategyInfo in measurements table |
| 84 | */ |
| 85 | class MtInfo : public StrategyInfo |
| 86 | { |
| 87 | public: |
| 88 | static constexpr int |
| 89 | getTypeId() |
| 90 | { |
| 91 | return 1011; |
| 92 | } |
| 93 | |
| 94 | MtInfo(); |
| 95 | |
| 96 | public: |
| 97 | FaceId lastNexthop; |
| 98 | RttEstimator rtt; |
| 99 | }; |
| 100 | |
| 101 | /** \brief find per-prefix measurements for Interest |
| 102 | */ |
Junxiao Shi | fc02186 | 2016-08-25 21:51:18 +0000 | [diff] [blame] | 103 | std::tuple<Name, MtInfo*> |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 104 | findPrefixMeasurements(const pit::Entry& pitEntry); |
| 105 | |
| 106 | /** \brief get or create pre-prefix measurements for incoming Data |
| 107 | * \note This function creates MtInfo but doesn't update it. |
| 108 | */ |
Junxiao Shi | fc02186 | 2016-08-25 21:51:18 +0000 | [diff] [blame] | 109 | MtInfo* |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 110 | addPrefixMeasurements(const Data& data); |
| 111 | |
| 112 | /** \brief global per-face StrategyInfo |
| 113 | */ |
| 114 | class FaceInfo |
| 115 | { |
| 116 | public: |
| 117 | FaceInfo(); |
| 118 | |
| 119 | public: |
| 120 | RttEstimator rtt; |
| 121 | }; |
| 122 | |
| 123 | typedef std::unordered_map<FaceId, FaceInfo> FaceInfoTable; |
| 124 | |
| 125 | void |
Junxiao Shi | ae04d34 | 2016-07-19 13:20:22 +0000 | [diff] [blame] | 126 | removeFaceInfo(const Face& face); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 127 | |
| 128 | private: // forwarding procedures |
| 129 | void |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 130 | afterReceiveNewInterest(const Face& inFace, const Interest& interest, |
| 131 | const shared_ptr<pit::Entry>& pitEntry); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 132 | |
| 133 | void |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 134 | afterReceiveRetxInterest(const Face& inFace, const Interest& interest, |
| 135 | const shared_ptr<pit::Entry>& pitEntry); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 136 | |
| 137 | /** \brief send to last working nexthop |
| 138 | * \return whether an Interest is sent |
| 139 | */ |
| 140 | bool |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 141 | sendToLastNexthop(const Face& inFace, const Interest& interest, |
| 142 | const shared_ptr<pit::Entry>& pitEntry, MtInfo& mi, |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 143 | const fib::Entry& fibEntry); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 144 | |
| 145 | void |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 146 | afterRtoTimeout(weak_ptr<pit::Entry> pitWeak, FaceId inFaceId, FaceId firstOutFaceId); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 147 | |
| 148 | /** \brief multicast to all nexthops |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 149 | * \param exceptFace don't forward to this face; also, inFace is always excluded |
| 150 | * \return how many Interests are sent |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 151 | */ |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 152 | int |
| 153 | multicast(const Face& inFace, const Interest& interest, |
| 154 | const shared_ptr<pit::Entry>& pitEntry, const fib::Entry& fibEntry, |
| 155 | FaceId exceptFace = face::INVALID_FACEID); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 156 | |
| 157 | void |
| 158 | updateMeasurements(const Face& inFace, const Data& data, |
| 159 | const RttEstimator::Duration& rtt); |
| 160 | |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 161 | private: |
| 162 | FaceInfoTable m_fit; |
Junxiao Shi | a788e25 | 2015-01-28 17:06:25 -0700 | [diff] [blame] | 163 | RetxSuppressionFixed m_retxSuppression; |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 164 | signal::ScopedConnection m_removeFaceInfoConn; |
| 165 | }; |
| 166 | |
| 167 | } // namespace fw |
| 168 | } // namespace nfd |
| 169 | |
| 170 | #endif // NFD_DAEMON_FW_ACCESS_STRATEGY_HPP |