NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
rib-entry.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2017 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_RIB_ENTRY_HPP
23 #define NDN_MGMT_NFD_RIB_ENTRY_HPP
24 
25 #include "route-flags-traits.hpp"
26 #include "../../encoding/block.hpp"
27 #include "../../name.hpp"
28 #include "../../util/time.hpp"
29 
30 namespace ndn {
31 namespace nfd {
32 
42 class Route : public RouteFlagsTraits<Route>
43 {
44 public:
45  class Error : public tlv::Error
46  {
47  public:
48  explicit
49  Error(const std::string& what)
50  : tlv::Error(what)
51  {
52  }
53  };
54 
55  Route();
56 
57  explicit
58  Route(const Block& block);
59 
60  uint64_t
61  getFaceId() const
62  {
63  return m_faceId;
64  }
65 
66  Route&
67  setFaceId(uint64_t faceId);
68 
70  getOrigin() const
71  {
72  return m_origin;
73  }
74 
75  Route&
76  setOrigin(RouteOrigin origin);
77 
78  uint64_t
79  getCost() const
80  {
81  return m_cost;
82  }
83 
84  Route&
85  setCost(uint64_t cost);
86 
87  uint64_t
88  getFlags() const
89  {
90  return m_flags;
91  }
92 
93  Route&
94  setFlags(uint64_t flags);
95 
96  bool
98  {
99  return !!m_expirationPeriod;
100  }
101 
102  time::milliseconds
104  {
105  return m_expirationPeriod ? *m_expirationPeriod : time::milliseconds::max();
106  }
107 
108  Route&
109  setExpirationPeriod(time::milliseconds expirationPeriod);
110 
111  Route&
113 
114  template<encoding::Tag TAG>
115  size_t
116  wireEncode(EncodingImpl<TAG>& block) const;
117 
118  const Block&
119  wireEncode() const;
120 
121  void
122  wireDecode(const Block& block);
123 
124 private:
125  uint64_t m_faceId;
126  RouteOrigin m_origin;
127  uint64_t m_cost;
128  uint64_t m_flags;
129  optional<time::milliseconds> m_expirationPeriod;
130 
131  mutable Block m_wire;
132 };
133 
135 
136 bool
137 operator==(const Route& a, const Route& b);
138 
139 inline bool
140 operator!=(const Route& a, const Route& b)
141 {
142  return !(a == b);
143 }
144 
145 std::ostream&
146 operator<<(std::ostream& os, const Route& route);
147 
148 
157 class RibEntry
158 {
159 public:
160  class Error : public tlv::Error
161  {
162  public:
163  explicit
164  Error(const std::string& what)
165  : tlv::Error(what)
166  {
167  }
168  };
169 
170  RibEntry();
171 
172  explicit
173  RibEntry(const Block& block);
174 
175  const Name&
176  getName() const
177  {
178  return m_prefix;
179  }
180 
181  RibEntry&
182  setName(const Name& prefix);
183 
184  const std::vector<Route>&
185  getRoutes() const
186  {
187  return m_routes;
188  }
189 
190  template<typename InputIt>
191  RibEntry&
192  setRoutes(InputIt first, InputIt last)
193  {
194  m_routes.assign(first, last);
195  m_wire.reset();
196  return *this;
197  }
198 
199  RibEntry&
200  addRoute(const Route& route);
201 
202  RibEntry&
203  clearRoutes();
204 
205  template<encoding::Tag TAG>
206  size_t
207  wireEncode(EncodingImpl<TAG>& block) const;
208 
209  const Block&
210  wireEncode() const;
211 
212  void
213  wireDecode(const Block& block);
214 
215 private:
216  Name m_prefix;
217  std::vector<Route> m_routes;
218 
219  mutable Block m_wire;
220 };
221 
223 
224 bool
225 operator==(const RibEntry& a, const RibEntry& b);
226 
227 inline bool
228 operator!=(const RibEntry& a, const RibEntry& b)
229 {
230  return !(a == b);
231 }
232 
233 std::ostream&
234 operator<<(std::ostream& os, const RibEntry& entry);
235 
236 } // namespace nfd
237 } // namespace ndn
238 
239 #endif // NDN_MGMT_NFD_RIB_ENTRY_HPP
Copyright (c) 2011-2015 Regents of the University of California.
RibEntry
Copyright (c) 2014-2017, Regents of the University of California, Arizona Board of Regents...
Definition: rib-entry.cpp:32
bool operator!=(const ChannelStatus &a, const ChannelStatus &b)
defines getters for each route inheritance flag
uint64_t getCost() const
Definition: rib-entry.hpp:79
Route & setFlags(uint64_t flags)
Definition: rib-entry.cpp:75
const Name & getName() const
Definition: rib-entry.hpp:176
void wireDecode(const Block &block)
Definition: rib-entry.cpp:287
Route & setOrigin(RouteOrigin origin)
Definition: rib-entry.cpp:59
Error(const std::string &what)
Definition: rib-entry.hpp:49
time::milliseconds getExpirationPeriod() const
Definition: rib-entry.hpp:103
Represents a TLV element of NDN packet format.
Definition: block.hpp:42
represents a route in a RibEntry
Definition: rib-entry.hpp:42
void wireDecode(const Block &block)
Definition: rib-entry.cpp:140
Route & setCost(uint64_t cost)
Definition: rib-entry.cpp:67
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
const Block & wireEncode() const
Definition: rib-entry.cpp:271
bool operator==(const ChannelStatus &a, const ChannelStatus &b)
uint64_t getFaceId() const
Definition: rib-entry.hpp:61
RibEntry & addRoute(const Route &route)
Definition: rib-entry.cpp:237
std::ostream & operator<<(std::ostream &os, FaceScope faceScope)
void reset()
Reset wire buffer of the element.
Definition: block.cpp:258
Represents an absolute name.
Definition: name.hpp:42
Route & unsetExpirationPeriod()
Definition: rib-entry.cpp:94
bool hasExpirationPeriod() const
Definition: rib-entry.hpp:97
const Block & wireEncode() const
Definition: rib-entry.cpp:124
RibEntry & setRoutes(InputIt first, InputIt last)
Definition: rib-entry.hpp:192
NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(ChannelStatus)
uint64_t getFlags() const
Definition: rib-entry.hpp:88
Route & setFaceId(uint64_t faceId)
Definition: rib-entry.cpp:51
Error(const std::string &what)
Definition: rib-entry.hpp:164
const std::vector< Route > & getRoutes() const
Definition: rib-entry.hpp:185
Route & setExpirationPeriod(time::milliseconds expirationPeriod)
Definition: rib-entry.cpp:83
RibEntry & setName(const Name &prefix)
Definition: rib-entry.cpp:229
represents an item in NFD RIB dataset
Definition: rib-entry.hpp:157
RouteOrigin getOrigin() const
Definition: rib-entry.hpp:70
represents an error in TLV encoding or decoding
Definition: tlv.hpp:50
RibEntry & clearRoutes()
Definition: rib-entry.cpp:245