blob: 0a24db934b7a10f370a19243bb06eebf240a4ff9 [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 typedef ns3::Ptr<CcnxFibEntry> iterator; // not sure, but let's see what will happen
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -070041 typedef ns3::Ptr<const CcnxFibEntry> const_iterator;
Alexander Afanasyev78057c32012-07-06 15:18:46 -070042
43 /**
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -070044 * \brief Interface ID
45 *
46 * \return interface ID
47 */
48 static TypeId GetTypeId ();
49 /**
Alexander Afanasyev78057c32012-07-06 15:18:46 -070050 * @brief Default constructor
51 */
52 CcnxFib () {}
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -070053
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070054 /**
Alexander Afanasyev78057c32012-07-06 15:18:46 -070055 * @brief Virtual destructor
Alexander Afanasyevcf133f02011-09-06 12:13:48 -070056 */
Alexander Afanasyev78057c32012-07-06 15:18:46 -070057 virtual ~CcnxFib () { };
58
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070059 /**
60 * \brief Perform longest prefix match
61 *
62 * \todo Implement exclude filters
63 *
64 * \param interest Interest packet header
Alexander Afanasyev8accdf62011-09-20 11:33:59 -070065 * \returns If entry found a valid iterator will be returned, otherwise end ()
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070066 */
Alexander Afanasyev78057c32012-07-06 15:18:46 -070067 virtual iterator
68 LongestPrefixMatch (const CcnxInterestHeader &interest) const = 0;
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070069
70 /**
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070071 * \brief Add or update FIB entry
72 *
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070073 * If the entry exists, metric will be updated. Otherwise, new entry will be created
74 *
75 * Entries in FIB never deleted. They can be invalidated with metric==NETWORK_UNREACHABLE
76 *
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070077 * @param name Prefix
78 * @param face Forwarding face
79 * @param metric Routing metric
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070080 */
Alexander Afanasyev78057c32012-07-06 15:18:46 -070081 virtual iterator
82 Add (const CcnxNameComponents &prefix, Ptr<CcnxFace> face, int32_t metric) = 0;
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070083
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080084 /**
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -070085 * \brief Add or update FIB entry using smart pointer to prefix
86 *
87 * If the entry exists, metric will be updated. Otherwise, new entry will be created
88 *
89 * Entries in FIB never deleted. They can be invalidated with metric==NETWORK_UNREACHABLE
90 *
91 * @param name Smart pointer to prefix
92 * @param face Forwarding face
93 * @param metric Routing metric
94 */
Alexander Afanasyev78057c32012-07-06 15:18:46 -070095 virtual iterator
96 Add (const Ptr<const CcnxNameComponents> &prefix, Ptr<CcnxFace> face, int32_t metric) = 0;
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -070097
98 /**
99 * @brief Remove FIB entry
100 *
101 * ! ATTENTION ! Use with caution. All PIT entries referencing the corresponding FIB entry will become invalid.
102 * So, simulation may crash.
103 *
104 * @param name Smart pointer to prefix
105 */
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700106 virtual void
107 Remove (const Ptr<const CcnxNameComponents> &prefix) = 0;
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700108
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -0700109 // /**
110 // * @brief Invalidate FIB entry ("Safe" version of Remove)
111 // *
112 // * All faces for the entry will be assigned maximum routing metric and NDN_FIB_RED status
113 // * @param name Smart pointer to prefix
114 // */
115 // virtual void
116 // Invalidate (const Ptr<const CcnxNameComponents> &prefix) = 0;
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700117
118 /**
119 * @brief Invalidate all FIB entries
120 */
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700121 virtual void
122 InvalidateAll () = 0;
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700123
124 /**
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800125 * @brief Remove all references to a face from FIB. If for some enty that face was the only element,
126 * this FIB entry will be removed.
127 */
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700128 virtual void
129 RemoveFromAll (Ptr<CcnxFace> face) = 0;
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700130
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700131 /**
132 * @brief Print out entries in FIB
133 */
134 virtual void
135 Print (std::ostream &os) const = 0;
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700136
137 /**
138 * @brief Return first element of FIB (no order guaranteed)
139 */
140 virtual const_iterator
141 Begin () = 0;
142
143 /**
144 * @brief Return item next after last (no order guaranteed)
145 */
146 virtual const_iterator
147 End () = 0;
148
149 /**
150 * @brief Advance the iterator
151 */
152 virtual const_iterator
153 Next (const_iterator item) = 0;
154
155 static inline Ptr<CcnxFib>
156 GetCcnxFib (Ptr<Object> node);
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700157
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -0700158private:
159 friend std::ostream& operator<< (std::ostream& os, const CcnxFib &fib);
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -0700160 CcnxFib(const CcnxFib&) {} ; ///< \brief copy constructor is disabled
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -0700161};
162
163///////////////////////////////////////////////////////////////////////////////
164///////////////////////////////////////////////////////////////////////////////
165
166std::ostream& operator<< (std::ostream& os, const CcnxFib &fib);
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700167
168Ptr<CcnxFib>
169CcnxFib::GetCcnxFib (Ptr<Object> node)
170{
171 return node->GetObject<CcnxFib> ();
172}
173
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -0700174} // namespace ns3
175
176#endif /* NDN_FIB_H */