blob: b68e21f0b0122c55a76a6a94c5787273ac667227 [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/*
Junxiao Shi68b53852018-07-25 13:56:38 -06003 * Copyright (c) 2013-2018 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:
Junxiao Shi68b53852018-07-25 13:56:38 -060040 using tlv::Error::Error;
Junxiao Shi7357ef22016-09-07 02:39:37 +000041 };
42
43 NextHopRecord();
44
45 explicit
46 NextHopRecord(const Block& block);
47
48 uint64_t
49 getFaceId() const
50 {
51 return m_faceId;
52 }
53
54 NextHopRecord&
55 setFaceId(uint64_t faceId);
56
57 uint64_t
58 getCost() const
59 {
60 return m_cost;
61 }
62
63 NextHopRecord&
64 setCost(uint64_t cost);
65
66 template<encoding::Tag TAG>
67 size_t
68 wireEncode(EncodingImpl<TAG>& block) const;
69
70 const Block&
71 wireEncode() const;
72
73 void
Davide Pesaventoa6f32ca2017-02-11 20:08:23 -050074 wireDecode(const Block& block);
Junxiao Shi7357ef22016-09-07 02:39:37 +000075
76private:
77 uint64_t m_faceId;
78 uint64_t m_cost;
79
80 mutable Block m_wire;
81};
82
Davide Pesavento88a0d812017-08-19 21:31:42 -040083NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(NextHopRecord);
84
Davide Pesaventoa6f32ca2017-02-11 20:08:23 -050085bool
86operator==(const NextHopRecord& a, const NextHopRecord& b);
87
88inline bool
89operator!=(const NextHopRecord& a, const NextHopRecord& b)
90{
91 return !(a == b);
92}
93
94std::ostream&
95operator<<(std::ostream& os, const NextHopRecord& nh);
96
97
98/** \ingroup management
99 * \sa https://redmine.named-data.net/projects/nfd/wiki/FibMgmt#FIB-Dataset
Junxiao Shi7357ef22016-09-07 02:39:37 +0000100 */
101class FibEntry
102{
103public:
104 class Error : public tlv::Error
105 {
106 public:
107 explicit
108 Error(const std::string& what)
109 : tlv::Error(what)
110 {
111 }
112 };
113
114 FibEntry();
115
116 explicit
117 FibEntry(const Block& block);
118
119 const Name&
120 getPrefix() const
121 {
122 return m_prefix;
123 }
124
125 FibEntry&
126 setPrefix(const Name& prefix);
127
Davide Pesaventoa6f32ca2017-02-11 20:08:23 -0500128 const std::vector<NextHopRecord>&
Junxiao Shi7357ef22016-09-07 02:39:37 +0000129 getNextHopRecords() const
130 {
131 return m_nextHopRecords;
132 }
133
Davide Pesaventoa6f32ca2017-02-11 20:08:23 -0500134 template<typename InputIt>
Junxiao Shi7357ef22016-09-07 02:39:37 +0000135 FibEntry&
Davide Pesaventoa6f32ca2017-02-11 20:08:23 -0500136 setNextHopRecords(InputIt first, InputIt last)
Junxiao Shi7357ef22016-09-07 02:39:37 +0000137 {
Davide Pesaventoa6f32ca2017-02-11 20:08:23 -0500138 m_nextHopRecords.assign(first, last);
Junxiao Shi7357ef22016-09-07 02:39:37 +0000139 m_wire.reset();
140 return *this;
141 }
142
Davide Pesaventoa6f32ca2017-02-11 20:08:23 -0500143 FibEntry&
144 addNextHopRecord(const NextHopRecord& nh);
145
146 FibEntry&
147 clearNextHopRecords();
148
Junxiao Shi7357ef22016-09-07 02:39:37 +0000149 template<encoding::Tag TAG>
150 size_t
151 wireEncode(EncodingImpl<TAG>& block) const;
152
153 const Block&
154 wireEncode() const;
155
156 void
Davide Pesaventoa6f32ca2017-02-11 20:08:23 -0500157 wireDecode(const Block& block);
Junxiao Shi7357ef22016-09-07 02:39:37 +0000158
159private:
160 Name m_prefix;
Davide Pesaventoa6f32ca2017-02-11 20:08:23 -0500161 std::vector<NextHopRecord> m_nextHopRecords;
Junxiao Shi7357ef22016-09-07 02:39:37 +0000162
163 mutable Block m_wire;
164};
165
Davide Pesavento88a0d812017-08-19 21:31:42 -0400166NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(FibEntry);
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