blob: d3b5c37d43c611e377b99250cf990e338a06ee58 [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 /**
Alexander Afanasyev042b4a72012-11-09 17:47:48 -080052 * @brief Helper function to retrieve logging name for the forwarding strategy
53 */
54 static std::string GetLogName ();
55
56 /**
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070057 * @brief Default constructor
58 */
59 ForwardingStrategy ();
60 virtual ~ForwardingStrategy ();
61
62 /**
63 * \brief Actual processing of incoming Ndn interests. Note, interests do not have payload
64 *
65 * Processing Interest packets
66 * @param face incoming face
67 * @param header deserialized Interest header
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070068 * @param origPacket original packet
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070069 */
70 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070071 OnInterest (Ptr<Face> face,
72 Ptr<const InterestHeader> header,
73 Ptr<const Packet> origPacket);
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070074
75 /**
76 * \brief Actual processing of incoming Ndn content objects
77 *
78 * Processing ContentObject packets
79 * @param face incoming face
80 * @param header deserialized ContentObject header
81 * @param payload data packet payload
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070082 * @param origPacket original packet
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070083 */
84 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070085 OnData (Ptr<Face> face,
86 Ptr<const ContentObjectHeader> header,
87 Ptr<Packet> payload,
88 Ptr<const Packet> origPacket);
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070089
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070090 /**
91 * @brief Event fired just before PIT entry is removed by timeout
92 * @param pitEntry PIT entry to be removed
93 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070094 virtual void
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070095 WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry);
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070096
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070097 /**
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070098 * @brief Event fired every time face is added to NDN stack
99 * @param face face to be removed
100 */
101 virtual void
102 AddFace (Ptr<Face> face);
103
104 /**
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700105 * @brief Event fired every time face is removed from NDN stack
106 * @param face face to be removed
107 *
108 * For example, when an application terminates, AppFace is removed and this method called by NDN stack.
109 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700110 virtual void
111 RemoveFace (Ptr<Face> face);
112
113protected:
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700114 /**
115 * @brief An event that is fired every time a new PIT entry is created
116 *
117 * Note that if NDN node is receiving a similar interest (interest for the same name),
118 * then either DidReceiveDuplicateInterest, DidSuppressSimilarInterest, or DidForwardSimilarInterest
119 * will be called
120 *
121 * Suppression of similar Interests is controlled using ShouldSuppressIncomingInterest virtual method
122 *
123 * @param inFace incoming face
124 * @param header deserialized Interest header
125 * @param origPacket original packet
126 * @param pitEntry created PIT entry (incoming and outgoing face sets are empty)
127 *
128 * @see DidReceiveDuplicateInterest, DidSuppressSimilarInterest, DidForwardSimilarInterest, ShouldSuppressIncomingInterest
129 */
130 virtual void
131 DidCreatePitEntry (Ptr<Face> inFace,
132 Ptr<const InterestHeader> header,
133 Ptr<const Packet> origPacket,
134 Ptr<pit::Entry> pitEntry);
135
136 /**
137 * @brief An event that is fired every time a new PIT entry cannot be created (e.g., PIT container imposes a limit)
138 *
139 * Note that this call can be called only for non-similar Interest (i.e., there is an attempt to create a new PIT entry).
140 * For any non-similar Interests, either FailedToCreatePitEntry or DidCreatePitEntry is called.
141 *
142 * @param inFace incoming face
143 * @param header deserialized Interest header
144 * @param origPacket original packet
145 */
146 virtual void
147 FailedToCreatePitEntry (Ptr<Face> inFace,
148 Ptr<const InterestHeader> header,
149 Ptr<const Packet> origPacket);
150
151 /**
152 * @brief An event that is fired every time a duplicated Interest is received
153 *
154 * This even is the last action that is performed before the Interest processing is halted
155 *
156 * @param inFace incoming face
157 * @param header deserialized Interest header
158 * @param origPacket original packet
159 * @param pitEntry an existing PIT entry, corresponding to the duplicated Interest
160 *
161 * @see DidReceiveDuplicateInterest, DidSuppressSimilarInterest, DidForwardSimilarInterest, ShouldSuppressIncomingInterest
162 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700163 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700164 DidReceiveDuplicateInterest (Ptr<Face> inFace,
165 Ptr<const InterestHeader> header,
166 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700167 Ptr<pit::Entry> pitEntry);
168
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700169 /**
170 * @brief An event that is fired every time when a similar Interest is received and suppressed (collapsed)
171 *
172 * This even is the last action that is performed before the Interest processing is halted
173 *
174 * @param inFace incoming face
175 * @param header deserialized Interest header
176 * @param origPacket original packet
177 * @param pitEntry an existing PIT entry, corresponding to the duplicated Interest
178 *
179 * @see DidReceiveDuplicateInterest, DidForwardSimilarInterest, ShouldSuppressIncomingInterest
180 */
181 virtual void
182 DidSuppressSimilarInterest (Ptr<Face> inFace,
183 Ptr<const InterestHeader> header,
184 Ptr<const Packet> origPacket,
185 Ptr<pit::Entry> pitEntry);
186
187 /**
188 * @brief An event that is fired every time when a similar Interest is received and further forwarded (not suppressed/collapsed)
189 *
190 * This even is fired just before handling the Interest to PropagateInterest method
191 *
192 * @param inFace incoming face
193 * @param header deserialized Interest header
194 * @param origPacket original packet
195 * @param pitEntry an existing PIT entry, corresponding to the duplicated Interest
196 *
197 * @see DidReceiveDuplicateInterest, DidSuppressSimilarInterest, ShouldSuppressIncomingInterest
198 */
199 virtual void
200 DidForwardSimilarInterest (Ptr<Face> inFace,
201 Ptr<const InterestHeader> header,
202 Ptr<const Packet> origPacket,
203 Ptr<pit::Entry> pitEntry);
204
205 /**
206 * @brief An even that is fired when Interest cannot be forwarded
207 *
208 * Note that the event will not fire if retransmission detection is enabled (by default)
209 * and retransmitted Interest cannot by forwarded. For more details, refer to the implementation.
210 *
211 * @param inFace incoming face
212 * @param header deserialized Interest header
213 * @param origPacket original packet
214 * @param pitEntry an existing PIT entry, corresponding to the duplicated Interest
215 *
216 * @see DetectRetransmittedInterest
217 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700218 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700219 DidExhaustForwardingOptions (Ptr<Face> inFace,
220 Ptr<const InterestHeader> header,
221 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700222 Ptr<pit::Entry> pitEntry);
223
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800224 /**
225 * @brief Method that implements logic to distinguish between new and retransmitted interest
226 *
227 * This method is called only when DetectRetransmissions attribute is set true (by default).
228 *
229 * Currently, the retransmission detection logic relies on the fact that list of incoming faces
230 * already has inFace (i.e., a similar interest is received on the same face more than once).
231 *
232 * @param inFace incoming face
233 * @param header deserialized Interest header
234 * @param origPacket original packet
235 * @param pitEntry an existing PIT entry, corresponding to the duplicated Interest
236 * @return true if Interest should be considered as retransmitted
237 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700238 virtual bool
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700239 DetectRetransmittedInterest (Ptr<Face> inFace,
240 Ptr<const InterestHeader> header,
241 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700242 Ptr<pit::Entry> pitEntry);
243
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800244 /**
245 * @brief Even fired just before Interest will be satisfied
246 *
247 * Note that when Interest is satisfied from the cache, incoming face will be 0
248 *
249 * @param inFace incoming face
250 * @param pitEntry an existing PIT entry, corresponding to the duplicated Interest
251 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700252 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700253 WillSatisfyPendingInterest (Ptr<Face> inFace,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700254 Ptr<pit::Entry> pitEntry);
255
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800256 /**
257 * @brief Actual procedure to satisfy Interest
258 *
259 * Note that when Interest is satisfied from the cache, incoming face will be 0
260 *
261 * @param inFace incoming face
262 * @param header deserialized ContentObject header
263 * @param payload ContentObject payload
264 * @param origPacket original packet
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 SatisfyPendingInterest (Ptr<Face> inFace, // 0 allowed (from cache)
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700269 Ptr<const ContentObjectHeader> header,
270 Ptr<const Packet> payload,
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700271 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700272 Ptr<pit::Entry> pitEntry);
273
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800274 /**
275 * @brief Event which is fired just after data was send out on the face
276 *
Alexander Afanasyev67f4a4a2012-11-24 17:18:17 -0800277 * @param inFace incoming face of the ContentObject
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800278 * @param outFace outgoing face
279 * @param header deserialized ContentObject header
280 * @param payload ContentObject payload
281 * @param origPacket original packet
282 * @param pitEntry an existing PIT entry, corresponding to the duplicated Interest
283 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700284 virtual void
Alexander Afanasyev67f4a4a2012-11-24 17:18:17 -0800285 DidSendOutData (Ptr<Face> inFace,
286 Ptr<Face> outFace,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700287 Ptr<const ContentObjectHeader> header,
288 Ptr<const Packet> payload,
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700289 Ptr<const Packet> origPacket,
290 Ptr<pit::Entry> pitEntry);
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800291
292 /**
293 * @brief Event which is fired every time an unsolicited DATA packet (no active PIT entry) is received
294 *
295 * The current implementation allows ignoring unsolicited DATA (by default), or cache it by setting
296 * attribute CacheUnsolicitedData true
297 *
298 * @param inFace incoming face
299 * @param header deserialized ContentObject header
300 * @param payload ContentObject payload
301 * @param origPacket original packet
302 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700303 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700304 DidReceiveUnsolicitedData (Ptr<Face> inFace,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700305 Ptr<const ContentObjectHeader> header,
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700306 Ptr<const Packet> payload,
307 Ptr<const Packet> origPacket);
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800308
309 /**
310 * @brief Method implementing logic to suppress (collapse) similar Interests
311 *
312 * In the base class implementation this method checks list of incoming/outgoing faces of the PIT entry
313 * (for new Intersets, both lists are empty before this call)
314 *
315 * For more details, refer to the source code.
316 *
317 * @param inFace incoming face
318 * @param header deserialized ContentObject header
319 * @param payload ContentObject payload
320 * @param origPacket original packet
321 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700322 virtual bool
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700323 ShouldSuppressIncomingInterest (Ptr<Face> inFace,
324 Ptr<const InterestHeader> header,
325 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700326 Ptr<pit::Entry> pitEntry);
327
328 /**
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800329 * @brief Method to check whether Interest can be send out on the particular face or not
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700330 *
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800331 * In the base class, this method perfoms two checks:
332 * 1. If inFace is equal to outFace (when equal, Interest forwarding is prohibited)
333 * 2. Whether Interest should be suppressed (list of outgoing faces include outFace),
334 * considering (if enabled) retransmission logic
335 *
336 * @param inFace incoming face of the Interest
337 * @param outFace proposed outgoing face of the Interest
338 * @param header parsed Interest header
339 * @param origPacket original Interest packet
340 * @param pitEntry reference to PIT entry (reference to corresponding FIB entry inside)
341 *
342 * @see DetectRetransmittedInterest
343 */
344 virtual bool
345 CanSendOutInterest (Ptr<Face> inFace,
346 Ptr<Face> outFace,
347 Ptr<const InterestHeader> header,
348 Ptr<const Packet> origPacket,
349 Ptr<pit::Entry> pitEntry);
350
351 /**
352 * @brief Method implementing actual interest forwarding, taking into account CanSendOutInterest decision
353 *
354 * If event returns false, then there is some kind of a problem exists
355 *
356 * @param inFace incoming face of the Interest
357 * @param outFace proposed outgoing face of the Interest
358 * @param header parsed Interest header
359 * @param origPacket original Interest packet
360 * @param pitEntry reference to PIT entry (reference to corresponding FIB entry inside)
361 *
362 * @see CanSendOutInterest
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700363 */
364 virtual bool
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700365 TrySendOutInterest (Ptr<Face> inFace,
366 Ptr<Face> outFace,
367 Ptr<const InterestHeader> header,
368 Ptr<const Packet> origPacket,
369 Ptr<pit::Entry> pitEntry);
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700370
371 /**
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800372 * @brief Event fired just after forwarding the Interest
373 *
Alexander Afanasyev67f4a4a2012-11-24 17:18:17 -0800374 * @param inFace incoming face of the Interest
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800375 * @param outFace outgoing face of the Interest
376 * @param header parsed Interest header
377 * @param origPacket original Interest packet
378 * @param pitEntry reference to PIT entry (reference to corresponding FIB entry inside)
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700379 */
380 virtual void
Alexander Afanasyev67f4a4a2012-11-24 17:18:17 -0800381 DidSendOutInterest (Ptr<Face> inFace,
382 Ptr<Face> outFace,
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700383 Ptr<const InterestHeader> header,
384 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700385 Ptr<pit::Entry> pitEntry);
386
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700387 /**
388 * @brief Wrapper method, which performs general tasks and calls DoPropagateInterest method
389 *
390 * General tasks so far are adding face to the list of incoming face, updating
391 * PIT entry lifetime, calling DoPropagateInterest, and retransmissions (enabled by default).
392 *
393 * @param inFace incoming face
394 * @param header Interest header
395 * @param origPacket original Interest packet
396 * @param pitEntry reference to PIT entry (reference to corresponding FIB entry inside)
397 *
398 * @see DoPropagateInterest
399 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700400 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700401 PropagateInterest (Ptr<Face> inFace,
402 Ptr<const InterestHeader> header,
403 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700404 Ptr<pit::Entry> pitEntry);
405
406 /**
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700407 * @brief Virtual method to perform Interest propagation according to the forwarding strategy logic
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700408 *
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700409 * In most cases, this is the call that needs to be implemented/re-implemented in order
410 * to perform forwarding of Interests according to the desired logic.
411 *
412 * There is also PropagateInterest method (generally, do not require to be overriden)
413 * which performs general tasks (adding face to the list of incoming face, updating
414 * PIT entry lifetime, calling DoPropagateInterest, as well as perform retransmissions (enabled by default).
415 *
416 * @param inFace incoming face
417 * @param header Interest header
418 * @param origPacket original Interest packet
419 * @param pitEntry reference to PIT entry (reference to corresponding FIB entry inside)
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700420 *
421 * @return true if interest was successfully propagated, false if all options have failed
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700422 *
423 * @see PropagateInterest
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700424 */
425 virtual bool
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700426 DoPropagateInterest (Ptr<Face> inFace,
427 Ptr<const InterestHeader> header,
428 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700429 Ptr<pit::Entry> pitEntry) = 0;
430
431protected:
432 // inherited from Object class
433 virtual void NotifyNewAggregate (); ///< @brief Even when object is aggregated to another Object
434 virtual void DoDispose (); ///< @brief Do cleanup
435
436protected:
437 Ptr<Pit> m_pit; ///< \brief Reference to PIT to which this forwarding strategy is associated
438 Ptr<Fib> m_fib; ///< \brief FIB
439 Ptr<ContentStore> m_contentStore; ///< \brief Content store (for caching purposes only)
440
441 bool m_cacheUnsolicitedData;
442 bool m_detectRetransmissions;
443
444 TracedCallback<Ptr<const InterestHeader>,
445 Ptr<const Face> > m_outInterests; ///< @brief Transmitted interests trace
446
447 TracedCallback<Ptr<const InterestHeader>,
448 Ptr<const Face> > m_inInterests; ///< @brief trace of incoming Interests
449
450 TracedCallback<Ptr<const InterestHeader>,
451 Ptr<const Face> > m_dropInterests; ///< @brief trace of dropped Interests
452
453 ////////////////////////////////////////////////////////////////////
454 ////////////////////////////////////////////////////////////////////
455 ////////////////////////////////////////////////////////////////////
456
457 TracedCallback<Ptr<const ContentObjectHeader>, Ptr<const Packet>,
458 bool /*from cache*/,
459 Ptr<const Face> > m_outData; ///< @brief trace of outgoing Data
460
461 TracedCallback<Ptr<const ContentObjectHeader>, Ptr<const Packet>,
462 Ptr<const Face> > m_inData; ///< @brief trace of incoming Data
463
464 TracedCallback<Ptr<const ContentObjectHeader>, Ptr<const Packet>,
465 Ptr<const Face> > m_dropData; ///< @brief trace of dropped Data
466};
467
468} // namespace ndn
469} // namespace ns3
470
471#endif /* NDN_FORWARDING_STRATEGY_H */