Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Davide Pesavento | b84bd3a | 2016-04-22 02:21:45 +0200 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, 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" |
| 30 | #include "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 | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 53 | AccessStrategy(Forwarder& forwarder, const Name& name = STRATEGY_NAME); |
| 54 | |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 55 | public: // triggers |
| 56 | virtual void |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 57 | afterReceiveInterest(const Face& inFace, const Interest& interest, |
| 58 | const shared_ptr<pit::Entry>& pitEntry) override; |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 59 | |
| 60 | virtual void |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 61 | beforeSatisfyInterest(const shared_ptr<pit::Entry>& pitEntry, |
Davide Pesavento | b84bd3a | 2016-04-22 02:21:45 +0200 | [diff] [blame] | 62 | const Face& inFace, const Data& data) override; |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 63 | |
| 64 | private: // StrategyInfo |
| 65 | /** \brief StrategyInfo on PIT entry |
| 66 | */ |
| 67 | class PitInfo : public StrategyInfo |
| 68 | { |
| 69 | public: |
| 70 | static constexpr int |
| 71 | getTypeId() |
| 72 | { |
| 73 | return 1010; |
| 74 | } |
| 75 | |
| 76 | public: |
| 77 | scheduler::ScopedEventId rtoTimer; |
| 78 | }; |
| 79 | |
| 80 | /** \brief StrategyInfo in measurements table |
| 81 | */ |
| 82 | class MtInfo : public StrategyInfo |
| 83 | { |
| 84 | public: |
| 85 | static constexpr int |
| 86 | getTypeId() |
| 87 | { |
| 88 | return 1011; |
| 89 | } |
| 90 | |
| 91 | MtInfo(); |
| 92 | |
| 93 | public: |
| 94 | FaceId lastNexthop; |
| 95 | RttEstimator rtt; |
| 96 | }; |
| 97 | |
| 98 | /** \brief find per-prefix measurements for Interest |
| 99 | */ |
Junxiao Shi | fc02186 | 2016-08-25 21:51:18 +0000 | [diff] [blame] | 100 | std::tuple<Name, MtInfo*> |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 101 | findPrefixMeasurements(const pit::Entry& pitEntry); |
| 102 | |
| 103 | /** \brief get or create pre-prefix measurements for incoming Data |
| 104 | * \note This function creates MtInfo but doesn't update it. |
| 105 | */ |
Junxiao Shi | fc02186 | 2016-08-25 21:51:18 +0000 | [diff] [blame] | 106 | MtInfo* |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 107 | addPrefixMeasurements(const Data& data); |
| 108 | |
| 109 | /** \brief global per-face StrategyInfo |
| 110 | */ |
| 111 | class FaceInfo |
| 112 | { |
| 113 | public: |
| 114 | FaceInfo(); |
| 115 | |
| 116 | public: |
| 117 | RttEstimator rtt; |
| 118 | }; |
| 119 | |
| 120 | typedef std::unordered_map<FaceId, FaceInfo> FaceInfoTable; |
| 121 | |
| 122 | void |
Junxiao Shi | ae04d34 | 2016-07-19 13:20:22 +0000 | [diff] [blame] | 123 | removeFaceInfo(const Face& face); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 124 | |
| 125 | private: // forwarding procedures |
| 126 | void |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 127 | afterReceiveNewInterest(const Face& inFace, const Interest& interest, |
| 128 | const shared_ptr<pit::Entry>& pitEntry); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 129 | |
| 130 | void |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 131 | afterReceiveRetxInterest(const Face& inFace, const Interest& interest, |
| 132 | const shared_ptr<pit::Entry>& pitEntry); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 133 | |
| 134 | /** \brief send to last working nexthop |
| 135 | * \return whether an Interest is sent |
| 136 | */ |
| 137 | bool |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 138 | sendToLastNexthop(const Face& inFace, const shared_ptr<pit::Entry>& pitEntry, MtInfo& mi, |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 139 | const fib::Entry& fibEntry); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 140 | |
| 141 | void |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 142 | afterRtoTimeout(weak_ptr<pit::Entry> pitWeak, FaceId inFace, FaceId firstOutFace); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 143 | |
| 144 | /** \brief multicast to all nexthops |
| 145 | * \param exceptFaces don't forward to those faces |
| 146 | */ |
| 147 | void |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 148 | multicast(const shared_ptr<pit::Entry>& pitEntry, const fib::Entry& fibEntry, |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 149 | std::unordered_set<FaceId> exceptFaces = std::unordered_set<FaceId>()); |
| 150 | |
| 151 | void |
| 152 | updateMeasurements(const Face& inFace, const Data& data, |
| 153 | const RttEstimator::Duration& rtt); |
| 154 | |
| 155 | public: |
| 156 | static const Name STRATEGY_NAME; |
| 157 | |
| 158 | private: |
| 159 | FaceInfoTable m_fit; |
Junxiao Shi | a788e25 | 2015-01-28 17:06:25 -0700 | [diff] [blame] | 160 | RetxSuppressionFixed m_retxSuppression; |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 161 | signal::ScopedConnection m_removeFaceInfoConn; |
| 162 | }; |
| 163 | |
| 164 | } // namespace fw |
| 165 | } // namespace nfd |
| 166 | |
| 167 | #endif // NFD_DAEMON_FW_ACCESS_STRATEGY_HPP |