blob: f164d7fbf8b8831b929e4ca590983173f8e9dd9b [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:
102 // events
103 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700104 DidReceiveDuplicateInterest (Ptr<Face> inFace,
105 Ptr<const InterestHeader> header,
106 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700107 Ptr<pit::Entry> pitEntry);
108
109 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700110 DidExhaustForwardingOptions (Ptr<Face> inFace,
111 Ptr<const InterestHeader> header,
112 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700113 Ptr<pit::Entry> pitEntry);
114
115 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700116 FailedToCreatePitEntry (Ptr<Face> inFace,
117 Ptr<const InterestHeader> header,
118 Ptr<const Packet> origPacket);
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700119
120 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700121 DidCreatePitEntry (Ptr<Face> inFace,
122 Ptr<const InterestHeader> header,
123 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700124 Ptr<pit::Entry> pitEntry);
125
126 virtual bool
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700127 DetectRetransmittedInterest (Ptr<Face> inFace,
128 Ptr<const InterestHeader> header,
129 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700130 Ptr<pit::Entry> pitEntry);
131
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700132 // When Interest is satisfied from the cache, incoming face is 0
133 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700134 WillSatisfyPendingInterest (Ptr<Face> inFace,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700135 Ptr<pit::Entry> pitEntry);
136
137 // for data received both from network and cache
138 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700139 SatisfyPendingInterest (Ptr<Face> inFace, // 0 allowed (from cache)
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700140 Ptr<const ContentObjectHeader> header,
141 Ptr<const Packet> payload,
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700142 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700143 Ptr<pit::Entry> pitEntry);
144
145 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700146 DidSendOutData (Ptr<Face> inFace,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700147 Ptr<const ContentObjectHeader> header,
148 Ptr<const Packet> payload,
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700149 Ptr<const Packet> origPacket,
150 Ptr<pit::Entry> pitEntry);
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700151
152 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700153 DidReceiveUnsolicitedData (Ptr<Face> inFace,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700154 Ptr<const ContentObjectHeader> header,
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700155 Ptr<const Packet> payload,
156 Ptr<const Packet> origPacket);
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700157
158 virtual bool
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700159 ShouldSuppressIncomingInterest (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
164 /**
165 * @brief Event fired before actually sending out an interest
166 *
167 * If event returns false, then there is some kind of a problem (e.g., per-face limit reached)
168 */
169 virtual bool
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700170 TrySendOutInterest (Ptr<Face> inFace,
171 Ptr<Face> outFace,
172 Ptr<const InterestHeader> header,
173 Ptr<const Packet> origPacket,
174 Ptr<pit::Entry> pitEntry);
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700175
176 /**
177 * @brief Event fired just after sending out an interest
178 */
179 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700180 DidSendOutInterest (Ptr<Face> outFace,
181 Ptr<const InterestHeader> header,
182 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700183 Ptr<pit::Entry> pitEntry);
184
185 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700186 PropagateInterest (Ptr<Face> inFace,
187 Ptr<const InterestHeader> header,
188 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700189 Ptr<pit::Entry> pitEntry);
190
191 /**
192 * @brief Base method to propagate the interest according to the forwarding strategy
193 *
194 * @param pitEntry Reference to PIT entry (reference to corresponding FIB entry inside)
195 * @param incomingFace Incoming face
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700196 * @param header Interest header
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700197 * @param packet Original Interest packet
198 * @param sendCallback Send callback
199 *
200 * @return true if interest was successfully propagated, false if all options have failed
201 */
202 virtual bool
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700203 DoPropagateInterest (Ptr<Face> inFace,
204 Ptr<const InterestHeader> header,
205 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700206 Ptr<pit::Entry> pitEntry) = 0;
207
208protected:
209 // inherited from Object class
210 virtual void NotifyNewAggregate (); ///< @brief Even when object is aggregated to another Object
211 virtual void DoDispose (); ///< @brief Do cleanup
212
213protected:
214 Ptr<Pit> m_pit; ///< \brief Reference to PIT to which this forwarding strategy is associated
215 Ptr<Fib> m_fib; ///< \brief FIB
216 Ptr<ContentStore> m_contentStore; ///< \brief Content store (for caching purposes only)
217
218 bool m_cacheUnsolicitedData;
219 bool m_detectRetransmissions;
220
221 TracedCallback<Ptr<const InterestHeader>,
222 Ptr<const Face> > m_outInterests; ///< @brief Transmitted interests trace
223
224 TracedCallback<Ptr<const InterestHeader>,
225 Ptr<const Face> > m_inInterests; ///< @brief trace of incoming Interests
226
227 TracedCallback<Ptr<const InterestHeader>,
228 Ptr<const Face> > m_dropInterests; ///< @brief trace of dropped Interests
229
230 ////////////////////////////////////////////////////////////////////
231 ////////////////////////////////////////////////////////////////////
232 ////////////////////////////////////////////////////////////////////
233
234 TracedCallback<Ptr<const ContentObjectHeader>, Ptr<const Packet>,
235 bool /*from cache*/,
236 Ptr<const Face> > m_outData; ///< @brief trace of outgoing Data
237
238 TracedCallback<Ptr<const ContentObjectHeader>, Ptr<const Packet>,
239 Ptr<const Face> > m_inData; ///< @brief trace of incoming Data
240
241 TracedCallback<Ptr<const ContentObjectHeader>, Ptr<const Packet>,
242 Ptr<const Face> > m_dropData; ///< @brief trace of dropped Data
243};
244
245} // namespace ndn
246} // namespace ns3
247
248#endif /* NDN_FORWARDING_STRATEGY_H */