best-route-strategy.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2020, Regents of the University of California,
4  * Arizona Board of Regents,
5  * Colorado State University,
6  * University Pierre & Marie Curie, Sorbonne University,
7  * Washington University in St. Louis,
8  * Beijing Institute of Technology,
9  * The University of Memphis.
10  *
11  * This file is part of NFD (Named Data Networking Forwarding Daemon).
12  * See AUTHORS.md for complete list of NFD authors and contributors.
13  *
14  * NFD is free software: you can redistribute it and/or modify it under the terms
15  * of the GNU General Public License as published by the Free Software Foundation,
16  * either version 3 of the License, or (at your option) any later version.
17  *
18  * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20  * PURPOSE. See the GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License along with
23  * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24  */
25 
26 #include "best-route-strategy.hpp"
27 #include "algorithm.hpp"
28 
29 namespace nfd {
30 namespace fw {
31 
33  : Strategy(forwarder)
34 {
35 }
36 
37 void
38 BestRouteStrategyBase::afterReceiveInterest(const FaceEndpoint& ingress, const Interest& interest,
39  const shared_ptr<pit::Entry>& pitEntry)
40 {
41  if (hasPendingOutRecords(*pitEntry)) {
42  // not a new Interest, don't forward
43  return;
44  }
45 
46  const fib::Entry& fibEntry = this->lookupFib(*pitEntry);
47  for (const auto& nexthop : fibEntry.getNextHops()) {
48  Face& outFace = nexthop.getFace();
49  if (!wouldViolateScope(ingress.face, interest, outFace) &&
50  canForwardToLegacy(*pitEntry, outFace)) {
51  this->sendInterest(pitEntry, outFace, interest);
52  return;
53  }
54  }
55 
56  this->rejectPendingInterest(pitEntry);
57 }
58 
60 
61 BestRouteStrategy::BestRouteStrategy(Forwarder& forwarder, const Name& name)
62  : BestRouteStrategyBase(forwarder)
63 {
65  if (!parsed.parameters.empty()) {
66  NDN_THROW(std::invalid_argument("BestRouteStrategy does not accept parameters"));
67  }
68  if (parsed.version && *parsed.version != getStrategyName()[-1].toVersion()) {
69  NDN_THROW(std::invalid_argument(
70  "BestRouteStrategy does not support version " + to_string(*parsed.version)));
71  }
73 }
74 
75 const Name&
77 {
78  static Name strategyName("/localhost/nfd/strategy/best-route/%FD%01");
79  return strategyName;
80 }
81 
82 } // namespace fw
83 } // namespace nfd
bool canForwardToLegacy(const pit::Entry &pitEntry, const Face &face)
decide whether Interest can be forwarded to face
Definition: algorithm.cpp:54
Main class of NFD&#39;s forwarding engine.
Definition: forwarder.hpp:51
void setInstanceName(const Name &name)
Set strategy instance name.
Definition: strategy.hpp:386
represents a FIB entry
Definition: fib-entry.hpp:53
void afterReceiveInterest(const FaceEndpoint &ingress, const Interest &interest, const shared_ptr< pit::Entry > &pitEntry) override
Trigger after Interest is received.
static Name makeInstanceName(const Name &input, const Name &strategyName)
Construct a strategy instance name.
Definition: strategy.cpp:134
BestRouteStrategy(Forwarder &forwarder, const Name &name=getStrategyName())
const fib::Entry & lookupFib(const pit::Entry &pitEntry) const
Performs a FIB lookup, considering Link object if present.
Definition: strategy.cpp:282
Represents a face-endpoint pair in the forwarder.
static const Name & getStrategyName()
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
generalization of a network interface
Definition: face.hpp:54
PartialName parameters
parameter components
Definition: strategy.hpp:359
bool hasPendingOutRecords(const pit::Entry &pitEntry)
determine whether pitEntry has any pending out-records
Definition: algorithm.cpp:108
Represents a forwarding strategy.
Definition: strategy.hpp:37
This file contains common algorithms used by forwarding strategies.
const NextHopList & getNextHops() const
Definition: fib-entry.hpp:66
static ParsedInstanceName parseInstanceName(const Name &input)
Parse a strategy instance name.
Definition: strategy.cpp:123
BestRouteStrategyBase(Forwarder &forwarder)
NFD_REGISTER_STRATEGY(SelfLearningStrategy)
bool wouldViolateScope(const Face &inFace, const Interest &interest, const Face &outFace)
determine whether forwarding the Interest in pitEntry to outFace would violate scope ...
Definition: algorithm.cpp:32
void rejectPendingInterest(const shared_ptr< pit::Entry > &pitEntry)
Schedule the PIT entry for immediate deletion.
Definition: strategy.hpp:291
Best Route strategy version 1.
pit::OutRecord * sendInterest(const shared_ptr< pit::Entry > &pitEntry, Face &egress, const Interest &interest)
Send an Interest packet.
Definition: strategy.cpp:197
optional< uint64_t > version
whether strategyName contains a version component
Definition: strategy.hpp:358