Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame] | 2 | /* |
Eric Newberry | 9d283ad | 2020-04-12 23:37:17 -0700 | [diff] [blame^] | 3 | * Copyright (c) 2014-2020, Regents of the University of California, |
Junxiao Shi | faf3eb0 | 2015-02-16 10:50:36 -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. |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 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/>. |
Junxiao Shi | af6569a | 2014-06-14 00:01:34 -0700 | [diff] [blame] | 24 | */ |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 25 | |
| 26 | #include "forwarder.hpp" |
Davide Pesavento | a314808 | 2018-04-12 18:21:54 -0400 | [diff] [blame] | 27 | |
Junxiao Shi | 00dc914 | 2016-11-21 14:23:12 +0000 | [diff] [blame] | 28 | #include "algorithm.hpp" |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 29 | #include "best-route-strategy2.hpp" |
Junxiao Shi | faf3eb0 | 2015-02-16 10:50:36 -0700 | [diff] [blame] | 30 | #include "strategy.hpp" |
Davide Pesavento | 2cae8ca | 2019-04-18 20:48:05 -0400 | [diff] [blame] | 31 | #include "common/global.hpp" |
| 32 | #include "common/logger.hpp" |
Junxiao Shi | 02b73f5 | 2016-07-28 01:48:27 +0000 | [diff] [blame] | 33 | #include "table/cleanup.hpp" |
Davide Pesavento | a314808 | 2018-04-12 18:21:54 -0400 | [diff] [blame] | 34 | |
Junxiao Shi | cbc8e94 | 2016-09-06 03:17:45 +0000 | [diff] [blame] | 35 | #include <ndn-cxx/lp/tags.hpp> |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 36 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 37 | namespace nfd { |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 38 | |
Davide Pesavento | a314808 | 2018-04-12 18:21:54 -0400 | [diff] [blame] | 39 | NFD_LOG_INIT(Forwarder); |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 40 | |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 41 | static Name |
| 42 | getDefaultStrategyName() |
| 43 | { |
Junxiao Shi | 037f4ab | 2016-12-13 04:27:06 +0000 | [diff] [blame] | 44 | return fw::BestRouteStrategy2::getStrategyName(); |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 47 | Forwarder::Forwarder(FaceTable& faceTable) |
| 48 | : m_faceTable(faceTable) |
| 49 | , m_unsolicitedDataPolicy(make_unique<fw::DefaultUnsolicitedDataPolicy>()) |
Junxiao Shi | fbe8efe | 2016-08-22 16:02:30 +0000 | [diff] [blame] | 50 | , m_fib(m_nameTree) |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 51 | , m_pit(m_nameTree) |
HangZhang | c85a23c | 2014-03-01 15:55:55 +0800 | [diff] [blame] | 52 | , m_measurements(m_nameTree) |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 53 | , m_strategyChoice(*this) |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 54 | { |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 55 | m_faceTable.afterAdd.connect([this] (const Face& face) { |
Junxiao Shi | dcffdaa | 2016-07-26 02:23:56 +0000 | [diff] [blame] | 56 | face.afterReceiveInterest.connect( |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 57 | [this, &face] (const Interest& interest, const EndpointId& endpointId) { |
| 58 | this->startProcessInterest(FaceEndpoint(face, endpointId), interest); |
Junxiao Shi | dcffdaa | 2016-07-26 02:23:56 +0000 | [diff] [blame] | 59 | }); |
| 60 | face.afterReceiveData.connect( |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 61 | [this, &face] (const Data& data, const EndpointId& endpointId) { |
| 62 | this->startProcessData(FaceEndpoint(face, endpointId), data); |
Junxiao Shi | dcffdaa | 2016-07-26 02:23:56 +0000 | [diff] [blame] | 63 | }); |
| 64 | face.afterReceiveNack.connect( |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 65 | [this, &face] (const lp::Nack& nack, const EndpointId& endpointId) { |
| 66 | this->startProcessNack(FaceEndpoint(face, endpointId), nack); |
Junxiao Shi | dcffdaa | 2016-07-26 02:23:56 +0000 | [diff] [blame] | 67 | }); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 68 | face.onDroppedInterest.connect( |
| 69 | [this, &face] (const Interest& interest) { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 70 | this->onDroppedInterest(FaceEndpoint(face, 0), interest); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 71 | }); |
Junxiao Shi | dcffdaa | 2016-07-26 02:23:56 +0000 | [diff] [blame] | 72 | }); |
| 73 | |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 74 | m_faceTable.beforeRemove.connect([this] (const Face& face) { |
Junxiao Shi | 02b73f5 | 2016-07-28 01:48:27 +0000 | [diff] [blame] | 75 | cleanupOnFaceRemoval(m_nameTree, m_fib, m_pit, face); |
Junxiao Shi | dcffdaa | 2016-07-26 02:23:56 +0000 | [diff] [blame] | 76 | }); |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 77 | |
Ju Pan | 2feb459 | 2019-09-16 20:56:38 +0000 | [diff] [blame] | 78 | m_fib.afterNewNextHop.connect([&] (const Name& prefix, const fib::NextHop& nextHop) { |
| 79 | this->startProcessNewNextHop(prefix, nextHop); |
| 80 | }); |
| 81 | |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 82 | m_strategyChoice.setDefaultStrategy(getDefaultStrategyName()); |
Alexander Afanasyev | 33b7277 | 2014-01-26 23:22:58 -0800 | [diff] [blame] | 83 | } |
| 84 | |
Junxiao Shi | dcffdaa | 2016-07-26 02:23:56 +0000 | [diff] [blame] | 85 | Forwarder::~Forwarder() = default; |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 86 | |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 87 | void |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 88 | Forwarder::onIncomingInterest(const FaceEndpoint& ingress, const Interest& interest) |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 89 | { |
| 90 | // receive Interest |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 91 | NFD_LOG_DEBUG("onIncomingInterest in=" << ingress << " interest=" << interest.getName()); |
| 92 | interest.setTag(make_shared<lp::IncomingFaceIdTag>(ingress.face.getId())); |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 93 | ++m_counters.nInInterests; |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 94 | |
Eric Newberry | 9d283ad | 2020-04-12 23:37:17 -0700 | [diff] [blame^] | 95 | // drop if HopLimit zero, decrement otherwise (if present) |
| 96 | if (interest.getHopLimit()) { |
| 97 | if (*interest.getHopLimit() < 1) { |
| 98 | NFD_LOG_DEBUG("onIncomingInterest in=" << ingress << " interest=" << interest.getName() |
| 99 | << " hop-limit=0"); |
| 100 | ++const_cast<PacketCounter&>(ingress.face.getCounters().nInHopLimitZero); |
| 101 | return; |
| 102 | } |
| 103 | |
| 104 | const_cast<Interest&>(interest).setHopLimit(*interest.getHopLimit() - 1); |
| 105 | } |
| 106 | |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 107 | // /localhost scope control |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 108 | bool isViolatingLocalhost = ingress.face.getScope() == ndn::nfd::FACE_SCOPE_NON_LOCAL && |
Junxiao Shi | f3410d8 | 2016-04-05 13:49:44 -0700 | [diff] [blame] | 109 | scope_prefix::LOCALHOST.isPrefixOf(interest.getName()); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 110 | if (isViolatingLocalhost) { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 111 | NFD_LOG_DEBUG("onIncomingInterest in=" << ingress |
| 112 | << " interest=" << interest.getName() << " violates /localhost"); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 113 | // (drop) |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 114 | return; |
| 115 | } |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 116 | |
Junxiao Shi | 330136a | 2016-03-10 04:53:08 -0700 | [diff] [blame] | 117 | // detect duplicate Nonce with Dead Nonce List |
| 118 | bool hasDuplicateNonceInDnl = m_deadNonceList.has(interest.getName(), interest.getNonce()); |
| 119 | if (hasDuplicateNonceInDnl) { |
| 120 | // goto Interest loop pipeline |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 121 | this->onInterestLoop(ingress, interest); |
Junxiao Shi | 330136a | 2016-03-10 04:53:08 -0700 | [diff] [blame] | 122 | return; |
| 123 | } |
| 124 | |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame] | 125 | // strip forwarding hint if Interest has reached producer region |
| 126 | if (!interest.getForwardingHint().empty() && |
| 127 | m_networkRegionTable.isInProducerRegion(interest.getForwardingHint())) { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 128 | NFD_LOG_DEBUG("onIncomingInterest in=" << ingress |
| 129 | << " interest=" << interest.getName() << " reaching-producer-region"); |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame] | 130 | const_cast<Interest&>(interest).setForwardingHint({}); |
Junxiao Shi | f9858fd | 2017-02-01 16:22:44 +0000 | [diff] [blame] | 131 | } |
| 132 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 133 | // PIT insert |
Junxiao Shi | 4063184 | 2014-03-01 13:52:37 -0700 | [diff] [blame] | 134 | shared_ptr<pit::Entry> pitEntry = m_pit.insert(interest).first; |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 135 | |
Junxiao Shi | 330136a | 2016-03-10 04:53:08 -0700 | [diff] [blame] | 136 | // detect duplicate Nonce in PIT entry |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 137 | int dnw = fw::findDuplicateNonce(*pitEntry, interest.getNonce(), ingress.face); |
Junxiao Shi | 2fe3af0 | 2017-03-04 17:24:19 +0000 | [diff] [blame] | 138 | bool hasDuplicateNonceInPit = dnw != fw::DUPLICATE_NONCE_NONE; |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 139 | if (ingress.face.getLinkType() == ndn::nfd::LINK_TYPE_POINT_TO_POINT) { |
Junxiao Shi | 2fe3af0 | 2017-03-04 17:24:19 +0000 | [diff] [blame] | 140 | // for p2p face: duplicate Nonce from same incoming face is not loop |
| 141 | hasDuplicateNonceInPit = hasDuplicateNonceInPit && !(dnw & fw::DUPLICATE_NONCE_IN_SAME); |
| 142 | } |
Junxiao Shi | 330136a | 2016-03-10 04:53:08 -0700 | [diff] [blame] | 143 | if (hasDuplicateNonceInPit) { |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 144 | // goto Interest loop pipeline |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 145 | this->onInterestLoop(ingress, interest); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 146 | return; |
| 147 | } |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 148 | |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 149 | // is pending? |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 150 | if (!pitEntry->hasInRecords()) { |
mzhang4 | eab7249 | 2015-02-25 11:16:09 -0600 | [diff] [blame] | 151 | m_cs.find(interest, |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 152 | bind(&Forwarder::onContentStoreHit, this, ingress, pitEntry, _1, _2), |
| 153 | bind(&Forwarder::onContentStoreMiss, this, ingress, pitEntry, _1)); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 154 | } |
mzhang4 | eab7249 | 2015-02-25 11:16:09 -0600 | [diff] [blame] | 155 | else { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 156 | this->onContentStoreMiss(ingress, pitEntry, interest); |
mzhang4 | eab7249 | 2015-02-25 11:16:09 -0600 | [diff] [blame] | 157 | } |
| 158 | } |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 159 | |
mzhang4 | eab7249 | 2015-02-25 11:16:09 -0600 | [diff] [blame] | 160 | void |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 161 | Forwarder::onInterestLoop(const FaceEndpoint& ingress, const Interest& interest) |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 162 | { |
Teng Liang | 4f5cdcf | 2017-03-16 15:33:31 -0700 | [diff] [blame] | 163 | // if multi-access or ad hoc face, drop |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 164 | if (ingress.face.getLinkType() != ndn::nfd::LINK_TYPE_POINT_TO_POINT) { |
| 165 | NFD_LOG_DEBUG("onInterestLoop in=" << ingress |
| 166 | << " interest=" << interest.getName() << " drop"); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 167 | return; |
| 168 | } |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 169 | |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 170 | NFD_LOG_DEBUG("onInterestLoop in=" << ingress << " interest=" << interest.getName() |
| 171 | << " send-Nack-duplicate"); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 172 | |
| 173 | // send Nack with reason=DUPLICATE |
| 174 | // note: Don't enter outgoing Nack pipeline because it needs an in-record. |
| 175 | lp::Nack nack(interest); |
| 176 | nack.setReason(lp::NackReason::DUPLICATE); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 177 | ingress.face.sendNack(nack, ingress.endpoint); |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | void |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 181 | Forwarder::onContentStoreMiss(const FaceEndpoint& ingress, |
| 182 | const shared_ptr<pit::Entry>& pitEntry, const Interest& interest) |
mzhang4 | eab7249 | 2015-02-25 11:16:09 -0600 | [diff] [blame] | 183 | { |
| 184 | NFD_LOG_DEBUG("onContentStoreMiss interest=" << interest.getName()); |
Junxiao Shi | 06a1eab | 2017-09-04 13:13:02 +0000 | [diff] [blame] | 185 | ++m_counters.nCsMisses; |
mzhang4 | eab7249 | 2015-02-25 11:16:09 -0600 | [diff] [blame] | 186 | |
Md Ashiqur Rahman | 115ea63 | 2019-07-06 02:34:31 +0000 | [diff] [blame] | 187 | // insert in-record |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 188 | pitEntry->insertOrUpdateInRecord(ingress.face, interest); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 189 | |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 190 | // set PIT expiry timer to the time that the last PIT in-record expires |
Davide Pesavento | b31206e | 2019-04-20 22:34:12 -0400 | [diff] [blame] | 191 | auto lastExpiring = std::max_element(pitEntry->in_begin(), pitEntry->in_end(), |
| 192 | [] (const auto& a, const auto& b) { |
| 193 | return a.getExpiry() < b.getExpiry(); |
| 194 | }); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 195 | auto lastExpiryFromNow = lastExpiring->getExpiry() - time::steady_clock::now(); |
| 196 | this->setExpiryTimer(pitEntry, time::duration_cast<time::milliseconds>(lastExpiryFromNow)); |
Alexander Afanasyev | a57f8b4 | 2014-07-10 20:11:32 -0700 | [diff] [blame] | 197 | |
Junxiao Shi | e342e8d | 2016-09-18 16:48:00 +0000 | [diff] [blame] | 198 | // has NextHopFaceId? |
Davide Pesavento | b31206e | 2019-04-20 22:34:12 -0400 | [diff] [blame] | 199 | auto nextHopTag = interest.getTag<lp::NextHopFaceIdTag>(); |
Junxiao Shi | e342e8d | 2016-09-18 16:48:00 +0000 | [diff] [blame] | 200 | if (nextHopTag != nullptr) { |
| 201 | // chosen NextHop face exists? |
| 202 | Face* nextHopFace = m_faceTable.get(*nextHopTag); |
| 203 | if (nextHopFace != nullptr) { |
Davide Pesavento | b31206e | 2019-04-20 22:34:12 -0400 | [diff] [blame] | 204 | NFD_LOG_DEBUG("onContentStoreMiss interest=" << interest.getName() |
| 205 | << " nexthop-faceid=" << nextHopFace->getId()); |
Junxiao Shi | e342e8d | 2016-09-18 16:48:00 +0000 | [diff] [blame] | 206 | // go to outgoing Interest pipeline |
Junxiao Shi | c5f651f | 2016-11-17 22:58:12 +0000 | [diff] [blame] | 207 | // scope control is unnecessary, because privileged app explicitly wants to forward |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 208 | this->onOutgoingInterest(pitEntry, FaceEndpoint(*nextHopFace, 0), interest); |
Junxiao Shi | e342e8d | 2016-09-18 16:48:00 +0000 | [diff] [blame] | 209 | } |
| 210 | return; |
| 211 | } |
| 212 | |
Junxiao Shi | 05cc50a | 2016-07-11 22:38:21 +0000 | [diff] [blame] | 213 | // dispatch to strategy: after incoming Interest |
Junxiao Shi | b9420cf | 2016-08-13 04:38:52 +0000 | [diff] [blame] | 214 | this->dispatchToStrategy(*pitEntry, |
Md Ashiqur Rahman | 115ea63 | 2019-07-06 02:34:31 +0000 | [diff] [blame] | 215 | [&] (fw::Strategy& strategy) { |
| 216 | strategy.afterReceiveInterest(FaceEndpoint(ingress.face, 0), interest, pitEntry); |
| 217 | }); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | void |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 221 | Forwarder::onContentStoreHit(const FaceEndpoint& ingress, const shared_ptr<pit::Entry>& pitEntry, |
Junxiao Shi | b9420cf | 2016-08-13 04:38:52 +0000 | [diff] [blame] | 222 | const Interest& interest, const Data& data) |
mzhang4 | eab7249 | 2015-02-25 11:16:09 -0600 | [diff] [blame] | 223 | { |
Vince Lehman | faa5c0c | 2015-08-18 12:52:46 -0500 | [diff] [blame] | 224 | NFD_LOG_DEBUG("onContentStoreHit interest=" << interest.getName()); |
Junxiao Shi | 06a1eab | 2017-09-04 13:13:02 +0000 | [diff] [blame] | 225 | ++m_counters.nCsHits; |
mzhang4 | eab7249 | 2015-02-25 11:16:09 -0600 | [diff] [blame] | 226 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 227 | data.setTag(make_shared<lp::IncomingFaceIdTag>(face::FACEID_CONTENT_STORE)); |
Davide Pesavento | b31206e | 2019-04-20 22:34:12 -0400 | [diff] [blame] | 228 | // FIXME Should we lookup PIT for other Interests that also match the data? |
mzhang4 | eab7249 | 2015-02-25 11:16:09 -0600 | [diff] [blame] | 229 | |
Teng Liang | 6f09ab6 | 2018-03-01 20:04:08 -0700 | [diff] [blame] | 230 | pitEntry->isSatisfied = true; |
| 231 | pitEntry->dataFreshnessPeriod = data.getFreshnessPeriod(); |
| 232 | |
Teng Liang | 85a3663 | 2018-03-21 05:59:34 -0700 | [diff] [blame] | 233 | // set PIT expiry timer to now |
| 234 | this->setExpiryTimer(pitEntry, 0_ms); |
mzhang4 | eab7249 | 2015-02-25 11:16:09 -0600 | [diff] [blame] | 235 | |
Teng Liang | 85a3663 | 2018-03-21 05:59:34 -0700 | [diff] [blame] | 236 | // dispatch to strategy: after Content Store hit |
| 237 | this->dispatchToStrategy(*pitEntry, |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 238 | [&] (fw::Strategy& strategy) { strategy.afterContentStoreHit(pitEntry, ingress, data); }); |
mzhang4 | eab7249 | 2015-02-25 11:16:09 -0600 | [diff] [blame] | 239 | } |
| 240 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 241 | void |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 242 | Forwarder::onOutgoingInterest(const shared_ptr<pit::Entry>& pitEntry, |
| 243 | const FaceEndpoint& egress, const Interest& interest) |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 244 | { |
Eric Newberry | 9d283ad | 2020-04-12 23:37:17 -0700 | [diff] [blame^] | 245 | // drop if HopLimit == 0 but sending on non-local face |
| 246 | if (interest.getHopLimit() == 0 && egress.face.getScope() == ndn::nfd::FACE_SCOPE_NON_LOCAL) { |
| 247 | NFD_LOG_DEBUG("onOutgoingInterest out=" << egress << " interest=" << pitEntry->getName() |
| 248 | << " non-local hop-limit=0"); |
| 249 | ++const_cast<PacketCounter&>(egress.face.getCounters().nOutHopLimitZero); |
| 250 | return; |
| 251 | } |
| 252 | |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 253 | NFD_LOG_DEBUG("onOutgoingInterest out=" << egress << " interest=" << pitEntry->getName()); |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 254 | |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 255 | // insert out-record |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 256 | pitEntry->insertOrUpdateOutRecord(egress.face, interest); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 257 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 258 | // send Interest |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 259 | egress.face.sendInterest(interest, egress.endpoint); |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 260 | ++m_counters.nOutInterests; |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | void |
Teng Liang | 6f09ab6 | 2018-03-01 20:04:08 -0700 | [diff] [blame] | 264 | Forwarder::onInterestFinalize(const shared_ptr<pit::Entry>& pitEntry) |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 265 | { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 266 | NFD_LOG_DEBUG("onInterestFinalize interest=" << pitEntry->getName() |
| 267 | << (pitEntry->isSatisfied ? " satisfied" : " unsatisfied")); |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 268 | |
| 269 | // Dead Nonce List insert if necessary |
Davide Pesavento | 3dade00 | 2019-03-19 11:29:56 -0600 | [diff] [blame] | 270 | this->insertDeadNonceList(*pitEntry, nullptr); |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 271 | |
Ju Pan | 6eb1ac9 | 2018-10-26 16:26:15 +0000 | [diff] [blame] | 272 | // Increment satisfied/unsatisfied Interests counter |
| 273 | if (pitEntry->isSatisfied) { |
| 274 | ++m_counters.nSatisfiedInterests; |
| 275 | } |
| 276 | else { |
| 277 | ++m_counters.nUnsatisfiedInterests; |
| 278 | } |
| 279 | |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 280 | // PIT delete |
Davide Pesavento | 3dade00 | 2019-03-19 11:29:56 -0600 | [diff] [blame] | 281 | pitEntry->expiryTimer.cancel(); |
Junxiao Shi | dbef6dc | 2016-08-15 02:58:36 +0000 | [diff] [blame] | 282 | m_pit.erase(pitEntry.get()); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | void |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 286 | Forwarder::onIncomingData(const FaceEndpoint& ingress, const Data& data) |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 287 | { |
| 288 | // receive Data |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 289 | NFD_LOG_DEBUG("onIncomingData in=" << ingress << " data=" << data.getName()); |
| 290 | data.setTag(make_shared<lp::IncomingFaceIdTag>(ingress.face.getId())); |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 291 | ++m_counters.nInData; |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 292 | |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 293 | // /localhost scope control |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 294 | bool isViolatingLocalhost = ingress.face.getScope() == ndn::nfd::FACE_SCOPE_NON_LOCAL && |
Junxiao Shi | f3410d8 | 2016-04-05 13:49:44 -0700 | [diff] [blame] | 295 | scope_prefix::LOCALHOST.isPrefixOf(data.getName()); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 296 | if (isViolatingLocalhost) { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 297 | NFD_LOG_DEBUG("onIncomingData in=" << ingress << " data=" << data.getName() << " violates /localhost"); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 298 | // (drop) |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 299 | return; |
| 300 | } |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 301 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 302 | // PIT match |
Junxiao Shi | b2bcbcd | 2014-11-08 09:30:28 -0700 | [diff] [blame] | 303 | pit::DataMatchResult pitMatches = m_pit.findAllDataMatches(data); |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 304 | if (pitMatches.size() == 0) { |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 305 | // goto Data unsolicited pipeline |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 306 | this->onDataUnsolicited(ingress, data); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 307 | return; |
| 308 | } |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 309 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 310 | // CS insert |
| 311 | m_cs.insert(data); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 312 | |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 313 | // when only one PIT entry is matched, trigger strategy: after receive Data |
| 314 | if (pitMatches.size() == 1) { |
| 315 | auto& pitEntry = pitMatches.front(); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 316 | |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 317 | NFD_LOG_DEBUG("onIncomingData matching=" << pitEntry->getName()); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 318 | |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 319 | // set PIT expiry timer to now |
| 320 | this->setExpiryTimer(pitEntry, 0_ms); |
| 321 | |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 322 | // trigger strategy: after receive Data |
Junxiao Shi | b9420cf | 2016-08-13 04:38:52 +0000 | [diff] [blame] | 323 | this->dispatchToStrategy(*pitEntry, |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 324 | [&] (fw::Strategy& strategy) { strategy.afterReceiveData(pitEntry, ingress, data); }); |
Junxiao Shi | d938a6b | 2014-05-11 23:40:29 -0700 | [diff] [blame] | 325 | |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 326 | // mark PIT satisfied |
Teng Liang | 6f09ab6 | 2018-03-01 20:04:08 -0700 | [diff] [blame] | 327 | pitEntry->isSatisfied = true; |
| 328 | pitEntry->dataFreshnessPeriod = data.getFreshnessPeriod(); |
| 329 | |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 330 | // Dead Nonce List insert if necessary (for out-record of inFace) |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 331 | this->insertDeadNonceList(*pitEntry, &ingress.face); |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 332 | |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 333 | // delete PIT entry's out-record |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 334 | pitEntry->deleteOutRecord(ingress.face); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 335 | } |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 336 | // when more than one PIT entry is matched, trigger strategy: before satisfy Interest, |
| 337 | // and send Data to all matched out faces |
| 338 | else { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 339 | std::set<std::pair<Face*, EndpointId>> pendingDownstreams; |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 340 | auto now = time::steady_clock::now(); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 341 | |
Davide Pesavento | b31206e | 2019-04-20 22:34:12 -0400 | [diff] [blame] | 342 | for (const auto& pitEntry : pitMatches) { |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 343 | NFD_LOG_DEBUG("onIncomingData matching=" << pitEntry->getName()); |
| 344 | |
| 345 | // remember pending downstreams |
| 346 | for (const pit::InRecord& inRecord : pitEntry->getInRecords()) { |
| 347 | if (inRecord.getExpiry() > now) { |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 348 | pendingDownstreams.emplace(&inRecord.getFace(), 0); |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 349 | } |
| 350 | } |
| 351 | |
| 352 | // set PIT expiry timer to now |
| 353 | this->setExpiryTimer(pitEntry, 0_ms); |
| 354 | |
| 355 | // invoke PIT satisfy callback |
| 356 | this->dispatchToStrategy(*pitEntry, |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 357 | [&] (fw::Strategy& strategy) { strategy.beforeSatisfyInterest(pitEntry, ingress, data); }); |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 358 | |
| 359 | // mark PIT satisfied |
| 360 | pitEntry->isSatisfied = true; |
| 361 | pitEntry->dataFreshnessPeriod = data.getFreshnessPeriod(); |
| 362 | |
| 363 | // Dead Nonce List insert if necessary (for out-record of inFace) |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 364 | this->insertDeadNonceList(*pitEntry, &ingress.face); |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 365 | |
| 366 | // clear PIT entry's in and out records |
| 367 | pitEntry->clearInRecords(); |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 368 | pitEntry->deleteOutRecord(ingress.face); |
Junxiao Shi | da006f5 | 2014-05-16 11:18:00 -0700 | [diff] [blame] | 369 | } |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 370 | |
| 371 | // foreach pending downstream |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 372 | for (const auto& pendingDownstream : pendingDownstreams) { |
| 373 | if (pendingDownstream.first->getId() == ingress.face.getId() && |
| 374 | pendingDownstream.second == ingress.endpoint && |
| 375 | pendingDownstream.first->getLinkType() != ndn::nfd::LINK_TYPE_AD_HOC) { |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 376 | continue; |
| 377 | } |
| 378 | // goto outgoing Data pipeline |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 379 | this->onOutgoingData(data, FaceEndpoint(*pendingDownstream.first, pendingDownstream.second)); |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 380 | } |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 381 | } |
| 382 | } |
| 383 | |
| 384 | void |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 385 | Forwarder::onDataUnsolicited(const FaceEndpoint& ingress, const Data& data) |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 386 | { |
| 387 | // accept to cache? |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 388 | fw::UnsolicitedDataDecision decision = m_unsolicitedDataPolicy->decide(ingress.face, data); |
Junxiao Shi | fbe8efe | 2016-08-22 16:02:30 +0000 | [diff] [blame] | 389 | if (decision == fw::UnsolicitedDataDecision::CACHE) { |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 390 | // CS insert |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 391 | m_cs.insert(data, true); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 392 | } |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 393 | |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 394 | NFD_LOG_DEBUG("onDataUnsolicited in=" << ingress << " data=" << data.getName() << " decision=" << decision); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | void |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 398 | Forwarder::onOutgoingData(const Data& data, const FaceEndpoint& egress) |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 399 | { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 400 | if (egress.face.getId() == face::INVALID_FACEID) { |
| 401 | NFD_LOG_WARN("onOutgoingData out=(invalid) data=" << data.getName()); |
Junxiao Shi | 223271b | 2014-07-03 22:06:13 -0700 | [diff] [blame] | 402 | return; |
| 403 | } |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 404 | NFD_LOG_DEBUG("onOutgoingData out=" << egress << " data=" << data.getName()); |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 405 | |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 406 | // /localhost scope control |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 407 | bool isViolatingLocalhost = egress.face.getScope() == ndn::nfd::FACE_SCOPE_NON_LOCAL && |
Junxiao Shi | f3410d8 | 2016-04-05 13:49:44 -0700 | [diff] [blame] | 408 | scope_prefix::LOCALHOST.isPrefixOf(data.getName()); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 409 | if (isViolatingLocalhost) { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 410 | NFD_LOG_DEBUG("onOutgoingData out=" << egress << " data=" << data.getName() << " violates /localhost"); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 411 | // (drop) |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 412 | return; |
| 413 | } |
| 414 | |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 415 | // TODO traffic manager |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 416 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 417 | // send Data |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 418 | egress.face.sendData(data, egress.endpoint); |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 419 | ++m_counters.nOutData; |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 420 | } |
| 421 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 422 | void |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 423 | Forwarder::onIncomingNack(const FaceEndpoint& ingress, const lp::Nack& nack) |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 424 | { |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 425 | // receive Nack |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 426 | nack.setTag(make_shared<lp::IncomingFaceIdTag>(ingress.face.getId())); |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 427 | ++m_counters.nInNacks; |
| 428 | |
Teng Liang | 4f5cdcf | 2017-03-16 15:33:31 -0700 | [diff] [blame] | 429 | // if multi-access or ad hoc face, drop |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 430 | if (ingress.face.getLinkType() != ndn::nfd::LINK_TYPE_POINT_TO_POINT) { |
Davide Pesavento | b31206e | 2019-04-20 22:34:12 -0400 | [diff] [blame] | 431 | NFD_LOG_DEBUG("onIncomingNack in=" << ingress |
| 432 | << " nack=" << nack.getInterest().getName() << "~" << nack.getReason() |
| 433 | << " link-type=" << ingress.face.getLinkType()); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 434 | return; |
| 435 | } |
| 436 | |
| 437 | // PIT match |
| 438 | shared_ptr<pit::Entry> pitEntry = m_pit.find(nack.getInterest()); |
| 439 | // if no PIT entry found, drop |
| 440 | if (pitEntry == nullptr) { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 441 | NFD_LOG_DEBUG("onIncomingNack in=" << ingress << " nack=" << nack.getInterest().getName() |
| 442 | << "~" << nack.getReason() << " no-PIT-entry"); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 443 | return; |
| 444 | } |
| 445 | |
| 446 | // has out-record? |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 447 | auto outRecord = pitEntry->getOutRecord(ingress.face); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 448 | // if no out-record found, drop |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 449 | if (outRecord == pitEntry->out_end()) { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 450 | NFD_LOG_DEBUG("onIncomingNack in=" << ingress << " nack=" << nack.getInterest().getName() |
| 451 | << "~" << nack.getReason() << " no-out-record"); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 452 | return; |
| 453 | } |
| 454 | |
| 455 | // if out-record has different Nonce, drop |
| 456 | if (nack.getInterest().getNonce() != outRecord->getLastNonce()) { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 457 | NFD_LOG_DEBUG("onIncomingNack in=" << ingress << " nack=" << nack.getInterest().getName() |
| 458 | << "~" << nack.getReason() << " wrong-Nonce " << nack.getInterest().getNonce() |
| 459 | << "!=" << outRecord->getLastNonce()); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 460 | return; |
| 461 | } |
| 462 | |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 463 | NFD_LOG_DEBUG("onIncomingNack in=" << ingress << " nack=" << nack.getInterest().getName() |
| 464 | << "~" << nack.getReason() << " OK"); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 465 | |
| 466 | // record Nack on out-record |
| 467 | outRecord->setIncomingNack(nack); |
| 468 | |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 469 | // set PIT expiry timer to now when all out-record receive Nack |
| 470 | if (!fw::hasPendingOutRecords(*pitEntry)) { |
| 471 | this->setExpiryTimer(pitEntry, 0_ms); |
| 472 | } |
| 473 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 474 | // trigger strategy: after receive NACK |
Junxiao Shi | b9420cf | 2016-08-13 04:38:52 +0000 | [diff] [blame] | 475 | this->dispatchToStrategy(*pitEntry, |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 476 | [&] (fw::Strategy& strategy) { strategy.afterReceiveNack(ingress, nack, pitEntry); }); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | void |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 480 | Forwarder::onOutgoingNack(const shared_ptr<pit::Entry>& pitEntry, |
| 481 | const FaceEndpoint& egress, const lp::NackHeader& nack) |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 482 | { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 483 | if (egress.face.getId() == face::INVALID_FACEID) { |
| 484 | NFD_LOG_WARN("onOutgoingNack out=(invalid)" |
Davide Pesavento | b31206e | 2019-04-20 22:34:12 -0400 | [diff] [blame] | 485 | << " nack=" << pitEntry->getInterest().getName() << "~" << nack.getReason()); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 486 | return; |
| 487 | } |
| 488 | |
| 489 | // has in-record? |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 490 | auto inRecord = pitEntry->getInRecord(egress.face); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 491 | |
| 492 | // if no in-record found, drop |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 493 | if (inRecord == pitEntry->in_end()) { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 494 | NFD_LOG_DEBUG("onOutgoingNack out=" << egress |
| 495 | << " nack=" << pitEntry->getInterest().getName() |
| 496 | << "~" << nack.getReason() << " no-in-record"); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 497 | return; |
| 498 | } |
| 499 | |
Teng Liang | 4f5cdcf | 2017-03-16 15:33:31 -0700 | [diff] [blame] | 500 | // if multi-access or ad hoc face, drop |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 501 | if (egress.face.getLinkType() != ndn::nfd::LINK_TYPE_POINT_TO_POINT) { |
| 502 | NFD_LOG_DEBUG("onOutgoingNack out=" << egress |
Davide Pesavento | b31206e | 2019-04-20 22:34:12 -0400 | [diff] [blame] | 503 | << " nack=" << pitEntry->getInterest().getName() << "~" << nack.getReason() |
| 504 | << " link-type=" << egress.face.getLinkType()); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 505 | return; |
| 506 | } |
| 507 | |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 508 | NFD_LOG_DEBUG("onOutgoingNack out=" << egress |
| 509 | << " nack=" << pitEntry->getInterest().getName() |
| 510 | << "~" << nack.getReason() << " OK"); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 511 | |
| 512 | // create Nack packet with the Interest from in-record |
| 513 | lp::Nack nackPkt(inRecord->getInterest()); |
| 514 | nackPkt.setHeader(nack); |
| 515 | |
| 516 | // erase in-record |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 517 | pitEntry->deleteInRecord(egress.face); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 518 | |
| 519 | // send Nack on face |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 520 | egress.face.sendNack(nackPkt, egress.endpoint); |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 521 | ++m_counters.nOutNacks; |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 522 | } |
| 523 | |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 524 | void |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 525 | Forwarder::onDroppedInterest(const FaceEndpoint& egress, const Interest& interest) |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 526 | { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 527 | m_strategyChoice.findEffectiveStrategy(interest.getName()).onDroppedInterest(egress, interest); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 528 | } |
| 529 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 530 | void |
Ju Pan | 2feb459 | 2019-09-16 20:56:38 +0000 | [diff] [blame] | 531 | Forwarder::onNewNextHop(const Name& prefix, const fib::NextHop& nextHop) |
| 532 | { |
| 533 | const auto affectedEntries = this->getNameTree().partialEnumerate(prefix, |
| 534 | [&] (const name_tree::Entry& nte) -> std::pair<bool, bool> { |
| 535 | const fib::Entry* fibEntry = nte.getFibEntry(); |
| 536 | const fw::Strategy* strategy = nullptr; |
| 537 | if (nte.getStrategyChoiceEntry() != nullptr) { |
| 538 | strategy = &nte.getStrategyChoiceEntry()->getStrategy(); |
| 539 | } |
| 540 | // current nte has buffered Interests but no fibEntry (except for the root nte) and the strategy |
| 541 | // enables new nexthop behavior, we enumerate the current nte and keep visiting its children. |
| 542 | if (nte.getName().size() == 0 || |
| 543 | (strategy != nullptr && strategy->wantNewNextHopTrigger() && |
| 544 | fibEntry == nullptr && nte.hasPitEntries())) { |
| 545 | return {true, true}; |
| 546 | } |
| 547 | // we don't need the current nte (no pitEntry or strategy doesn't support new nexthop), but |
| 548 | // if the current nte has no fibEntry, it's still possible that its children are affected by |
| 549 | // the new nexthop. |
| 550 | else if (fibEntry == nullptr) { |
| 551 | return {false, true}; |
| 552 | } |
| 553 | // if the current nte has a fibEntry, we ignore the current nte and don't visit its |
| 554 | // children because they are already covered by the current nte's fibEntry. |
| 555 | else { |
| 556 | return {false, false}; |
| 557 | } |
| 558 | }); |
| 559 | |
| 560 | for (const auto& nte : affectedEntries) { |
| 561 | for (const auto& pitEntry : nte.getPitEntries()) { |
| 562 | this->dispatchToStrategy(*pitEntry, |
| 563 | [&] (fw::Strategy& strategy) { |
| 564 | strategy.afterNewNextHop(nextHop, pitEntry); |
| 565 | }); |
| 566 | } |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | void |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 571 | Forwarder::setExpiryTimer(const shared_ptr<pit::Entry>& pitEntry, time::milliseconds duration) |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 572 | { |
Teng Liang | 39465c2 | 2018-11-12 19:43:04 -0700 | [diff] [blame] | 573 | BOOST_ASSERT(pitEntry); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 574 | BOOST_ASSERT(duration >= 0_ms); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 575 | |
Davide Pesavento | 3dade00 | 2019-03-19 11:29:56 -0600 | [diff] [blame] | 576 | pitEntry->expiryTimer.cancel(); |
| 577 | pitEntry->expiryTimer = getScheduler().schedule(duration, [=] { onInterestFinalize(pitEntry); }); |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | void |
Teng Liang | 6f09ab6 | 2018-03-01 20:04:08 -0700 | [diff] [blame] | 581 | Forwarder::insertDeadNonceList(pit::Entry& pitEntry, Face* upstream) |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 582 | { |
| 583 | // need Dead Nonce List insert? |
Eric Newberry | f4056d0 | 2017-05-26 17:31:53 +0000 | [diff] [blame] | 584 | bool needDnl = true; |
Teng Liang | 6f09ab6 | 2018-03-01 20:04:08 -0700 | [diff] [blame] | 585 | if (pitEntry.isSatisfied) { |
| 586 | BOOST_ASSERT(pitEntry.dataFreshnessPeriod >= 0_ms); |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 587 | needDnl = static_cast<bool>(pitEntry.getInterest().getMustBeFresh()) && |
Teng Liang | 6f09ab6 | 2018-03-01 20:04:08 -0700 | [diff] [blame] | 588 | pitEntry.dataFreshnessPeriod < m_deadNonceList.getLifetime(); |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | if (!needDnl) { |
| 592 | return; |
| 593 | } |
| 594 | |
| 595 | // Dead Nonce List insert |
Teng Liang | f995f38 | 2017-04-04 22:09:39 +0000 | [diff] [blame] | 596 | if (upstream == nullptr) { |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 597 | // insert all outgoing Nonces |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 598 | const auto& outRecords = pitEntry.getOutRecords(); |
| 599 | std::for_each(outRecords.begin(), outRecords.end(), [&] (const auto& outRecord) { |
| 600 | m_deadNonceList.add(pitEntry.getName(), outRecord.getLastNonce()); |
| 601 | }); |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 602 | } |
| 603 | else { |
| 604 | // insert outgoing Nonce of a specific face |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 605 | auto outRecord = pitEntry.getOutRecord(*upstream); |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 606 | if (outRecord != pitEntry.getOutRecords().end()) { |
| 607 | m_deadNonceList.add(pitEntry.getName(), outRecord->getLastNonce()); |
| 608 | } |
| 609 | } |
| 610 | } |
| 611 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 612 | } // namespace nfd |