blob: fbf2295ce5b5196a19558dc6dde468830b1af833 [file] [log] [blame]
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -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>
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070019 */
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070020
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070021#ifndef NDN_FORWARDING_STRATEGY_H
22#define NDN_FORWARDING_STRATEGY_H
23
24#include "ns3/packet.h"
25#include "ns3/callback.h"
26#include "ns3/object.h"
27#include "ns3/traced-callback.h"
28
29namespace ns3 {
30namespace ndn {
31
32class Face;
33class InterestHeader;
34class ContentObjectHeader;
35class Pit;
36namespace pit { class Entry; }
37class FibFaceMetric;
38class Fib;
39class ContentStore;
40
41/**
42 * \ingroup ndn
43 * \brief Abstract base class for Ndn forwarding strategies
44 */
45class ForwardingStrategy :
46 public Object
47{
48public:
49 static TypeId GetTypeId (void);
50
51 /**
52 * @brief Default constructor
53 */
54 ForwardingStrategy ();
55 virtual ~ForwardingStrategy ();
56
57 /**
58 * \brief Actual processing of incoming Ndn interests. Note, interests do not have payload
59 *
60 * Processing Interest packets
61 * @param face incoming face
62 * @param header deserialized Interest header
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070063 * @param origPacket original packet
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070064 */
65 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070066 OnInterest (Ptr<Face> face,
67 Ptr<const InterestHeader> header,
68 Ptr<const Packet> origPacket);
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070069
70 /**
71 * \brief Actual processing of incoming Ndn content objects
72 *
73 * Processing ContentObject packets
74 * @param face incoming face
75 * @param header deserialized ContentObject header
76 * @param payload data packet payload
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070077 * @param origPacket original packet
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070078 */
79 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070080 OnData (Ptr<Face> face,
81 Ptr<const ContentObjectHeader> header,
82 Ptr<Packet> payload,
83 Ptr<const Packet> origPacket);
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070084
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070085 /**
86 * @brief Event fired just before PIT entry is removed by timeout
87 * @param pitEntry PIT entry to be removed
88 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070089 virtual void
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070090 WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry);
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070091
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070092 /**
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070093 * @brief Event fired every time face is added to NDN stack
94 * @param face face to be removed
95 */
96 virtual void
97 AddFace (Ptr<Face> face);
98
99 /**
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700100 * @brief Event fired every time face is removed from NDN stack
101 * @param face face to be removed
102 *
103 * For example, when an application terminates, AppFace is removed and this method called by NDN stack.
104 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700105 virtual void
106 RemoveFace (Ptr<Face> face);
107
108protected:
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700109 /**
110 * @brief An event that is fired every time a new PIT entry is created
111 *
112 * Note that if NDN node is receiving a similar interest (interest for the same name),
113 * then either DidReceiveDuplicateInterest, DidSuppressSimilarInterest, or DidForwardSimilarInterest
114 * will be called
115 *
116 * Suppression of similar Interests is controlled using ShouldSuppressIncomingInterest virtual method
117 *
118 * @param inFace incoming face
119 * @param header deserialized Interest header
120 * @param origPacket original packet
121 * @param pitEntry created PIT entry (incoming and outgoing face sets are empty)
122 *
123 * @see DidReceiveDuplicateInterest, DidSuppressSimilarInterest, DidForwardSimilarInterest, ShouldSuppressIncomingInterest
124 */
125 virtual void
126 DidCreatePitEntry (Ptr<Face> inFace,
127 Ptr<const InterestHeader> header,
128 Ptr<const Packet> origPacket,
129 Ptr<pit::Entry> pitEntry);
130
131 /**
132 * @brief An event that is fired every time a new PIT entry cannot be created (e.g., PIT container imposes a limit)
133 *
134 * Note that this call can be called only for non-similar Interest (i.e., there is an attempt to create a new PIT entry).
135 * For any non-similar Interests, either FailedToCreatePitEntry or DidCreatePitEntry is called.
136 *
137 * @param inFace incoming face
138 * @param header deserialized Interest header
139 * @param origPacket original packet
140 */
141 virtual void
142 FailedToCreatePitEntry (Ptr<Face> inFace,
143 Ptr<const InterestHeader> header,
144 Ptr<const Packet> origPacket);
145
146 /**
147 * @brief An event that is fired every time a duplicated Interest is received
148 *
149 * This even is the last action that is performed before the Interest processing is halted
150 *
151 * @param inFace incoming face
152 * @param header deserialized Interest header
153 * @param origPacket original packet
154 * @param pitEntry an existing PIT entry, corresponding to the duplicated Interest
155 *
156 * @see DidReceiveDuplicateInterest, DidSuppressSimilarInterest, DidForwardSimilarInterest, ShouldSuppressIncomingInterest
157 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700158 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700159 DidReceiveDuplicateInterest (Ptr<Face> inFace,
160 Ptr<const InterestHeader> header,
161 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700162 Ptr<pit::Entry> pitEntry);
163
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700164 /**
165 * @brief An event that is fired every time when a similar Interest is received and suppressed (collapsed)
166 *
167 * This even is the last action that is performed before the Interest processing is halted
168 *
169 * @param inFace incoming face
170 * @param header deserialized Interest header
171 * @param origPacket original packet
172 * @param pitEntry an existing PIT entry, corresponding to the duplicated Interest
173 *
174 * @see DidReceiveDuplicateInterest, DidForwardSimilarInterest, ShouldSuppressIncomingInterest
175 */
176 virtual void
177 DidSuppressSimilarInterest (Ptr<Face> inFace,
178 Ptr<const InterestHeader> header,
179 Ptr<const Packet> origPacket,
180 Ptr<pit::Entry> pitEntry);
181
182 /**
183 * @brief An event that is fired every time when a similar Interest is received and further forwarded (not suppressed/collapsed)
184 *
185 * This even is fired just before handling the Interest to PropagateInterest method
186 *
187 * @param inFace incoming face
188 * @param header deserialized Interest header
189 * @param origPacket original packet
190 * @param pitEntry an existing PIT entry, corresponding to the duplicated Interest
191 *
192 * @see DidReceiveDuplicateInterest, DidSuppressSimilarInterest, ShouldSuppressIncomingInterest
193 */
194 virtual void
195 DidForwardSimilarInterest (Ptr<Face> inFace,
196 Ptr<const InterestHeader> header,
197 Ptr<const Packet> origPacket,
198 Ptr<pit::Entry> pitEntry);
199
200 /**
201 * @brief An even that is fired when Interest cannot be forwarded
202 *
203 * Note that the event will not fire if retransmission detection is enabled (by default)
204 * and retransmitted Interest cannot by forwarded. For more details, refer to the implementation.
205 *
206 * @param inFace incoming face
207 * @param header deserialized Interest header
208 * @param origPacket original packet
209 * @param pitEntry an existing PIT entry, corresponding to the duplicated Interest
210 *
211 * @see DetectRetransmittedInterest
212 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700213 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700214 DidExhaustForwardingOptions (Ptr<Face> inFace,
215 Ptr<const InterestHeader> header,
216 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700217 Ptr<pit::Entry> pitEntry);
218
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700219 virtual bool
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700220 DetectRetransmittedInterest (Ptr<Face> inFace,
221 Ptr<const InterestHeader> header,
222 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700223 Ptr<pit::Entry> pitEntry);
224
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700225 // When Interest is satisfied from the cache, incoming face is 0
226 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700227 WillSatisfyPendingInterest (Ptr<Face> inFace,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700228 Ptr<pit::Entry> pitEntry);
229
230 // for data received both from network and cache
231 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700232 SatisfyPendingInterest (Ptr<Face> inFace, // 0 allowed (from cache)
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700233 Ptr<const ContentObjectHeader> header,
234 Ptr<const Packet> payload,
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700235 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700236 Ptr<pit::Entry> pitEntry);
237
238 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700239 DidSendOutData (Ptr<Face> inFace,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700240 Ptr<const ContentObjectHeader> header,
241 Ptr<const Packet> payload,
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700242 Ptr<const Packet> origPacket,
243 Ptr<pit::Entry> pitEntry);
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700244
245 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700246 DidReceiveUnsolicitedData (Ptr<Face> inFace,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700247 Ptr<const ContentObjectHeader> header,
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700248 Ptr<const Packet> payload,
249 Ptr<const Packet> origPacket);
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700250
251 virtual bool
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700252 ShouldSuppressIncomingInterest (Ptr<Face> inFace,
253 Ptr<const InterestHeader> header,
254 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700255 Ptr<pit::Entry> pitEntry);
256
257 /**
258 * @brief Event fired before actually sending out an interest
259 *
260 * If event returns false, then there is some kind of a problem (e.g., per-face limit reached)
261 */
262 virtual bool
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700263 TrySendOutInterest (Ptr<Face> inFace,
264 Ptr<Face> outFace,
265 Ptr<const InterestHeader> header,
266 Ptr<const Packet> origPacket,
267 Ptr<pit::Entry> pitEntry);
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700268
269 /**
270 * @brief Event fired just after sending out an interest
271 */
272 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700273 DidSendOutInterest (Ptr<Face> outFace,
274 Ptr<const InterestHeader> header,
275 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700276 Ptr<pit::Entry> pitEntry);
277
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700278 /**
279 * @brief Wrapper method, which performs general tasks and calls DoPropagateInterest method
280 *
281 * General tasks so far are adding face to the list of incoming face, updating
282 * PIT entry lifetime, calling DoPropagateInterest, and retransmissions (enabled by default).
283 *
284 * @param inFace incoming face
285 * @param header Interest header
286 * @param origPacket original Interest packet
287 * @param pitEntry reference to PIT entry (reference to corresponding FIB entry inside)
288 *
289 * @see DoPropagateInterest
290 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700291 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700292 PropagateInterest (Ptr<Face> inFace,
293 Ptr<const InterestHeader> header,
294 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700295 Ptr<pit::Entry> pitEntry);
296
297 /**
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700298 * @brief Virtual method to perform Interest propagation according to the forwarding strategy logic
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700299 *
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700300 * In most cases, this is the call that needs to be implemented/re-implemented in order
301 * to perform forwarding of Interests according to the desired logic.
302 *
303 * There is also PropagateInterest method (generally, do not require to be overriden)
304 * which performs general tasks (adding face to the list of incoming face, updating
305 * PIT entry lifetime, calling DoPropagateInterest, as well as perform retransmissions (enabled by default).
306 *
307 * @param inFace incoming face
308 * @param header Interest header
309 * @param origPacket original Interest packet
310 * @param pitEntry reference to PIT entry (reference to corresponding FIB entry inside)
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700311 *
312 * @return true if interest was successfully propagated, false if all options have failed
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700313 *
314 * @see PropagateInterest
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700315 */
316 virtual bool
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700317 DoPropagateInterest (Ptr<Face> inFace,
318 Ptr<const InterestHeader> header,
319 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700320 Ptr<pit::Entry> pitEntry) = 0;
321
322protected:
323 // inherited from Object class
324 virtual void NotifyNewAggregate (); ///< @brief Even when object is aggregated to another Object
325 virtual void DoDispose (); ///< @brief Do cleanup
326
327protected:
328 Ptr<Pit> m_pit; ///< \brief Reference to PIT to which this forwarding strategy is associated
329 Ptr<Fib> m_fib; ///< \brief FIB
330 Ptr<ContentStore> m_contentStore; ///< \brief Content store (for caching purposes only)
331
332 bool m_cacheUnsolicitedData;
333 bool m_detectRetransmissions;
334
335 TracedCallback<Ptr<const InterestHeader>,
336 Ptr<const Face> > m_outInterests; ///< @brief Transmitted interests trace
337
338 TracedCallback<Ptr<const InterestHeader>,
339 Ptr<const Face> > m_inInterests; ///< @brief trace of incoming Interests
340
341 TracedCallback<Ptr<const InterestHeader>,
342 Ptr<const Face> > m_dropInterests; ///< @brief trace of dropped Interests
343
344 ////////////////////////////////////////////////////////////////////
345 ////////////////////////////////////////////////////////////////////
346 ////////////////////////////////////////////////////////////////////
347
348 TracedCallback<Ptr<const ContentObjectHeader>, Ptr<const Packet>,
349 bool /*from cache*/,
350 Ptr<const Face> > m_outData; ///< @brief trace of outgoing Data
351
352 TracedCallback<Ptr<const ContentObjectHeader>, Ptr<const Packet>,
353 Ptr<const Face> > m_inData; ///< @brief trace of incoming Data
354
355 TracedCallback<Ptr<const ContentObjectHeader>, Ptr<const Packet>,
356 Ptr<const Face> > m_dropData; ///< @brief trace of dropped Data
357};
358
359} // namespace ndn
360} // namespace ns3
361
362#endif /* NDN_FORWARDING_STRATEGY_H */