blob: 3f0a14716de4f9bcc556af16e1c168701b8ce8a7 [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 /**
93 * @brief Event fired every time face is removed from NDN stack
94 * @param face face to be removed
95 *
96 * For example, when an application terminates, AppFace is removed and this method called by NDN stack.
97 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070098 virtual void
99 RemoveFace (Ptr<Face> face);
100
101protected:
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700102 /**
103 * @brief An event that is fired every time a new PIT entry is created
104 *
105 * Note that if NDN node is receiving a similar interest (interest for the same name),
106 * then either DidReceiveDuplicateInterest, DidSuppressSimilarInterest, or DidForwardSimilarInterest
107 * will be called
108 *
109 * Suppression of similar Interests is controlled using ShouldSuppressIncomingInterest virtual method
110 *
111 * @param inFace incoming face
112 * @param header deserialized Interest header
113 * @param origPacket original packet
114 * @param pitEntry created PIT entry (incoming and outgoing face sets are empty)
115 *
116 * @see DidReceiveDuplicateInterest, DidSuppressSimilarInterest, DidForwardSimilarInterest, ShouldSuppressIncomingInterest
117 */
118 virtual void
119 DidCreatePitEntry (Ptr<Face> inFace,
120 Ptr<const InterestHeader> header,
121 Ptr<const Packet> origPacket,
122 Ptr<pit::Entry> pitEntry);
123
124 /**
125 * @brief An event that is fired every time a new PIT entry cannot be created (e.g., PIT container imposes a limit)
126 *
127 * Note that this call can be called only for non-similar Interest (i.e., there is an attempt to create a new PIT entry).
128 * For any non-similar Interests, either FailedToCreatePitEntry or DidCreatePitEntry is called.
129 *
130 * @param inFace incoming face
131 * @param header deserialized Interest header
132 * @param origPacket original packet
133 */
134 virtual void
135 FailedToCreatePitEntry (Ptr<Face> inFace,
136 Ptr<const InterestHeader> header,
137 Ptr<const Packet> origPacket);
138
139 /**
140 * @brief An event that is fired every time a duplicated Interest is received
141 *
142 * This even is the last action that is performed before the Interest processing is halted
143 *
144 * @param inFace incoming face
145 * @param header deserialized Interest header
146 * @param origPacket original packet
147 * @param pitEntry an existing PIT entry, corresponding to the duplicated Interest
148 *
149 * @see DidReceiveDuplicateInterest, DidSuppressSimilarInterest, DidForwardSimilarInterest, ShouldSuppressIncomingInterest
150 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700151 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700152 DidReceiveDuplicateInterest (Ptr<Face> inFace,
153 Ptr<const InterestHeader> header,
154 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700155 Ptr<pit::Entry> pitEntry);
156
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700157 /**
158 * @brief An event that is fired every time when a similar Interest is received and suppressed (collapsed)
159 *
160 * This even is the last action that is performed before the Interest processing is halted
161 *
162 * @param inFace incoming face
163 * @param header deserialized Interest header
164 * @param origPacket original packet
165 * @param pitEntry an existing PIT entry, corresponding to the duplicated Interest
166 *
167 * @see DidReceiveDuplicateInterest, DidForwardSimilarInterest, ShouldSuppressIncomingInterest
168 */
169 virtual void
170 DidSuppressSimilarInterest (Ptr<Face> inFace,
171 Ptr<const InterestHeader> header,
172 Ptr<const Packet> origPacket,
173 Ptr<pit::Entry> pitEntry);
174
175 /**
176 * @brief An event that is fired every time when a similar Interest is received and further forwarded (not suppressed/collapsed)
177 *
178 * This even is fired just before handling the Interest to PropagateInterest method
179 *
180 * @param inFace incoming face
181 * @param header deserialized Interest header
182 * @param origPacket original packet
183 * @param pitEntry an existing PIT entry, corresponding to the duplicated Interest
184 *
185 * @see DidReceiveDuplicateInterest, DidSuppressSimilarInterest, ShouldSuppressIncomingInterest
186 */
187 virtual void
188 DidForwardSimilarInterest (Ptr<Face> inFace,
189 Ptr<const InterestHeader> header,
190 Ptr<const Packet> origPacket,
191 Ptr<pit::Entry> pitEntry);
192
193 /**
194 * @brief An even that is fired when Interest cannot be forwarded
195 *
196 * Note that the event will not fire if retransmission detection is enabled (by default)
197 * and retransmitted Interest cannot by forwarded. For more details, refer to the implementation.
198 *
199 * @param inFace incoming face
200 * @param header deserialized Interest header
201 * @param origPacket original packet
202 * @param pitEntry an existing PIT entry, corresponding to the duplicated Interest
203 *
204 * @see DetectRetransmittedInterest
205 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700206 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700207 DidExhaustForwardingOptions (Ptr<Face> inFace,
208 Ptr<const InterestHeader> header,
209 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700210 Ptr<pit::Entry> pitEntry);
211
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700212 virtual bool
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700213 DetectRetransmittedInterest (Ptr<Face> inFace,
214 Ptr<const InterestHeader> header,
215 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700216 Ptr<pit::Entry> pitEntry);
217
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700218 // When Interest is satisfied from the cache, incoming face is 0
219 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700220 WillSatisfyPendingInterest (Ptr<Face> inFace,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700221 Ptr<pit::Entry> pitEntry);
222
223 // for data received both from network and cache
224 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700225 SatisfyPendingInterest (Ptr<Face> inFace, // 0 allowed (from cache)
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700226 Ptr<const ContentObjectHeader> header,
227 Ptr<const Packet> payload,
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700228 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700229 Ptr<pit::Entry> pitEntry);
230
231 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700232 DidSendOutData (Ptr<Face> inFace,
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,
236 Ptr<pit::Entry> pitEntry);
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700237
238 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700239 DidReceiveUnsolicitedData (Ptr<Face> inFace,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700240 Ptr<const ContentObjectHeader> header,
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700241 Ptr<const Packet> payload,
242 Ptr<const Packet> origPacket);
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700243
244 virtual bool
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700245 ShouldSuppressIncomingInterest (Ptr<Face> inFace,
246 Ptr<const InterestHeader> header,
247 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700248 Ptr<pit::Entry> pitEntry);
249
250 /**
251 * @brief Event fired before actually sending out an interest
252 *
253 * If event returns false, then there is some kind of a problem (e.g., per-face limit reached)
254 */
255 virtual bool
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700256 TrySendOutInterest (Ptr<Face> inFace,
257 Ptr<Face> outFace,
258 Ptr<const InterestHeader> header,
259 Ptr<const Packet> origPacket,
260 Ptr<pit::Entry> pitEntry);
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700261
262 /**
263 * @brief Event fired just after sending out an interest
264 */
265 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700266 DidSendOutInterest (Ptr<Face> outFace,
267 Ptr<const InterestHeader> header,
268 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700269 Ptr<pit::Entry> pitEntry);
270
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700271 /**
272 * @brief Wrapper method, which performs general tasks and calls DoPropagateInterest method
273 *
274 * General tasks so far are adding face to the list of incoming face, updating
275 * PIT entry lifetime, calling DoPropagateInterest, and retransmissions (enabled by default).
276 *
277 * @param inFace incoming face
278 * @param header Interest header
279 * @param origPacket original Interest packet
280 * @param pitEntry reference to PIT entry (reference to corresponding FIB entry inside)
281 *
282 * @see DoPropagateInterest
283 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700284 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700285 PropagateInterest (Ptr<Face> inFace,
286 Ptr<const InterestHeader> header,
287 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700288 Ptr<pit::Entry> pitEntry);
289
290 /**
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700291 * @brief Virtual method to perform Interest propagation according to the forwarding strategy logic
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700292 *
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700293 * In most cases, this is the call that needs to be implemented/re-implemented in order
294 * to perform forwarding of Interests according to the desired logic.
295 *
296 * There is also PropagateInterest method (generally, do not require to be overriden)
297 * which performs general tasks (adding face to the list of incoming face, updating
298 * PIT entry lifetime, calling DoPropagateInterest, as well as perform retransmissions (enabled by default).
299 *
300 * @param inFace incoming face
301 * @param header Interest header
302 * @param origPacket original Interest packet
303 * @param pitEntry reference to PIT entry (reference to corresponding FIB entry inside)
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700304 *
305 * @return true if interest was successfully propagated, false if all options have failed
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700306 *
307 * @see PropagateInterest
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700308 */
309 virtual bool
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700310 DoPropagateInterest (Ptr<Face> inFace,
311 Ptr<const InterestHeader> header,
312 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700313 Ptr<pit::Entry> pitEntry) = 0;
314
315protected:
316 // inherited from Object class
317 virtual void NotifyNewAggregate (); ///< @brief Even when object is aggregated to another Object
318 virtual void DoDispose (); ///< @brief Do cleanup
319
320protected:
321 Ptr<Pit> m_pit; ///< \brief Reference to PIT to which this forwarding strategy is associated
322 Ptr<Fib> m_fib; ///< \brief FIB
323 Ptr<ContentStore> m_contentStore; ///< \brief Content store (for caching purposes only)
324
325 bool m_cacheUnsolicitedData;
326 bool m_detectRetransmissions;
327
328 TracedCallback<Ptr<const InterestHeader>,
329 Ptr<const Face> > m_outInterests; ///< @brief Transmitted interests trace
330
331 TracedCallback<Ptr<const InterestHeader>,
332 Ptr<const Face> > m_inInterests; ///< @brief trace of incoming Interests
333
334 TracedCallback<Ptr<const InterestHeader>,
335 Ptr<const Face> > m_dropInterests; ///< @brief trace of dropped Interests
336
337 ////////////////////////////////////////////////////////////////////
338 ////////////////////////////////////////////////////////////////////
339 ////////////////////////////////////////////////////////////////////
340
341 TracedCallback<Ptr<const ContentObjectHeader>, Ptr<const Packet>,
342 bool /*from cache*/,
343 Ptr<const Face> > m_outData; ///< @brief trace of outgoing Data
344
345 TracedCallback<Ptr<const ContentObjectHeader>, Ptr<const Packet>,
346 Ptr<const Face> > m_inData; ///< @brief trace of incoming Data
347
348 TracedCallback<Ptr<const ContentObjectHeader>, Ptr<const Packet>,
349 Ptr<const Face> > m_dropData; ///< @brief trace of dropped Data
350};
351
352} // namespace ndn
353} // namespace ns3
354
355#endif /* NDN_FORWARDING_STRATEGY_H */