7bb01512b0
This commit also deletes fib::Entry::set/getStrategy attribute. refs #1276 Change-Id: I57dfe842a8024e0ad9908ba8a9c415d5f4ac1bbe
75 lines
1.5 KiB
C++
75 lines
1.5 KiB
C++
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
|
/**
|
|
* Copyright (C) 2014 Named Data Networking Project
|
|
* See COPYING for copyright and distribution information.
|
|
*/
|
|
|
|
#include "fib-entry.hpp"
|
|
|
|
namespace nfd {
|
|
namespace fib {
|
|
|
|
Entry::Entry(const Name& prefix)
|
|
: m_prefix(prefix)
|
|
{
|
|
}
|
|
|
|
static inline bool
|
|
predicate_NextHop_eq_Face(const NextHop& nexthop, shared_ptr<Face> face)
|
|
{
|
|
return nexthop.getFace() == face;
|
|
}
|
|
|
|
bool
|
|
Entry::hasNextHop(shared_ptr<Face> face) const
|
|
{
|
|
NextHopList::const_iterator it = std::find_if(m_nextHops.begin(), m_nextHops.end(),
|
|
bind(&predicate_NextHop_eq_Face, _1, face));
|
|
return it != m_nextHops.end();
|
|
}
|
|
|
|
void
|
|
Entry::addNextHop(shared_ptr<Face> face, int32_t cost)
|
|
{
|
|
NextHopList::iterator it = std::find_if(m_nextHops.begin(), m_nextHops.end(),
|
|
bind(&predicate_NextHop_eq_Face, _1, face));
|
|
if (it == m_nextHops.end()) {
|
|
m_nextHops.push_back(fib::NextHop(face));
|
|
it = m_nextHops.end() - 1;
|
|
}
|
|
// now it refers to the NextHop for face
|
|
|
|
it->setCost(cost);
|
|
|
|
this->sortNextHops();
|
|
|
|
}
|
|
|
|
void
|
|
Entry::removeNextHop(shared_ptr<Face> face)
|
|
{
|
|
NextHopList::iterator it = std::find_if(m_nextHops.begin(), m_nextHops.end(),
|
|
bind(&predicate_NextHop_eq_Face, _1, face));
|
|
if (it == m_nextHops.end()) {
|
|
return;
|
|
}
|
|
|
|
m_nextHops.erase(it);
|
|
}
|
|
|
|
static inline bool
|
|
compare_NextHop_cost(const NextHop& a, const NextHop& b)
|
|
{
|
|
return a.getCost() < b.getCost();
|
|
}
|
|
|
|
void
|
|
Entry::sortNextHops()
|
|
{
|
|
std::sort(m_nextHops.begin(), m_nextHops.end(), &compare_NextHop_cost);
|
|
}
|
|
|
|
|
|
} // namespace fib
|
|
} // namespace nfd
|