blob: db72d3780ec829d0027df8057b21d0fb82bdc130 [file] [log] [blame]
Vince12e49462014-06-09 13:29:32 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014, 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 "rib-entry.hpp"
27
28#include <ndn-cxx/management/nfd-control-command.hpp>
29
30namespace nfd {
31namespace rib {
32
33RibEntry::FaceList::iterator
34RibEntry::findFace(const FaceEntry& face)
35{
36 return std::find_if(begin(), end(), bind(&compareFaceIdAndOrigin, _1, face));
37}
38
39bool
40RibEntry::insertFace(const FaceEntry& entry)
41{
42 iterator it = findFace(entry);
43
44 if (it == end())
45 {
46 m_faces.push_back(entry);
47 return true;
48 }
49 else
50 {
51 return false;
52 }
53}
54
55bool
56RibEntry::eraseFace(const FaceEntry& face)
57{
58 RibEntry::iterator it = std::find_if(begin(), end(), bind(&compareFaceIdAndOrigin, _1, face));
59 if (it != m_faces.end())
60 {
61 m_faces.erase(it);
62 return true;
63 }
64 else
65 {
66 return false;
67 }
68}
69
70bool
71RibEntry::hasFaceId(const uint64_t faceId) const
72{
73 RibEntry::const_iterator it = std::find_if(cbegin(), cend(), bind(&compareFaceId, _1, faceId));
74
75 return (it != cend());
76}
77
78void
79RibEntry::addChild(shared_ptr<RibEntry> child)
80{
81 BOOST_ASSERT(!static_cast<bool>(child->getParent()));
82 child->setParent(this->shared_from_this());
83 m_children.push_back(child);
84}
85
86void
87RibEntry::removeChild(shared_ptr<RibEntry> child)
88{
89 BOOST_ASSERT(child->getParent().get() == this);
90 child->setParent(shared_ptr<RibEntry>());
91 m_children.remove(child);
92}
93
94RibEntry::FaceList::iterator
95RibEntry::eraseFace(FaceList::iterator face)
96{
97 return m_faces.erase(face);
98}
99
100std::ostream&
101operator<<(std::ostream& os, const FaceEntry& entry)
102{
103 os << "FaceEntry("
104 << " faceid: " << entry.faceId
105 << " origin: " << entry.origin
106 << " cost: " << entry.cost
107 << " flags: " << entry.flags
108 << " expires in: " << (entry.expires - time::steady_clock::now())
109 << ")";
110
111 return os;
112}
113
114std::ostream&
115operator<<(std::ostream& os, const RibEntry& entry)
116{
117 os << "RibEntry{\n";
118 os << "\tName: " << entry.getName() << "\n";
119
120 for (RibEntry::FaceList::const_iterator faceIt = entry.cbegin(); faceIt != entry.cend(); ++faceIt)
121 {
122 os << "\t" << (*faceIt) << "\n";
123 }
124
125 os << "}";
126
127 return os;
128}
129
130} // namespace rib
131} // namespace nfd