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-2018 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 "ndn-cxx/name.hpp"
28 #include "ndn-cxx/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  using tlv::Error::Error;
49  };
50 
51  Route();
52 
53  explicit
54  Route(const Block& block);
55 
56  uint64_t
57  getFaceId() const
58  {
59  return m_faceId;
60  }
61 
62  Route&
63  setFaceId(uint64_t faceId);
64 
66  getOrigin() const
67  {
68  return m_origin;
69  }
70 
71  Route&
72  setOrigin(RouteOrigin origin);
73 
74  uint64_t
75  getCost() const
76  {
77  return m_cost;
78  }
79 
80  Route&
81  setCost(uint64_t cost);
82 
83  uint64_t
84  getFlags() const
85  {
86  return m_flags;
87  }
88 
89  Route&
90  setFlags(uint64_t flags);
91 
92  bool
94  {
95  return !!m_expirationPeriod;
96  }
97 
98  time::milliseconds
100  {
101  return m_expirationPeriod ? *m_expirationPeriod : time::milliseconds::max();
102  }
103 
104  Route&
105  setExpirationPeriod(time::milliseconds expirationPeriod);
106 
107  Route&
109 
110  template<encoding::Tag TAG>
111  size_t
112  wireEncode(EncodingImpl<TAG>& block) const;
113 
114  const Block&
115  wireEncode() const;
116 
117  void
118  wireDecode(const Block& block);
119 
120 private:
121  uint64_t m_faceId;
122  RouteOrigin m_origin;
123  uint64_t m_cost;
124  uint64_t m_flags;
125  optional<time::milliseconds> m_expirationPeriod;
126 
127  mutable Block m_wire;
128 };
129 
131 
132 bool
133 operator==(const Route& a, const Route& b);
134 
135 inline bool
136 operator!=(const Route& a, const Route& b)
137 {
138  return !(a == b);
139 }
140 
141 std::ostream&
142 operator<<(std::ostream& os, const Route& route);
143 
144 
153 class RibEntry
154 {
155 public:
156  class Error : public tlv::Error
157  {
158  public:
159  explicit
160  Error(const std::string& what)
161  : tlv::Error(what)
162  {
163  }
164  };
165 
166  RibEntry();
167 
168  explicit
169  RibEntry(const Block& block);
170 
171  const Name&
172  getName() const
173  {
174  return m_prefix;
175  }
176 
177  RibEntry&
178  setName(const Name& prefix);
179 
180  const std::vector<Route>&
181  getRoutes() const
182  {
183  return m_routes;
184  }
185 
186  template<typename InputIt>
187  RibEntry&
188  setRoutes(InputIt first, InputIt last)
189  {
190  m_routes.assign(first, last);
191  m_wire.reset();
192  return *this;
193  }
194 
195  RibEntry&
196  addRoute(const Route& route);
197 
198  RibEntry&
199  clearRoutes();
200 
201  template<encoding::Tag TAG>
202  size_t
203  wireEncode(EncodingImpl<TAG>& block) const;
204 
205  const Block&
206  wireEncode() const;
207 
208  void
209  wireDecode(const Block& block);
210 
211 private:
212  Name m_prefix;
213  std::vector<Route> m_routes;
214 
215  mutable Block m_wire;
216 };
217 
219 
220 bool
221 operator==(const RibEntry& a, const RibEntry& b);
222 
223 inline bool
224 operator!=(const RibEntry& a, const RibEntry& b)
225 {
226  return !(a == b);
227 }
228 
229 std::ostream&
230 operator<<(std::ostream& os, const RibEntry& entry);
231 
232 } // namespace nfd
233 } // namespace ndn
234 
235 #endif // NDN_MGMT_NFD_RIB_ENTRY_HPP
Copyright (c) 2011-2015 Regents of the University of California.
bool operator!=(const ChannelStatus &a, const ChannelStatus &b)
defines getters for each route inheritance flag
uint64_t getCost() const
Definition: rib-entry.hpp:75
Route & setFlags(uint64_t flags)
Definition: rib-entry.cpp:75
const Name & getName() const
Definition: rib-entry.hpp:172
void wireDecode(const Block &block)
Definition: rib-entry.cpp:287
Route & setOrigin(RouteOrigin origin)
Definition: rib-entry.cpp:59
time::milliseconds getExpirationPeriod() const
Definition: rib-entry.hpp:99
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:57
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:255
Represents an absolute name.
Definition: name.hpp:43
Route & unsetExpirationPeriod()
Definition: rib-entry.cpp:94
bool hasExpirationPeriod() const
Definition: rib-entry.hpp:93
const Block & wireEncode() const
Definition: rib-entry.cpp:124
RibEntry & setRoutes(InputIt first, InputIt last)
Definition: rib-entry.hpp:188
NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(ChannelStatus)
uint64_t getFlags() const
Definition: rib-entry.hpp:84
Route & setFaceId(uint64_t faceId)
Definition: rib-entry.cpp:51
Error(const std::string &what)
Definition: rib-entry.hpp:160
const std::vector< Route > & getRoutes() const
Definition: rib-entry.hpp:181
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:153
RouteOrigin getOrigin() const
Definition: rib-entry.hpp:66
represents an error in TLV encoding or decoding
Definition: tlv.hpp:52
RibEntry & clearRoutes()
Definition: rib-entry.cpp:245