fib-entry.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #include "fib-entry.hpp"
27 
28 namespace nfd {
29 namespace fib {
30 
31 Entry::Entry(const Name& prefix)
32  : m_prefix(prefix)
33  , m_nameTreeEntry(nullptr)
34 {
35 }
36 
38 Entry::findNextHop(const Face& face)
39 {
40  return std::find_if(m_nextHops.begin(), m_nextHops.end(),
41  [&face] (const NextHop& nexthop) {
42  return &nexthop.getFace() == &face;
43  });
44 }
45 
46 bool
47 Entry::hasNextHop(const Face& face) const
48 {
49  return const_cast<Entry*>(this)->findNextHop(face) != m_nextHops.end();
50 }
51 
52 void
53 Entry::addNextHop(Face& face, uint64_t cost)
54 {
55  auto it = this->findNextHop(face);
56  if (it == m_nextHops.end()) {
57  m_nextHops.emplace_back(face);
58  it = std::prev(m_nextHops.end());
59  }
60 
61  it->setCost(cost);
62  this->sortNextHops();
63 }
64 
65 void
66 Entry::removeNextHop(const Face& face)
67 {
68  auto it = this->findNextHop(face);
69  if (it != m_nextHops.end()) {
70  m_nextHops.erase(it);
71  }
72 }
73 
74 void
75 Entry::sortNextHops()
76 {
77  std::sort(m_nextHops.begin(), m_nextHops.end(),
78  [] (const NextHop& a, const NextHop& b) { return a.getCost() < b.getCost(); });
79 }
80 
81 } // namespace fib
82 } // namespace nfd
bool hasNextHop(const Face &face) const
Definition: fib-entry.cpp:47
represents a FIB entry
Definition: fib-entry.hpp:51
void addNextHop(Face &face, uint64_t cost)
adds a NextHop record
Definition: fib-entry.cpp:53
Entry(const Name &prefix)
Definition: fib-entry.cpp:31
Table::const_iterator iterator
Definition: cs-internal.hpp:41
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
void removeNextHop(const Face &face)
removes a NextHop record
Definition: fib-entry.cpp:66
represents a nexthop record in FIB entry
Definition: fib-nexthop.hpp:38
uint64_t getCost() const
Definition: fib-nexthop.hpp:51