NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
nfd-rib-entry.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #ifndef NDN_MANAGEMENT_NFD_RIB_ENTRY_HPP
23 #define NDN_MANAGEMENT_NFD_RIB_ENTRY_HPP
24 
25 #include "nfd-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_MANAGEMENT_NFD_RIB_ENTRY_HPP
Copyright (c) 2011-2015 Regents of the University of California.
RouteList::const_iterator iterator
bool hasInfiniteExpirationPeriod() const
uint64_t getCost() const
const Name & getName() const
Error(const std::string &what)
RibEntry & setName(const Name &prefix)
Class representing a wire element of NDN-TLV packet format.
Definition: block.hpp:43
Data abstraction for Route.
Route & setFaceId(uint64_t faceId)
iterator begin() const
iterator end() const
Route & setExpirationPeriod(const time::milliseconds &expirationPeriod)
implements getters to each RIB flag
RibEntry & clearRoutes()
Route & setFlags(uint64_t flags)
set route inheritance flags
static const time::milliseconds INFINITE_EXPIRATION_PERIOD
std::list< Route > RouteList
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
const Block & wireEncode() const
uint64_t getFaceId() const
void wireDecode(const Block &wire)
std::ostream & operator<<(std::ostream &os, FaceScope faceScope)
void reset()
Reset wire buffer of the element.
Definition: block.cpp:302
Name abstraction to represent an absolute name.
Definition: name.hpp:46
const std::list< Route > & getRoutes() const
RibEntry & addRoute(const Route &route)
uint64_t getOrigin() const
const Block & wireEncode() const
void wireDecode(const Block &wire)
const time::milliseconds & getExpirationPeriod() const
uint64_t getFlags() const
Route & setCost(uint64_t cost)
Error(const std::string &what)
Route & setOrigin(uint64_t origin)
set Origin
Data abstraction for RIB entry.
represents an error in TLV encoding or decoding
Definition: tlv.hpp:50