blob: 913448f95b8992c2af0d6fc9df545cdd89a5310d [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
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070022#include "ndn-forwarding-strategy.h"
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -070023
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070024#include "ns3/ndn-pit.h"
25#include "ns3/ndn-pit-entry.h"
26#include "ns3/ndn-interest-header.h"
27#include "ns3/ndn-content-object-header.h"
28#include "ns3/ndn-pit.h"
29#include "ns3/ndn-fib.h"
30#include "ns3/ndn-content-store.h"
31#include "ns3/ndn-face.h"
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -070032
33#include "ns3/assert.h"
34#include "ns3/ptr.h"
35#include "ns3/log.h"
36#include "ns3/simulator.h"
37#include "ns3/boolean.h"
38#include "ns3/string.h"
39
40#include <boost/ref.hpp>
41#include <boost/foreach.hpp>
42#include <boost/lambda/lambda.hpp>
43#include <boost/lambda/bind.hpp>
44#include <boost/tuple/tuple.hpp>
45namespace ll = boost::lambda;
46
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070047NS_LOG_COMPONENT_DEFINE ("ndn.ForwardingStrategy");
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -070048
49namespace ns3 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070050namespace ndn {
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -070051
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070052NS_OBJECT_ENSURE_REGISTERED (ForwardingStrategy);
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -070053
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070054TypeId ForwardingStrategy::GetTypeId (void)
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -070055{
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070056 static TypeId tid = TypeId ("ns3::ndn::ForwardingStrategy")
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070057 .SetGroupName ("Ndn")
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -070058 .SetParent<Object> ()
59
60 ////////////////////////////////////////////////////////////////////
61 ////////////////////////////////////////////////////////////////////
62
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070063 .AddTraceSource ("OutInterests", "OutInterests", MakeTraceSourceAccessor (&ForwardingStrategy::m_outInterests))
64 .AddTraceSource ("InInterests", "InInterests", MakeTraceSourceAccessor (&ForwardingStrategy::m_inInterests))
65 .AddTraceSource ("DropInterests", "DropInterests", MakeTraceSourceAccessor (&ForwardingStrategy::m_dropInterests))
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -070066
67 ////////////////////////////////////////////////////////////////////
68 ////////////////////////////////////////////////////////////////////
69
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070070 .AddTraceSource ("OutData", "OutData", MakeTraceSourceAccessor (&ForwardingStrategy::m_outData))
71 .AddTraceSource ("InData", "InData", MakeTraceSourceAccessor (&ForwardingStrategy::m_inData))
72 .AddTraceSource ("DropData", "DropData", MakeTraceSourceAccessor (&ForwardingStrategy::m_dropData))
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -070073
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -070074 .AddAttribute ("CacheUnsolicitedData", "Cache overheard data that have not been requested",
75 BooleanValue (false),
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070076 MakeBooleanAccessor (&ForwardingStrategy::m_cacheUnsolicitedData),
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -070077 MakeBooleanChecker ())
78
Alexander Afanasyev996b4872012-07-17 17:07:56 -070079 .AddAttribute ("DetectRetransmissions", "If non-duplicate interest is received on the same face more than once, "
80 "it is considered a retransmission",
81 BooleanValue (true),
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070082 MakeBooleanAccessor (&ForwardingStrategy::m_detectRetransmissions),
Alexander Afanasyev996b4872012-07-17 17:07:56 -070083 MakeBooleanChecker ())
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -070084 ;
85 return tid;
86}
87
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070088ForwardingStrategy::ForwardingStrategy ()
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -070089{
90}
91
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070092ForwardingStrategy::~ForwardingStrategy ()
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -070093{
94}
95
96void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070097ForwardingStrategy::NotifyNewAggregate ()
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -070098{
99 if (m_pit == 0)
100 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700101 m_pit = GetObject<Pit> ();
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700102 }
103 if (m_fib == 0)
104 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700105 m_fib = GetObject<Fib> ();
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700106 }
107 if (m_contentStore == 0)
108 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700109 m_contentStore = GetObject<ContentStore> ();
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700110 }
111
112 Object::NotifyNewAggregate ();
113}
114
115void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700116ForwardingStrategy::DoDispose ()
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700117{
118 m_pit = 0;
119 m_contentStore = 0;
120 m_fib = 0;
121
122 Object::DoDispose ();
123}
124
125void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700126ForwardingStrategy::OnInterest (const Ptr<Face> &incomingFace,
127 Ptr<InterestHeader> &header,
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700128 const Ptr<const Packet> &packet)
129{
130 m_inInterests (header, incomingFace);
131
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700132 Ptr<pit::Entry> pitEntry = m_pit->Lookup (*header);
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700133 if (pitEntry == 0)
134 {
135 pitEntry = m_pit->Create (header);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700136 if (pitEntry != 0)
137 {
138 DidCreatePitEntry (incomingFace, header, packet, pitEntry);
139 }
140 else
141 {
142 FailedToCreatePitEntry (incomingFace, header, packet);
143 return;
144 }
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700145 }
146
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700147 bool isDuplicated = true;
148 if (!pitEntry->IsNonceSeen (header->GetNonce ()))
149 {
150 pitEntry->AddSeenNonce (header->GetNonce ());
151 isDuplicated = false;
152 }
153
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700154 if (isDuplicated)
155 {
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700156 DidReceiveDuplicateInterest (incomingFace, header, packet, pitEntry);
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700157 return;
158 }
159
160 Ptr<Packet> contentObject;
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700161 Ptr<const ContentObjectHeader> contentObjectHeader; // used for tracing
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700162 Ptr<const Packet> payload; // used for tracing
163 boost::tie (contentObject, contentObjectHeader, payload) = m_contentStore->Lookup (header);
164 if (contentObject != 0)
165 {
166 NS_ASSERT (contentObjectHeader != 0);
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700167
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700168 pitEntry->AddIncoming (incomingFace/*, Seconds (1.0)*/);
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700169
170 // Do data plane performance measurements
171 WillSatisfyPendingInterest (0, pitEntry);
172
173 // Actually satisfy pending interest
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700174 SatisfyPendingInterest (0, contentObjectHeader, payload, contentObject, pitEntry);
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700175 return;
176 }
177
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700178 if (ShouldSuppressIncomingInterest (incomingFace, pitEntry))
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700179 {
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700180 pitEntry->AddIncoming (incomingFace/*, header->GetInterestLifetime ()*/);
181 // update PIT entry lifetime
182 pitEntry->UpdateLifetime (header->GetInterestLifetime ());
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700183
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700184 // Suppress this interest if we're still expecting data from some other face
185 NS_LOG_DEBUG ("Suppress interests");
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700186 m_dropInterests (header, incomingFace);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700187 return;
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700188 }
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700189
190 PropagateInterest (incomingFace, header, packet, pitEntry);
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700191}
192
193void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700194ForwardingStrategy::OnData (const Ptr<Face> &incomingFace,
195 Ptr<ContentObjectHeader> &header,
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700196 Ptr<Packet> &payload,
197 const Ptr<const Packet> &packet)
198{
199 NS_LOG_FUNCTION (incomingFace << header->GetName () << payload << packet);
200 m_inData (header, payload, incomingFace);
201
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700202 // Lookup PIT entry
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700203 Ptr<pit::Entry> pitEntry = m_pit->Lookup (*header);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700204 if (pitEntry == 0)
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700205 {
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700206 DidReceiveUnsolicitedData (incomingFace, header, payload);
207 return;
208 }
209 else
210 {
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700211 // Add or update entry in the content store
212 m_contentStore->Add (header, payload);
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700213 }
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700214
215 while (pitEntry != 0)
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700216 {
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700217 // Do data plane performance measurements
218 WillSatisfyPendingInterest (incomingFace, pitEntry);
219
220 // Actually satisfy pending interest
221 SatisfyPendingInterest (incomingFace, header, payload, packet, pitEntry);
222
223 // Lookup another PIT entry
224 pitEntry = m_pit->Lookup (*header);
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700225 }
226}
227
228
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700229void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700230ForwardingStrategy::DidReceiveDuplicateInterest (const Ptr<Face> &incomingFace,
231 Ptr<InterestHeader> &header,
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700232 const Ptr<const Packet> &packet,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700233 Ptr<pit::Entry> pitEntry)
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700234{
Alexander Afanasyeve288d8b2012-07-20 15:35:17 -0700235 NS_LOG_FUNCTION (this << boost::cref (*incomingFace));
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700236 /////////////////////////////////////////////////////////////////////////////////////////
237 // //
238 // !!!! IMPORTANT CHANGE !!!! Duplicate interests will create incoming face entry !!!! //
239 // //
240 /////////////////////////////////////////////////////////////////////////////////////////
241 pitEntry->AddIncoming (incomingFace);
242 m_dropInterests (header, incomingFace);
243}
244
245void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700246ForwardingStrategy::DidExhaustForwardingOptions (const Ptr<Face> &incomingFace,
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -0700247 Ptr<InterestHeader> header,
248 const Ptr<const Packet> &packet,
249 Ptr<pit::Entry> pitEntry)
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700250{
Alexander Afanasyeve288d8b2012-07-20 15:35:17 -0700251 NS_LOG_FUNCTION (this << boost::cref (*incomingFace));
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -0700252 if (pitEntry->GetOutgoing ().size () == 0)
253 {
254 m_dropInterests (header, incomingFace);
255
256 // All incoming interests cannot be satisfied. Remove them
257 pitEntry->ClearIncoming ();
258
259 // Remove also outgoing
260 pitEntry->ClearOutgoing ();
261
262 // Set pruning timout on PIT entry (instead of deleting the record)
263 m_pit->MarkErased (pitEntry);
264 }
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700265}
266
267void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700268ForwardingStrategy::FailedToCreatePitEntry (const Ptr<Face> &incomingFace,
269 Ptr<InterestHeader> header,
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700270 const Ptr<const Packet> &packet)
271{
272 NS_LOG_FUNCTION (this);
273 m_dropInterests (header, incomingFace);
274}
275
276void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700277ForwardingStrategy::DidCreatePitEntry (const Ptr<Face> &incomingFace,
278 Ptr<InterestHeader> header,
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700279 const Ptr<const Packet> &packet,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700280 Ptr<pit::Entry> pitEntrypitEntry)
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700281{
282}
283
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700284bool
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700285ForwardingStrategy::DetectRetransmittedInterest (const Ptr<Face> &incomingFace,
286 Ptr<pit::Entry> pitEntry)
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700287{
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700288 pit::Entry::in_iterator inFace = pitEntry->GetIncoming ().find (incomingFace);
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700289
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700290 bool isRetransmitted = false;
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700291
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700292 if (inFace != pitEntry->GetIncoming ().end ())
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700293 {
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700294 // this is almost definitely a retransmission. But should we trust the user on that?
295 isRetransmitted = true;
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700296 }
297
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700298 return isRetransmitted;
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700299}
300
301void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700302ForwardingStrategy::SatisfyPendingInterest (const Ptr<Face> &incomingFace,
303 Ptr<const ContentObjectHeader> header,
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700304 Ptr<const Packet> payload,
305 const Ptr<const Packet> &packet,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700306 Ptr<pit::Entry> pitEntry)
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700307{
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700308 if (incomingFace != 0)
309 pitEntry->RemoveIncoming (incomingFace);
310
311 //satisfy all pending incoming Interests
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700312 BOOST_FOREACH (const pit::IncomingFace &incoming, pitEntry->GetIncoming ())
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700313 {
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -0700314 bool ok = incoming.m_face->Send (packet->Copy ());
315 if (ok)
316 {
317 m_outData (header, payload, incomingFace == 0, incoming.m_face);
318 DidSendOutData (incoming.m_face, header, payload, packet);
319
320 NS_LOG_DEBUG ("Satisfy " << *incoming.m_face);
321 }
322 else
323 {
324 m_dropData (header, payload, incoming.m_face);
325 NS_LOG_DEBUG ("Cannot satisfy data to " << *incoming.m_face);
326 }
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700327
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700328 // successfull forwarded data trace
329 }
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700330
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700331 // All incoming interests are satisfied. Remove them
332 pitEntry->ClearIncoming ();
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700333
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700334 // Remove all outgoing faces
335 pitEntry->ClearOutgoing ();
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700336
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700337 // Set pruning timout on PIT entry (instead of deleting the record)
338 m_pit->MarkErased (pitEntry);
339}
340
341void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700342ForwardingStrategy::DidReceiveUnsolicitedData (const Ptr<Face> &incomingFace,
343 Ptr<const ContentObjectHeader> header,
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700344 Ptr<const Packet> payload)
345{
346 if (m_cacheUnsolicitedData)
347 {
348 // Optimistically add or update entry in the content store
349 m_contentStore->Add (header, payload);
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700350 }
351 else
352 {
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700353 // Drop data packet if PIT entry is not found
354 // (unsolicited data packets should not "poison" content store)
355
356 //drop dulicated or not requested data packet
357 m_dropData (header, payload, incomingFace);
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700358 }
359}
360
361void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700362ForwardingStrategy::WillSatisfyPendingInterest (const Ptr<Face> &incomingFace,
363 Ptr<pit::Entry> pitEntry)
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700364{
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700365 pit::Entry::out_iterator out = pitEntry->GetOutgoing ().find (incomingFace);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700366
367 // If we have sent interest for this data via this face, then update stats.
368 if (out != pitEntry->GetOutgoing ().end ())
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700369 {
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700370 pitEntry->GetFibEntry ()->UpdateFaceRtt (incomingFace, Simulator::Now () - out->m_sendTime);
371 }
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700372}
373
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700374bool
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700375ForwardingStrategy::ShouldSuppressIncomingInterest (const Ptr<Face> &incomingFace,
376 Ptr<pit::Entry> pitEntry)
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700377{
378 bool isNew = pitEntry->GetIncoming ().size () == 0 && pitEntry->GetOutgoing ().size () == 0;
379
380 if (isNew) return false; // never suppress new interests
381
382 bool isRetransmitted = m_detectRetransmissions && // a small guard
383 DetectRetransmittedInterest (incomingFace, pitEntry);
384
385 if (pitEntry->GetOutgoing ().find (incomingFace) != pitEntry->GetOutgoing ().end ())
386 {
387 NS_LOG_DEBUG ("Non duplicate interests from the face we have sent interest to. Don't suppress");
388 // got a non-duplicate interest from the face we have sent interest to
389 // Probably, there is no point in waiting data from that face... Not sure yet
390
391 // If we're expecting data from the interface we got the interest from ("producer" asks us for "his own" data)
392 // Mark interface YELLOW, but keep a small hope that data will come eventually.
393
394 // ?? not sure if we need to do that ?? ...
395
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700396 // pitEntry->GetFibEntry ()->UpdateStatus (incomingFace, fib::FaceMetric::NDN_FIB_YELLOW);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700397 }
398 else
399 if (!isNew && !isRetransmitted)
400 {
401 return true;
402 }
403
404 return false;
405}
406
407void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700408ForwardingStrategy::PropagateInterest (const Ptr<Face> &incomingFace,
409 Ptr<InterestHeader> header,
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700410 const Ptr<const Packet> &packet,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700411 Ptr<pit::Entry> pitEntry)
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700412{
413 bool isRetransmitted = m_detectRetransmissions && // a small guard
414 DetectRetransmittedInterest (incomingFace, pitEntry);
415
416 pitEntry->AddIncoming (incomingFace/*, header->GetInterestLifetime ()*/);
417 /// @todo Make lifetime per incoming interface
418 pitEntry->UpdateLifetime (header->GetInterestLifetime ());
419
420 bool propagated = DoPropagateInterest (incomingFace, header, packet, pitEntry);
421
422 if (!propagated && isRetransmitted) //give another chance if retransmitted
423 {
424 // increase max number of allowed retransmissions
425 pitEntry->IncreaseAllowedRetxCount ();
426
427 // try again
428 propagated = DoPropagateInterest (incomingFace, header, packet, pitEntry);
429 }
430
431 // ForwardingStrategy will try its best to forward packet to at least one interface.
432 // If no interests was propagated, then there is not other option for forwarding or
433 // ForwardingStrategy failed to find it.
434 if (!propagated && pitEntry->GetOutgoing ().size () == 0)
435 {
436 DidExhaustForwardingOptions (incomingFace, header, packet, pitEntry);
437 }
438}
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700439
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700440bool
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700441ForwardingStrategy::WillSendOutInterest (const Ptr<Face> &outgoingFace,
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700442 Ptr<InterestHeader> header,
443 Ptr<pit::Entry> pitEntry)
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700444{
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700445 pit::Entry::out_iterator outgoing =
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700446 pitEntry->GetOutgoing ().find (outgoingFace);
447
448 if (outgoing != pitEntry->GetOutgoing ().end () &&
449 outgoing->m_retxCount >= pitEntry->GetMaxRetxCount ())
450 {
451 NS_LOG_ERROR (outgoing->m_retxCount << " >= " << pitEntry->GetMaxRetxCount ());
452 return false; // already forwarded before during this retransmission cycle
453 }
454
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700455 pitEntry->AddOutgoing (outgoingFace);
456 return true;
457}
458
459void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700460ForwardingStrategy::DidSendOutInterest (const Ptr<Face> &outgoingFace,
461 Ptr<InterestHeader> header,
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -0700462 const Ptr<const Packet> &packet,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700463 Ptr<pit::Entry> pitEntry)
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700464{
465 m_outInterests (header, outgoingFace);
466}
467
468void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700469ForwardingStrategy::DidSendOutData (const Ptr<Face> &face,
470 Ptr<const ContentObjectHeader> header,
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -0700471 Ptr<const Packet> payload,
472 const Ptr<const Packet> &packet)
473{
474}
475
476void
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700477ForwardingStrategy::WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry)
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700478{
479 // do nothing for now. may be need to do some logging
480}
481
Alexander Afanasyev33364b62012-07-26 17:53:56 -0700482
483void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700484ForwardingStrategy::RemoveFace (Ptr<Face> face)
Alexander Afanasyev33364b62012-07-26 17:53:56 -0700485{
486 // do nothing here
487}
488
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700489} // namespace ndn
490} // namespace ns3