blob: 31fd2d8b3a6c826c504ae203c50eadf9deee21a4 [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
41 typedef ns3::Ptr<CcnxFibEntry> const_iterator;
42
43 /**
44 * @brief Default constructor
45 */
46 CcnxFib () {}
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -070047
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070048 /**
Alexander Afanasyev78057c32012-07-06 15:18:46 -070049 * @brief Virtual destructor
Alexander Afanasyevcf133f02011-09-06 12:13:48 -070050 */
Alexander Afanasyev78057c32012-07-06 15:18:46 -070051 virtual ~CcnxFib () { };
52
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070053 /**
54 * \brief Perform longest prefix match
55 *
56 * \todo Implement exclude filters
57 *
58 * \param interest Interest packet header
Alexander Afanasyev8accdf62011-09-20 11:33:59 -070059 * \returns If entry found a valid iterator will be returned, otherwise end ()
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070060 */
Alexander Afanasyev78057c32012-07-06 15:18:46 -070061 virtual iterator
62 LongestPrefixMatch (const CcnxInterestHeader &interest) const = 0;
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070063
64 /**
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070065 * \brief Add or update FIB entry
66 *
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070067 * If the entry exists, metric will be updated. Otherwise, new entry will be created
68 *
69 * Entries in FIB never deleted. They can be invalidated with metric==NETWORK_UNREACHABLE
70 *
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070071 * @param name Prefix
72 * @param face Forwarding face
73 * @param metric Routing metric
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070074 */
Alexander Afanasyev78057c32012-07-06 15:18:46 -070075 virtual iterator
76 Add (const CcnxNameComponents &prefix, Ptr<CcnxFace> face, int32_t metric) = 0;
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070077
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080078 /**
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -070079 * \brief Add or update FIB entry using smart pointer to prefix
80 *
81 * If the entry exists, metric will be updated. Otherwise, new entry will be created
82 *
83 * Entries in FIB never deleted. They can be invalidated with metric==NETWORK_UNREACHABLE
84 *
85 * @param name Smart pointer to prefix
86 * @param face Forwarding face
87 * @param metric Routing metric
88 */
Alexander Afanasyev78057c32012-07-06 15:18:46 -070089 virtual iterator
90 Add (const Ptr<const CcnxNameComponents> &prefix, Ptr<CcnxFace> face, int32_t metric) = 0;
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -070091
92 /**
93 * @brief Remove FIB entry
94 *
95 * ! ATTENTION ! Use with caution. All PIT entries referencing the corresponding FIB entry will become invalid.
96 * So, simulation may crash.
97 *
98 * @param name Smart pointer to prefix
99 */
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700100 virtual void
101 Remove (const Ptr<const CcnxNameComponents> &prefix) = 0;
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700102
103 /**
104 * @brief Invalidate FIB entry ("Safe" version of Remove)
105 *
106 * All faces for the entry will be assigned maximum routing metric and NDN_FIB_RED status
107 * @param name Smart pointer to prefix
108 */
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700109 virtual void
110 Invalidate (const Ptr<const CcnxNameComponents> &prefix) = 0;
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700111
112 /**
113 * @brief Invalidate all FIB entries
114 */
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700115 virtual void
116 InvalidateAll () = 0;
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700117
118 /**
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800119 * @brief Remove reference to a face from the entry. If entry had only this face, the whole
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800120 * entry will be removed
121 */
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700122 virtual void
123 Remove (const CcnxFibEntry &entry, Ptr<CcnxFace> face) = 0;
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800124
125 /**
126 * @brief Remove all references to a face from FIB. If for some enty that face was the only element,
127 * this FIB entry will be removed.
128 */
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700129 virtual void
130 RemoveFromAll (Ptr<CcnxFace> face) = 0;
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700131
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700132 /**
133 * @brief Print out entries in FIB
134 */
135 virtual void
136 Print (std::ostream &os) const = 0;
137
138 // /**
139 // * @brief Modify element in container
140 // */
141 // template<typename Modifier>
142 // virtual bool
143 // modify (iterator position, Modifier mod) = 0;
144 // // {
145 // // return this->m_fib.modify (position, mod);
146 // // }
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700147
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -0700148private:
149 friend std::ostream& operator<< (std::ostream& os, const CcnxFib &fib);
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -0700150 CcnxFib(const CcnxFib&) {} ; ///< \brief copy constructor is disabled
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -0700151};
152
153///////////////////////////////////////////////////////////////////////////////
154///////////////////////////////////////////////////////////////////////////////
155
156std::ostream& operator<< (std::ostream& os, const CcnxFib &fib);
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -0700157
158} // namespace ns3
159
160#endif /* NDN_FIB_H */