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-pit-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_PIT_ENTRY_H_
22 #define _NDN_PIT_ENTRY_H_
23 
24 #include "ns3/ptr.h"
25 #include "ns3/simple-ref-count.h"
26 
27 #include "ns3/ndn-fib.h"
28 
29 #include "ns3/ndn-pit-entry-incoming-face.h"
30 #include "ns3/ndn-pit-entry-outgoing-face.h"
31 
32 #include <boost/multi_index_container.hpp>
33 #include <boost/multi_index/tag.hpp>
34 #include <boost/multi_index/ordered_index.hpp>
35 // #include <boost/multi_index/composite_key.hpp>
36 // #include <boost/multi_index/hashed_index.hpp>
37 #include <boost/multi_index/member.hpp>
38 // #include <boost/multi_index/mem_fun.hpp>
39 #include <set>
40 #include <boost/shared_ptr.hpp>
41 
42 namespace ns3 {
43 namespace ndn {
44 
45 class Pit;
46 
47 namespace fw { class Tag; }
48 
49 namespace pit {
50 
57 class Entry : public SimpleRefCount<Entry>
58 {
59 public:
60  typedef std::set< IncomingFace > in_container;
61  typedef in_container::iterator in_iterator;
62 
63  // typedef OutgoingFaceContainer::type out_container; ///< @brief outgoing faces container type
64  typedef std::set< OutgoingFace > out_container;
65  typedef out_container::iterator out_iterator;
66 
67  typedef std::set< uint32_t > nonce_container;
68 
75  Entry (Pit &container, Ptr<const Interest> header, Ptr<fib::Entry> fibEntry);
76 
80  virtual ~Entry ();
81 
90  virtual void
91  UpdateLifetime (const Time &lifetime);
92 
100  virtual void
101  OffsetLifetime (const Time &offsetTime);
102 
106  const Name &
107  GetPrefix () const;
108 
114  const Time &
115  GetExpireTime () const;
116 
122  bool
123  IsNonceSeen (uint32_t nonce) const;
124 
132  virtual void
133  AddSeenNonce (uint32_t nonce);
134 
141  virtual in_iterator
142  AddIncoming (Ptr<Face> face);
143 
147  virtual void
148  RemoveIncoming (Ptr<Face> face);
149 
153  virtual void
154  ClearIncoming ();
155 
162  virtual out_iterator
163  AddOutgoing (Ptr<Face> face);
164 
168  virtual void
169  ClearOutgoing ();
170 
177  virtual void
178  RemoveAllReferencesToFace (Ptr<Face> face);
179 
183  // virtual void
184  // SetWaitingInVain (out_iterator face);
185  virtual void
186  SetWaitingInVain (Ptr<Face> face);
187 
191  bool
192  AreAllOutgoingInVain () const;
193 
198  bool
199  AreTherePromisingOutgoingFacesExcept (Ptr<Face> face) const;
200 
204  virtual void
206 
210  uint32_t
211  GetMaxRetxCount () const;
212 
216  Ptr<fib::Entry>
217  GetFibEntry ();
218 
222  const in_container &
223  GetIncoming () const;
224 
228  const out_container &
229  GetOutgoing () const;
230 
234  uint32_t
235  GetOutgoingCount () const;
236 
240  inline void
241  AddFwTag (boost::shared_ptr< fw::Tag > tag);
242 
246  template<class T>
247  inline boost::shared_ptr< T >
248  GetFwTag ();
249 
253  template<class T>
254  inline void
255  RemoveFwTag ();
256 
260  Ptr<const Interest>
261  GetInterest () const;
262 
263 private:
264  friend std::ostream& operator<< (std::ostream& os, const Entry &entry);
265 
266 protected:
268 
269  Ptr<const Interest> m_interest;
270  Ptr<fib::Entry> m_fibEntry;
271 
275 
277 
279  uint32_t m_maxRetxCount;
280 
281  std::list< boost::shared_ptr<fw::Tag> > m_fwTags;
282 };
283 
285 struct EntryIsNotEmpty
286 {
287  bool
288  operator () (Ptr<Entry> entry)
289  {
290  return !entry->GetIncoming ().empty ();
291  }
292 };
294 
295 std::ostream& operator<< (std::ostream& os, const Entry &entry);
296 
297 inline void
298 Entry::AddFwTag (boost::shared_ptr< fw::Tag > tag)
299 {
300  m_fwTags.push_back (tag);
301 }
302 
306 template<class T>
307 inline boost::shared_ptr< T >
309 {
310  for (std::list< boost::shared_ptr<fw::Tag> >::iterator item = m_fwTags.begin ();
311  item != m_fwTags.end ();
312  item ++)
313  {
314  boost::shared_ptr< T > retPtr = boost::dynamic_pointer_cast<T> (*item);
315  if (retPtr != boost::shared_ptr< T > ())
316  {
317  return retPtr;
318  }
319  }
320 
321  return boost::shared_ptr< T > ();
322 }
323 
324 // /**
325 // * @brief Peek the forwarding strategy tag
326 // */
327 // template<class T>
328 // inline boost::shared_ptr< const T >
329 // Entry::PeekFwTag () const
330 // {
331 // for (std::list< boost::shared_ptr<fw::Tag> >::const_iterator item = m_fwTags.begin ();
332 // item != m_fwTags.end ();
333 // item ++)
334 // {
335 // boost::shared_ptr< const T > retPtr = boost::dynamic_pointer_cast<const T> (*item);
336 // if (retPtr != 0)
337 // {
338 // return retPtr;
339 // }
340 // }
341 
342 // return 0;
343 // }
344 
345 template<class T>
346 inline void
348 {
349  for (std::list< boost::shared_ptr<fw::Tag> >::iterator item = m_fwTags.begin ();
350  item != m_fwTags.end ();
351  item ++)
352  {
353  boost::shared_ptr< T > retPtr = boost::dynamic_pointer_cast< T > (*item);
354  if (retPtr != boost::shared_ptr< T > ())
355  {
356  m_fwTags.erase (item);
357  return;
358  }
359  }
360 }
361 
362 
363 } // namespace pit
364 } // namespace ndn
365 } // namespace ns3
366 
367 #endif // _NDN_PIT_ENTRY_H_
bool AreTherePromisingOutgoingFacesExcept(Ptr< Face > face) const
Similar to AreAllOutgoingInVain, but ignores face
Ptr< fib::Entry > m_fibEntry
FIB entry related to this prefix.
Class for NDN Name.
Definition: name.h:29
structure for PIT entry
Definition: ndn-pit-entry.h:57
void RemoveFwTag()
Remove the forwarding strategy tag.
Entry(Pit &container, Ptr< const Interest > header, Ptr< fib::Entry > fibEntry)
PIT entry constructor.
out_container m_outgoing
container for outgoing interests
Ptr< const Interest > m_interest
Interest of the PIT entry (if several interests are received, then nonce is from the first Interest) ...
virtual in_iterator AddIncoming(Ptr< Face > face)
Add face to the list of incoming faces.
virtual void RemoveAllReferencesToFace(Ptr< Face > face)
Remove all references to face.
virtual ~Entry()
Virtual destructor.
std::set< OutgoingFace > out_container
outgoing faces container type
Definition: ndn-pit-entry.h:64
Class implementing Pending Interests Table.
Definition: ndn-pit.h:60
Time m_lastRetransmission
Last time when number of retransmissions were increased.
virtual out_iterator AddOutgoing(Ptr< Face > face)
Add face to the list of outgoing faces.
Ptr< fib::Entry > GetFibEntry()
Get associated FIB entry.
virtual void ClearIncoming()
Clear all incoming faces either after all of them were satisfied or NACKed.
bool AreAllOutgoingInVain() const
Check if all outgoing faces are NACKed.
void AddFwTag(boost::shared_ptr< fw::Tag > tag)
Add new forwarding strategy tag.
in_container::iterator in_iterator
iterator to incoming faces
Definition: ndn-pit-entry.h:61
std::list< boost::shared_ptr< fw::Tag > > m_fwTags
Forwarding strategy tags.
virtual void RemoveIncoming(Ptr< Face > face)
Remove incoming entry for face face
in_container m_incoming
container for incoming interests
virtual void OffsetLifetime(const Time &offsetTime)
Offset the currently set PIT lifetime (allowed both negative and positive offsets) ...
boost::shared_ptr< T > GetFwTag()
Get forwarding strategy tag (tag is not removed)
std::set< IncomingFace > in_container
incoming faces container type
Definition: ndn-pit-entry.h:60
Ptr< const Interest > GetInterest() const
Get Interest (if several interests are received, then nonce is from the first Interest) ...
Time m_expireTime
Time when PIT entry will be removed.
const in_container & GetIncoming() const
Get associated list (const reference) of incoming faces.
virtual void ClearOutgoing()
Clear all incoming faces either after all of them were satisfied or NACKed.
const out_container & GetOutgoing() const
Get associated list (const reference) of outgoing faces.
uint32_t m_maxRetxCount
Maximum allowed number of retransmissions via outgoing faces.
virtual void AddSeenNonce(uint32_t nonce)
Add nonce to the list of seen nonces.
virtual void UpdateLifetime(const Time &lifetime)
Update lifetime of PIT entry.
nonce_container m_seenNonces
map of nonces that were seen for this prefix
const Name & GetPrefix() const
Get prefix of the PIT entry.
virtual void SetWaitingInVain(Ptr< Face > face)
Flag outgoing face as hopeless.
uint32_t GetOutgoingCount() const
Get number of outgoing faces (needed for python bindings)
Pit & m_container
Reference to the container (to rearrange indexes, if necessary)
std::set< uint32_t > nonce_container
nonce container type
Definition: ndn-pit-entry.h:67
const Time & GetExpireTime() const
Get current expiration time of the record.
virtual void IncreaseAllowedRetxCount()
Increase maximum limit of allowed retransmission per outgoing face.
uint32_t GetMaxRetxCount() const
Get maximum allowed number of retransmissions via outgoing faces.
bool IsNonceSeen(uint32_t nonce) const
Check if nonce nonce for the same prefix has already been seen.
out_container::iterator out_iterator
iterator to outgoing faces
Definition: ndn-pit-entry.h:65