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