blob: 6a7304cfd1e543b46766120472b91db0b3bec4c5 [file] [log] [blame]
Junxiao Shi7357ef22016-09-07 02:39:37 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2016 Regents of the University of California.
4 *
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"
27#include <list>
28
29namespace ndn {
30namespace nfd {
31
32/** @ingroup management
33 */
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
78 wireDecode(const Block& wire);
79
80private:
81 uint64_t m_faceId;
82 uint64_t m_cost;
83
84 mutable Block m_wire;
85};
86
87/** @ingroup management
88 */
89class FibEntry
90{
91public:
92 class Error : public tlv::Error
93 {
94 public:
95 explicit
96 Error(const std::string& what)
97 : tlv::Error(what)
98 {
99 }
100 };
101
102 FibEntry();
103
104 explicit
105 FibEntry(const Block& block);
106
107 const Name&
108 getPrefix() const
109 {
110 return m_prefix;
111 }
112
113 FibEntry&
114 setPrefix(const Name& prefix);
115
116 const std::list<NextHopRecord>&
117 getNextHopRecords() const
118 {
119 return m_nextHopRecords;
120 }
121
122 FibEntry&
123 addNextHopRecord(const NextHopRecord& nextHopRecord);
124
125 template<typename T>
126 FibEntry&
127 setNextHopRecords(const T& begin, const T& end)
128 {
129 m_nextHopRecords.clear();
130 m_nextHopRecords.assign(begin, end);
131 m_wire.reset();
132 return *this;
133 }
134
135 template<encoding::Tag TAG>
136 size_t
137 wireEncode(EncodingImpl<TAG>& block) const;
138
139 const Block&
140 wireEncode() const;
141
142 void
143 wireDecode(const Block& wire);
144
145private:
146 Name m_prefix;
147 std::list<NextHopRecord> m_nextHopRecords;
148
149 mutable Block m_wire;
150};
151
152} // namespace nfd
153} // namespace ndn
154
155#endif // NDN_MGMT_NFD_FIB_ENTRY_HPP