blob: b838565e52b795abafc9825ef4e9ec5298de4de6 [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;
Alexander Afanasyevadcccf42012-11-26 23:55:34 -080039namespace fib { class Entry; }
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070040class ContentStore;
41
42/**
43 * \ingroup ndn
44 * \brief Abstract base class for Ndn forwarding strategies
45 */
46class ForwardingStrategy :
47 public Object
48{
49public:
50 static TypeId GetTypeId (void);
51
52 /**
Alexander Afanasyev042b4a72012-11-09 17:47:48 -080053 * @brief Helper function to retrieve logging name for the forwarding strategy
54 */
55 static std::string GetLogName ();
56
57 /**
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070058 * @brief Default constructor
59 */
60 ForwardingStrategy ();
61 virtual ~ForwardingStrategy ();
62
63 /**
64 * \brief Actual processing of incoming Ndn interests. Note, interests do not have payload
65 *
66 * Processing Interest packets
67 * @param face incoming face
68 * @param header deserialized Interest header
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070069 * @param origPacket original packet
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070070 */
71 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070072 OnInterest (Ptr<Face> face,
73 Ptr<const InterestHeader> header,
74 Ptr<const Packet> origPacket);
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070075
76 /**
77 * \brief Actual processing of incoming Ndn content objects
78 *
79 * Processing ContentObject packets
80 * @param face incoming face
81 * @param header deserialized ContentObject header
82 * @param payload data packet payload
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070083 * @param origPacket original packet
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070084 */
85 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070086 OnData (Ptr<Face> face,
87 Ptr<const ContentObjectHeader> header,
88 Ptr<Packet> payload,
89 Ptr<const Packet> origPacket);
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070090
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070091 /**
92 * @brief Event fired just before PIT entry is removed by timeout
93 * @param pitEntry PIT entry to be removed
94 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070095 virtual void
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070096 WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry);
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070097
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070098 /**
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070099 * @brief Event fired every time face is added to NDN stack
100 * @param face face to be removed
101 */
102 virtual void
103 AddFace (Ptr<Face> face);
104
105 /**
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700106 * @brief Event fired every time face is removed from NDN stack
107 * @param face face to be removed
108 *
109 * For example, when an application terminates, AppFace is removed and this method called by NDN stack.
110 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700111 virtual void
112 RemoveFace (Ptr<Face> face);
Alexander Afanasyevadcccf42012-11-26 23:55:34 -0800113
114 /**
115 * @brief Event fired every time a FIB entry is added to FIB
116 * @param fibEntry FIB entry that was added
117 */
118 virtual void
119 DidAddFibEntry (Ptr<fib::Entry> fibEntry);
120
121 /**
122 * @brief Fired just before FIB entry will be removed from FIB
123 * @param fibEntry FIB entry that will be removed
124 */
125 virtual void
126 WillRemoveFibEntry (Ptr<fib::Entry> fibEntry);
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700127
128protected:
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700129 /**
130 * @brief An event that is fired every time a new PIT entry is created
131 *
132 * Note that if NDN node is receiving a similar interest (interest for the same name),
133 * then either DidReceiveDuplicateInterest, DidSuppressSimilarInterest, or DidForwardSimilarInterest
134 * will be called
135 *
136 * Suppression of similar Interests is controlled using ShouldSuppressIncomingInterest virtual method
137 *
138 * @param inFace incoming face
139 * @param header deserialized Interest header
140 * @param origPacket original packet
141 * @param pitEntry created PIT entry (incoming and outgoing face sets are empty)
142 *
143 * @see DidReceiveDuplicateInterest, DidSuppressSimilarInterest, DidForwardSimilarInterest, ShouldSuppressIncomingInterest
144 */
145 virtual void
146 DidCreatePitEntry (Ptr<Face> inFace,
147 Ptr<const InterestHeader> header,
148 Ptr<const Packet> origPacket,
149 Ptr<pit::Entry> pitEntry);
150
151 /**
152 * @brief An event that is fired every time a new PIT entry cannot be created (e.g., PIT container imposes a limit)
153 *
154 * Note that this call can be called only for non-similar Interest (i.e., there is an attempt to create a new PIT entry).
155 * For any non-similar Interests, either FailedToCreatePitEntry or DidCreatePitEntry is called.
156 *
157 * @param inFace incoming face
158 * @param header deserialized Interest header
159 * @param origPacket original packet
160 */
161 virtual void
162 FailedToCreatePitEntry (Ptr<Face> inFace,
163 Ptr<const InterestHeader> header,
164 Ptr<const Packet> origPacket);
165
166 /**
167 * @brief An event that is fired every time a duplicated Interest is received
168 *
169 * This even is the last action that is performed before the Interest processing is halted
170 *
171 * @param inFace incoming face
172 * @param header deserialized Interest header
173 * @param origPacket original packet
174 * @param pitEntry an existing PIT entry, corresponding to the duplicated Interest
175 *
176 * @see DidReceiveDuplicateInterest, DidSuppressSimilarInterest, DidForwardSimilarInterest, ShouldSuppressIncomingInterest
177 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700178 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700179 DidReceiveDuplicateInterest (Ptr<Face> inFace,
180 Ptr<const InterestHeader> header,
181 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700182 Ptr<pit::Entry> pitEntry);
183
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700184 /**
185 * @brief An event that is fired every time when a similar Interest is received and suppressed (collapsed)
186 *
187 * This even is the last action that is performed before the Interest processing is halted
188 *
189 * @param inFace incoming face
190 * @param header deserialized Interest header
191 * @param origPacket original packet
192 * @param pitEntry an existing PIT entry, corresponding to the duplicated Interest
193 *
194 * @see DidReceiveDuplicateInterest, DidForwardSimilarInterest, ShouldSuppressIncomingInterest
195 */
196 virtual void
197 DidSuppressSimilarInterest (Ptr<Face> inFace,
198 Ptr<const InterestHeader> header,
199 Ptr<const Packet> origPacket,
200 Ptr<pit::Entry> pitEntry);
201
202 /**
203 * @brief An event that is fired every time when a similar Interest is received and further forwarded (not suppressed/collapsed)
204 *
205 * This even is fired just before handling the Interest to PropagateInterest method
206 *
207 * @param inFace incoming face
208 * @param header deserialized Interest header
209 * @param origPacket original packet
210 * @param pitEntry an existing PIT entry, corresponding to the duplicated Interest
211 *
212 * @see DidReceiveDuplicateInterest, DidSuppressSimilarInterest, ShouldSuppressIncomingInterest
213 */
214 virtual void
215 DidForwardSimilarInterest (Ptr<Face> inFace,
216 Ptr<const InterestHeader> header,
217 Ptr<const Packet> origPacket,
218 Ptr<pit::Entry> pitEntry);
219
220 /**
221 * @brief An even that is fired when Interest cannot be forwarded
222 *
223 * Note that the event will not fire if retransmission detection is enabled (by default)
224 * and retransmitted Interest cannot by forwarded. For more details, refer to the implementation.
225 *
226 * @param inFace incoming face
227 * @param header deserialized Interest header
228 * @param origPacket original packet
229 * @param pitEntry an existing PIT entry, corresponding to the duplicated Interest
230 *
231 * @see DetectRetransmittedInterest
232 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700233 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700234 DidExhaustForwardingOptions (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 Method that implements logic to distinguish between new and retransmitted interest
241 *
242 * This method is called only when DetectRetransmissions attribute is set true (by default).
243 *
244 * Currently, the retransmission detection logic relies on the fact that list of incoming faces
245 * already has inFace (i.e., a similar interest is received on the same face more than once).
246 *
247 * @param inFace incoming face
248 * @param header deserialized Interest header
249 * @param origPacket original packet
250 * @param pitEntry an existing PIT entry, corresponding to the duplicated Interest
251 * @return true if Interest should be considered as retransmitted
252 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700253 virtual bool
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700254 DetectRetransmittedInterest (Ptr<Face> inFace,
255 Ptr<const InterestHeader> header,
256 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700257 Ptr<pit::Entry> pitEntry);
258
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800259 /**
260 * @brief Even fired just before Interest will be satisfied
261 *
262 * Note that when Interest is satisfied from the cache, incoming face will be 0
263 *
264 * @param inFace incoming face
265 * @param pitEntry an existing PIT entry, corresponding to the duplicated Interest
266 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700267 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700268 WillSatisfyPendingInterest (Ptr<Face> inFace,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700269 Ptr<pit::Entry> pitEntry);
270
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800271 /**
272 * @brief Actual procedure to satisfy Interest
273 *
274 * Note that when Interest is satisfied from the cache, incoming face will be 0
275 *
276 * @param inFace incoming face
277 * @param header deserialized ContentObject header
278 * @param payload ContentObject payload
279 * @param origPacket original packet
280 * @param pitEntry an existing PIT entry, corresponding to the duplicated Interest
281 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700282 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700283 SatisfyPendingInterest (Ptr<Face> inFace, // 0 allowed (from cache)
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700284 Ptr<const ContentObjectHeader> header,
285 Ptr<const Packet> payload,
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700286 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700287 Ptr<pit::Entry> pitEntry);
288
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800289 /**
290 * @brief Event which is fired just after data was send out on the face
291 *
Alexander Afanasyev67f4a4a2012-11-24 17:18:17 -0800292 * @param inFace incoming face of the ContentObject
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800293 * @param outFace outgoing face
294 * @param header deserialized ContentObject header
295 * @param payload ContentObject payload
296 * @param origPacket original packet
297 * @param pitEntry an existing PIT entry, corresponding to the duplicated Interest
298 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700299 virtual void
Alexander Afanasyev67f4a4a2012-11-24 17:18:17 -0800300 DidSendOutData (Ptr<Face> inFace,
301 Ptr<Face> outFace,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700302 Ptr<const ContentObjectHeader> header,
303 Ptr<const Packet> payload,
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700304 Ptr<const Packet> origPacket,
305 Ptr<pit::Entry> pitEntry);
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800306
307 /**
308 * @brief Event which is fired every time an unsolicited DATA packet (no active PIT entry) is received
309 *
310 * The current implementation allows ignoring unsolicited DATA (by default), or cache it by setting
311 * attribute CacheUnsolicitedData true
312 *
313 * @param inFace incoming face
314 * @param header deserialized ContentObject header
315 * @param payload ContentObject payload
316 * @param origPacket original packet
317 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700318 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700319 DidReceiveUnsolicitedData (Ptr<Face> inFace,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700320 Ptr<const ContentObjectHeader> header,
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700321 Ptr<const Packet> payload,
322 Ptr<const Packet> origPacket);
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800323
324 /**
325 * @brief Method implementing logic to suppress (collapse) similar Interests
326 *
327 * In the base class implementation this method checks list of incoming/outgoing faces of the PIT entry
328 * (for new Intersets, both lists are empty before this call)
329 *
330 * For more details, refer to the source code.
331 *
332 * @param inFace incoming face
333 * @param header deserialized ContentObject header
334 * @param payload ContentObject payload
335 * @param origPacket original packet
336 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700337 virtual bool
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700338 ShouldSuppressIncomingInterest (Ptr<Face> inFace,
339 Ptr<const InterestHeader> header,
340 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700341 Ptr<pit::Entry> pitEntry);
342
343 /**
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800344 * @brief Method to check whether Interest can be send out on the particular face or not
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700345 *
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800346 * In the base class, this method perfoms two checks:
347 * 1. If inFace is equal to outFace (when equal, Interest forwarding is prohibited)
348 * 2. Whether Interest should be suppressed (list of outgoing faces include outFace),
349 * considering (if enabled) retransmission logic
350 *
351 * @param inFace incoming face of the Interest
352 * @param outFace proposed outgoing face of the Interest
353 * @param header parsed Interest header
354 * @param origPacket original Interest packet
355 * @param pitEntry reference to PIT entry (reference to corresponding FIB entry inside)
356 *
357 * @see DetectRetransmittedInterest
358 */
359 virtual bool
360 CanSendOutInterest (Ptr<Face> inFace,
361 Ptr<Face> outFace,
362 Ptr<const InterestHeader> header,
363 Ptr<const Packet> origPacket,
364 Ptr<pit::Entry> pitEntry);
365
366 /**
367 * @brief Method implementing actual interest forwarding, taking into account CanSendOutInterest decision
368 *
369 * If event returns false, then there is some kind of a problem exists
370 *
371 * @param inFace incoming face of the Interest
372 * @param outFace proposed outgoing face of the Interest
373 * @param header parsed Interest header
374 * @param origPacket original Interest packet
375 * @param pitEntry reference to PIT entry (reference to corresponding FIB entry inside)
376 *
377 * @see CanSendOutInterest
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700378 */
379 virtual bool
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700380 TrySendOutInterest (Ptr<Face> inFace,
381 Ptr<Face> outFace,
382 Ptr<const InterestHeader> header,
383 Ptr<const Packet> origPacket,
384 Ptr<pit::Entry> pitEntry);
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700385
386 /**
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800387 * @brief Event fired just after forwarding the Interest
388 *
Alexander Afanasyev67f4a4a2012-11-24 17:18:17 -0800389 * @param inFace incoming face of the Interest
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800390 * @param outFace outgoing face of the Interest
391 * @param header parsed Interest header
392 * @param origPacket original Interest packet
393 * @param pitEntry reference to PIT entry (reference to corresponding FIB entry inside)
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700394 */
395 virtual void
Alexander Afanasyev67f4a4a2012-11-24 17:18:17 -0800396 DidSendOutInterest (Ptr<Face> inFace,
397 Ptr<Face> outFace,
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700398 Ptr<const InterestHeader> header,
399 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700400 Ptr<pit::Entry> pitEntry);
401
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700402 /**
403 * @brief Wrapper method, which performs general tasks and calls DoPropagateInterest method
404 *
405 * General tasks so far are adding face to the list of incoming face, updating
406 * PIT entry lifetime, calling DoPropagateInterest, and retransmissions (enabled by default).
407 *
408 * @param inFace incoming face
409 * @param header Interest header
410 * @param origPacket original Interest packet
411 * @param pitEntry reference to PIT entry (reference to corresponding FIB entry inside)
412 *
413 * @see DoPropagateInterest
414 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700415 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700416 PropagateInterest (Ptr<Face> inFace,
417 Ptr<const InterestHeader> header,
418 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700419 Ptr<pit::Entry> pitEntry);
420
421 /**
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700422 * @brief Virtual method to perform Interest propagation according to the forwarding strategy logic
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700423 *
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700424 * In most cases, this is the call that needs to be implemented/re-implemented in order
425 * to perform forwarding of Interests according to the desired logic.
426 *
427 * There is also PropagateInterest method (generally, do not require to be overriden)
428 * which performs general tasks (adding face to the list of incoming face, updating
429 * PIT entry lifetime, calling DoPropagateInterest, as well as perform retransmissions (enabled by default).
430 *
431 * @param inFace incoming face
432 * @param header Interest header
433 * @param origPacket original Interest packet
434 * @param pitEntry reference to PIT entry (reference to corresponding FIB entry inside)
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700435 *
436 * @return true if interest was successfully propagated, false if all options have failed
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700437 *
438 * @see PropagateInterest
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700439 */
440 virtual bool
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700441 DoPropagateInterest (Ptr<Face> inFace,
442 Ptr<const InterestHeader> header,
443 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700444 Ptr<pit::Entry> pitEntry) = 0;
445
446protected:
447 // inherited from Object class
448 virtual void NotifyNewAggregate (); ///< @brief Even when object is aggregated to another Object
449 virtual void DoDispose (); ///< @brief Do cleanup
450
451protected:
452 Ptr<Pit> m_pit; ///< \brief Reference to PIT to which this forwarding strategy is associated
453 Ptr<Fib> m_fib; ///< \brief FIB
454 Ptr<ContentStore> m_contentStore; ///< \brief Content store (for caching purposes only)
455
456 bool m_cacheUnsolicitedData;
457 bool m_detectRetransmissions;
458
459 TracedCallback<Ptr<const InterestHeader>,
460 Ptr<const Face> > m_outInterests; ///< @brief Transmitted interests trace
461
462 TracedCallback<Ptr<const InterestHeader>,
463 Ptr<const Face> > m_inInterests; ///< @brief trace of incoming Interests
464
465 TracedCallback<Ptr<const InterestHeader>,
466 Ptr<const Face> > m_dropInterests; ///< @brief trace of dropped Interests
467
468 ////////////////////////////////////////////////////////////////////
469 ////////////////////////////////////////////////////////////////////
470 ////////////////////////////////////////////////////////////////////
471
472 TracedCallback<Ptr<const ContentObjectHeader>, Ptr<const Packet>,
473 bool /*from cache*/,
474 Ptr<const Face> > m_outData; ///< @brief trace of outgoing Data
475
476 TracedCallback<Ptr<const ContentObjectHeader>, Ptr<const Packet>,
477 Ptr<const Face> > m_inData; ///< @brief trace of incoming Data
478
479 TracedCallback<Ptr<const ContentObjectHeader>, Ptr<const Packet>,
480 Ptr<const Face> > m_dropData; ///< @brief trace of dropped Data
481};
482
483} // namespace ndn
484} // namespace ns3
485
486#endif /* NDN_FORWARDING_STRATEGY_H */