blob: 75f66475c85f76f29dd778539aee99ab9276e9bd [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>
19 * Ilya Moiseenko <iliamo@cs.ucla.edu>
20 */
21#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
63 * @param packet original packet
64 */
65 virtual void
66 OnInterest (const Ptr<Face> &face,
67 Ptr<InterestHeader> &header,
68 const Ptr<const Packet> &p);
69
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
77 * @param packet original packet
78 */
79 virtual void
80 OnData (const Ptr<Face> &face,
81 Ptr<ContentObjectHeader> &header,
82 Ptr<Packet> &payload,
83 const Ptr<const Packet> &packet);
84
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
104 DidReceiveDuplicateInterest (const Ptr<Face> &face,
105 Ptr<InterestHeader> &header,
106 const Ptr<const Packet> &packet,
107 Ptr<pit::Entry> pitEntry);
108
109 virtual void
110 DidExhaustForwardingOptions (const Ptr<Face> &incomingFace,
111 Ptr<InterestHeader> header,
112 const Ptr<const Packet> &packet,
113 Ptr<pit::Entry> pitEntry);
114
115 virtual void
116 FailedToCreatePitEntry (const Ptr<Face> &incomingFace,
117 Ptr<InterestHeader> header,
118 const Ptr<const Packet> &packet);
119
120 virtual void
121 DidCreatePitEntry (const Ptr<Face> &incomingFace,
122 Ptr<InterestHeader> header,
123 const Ptr<const Packet> &packet,
124 Ptr<pit::Entry> pitEntry);
125
126 virtual bool
127 DetectRetransmittedInterest (const Ptr<Face> &incomingFace,
128 Ptr<pit::Entry> pitEntry);
129
130 // makes sense only for data received from network
131 // When Interest is satisfied from the cache, incoming face is 0
132 virtual void
133 WillSatisfyPendingInterest (const Ptr<Face> &incomingFace,
134 Ptr<pit::Entry> pitEntry);
135
136 // for data received both from network and cache
137 virtual void
138 SatisfyPendingInterest (const Ptr<Face> &incomingFace, // 0 allowed (from cache)
139 Ptr<const ContentObjectHeader> header,
140 Ptr<const Packet> payload,
141 const Ptr<const Packet> &packet,
142 Ptr<pit::Entry> pitEntry);
143
144 virtual void
145 DidSendOutData (const Ptr<Face> &face,
146 Ptr<const ContentObjectHeader> header,
147 Ptr<const Packet> payload,
148 const Ptr<const Packet> &packet);
149
150 virtual void
151 DidReceiveUnsolicitedData (const Ptr<Face> &incomingFace,
152 Ptr<const ContentObjectHeader> header,
153 Ptr<const Packet> payload);
154
155 virtual bool
156 ShouldSuppressIncomingInterest (const Ptr<Face> &incomingFace,
157 Ptr<pit::Entry> pitEntry);
158
159 /**
160 * @brief Event fired before actually sending out an interest
161 *
162 * If event returns false, then there is some kind of a problem (e.g., per-face limit reached)
163 */
164 virtual bool
165 WillSendOutInterest (const Ptr<Face> &outgoingFace,
166 Ptr<InterestHeader> header,
167 Ptr<pit::Entry> pitEntry);
168
169 /**
170 * @brief Event fired just after sending out an interest
171 */
172 virtual void
173 DidSendOutInterest (const Ptr<Face> &outgoingFace,
174 Ptr<InterestHeader> header,
175 const Ptr<const Packet> &packet,
176 Ptr<pit::Entry> pitEntry);
177
178 virtual void
179 PropagateInterest (const Ptr<Face> &incomingFace,
180 Ptr<InterestHeader> header,
181 const Ptr<const Packet> &packet,
182 Ptr<pit::Entry> pitEntry);
183
184 /**
185 * @brief Base method to propagate the interest according to the forwarding strategy
186 *
187 * @param pitEntry Reference to PIT entry (reference to corresponding FIB entry inside)
188 * @param incomingFace Incoming face
189 * @param header InterestHeader
190 * @param packet Original Interest packet
191 * @param sendCallback Send callback
192 *
193 * @return true if interest was successfully propagated, false if all options have failed
194 */
195 virtual bool
196 DoPropagateInterest (const Ptr<Face> &incomingFace,
197 Ptr<InterestHeader> header,
198 const Ptr<const Packet> &packet,
199 Ptr<pit::Entry> pitEntry) = 0;
200
201protected:
202 // inherited from Object class
203 virtual void NotifyNewAggregate (); ///< @brief Even when object is aggregated to another Object
204 virtual void DoDispose (); ///< @brief Do cleanup
205
206protected:
207 Ptr<Pit> m_pit; ///< \brief Reference to PIT to which this forwarding strategy is associated
208 Ptr<Fib> m_fib; ///< \brief FIB
209 Ptr<ContentStore> m_contentStore; ///< \brief Content store (for caching purposes only)
210
211 bool m_cacheUnsolicitedData;
212 bool m_detectRetransmissions;
213
214 TracedCallback<Ptr<const InterestHeader>,
215 Ptr<const Face> > m_outInterests; ///< @brief Transmitted interests trace
216
217 TracedCallback<Ptr<const InterestHeader>,
218 Ptr<const Face> > m_inInterests; ///< @brief trace of incoming Interests
219
220 TracedCallback<Ptr<const InterestHeader>,
221 Ptr<const Face> > m_dropInterests; ///< @brief trace of dropped Interests
222
223 ////////////////////////////////////////////////////////////////////
224 ////////////////////////////////////////////////////////////////////
225 ////////////////////////////////////////////////////////////////////
226
227 TracedCallback<Ptr<const ContentObjectHeader>, Ptr<const Packet>,
228 bool /*from cache*/,
229 Ptr<const Face> > m_outData; ///< @brief trace of outgoing Data
230
231 TracedCallback<Ptr<const ContentObjectHeader>, Ptr<const Packet>,
232 Ptr<const Face> > m_inData; ///< @brief trace of incoming Data
233
234 TracedCallback<Ptr<const ContentObjectHeader>, Ptr<const Packet>,
235 Ptr<const Face> > m_dropData; ///< @brief trace of dropped Data
236};
237
238} // namespace ndn
239} // namespace ns3
240
241#endif /* NDN_FORWARDING_STRATEGY_H */