NS-3 based Named Data Networking (NDN) simulator
ndnSIM: NDN, CCN, CCNx, content centric networks
API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
ndn-fib-entry.h
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2 /*
3  * Copyright (c) 2011 University of California, Los Angeles
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19  */
20 
21 #ifndef _NDN_FIB_ENTRY_H_
22 #define _NDN_FIB_ENTRY_H_
23 
24 #include "ns3/ptr.h"
25 #include "ns3/nstime.h"
26 #include "ns3/ndn-face.h"
27 #include "ns3/ndn-name.h"
28 #include "ns3/ndn-limits.h"
29 #include "ns3/traced-value.h"
30 
31 #include <boost/multi_index_container.hpp>
32 #include <boost/multi_index/tag.hpp>
33 #include <boost/multi_index/ordered_index.hpp>
34 #include <boost/multi_index/composite_key.hpp>
35 #include <boost/multi_index/hashed_index.hpp>
36 #include <boost/multi_index/random_access_index.hpp>
37 #include <boost/multi_index/member.hpp>
38 #include <boost/multi_index/mem_fun.hpp>
39 
40 namespace ns3 {
41 namespace ndn {
42 
43 class Name;
44 typedef Name NameComponents;
45 
46 class Fib;
47 
52 namespace fib {
53 
59 {
60 public:
64  enum Status { NDN_FIB_GREEN = 1,
65  NDN_FIB_YELLOW = 2,
66  NDN_FIB_RED = 3 };
67 public:
74  FaceMetric (Ptr<Face> face, int32_t cost)
75  : m_face (face)
76  , m_status (NDN_FIB_YELLOW)
77  , m_routingCost (cost)
78  , m_sRtt (Seconds (0))
79  , m_rttVar (Seconds (0))
80  , m_realDelay (Seconds (0))
81  { }
82 
86  bool
87  operator< (const FaceMetric &fm) const { return *m_face < *fm.m_face; } // return identity of the face
88 
92  bool
93  operator< (const Ptr<Face> &face) const { return *m_face < *face; }
94 
98  Ptr<Face>
99  GetFace () const { return m_face; }
100 
105  void
106  UpdateRtt (const Time &rttSample);
107 
111  Status
112  GetStatus () const
113  {
114  return m_status;
115  }
116 
120  void
121  SetStatus (Status status)
122  {
123  m_status.Set (status);
124  }
125 
129  int32_t
130  GetRoutingCost () const
131  {
132  return m_routingCost;
133  }
134 
138  void
139  SetRoutingCost (int32_t routingCost)
140  {
141  m_routingCost = routingCost;
142  }
143 
147  Time
148  GetSRtt () const
149  {
150  return m_sRtt;
151  }
152 
156  Time
157  GetRttVar () const
158  {
159  return m_rttVar;
160  }
161 
165  Time
166  GetRealDelay () const
167  {
168  return m_realDelay;
169  }
170 
174  void
175  SetRealDelay (Time realDelay)
176  {
177  m_realDelay = realDelay;
178  }
179 
183  TracedValue<Status> &
185  {
186  return m_status;
187  }
188 
189 private:
190  friend std::ostream& operator<< (std::ostream& os, const FaceMetric &metric);
191 
192 private:
193  Ptr<Face> m_face;
194 
195  TracedValue<Status> m_status;
196 
200  int32_t m_routingCost;
201 
202  Time m_sRtt;
203  Time m_rttVar;
204 
205  Time m_realDelay;
206 };
207 
209 class i_face {};
210 class i_metric {};
211 class i_nth {};
213 
214 
226 {
228  typedef boost::multi_index::multi_index_container<
229  FaceMetric,
230  boost::multi_index::indexed_by<
231  // For fast access to elements using Face
232  boost::multi_index::ordered_unique<
233  boost::multi_index::tag<i_face>,
234  boost::multi_index::const_mem_fun<FaceMetric,Ptr<Face>,&FaceMetric::GetFace>
235  >,
236 
237  // List of available faces ordered by (status, m_routingCost)
238  boost::multi_index::ordered_non_unique<
239  boost::multi_index::tag<i_metric>,
240  boost::multi_index::composite_key<
241  FaceMetric,
242  boost::multi_index::const_mem_fun<FaceMetric,FaceMetric::Status,&FaceMetric::GetStatus>,
243  boost::multi_index::const_mem_fun<FaceMetric,int32_t,&FaceMetric::GetRoutingCost>
244  >
245  >,
246 
247  // To optimize nth candidate selection (sacrifice a little bit space to gain speed)
248  boost::multi_index::random_access<
249  boost::multi_index::tag<i_nth>
250  >
251  >
252  > type;
254 };
255 
261 class Entry : public Object
262 {
263 public:
264  typedef Entry base_type;
265 
266 public:
267  class NoFaces {};
268 
273  Entry (Ptr<Fib> fib, const Ptr<const Name> &prefix)
274  : m_fib (fib)
275  , m_prefix (prefix)
276  , m_needsProbing (false)
277  {
278  }
279 
284  void UpdateStatus (Ptr<Face> face, FaceMetric::Status status);
285 
291  void AddOrUpdateRoutingMetric (Ptr<Face> face, int32_t metric);
292 
296  void
297  SetRealDelayToProducer (Ptr<Face> face, Time delay);
298 
304  void
305  Invalidate ();
306 
310  void
311  UpdateFaceRtt (Ptr<Face> face, const Time &sample);
312 
316  const Name&
317  GetPrefix () const { return *m_prefix; }
318 
324  const FaceMetric &
325  FindBestCandidate (uint32_t skip = 0) const;
326 
330  void
331  RemoveFace (const Ptr<Face> &face)
332  {
333  m_faces.erase (face);
334  }
335 
339  Ptr<Fib>
340  GetFib ();
341 
342 private:
343  friend std::ostream& operator<< (std::ostream& os, const Entry &entry);
344 
345 public:
346  Ptr<Fib> m_fib;
347 
348  Ptr<const Name> m_prefix;
349  FaceMetricContainer::type m_faces;
350 
352 };
353 
354 std::ostream& operator<< (std::ostream& os, const Entry &entry);
355 std::ostream& operator<< (std::ostream& os, const FaceMetric &metric);
356 
357 } // namespace fib
358 } // namespace ndn
359 } // namespace ns3
360 
361 #endif // _NDN_FIB_ENTRY_H_
Entry(Ptr< Fib > fib, const Ptr< const Name > &prefix)
Constructor.
Exception class for the case when FIB entry is not found.
Class for NDN Name.
Definition: name.h:29
TracedValue< Status > & GetStatusTrace()
Get direct access to status trace.
bool m_needsProbing
flag indicating that probing should be performed
Status
Color codes for FIB face status.
Definition: ndn-fib-entry.h:64
Structure for FIB table entry, holding indexed list of available faces and their respective metrics...
void UpdateStatus(Ptr< Face > face, FaceMetric::Status status)
Update status of FIB next hop.
Typedef for indexed face container of Entry.
void SetStatus(Status status)
Set current status of FIB entry.
Ptr< Face > GetFace() const
Return Face associated with FaceMetric.
Definition: ndn-fib-entry.h:99
bool operator<(const FaceMetric &fm) const
Comparison operator used by boost::multi_index::identity<>
Definition: ndn-fib-entry.h:87
void AddOrUpdateRoutingMetric(Ptr< Face > face, int32_t metric)
Add or update routing metric of FIB next hop.
void Invalidate()
Invalidate face.
FaceMetricContainer::type m_faces
Indexed list of faces.
Time GetSRtt() const
Get current estimate for smoothed RTT value.
int32_t GetRoutingCost() const
Get current routing cost.
const Name & GetPrefix() const
Get prefix for the FIB entry.
void UpdateRtt(const Time &rttSample)
Recalculate smoothed RTT and RTT variation.
Structure holding various parameters associated with a (FibEntry, Face) tuple.
Definition: ndn-fib-entry.h:58
Ptr< Fib > GetFib()
Get pointer to access FIB, to which this entry is added.
void SetRealDelay(Time realDelay)
Set real propagation delay to the producer, calculated based on NS-3 p2p link delays.
void SetRealDelayToProducer(Ptr< Face > face, Time delay)
Set real delay to the producer.
Status GetStatus() const
Get current status of FIB entry.
Time GetRttVar() const
Get current estimate for the RTT variation.
FaceMetric(Ptr< Face > face, int32_t cost)
Metric constructor.
Definition: ndn-fib-entry.h:74
void SetRoutingCost(int32_t routingCost)
Set routing cost.
Ptr< Fib > m_fib
FIB to which entry is added.
const FaceMetric & FindBestCandidate(uint32_t skip=0) const
Find "best route" candidate, skipping `skip' first candidates (modulo # of faces) ...
void UpdateFaceRtt(Ptr< Face > face, const Time &sample)
Update RTT averages for the face.
Ptr< const Name > m_prefix
Prefix of the FIB entry.
Time GetRealDelay() const
Get real propagation delay to the producer, calculated based on NS-3 p2p link delays.
void RemoveFace(const Ptr< Face > &face)
Remove record associated with face