blob: a9b9efc880cdb1ac4d8597c60740629c783dca7f [file] [log] [blame]
Alexander Afanasyev78057c32012-07-06 15:18:46 -07001/* -*- 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 _CCNX_FIB_IMPL_H_
22#define _CCNX_FIB_IMPL_H_
23
24#include "ns3/ccnx-fib.h"
25#include "ns3/ccnx-name-components.h"
26
27#include "../utils/trie-with-policy.h"
28#include "../utils/empty-policy.h"
29
30namespace ns3 {
31
Alexander Afanasyev1ba09b82012-07-09 09:16:14 -070032class CcnxFibEntryImpl : public CcnxFibEntry
33{
34public:
35 typedef ndnSIM::trie_with_policy<
36 CcnxNameComponents,
37 ndnSIM::smart_pointer_payload_traits<CcnxFibEntryImpl>,
38 ndnSIM::empty_policy_traits
39 > trie;
40
41 CcnxFibEntryImpl (const Ptr<const CcnxNameComponents> &prefix)
42 : CcnxFibEntry (prefix)
43 , item_ (0)
44 {
45 }
46
47 void
48 SetTrie (trie::iterator item)
49 {
50 item_ = item;
51 }
52
53 trie::iterator to_iterator () { return item_; }
54 trie::const_iterator to_iterator () const { return item_; }
55
56private:
57 trie::iterator item_;
58};
59
Alexander Afanasyev78057c32012-07-06 15:18:46 -070060struct CcnxFibEntryContainer
61{
62 typedef ndnSIM::trie_with_policy<
63 CcnxNameComponents,
Alexander Afanasyev1ba09b82012-07-09 09:16:14 -070064 ndnSIM::smart_pointer_payload_traits<CcnxFibEntryImpl>,
Alexander Afanasyev78057c32012-07-06 15:18:46 -070065 ndnSIM::empty_policy_traits
66 > type;
67};
68
69/**
70 * \ingroup ccnx
71 * \brief Class implementing FIB functionality
72 */
73class CcnxFibImpl : public CcnxFib,
74 private CcnxFibEntryContainer::type
75{
76public:
77 typedef CcnxFibEntryContainer::type super;
78
79 /**
80 * \brief Interface ID
81 *
82 * \return interface ID
83 */
84 static TypeId GetTypeId ();
85
86 /**
87 * \brief Constructor
88 */
89 CcnxFibImpl ();
90
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -070091 virtual CcnxFib::iterator
Alexander Afanasyev78057c32012-07-06 15:18:46 -070092 LongestPrefixMatch (const CcnxInterestHeader &interest) const;
93
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -070094 virtual CcnxFib::iterator
Alexander Afanasyev78057c32012-07-06 15:18:46 -070095 Add (const CcnxNameComponents &prefix, Ptr<CcnxFace> face, int32_t metric);
96
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -070097 virtual CcnxFib::iterator
Alexander Afanasyev78057c32012-07-06 15:18:46 -070098 Add (const Ptr<const CcnxNameComponents> &prefix, Ptr<CcnxFace> face, int32_t metric);
99
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700100 virtual void
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700101 Remove (const Ptr<const CcnxNameComponents> &prefix);
102
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700103 virtual void
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700104 InvalidateAll ();
105
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700106 virtual void
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700107 RemoveFromAll (Ptr<CcnxFace> face);
108
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700109 virtual void
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700110 Print (std::ostream &os) const;
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700111
112 virtual CcnxFib::const_iterator
113 Begin ();
114
115 virtual CcnxFib::const_iterator
116 End ();
117
118 virtual CcnxFib::const_iterator
119 Next (CcnxFib::const_iterator item);
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700120
121 /**
122 * @brief Modify element in container
123 */
124 template<typename Modifier>
125 bool
Alexander Afanasyev1ba09b82012-07-09 09:16:14 -0700126 modify (CcnxFib::iterator item, Modifier mod)
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700127 {
Alexander Afanasyev1ba09b82012-07-09 09:16:14 -0700128 return super::modify (StaticCast<CcnxFibEntryImpl> (item)->to_iterator (), mod);
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700129 }
130
131protected:
132 // inherited from Object class
133 virtual void NotifyNewAggregate (); ///< @brief Notify when object is aggregated
134 virtual void DoDispose (); ///< @brief Perform cleanup
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -0700135
136private:
137 /**
138 * @brief Remove reference to a face from the entry. If entry had only this face, the whole
139 * entry will be removed
140 */
141 void
142 Remove (super::parent_trie &item, Ptr<CcnxFace> face);
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700143
144private:
145 Ptr<Node> m_node;
146};
147
148} // namespace ns3
149
150#endif /* _CCNX_FIB_IMPL_H_ */