blob: c46c70f3dae72bc6c3d9cecf9863408317f0f86e [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);
86
Alexander Afanasyev996b4872012-07-17 17:07:56 -070087protected:
88 // events
89 virtual void
90 DidReceiveDuplicateInterest (const Ptr<CcnxFace> &face,
91 Ptr<CcnxInterestHeader> &header,
92 const Ptr<const Packet> &packet,
93 Ptr<CcnxPitEntry> pitEntry);
94
95 virtual void
96 DidExhaustForwardingOptions (const Ptr<CcnxFace> &incomingFace,
97 Ptr<CcnxInterestHeader> header,
98 const Ptr<const Packet> &packet,
99 Ptr<CcnxPitEntry> pitEntry);
100
101 virtual void
102 FailedToCreatePitEntry (const Ptr<CcnxFace> &incomingFace,
103 Ptr<CcnxInterestHeader> header,
104 const Ptr<const Packet> &packet);
105
106 virtual void
107 DidCreatePitEntry (const Ptr<CcnxFace> &incomingFace,
108 Ptr<CcnxInterestHeader> header,
109 const Ptr<const Packet> &packet,
110 Ptr<CcnxPitEntry> pitEntry);
111
112 virtual bool
113 DetectRetransmittedInterest (const Ptr<CcnxFace> &incomingFace,
114 Ptr<CcnxPitEntry> pitEntry);
115
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700116 // makes sense only for data received from network
117 // When Interest is satisfied from the cache, incoming face is 0
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700118 virtual void
119 WillSatisfyPendingInterest (const Ptr<CcnxFace> &incomingFace,
120 Ptr<CcnxPitEntry> pitEntry);
121
122 // for data received both from network and cache
123 virtual void
124 SatisfyPendingInterest (const Ptr<CcnxFace> &incomingFace, // 0 allowed (from cache)
125 Ptr<const CcnxContentObjectHeader> header,
126 Ptr<const Packet> payload,
127 const Ptr<const Packet> &packet,
128 Ptr<CcnxPitEntry> pitEntry);
129
130 virtual void
131 DidReceiveUnsolicitedData (const Ptr<CcnxFace> &incomingFace,
132 Ptr<const CcnxContentObjectHeader> header,
133 Ptr<const Packet> payload);
134
135 virtual bool
136 ShouldSuppressIncomingInterest (const Ptr<CcnxFace> &incomingFace,
137 Ptr<CcnxPitEntry> pitEntry);
138
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700139 /**
140 * @brief Event fired before actually sending out an interest
141 *
142 * If event returns false, then there is some kind of a problem (e.g., per-face limit reached)
143 */
144 virtual bool
145 WillSendOutInterest (const Ptr<CcnxFace> &outgoingFace,
146 Ptr<CcnxInterestHeader> header,
147 Ptr<CcnxPitEntry> pitEntry);
148
149 /**
150 * @brief Event fired just after sending out an interest
151 */
152 virtual void
153 DidSendOutInterest (const Ptr<CcnxFace> &outgoingFace,
154 Ptr<CcnxInterestHeader> header,
155 Ptr<CcnxPitEntry> pitEntry);
156
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700157
158 virtual void
159 PropagateInterest (const Ptr<CcnxFace> &incomingFace,
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700160 Ptr<CcnxInterestHeader> header,
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700161 const Ptr<const Packet> &packet,
162 Ptr<CcnxPitEntry> pitEntry);
163
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700164 /**
165 * @brief Base method to propagate the interest according to the forwarding strategy
166 *
167 * @param pitEntry Reference to PIT entry (reference to corresponding FIB entry inside)
168 * @param incomingFace Incoming face
169 * @param header CcnxInterestHeader
170 * @param packet Original Interest packet
171 * @param sendCallback Send callback
172 *
173 * @return true if interest was successfully propagated, false if all options have failed
174 */
175 virtual bool
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700176 DoPropagateInterest (const Ptr<CcnxFace> &incomingFace,
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700177 Ptr<CcnxInterestHeader> header,
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700178 const Ptr<const Packet> &packet,
179 Ptr<CcnxPitEntry> pitEntry) = 0;
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700180
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700181
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700182 // virtual void
183 // OnDataDelayed (Ptr<const CcnxContentObjectHeader> header,
184 // Ptr<const Packet> payload,
185 // const Ptr<const Packet> &packet);
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700186
187protected:
188 // inherited from Object class
189 virtual void NotifyNewAggregate (); ///< @brief Even when object is aggregated to another Object
190 virtual void DoDispose (); ///< @brief Do cleanup
191
192protected:
193 Ptr<CcnxPit> m_pit; ///< \brief Reference to PIT to which this forwarding strategy is associated
194 Ptr<CcnxFib> m_fib; ///< \brief FIB
195 Ptr<CcnxContentStore> m_contentStore; ///< \brief Content store (for caching purposes only)
196
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700197 bool m_cacheUnsolicitedData;
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700198 bool m_detectRetransmissions;
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700199
200 TracedCallback<Ptr<const CcnxInterestHeader>,
201 Ptr<const CcnxFace> > m_outInterests; ///< @brief Transmitted interests trace
202
203 TracedCallback<Ptr<const CcnxInterestHeader>,
204 Ptr<const CcnxFace> > m_inInterests; ///< @brief trace of incoming Interests
205
206 TracedCallback<Ptr<const CcnxInterestHeader>,
207 Ptr<const CcnxFace> > m_dropInterests; ///< @brief trace of dropped Interests
208
209 ////////////////////////////////////////////////////////////////////
210 ////////////////////////////////////////////////////////////////////
211 ////////////////////////////////////////////////////////////////////
212
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700213 TracedCallback<Ptr<const CcnxContentObjectHeader>, Ptr<const Packet>,
214 bool /*from cache*/,
215 Ptr<const CcnxFace> > m_outData; ///< @brief trace of outgoing Data
216
217 TracedCallback<Ptr<const CcnxContentObjectHeader>, Ptr<const Packet>,
218 Ptr<const CcnxFace> > m_inData; ///< @brief trace of incoming Data
219
220 TracedCallback<Ptr<const CcnxContentObjectHeader>, Ptr<const Packet>,
221 Ptr<const CcnxFace> > m_dropData; ///< @brief trace of dropped Data
222};
223
224} //namespace ns3
225
226#endif /* CCNX_FORWARDING_STRATEGY_H */