blob: f1f30039c5975b4a762dbb40363a821c3b6480f3 [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Steve DiBenedetto6d792d72014-03-15 19:01:36 -06002/**
Alexander Afanasyev74633892015-02-08 18:08:46 -08003 * Copyright (c) 2013-2015 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * 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.
Steve DiBenedetto6d792d72014-03-15 19:01:36 -060020 */
21
22#ifndef NDN_MANAGEMENT_NFD_FIB_ENTRY_HPP
23#define NDN_MANAGEMENT_NFD_FIB_ENTRY_HPP
24
25#include "../encoding/block.hpp"
Steve DiBenedetto6d792d72014-03-15 19:01:36 -060026#include "../name.hpp"
Alexander Afanasyev258ec2b2014-05-14 16:15:37 -070027#include <list>
28
Steve DiBenedetto6d792d72014-03-15 19:01:36 -060029namespace ndn {
30namespace nfd {
31
Junxiao Shi65f1a712014-11-20 14:59:36 -070032/** @ingroup management
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040033 */
Steve DiBenedetto6d792d72014-03-15 19:01:36 -060034class NextHopRecord
35{
36public:
Steve DiBenedetto54ce6682014-07-22 13:22:57 -060037 class Error : public tlv::Error
Steve DiBenedetto6d792d72014-03-15 19:01:36 -060038 {
39 public:
Junxiao Shi65f1a712014-11-20 14:59:36 -070040 explicit
41 Error(const std::string& what)
42 : tlv::Error(what)
43 {
44 }
Steve DiBenedetto6d792d72014-03-15 19:01:36 -060045 };
46
Junxiao Shi65f1a712014-11-20 14:59:36 -070047 NextHopRecord();
Steve DiBenedetto6d792d72014-03-15 19:01:36 -060048
Alexander Afanasyev44b438a2014-03-19 12:51:49 -070049 explicit
Junxiao Shi65f1a712014-11-20 14:59:36 -070050 NextHopRecord(const Block& block);
Steve DiBenedetto6d792d72014-03-15 19:01:36 -060051
52 uint64_t
53 getFaceId() const
54 {
55 return m_faceId;
56 }
57
58 NextHopRecord&
Junxiao Shi65f1a712014-11-20 14:59:36 -070059 setFaceId(uint64_t faceId);
Steve DiBenedetto6d792d72014-03-15 19:01:36 -060060
61 uint64_t
62 getCost() const
63 {
64 return m_cost;
65 }
66
67 NextHopRecord&
Junxiao Shi65f1a712014-11-20 14:59:36 -070068 setCost(uint64_t cost);
Steve DiBenedetto6d792d72014-03-15 19:01:36 -060069
Alexander Afanasyev74633892015-02-08 18:08:46 -080070 template<encoding::Tag TAG>
Steve DiBenedetto6d792d72014-03-15 19:01:36 -060071 size_t
Alexander Afanasyev74633892015-02-08 18:08:46 -080072 wireEncode(EncodingImpl<TAG>& block) const;
Steve DiBenedetto6d792d72014-03-15 19:01:36 -060073
74 const Block&
Junxiao Shi65f1a712014-11-20 14:59:36 -070075 wireEncode() const;
Steve DiBenedetto6d792d72014-03-15 19:01:36 -060076
77 void
Junxiao Shi65f1a712014-11-20 14:59:36 -070078 wireDecode(const Block& wire);
Steve DiBenedetto6d792d72014-03-15 19:01:36 -060079
80private:
81 uint64_t m_faceId;
82 uint64_t m_cost;
83
84 mutable Block m_wire;
85};
86
Junxiao Shi65f1a712014-11-20 14:59:36 -070087/** @ingroup management
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040088 */
Steve DiBenedetto6d792d72014-03-15 19:01:36 -060089class FibEntry
90{
91public:
Junxiao Shi65f1a712014-11-20 14:59:36 -070092 class Error : public tlv::Error
Steve DiBenedetto6d792d72014-03-15 19:01:36 -060093 {
Junxiao Shi65f1a712014-11-20 14:59:36 -070094 public:
95 explicit
96 Error(const std::string& what)
97 : tlv::Error(what)
98 {
99 }
100 };
101
102 FibEntry();
Steve DiBenedetto6d792d72014-03-15 19:01:36 -0600103
Alexander Afanasyev44b438a2014-03-19 12:51:49 -0700104 explicit
Junxiao Shi65f1a712014-11-20 14:59:36 -0700105 FibEntry(const Block& block);
Steve DiBenedetto6d792d72014-03-15 19:01:36 -0600106
107 const Name&
108 getPrefix() const
109 {
110 return m_prefix;
111 }
112
113 FibEntry&
Junxiao Shi65f1a712014-11-20 14:59:36 -0700114 setPrefix(const Name& prefix);
Steve DiBenedetto6d792d72014-03-15 19:01:36 -0600115
116 const std::list<NextHopRecord>&
117 getNextHopRecords() const
118 {
119 return m_nextHopRecords;
120 }
121
122 FibEntry&
Junxiao Shi65f1a712014-11-20 14:59:36 -0700123 addNextHopRecord(const NextHopRecord& nextHopRecord);
Steve DiBenedetto6d792d72014-03-15 19:01:36 -0600124
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
Alexander Afanasyev74633892015-02-08 18:08:46 -0800135 template<encoding::Tag TAG>
Steve DiBenedetto6d792d72014-03-15 19:01:36 -0600136 size_t
Alexander Afanasyev74633892015-02-08 18:08:46 -0800137 wireEncode(EncodingImpl<TAG>& block) const;
Steve DiBenedetto6d792d72014-03-15 19:01:36 -0600138
139 const Block&
Junxiao Shi65f1a712014-11-20 14:59:36 -0700140 wireEncode() const;
Steve DiBenedetto6d792d72014-03-15 19:01:36 -0600141
142 void
Junxiao Shi65f1a712014-11-20 14:59:36 -0700143 wireDecode(const Block& wire);
Steve DiBenedetto6d792d72014-03-15 19:01:36 -0600144
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_MANAGEMENT_NFD_FIB_ENTRY_HPP