blob: fa42502624238ba8f674b4c154b900101910fa5c [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 Afanasyevdb15acb2012-11-09 14:16:27 -0800219 /**
220 * @brief Method that implements logic to distinguish between new and retransmitted interest
221 *
222 * This method is called only when DetectRetransmissions attribute is set true (by default).
223 *
224 * Currently, the retransmission detection logic relies on the fact that list of incoming faces
225 * already has inFace (i.e., a similar interest is received on the same face more than once).
226 *
227 * @param inFace incoming face
228 * @param header deserialized Interest header
229 * @param origPacket original packet
230 * @param pitEntry an existing PIT entry, corresponding to the duplicated Interest
231 * @return true if Interest should be considered as retransmitted
232 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700233 virtual bool
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700234 DetectRetransmittedInterest (Ptr<Face> inFace,
235 Ptr<const InterestHeader> header,
236 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700237 Ptr<pit::Entry> pitEntry);
238
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800239 /**
240 * @brief Even fired just before Interest will be satisfied
241 *
242 * Note that when Interest is satisfied from the cache, incoming face will be 0
243 *
244 * @param inFace incoming face
245 * @param pitEntry an existing PIT entry, corresponding to the duplicated Interest
246 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700247 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700248 WillSatisfyPendingInterest (Ptr<Face> inFace,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700249 Ptr<pit::Entry> pitEntry);
250
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800251 /**
252 * @brief Actual procedure to satisfy Interest
253 *
254 * Note that when Interest is satisfied from the cache, incoming face will be 0
255 *
256 * @param inFace incoming face
257 * @param header deserialized ContentObject header
258 * @param payload ContentObject payload
259 * @param origPacket original packet
260 * @param pitEntry an existing PIT entry, corresponding to the duplicated Interest
261 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700262 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700263 SatisfyPendingInterest (Ptr<Face> inFace, // 0 allowed (from cache)
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700264 Ptr<const ContentObjectHeader> header,
265 Ptr<const Packet> payload,
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700266 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700267 Ptr<pit::Entry> pitEntry);
268
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800269 /**
270 * @brief Event which is fired just after data was send out on the face
271 *
272 * @param outFace outgoing face
273 * @param header deserialized ContentObject header
274 * @param payload ContentObject payload
275 * @param origPacket original packet
276 * @param pitEntry an existing PIT entry, corresponding to the duplicated Interest
277 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700278 virtual void
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800279 DidSendOutData (Ptr<Face> outFace,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700280 Ptr<const ContentObjectHeader> header,
281 Ptr<const Packet> payload,
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700282 Ptr<const Packet> origPacket,
283 Ptr<pit::Entry> pitEntry);
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800284
285 /**
286 * @brief Event which is fired every time an unsolicited DATA packet (no active PIT entry) is received
287 *
288 * The current implementation allows ignoring unsolicited DATA (by default), or cache it by setting
289 * attribute CacheUnsolicitedData true
290 *
291 * @param inFace incoming face
292 * @param header deserialized ContentObject header
293 * @param payload ContentObject payload
294 * @param origPacket original packet
295 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700296 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700297 DidReceiveUnsolicitedData (Ptr<Face> inFace,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700298 Ptr<const ContentObjectHeader> header,
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700299 Ptr<const Packet> payload,
300 Ptr<const Packet> origPacket);
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800301
302 /**
303 * @brief Method implementing logic to suppress (collapse) similar Interests
304 *
305 * In the base class implementation this method checks list of incoming/outgoing faces of the PIT entry
306 * (for new Intersets, both lists are empty before this call)
307 *
308 * For more details, refer to the source code.
309 *
310 * @param inFace incoming face
311 * @param header deserialized ContentObject header
312 * @param payload ContentObject payload
313 * @param origPacket original packet
314 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700315 virtual bool
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700316 ShouldSuppressIncomingInterest (Ptr<Face> inFace,
317 Ptr<const InterestHeader> header,
318 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700319 Ptr<pit::Entry> pitEntry);
320
321 /**
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800322 * @brief Method to check whether Interest can be send out on the particular face or not
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700323 *
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800324 * In the base class, this method perfoms two checks:
325 * 1. If inFace is equal to outFace (when equal, Interest forwarding is prohibited)
326 * 2. Whether Interest should be suppressed (list of outgoing faces include outFace),
327 * considering (if enabled) retransmission logic
328 *
329 * @param inFace incoming face of the Interest
330 * @param outFace proposed outgoing face of the Interest
331 * @param header parsed Interest header
332 * @param origPacket original Interest packet
333 * @param pitEntry reference to PIT entry (reference to corresponding FIB entry inside)
334 *
335 * @see DetectRetransmittedInterest
336 */
337 virtual bool
338 CanSendOutInterest (Ptr<Face> inFace,
339 Ptr<Face> outFace,
340 Ptr<const InterestHeader> header,
341 Ptr<const Packet> origPacket,
342 Ptr<pit::Entry> pitEntry);
343
344 /**
345 * @brief Method implementing actual interest forwarding, taking into account CanSendOutInterest decision
346 *
347 * If event returns false, then there is some kind of a problem exists
348 *
349 * @param inFace incoming face of the Interest
350 * @param outFace proposed outgoing face of the Interest
351 * @param header parsed Interest header
352 * @param origPacket original Interest packet
353 * @param pitEntry reference to PIT entry (reference to corresponding FIB entry inside)
354 *
355 * @see CanSendOutInterest
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700356 */
357 virtual bool
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700358 TrySendOutInterest (Ptr<Face> inFace,
359 Ptr<Face> outFace,
360 Ptr<const InterestHeader> header,
361 Ptr<const Packet> origPacket,
362 Ptr<pit::Entry> pitEntry);
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700363
364 /**
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800365 * @brief Event fired just after forwarding the Interest
366 *
367 * @param outFace outgoing face of the Interest
368 * @param header parsed Interest header
369 * @param origPacket original Interest packet
370 * @param pitEntry reference to PIT entry (reference to corresponding FIB entry inside)
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700371 */
372 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700373 DidSendOutInterest (Ptr<Face> outFace,
374 Ptr<const InterestHeader> header,
375 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700376 Ptr<pit::Entry> pitEntry);
377
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700378 /**
379 * @brief Wrapper method, which performs general tasks and calls DoPropagateInterest method
380 *
381 * General tasks so far are adding face to the list of incoming face, updating
382 * PIT entry lifetime, calling DoPropagateInterest, and retransmissions (enabled by default).
383 *
384 * @param inFace incoming face
385 * @param header Interest header
386 * @param origPacket original Interest packet
387 * @param pitEntry reference to PIT entry (reference to corresponding FIB entry inside)
388 *
389 * @see DoPropagateInterest
390 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700391 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700392 PropagateInterest (Ptr<Face> inFace,
393 Ptr<const InterestHeader> header,
394 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700395 Ptr<pit::Entry> pitEntry);
396
397 /**
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700398 * @brief Virtual method to perform Interest propagation according to the forwarding strategy logic
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700399 *
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700400 * In most cases, this is the call that needs to be implemented/re-implemented in order
401 * to perform forwarding of Interests according to the desired logic.
402 *
403 * There is also PropagateInterest method (generally, do not require to be overriden)
404 * which performs general tasks (adding face to the list of incoming face, updating
405 * PIT entry lifetime, calling DoPropagateInterest, as well as perform retransmissions (enabled by default).
406 *
407 * @param inFace incoming face
408 * @param header Interest header
409 * @param origPacket original Interest packet
410 * @param pitEntry reference to PIT entry (reference to corresponding FIB entry inside)
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700411 *
412 * @return true if interest was successfully propagated, false if all options have failed
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700413 *
414 * @see PropagateInterest
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700415 */
416 virtual bool
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700417 DoPropagateInterest (Ptr<Face> inFace,
418 Ptr<const InterestHeader> header,
419 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700420 Ptr<pit::Entry> pitEntry) = 0;
421
422protected:
423 // inherited from Object class
424 virtual void NotifyNewAggregate (); ///< @brief Even when object is aggregated to another Object
425 virtual void DoDispose (); ///< @brief Do cleanup
426
427protected:
428 Ptr<Pit> m_pit; ///< \brief Reference to PIT to which this forwarding strategy is associated
429 Ptr<Fib> m_fib; ///< \brief FIB
430 Ptr<ContentStore> m_contentStore; ///< \brief Content store (for caching purposes only)
431
432 bool m_cacheUnsolicitedData;
433 bool m_detectRetransmissions;
434
435 TracedCallback<Ptr<const InterestHeader>,
436 Ptr<const Face> > m_outInterests; ///< @brief Transmitted interests trace
437
438 TracedCallback<Ptr<const InterestHeader>,
439 Ptr<const Face> > m_inInterests; ///< @brief trace of incoming Interests
440
441 TracedCallback<Ptr<const InterestHeader>,
442 Ptr<const Face> > m_dropInterests; ///< @brief trace of dropped Interests
443
444 ////////////////////////////////////////////////////////////////////
445 ////////////////////////////////////////////////////////////////////
446 ////////////////////////////////////////////////////////////////////
447
448 TracedCallback<Ptr<const ContentObjectHeader>, Ptr<const Packet>,
449 bool /*from cache*/,
450 Ptr<const Face> > m_outData; ///< @brief trace of outgoing Data
451
452 TracedCallback<Ptr<const ContentObjectHeader>, Ptr<const Packet>,
453 Ptr<const Face> > m_inData; ///< @brief trace of incoming Data
454
455 TracedCallback<Ptr<const ContentObjectHeader>, Ptr<const Packet>,
456 Ptr<const Face> > m_dropData; ///< @brief trace of dropped Data
457};
458
459} // namespace ndn
460} // namespace ns3
461
462#endif /* NDN_FORWARDING_STRATEGY_H */