blob: d91f6511c84b13e07a2a914fa4c77b745165785e [file] [log] [blame]
Junxiao Shi7357ef22016-09-07 02:39:37 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento88a0d812017-08-19 21:31:42 -04002/*
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 Pesavento88a0d812017-08-19 21:31:42 -040087NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(NextHopRecord);
88
Davide Pesaventoa6f32ca2017-02-11 20:08:23 -050089bool
90operator==(const NextHopRecord& a, const NextHopRecord& b);
91
92inline bool
93operator!=(const NextHopRecord& a, const NextHopRecord& b)
94{
95 return !(a == b);
96}
97
98std::ostream&
99operator<<(std::ostream& os, const NextHopRecord& nh);
100
101
102/** \ingroup management
103 * \sa https://redmine.named-data.net/projects/nfd/wiki/FibMgmt#FIB-Dataset
Junxiao Shi7357ef22016-09-07 02:39:37 +0000104 */
105class FibEntry
106{
107public:
108 class Error : public tlv::Error
109 {
110 public:
111 explicit
112 Error(const std::string& what)
113 : tlv::Error(what)
114 {
115 }
116 };
117
118 FibEntry();
119
120 explicit
121 FibEntry(const Block& block);
122
123 const Name&
124 getPrefix() const
125 {
126 return m_prefix;
127 }
128
129 FibEntry&
130 setPrefix(const Name& prefix);
131
Davide Pesaventoa6f32ca2017-02-11 20:08:23 -0500132 const std::vector<NextHopRecord>&
Junxiao Shi7357ef22016-09-07 02:39:37 +0000133 getNextHopRecords() const
134 {
135 return m_nextHopRecords;
136 }
137
Davide Pesaventoa6f32ca2017-02-11 20:08:23 -0500138 template<typename InputIt>
Junxiao Shi7357ef22016-09-07 02:39:37 +0000139 FibEntry&
Davide Pesaventoa6f32ca2017-02-11 20:08:23 -0500140 setNextHopRecords(InputIt first, InputIt last)
Junxiao Shi7357ef22016-09-07 02:39:37 +0000141 {
Davide Pesaventoa6f32ca2017-02-11 20:08:23 -0500142 m_nextHopRecords.assign(first, last);
Junxiao Shi7357ef22016-09-07 02:39:37 +0000143 m_wire.reset();
144 return *this;
145 }
146
Davide Pesaventoa6f32ca2017-02-11 20:08:23 -0500147 FibEntry&
148 addNextHopRecord(const NextHopRecord& nh);
149
150 FibEntry&
151 clearNextHopRecords();
152
Junxiao Shi7357ef22016-09-07 02:39:37 +0000153 template<encoding::Tag TAG>
154 size_t
155 wireEncode(EncodingImpl<TAG>& block) const;
156
157 const Block&
158 wireEncode() const;
159
160 void
Davide Pesaventoa6f32ca2017-02-11 20:08:23 -0500161 wireDecode(const Block& block);
Junxiao Shi7357ef22016-09-07 02:39:37 +0000162
163private:
164 Name m_prefix;
Davide Pesaventoa6f32ca2017-02-11 20:08:23 -0500165 std::vector<NextHopRecord> m_nextHopRecords;
Junxiao Shi7357ef22016-09-07 02:39:37 +0000166
167 mutable Block m_wire;
168};
169
Davide Pesavento88a0d812017-08-19 21:31:42 -0400170NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(FibEntry);
171
Davide Pesaventoa6f32ca2017-02-11 20:08:23 -0500172bool
173operator==(const FibEntry& a, const FibEntry& b);
174
175inline bool
176operator!=(const FibEntry& a, const FibEntry& b)
177{
178 return !(a == b);
179}
180
181std::ostream&
182operator<<(std::ostream& os, const FibEntry& entry);
183
Junxiao Shi7357ef22016-09-07 02:39:37 +0000184} // namespace nfd
185} // namespace ndn
186
187#endif // NDN_MGMT_NFD_FIB_ENTRY_HPP