blob: eae0c6590b69cc4d9673877fa7a0d047351f6716 [file] [log] [blame]
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -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_H_
22#define _CCNX_FIB_H_
23
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070024#include "ns3/simple-ref-count.h"
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070025#include "ns3/node.h"
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070026
Alexander Afanasyev78057c32012-07-06 15:18:46 -070027#include "ns3/ccnx-fib-entry.h"
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070028
29namespace ns3 {
30
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070031class CcnxInterestHeader;
32
33/**
34 * \ingroup ccnx
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070035 * \brief Class implementing FIB functionality
36 */
Alexander Afanasyev07827182011-12-13 01:07:32 -080037class CcnxFib : public Object
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070038{
39public:
Alexander Afanasyev78057c32012-07-06 15:18:46 -070040 /**
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -070041 * \brief Interface ID
42 *
43 * \return interface ID
44 */
45 static TypeId GetTypeId ();
46 /**
Alexander Afanasyev78057c32012-07-06 15:18:46 -070047 * @brief Default constructor
48 */
49 CcnxFib () {}
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -070050
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070051 /**
Alexander Afanasyev78057c32012-07-06 15:18:46 -070052 * @brief Virtual destructor
Alexander Afanasyevcf133f02011-09-06 12:13:48 -070053 */
Alexander Afanasyev78057c32012-07-06 15:18:46 -070054 virtual ~CcnxFib () { };
55
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070056 /**
57 * \brief Perform longest prefix match
58 *
59 * \todo Implement exclude filters
60 *
61 * \param interest Interest packet header
Alexander Afanasyev8accdf62011-09-20 11:33:59 -070062 * \returns If entry found a valid iterator will be returned, otherwise end ()
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070063 */
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070064 virtual Ptr<CcnxFibEntry>
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070065 LongestPrefixMatch (const CcnxInterestHeader &interest) = 0;
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070066
67 /**
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070068 * \brief Add or update FIB entry
69 *
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070070 * If the entry exists, metric will be updated. Otherwise, new entry will be created
71 *
72 * Entries in FIB never deleted. They can be invalidated with metric==NETWORK_UNREACHABLE
73 *
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070074 * @param name Prefix
75 * @param face Forwarding face
76 * @param metric Routing metric
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070077 */
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070078 virtual Ptr<CcnxFibEntry>
Alexander Afanasyev78057c32012-07-06 15:18:46 -070079 Add (const CcnxNameComponents &prefix, Ptr<CcnxFace> face, int32_t metric) = 0;
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070080
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080081 /**
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -070082 * \brief Add or update FIB entry using smart pointer to prefix
83 *
84 * If the entry exists, metric will be updated. Otherwise, new entry will be created
85 *
86 * Entries in FIB never deleted. They can be invalidated with metric==NETWORK_UNREACHABLE
87 *
88 * @param name Smart pointer to prefix
89 * @param face Forwarding face
90 * @param metric Routing metric
91 */
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070092 virtual Ptr<CcnxFibEntry>
Alexander Afanasyev78057c32012-07-06 15:18:46 -070093 Add (const Ptr<const CcnxNameComponents> &prefix, Ptr<CcnxFace> face, int32_t metric) = 0;
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -070094
95 /**
96 * @brief Remove FIB entry
97 *
98 * ! ATTENTION ! Use with caution. All PIT entries referencing the corresponding FIB entry will become invalid.
99 * So, simulation may crash.
100 *
101 * @param name Smart pointer to prefix
102 */
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700103 virtual void
104 Remove (const Ptr<const CcnxNameComponents> &prefix) = 0;
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700105
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -0700106 // /**
107 // * @brief Invalidate FIB entry ("Safe" version of Remove)
108 // *
109 // * All faces for the entry will be assigned maximum routing metric and NDN_FIB_RED status
110 // * @param name Smart pointer to prefix
111 // */
112 // virtual void
113 // Invalidate (const Ptr<const CcnxNameComponents> &prefix) = 0;
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700114
115 /**
116 * @brief Invalidate all FIB entries
117 */
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700118 virtual void
119 InvalidateAll () = 0;
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700120
121 /**
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800122 * @brief Remove all references to a face from FIB. If for some enty that face was the only element,
123 * this FIB entry will be removed.
124 */
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700125 virtual void
126 RemoveFromAll (Ptr<CcnxFace> face) = 0;
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700127
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700128 /**
129 * @brief Print out entries in FIB
130 */
131 virtual void
132 Print (std::ostream &os) const = 0;
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700133
134 /**
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700135 * @brief Get number of entries in FIB
136 */
137 virtual uint32_t
138 GetSize () const = 0;
139
140 /**
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700141 * @brief Return first element of FIB (no order guaranteed)
142 */
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700143 virtual Ptr<const CcnxFibEntry>
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700144 Begin () = 0;
145
146 /**
147 * @brief Return item next after last (no order guaranteed)
148 */
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700149 virtual Ptr<const CcnxFibEntry>
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700150 End () = 0;
151
152 /**
153 * @brief Advance the iterator
154 */
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700155 virtual Ptr<const CcnxFibEntry>
156 Next (Ptr<const CcnxFibEntry>) = 0;
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700157
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700158 ////////////////////////////////////////////////////////////////////////////
159 ////////////////////////////////////////////////////////////////////////////
160 ////////////////////////////////////////////////////////////////////////////
161
162 /**
163 * @brief Static call to cheat python bindings
164 */
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700165 static inline Ptr<CcnxFib>
166 GetCcnxFib (Ptr<Object> node);
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700167
168 ////////////////////////////////////////////////////////////////////////////
169 ////////////////////////////////////////////////////////////////////////////
170 ////////////////////////////////////////////////////////////////////////////
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700171
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -0700172private:
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -0700173 CcnxFib(const CcnxFib&) {} ; ///< \brief copy constructor is disabled
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -0700174};
175
176///////////////////////////////////////////////////////////////////////////////
177///////////////////////////////////////////////////////////////////////////////
178
179std::ostream& operator<< (std::ostream& os, const CcnxFib &fib);
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700180
181Ptr<CcnxFib>
182CcnxFib::GetCcnxFib (Ptr<Object> node)
183{
184 return node->GetObject<CcnxFib> ();
185}
186
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -0700187} // namespace ns3
188
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700189#endif // _CCNX_FIB_H_