blob: 2275a8c7de5cac2e59c1591cea221556b260596b [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"
Alexander Afanasyevbd9c18e2012-11-19 15:23:41 -080026#include "ns3/ndn-interest.h"
27#include "ns3/ndn-content-object.h"
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070028#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
Alexander Afanasyev1a0fff62013-01-19 14:29:51 -080040#include "ns3/ndnSIM/utils/ndn-fw-hop-count-tag.h"
41
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -070042#include <boost/ref.hpp>
43#include <boost/foreach.hpp>
44#include <boost/lambda/lambda.hpp>
45#include <boost/lambda/bind.hpp>
46#include <boost/tuple/tuple.hpp>
47namespace ll = boost::lambda;
48
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -070049namespace 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 Afanasyev042b4a72012-11-09 17:47:48 -080054NS_LOG_COMPONENT_DEFINE (ForwardingStrategy::GetLogName ().c_str ());
55
56std::string
57ForwardingStrategy::GetLogName ()
58{
59 return "ndn.fw";
60}
61
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070062TypeId ForwardingStrategy::GetTypeId (void)
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -070063{
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070064 static TypeId tid = TypeId ("ns3::ndn::ForwardingStrategy")
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070065 .SetGroupName ("Ndn")
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -070066 .SetParent<Object> ()
67
68 ////////////////////////////////////////////////////////////////////
69 ////////////////////////////////////////////////////////////////////
70
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070071 .AddTraceSource ("OutInterests", "OutInterests", MakeTraceSourceAccessor (&ForwardingStrategy::m_outInterests))
72 .AddTraceSource ("InInterests", "InInterests", MakeTraceSourceAccessor (&ForwardingStrategy::m_inInterests))
73 .AddTraceSource ("DropInterests", "DropInterests", MakeTraceSourceAccessor (&ForwardingStrategy::m_dropInterests))
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -080074
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -070075 ////////////////////////////////////////////////////////////////////
76 ////////////////////////////////////////////////////////////////////
77
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070078 .AddTraceSource ("OutData", "OutData", MakeTraceSourceAccessor (&ForwardingStrategy::m_outData))
79 .AddTraceSource ("InData", "InData", MakeTraceSourceAccessor (&ForwardingStrategy::m_inData))
80 .AddTraceSource ("DropData", "DropData", MakeTraceSourceAccessor (&ForwardingStrategy::m_dropData))
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -070081
Alexander Afanasyev37b84c52013-04-26 13:38:52 -070082 ////////////////////////////////////////////////////////////////////
83 ////////////////////////////////////////////////////////////////////
84
85 .AddTraceSource ("SatisfiedInterests", "SatisfiedInterests", MakeTraceSourceAccessor (&ForwardingStrategy::m_satisfiedInterests))
86 .AddTraceSource ("TimedOutInterests", "TimedOutInterests", MakeTraceSourceAccessor (&ForwardingStrategy::m_timedOutInterests))
Alexander Afanasyevdd9fa4f2013-05-15 16:35:04 -070087
88 .AddAttribute ("CacheUnsolicitedDataFromApps", "Cache unsolicited data that has been pushed from applications",
89 BooleanValue (true),
90 MakeBooleanAccessor (&ForwardingStrategy::m_cacheUnsolicitedDataFromApps),
91 MakeBooleanChecker ())
Alexander Afanasyev37b84c52013-04-26 13:38:52 -070092
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -070093 .AddAttribute ("CacheUnsolicitedData", "Cache overheard data that have not been requested",
94 BooleanValue (false),
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070095 MakeBooleanAccessor (&ForwardingStrategy::m_cacheUnsolicitedData),
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -070096 MakeBooleanChecker ())
97
Alexander Afanasyev996b4872012-07-17 17:07:56 -070098 .AddAttribute ("DetectRetransmissions", "If non-duplicate interest is received on the same face more than once, "
99 "it is considered a retransmission",
100 BooleanValue (true),
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700101 MakeBooleanAccessor (&ForwardingStrategy::m_detectRetransmissions),
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700102 MakeBooleanChecker ())
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700103 ;
104 return tid;
105}
106
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700107ForwardingStrategy::ForwardingStrategy ()
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700108{
109}
110
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700111ForwardingStrategy::~ForwardingStrategy ()
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700112{
113}
114
115void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700116ForwardingStrategy::NotifyNewAggregate ()
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700117{
118 if (m_pit == 0)
119 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700120 m_pit = GetObject<Pit> ();
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700121 }
122 if (m_fib == 0)
123 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700124 m_fib = GetObject<Fib> ();
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700125 }
126 if (m_contentStore == 0)
127 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700128 m_contentStore = GetObject<ContentStore> ();
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700129 }
130
131 Object::NotifyNewAggregate ();
132}
133
134void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700135ForwardingStrategy::DoDispose ()
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700136{
137 m_pit = 0;
138 m_contentStore = 0;
139 m_fib = 0;
140
141 Object::DoDispose ();
142}
143
144void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700145ForwardingStrategy::OnInterest (Ptr<Face> inFace,
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700146 Ptr<Interest> interest)
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700147{
Alexander Afanasyevee762552013-07-10 22:29:22 -0700148 NS_LOG_FUNCTION (inFace << interest->GetName ());
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700149 m_inInterests (interest, inFace);
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700150
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700151 Ptr<pit::Entry> pitEntry = m_pit->Lookup (*interest);
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700152 bool similarInterest = true;
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700153 if (pitEntry == 0)
154 {
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700155 similarInterest = false;
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700156 pitEntry = m_pit->Create (interest);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700157 if (pitEntry != 0)
158 {
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700159 DidCreatePitEntry (inFace, interest, pitEntry);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700160 }
161 else
162 {
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700163 FailedToCreatePitEntry (inFace, interest);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700164 return;
165 }
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700166 }
167
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700168 bool isDuplicated = true;
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700169 if (!pitEntry->IsNonceSeen (interest->GetNonce ()))
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700170 {
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700171 pitEntry->AddSeenNonce (interest->GetNonce ());
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700172 isDuplicated = false;
173 }
174
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800175 if (isDuplicated)
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700176 {
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700177 DidReceiveDuplicateInterest (inFace, interest, pitEntry);
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700178 return;
179 }
180
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700181 Ptr<ContentObject> contentObject;
182 contentObject = m_contentStore->Lookup (interest);
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700183 if (contentObject != 0)
184 {
Alexander Afanasyev1a0fff62013-01-19 14:29:51 -0800185 FwHopCountTag hopCountTag;
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700186 if (interest->GetPayload ()->PeekPacketTag (hopCountTag))
Alexander Afanasyev1a0fff62013-01-19 14:29:51 -0800187 {
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700188 contentObject->GetPayload ()->AddPacketTag (hopCountTag);
Alexander Afanasyev1a0fff62013-01-19 14:29:51 -0800189 }
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700190
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700191 pitEntry->AddIncoming (inFace/*, Seconds (1.0)*/);
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700192
193 // Do data plane performance measurements
194 WillSatisfyPendingInterest (0, pitEntry);
195
196 // Actually satisfy pending interest
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700197 SatisfyPendingInterest (0, contentObject, pitEntry);
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700198 return;
199 }
200
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700201 if (similarInterest && ShouldSuppressIncomingInterest (inFace, interest, pitEntry))
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700202 {
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700203 pitEntry->AddIncoming (inFace/*, interest->GetInterestLifetime ()*/);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700204 // update PIT entry lifetime
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700205 pitEntry->UpdateLifetime (interest->GetInterestLifetime ());
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700206
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700207 // Suppress this interest if we're still expecting data from some other face
208 NS_LOG_DEBUG ("Suppress interests");
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700209 m_dropInterests (interest, inFace);
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700210
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700211 DidSuppressSimilarInterest (inFace, interest, pitEntry);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700212 return;
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700213 }
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700214
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700215 if (similarInterest)
216 {
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700217 DidForwardSimilarInterest (inFace, interest, pitEntry);
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700218 }
219
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700220 PropagateInterest (inFace, interest, pitEntry);
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700221}
222
223void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700224ForwardingStrategy::OnData (Ptr<Face> inFace,
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700225 Ptr<ContentObject> data)
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700226{
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700227 NS_LOG_FUNCTION (inFace << data->GetName ());
228 m_inData (data, inFace);
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800229
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700230 // Lookup PIT entry
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700231 Ptr<pit::Entry> pitEntry = m_pit->Lookup (*data);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700232 if (pitEntry == 0)
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700233 {
Alexander Afanasyeve6c07b52013-02-12 11:05:14 -0800234 bool cached = false;
235
Alexander Afanasyevdd9fa4f2013-05-15 16:35:04 -0700236 if (m_cacheUnsolicitedData || (m_cacheUnsolicitedDataFromApps && (inFace->GetFlags () | Face::APPLICATION)))
Alexander Afanasyeve6c07b52013-02-12 11:05:14 -0800237 {
Alexander Afanasyeve6c07b52013-02-12 11:05:14 -0800238 // Optimistically add or update entry in the content store
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700239 cached = m_contentStore->Add (data);
Alexander Afanasyeve6c07b52013-02-12 11:05:14 -0800240 }
241 else
242 {
243 // Drop data packet if PIT entry is not found
244 // (unsolicited data packets should not "poison" content store)
245
246 //drop dulicated or not requested data packet
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700247 m_dropData (data, inFace);
Alexander Afanasyeve6c07b52013-02-12 11:05:14 -0800248 }
249
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700250 DidReceiveUnsolicitedData (inFace, data, cached);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700251 return;
252 }
253 else
254 {
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700255 bool cached = m_contentStore->Add (data);
256 DidReceiveSolicitedData (inFace, data, cached);
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700257 }
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700258
259 while (pitEntry != 0)
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700260 {
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700261 // Do data plane performance measurements
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700262 WillSatisfyPendingInterest (inFace, pitEntry);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700263
264 // Actually satisfy pending interest
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -0700265 SatisfyPendingInterest (inFace, data, pitEntry);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700266
267 // Lookup another PIT entry
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -0700268 pitEntry = m_pit->Lookup (*data);
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700269 }
270}
271
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700272void
273ForwardingStrategy::DidCreatePitEntry (Ptr<Face> inFace,
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700274 Ptr<const Interest> interest,
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700275 Ptr<pit::Entry> pitEntrypitEntry)
276{
277}
278
279void
280ForwardingStrategy::FailedToCreatePitEntry (Ptr<Face> inFace,
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700281 Ptr<const Interest> interest)
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700282{
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700283 m_dropInterests (interest, inFace);
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700284}
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700285
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700286void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700287ForwardingStrategy::DidReceiveDuplicateInterest (Ptr<Face> inFace,
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700288 Ptr<const Interest> interest,
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700289 Ptr<pit::Entry> pitEntry)
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700290{
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700291 /////////////////////////////////////////////////////////////////////////////////////////
292 // //
293 // !!!! IMPORTANT CHANGE !!!! Duplicate interests will create incoming face entry !!!! //
294 // //
295 /////////////////////////////////////////////////////////////////////////////////////////
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700296 pitEntry->AddIncoming (inFace);
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700297 m_dropInterests (interest, inFace);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700298}
299
300void
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700301ForwardingStrategy::DidSuppressSimilarInterest (Ptr<Face> face,
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700302 Ptr<const Interest> interest,
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700303 Ptr<pit::Entry> pitEntry)
304{
305}
306
307void
308ForwardingStrategy::DidForwardSimilarInterest (Ptr<Face> inFace,
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700309 Ptr<const Interest> interest,
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700310 Ptr<pit::Entry> pitEntry)
311{
312}
313
314void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700315ForwardingStrategy::DidExhaustForwardingOptions (Ptr<Face> inFace,
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700316 Ptr<const Interest> interest,
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -0700317 Ptr<pit::Entry> pitEntry)
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700318{
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700319 NS_LOG_FUNCTION (this << boost::cref (*inFace));
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800320 if (pitEntry->AreAllOutgoingInVain ())
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -0700321 {
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700322 m_dropInterests (interest, inFace);
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -0700323
324 // All incoming interests cannot be satisfied. Remove them
325 pitEntry->ClearIncoming ();
326
327 // Remove also outgoing
328 pitEntry->ClearOutgoing ();
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800329
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -0700330 // Set pruning timout on PIT entry (instead of deleting the record)
331 m_pit->MarkErased (pitEntry);
332 }
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700333}
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800334
Alexander Afanasyev6466fff2012-10-24 22:51:57 -0700335
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700336
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700337bool
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700338ForwardingStrategy::DetectRetransmittedInterest (Ptr<Face> inFace,
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700339 Ptr<const Interest> interest,
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700340 Ptr<pit::Entry> pitEntry)
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700341{
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700342 pit::Entry::in_iterator existingInFace = pitEntry->GetIncoming ().find (inFace);
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700343
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700344 bool isRetransmitted = false;
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800345
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700346 if (existingInFace != pitEntry->GetIncoming ().end ())
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700347 {
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700348 // this is almost definitely a retransmission. But should we trust the user on that?
349 isRetransmitted = true;
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700350 }
351
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700352 return isRetransmitted;
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700353}
354
355void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700356ForwardingStrategy::SatisfyPendingInterest (Ptr<Face> inFace,
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700357 Ptr<const ContentObject> data,
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700358 Ptr<pit::Entry> pitEntry)
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700359{
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700360 if (inFace != 0)
361 pitEntry->RemoveIncoming (inFace);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700362
363 //satisfy all pending incoming Interests
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700364 BOOST_FOREACH (const pit::IncomingFace &incoming, pitEntry->GetIncoming ())
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700365 {
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700366 bool ok = incoming.m_face->SendData (data);
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800367
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700368 DidSendOutData (inFace, incoming.m_face, data, pitEntry);
Alexander Afanasyevd0887982013-03-18 11:47:58 -0600369 NS_LOG_DEBUG ("Satisfy " << *incoming.m_face);
370
371 if (!ok)
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -0700372 {
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700373 m_dropData (data, incoming.m_face);
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -0700374 NS_LOG_DEBUG ("Cannot satisfy data to " << *incoming.m_face);
375 }
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700376 }
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700377
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700378 // All incoming interests are satisfied. Remove them
379 pitEntry->ClearIncoming ();
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700380
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700381 // Remove all outgoing faces
382 pitEntry->ClearOutgoing ();
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800383
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700384 // Set pruning timout on PIT entry (instead of deleting the record)
385 m_pit->MarkErased (pitEntry);
386}
387
388void
Alexander Afanasyeve6c07b52013-02-12 11:05:14 -0800389ForwardingStrategy::DidReceiveSolicitedData (Ptr<Face> inFace,
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700390 Ptr<const ContentObject> data,
Alexander Afanasyeve6c07b52013-02-12 11:05:14 -0800391 bool didCreateCacheEntry)
392{
393 // do nothing
394}
395
396void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700397ForwardingStrategy::DidReceiveUnsolicitedData (Ptr<Face> inFace,
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700398 Ptr<const ContentObject> data,
Alexander Afanasyeve6c07b52013-02-12 11:05:14 -0800399 bool didCreateCacheEntry)
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700400{
Alexander Afanasyeve6c07b52013-02-12 11:05:14 -0800401 // do nothing
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700402}
403
404void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700405ForwardingStrategy::WillSatisfyPendingInterest (Ptr<Face> inFace,
406 Ptr<pit::Entry> pitEntry)
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700407{
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700408 pit::Entry::out_iterator out = pitEntry->GetOutgoing ().find (inFace);
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800409
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700410 // If we have sent interest for this data via this face, then update stats.
411 if (out != pitEntry->GetOutgoing ().end ())
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700412 {
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700413 pitEntry->GetFibEntry ()->UpdateFaceRtt (inFace, Simulator::Now () - out->m_sendTime);
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800414 }
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700415
416 m_satisfiedInterests (pitEntry);
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700417}
418
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700419bool
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700420ForwardingStrategy::ShouldSuppressIncomingInterest (Ptr<Face> inFace,
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700421 Ptr<const Interest> interest,
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700422 Ptr<pit::Entry> pitEntry)
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700423{
424 bool isNew = pitEntry->GetIncoming ().size () == 0 && pitEntry->GetOutgoing ().size () == 0;
425
426 if (isNew) return false; // never suppress new interests
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800427
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700428 bool isRetransmitted = m_detectRetransmissions && // a small guard
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700429 DetectRetransmittedInterest (inFace, interest, pitEntry);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700430
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700431 if (pitEntry->GetOutgoing ().find (inFace) != pitEntry->GetOutgoing ().end ())
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700432 {
433 NS_LOG_DEBUG ("Non duplicate interests from the face we have sent interest to. Don't suppress");
434 // got a non-duplicate interest from the face we have sent interest to
435 // Probably, there is no point in waiting data from that face... Not sure yet
436
437 // If we're expecting data from the interface we got the interest from ("producer" asks us for "his own" data)
438 // Mark interface YELLOW, but keep a small hope that data will come eventually.
439
440 // ?? not sure if we need to do that ?? ...
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800441
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700442 // pitEntry->GetFibEntry ()->UpdateStatus (inFace, fib::FaceMetric::NDN_FIB_YELLOW);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700443 }
444 else
445 if (!isNew && !isRetransmitted)
446 {
447 return true;
448 }
449
450 return false;
451}
452
453void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700454ForwardingStrategy::PropagateInterest (Ptr<Face> inFace,
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700455 Ptr<const Interest> interest,
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700456 Ptr<pit::Entry> pitEntry)
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700457{
458 bool isRetransmitted = m_detectRetransmissions && // a small guard
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700459 DetectRetransmittedInterest (inFace, interest, pitEntry);
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800460
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700461 pitEntry->AddIncoming (inFace/*, interest->GetInterestLifetime ()*/);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700462 /// @todo Make lifetime per incoming interface
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700463 pitEntry->UpdateLifetime (interest->GetInterestLifetime ());
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800464
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700465 bool propagated = DoPropagateInterest (inFace, interest, pitEntry);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700466
467 if (!propagated && isRetransmitted) //give another chance if retransmitted
468 {
469 // increase max number of allowed retransmissions
470 pitEntry->IncreaseAllowedRetxCount ();
471
472 // try again
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700473 propagated = DoPropagateInterest (inFace, interest, pitEntry);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700474 }
475
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800476 // if (!propagated)
477 // {
478 // NS_LOG_DEBUG ("++++++++++++++++++++++++++++++++++++++++++++++++++++++");
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700479 // NS_LOG_DEBUG ("+++ Not propagated ["<< interest->GetName () <<"], but number of outgoing faces: " << pitEntry->GetOutgoing ().size ());
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800480 // NS_LOG_DEBUG ("++++++++++++++++++++++++++++++++++++++++++++++++++++++");
481 // }
482
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700483 // ForwardingStrategy will try its best to forward packet to at least one interface.
484 // If no interests was propagated, then there is not other option for forwarding or
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800485 // ForwardingStrategy failed to find it.
486 if (!propagated && pitEntry->AreAllOutgoingInVain ())
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700487 {
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700488 DidExhaustForwardingOptions (inFace, interest, pitEntry);
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700489 }
490}
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700491
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700492bool
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800493ForwardingStrategy::CanSendOutInterest (Ptr<Face> inFace,
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700494 Ptr<Face> outFace,
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700495 Ptr<const Interest> interest,
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700496 Ptr<pit::Entry> pitEntry)
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700497{
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800498 if (outFace == inFace)
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700499 {
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800500 // NS_LOG_DEBUG ("Same as incoming");
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700501 return false; // same face as incoming, don't forward
502 }
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800503
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700504 pit::Entry::out_iterator outgoing =
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700505 pitEntry->GetOutgoing ().find (outFace);
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700506
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700507 if (outgoing != pitEntry->GetOutgoing ().end ())
508 {
509 if (!m_detectRetransmissions)
510 return false; // suppress
511 else if (outgoing->m_retxCount >= pitEntry->GetMaxRetxCount ())
512 {
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800513 // NS_LOG_DEBUG ("Already forwarded before during this retransmission cycle (" <<outgoing->m_retxCount << " >= " << pitEntry->GetMaxRetxCount () << ")");
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700514 return false; // already forwarded before during this retransmission cycle
515 }
516 }
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800517
518 return true;
519}
520
521
522bool
523ForwardingStrategy::TrySendOutInterest (Ptr<Face> inFace,
524 Ptr<Face> outFace,
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700525 Ptr<const Interest> interest,
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800526 Ptr<pit::Entry> pitEntry)
527{
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700528 if (!CanSendOutInterest (inFace, outFace, interest, pitEntry))
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800529 {
530 return false;
531 }
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800532
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700533 pitEntry->AddOutgoing (outFace);
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700534
535 //transmission
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700536 bool successSend = outFace->SendInterest (interest);
Alexander Afanasyevd0887982013-03-18 11:47:58 -0600537 if (!successSend)
538 {
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700539 m_dropInterests (interest, outFace);
Alexander Afanasyevd0887982013-03-18 11:47:58 -0600540 }
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700541
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700542 DidSendOutInterest (inFace, outFace, interest, pitEntry);
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700543
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700544 return true;
545}
546
547void
Alexander Afanasyev67f4a4a2012-11-24 17:18:17 -0800548ForwardingStrategy::DidSendOutInterest (Ptr<Face> inFace,
549 Ptr<Face> outFace,
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700550 Ptr<const Interest> interest,
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700551 Ptr<pit::Entry> pitEntry)
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700552{
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700553 m_outInterests (interest, outFace);
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700554}
555
556void
Alexander Afanasyev67f4a4a2012-11-24 17:18:17 -0800557ForwardingStrategy::DidSendOutData (Ptr<Face> inFace,
558 Ptr<Face> outFace,
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700559 Ptr<const ContentObject> data,
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700560 Ptr<pit::Entry> pitEntry)
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -0700561{
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700562 m_outData (data, inFace == 0, outFace);
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -0700563}
564
565void
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700566ForwardingStrategy::WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry)
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700567{
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700568 m_timedOutInterests (pitEntry);
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700569}
570
Alexander Afanasyevf5c07742012-10-31 13:13:05 -0700571void
572ForwardingStrategy::AddFace (Ptr<Face> face)
573{
574 // do nothing here
575}
Alexander Afanasyev33364b62012-07-26 17:53:56 -0700576
577void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700578ForwardingStrategy::RemoveFace (Ptr<Face> face)
Alexander Afanasyev33364b62012-07-26 17:53:56 -0700579{
580 // do nothing here
581}
582
Alexander Afanasyevadcccf42012-11-26 23:55:34 -0800583void
584ForwardingStrategy::DidAddFibEntry (Ptr<fib::Entry> fibEntry)
585{
586 // do nothing here
587}
588
589void
590ForwardingStrategy::WillRemoveFibEntry (Ptr<fib::Entry> fibEntry)
591{
592 // do nothing here
593}
594
595
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700596} // namespace ndn
597} // namespace ns3