blob: f2acfed60d8f76675693db75fe90ed33b77f9e40 [file] [log] [blame]
Junxiao Shi986b8492014-08-20 12:07:14 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Ashlesh Gawande90015992017-07-11 17:25:48 -05002/*
Davide Pesavento19779d82019-02-14 13:40:04 -05003 * Copyright (c) 2014-2019, Regents of the University of California,
Junxiao Shi192af1f2015-01-13 23:19:39 -07004 * 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.
Junxiao Shi986b8492014-08-20 12:07:14 -070010 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26#include "best-route-strategy2.hpp"
Junxiao Shi00dc9142016-11-21 14:23:12 +000027#include "algorithm.hpp"
Davide Pesavento2cae8ca2019-04-18 20:48:05 -040028#include "common/logger.hpp"
Junxiao Shi986b8492014-08-20 12:07:14 -070029
30namespace nfd {
31namespace fw {
32
Davide Pesaventoa3148082018-04-12 18:21:54 -040033NFD_LOG_INIT(BestRouteStrategy2);
Junxiao Shifaf3eb02015-02-16 10:50:36 -070034NFD_REGISTER_STRATEGY(BestRouteStrategy2);
Junxiao Shi986b8492014-08-20 12:07:14 -070035
Junxiao Shi52e85402015-11-11 06:06:58 -070036const time::milliseconds BestRouteStrategy2::RETX_SUPPRESSION_INITIAL(10);
37const time::milliseconds BestRouteStrategy2::RETX_SUPPRESSION_MAX(250);
38
Junxiao Shi986b8492014-08-20 12:07:14 -070039BestRouteStrategy2::BestRouteStrategy2(Forwarder& forwarder, const Name& name)
Junxiao Shi18739c42016-12-22 08:03:00 +000040 : Strategy(forwarder)
Junxiao Shi99540072017-01-27 19:57:33 +000041 , ProcessNackTraits(this)
Junxiao Shi52e85402015-11-11 06:06:58 -070042 , m_retxSuppression(RETX_SUPPRESSION_INITIAL,
43 RetxSuppressionExponential::DEFAULT_MULTIPLIER,
44 RETX_SUPPRESSION_MAX)
Junxiao Shi986b8492014-08-20 12:07:14 -070045{
Junxiao Shi18739c42016-12-22 08:03:00 +000046 ParsedInstanceName parsed = parseInstanceName(name);
47 if (!parsed.parameters.empty()) {
Davide Pesavento19779d82019-02-14 13:40:04 -050048 NDN_THROW(std::invalid_argument("BestRouteStrategy2 does not accept parameters"));
Junxiao Shi18739c42016-12-22 08:03:00 +000049 }
Junxiao Shi91f6ee02016-12-29 21:44:44 +000050 if (parsed.version && *parsed.version != getStrategyName()[-1].toVersion()) {
Davide Pesavento19779d82019-02-14 13:40:04 -050051 NDN_THROW(std::invalid_argument(
Alexander Afanasyev0c63c632017-12-05 11:17:09 -050052 "BestRouteStrategy2 does not support version " + to_string(*parsed.version)));
Junxiao Shi91f6ee02016-12-29 21:44:44 +000053 }
Junxiao Shi18739c42016-12-22 08:03:00 +000054 this->setInstanceName(makeInstanceName(name, getStrategyName()));
Junxiao Shi986b8492014-08-20 12:07:14 -070055}
56
Junxiao Shi037f4ab2016-12-13 04:27:06 +000057const Name&
58BestRouteStrategy2::getStrategyName()
59{
Teng Liangf995f382017-04-04 22:09:39 +000060 static Name strategyName("/localhost/nfd/strategy/best-route/%FD%05");
Junxiao Shi037f4ab2016-12-13 04:27:06 +000061 return strategyName;
62}
63
Junxiao Shi986b8492014-08-20 12:07:14 -070064void
ashiqopuc7079482019-02-20 05:34:37 +000065BestRouteStrategy2::afterReceiveInterest(const FaceEndpoint& ingress, const Interest& interest,
Junxiao Shi15e98b02016-08-12 11:21:44 +000066 const shared_ptr<pit::Entry>& pitEntry)
Junxiao Shi986b8492014-08-20 12:07:14 -070067{
Ashlesh Gawande90015992017-07-11 17:25:48 -050068 RetxSuppressionResult suppression = m_retxSuppression.decidePerPitEntry(*pitEntry);
69 if (suppression == RetxSuppressionResult::SUPPRESS) {
ashiqopuc7079482019-02-20 05:34:37 +000070 NFD_LOG_DEBUG(interest << " from=" << ingress << " suppressed");
Junxiao Shi8d843142016-07-11 22:42:42 +000071 return;
72 }
73
74 const fib::Entry& fibEntry = this->lookupFib(*pitEntry);
75 const fib::NextHopList& nexthops = fibEntry.getNextHops();
Davide Pesaventoe4b22382018-06-10 14:37:24 -040076 auto it = nexthops.end();
Junxiao Shi986b8492014-08-20 12:07:14 -070077
Ashlesh Gawande90015992017-07-11 17:25:48 -050078 if (suppression == RetxSuppressionResult::NEW) {
Junxiao Shi986b8492014-08-20 12:07:14 -070079 // forward to nexthop with lowest cost except downstream
Davide Pesaventoe4b22382018-06-10 14:37:24 -040080 it = std::find_if(nexthops.begin(), nexthops.end(), [&] (const auto& nexthop) {
ashiqopuc7079482019-02-20 05:34:37 +000081 return isNextHopEligible(ingress.face, interest, nexthop, pitEntry);
Davide Pesaventoe4b22382018-06-10 14:37:24 -040082 });
Junxiao Shi986b8492014-08-20 12:07:14 -070083
84 if (it == nexthops.end()) {
ashiqopuc7079482019-02-20 05:34:37 +000085 NFD_LOG_DEBUG(interest << " from=" << ingress << " noNextHop");
Junxiao Shi5e5e4452015-09-24 16:56:52 -070086
87 lp::NackHeader nackHeader;
88 nackHeader.setReason(lp::NackReason::NO_ROUTE);
ashiqopuc7079482019-02-20 05:34:37 +000089 this->sendNack(pitEntry, ingress, nackHeader);
Junxiao Shi5e5e4452015-09-24 16:56:52 -070090
Junxiao Shi986b8492014-08-20 12:07:14 -070091 this->rejectPendingInterest(pitEntry);
92 return;
93 }
94
ashiqopuc7079482019-02-20 05:34:37 +000095 auto egress = FaceEndpoint(it->getFace(), 0);
ashiqopuc7079482019-02-20 05:34:37 +000096 NFD_LOG_DEBUG(interest << " from=" << ingress << " newPitEntry-to=" << egress);
Saurab Dulala6dec222019-04-01 00:15:10 -050097 this->sendInterest(pitEntry, egress, interest);
Junxiao Shi986b8492014-08-20 12:07:14 -070098 return;
99 }
100
Junxiao Shi986b8492014-08-20 12:07:14 -0700101 // find an unused upstream with lowest cost except downstream
Davide Pesaventoe4b22382018-06-10 14:37:24 -0400102 it = std::find_if(nexthops.begin(), nexthops.end(), [&] (const auto& nexthop) {
ashiqopuc7079482019-02-20 05:34:37 +0000103 return isNextHopEligible(ingress.face, interest, nexthop, pitEntry, true, time::steady_clock::now());
Davide Pesaventoe4b22382018-06-10 14:37:24 -0400104 });
105
Junxiao Shi986b8492014-08-20 12:07:14 -0700106 if (it != nexthops.end()) {
ashiqopuc7079482019-02-20 05:34:37 +0000107 auto egress = FaceEndpoint(it->getFace(), 0);
108 this->sendInterest(pitEntry, egress, interest);
109 NFD_LOG_DEBUG(interest << " from=" << ingress << " retransmit-unused-to=" << egress);
Junxiao Shi986b8492014-08-20 12:07:14 -0700110 return;
111 }
112
113 // find an eligible upstream that is used earliest
ashiqopuc7079482019-02-20 05:34:37 +0000114 it = findEligibleNextHopWithEarliestOutRecord(ingress.face, interest, nexthops, pitEntry);
Junxiao Shi986b8492014-08-20 12:07:14 -0700115 if (it == nexthops.end()) {
ashiqopuc7079482019-02-20 05:34:37 +0000116 NFD_LOG_DEBUG(interest << " from=" << ingress << " retransmitNoNextHop");
Junxiao Shi986b8492014-08-20 12:07:14 -0700117 }
118 else {
ashiqopuc7079482019-02-20 05:34:37 +0000119 auto egress = FaceEndpoint(it->getFace(), 0);
120 this->sendInterest(pitEntry, egress, interest);
121 NFD_LOG_DEBUG(interest << " from=" << ingress << " retransmit-retry-to=" << egress);
Junxiao Shi986b8492014-08-20 12:07:14 -0700122 }
123}
124
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700125void
ashiqopuc7079482019-02-20 05:34:37 +0000126BestRouteStrategy2::afterReceiveNack(const FaceEndpoint& ingress, const lp::Nack& nack,
Junxiao Shi15e98b02016-08-12 11:21:44 +0000127 const shared_ptr<pit::Entry>& pitEntry)
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700128{
ashiqopuc7079482019-02-20 05:34:37 +0000129 this->processNack(ingress.face, nack, pitEntry);
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700130}
131
Junxiao Shi986b8492014-08-20 12:07:14 -0700132} // namespace fw
133} // namespace nfd