blob: 068307900cb85f96f7ae864dc6147a5136570f84 [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);
83
Alexander Afanasyev996b4872012-07-17 17:07:56 -070084protected:
85 // events
86 virtual void
87 DidReceiveDuplicateInterest (const Ptr<CcnxFace> &face,
88 Ptr<CcnxInterestHeader> &header,
89 const Ptr<const Packet> &packet,
90 Ptr<CcnxPitEntry> pitEntry);
91
92 virtual void
93 DidExhaustForwardingOptions (const Ptr<CcnxFace> &incomingFace,
94 Ptr<CcnxInterestHeader> header,
95 const Ptr<const Packet> &packet,
96 Ptr<CcnxPitEntry> pitEntry);
97
98 virtual void
99 FailedToCreatePitEntry (const Ptr<CcnxFace> &incomingFace,
100 Ptr<CcnxInterestHeader> header,
101 const Ptr<const Packet> &packet);
102
103 virtual void
104 DidCreatePitEntry (const Ptr<CcnxFace> &incomingFace,
105 Ptr<CcnxInterestHeader> header,
106 const Ptr<const Packet> &packet,
107 Ptr<CcnxPitEntry> pitEntry);
108
109 virtual bool
110 DetectRetransmittedInterest (const Ptr<CcnxFace> &incomingFace,
111 Ptr<CcnxPitEntry> pitEntry);
112
113 // only for data received from network
114 virtual void
115 WillSatisfyPendingInterest (const Ptr<CcnxFace> &incomingFace,
116 Ptr<CcnxPitEntry> pitEntry);
117
118 // for data received both from network and cache
119 virtual void
120 SatisfyPendingInterest (const Ptr<CcnxFace> &incomingFace, // 0 allowed (from cache)
121 Ptr<const CcnxContentObjectHeader> header,
122 Ptr<const Packet> payload,
123 const Ptr<const Packet> &packet,
124 Ptr<CcnxPitEntry> pitEntry);
125
126 virtual void
127 DidReceiveUnsolicitedData (const Ptr<CcnxFace> &incomingFace,
128 Ptr<const CcnxContentObjectHeader> header,
129 Ptr<const Packet> payload);
130
131 virtual bool
132 ShouldSuppressIncomingInterest (const Ptr<CcnxFace> &incomingFace,
133 Ptr<CcnxPitEntry> pitEntry);
134
135
136 virtual void
137 PropagateInterest (const Ptr<CcnxFace> &incomingFace,
138 Ptr<CcnxInterestHeader> &header,
139 const Ptr<const Packet> &packet,
140 Ptr<CcnxPitEntry> pitEntry);
141
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700142 /**
143 * @brief Base method to propagate the interest according to the forwarding strategy
144 *
145 * @param pitEntry Reference to PIT entry (reference to corresponding FIB entry inside)
146 * @param incomingFace Incoming face
147 * @param header CcnxInterestHeader
148 * @param packet Original Interest packet
149 * @param sendCallback Send callback
150 *
151 * @return true if interest was successfully propagated, false if all options have failed
152 */
153 virtual bool
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700154 DoPropagateInterest (const Ptr<CcnxFace> &incomingFace,
155 Ptr<CcnxInterestHeader> &header,
156 const Ptr<const Packet> &packet,
157 Ptr<CcnxPitEntry> pitEntry) = 0;
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700158
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700159
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700160 // virtual void
161 // OnDataDelayed (Ptr<const CcnxContentObjectHeader> header,
162 // Ptr<const Packet> payload,
163 // const Ptr<const Packet> &packet);
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700164
165protected:
166 // inherited from Object class
167 virtual void NotifyNewAggregate (); ///< @brief Even when object is aggregated to another Object
168 virtual void DoDispose (); ///< @brief Do cleanup
169
170protected:
171 Ptr<CcnxPit> m_pit; ///< \brief Reference to PIT to which this forwarding strategy is associated
172 Ptr<CcnxFib> m_fib; ///< \brief FIB
173 Ptr<CcnxContentStore> m_contentStore; ///< \brief Content store (for caching purposes only)
174
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700175 bool m_cacheUnsolicitedData;
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700176 bool m_detectRetransmissions;
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700177
178 TracedCallback<Ptr<const CcnxInterestHeader>,
179 Ptr<const CcnxFace> > m_outInterests; ///< @brief Transmitted interests trace
180
181 TracedCallback<Ptr<const CcnxInterestHeader>,
182 Ptr<const CcnxFace> > m_inInterests; ///< @brief trace of incoming Interests
183
184 TracedCallback<Ptr<const CcnxInterestHeader>,
185 Ptr<const CcnxFace> > m_dropInterests; ///< @brief trace of dropped Interests
186
187 ////////////////////////////////////////////////////////////////////
188 ////////////////////////////////////////////////////////////////////
189 ////////////////////////////////////////////////////////////////////
190
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700191 TracedCallback<Ptr<const CcnxContentObjectHeader>, Ptr<const Packet>,
192 bool /*from cache*/,
193 Ptr<const CcnxFace> > m_outData; ///< @brief trace of outgoing Data
194
195 TracedCallback<Ptr<const CcnxContentObjectHeader>, Ptr<const Packet>,
196 Ptr<const CcnxFace> > m_inData; ///< @brief trace of incoming Data
197
198 TracedCallback<Ptr<const CcnxContentObjectHeader>, Ptr<const Packet>,
199 Ptr<const CcnxFace> > m_dropData; ///< @brief trace of dropped Data
200};
201
202} //namespace ns3
203
204#endif /* CCNX_FORWARDING_STRATEGY_H */