blob: 9fc4d29fbf9be83257468e8910887e8c9c9c375c [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 Afanasyev31cb4692012-08-17 13:08:20 -0700126ForwardingStrategy::OnInterest (Ptr<Face> inFace,
127 Ptr<const InterestHeader> header,
128 Ptr<const Packet> origPacket)
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700129{
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700130 m_inInterests (header, inFace);
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700131
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700132 Ptr<pit::Entry> pitEntry = m_pit->Lookup (*header);
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700133 bool similarInterest = true;
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700134 if (pitEntry == 0)
135 {
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700136 similarInterest = false;
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700137 pitEntry = m_pit->Create (header);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700138 if (pitEntry != 0)
139 {
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700140 DidCreatePitEntry (inFace, header, origPacket, pitEntry);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700141 }
142 else
143 {
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700144 FailedToCreatePitEntry (inFace, header, origPacket);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700145 return;
146 }
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700147 }
148
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700149 bool isDuplicated = true;
150 if (!pitEntry->IsNonceSeen (header->GetNonce ()))
151 {
152 pitEntry->AddSeenNonce (header->GetNonce ());
153 isDuplicated = false;
154 }
155
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700156 if (isDuplicated)
157 {
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700158 DidReceiveDuplicateInterest (inFace, header, origPacket, pitEntry);
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700159 return;
160 }
161
162 Ptr<Packet> contentObject;
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700163 Ptr<const ContentObjectHeader> contentObjectHeader; // used for tracing
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700164 Ptr<const Packet> payload; // used for tracing
165 boost::tie (contentObject, contentObjectHeader, payload) = m_contentStore->Lookup (header);
166 if (contentObject != 0)
167 {
168 NS_ASSERT (contentObjectHeader != 0);
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700169
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700170 pitEntry->AddIncoming (inFace/*, Seconds (1.0)*/);
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700171
172 // Do data plane performance measurements
173 WillSatisfyPendingInterest (0, pitEntry);
174
175 // Actually satisfy pending interest
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700176 SatisfyPendingInterest (0, contentObjectHeader, payload, contentObject, pitEntry);
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700177 return;
178 }
179
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700180 if (similarInterest && ShouldSuppressIncomingInterest (inFace, header, origPacket, pitEntry))
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700181 {
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700182 pitEntry->AddIncoming (inFace/*, header->GetInterestLifetime ()*/);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700183 // update PIT entry lifetime
184 pitEntry->UpdateLifetime (header->GetInterestLifetime ());
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700185
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700186 // Suppress this interest if we're still expecting data from some other face
187 NS_LOG_DEBUG ("Suppress interests");
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700188 m_dropInterests (header, inFace);
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700189
190 DidSuppressSimilarInterest (inFace, header, origPacket, pitEntry);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700191 return;
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700192 }
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700193
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700194 if (similarInterest)
195 {
196 DidForwardSimilarInterest (inFace, header, origPacket, pitEntry);
197 }
198
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700199 PropagateInterest (inFace, header, origPacket, pitEntry);
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700200}
201
202void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700203ForwardingStrategy::OnData (Ptr<Face> inFace,
204 Ptr<const ContentObjectHeader> header,
205 Ptr<Packet> payload,
206 Ptr<const Packet> origPacket)
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700207{
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700208 NS_LOG_FUNCTION (inFace << header->GetName () << payload << origPacket);
209 m_inData (header, payload, inFace);
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700210
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700211 // Lookup PIT entry
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700212 Ptr<pit::Entry> pitEntry = m_pit->Lookup (*header);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700213 if (pitEntry == 0)
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700214 {
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700215 DidReceiveUnsolicitedData (inFace, header, payload, origPacket);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700216 return;
217 }
218 else
219 {
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700220 // Add or update entry in the content store
221 m_contentStore->Add (header, payload);
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700222 }
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700223
224 while (pitEntry != 0)
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700225 {
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700226 // Do data plane performance measurements
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700227 WillSatisfyPendingInterest (inFace, pitEntry);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700228
229 // Actually satisfy pending interest
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700230 SatisfyPendingInterest (inFace, header, payload, origPacket, pitEntry);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700231
232 // Lookup another PIT entry
233 pitEntry = m_pit->Lookup (*header);
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700234 }
235}
236
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700237void
238ForwardingStrategy::DidCreatePitEntry (Ptr<Face> inFace,
239 Ptr<const InterestHeader> header,
240 Ptr<const Packet> origPacket,
241 Ptr<pit::Entry> pitEntrypitEntry)
242{
243}
244
245void
246ForwardingStrategy::FailedToCreatePitEntry (Ptr<Face> inFace,
247 Ptr<const InterestHeader> header,
248 Ptr<const Packet> origPacket)
249{
250 m_dropInterests (header, inFace);
251}
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700252
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700253void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700254ForwardingStrategy::DidReceiveDuplicateInterest (Ptr<Face> inFace,
255 Ptr<const InterestHeader> header,
256 Ptr<const Packet> origPacket,
257 Ptr<pit::Entry> pitEntry)
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700258{
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700259 /////////////////////////////////////////////////////////////////////////////////////////
260 // //
261 // !!!! IMPORTANT CHANGE !!!! Duplicate interests will create incoming face entry !!!! //
262 // //
263 /////////////////////////////////////////////////////////////////////////////////////////
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700264 pitEntry->AddIncoming (inFace);
265 m_dropInterests (header, inFace);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700266}
267
268void
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700269ForwardingStrategy::DidSuppressSimilarInterest (Ptr<Face> face,
270 Ptr<const InterestHeader> header,
271 Ptr<const Packet> origPacket,
272 Ptr<pit::Entry> pitEntry)
273{
274}
275
276void
277ForwardingStrategy::DidForwardSimilarInterest (Ptr<Face> inFace,
278 Ptr<const InterestHeader> header,
279 Ptr<const Packet> origPacket,
280 Ptr<pit::Entry> pitEntry)
281{
282}
283
284void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700285ForwardingStrategy::DidExhaustForwardingOptions (Ptr<Face> inFace,
286 Ptr<const InterestHeader> header,
287 Ptr<const Packet> origPacket,
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -0700288 Ptr<pit::Entry> pitEntry)
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700289{
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700290 NS_LOG_FUNCTION (this << boost::cref (*inFace));
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -0700291 if (pitEntry->GetOutgoing ().size () == 0)
292 {
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700293 m_dropInterests (header, inFace);
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -0700294
295 // All incoming interests cannot be satisfied. Remove them
296 pitEntry->ClearIncoming ();
297
298 // Remove also outgoing
299 pitEntry->ClearOutgoing ();
300
301 // Set pruning timout on PIT entry (instead of deleting the record)
302 m_pit->MarkErased (pitEntry);
303 }
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700304}
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700305
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700306
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700307
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700308bool
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700309ForwardingStrategy::DetectRetransmittedInterest (Ptr<Face> inFace,
310 Ptr<const InterestHeader> header,
311 Ptr<const Packet> packet,
312 Ptr<pit::Entry> pitEntry)
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700313{
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700314 pit::Entry::in_iterator existingInFace = pitEntry->GetIncoming ().find (inFace);
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700315
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700316 bool isRetransmitted = false;
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700317
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700318 if (existingInFace != pitEntry->GetIncoming ().end ())
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700319 {
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700320 // this is almost definitely a retransmission. But should we trust the user on that?
321 isRetransmitted = true;
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700322 }
323
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700324 return isRetransmitted;
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700325}
326
327void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700328ForwardingStrategy::SatisfyPendingInterest (Ptr<Face> inFace,
329 Ptr<const ContentObjectHeader> header,
330 Ptr<const Packet> payload,
331 Ptr<const Packet> origPacket,
332 Ptr<pit::Entry> pitEntry)
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700333{
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700334 if (inFace != 0)
335 pitEntry->RemoveIncoming (inFace);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700336
337 //satisfy all pending incoming Interests
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700338 BOOST_FOREACH (const pit::IncomingFace &incoming, pitEntry->GetIncoming ())
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700339 {
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700340 bool ok = incoming.m_face->Send (origPacket->Copy ());
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -0700341 if (ok)
342 {
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700343 m_outData (header, payload, inFace == 0, incoming.m_face);
344 DidSendOutData (incoming.m_face, header, payload, origPacket, pitEntry);
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -0700345
346 NS_LOG_DEBUG ("Satisfy " << *incoming.m_face);
347 }
348 else
349 {
350 m_dropData (header, payload, incoming.m_face);
351 NS_LOG_DEBUG ("Cannot satisfy data to " << *incoming.m_face);
352 }
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700353
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700354 // successfull forwarded data trace
355 }
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700356
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700357 // All incoming interests are satisfied. Remove them
358 pitEntry->ClearIncoming ();
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700359
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700360 // Remove all outgoing faces
361 pitEntry->ClearOutgoing ();
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700362
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700363 // Set pruning timout on PIT entry (instead of deleting the record)
364 m_pit->MarkErased (pitEntry);
365}
366
367void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700368ForwardingStrategy::DidReceiveUnsolicitedData (Ptr<Face> inFace,
369 Ptr<const ContentObjectHeader> header,
370 Ptr<const Packet> payload,
371 Ptr<const Packet> origPacket)
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700372{
373 if (m_cacheUnsolicitedData)
374 {
375 // Optimistically add or update entry in the content store
376 m_contentStore->Add (header, payload);
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700377 }
378 else
379 {
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700380 // Drop data packet if PIT entry is not found
381 // (unsolicited data packets should not "poison" content store)
382
383 //drop dulicated or not requested data packet
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700384 m_dropData (header, payload, inFace);
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700385 }
386}
387
388void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700389ForwardingStrategy::WillSatisfyPendingInterest (Ptr<Face> inFace,
390 Ptr<pit::Entry> pitEntry)
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700391{
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700392 pit::Entry::out_iterator out = pitEntry->GetOutgoing ().find (inFace);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700393
394 // If we have sent interest for this data via this face, then update stats.
395 if (out != pitEntry->GetOutgoing ().end ())
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700396 {
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700397 pitEntry->GetFibEntry ()->UpdateFaceRtt (inFace, Simulator::Now () - out->m_sendTime);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700398 }
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700399}
400
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700401bool
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700402ForwardingStrategy::ShouldSuppressIncomingInterest (Ptr<Face> inFace,
403 Ptr<const InterestHeader> header,
404 Ptr<const Packet> origPacket,
405 Ptr<pit::Entry> pitEntry)
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700406{
407 bool isNew = pitEntry->GetIncoming ().size () == 0 && pitEntry->GetOutgoing ().size () == 0;
408
409 if (isNew) return false; // never suppress new interests
410
411 bool isRetransmitted = m_detectRetransmissions && // a small guard
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700412 DetectRetransmittedInterest (inFace, header, origPacket, pitEntry);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700413
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700414 if (pitEntry->GetOutgoing ().find (inFace) != pitEntry->GetOutgoing ().end ())
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700415 {
416 NS_LOG_DEBUG ("Non duplicate interests from the face we have sent interest to. Don't suppress");
417 // got a non-duplicate interest from the face we have sent interest to
418 // Probably, there is no point in waiting data from that face... Not sure yet
419
420 // If we're expecting data from the interface we got the interest from ("producer" asks us for "his own" data)
421 // Mark interface YELLOW, but keep a small hope that data will come eventually.
422
423 // ?? not sure if we need to do that ?? ...
424
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700425 // pitEntry->GetFibEntry ()->UpdateStatus (inFace, fib::FaceMetric::NDN_FIB_YELLOW);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700426 }
427 else
428 if (!isNew && !isRetransmitted)
429 {
430 return true;
431 }
432
433 return false;
434}
435
436void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700437ForwardingStrategy::PropagateInterest (Ptr<Face> inFace,
438 Ptr<const InterestHeader> header,
439 Ptr<const Packet> origPacket,
440 Ptr<pit::Entry> pitEntry)
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700441{
442 bool isRetransmitted = m_detectRetransmissions && // a small guard
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700443 DetectRetransmittedInterest (inFace, header, origPacket, pitEntry);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700444
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700445 pitEntry->AddIncoming (inFace/*, header->GetInterestLifetime ()*/);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700446 /// @todo Make lifetime per incoming interface
447 pitEntry->UpdateLifetime (header->GetInterestLifetime ());
448
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700449 bool propagated = DoPropagateInterest (inFace, header, origPacket, pitEntry);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700450
451 if (!propagated && isRetransmitted) //give another chance if retransmitted
452 {
453 // increase max number of allowed retransmissions
454 pitEntry->IncreaseAllowedRetxCount ();
455
456 // try again
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700457 propagated = DoPropagateInterest (inFace, header, origPacket, pitEntry);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700458 }
459
460 // ForwardingStrategy will try its best to forward packet to at least one interface.
461 // If no interests was propagated, then there is not other option for forwarding or
462 // ForwardingStrategy failed to find it.
463 if (!propagated && pitEntry->GetOutgoing ().size () == 0)
464 {
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700465 DidExhaustForwardingOptions (inFace, header, origPacket, pitEntry);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700466 }
467}
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700468
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700469bool
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700470ForwardingStrategy::TrySendOutInterest (Ptr<Face> inFace,
471 Ptr<Face> outFace,
472 Ptr<const InterestHeader> header,
473 Ptr<const Packet> origPacket,
474 Ptr<pit::Entry> pitEntry)
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700475{
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700476 if (outFace == inFace)
477 {
478 NS_LOG_DEBUG ("Same as incoming");
479 return false; // same face as incoming, don't forward
480 }
481
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700482 pit::Entry::out_iterator outgoing =
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700483 pitEntry->GetOutgoing ().find (outFace);
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700484
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700485 if (outgoing != pitEntry->GetOutgoing ().end ())
486 {
487 if (!m_detectRetransmissions)
488 return false; // suppress
489 else if (outgoing->m_retxCount >= pitEntry->GetMaxRetxCount ())
490 {
491 NS_LOG_ERROR (outgoing->m_retxCount << " >= " << pitEntry->GetMaxRetxCount ());
492 return false; // already forwarded before during this retransmission cycle
493 }
494 }
495
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700496 pitEntry->AddOutgoing (outFace);
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700497
498 //transmission
499 Ptr<Packet> packetToSend = origPacket->Copy ();
500 outFace->Send (packetToSend);
501
502 DidSendOutInterest (outFace, header, origPacket, pitEntry);
503
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700504 return true;
505}
506
507void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700508ForwardingStrategy::DidSendOutInterest (Ptr<Face> outFace,
509 Ptr<const InterestHeader> header,
510 Ptr<const Packet> origPacket,
511 Ptr<pit::Entry> pitEntry)
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700512{
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700513 m_outInterests (header, outFace);
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700514}
515
516void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700517ForwardingStrategy::DidSendOutData (Ptr<Face> inFace,
518 Ptr<const ContentObjectHeader> header,
519 Ptr<const Packet> payload,
520 Ptr<const Packet> origPacket,
521 Ptr<pit::Entry> pitEntry)
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -0700522{
523}
524
525void
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700526ForwardingStrategy::WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry)
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700527{
528 // do nothing for now. may be need to do some logging
529}
530
Alexander Afanasyev33364b62012-07-26 17:53:56 -0700531
532void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700533ForwardingStrategy::RemoveFace (Ptr<Face> face)
Alexander Afanasyev33364b62012-07-26 17:53:56 -0700534{
535 // do nothing here
536}
537
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700538} // namespace ndn
539} // namespace ns3