blob: cf098785f7a3c45b4d809ae5cc3dbcea98c43a2b [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,
247 Ptr<InterestHeader> header,
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700248 const Ptr<const Packet> &packet,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700249 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 Afanasyev996b4872012-07-17 17:07:56 -0700252 m_dropInterests (header, incomingFace);
253}
254
255void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700256ForwardingStrategy::FailedToCreatePitEntry (const Ptr<Face> &incomingFace,
257 Ptr<InterestHeader> header,
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700258 const Ptr<const Packet> &packet)
259{
260 NS_LOG_FUNCTION (this);
261 m_dropInterests (header, incomingFace);
262}
263
264void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700265ForwardingStrategy::DidCreatePitEntry (const Ptr<Face> &incomingFace,
266 Ptr<InterestHeader> header,
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700267 const Ptr<const Packet> &packet,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700268 Ptr<pit::Entry> pitEntrypitEntry)
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700269{
270}
271
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700272bool
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700273ForwardingStrategy::DetectRetransmittedInterest (const Ptr<Face> &incomingFace,
274 Ptr<pit::Entry> pitEntry)
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700275{
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700276 pit::Entry::in_iterator inFace = pitEntry->GetIncoming ().find (incomingFace);
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700277
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700278 bool isRetransmitted = false;
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700279
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700280 if (inFace != pitEntry->GetIncoming ().end ())
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700281 {
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700282 // this is almost definitely a retransmission. But should we trust the user on that?
283 isRetransmitted = true;
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700284 }
285
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700286 return isRetransmitted;
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700287}
288
289void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700290ForwardingStrategy::SatisfyPendingInterest (const Ptr<Face> &incomingFace,
291 Ptr<const ContentObjectHeader> header,
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700292 Ptr<const Packet> payload,
293 const Ptr<const Packet> &packet,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700294 Ptr<pit::Entry> pitEntry)
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700295{
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700296 if (incomingFace != 0)
297 pitEntry->RemoveIncoming (incomingFace);
298
299 //satisfy all pending incoming Interests
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700300 BOOST_FOREACH (const pit::IncomingFace &incoming, pitEntry->GetIncoming ())
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700301 {
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -0700302 bool ok = incoming.m_face->Send (packet->Copy ());
303 if (ok)
304 {
305 m_outData (header, payload, incomingFace == 0, incoming.m_face);
306 DidSendOutData (incoming.m_face, header, payload, packet);
307
308 NS_LOG_DEBUG ("Satisfy " << *incoming.m_face);
309 }
310 else
311 {
312 m_dropData (header, payload, incoming.m_face);
313 NS_LOG_DEBUG ("Cannot satisfy data to " << *incoming.m_face);
314 }
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700315
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700316 // successfull forwarded data trace
317 }
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700318
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700319 // All incoming interests are satisfied. Remove them
320 pitEntry->ClearIncoming ();
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700321
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700322 // Remove all outgoing faces
323 pitEntry->ClearOutgoing ();
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700324
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700325 // Set pruning timout on PIT entry (instead of deleting the record)
326 m_pit->MarkErased (pitEntry);
327}
328
329void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700330ForwardingStrategy::DidReceiveUnsolicitedData (const Ptr<Face> &incomingFace,
331 Ptr<const ContentObjectHeader> header,
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700332 Ptr<const Packet> payload)
333{
334 if (m_cacheUnsolicitedData)
335 {
336 // Optimistically add or update entry in the content store
337 m_contentStore->Add (header, payload);
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700338 }
339 else
340 {
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700341 // Drop data packet if PIT entry is not found
342 // (unsolicited data packets should not "poison" content store)
343
344 //drop dulicated or not requested data packet
345 m_dropData (header, payload, incomingFace);
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700346 }
347}
348
349void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700350ForwardingStrategy::WillSatisfyPendingInterest (const Ptr<Face> &incomingFace,
351 Ptr<pit::Entry> pitEntry)
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700352{
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700353 pit::Entry::out_iterator out = pitEntry->GetOutgoing ().find (incomingFace);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700354
355 // If we have sent interest for this data via this face, then update stats.
356 if (out != pitEntry->GetOutgoing ().end ())
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700357 {
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700358 pitEntry->GetFibEntry ()->UpdateFaceRtt (incomingFace, Simulator::Now () - out->m_sendTime);
359 }
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700360}
361
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700362bool
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700363ForwardingStrategy::ShouldSuppressIncomingInterest (const Ptr<Face> &incomingFace,
364 Ptr<pit::Entry> pitEntry)
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700365{
366 bool isNew = pitEntry->GetIncoming ().size () == 0 && pitEntry->GetOutgoing ().size () == 0;
367
368 if (isNew) return false; // never suppress new interests
369
370 bool isRetransmitted = m_detectRetransmissions && // a small guard
371 DetectRetransmittedInterest (incomingFace, pitEntry);
372
373 if (pitEntry->GetOutgoing ().find (incomingFace) != pitEntry->GetOutgoing ().end ())
374 {
375 NS_LOG_DEBUG ("Non duplicate interests from the face we have sent interest to. Don't suppress");
376 // got a non-duplicate interest from the face we have sent interest to
377 // Probably, there is no point in waiting data from that face... Not sure yet
378
379 // If we're expecting data from the interface we got the interest from ("producer" asks us for "his own" data)
380 // Mark interface YELLOW, but keep a small hope that data will come eventually.
381
382 // ?? not sure if we need to do that ?? ...
383
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700384 // pitEntry->GetFibEntry ()->UpdateStatus (incomingFace, fib::FaceMetric::NDN_FIB_YELLOW);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700385 }
386 else
387 if (!isNew && !isRetransmitted)
388 {
389 return true;
390 }
391
392 return false;
393}
394
395void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700396ForwardingStrategy::PropagateInterest (const Ptr<Face> &incomingFace,
397 Ptr<InterestHeader> header,
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700398 const Ptr<const Packet> &packet,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700399 Ptr<pit::Entry> pitEntry)
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700400{
401 bool isRetransmitted = m_detectRetransmissions && // a small guard
402 DetectRetransmittedInterest (incomingFace, pitEntry);
403
404 pitEntry->AddIncoming (incomingFace/*, header->GetInterestLifetime ()*/);
405 /// @todo Make lifetime per incoming interface
406 pitEntry->UpdateLifetime (header->GetInterestLifetime ());
407
408 bool propagated = DoPropagateInterest (incomingFace, header, packet, pitEntry);
409
410 if (!propagated && isRetransmitted) //give another chance if retransmitted
411 {
412 // increase max number of allowed retransmissions
413 pitEntry->IncreaseAllowedRetxCount ();
414
415 // try again
416 propagated = DoPropagateInterest (incomingFace, header, packet, pitEntry);
417 }
418
419 // ForwardingStrategy will try its best to forward packet to at least one interface.
420 // If no interests was propagated, then there is not other option for forwarding or
421 // ForwardingStrategy failed to find it.
422 if (!propagated && pitEntry->GetOutgoing ().size () == 0)
423 {
424 DidExhaustForwardingOptions (incomingFace, header, packet, pitEntry);
425 }
426}
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700427
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700428bool
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700429ForwardingStrategy::WillSendOutInterest (const Ptr<Face> &outgoingFace,
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700430 Ptr<InterestHeader> header,
431 Ptr<pit::Entry> pitEntry)
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700432{
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700433 pit::Entry::out_iterator outgoing =
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700434 pitEntry->GetOutgoing ().find (outgoingFace);
435
436 if (outgoing != pitEntry->GetOutgoing ().end () &&
437 outgoing->m_retxCount >= pitEntry->GetMaxRetxCount ())
438 {
439 NS_LOG_ERROR (outgoing->m_retxCount << " >= " << pitEntry->GetMaxRetxCount ());
440 return false; // already forwarded before during this retransmission cycle
441 }
442
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700443 pitEntry->AddOutgoing (outgoingFace);
444 return true;
445}
446
447void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700448ForwardingStrategy::DidSendOutInterest (const Ptr<Face> &outgoingFace,
449 Ptr<InterestHeader> header,
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -0700450 const Ptr<const Packet> &packet,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700451 Ptr<pit::Entry> pitEntry)
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700452{
453 m_outInterests (header, outgoingFace);
454}
455
456void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700457ForwardingStrategy::DidSendOutData (const Ptr<Face> &face,
458 Ptr<const ContentObjectHeader> header,
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -0700459 Ptr<const Packet> payload,
460 const Ptr<const Packet> &packet)
461{
462}
463
464void
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700465ForwardingStrategy::WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry)
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700466{
467 // do nothing for now. may be need to do some logging
468}
469
Alexander Afanasyev33364b62012-07-26 17:53:56 -0700470
471void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700472ForwardingStrategy::RemoveFace (Ptr<Face> face)
Alexander Afanasyev33364b62012-07-26 17:53:56 -0700473{
474 // do nothing here
475}
476
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700477} // namespace ndn
478} // namespace ns3