22 #include "ndn-forwarding-strategy.h"
24 #include "ns3/ndn-pit.h"
25 #include "ns3/ndn-pit-entry.h"
26 #include "ns3/ndn-interest.h"
27 #include "ns3/ndn-data.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"
33 #include "ns3/assert.h"
36 #include "ns3/simulator.h"
37 #include "ns3/boolean.h"
38 #include "ns3/string.h"
40 #include "ns3/ndnSIM/utils/ndn-fw-hop-count-tag.h"
42 #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>
47 namespace ll = boost::lambda;
52 NS_OBJECT_ENSURE_REGISTERED (ForwardingStrategy);
62 TypeId ForwardingStrategy::GetTypeId (
void)
64 static TypeId tid = TypeId (
"ns3::ndn::ForwardingStrategy")
85 .AddTraceSource (
"SatisfiedInterests",
"SatisfiedInterests", MakeTraceSourceAccessor (&ForwardingStrategy::m_satisfiedInterests))
86 .AddTraceSource (
"TimedOutInterests",
"TimedOutInterests", MakeTraceSourceAccessor (&ForwardingStrategy::m_timedOutInterests))
88 .AddAttribute (
"CacheUnsolicitedDataFromApps",
"Cache unsolicited data that has been pushed from applications",
90 MakeBooleanAccessor (&ForwardingStrategy::m_cacheUnsolicitedDataFromApps),
91 MakeBooleanChecker ())
93 .AddAttribute (
"CacheUnsolicitedData",
"Cache overheard data that have not been requested",
95 MakeBooleanAccessor (&ForwardingStrategy::m_cacheUnsolicitedData),
96 MakeBooleanChecker ())
98 .AddAttribute (
"DetectRetransmissions",
"If non-duplicate interest is received on the same face more than once, "
99 "it is considered a retransmission",
101 MakeBooleanAccessor (&ForwardingStrategy::m_detectRetransmissions),
102 MakeBooleanChecker ())
111 ForwardingStrategy::~ForwardingStrategy ()
120 m_pit = GetObject<Pit> ();
124 m_fib = GetObject<Fib> ();
131 Object::NotifyNewAggregate ();
141 Object::DoDispose ();
146 Ptr<Interest> interest)
148 NS_LOG_FUNCTION (inFace << interest->GetName ());
151 Ptr<pit::Entry> pitEntry =
m_pit->Lookup (*interest);
152 bool similarInterest =
true;
155 similarInterest =
false;
156 pitEntry =
m_pit->Create (interest);
168 bool isDuplicated =
true;
169 if (!pitEntry->IsNonceSeen (interest->GetNonce ()))
171 pitEntry->AddSeenNonce (interest->GetNonce ());
172 isDuplicated =
false;
181 Ptr<Data> contentObject;
183 if (contentObject != 0)
186 if (interest->GetPayload ()->PeekPacketTag (hopCountTag))
188 contentObject->GetPayload ()->AddPacketTag (hopCountTag);
191 pitEntry->AddIncoming (inFace);
203 pitEntry->AddIncoming (inFace);
205 pitEntry->UpdateLifetime (interest->GetInterestLifetime ());
208 NS_LOG_DEBUG (
"Suppress interests");
227 NS_LOG_FUNCTION (inFace << data->GetName ());
231 Ptr<pit::Entry> pitEntry =
m_pit->Lookup (*data);
236 if (m_cacheUnsolicitedData || (m_cacheUnsolicitedDataFromApps && (inFace->GetFlags () &
Face::APPLICATION)))
259 while (pitEntry != 0)
268 pitEntry =
m_pit->Lookup (*data);
274 Ptr<const Interest> interest,
275 Ptr<pit::Entry> pitEntrypitEntry)
281 Ptr<const Interest> interest)
288 Ptr<const Interest> interest,
289 Ptr<pit::Entry> pitEntry)
296 pitEntry->AddIncoming (inFace);
302 Ptr<const Interest> interest,
303 Ptr<pit::Entry> pitEntry)
309 Ptr<const Interest> interest,
310 Ptr<pit::Entry> pitEntry)
316 Ptr<const Interest> interest,
317 Ptr<pit::Entry> pitEntry)
319 NS_LOG_FUNCTION (
this << boost::cref (*inFace));
320 if (pitEntry->AreAllOutgoingInVain ())
325 pitEntry->ClearIncoming ();
328 pitEntry->ClearOutgoing ();
331 m_pit->MarkErased (pitEntry);
339 Ptr<const Interest> interest,
340 Ptr<pit::Entry> pitEntry)
344 bool isRetransmitted =
false;
346 if (existingInFace != pitEntry->GetIncoming ().end ())
349 isRetransmitted =
true;
352 return isRetransmitted;
357 Ptr<const Data> data,
358 Ptr<pit::Entry> pitEntry)
361 pitEntry->RemoveIncoming (inFace);
366 bool ok = incoming.
m_face->SendData (data);
369 NS_LOG_DEBUG (
"Satisfy " << *incoming.
m_face);
374 NS_LOG_DEBUG (
"Cannot satisfy data to " << *incoming.
m_face);
379 pitEntry->ClearIncoming ();
382 pitEntry->ClearOutgoing ();
385 m_pit->MarkErased (pitEntry);
390 Ptr<const Data> data,
391 bool didCreateCacheEntry)
398 Ptr<const Data> data,
399 bool didCreateCacheEntry)
406 Ptr<pit::Entry> pitEntry)
411 if (out != pitEntry->GetOutgoing ().end ())
413 pitEntry->GetFibEntry ()->UpdateFaceRtt (inFace, Simulator::Now () - out->m_sendTime);
416 m_satisfiedInterests (pitEntry);
421 Ptr<const Interest> interest,
422 Ptr<pit::Entry> pitEntry)
424 bool isNew = pitEntry->GetIncoming ().size () == 0 && pitEntry->GetOutgoing ().size () == 0;
426 if (isNew)
return false;
428 bool isRetransmitted = m_detectRetransmissions &&
431 if (pitEntry->GetOutgoing ().find (inFace) != pitEntry->GetOutgoing ().end ())
433 NS_LOG_DEBUG (
"Non duplicate interests from the face we have sent interest to. Don't suppress");
445 if (!isNew && !isRetransmitted)
455 Ptr<const Interest> interest,
456 Ptr<pit::Entry> pitEntry)
458 bool isRetransmitted = m_detectRetransmissions &&
461 pitEntry->AddIncoming (inFace);
463 pitEntry->UpdateLifetime (interest->GetInterestLifetime ());
467 if (!propagated && isRetransmitted)
470 pitEntry->IncreaseAllowedRetxCount ();
486 if (!propagated && pitEntry->AreAllOutgoingInVain ())
495 Ptr<const Interest> interest,
496 Ptr<pit::Entry> pitEntry)
498 if (outFace == inFace)
505 pitEntry->GetOutgoing ().find (outFace);
507 if (outgoing != pitEntry->GetOutgoing ().end ())
509 if (!m_detectRetransmissions)
511 else if (outgoing->m_retxCount >= pitEntry->GetMaxRetxCount ())
525 Ptr<const Interest> interest,
526 Ptr<pit::Entry> pitEntry)
533 pitEntry->AddOutgoing (outFace);
536 bool successSend = outFace->SendInterest (interest);
550 Ptr<const Interest> interest,
551 Ptr<pit::Entry> pitEntry)
559 Ptr<const Data> data,
560 Ptr<pit::Entry> pitEntry)
568 m_timedOutInterests (pitEntry);
virtual bool DetectRetransmittedInterest(Ptr< Face > inFace, Ptr< const Interest > interest, Ptr< pit::Entry > pitEntry)
Method that implements logic to distinguish between new and retransmitted interest.
virtual void FailedToCreatePitEntry(Ptr< Face > inFace, Ptr< const Interest > interest)
An event that is fired every time a new PIT entry cannot be created (e.g., PIT container imposes a li...
virtual void OnInterest(Ptr< Face > face, Ptr< Interest > interest)
Actual processing of incoming Ndn interests.
TracedCallback< Ptr< const Interest >, Ptr< const Face > > m_outInterests
Transmitted interests trace.
virtual bool CanSendOutInterest(Ptr< Face > inFace, Ptr< Face > outFace, Ptr< const Interest > interest, Ptr< pit::Entry > pitEntry)
Method to check whether Interest can be send out on the particular face or not.
virtual bool DoPropagateInterest(Ptr< Face > inFace, Ptr< const Interest > interest, Ptr< pit::Entry > pitEntry)=0
Virtual method to perform Interest propagation according to the forwarding strategy logic...
virtual void DidReceiveSolicitedData(Ptr< Face > inFace, Ptr< const Data > data, bool didCreateCacheEntry)
Event which is fired every time a requested (solicited) DATA packet (there is an active PIT entry) is...
virtual void DidExhaustForwardingOptions(Ptr< Face > inFace, Ptr< const Interest > interest, Ptr< pit::Entry > pitEntry)
An even that is fired when Interest cannot be forwarded.
virtual void DidReceiveUnsolicitedData(Ptr< Face > inFace, Ptr< const Data > data, bool didCreateCacheEntry)
Event which is fired every time an unsolicited DATA packet (no active PIT entry) is received...
virtual void WillSatisfyPendingInterest(Ptr< Face > inFace, Ptr< pit::Entry > pitEntry)
Even fired just before Interest will be satisfied.
Ptr< Face > m_face
face of the incoming Interest
virtual void NotifyNewAggregate()
Even when object is aggregated to another Object.
virtual void DidSuppressSimilarInterest(Ptr< Face > inFace, Ptr< const Interest > interest, Ptr< pit::Entry > pitEntry)
An event that is fired every time when a similar Interest is received and suppressed (collapsed) ...
static std::string GetLogName()
Helper function to retrieve logging name for the forwarding strategy.
virtual void DidSendOutData(Ptr< Face > inFace, Ptr< Face > outFace, Ptr< const Data > data, Ptr< pit::Entry > pitEntry)
Event which is fired just after data was send out on the face.
in_container::iterator in_iterator
iterator to incoming faces
virtual void DidReceiveDuplicateInterest(Ptr< Face > inFace, Ptr< const Interest > interest, Ptr< pit::Entry > pitEntry)
An event that is fired every time a duplicated Interest is received.
virtual bool ShouldSuppressIncomingInterest(Ptr< Face > inFace, Ptr< const Interest > interest, Ptr< pit::Entry > pitEntry)
Method implementing logic to suppress (collapse) similar Interests.
TracedCallback< Ptr< const Data >, bool, Ptr< const Face > > m_outData
trace of outgoing Data
virtual void WillEraseTimedOutPendingInterest(Ptr< pit::Entry > pitEntry)
Event fired just before PIT entry is removed by timeout.
TracedCallback< Ptr< const Interest >, Ptr< const Face > > m_dropInterests
trace of dropped Interests
virtual void RemoveFace(Ptr< Face > face)
Event fired every time face is removed from NDN stack.
virtual void DoDispose()
Do cleanup.
virtual void DidSendOutInterest(Ptr< Face > inFace, Ptr< Face > outFace, Ptr< const Interest > interest, Ptr< pit::Entry > pitEntry)
Event fired just after forwarding the Interest.
TracedCallback< Ptr< const Data >, Ptr< const Face > > m_dropData
trace of dropped Data
ForwardingStrategy()
Default constructor.
virtual void DidCreatePitEntry(Ptr< Face > inFace, Ptr< const Interest > interest, Ptr< pit::Entry > pitEntry)
An event that is fired every time a new PIT entry is created.
virtual void OnData(Ptr< Face > face, Ptr< Data > data)
Actual processing of incoming Ndn content objects.
virtual void PropagateInterest(Ptr< Face > inFace, Ptr< const Interest > interest, Ptr< pit::Entry > pitEntry)
Wrapper method, which performs general tasks and calls DoPropagateInterest method.
virtual void WillRemoveFibEntry(Ptr< fib::Entry > fibEntry)
Fired just before FIB entry will be removed from FIB.
Ptr< ContentStore > m_contentStore
Content store (for caching purposes only)
virtual void DidAddFibEntry(Ptr< fib::Entry > fibEntry)
Event fired every time a FIB entry is added to FIB.
Ptr< Pit > m_pit
Reference to PIT to which this forwarding strategy is associated.
Packet tag that is used to track hop count for Interest-Data pairs.
TracedCallback< Ptr< const Interest >, Ptr< const Face > > m_inInterests
trace of incoming Interests
virtual void DidForwardSimilarInterest(Ptr< Face > inFace, Ptr< const Interest > interest, Ptr< pit::Entry > pitEntry)
An event that is fired every time when a similar Interest is received and further forwarded (not supp...
virtual void AddFace(Ptr< Face > face)
Event fired every time face is added to NDN stack.
virtual bool TrySendOutInterest(Ptr< Face > inFace, Ptr< Face > outFace, Ptr< const Interest > interest, Ptr< pit::Entry > pitEntry)
Method implementing actual interest forwarding, taking into account CanSendOutInterest decision...
TracedCallback< Ptr< const Data >, Ptr< const Face > > m_inData
trace of incoming Data
out_container::iterator out_iterator
iterator to outgoing faces
virtual void SatisfyPendingInterest(Ptr< Face > inFace, Ptr< const Data > data, Ptr< pit::Entry > pitEntry)
Actual procedure to satisfy Interest.
PIT state component for each incoming interest (not including duplicates)