blob: ff0dcefa8c7e4b656c972c06909595c9ab781b01 [file] [log] [blame]
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -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 CCNX_FORWARDING_STRATEGY_H
22#define CCNX_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 {
30
31class CcnxFace;
32class CcnxInterestHeader;
33class CcnxContentObjectHeader;
34class CcnxPit;
35class CcnxPitEntry;
36class CcnxFibFaceMetric;
37class CcnxFib;
38class CcnxContentStore;
39
40/**
41 * \ingroup ccnx
42 * \brief Abstract base class for CCNx forwarding strategies
43 */
Alexander Afanasyev996b4872012-07-17 17:07:56 -070044class CcnxForwardingStrategy :
45 public Object
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -070046{
47public:
48 static TypeId GetTypeId (void);
49
50 /**
51 * @brief Default constructor
52 */
53 CcnxForwardingStrategy ();
54 virtual ~CcnxForwardingStrategy ();
55
56 /**
57 * \brief Actual processing of incoming CCNx interests. Note, interests do not have payload
58 *
59 * Processing Interest packets
60 * @param face incoming face
61 * @param header deserialized Interest header
62 * @param packet original packet
63 */
64 virtual void
65 OnInterest (const Ptr<CcnxFace> &face,
66 Ptr<CcnxInterestHeader> &header,
67 const Ptr<const Packet> &p);
68
69 /**
70 * \brief Actual processing of incoming CCNx content objects
71 *
72 * Processing ContentObject packets
73 * @param face incoming face
74 * @param header deserialized ContentObject header
75 * @param payload data packet payload
76 * @param packet original packet
77 */
78 virtual void
79 OnData (const Ptr<CcnxFace> &face,
80 Ptr<CcnxContentObjectHeader> &header,
81 Ptr<Packet> &payload,
82 const Ptr<const Packet> &packet);
Alexander Afanasyevf249a192012-07-18 16:52:51 -070083
84 virtual void
85 WillErasePendingInterest (Ptr<CcnxPitEntry> pitEntry);
Alexander Afanasyev33364b62012-07-26 17:53:56 -070086
87 virtual void
88 RemoveFace (Ptr<CcnxFace> face);
Alexander Afanasyevf249a192012-07-18 16:52:51 -070089
Alexander Afanasyev996b4872012-07-17 17:07:56 -070090protected:
91 // events
92 virtual void
93 DidReceiveDuplicateInterest (const Ptr<CcnxFace> &face,
94 Ptr<CcnxInterestHeader> &header,
95 const Ptr<const Packet> &packet,
96 Ptr<CcnxPitEntry> pitEntry);
97
98 virtual void
99 DidExhaustForwardingOptions (const Ptr<CcnxFace> &incomingFace,
100 Ptr<CcnxInterestHeader> header,
101 const Ptr<const Packet> &packet,
102 Ptr<CcnxPitEntry> pitEntry);
103
104 virtual void
105 FailedToCreatePitEntry (const Ptr<CcnxFace> &incomingFace,
106 Ptr<CcnxInterestHeader> header,
107 const Ptr<const Packet> &packet);
108
109 virtual void
110 DidCreatePitEntry (const Ptr<CcnxFace> &incomingFace,
111 Ptr<CcnxInterestHeader> header,
112 const Ptr<const Packet> &packet,
113 Ptr<CcnxPitEntry> pitEntry);
114
115 virtual bool
116 DetectRetransmittedInterest (const Ptr<CcnxFace> &incomingFace,
117 Ptr<CcnxPitEntry> pitEntry);
118
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700119 // makes sense only for data received from network
120 // When Interest is satisfied from the cache, incoming face is 0
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700121 virtual void
122 WillSatisfyPendingInterest (const Ptr<CcnxFace> &incomingFace,
123 Ptr<CcnxPitEntry> pitEntry);
124
125 // for data received both from network and cache
126 virtual void
127 SatisfyPendingInterest (const Ptr<CcnxFace> &incomingFace, // 0 allowed (from cache)
128 Ptr<const CcnxContentObjectHeader> header,
129 Ptr<const Packet> payload,
130 const Ptr<const Packet> &packet,
131 Ptr<CcnxPitEntry> pitEntry);
132
133 virtual void
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -0700134 DidSendOutData (const Ptr<CcnxFace> &face,
135 Ptr<const CcnxContentObjectHeader> header,
136 Ptr<const Packet> payload,
137 const Ptr<const Packet> &packet);
138
139 virtual void
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700140 DidReceiveUnsolicitedData (const Ptr<CcnxFace> &incomingFace,
141 Ptr<const CcnxContentObjectHeader> header,
142 Ptr<const Packet> payload);
143
144 virtual bool
145 ShouldSuppressIncomingInterest (const Ptr<CcnxFace> &incomingFace,
146 Ptr<CcnxPitEntry> pitEntry);
147
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700148 /**
149 * @brief Event fired before actually sending out an interest
150 *
151 * If event returns false, then there is some kind of a problem (e.g., per-face limit reached)
152 */
153 virtual bool
154 WillSendOutInterest (const Ptr<CcnxFace> &outgoingFace,
155 Ptr<CcnxInterestHeader> header,
156 Ptr<CcnxPitEntry> pitEntry);
157
158 /**
159 * @brief Event fired just after sending out an interest
160 */
161 virtual void
162 DidSendOutInterest (const Ptr<CcnxFace> &outgoingFace,
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -0700163 Ptr<CcnxInterestHeader> header,
164 const Ptr<const Packet> &packet,
165 Ptr<CcnxPitEntry> pitEntry);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700166
167 virtual void
168 PropagateInterest (const Ptr<CcnxFace> &incomingFace,
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700169 Ptr<CcnxInterestHeader> header,
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700170 const Ptr<const Packet> &packet,
171 Ptr<CcnxPitEntry> pitEntry);
172
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700173 /**
174 * @brief Base method to propagate the interest according to the forwarding strategy
175 *
176 * @param pitEntry Reference to PIT entry (reference to corresponding FIB entry inside)
177 * @param incomingFace Incoming face
178 * @param header CcnxInterestHeader
179 * @param packet Original Interest packet
180 * @param sendCallback Send callback
181 *
182 * @return true if interest was successfully propagated, false if all options have failed
183 */
184 virtual bool
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700185 DoPropagateInterest (const Ptr<CcnxFace> &incomingFace,
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700186 Ptr<CcnxInterestHeader> header,
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700187 const Ptr<const Packet> &packet,
188 Ptr<CcnxPitEntry> pitEntry) = 0;
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700189
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700190
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700191 // virtual void
192 // OnDataDelayed (Ptr<const CcnxContentObjectHeader> header,
193 // Ptr<const Packet> payload,
194 // const Ptr<const Packet> &packet);
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700195
196protected:
197 // inherited from Object class
198 virtual void NotifyNewAggregate (); ///< @brief Even when object is aggregated to another Object
199 virtual void DoDispose (); ///< @brief Do cleanup
200
201protected:
202 Ptr<CcnxPit> m_pit; ///< \brief Reference to PIT to which this forwarding strategy is associated
203 Ptr<CcnxFib> m_fib; ///< \brief FIB
204 Ptr<CcnxContentStore> m_contentStore; ///< \brief Content store (for caching purposes only)
205
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700206 bool m_cacheUnsolicitedData;
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700207 bool m_detectRetransmissions;
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700208
209 TracedCallback<Ptr<const CcnxInterestHeader>,
210 Ptr<const CcnxFace> > m_outInterests; ///< @brief Transmitted interests trace
211
212 TracedCallback<Ptr<const CcnxInterestHeader>,
213 Ptr<const CcnxFace> > m_inInterests; ///< @brief trace of incoming Interests
214
215 TracedCallback<Ptr<const CcnxInterestHeader>,
216 Ptr<const CcnxFace> > m_dropInterests; ///< @brief trace of dropped Interests
217
218 ////////////////////////////////////////////////////////////////////
219 ////////////////////////////////////////////////////////////////////
220 ////////////////////////////////////////////////////////////////////
221
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700222 TracedCallback<Ptr<const CcnxContentObjectHeader>, Ptr<const Packet>,
223 bool /*from cache*/,
224 Ptr<const CcnxFace> > m_outData; ///< @brief trace of outgoing Data
225
226 TracedCallback<Ptr<const CcnxContentObjectHeader>, Ptr<const Packet>,
227 Ptr<const CcnxFace> > m_inData; ///< @brief trace of incoming Data
228
229 TracedCallback<Ptr<const CcnxContentObjectHeader>, Ptr<const Packet>,
230 Ptr<const CcnxFace> > m_dropData; ///< @brief trace of dropped Data
231};
232
233} //namespace ns3
234
235#endif /* CCNX_FORWARDING_STRATEGY_H */