NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: 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; -*- */
22 #ifndef NDN_MGMT_NFD_RIB_ENTRY_HPP
23 #define NDN_MGMT_NFD_RIB_ENTRY_HPP
24 
25 #include "rib-flags.hpp" // include this first, to ensure it compiles on its own.
26 #include "../../name.hpp"
27 #include "../../util/time.hpp"
28 
29 #include <list>
30 
31 namespace ndn {
32 namespace nfd {
33 
51 class Route : public RibFlagsTraits<Route>
52 {
53 public:
54  class Error : public tlv::Error
55  {
56  public:
57  explicit
58  Error(const std::string& what) : tlv::Error(what)
59  {
60  }
61  };
62 
63  Route();
64 
65  explicit
66  Route(const Block& block);
67 
68  uint64_t
69  getFaceId() const
70  {
71  return m_faceId;
72  }
73 
74  Route&
75  setFaceId(uint64_t faceId)
76  {
77  m_faceId = faceId;
78  m_wire.reset();
79  return *this;
80  }
81 
82  uint64_t
83  getOrigin() const
84  {
85  return m_origin;
86  }
87 
91  Route&
92  setOrigin(uint64_t origin)
93  {
94  m_origin = origin;
95  m_wire.reset();
96  return *this;
97  }
98 
99  uint64_t
100  getCost() const
101  {
102  return m_cost;
103  }
104 
105  Route&
106  setCost(uint64_t cost)
107  {
108  m_cost = cost;
109  m_wire.reset();
110  return *this;
111  }
112 
113  uint64_t
114  getFlags() const
115  {
116  return m_flags;
117  }
118 
122  Route&
123  setFlags(uint64_t flags)
124  {
125  m_flags = flags;
126  m_wire.reset();
127  return *this;
128  }
129 
130  static const time::milliseconds INFINITE_EXPIRATION_PERIOD;
131 
132  const time::milliseconds&
134  {
135  return m_expirationPeriod;
136  }
137 
138  Route&
139  setExpirationPeriod(const time::milliseconds& expirationPeriod)
140  {
141  m_expirationPeriod = expirationPeriod;
142 
143  m_hasInfiniteExpirationPeriod = m_expirationPeriod == INFINITE_EXPIRATION_PERIOD;
144 
145  m_wire.reset();
146  return *this;
147  }
148 
149  bool
151  {
152  return m_hasInfiniteExpirationPeriod;
153  }
154 
155  template<encoding::Tag TAG>
156  size_t
157  wireEncode(EncodingImpl<TAG>& block) const;
158 
159  const Block&
160  wireEncode() const;
161 
162  void
163  wireDecode(const Block& wire);
164 
165 private:
166  uint64_t m_faceId;
167  uint64_t m_origin;
168  uint64_t m_cost;
169  uint64_t m_flags;
170  time::milliseconds m_expirationPeriod;
171  bool m_hasInfiniteExpirationPeriod;
172 
173  mutable Block m_wire;
174 };
175 
176 std::ostream&
177 operator<<(std::ostream& os, const Route& route);
178 
192 class RibEntry
193 {
194 public:
195  class Error : public tlv::Error
196  {
197  public:
198  Error(const std::string& what) : tlv::Error(what)
199  {
200  }
201  };
202 
203  typedef std::list<Route> RouteList;
204  typedef RouteList::const_iterator iterator;
205 
206  RibEntry();
207 
208  explicit
209  RibEntry(const Block& block);
210 
211  const Name&
212  getName() const
213  {
214  return m_prefix;
215  }
216 
217  RibEntry&
218  setName(const Name& prefix)
219  {
220  m_prefix = prefix;
221  m_wire.reset();
222  return *this;
223  }
224 
225  const std::list<Route>&
226  getRoutes() const
227  {
228  return m_routes;
229  }
230 
231  RibEntry&
232  addRoute(const Route& route)
233  {
234  m_routes.push_back(route);
235  m_wire.reset();
236  return *this;
237  }
238 
239  RibEntry&
241  {
242  m_routes.clear();
243  return *this;
244  }
245 
246  template<encoding::Tag TAG>
247  size_t
248  wireEncode(EncodingImpl<TAG>& block) const;
249 
250  const Block&
251  wireEncode() const;
252 
253  void
254  wireDecode(const Block& wire);
255 
256  iterator
257  begin() const;
258 
259  iterator
260  end() const;
261 
262 private:
263  Name m_prefix;
264  RouteList m_routes;
265 
266  mutable Block m_wire;
267 };
268 
269 inline RibEntry::iterator
271 {
272  return m_routes.begin();
273 }
274 
275 inline RibEntry::iterator
277 {
278  return m_routes.end();
279 }
280 
281 std::ostream&
282 operator<<(std::ostream& os, const RibEntry& entry);
283 
284 } // namespace nfd
285 } // namespace ndn
286 
287 #endif // NDN_MGMT_NFD_RIB_ENTRY_HPP
Copyright (c) 2011-2015 Regents of the University of California.
RibEntry
Copyright (c) 2014-2016, Regents of the University of California, Arizona Board of Regents...
Definition: rib-entry.cpp:32
RouteList::const_iterator iterator
Definition: rib-entry.hpp:204
bool hasInfiniteExpirationPeriod() const
Definition: rib-entry.hpp:150
uint64_t getCost() const
Definition: rib-entry.hpp:100
const Name & getName() const
Definition: rib-entry.hpp:212
Error(const std::string &what)
Definition: rib-entry.hpp:58
RibEntry & setName(const Name &prefix)
Definition: rib-entry.hpp:218
Class representing a wire element of NDN-TLV packet format.
Definition: block.hpp:43
Data abstraction for Route.
Definition: rib-entry.hpp:51
Route & setFaceId(uint64_t faceId)
Definition: rib-entry.hpp:75
iterator begin() const
Definition: rib-entry.hpp:270
iterator end() const
Definition: rib-entry.hpp:276
Route & setExpirationPeriod(const time::milliseconds &expirationPeriod)
Definition: rib-entry.hpp:139
implements getters to each RIB flag
Definition: rib-flags.hpp:38
RibEntry & clearRoutes()
Definition: rib-entry.hpp:240
Route & setFlags(uint64_t flags)
set route inheritance flags
Definition: rib-entry.hpp:123
static const time::milliseconds INFINITE_EXPIRATION_PERIOD
Definition: rib-entry.hpp:130
std::list< Route > RouteList
Definition: rib-entry.hpp:203
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
uint64_t getFaceId() const
Definition: rib-entry.hpp:69
void wireDecode(const Block &wire)
Definition: rib-entry.cpp:119
std::ostream & operator<<(std::ostream &os, FaceScope faceScope)
Name abstraction to represent an absolute name.
Definition: name.hpp:46
const std::list< Route > & getRoutes() const
Definition: rib-entry.hpp:226
RibEntry & addRoute(const Route &route)
Definition: rib-entry.hpp:232
uint64_t getOrigin() const
Definition: rib-entry.hpp:83
const Block & wireEncode() const
Definition: rib-entry.cpp:101
const time::milliseconds & getExpirationPeriod() const
Definition: rib-entry.hpp:133
uint64_t getFlags() const
Definition: rib-entry.hpp:114
Route & setCost(uint64_t cost)
Definition: rib-entry.hpp:106
Error(const std::string &what)
Definition: rib-entry.hpp:198
Route & setOrigin(uint64_t origin)
set Origin
Definition: rib-entry.hpp:92
Data abstraction for RIB entry.
Definition: rib-entry.hpp:192
represents an error in TLV encoding or decoding
Definition: tlv.hpp:50