blob: fa609ef7d6a6bb7e7fe7ca833420d629c86d40c9 [file] [log] [blame]
Junxiao Shi7357ef22016-09-07 02:39:37 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Davide Pesaventoa6f32ca2017-02-11 20:08:23 -05003 * Copyright (c) 2013-2017 Regents of the University of California.
Junxiao Shi7357ef22016-09-07 02:39:37 +00004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20 */
21
22#ifndef NDN_MGMT_NFD_FIB_ENTRY_HPP
23#define NDN_MGMT_NFD_FIB_ENTRY_HPP
24
25#include "../../encoding/block.hpp"
26#include "../../name.hpp"
Junxiao Shi7357ef22016-09-07 02:39:37 +000027
28namespace ndn {
29namespace nfd {
30
Davide Pesaventoa6f32ca2017-02-11 20:08:23 -050031/** \ingroup management
32 * \sa https://redmine.named-data.net/projects/nfd/wiki/FibMgmt#FIB-Dataset
Junxiao Shi7357ef22016-09-07 02:39:37 +000033 */
34class NextHopRecord
35{
36public:
37 class Error : public tlv::Error
38 {
39 public:
40 explicit
41 Error(const std::string& what)
42 : tlv::Error(what)
43 {
44 }
45 };
46
47 NextHopRecord();
48
49 explicit
50 NextHopRecord(const Block& block);
51
52 uint64_t
53 getFaceId() const
54 {
55 return m_faceId;
56 }
57
58 NextHopRecord&
59 setFaceId(uint64_t faceId);
60
61 uint64_t
62 getCost() const
63 {
64 return m_cost;
65 }
66
67 NextHopRecord&
68 setCost(uint64_t cost);
69
70 template<encoding::Tag TAG>
71 size_t
72 wireEncode(EncodingImpl<TAG>& block) const;
73
74 const Block&
75 wireEncode() const;
76
77 void
Davide Pesaventoa6f32ca2017-02-11 20:08:23 -050078 wireDecode(const Block& block);
Junxiao Shi7357ef22016-09-07 02:39:37 +000079
80private:
81 uint64_t m_faceId;
82 uint64_t m_cost;
83
84 mutable Block m_wire;
85};
86
Davide Pesaventoa6f32ca2017-02-11 20:08:23 -050087bool
88operator==(const NextHopRecord& a, const NextHopRecord& b);
89
90inline bool
91operator!=(const NextHopRecord& a, const NextHopRecord& b)
92{
93 return !(a == b);
94}
95
96std::ostream&
97operator<<(std::ostream& os, const NextHopRecord& nh);
98
99
100/** \ingroup management
101 * \sa https://redmine.named-data.net/projects/nfd/wiki/FibMgmt#FIB-Dataset
Junxiao Shi7357ef22016-09-07 02:39:37 +0000102 */
103class FibEntry
104{
105public:
106 class Error : public tlv::Error
107 {
108 public:
109 explicit
110 Error(const std::string& what)
111 : tlv::Error(what)
112 {
113 }
114 };
115
116 FibEntry();
117
118 explicit
119 FibEntry(const Block& block);
120
121 const Name&
122 getPrefix() const
123 {
124 return m_prefix;
125 }
126
127 FibEntry&
128 setPrefix(const Name& prefix);
129
Davide Pesaventoa6f32ca2017-02-11 20:08:23 -0500130 const std::vector<NextHopRecord>&
Junxiao Shi7357ef22016-09-07 02:39:37 +0000131 getNextHopRecords() const
132 {
133 return m_nextHopRecords;
134 }
135
Davide Pesaventoa6f32ca2017-02-11 20:08:23 -0500136 template<typename InputIt>
Junxiao Shi7357ef22016-09-07 02:39:37 +0000137 FibEntry&
Davide Pesaventoa6f32ca2017-02-11 20:08:23 -0500138 setNextHopRecords(InputIt first, InputIt last)
Junxiao Shi7357ef22016-09-07 02:39:37 +0000139 {
Davide Pesaventoa6f32ca2017-02-11 20:08:23 -0500140 m_nextHopRecords.assign(first, last);
Junxiao Shi7357ef22016-09-07 02:39:37 +0000141 m_wire.reset();
142 return *this;
143 }
144
Davide Pesaventoa6f32ca2017-02-11 20:08:23 -0500145 FibEntry&
146 addNextHopRecord(const NextHopRecord& nh);
147
148 FibEntry&
149 clearNextHopRecords();
150
Junxiao Shi7357ef22016-09-07 02:39:37 +0000151 template<encoding::Tag TAG>
152 size_t
153 wireEncode(EncodingImpl<TAG>& block) const;
154
155 const Block&
156 wireEncode() const;
157
158 void
Davide Pesaventoa6f32ca2017-02-11 20:08:23 -0500159 wireDecode(const Block& block);
Junxiao Shi7357ef22016-09-07 02:39:37 +0000160
161private:
162 Name m_prefix;
Davide Pesaventoa6f32ca2017-02-11 20:08:23 -0500163 std::vector<NextHopRecord> m_nextHopRecords;
Junxiao Shi7357ef22016-09-07 02:39:37 +0000164
165 mutable Block m_wire;
166};
167
Davide Pesaventoa6f32ca2017-02-11 20:08:23 -0500168bool
169operator==(const FibEntry& a, const FibEntry& b);
170
171inline bool
172operator!=(const FibEntry& a, const FibEntry& b)
173{
174 return !(a == b);
175}
176
177std::ostream&
178operator<<(std::ostream& os, const FibEntry& entry);
179
Junxiao Shi7357ef22016-09-07 02:39:37 +0000180} // namespace nfd
181} // namespace ndn
182
183#endif // NDN_MGMT_NFD_FIB_ENTRY_HPP