Serious refactoring. Making forwarding strategy really modular
diff --git a/model/forwarding-strategy/ccnx-bestroute-strategy.cc b/model/forwarding-strategy/best-route.cc
similarity index 77%
rename from model/forwarding-strategy/ccnx-bestroute-strategy.cc
rename to model/forwarding-strategy/best-route.cc
index 75efdd4..33d9cde 100644
--- a/model/forwarding-strategy/ccnx-bestroute-strategy.cc
+++ b/model/forwarding-strategy/best-route.cc
@@ -19,7 +19,7 @@
* Ilya Moiseenko <iliamo@cs.ucla.edu>
*/
-#include "ccnx-bestroute-strategy.h"
+#include "best-route.h"
#include "ns3/ccnx-interest-header.h"
#include "ns3/ccnx-pit.h"
@@ -33,41 +33,41 @@
#include <boost/lambda/bind.hpp>
namespace ll = boost::lambda;
-NS_LOG_COMPONENT_DEFINE ("CcnxBestRouteStrategy");
+NS_LOG_COMPONENT_DEFINE ("NdnSimBestRoute");
-namespace ns3
-{
+namespace ns3 {
+namespace ndnSIM {
using namespace __ccnx_private;
-NS_OBJECT_ENSURE_REGISTERED (CcnxBestRouteStrategy);
+NS_OBJECT_ENSURE_REGISTERED (BestRoute);
-TypeId CcnxBestRouteStrategy::GetTypeId (void)
+TypeId
+BestRoute::GetTypeId (void)
{
- static TypeId tid = TypeId ("ns3::CcnxBestRouteStrategy")
+ static TypeId tid = TypeId ("ns3::ndnSIM::BestRoute")
.SetGroupName ("Ccnx")
- .SetParent <CcnxForwardingStrategy> ()
- .AddConstructor <CcnxBestRouteStrategy> ()
+ .SetParent <GreenYellowRed> ()
+ .AddConstructor <BestRoute> ()
;
return tid;
}
-CcnxBestRouteStrategy::CcnxBestRouteStrategy ()
+BestRoute::BestRoute ()
{
}
bool
-CcnxBestRouteStrategy::PropagateInterest (Ptr<CcnxPitEntry> pitEntry,
- const Ptr<CcnxFace> &incomingFace,
- Ptr<CcnxInterestHeader> &header,
- const Ptr<const Packet> &packet)
+BestRoute::DoPropagateInterest (const Ptr<CcnxFace> &incomingFace,
+ Ptr<CcnxInterestHeader> &header,
+ const Ptr<const Packet> &packet,
+ Ptr<CcnxPitEntry> pitEntry)
{
NS_LOG_FUNCTION (this);
-
// Try to work out with just green faces
- bool greenOk = PropagateInterestViaGreen (pitEntry, incomingFace, header, packet);
+ bool greenOk = super::DoPropagateInterest (incomingFace, header, packet, pitEntry);
if (greenOk)
return true;
@@ -115,5 +115,6 @@
NS_LOG_INFO ("Propagated to " << propagatedCount << " faces");
return propagatedCount > 0;
}
-
-} //namespace ns3
+
+} // namespace ndnSIM
+} // namespace ns3
diff --git a/model/forwarding-strategy/best-route.h b/model/forwarding-strategy/best-route.h
new file mode 100644
index 0000000..aec1147
--- /dev/null
+++ b/model/forwarding-strategy/best-route.h
@@ -0,0 +1,61 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ * Ilya Moiseenko <iliamo@cs.ucla.edu>
+ */
+
+
+#ifndef NDNSIM_BEST_ROUTE_H
+#define NDNSIM_BEST_ROUTE_H
+
+#include "green-yellow-red.h"
+
+namespace ns3 {
+namespace ndnSIM {
+
+/**
+ * \ingroup ccnx
+ * \brief Best route strategy
+ */
+class BestRoute :
+ public GreenYellowRed
+{
+public:
+ static TypeId
+ GetTypeId (void);
+
+ /**
+ * @brief Default constructor
+ */
+ BestRoute ();
+
+ // inherited from CcnxForwardingStrategy
+ virtual bool
+ DoPropagateInterest (const Ptr<CcnxFace> &incomingFace,
+ Ptr<CcnxInterestHeader> &header,
+ const Ptr<const Packet> &packet,
+ Ptr<CcnxPitEntry> pitEntry);
+
+private:
+ typedef GreenYellowRed super;
+};
+
+} // namespace ndnSIM
+} // namespace ns3
+
+#endif // NDNSIM_BEST_ROUTE_H
diff --git a/model/forwarding-strategy/ccnx-bestroute-strategy.h b/model/forwarding-strategy/ccnx-bestroute-strategy.h
deleted file mode 100644
index 6768da6..0000000
--- a/model/forwarding-strategy/ccnx-bestroute-strategy.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2011 University of California, Los Angeles
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author: Ilya Moiseenko <iliamo@cs.ucla.edu>
- */
-
-
-#ifndef CCNX_BESTROUTE_STRATEGY_H
-#define CCNX_BESTROUTE_STRATEGY_H
-
-#include "ccnx-forwarding-strategy.h"
-
-namespace ns3
-{
-
-class CcnxFace;
-class CcnxInterestHeader;
-
-/**
- * \ingroup ccnx
- * \brief Best route strategy
- *
- * \todo Describe
- */
-class CcnxBestRouteStrategy : public CcnxForwardingStrategy
-{
-public:
- static TypeId GetTypeId (void);
-
- /**
- * @brief Default constructor
- */
- CcnxBestRouteStrategy ();
-
- // inherited from CcnxForwardingStrategy
- virtual bool
- PropagateInterest (Ptr<CcnxPitEntry> pitEntry,
- const Ptr<CcnxFace> &incomingFace,
- Ptr<CcnxInterestHeader> &header,
- const Ptr<const Packet> &packet);
-};
-
-} //namespace ns3
-
-#endif /* CCNX_BESTROUTE_STRATEGY_H */
diff --git a/model/forwarding-strategy/ccnx-forwarding-strategy.cc b/model/forwarding-strategy/ccnx-forwarding-strategy.cc
index 9cdfa4d..3d6f3de 100644
--- a/model/forwarding-strategy/ccnx-forwarding-strategy.cc
+++ b/model/forwarding-strategy/ccnx-forwarding-strategy.cc
@@ -67,26 +67,20 @@
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
- .AddTraceSource ("OutNacks", "OutNacks", MakeTraceSourceAccessor (&CcnxForwardingStrategy::m_outNacks))
- .AddTraceSource ("InNacks", "InNacks", MakeTraceSourceAccessor (&CcnxForwardingStrategy::m_inNacks))
- .AddTraceSource ("DropNacks", "DropNacks", MakeTraceSourceAccessor (&CcnxForwardingStrategy::m_dropNacks))
-
- ////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////
-
.AddTraceSource ("OutData", "OutData", MakeTraceSourceAccessor (&CcnxForwardingStrategy::m_outData))
.AddTraceSource ("InData", "InData", MakeTraceSourceAccessor (&CcnxForwardingStrategy::m_inData))
.AddTraceSource ("DropData", "DropData", MakeTraceSourceAccessor (&CcnxForwardingStrategy::m_dropData))
- .AddAttribute ("EnableNACKs", "Enabling support of NACKs",
- BooleanValue (false),
- MakeBooleanAccessor (&CcnxForwardingStrategy::m_nacksEnabled),
- MakeBooleanChecker ())
.AddAttribute ("CacheUnsolicitedData", "Cache overheard data that have not been requested",
BooleanValue (false),
MakeBooleanAccessor (&CcnxForwardingStrategy::m_cacheUnsolicitedData),
MakeBooleanChecker ())
+ .AddAttribute ("DetectRetransmissions", "If non-duplicate interest is received on the same face more than once, "
+ "it is considered a retransmission",
+ BooleanValue (true),
+ MakeBooleanAccessor (&CcnxForwardingStrategy::m_detectRetransmissions),
+ MakeBooleanChecker ())
;
return tid;
}
@@ -139,16 +133,17 @@
if (pitEntry == 0)
{
pitEntry = m_pit->Create (header);
+ if (pitEntry != 0)
+ {
+ DidCreatePitEntry (incomingFace, header, packet, pitEntry);
+ }
+ else
+ {
+ FailedToCreatePitEntry (incomingFace, header, packet);
+ return;
+ }
}
- if (pitEntry == 0)
- {
- // if it is still not created, then give up processing
- m_dropInterests (header, incomingFace);
- return;
- }
-
- bool isNew = pitEntry->GetIncoming ().size () == 0 && pitEntry->GetOutgoing ().size () == 0;
bool isDuplicated = true;
if (!pitEntry->IsNonceSeen (header->GetNonce ()))
{
@@ -156,61 +151,9 @@
isDuplicated = false;
}
- NS_LOG_FUNCTION (header->GetName () << header->GetNonce () << boost::cref (*incomingFace) << isDuplicated);
-
- /////////////////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////////////////
- // //
- // !!!! IMPORTANT CHANGE !!!! Duplicate interests will create incoming face entry !!!! //
- // //
- /////////////////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////////////////
-
- // Data is not in cache
- CcnxPitEntry::in_iterator inFace = pitEntry->GetIncoming ().find (incomingFace);
- CcnxPitEntry::out_iterator outFace = pitEntry->GetOutgoing ().find (incomingFace);
-
- bool isRetransmitted = false;
-
- if (inFace != pitEntry->GetIncoming ().end ())
- {
- // CcnxPitEntryIncomingFace.m_arrivalTime keeps track arrival time of the first packet... why?
-
- isRetransmitted = true;
- // this is almost definitely a retransmission. But should we trust the user on that?
- }
- else
- {
- inFace = pitEntry->AddIncoming (incomingFace);
- }
- //////////////////////////////////////////////////////////////////////////////////
- //////////////////////////////////////////////////////////////////////////////////
- //////////////////////////////////////////////////////////////////////////////////
-
if (isDuplicated)
{
- NS_LOG_DEBUG ("Received duplicatie interest on " << *incomingFace);
- m_dropInterests (header, incomingFace);
-
- /**
- * This condition will handle "routing" loops and also recently satisfied interests.
- * Every time interest is satisfied, PIT entry (with empty incoming and outgoing faces)
- * is kept for another small chunk of time.
- */
-
- if (m_nacksEnabled)
- {
- NS_LOG_DEBUG ("Sending NACK_LOOP");
- header->SetNack (CcnxInterestHeader::NACK_LOOP);
- Ptr<Packet> nack = Create<Packet> ();
- nack->AddHeader (*header);
-
- incomingFace->Send (nack);
- m_outNacks (header, incomingFace);
- }
-
+ DidReceiveDuplicateInterest (incomingFace, header, packet, pitEntry);
return;
}
@@ -221,64 +164,25 @@
if (contentObject != 0)
{
NS_ASSERT (contentObjectHeader != 0);
- NS_LOG_LOGIC("Found in cache");
- OnDataDelayed (contentObjectHeader, payload, contentObject);
+ pitEntry->AddIncoming (incomingFace/*, Seconds (1.0)*/);
+ SatisfyPendingInterest (0, contentObjectHeader, payload, contentObject, pitEntry);
return;
}
- // update PIT entry lifetime
- pitEntry->UpdateLifetime (header->GetInterestLifetime ());
-
- if (outFace != pitEntry->GetOutgoing ().end ())
+ if (ShouldSuppressIncomingInterest (incomingFace, pitEntry))
{
- NS_LOG_DEBUG ("Non duplicate interests from the face we have sent interest to. Don't suppress");
- // got a non-duplicate interest from the face we have sent interest to
- // Probably, there is no point in waiting data from that face... Not sure yet
+ pitEntry->AddIncoming (incomingFace/*, header->GetInterestLifetime ()*/);
+ // update PIT entry lifetime
+ pitEntry->UpdateLifetime (header->GetInterestLifetime ());
- // If we're expecting data from the interface we got the interest from ("producer" asks us for "his own" data)
- // Mark interface YELLOW, but keep a small hope that data will come eventually.
-
- // ?? not sure if we need to do that ?? ...
-
- pitEntry->GetFibEntry ()->UpdateStatus (incomingFace, CcnxFibFaceMetric::NDN_FIB_YELLOW);
- // StaticCast<CcnxFibImpl> (m_fib)->modify(pitEntry->GetFibEntry (),
- // ll::bind (&CcnxFibEntry::UpdateStatus,
- // ll::_1, incomingFace, CcnxFibFaceMetric::NDN_FIB_YELLOW));
- }
- else
- if (!isNew && !isRetransmitted)
- {
- // Suppress this interest if we're still expecting data from some other face
- NS_LOG_DEBUG ("Suppress interests");
- m_dropInterests (header, incomingFace);
- return;
- }
-
- /////////////////////////////////////////////////////////////////////
- // Propagate
- /////////////////////////////////////////////////////////////////////
-
- bool propagated = PropagateInterest (pitEntry, incomingFace, header, packet);
-
- if (!propagated && isRetransmitted) //give another chance if retransmitted
- {
- // increase max number of allowed retransmissions
- pitEntry->IncreaseAllowedRetxCount ();
-
- // try again
- propagated = PropagateInterest (pitEntry, incomingFace, header, packet);
- }
-
- // ForwardingStrategy will try its best to forward packet to at least one interface.
- // If no interests was propagated, then there is not other option for forwarding or
- // ForwardingStrategy failed to find it.
- if (!propagated)
- {
- NS_LOG_DEBUG ("Not propagated");
+ // Suppress this interest if we're still expecting data from some other face
+ NS_LOG_DEBUG ("Suppress interests");
m_dropInterests (header, incomingFace);
- GiveUpInterest (pitEntry, header);
+ return;
}
+
+ PropagateInterest (incomingFace, header, packet, pitEntry);
}
void
@@ -290,205 +194,220 @@
NS_LOG_FUNCTION (incomingFace << header->GetName () << payload << packet);
m_inData (header, payload, incomingFace);
- // 1. Lookup PIT entry
+ // Lookup PIT entry
Ptr<CcnxPitEntry> pitEntry = m_pit->Lookup (*header);
- if (pitEntry != 0)
+ if (pitEntry == 0)
{
- // Note that with MultiIndex we need to modify entries indirectly
-
- CcnxPitEntry::out_iterator out = pitEntry->GetOutgoing ().find (incomingFace);
-
- // If we have sent interest for this data via this face, then update stats.
- if (out != pitEntry->GetOutgoing ().end ())
- {
- pitEntry->GetFibEntry ()->UpdateFaceRtt (incomingFace, Simulator::Now () - out->m_sendTime);
- // StaticCast<CcnxFibImpl> (m_fib)->modify (pitEntry->GetFibEntry (),
- // ll::bind (&CcnxFibEntry::UpdateFaceRtt,
- // ll::_1,
- // incomingFace,
- // Simulator::Now () - out->m_sendTime));
- }
- else
- {
- // Unsolicited data, but we're interested in it... should we get it?
- // Potential hole for attacks
-
- if (m_cacheUnsolicitedData)
- {
- // Optimistically add or update entry in the content store
- m_contentStore->Add (header, payload);
- }
- else
- {
- NS_LOG_ERROR ("PIT entry for "<< header->GetName ()<<" is valid, "
- "but outgoing entry for interface "<< boost::cref(*incomingFace) <<" doesn't exist\n");
- }
- // ignore unsolicited data
- return;
- }
-
- // Update metric status for the incoming interface in the corresponding FIB entry
- pitEntry->GetFibEntry ()->UpdateStatus (incomingFace, CcnxFibFaceMetric::NDN_FIB_GREEN);
- // StaticCast<CcnxFibImpl>(m_fib)->modify (pitEntry->GetFibEntry (),
- // ll::bind (&CcnxFibEntry::UpdateStatus, ll::_1,
- // incomingFace, CcnxFibFaceMetric::NDN_FIB_GREEN));
-
+ DidReceiveUnsolicitedData (incomingFace, header, payload);
+ return;
+ }
+ else
+ {
// Add or update entry in the content store
m_contentStore->Add (header, payload);
-
- pitEntry->RemoveIncoming (incomingFace);
-
- if (pitEntry->GetIncoming ().size () == 0)
- {
- // Set pruning timout on PIT entry (instead of deleting the record)
- m_pit->MarkErased (pitEntry);
- }
- else
- {
- OnDataDelayed (header, payload, packet);
- }
}
- else
+
+ while (pitEntry != 0)
{
- NS_LOG_DEBUG ("Pit entry not found");
- if (m_cacheUnsolicitedData)
- {
- // Optimistically add or update entry in the content store
- m_contentStore->Add (header, payload);
- }
- else
- {
- // Drop data packet if PIT entry is not found
- // (unsolicited data packets should not "poison" content store)
-
- //drop dulicated or not requested data packet
- m_dropData (header, payload, incomingFace);
- }
- return; // do not process unsoliced data packets
+ // Do data plane performance measurements
+ WillSatisfyPendingInterest (incomingFace, pitEntry);
+
+ // Actually satisfy pending interest
+ SatisfyPendingInterest (incomingFace, header, payload, packet, pitEntry);
+
+ // Lookup another PIT entry
+ pitEntry = m_pit->Lookup (*header);
}
}
+void
+CcnxForwardingStrategy::DidReceiveDuplicateInterest (const Ptr<CcnxFace> &incomingFace,
+ Ptr<CcnxInterestHeader> &header,
+ const Ptr<const Packet> &packet,
+ Ptr<CcnxPitEntry> pitEntry)
+{
+ NS_LOG_FUNCTION (this << *incomingFace);
+ /////////////////////////////////////////////////////////////////////////////////////////
+ // //
+ // !!!! IMPORTANT CHANGE !!!! Duplicate interests will create incoming face entry !!!! //
+ // //
+ /////////////////////////////////////////////////////////////////////////////////////////
+ pitEntry->AddIncoming (incomingFace);
+ m_dropInterests (header, incomingFace);
+}
+
+void
+CcnxForwardingStrategy::DidExhaustForwardingOptions (const Ptr<CcnxFace> &incomingFace,
+ Ptr<CcnxInterestHeader> header,
+ const Ptr<const Packet> &packet,
+ Ptr<CcnxPitEntry> pitEntry)
+{
+ NS_LOG_FUNCTION (this << *incomingFace);
+ m_dropInterests (header, incomingFace);
+}
+
+void
+CcnxForwardingStrategy::FailedToCreatePitEntry (const Ptr<CcnxFace> &incomingFace,
+ Ptr<CcnxInterestHeader> header,
+ const Ptr<const Packet> &packet)
+{
+ NS_LOG_FUNCTION (this);
+ m_dropInterests (header, incomingFace);
+}
+
+void
+CcnxForwardingStrategy::DidCreatePitEntry (const Ptr<CcnxFace> &incomingFace,
+ Ptr<CcnxInterestHeader> header,
+ const Ptr<const Packet> &packet,
+ Ptr<CcnxPitEntry> pitEntrypitEntry)
+{
+}
+
bool
-CcnxForwardingStrategy::PropagateInterestViaGreen (Ptr<CcnxPitEntry> pitEntry,
- const Ptr<CcnxFace> &incomingFace,
- Ptr<CcnxInterestHeader> &header,
- const Ptr<const Packet> &packet)
+CcnxForwardingStrategy::DetectRetransmittedInterest (const Ptr<CcnxFace> &incomingFace,
+ Ptr<CcnxPitEntry> pitEntry)
{
- NS_LOG_FUNCTION (this);
- NS_ASSERT_MSG (m_pit != 0, "PIT should be aggregated with forwarding strategy");
+ CcnxPitEntry::in_iterator inFace = pitEntry->GetIncoming ().find (incomingFace);
- int propagatedCount = 0;
+ bool isRetransmitted = false;
- BOOST_FOREACH (const CcnxFibFaceMetric &metricFace, pitEntry->GetFibEntry ()->m_faces.get<i_metric> ())
+ if (inFace != pitEntry->GetIncoming ().end ())
{
- if (metricFace.m_status == CcnxFibFaceMetric::NDN_FIB_RED ||
- metricFace.m_status == CcnxFibFaceMetric::NDN_FIB_YELLOW)
- break; //propagate only to green faces
-
- if (pitEntry->GetIncoming ().find (metricFace.m_face) != pitEntry->GetIncoming ().end ())
- continue; // don't forward to face that we received interest from
-
- CcnxPitEntryOutgoingFaceContainer::type::iterator outgoing =
- pitEntry->GetOutgoing ().find (metricFace.m_face);
-
- if (outgoing != pitEntry->GetOutgoing ().end () &&
- outgoing->m_retxCount >= pitEntry->GetMaxRetxCount ())
- {
- NS_LOG_DEBUG ("retxCount: " << outgoing->m_retxCount << ", maxRetxCount: " << pitEntry->GetMaxRetxCount ());
- continue;
- }
-
- bool faceAvailable = metricFace.m_face->IsBelowLimit ();
- if (!faceAvailable) // huh...
- {
- // let's try different green face
- continue;
- }
-
- pitEntry->AddOutgoing (metricFace.m_face);
-
- Ptr<Packet> packetToSend = packet->Copy ();
-
- //transmission
- metricFace.m_face->Send (packetToSend);
- m_outInterests (header, metricFace.m_face);
-
- propagatedCount++;
- break; // propagate only one interest
+ // this is almost definitely a retransmission. But should we trust the user on that?
+ isRetransmitted = true;
}
- return propagatedCount > 0;
+ return isRetransmitted;
}
void
-CcnxForwardingStrategy::OnDataDelayed (Ptr<const CcnxContentObjectHeader> header,
- Ptr<const Packet> payload,
- const Ptr<const Packet> &packet)
+CcnxForwardingStrategy::SatisfyPendingInterest (const Ptr<CcnxFace> &incomingFace,
+ Ptr<const CcnxContentObjectHeader> header,
+ Ptr<const Packet> payload,
+ const Ptr<const Packet> &packet,
+ Ptr<CcnxPitEntry> pitEntry)
{
- // 1. Lookup PIT entry
- Ptr<CcnxPitEntry> pitEntry = m_pit->Lookup (*header);
- if (pitEntry != 0)
+ if (incomingFace != 0)
+ pitEntry->RemoveIncoming (incomingFace);
+
+ //satisfy all pending incoming Interests
+ BOOST_FOREACH (const CcnxPitEntryIncomingFace &incoming, pitEntry->GetIncoming ())
{
- //satisfy all pending incoming Interests
- BOOST_FOREACH (const CcnxPitEntryIncomingFace &incoming, pitEntry->GetIncoming ())
- {
- incoming.m_face->Send (packet->Copy ());
- m_outData (header, payload, false, incoming.m_face);
- NS_LOG_DEBUG ("Satisfy " << *incoming.m_face);
+ incoming.m_face->Send (packet->Copy ());
+ m_outData (header, payload, false, incoming.m_face);
+ NS_LOG_DEBUG ("Satisfy " << *incoming.m_face);
- // successfull forwarded data trace
- }
+ // successfull forwarded data trace
+ }
- if (pitEntry->GetIncoming ().size () > 0)
- {
- // All incoming interests are satisfied. Remove them
- pitEntry->ClearIncoming ();
+ // All incoming interests are satisfied. Remove them
+ pitEntry->ClearIncoming ();
- // Remove all outgoing faces
- pitEntry->ClearOutgoing ();
+ // Remove all outgoing faces
+ pitEntry->ClearOutgoing ();
- // Set pruning timout on PIT entry (instead of deleting the record)
- m_pit->MarkErased (pitEntry);
- }
+ // Set pruning timout on PIT entry (instead of deleting the record)
+ m_pit->MarkErased (pitEntry);
+}
+
+void
+CcnxForwardingStrategy::DidReceiveUnsolicitedData (const Ptr<CcnxFace> &incomingFace,
+ Ptr<const CcnxContentObjectHeader> header,
+ Ptr<const Packet> payload)
+{
+ if (m_cacheUnsolicitedData)
+ {
+ // Optimistically add or update entry in the content store
+ m_contentStore->Add (header, payload);
}
else
{
- NS_LOG_DEBUG ("Pit entry not found (was satisfied and removed before)");
- return; // do not process unsoliced data packets
+ // Drop data packet if PIT entry is not found
+ // (unsolicited data packets should not "poison" content store)
+
+ //drop dulicated or not requested data packet
+ m_dropData (header, payload, incomingFace);
}
}
void
-CcnxForwardingStrategy::GiveUpInterest (Ptr<CcnxPitEntry> pitEntry,
- Ptr<CcnxInterestHeader> header)
+CcnxForwardingStrategy::WillSatisfyPendingInterest (const Ptr<CcnxFace> &incomingFace,
+ Ptr<CcnxPitEntry> pitEntry)
{
- NS_LOG_FUNCTION (this);
-
- if (m_nacksEnabled)
+ CcnxPitEntry::out_iterator out = pitEntry->GetOutgoing ().find (incomingFace);
+
+ // If we have sent interest for this data via this face, then update stats.
+ if (out != pitEntry->GetOutgoing ().end ())
{
- Ptr<Packet> packet = Create<Packet> ();
- header->SetNack (CcnxInterestHeader::NACK_GIVEUP_PIT);
- packet->AddHeader (*header);
-
- BOOST_FOREACH (const CcnxPitEntryIncomingFace &incoming, pitEntry->GetIncoming ())
- {
- NS_LOG_DEBUG ("Send NACK for " << boost::cref (header->GetName ()) << " to " << boost::cref (*incoming.m_face));
- incoming.m_face->Send (packet->Copy ());
-
- m_outNacks (header, incoming.m_face);
- }
-
- // All incoming interests cannot be satisfied. Remove them
- pitEntry->ClearIncoming ();
-
- // Remove also outgoing
- pitEntry->ClearOutgoing ();
-
- // Set pruning timout on PIT entry (instead of deleting the record)
- m_pit->MarkErased (pitEntry);
- }
+ pitEntry->GetFibEntry ()->UpdateFaceRtt (incomingFace, Simulator::Now () - out->m_sendTime);
+ }
}
+bool
+CcnxForwardingStrategy::ShouldSuppressIncomingInterest (const Ptr<CcnxFace> &incomingFace,
+ Ptr<CcnxPitEntry> pitEntry)
+{
+ bool isNew = pitEntry->GetIncoming ().size () == 0 && pitEntry->GetOutgoing ().size () == 0;
+
+ if (isNew) return false; // never suppress new interests
+
+ bool isRetransmitted = m_detectRetransmissions && // a small guard
+ DetectRetransmittedInterest (incomingFace, pitEntry);
+
+ if (pitEntry->GetOutgoing ().find (incomingFace) != pitEntry->GetOutgoing ().end ())
+ {
+ NS_LOG_DEBUG ("Non duplicate interests from the face we have sent interest to. Don't suppress");
+ // got a non-duplicate interest from the face we have sent interest to
+ // Probably, there is no point in waiting data from that face... Not sure yet
+
+ // If we're expecting data from the interface we got the interest from ("producer" asks us for "his own" data)
+ // Mark interface YELLOW, but keep a small hope that data will come eventually.
+
+ // ?? not sure if we need to do that ?? ...
+
+ // pitEntry->GetFibEntry ()->UpdateStatus (incomingFace, CcnxFibFaceMetric::NDN_FIB_YELLOW);
+ }
+ else
+ if (!isNew && !isRetransmitted)
+ {
+ return true;
+ }
+
+ return false;
+}
+
+void
+CcnxForwardingStrategy::PropagateInterest (const Ptr<CcnxFace> &incomingFace,
+ Ptr<CcnxInterestHeader> &header,
+ const Ptr<const Packet> &packet,
+ Ptr<CcnxPitEntry> pitEntry)
+{
+ bool isRetransmitted = m_detectRetransmissions && // a small guard
+ DetectRetransmittedInterest (incomingFace, pitEntry);
+
+ pitEntry->AddIncoming (incomingFace/*, header->GetInterestLifetime ()*/);
+ /// @todo Make lifetime per incoming interface
+ pitEntry->UpdateLifetime (header->GetInterestLifetime ());
+
+ bool propagated = DoPropagateInterest (incomingFace, header, packet, pitEntry);
+
+ if (!propagated && isRetransmitted) //give another chance if retransmitted
+ {
+ // increase max number of allowed retransmissions
+ pitEntry->IncreaseAllowedRetxCount ();
+
+ // try again
+ propagated = DoPropagateInterest (incomingFace, header, packet, pitEntry);
+ }
+
+ // ForwardingStrategy will try its best to forward packet to at least one interface.
+ // If no interests was propagated, then there is not other option for forwarding or
+ // ForwardingStrategy failed to find it.
+ if (!propagated && pitEntry->GetOutgoing ().size () == 0)
+ {
+ DidExhaustForwardingOptions (incomingFace, header, packet, pitEntry);
+ }
+}
} //namespace ns3
diff --git a/model/forwarding-strategy/ccnx-forwarding-strategy.h b/model/forwarding-strategy/ccnx-forwarding-strategy.h
index 20d92a4..0683079 100644
--- a/model/forwarding-strategy/ccnx-forwarding-strategy.h
+++ b/model/forwarding-strategy/ccnx-forwarding-strategy.h
@@ -41,7 +41,8 @@
* \ingroup ccnx
* \brief Abstract base class for CCNx forwarding strategies
*/
-class CcnxForwardingStrategy : public Object
+class CcnxForwardingStrategy :
+ public Object
{
public:
static TypeId GetTypeId (void);
@@ -80,7 +81,64 @@
Ptr<Packet> &payload,
const Ptr<const Packet> &packet);
-// protected:
+protected:
+ // events
+ virtual void
+ DidReceiveDuplicateInterest (const Ptr<CcnxFace> &face,
+ Ptr<CcnxInterestHeader> &header,
+ const Ptr<const Packet> &packet,
+ Ptr<CcnxPitEntry> pitEntry);
+
+ virtual void
+ DidExhaustForwardingOptions (const Ptr<CcnxFace> &incomingFace,
+ Ptr<CcnxInterestHeader> header,
+ const Ptr<const Packet> &packet,
+ Ptr<CcnxPitEntry> pitEntry);
+
+ virtual void
+ FailedToCreatePitEntry (const Ptr<CcnxFace> &incomingFace,
+ Ptr<CcnxInterestHeader> header,
+ const Ptr<const Packet> &packet);
+
+ virtual void
+ DidCreatePitEntry (const Ptr<CcnxFace> &incomingFace,
+ Ptr<CcnxInterestHeader> header,
+ const Ptr<const Packet> &packet,
+ Ptr<CcnxPitEntry> pitEntry);
+
+ virtual bool
+ DetectRetransmittedInterest (const Ptr<CcnxFace> &incomingFace,
+ Ptr<CcnxPitEntry> pitEntry);
+
+ // only for data received from network
+ virtual void
+ WillSatisfyPendingInterest (const Ptr<CcnxFace> &incomingFace,
+ Ptr<CcnxPitEntry> pitEntry);
+
+ // for data received both from network and cache
+ virtual void
+ SatisfyPendingInterest (const Ptr<CcnxFace> &incomingFace, // 0 allowed (from cache)
+ Ptr<const CcnxContentObjectHeader> header,
+ Ptr<const Packet> payload,
+ const Ptr<const Packet> &packet,
+ Ptr<CcnxPitEntry> pitEntry);
+
+ virtual void
+ DidReceiveUnsolicitedData (const Ptr<CcnxFace> &incomingFace,
+ Ptr<const CcnxContentObjectHeader> header,
+ Ptr<const Packet> payload);
+
+ virtual bool
+ ShouldSuppressIncomingInterest (const Ptr<CcnxFace> &incomingFace,
+ Ptr<CcnxPitEntry> pitEntry);
+
+
+ virtual void
+ PropagateInterest (const Ptr<CcnxFace> &incomingFace,
+ Ptr<CcnxInterestHeader> &header,
+ const Ptr<const Packet> &packet,
+ Ptr<CcnxPitEntry> pitEntry);
+
/**
* @brief Base method to propagate the interest according to the forwarding strategy
*
@@ -93,38 +151,16 @@
* @return true if interest was successfully propagated, false if all options have failed
*/
virtual bool
- PropagateInterest (Ptr<CcnxPitEntry> pitEntry,
- const Ptr<CcnxFace> &incomingFace,
- Ptr<CcnxInterestHeader> &header,
- const Ptr<const Packet> &packet) = 0;
+ DoPropagateInterest (const Ptr<CcnxFace> &incomingFace,
+ Ptr<CcnxInterestHeader> &header,
+ const Ptr<const Packet> &packet,
+ Ptr<CcnxPitEntry> pitEntry) = 0;
-protected:
- /**
- * @brief Propagate interest via a green interface. Fail, if no green interfaces available
- *
- * @param pitEntry Reference to PIT entry (reference to corresponding FIB entry inside)
- * @param incomingFace Incoming face
- * @param header CcnxInterestHeader
- * @param packet Original Interest packet
- * @param sendCallback Send callback
- * @return true if interest was successfully propagated, false if all options have failed
- *
- * \see PropagateInterest
- */
- bool
- PropagateInterestViaGreen (Ptr<CcnxPitEntry> pitEntry,
- const Ptr<CcnxFace> &incomingFace,
- Ptr<CcnxInterestHeader> &header,
- const Ptr<const Packet> &packet);
- virtual void
- GiveUpInterest (Ptr<CcnxPitEntry> pitEntry,
- Ptr<CcnxInterestHeader> header);
-
- virtual void
- OnDataDelayed (Ptr<const CcnxContentObjectHeader> header,
- Ptr<const Packet> payload,
- const Ptr<const Packet> &packet);
+ // virtual void
+ // OnDataDelayed (Ptr<const CcnxContentObjectHeader> header,
+ // Ptr<const Packet> payload,
+ // const Ptr<const Packet> &packet);
protected:
// inherited from Object class
@@ -136,11 +172,8 @@
Ptr<CcnxFib> m_fib; ///< \brief FIB
Ptr<CcnxContentStore> m_contentStore; ///< \brief Content store (for caching purposes only)
- bool m_nacksEnabled;
bool m_cacheUnsolicitedData;
-
- // transmittedInterestTrace is inside ForwardingStrategy
-
+ bool m_detectRetransmissions;
TracedCallback<Ptr<const CcnxInterestHeader>,
Ptr<const CcnxFace> > m_outInterests; ///< @brief Transmitted interests trace
@@ -155,19 +188,6 @@
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
- TracedCallback<Ptr<const CcnxInterestHeader>,
- Ptr<const CcnxFace> > m_outNacks; ///< @brief trace of outgoing NACKs
-
- TracedCallback<Ptr<const CcnxInterestHeader>,
- Ptr<const CcnxFace> > m_inNacks; ///< @brief trace of incoming NACKs
-
- TracedCallback<Ptr<const CcnxInterestHeader>,
- Ptr<const CcnxFace> > m_dropNacks; ///< @brief trace of dropped NACKs
-
- ////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////
-
TracedCallback<Ptr<const CcnxContentObjectHeader>, Ptr<const Packet>,
bool /*from cache*/,
Ptr<const CcnxFace> > m_outData; ///< @brief trace of outgoing Data
diff --git a/model/forwarding-strategy/ccnx-flooding-strategy.cc b/model/forwarding-strategy/flooding.cc
similarity index 69%
rename from model/forwarding-strategy/ccnx-flooding-strategy.cc
rename to model/forwarding-strategy/flooding.cc
index c803560..79a29b9 100644
--- a/model/forwarding-strategy/ccnx-flooding-strategy.cc
+++ b/model/forwarding-strategy/flooding.cc
@@ -19,7 +19,7 @@
* Ilya Moiseenko <iliamo@cs.ucla.edu>
*/
-#include "ccnx-flooding-strategy.h"
+#include "flooding.h"
#include "ns3/ccnx-interest-header.h"
#include "ns3/ccnx-pit.h"
@@ -36,53 +36,37 @@
#include <boost/lambda/bind.hpp>
namespace ll = boost::lambda;
-NS_LOG_COMPONENT_DEFINE ("CcnxFloodingStrategy");
+NS_LOG_COMPONENT_DEFINE ("NdnSimFlooding");
-namespace ns3
-{
+namespace ns3 {
+namespace ndnSIM {
using namespace __ccnx_private;
-NS_OBJECT_ENSURE_REGISTERED (CcnxFloodingStrategy);
+NS_OBJECT_ENSURE_REGISTERED (Flooding);
-TypeId CcnxFloodingStrategy::GetTypeId (void)
+TypeId Flooding::GetTypeId (void)
{
- static TypeId tid = TypeId ("ns3::CcnxFloodingStrategy")
+ static TypeId tid = TypeId ("ns3::ndnSIM::Flooding")
.SetGroupName ("Ccnx")
- .SetParent <CcnxForwardingStrategy> ()
- .AddConstructor <CcnxFloodingStrategy> ()
-
- .AddAttribute ("SmartFlooding",
- "If true then if a GREEN face exists, Interests will be sent only to such face (!only to one green face!)",
- BooleanValue (false),
- MakeBooleanAccessor (&CcnxFloodingStrategy::m_smartFlooding),
- MakeBooleanChecker ())
+ .SetParent <Nacks> ()
+ .AddConstructor <Flooding> ()
;
return tid;
}
-CcnxFloodingStrategy::CcnxFloodingStrategy ()
+Flooding::Flooding ()
{
}
bool
-CcnxFloodingStrategy::PropagateInterest (Ptr<CcnxPitEntry> pitEntry,
- const Ptr<CcnxFace> &incomingFace,
- Ptr<CcnxInterestHeader> &header,
- const Ptr<const Packet> &packet)
+Flooding::DoPropagateInterest (const Ptr<CcnxFace> &incomingFace,
+ Ptr<CcnxInterestHeader> &header,
+ const Ptr<const Packet> &packet,
+ Ptr<CcnxPitEntry> pitEntry)
{
NS_LOG_FUNCTION (this);
- if (m_smartFlooding)
- {
- // Try to work out with just green faces
- bool greenOk = PropagateInterestViaGreen (pitEntry, incomingFace, header, packet);
- if (greenOk)
- return true;
-
- // boo... :(
- }
-
int propagatedCount = 0;
BOOST_FOREACH (const CcnxFibFaceMetric &metricFace, pitEntry->GetFibEntry ()->m_faces.get<i_metric> ())
@@ -128,5 +112,6 @@
NS_LOG_INFO ("Propagated to " << propagatedCount << " faces");
return propagatedCount > 0;
}
-
-} //namespace ns3
+
+} // namespace ndnSIM
+} // namespace ns3
diff --git a/model/forwarding-strategy/ccnx-flooding-strategy.h b/model/forwarding-strategy/flooding.h
similarity index 60%
rename from model/forwarding-strategy/ccnx-flooding-strategy.h
rename to model/forwarding-strategy/flooding.h
index fa77988..99a6b9c 100644
--- a/model/forwarding-strategy/ccnx-flooding-strategy.h
+++ b/model/forwarding-strategy/flooding.h
@@ -15,27 +15,26 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Author: Ilya Moiseenko <iliamo@cs.ucla.edu>
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ * Ilya Moiseenko <iliamo@cs.ucla.edu>
*/
-#ifndef CCNX_FLOODING_STRATEGY_H
-#define CCNX_FLOODING_STRATEGY_H
+#ifndef NDNSIM_FLOODING_H
+#define NDNSIM_FLOODING_H
-#include "ccnx-forwarding-strategy.h"
+#include "nacks.h"
-namespace ns3
-{
-
-class CcnxFace;
-class CcnxInterestHeader;
-
+namespace ns3 {
+namespace ndnSIM {
+
/**
* \ingroup ccnx
* \brief Flooding strategy
*
* \todo Describe
*/
-class CcnxFloodingStrategy : public CcnxForwardingStrategy
+class Flooding :
+ public Nacks
{
public:
static TypeId GetTypeId (void);
@@ -43,19 +42,21 @@
/**
* @brief Default constructor
*/
- CcnxFloodingStrategy ();
+ Flooding ();
- // inherited from CcnxForwardingStrategy
+protected:
+ // inherited from Nacks/CcnxForwardingStrategy
virtual bool
- PropagateInterest (Ptr<CcnxPitEntry> pitEntry,
- const Ptr<CcnxFace> &incomingFace,
- Ptr<CcnxInterestHeader> &header,
- const Ptr<const Packet> &packet);
+ DoPropagateInterest (const Ptr<CcnxFace> &incomingFace,
+ Ptr<CcnxInterestHeader> &header,
+ const Ptr<const Packet> &packet,
+ Ptr<CcnxPitEntry> pitEntry);
private:
- bool m_smartFlooding;
+ typedef Nacks super;
};
-
-} //namespace ns3
-#endif /* CCNX_FLOODING_STRATEGY_H */
+} // namespace ndnSIM
+} // namespace ns3
+
+#endif // NDNSIM_FLOODING
diff --git a/model/forwarding-strategy/green-yellow-red.cc b/model/forwarding-strategy/green-yellow-red.cc
new file mode 100644
index 0000000..f945bbe
--- /dev/null
+++ b/model/forwarding-strategy/green-yellow-red.cc
@@ -0,0 +1,130 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ * Ilya Moiseenko <iliamo@cs.ucla.edu>
+ */
+
+#include "green-yellow-red.h"
+
+#include "ns3/ccnx-pit.h"
+#include "ns3/ccnx-pit-entry.h"
+#include "ns3/ccnx-interest-header.h"
+#include "ns3/ccnx-content-object-header.h"
+#include "ns3/ccnx-pit.h"
+#include "ns3/ccnx-fib.h"
+#include "ns3/ccnx-content-store.h"
+
+#include "ns3/assert.h"
+#include "ns3/ptr.h"
+#include "ns3/log.h"
+#include "ns3/simulator.h"
+#include "ns3/boolean.h"
+#include "ns3/string.h"
+
+#include <boost/ref.hpp>
+#include <boost/foreach.hpp>
+#include <boost/lambda/lambda.hpp>
+#include <boost/lambda/bind.hpp>
+#include <boost/tuple/tuple.hpp>
+namespace ll = boost::lambda;
+
+NS_LOG_COMPONENT_DEFINE ("NdnSimGreenYellowRed");
+
+namespace ns3 {
+
+using namespace __ccnx_private;
+
+namespace ndnSIM {
+
+NS_OBJECT_ENSURE_REGISTERED (GreenYellowRed);
+
+TypeId
+GreenYellowRed::GetTypeId (void)
+{
+ static TypeId tid = TypeId ("ns3::ndnSIM::GreenYellowRed")
+ .SetGroupName ("Ccnx")
+ .SetParent<CcnxForwardingStrategy> ()
+
+ ;
+ return tid;
+}
+
+bool
+GreenYellowRed::DoPropagateInterest (const Ptr<CcnxFace> &incomingFace,
+ Ptr<CcnxInterestHeader> &header,
+ const Ptr<const Packet> &packet,
+ Ptr<CcnxPitEntry> pitEntry)
+{
+ NS_LOG_FUNCTION (this);
+ NS_ASSERT_MSG (m_pit != 0, "PIT should be aggregated with forwarding strategy");
+
+ int propagatedCount = 0;
+
+ BOOST_FOREACH (const CcnxFibFaceMetric &metricFace, pitEntry->GetFibEntry ()->m_faces.get<i_metric> ())
+ {
+ if (metricFace.m_status == CcnxFibFaceMetric::NDN_FIB_RED ||
+ metricFace.m_status == CcnxFibFaceMetric::NDN_FIB_YELLOW)
+ break; //propagate only to green faces
+
+ if (pitEntry->GetIncoming ().find (metricFace.m_face) != pitEntry->GetIncoming ().end ())
+ continue; // don't forward to face that we received interest from
+
+ CcnxPitEntryOutgoingFaceContainer::type::iterator outgoing =
+ pitEntry->GetOutgoing ().find (metricFace.m_face);
+
+ if (outgoing != pitEntry->GetOutgoing ().end () &&
+ outgoing->m_retxCount >= pitEntry->GetMaxRetxCount ())
+ {
+ NS_LOG_DEBUG ("retxCount: " << outgoing->m_retxCount << ", maxRetxCount: " << pitEntry->GetMaxRetxCount ());
+ continue;
+ }
+
+ bool faceAvailable = metricFace.m_face->IsBelowLimit ();
+ if (!faceAvailable) // huh...
+ {
+ // let's try different green face
+ continue;
+ }
+
+ pitEntry->AddOutgoing (metricFace.m_face);
+
+ Ptr<Packet> packetToSend = packet->Copy ();
+
+ //transmission
+ metricFace.m_face->Send (packetToSend);
+ m_outInterests (header, metricFace.m_face);
+
+ propagatedCount++;
+ break; // propagate only one interest
+ }
+
+ return propagatedCount > 0;
+}
+
+void
+GreenYellowRed::WillSatisfyPendingInterest (const Ptr<CcnxFace> &incomingFace,
+ Ptr<CcnxPitEntry> pitEntry)
+{
+ // Update metric status for the incoming interface in the corresponding FIB entry
+ pitEntry->GetFibEntry ()->UpdateStatus (incomingFace, CcnxFibFaceMetric::NDN_FIB_GREEN);
+
+ super::WillSatisfyPendingInterest (incomingFace, pitEntry);
+}
+
+} // namespace ndnSIM
+} // namespace ns3
diff --git a/model/forwarding-strategy/green-yellow-red.h b/model/forwarding-strategy/green-yellow-red.h
new file mode 100644
index 0000000..71f4955
--- /dev/null
+++ b/model/forwarding-strategy/green-yellow-red.h
@@ -0,0 +1,56 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ * Ilya Moiseenko <iliamo@cs.ucla.edu>
+ */
+#ifndef NDNSIM_GREEN_YELLOW_RED_H
+#define NDNSIM_GREEN_YELLOW_RED_H
+
+#include "ccnx-forwarding-strategy.h"
+
+namespace ns3 {
+namespace ndnSIM {
+
+/**
+ * \ingroup ccnx
+ */
+class GreenYellowRed :
+ public CcnxForwardingStrategy
+{
+public:
+ static TypeId GetTypeId (void);
+
+protected:
+ virtual void
+ WillSatisfyPendingInterest (const Ptr<CcnxFace> &incomingFace,
+ Ptr<CcnxPitEntry> pitEntry);
+
+ virtual bool
+ DoPropagateInterest (const Ptr<CcnxFace> &incomingFace,
+ Ptr<CcnxInterestHeader> &header,
+ const Ptr<const Packet> &packet,
+ Ptr<CcnxPitEntry> pitEntry);
+
+private:
+ typedef CcnxForwardingStrategy super;
+};
+
+} // namespace ndnSIM
+} // namespace ns3
+
+#endif // NDNSIM_GREEN_YELLOW_RED
diff --git a/model/forwarding-strategy/nacks.cc b/model/forwarding-strategy/nacks.cc
new file mode 100644
index 0000000..925788c
--- /dev/null
+++ b/model/forwarding-strategy/nacks.cc
@@ -0,0 +1,148 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "nacks.h"
+
+#include "ns3/ccnx-pit.h"
+#include "ns3/ccnx-pit-entry.h"
+#include "ns3/ccnx-interest-header.h"
+#include "ns3/ccnx-content-object-header.h"
+#include "ns3/ccnx-pit.h"
+#include "ns3/ccnx-fib.h"
+#include "ns3/ccnx-content-store.h"
+
+#include "ns3/assert.h"
+#include "ns3/ptr.h"
+#include "ns3/log.h"
+#include "ns3/simulator.h"
+#include "ns3/boolean.h"
+#include "ns3/string.h"
+
+#include <boost/ref.hpp>
+#include <boost/foreach.hpp>
+#include <boost/lambda/lambda.hpp>
+#include <boost/lambda/bind.hpp>
+#include <boost/tuple/tuple.hpp>
+namespace ll = boost::lambda;
+
+NS_LOG_COMPONENT_DEFINE ("NdnSimNacks");
+
+namespace ns3 {
+namespace ndnSIM {
+
+NS_OBJECT_ENSURE_REGISTERED (Nacks);
+
+TypeId
+Nacks::GetTypeId (void)
+{
+ static TypeId tid = TypeId ("ns3::ndnSIM::Nacks")
+ .SetGroupName ("Ccnx")
+ .SetParent<CcnxForwardingStrategy> ()
+
+ ////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////
+
+ .AddTraceSource ("OutNacks", "OutNacks", MakeTraceSourceAccessor (&Nacks::m_outNacks))
+ .AddTraceSource ("InNacks", "InNacks", MakeTraceSourceAccessor (&Nacks::m_inNacks))
+ .AddTraceSource ("DropNacks", "DropNacks", MakeTraceSourceAccessor (&Nacks::m_dropNacks))
+
+ .AddAttribute ("EnableNACKs", "Enabling support of NACKs",
+ BooleanValue (false),
+ MakeBooleanAccessor (&Nacks::m_nacksEnabled),
+ MakeBooleanChecker ())
+ ;
+ return tid;
+}
+
+void
+Nacks::OnInterest (const Ptr<CcnxFace> &incomingFace,
+ Ptr<CcnxInterestHeader> &header,
+ const Ptr<const Packet> &packet)
+{
+ if (header->GetNack () > 0)
+ OnNack (incomingFace, header, packet/*original packet*/);
+ else
+ super::OnInterest (incomingFace, header, packet/*original packet*/);
+}
+
+void
+Nacks::OnNack (const Ptr<CcnxFace> &face,
+ Ptr<CcnxInterestHeader> &header,
+ const Ptr<const Packet> &p)
+{
+ NS_ASSERT (false);
+}
+
+void
+Nacks::DidReceiveDuplicateInterest (const Ptr<CcnxFace> &incomingFace,
+ Ptr<CcnxInterestHeader> &header,
+ const Ptr<const Packet> &packet,
+ Ptr<CcnxPitEntry> pitEntry)
+{
+ super::DidReceiveDuplicateInterest (incomingFace, header, packet, pitEntry);
+
+ if (m_nacksEnabled)
+ {
+ NS_LOG_DEBUG ("Sending NACK_LOOP");
+ header->SetNack (CcnxInterestHeader::NACK_LOOP);
+ Ptr<Packet> nack = Create<Packet> ();
+ nack->AddHeader (*header);
+
+ incomingFace->Send (nack);
+ m_outNacks (header, incomingFace);
+ }
+}
+
+void
+Nacks::DidExhaustForwardingOptions (const Ptr<CcnxFace> &incomingFace,
+ Ptr<CcnxInterestHeader> header,
+ const Ptr<const Packet> &packet,
+ Ptr<CcnxPitEntry> pitEntry)
+{
+ super::DidExhaustForwardingOptions (incomingFace, header, packet, pitEntry);
+
+ if (m_nacksEnabled)
+ {
+ Ptr<Packet> packet = Create<Packet> ();
+ header->SetNack (CcnxInterestHeader::NACK_GIVEUP_PIT);
+ packet->AddHeader (*header);
+
+ BOOST_FOREACH (const CcnxPitEntryIncomingFace &incoming, pitEntry->GetIncoming ())
+ {
+ NS_LOG_DEBUG ("Send NACK for " << boost::cref (header->GetName ()) << " to " << boost::cref (*incoming.m_face));
+ incoming.m_face->Send (packet->Copy ());
+
+ m_outNacks (header, incoming.m_face);
+ }
+
+ // All incoming interests cannot be satisfied. Remove them
+ pitEntry->ClearIncoming ();
+
+ // Remove also outgoing
+ pitEntry->ClearOutgoing ();
+
+ // Set pruning timout on PIT entry (instead of deleting the record)
+ m_pit->MarkErased (pitEntry);
+ }
+}
+
+
+} // namespace ndnSIM
+} // namespace ns3
diff --git a/model/forwarding-strategy/nacks.h b/model/forwarding-strategy/nacks.h
new file mode 100644
index 0000000..fbcec9f
--- /dev/null
+++ b/model/forwarding-strategy/nacks.h
@@ -0,0 +1,97 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+#ifndef NDNSIM_NACKS_H
+#define NDNSIM_NACKS_H
+
+#include "ns3/ccnx-forwarding-strategy.h"
+
+namespace ns3 {
+
+namespace ndnSIM {
+
+/**
+ * \ingroup ccnx
+ * \brief Abstract base class for CCNx forwarding strategies
+ */
+class Nacks :
+ public CcnxForwardingStrategy
+{
+public:
+ static TypeId
+ GetTypeId (void);
+
+ /**
+ * \brief Actual processing of incoming CCNx interests. Note, interests do not have payload
+ *
+ * Processing Interest packets
+ * @param face incoming face
+ * @param header deserialized Interest header
+ * @param packet original packet
+ */
+ virtual void
+ OnInterest (const Ptr<CcnxFace> &face,
+ Ptr<CcnxInterestHeader> &header,
+ const Ptr<const Packet> &p);
+
+protected:
+ // using CcnxForwardingStrategy::PropagateInterest; // some strange c++ cheating
+
+ virtual void
+ DidReceiveDuplicateInterest (const Ptr<CcnxFace> &face,
+ Ptr<CcnxInterestHeader> &header,
+ const Ptr<const Packet> &packet,
+ Ptr<CcnxPitEntry> pitEntry);
+
+ virtual void
+ DidExhaustForwardingOptions (const Ptr<CcnxFace> &incomingFace,
+ Ptr<CcnxInterestHeader> header,
+ const Ptr<const Packet> &packet,
+ Ptr<CcnxPitEntry> pitEntry);
+
+ virtual void
+ OnNack (const Ptr<CcnxFace> &face,
+ Ptr<CcnxInterestHeader> &header,
+ const Ptr<const Packet> &p);
+
+ // virtual void
+ // OnDataDelayed (Ptr<const CcnxContentObjectHeader> header,
+ // Ptr<const Packet> payload,
+ // const Ptr<const Packet> &packet);
+
+protected:
+ bool m_nacksEnabled;
+
+ TracedCallback<Ptr<const CcnxInterestHeader>,
+ Ptr<const CcnxFace> > m_outNacks; ///< @brief trace of outgoing NACKs
+
+ TracedCallback<Ptr<const CcnxInterestHeader>,
+ Ptr<const CcnxFace> > m_inNacks; ///< @brief trace of incoming NACKs
+
+ TracedCallback<Ptr<const CcnxInterestHeader>,
+ Ptr<const CcnxFace> > m_dropNacks; ///< @brief trace of dropped NACKs
+
+private:
+ typedef CcnxForwardingStrategy super;
+};
+
+} // namespace ndnSIM
+} // namespace ns3
+
+#endif // NDNSIM_NACKS
diff --git a/model/forwarding-strategy/ccnx-flooding-strategy.cc b/model/forwarding-strategy/smart-flooding.cc
similarity index 68%
copy from model/forwarding-strategy/ccnx-flooding-strategy.cc
copy to model/forwarding-strategy/smart-flooding.cc
index c803560..20bc7ba 100644
--- a/model/forwarding-strategy/ccnx-flooding-strategy.cc
+++ b/model/forwarding-strategy/smart-flooding.cc
@@ -16,10 +16,9 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- * Ilya Moiseenko <iliamo@cs.ucla.edu>
*/
-#include "ccnx-flooding-strategy.h"
+#include "smart-flooding.h"
#include "ns3/ccnx-interest-header.h"
#include "ns3/ccnx-pit.h"
@@ -36,52 +35,43 @@
#include <boost/lambda/bind.hpp>
namespace ll = boost::lambda;
-NS_LOG_COMPONENT_DEFINE ("CcnxFloodingStrategy");
+NS_LOG_COMPONENT_DEFINE ("NdnSimSmartFlooding");
-namespace ns3
-{
+namespace ns3 {
using namespace __ccnx_private;
-NS_OBJECT_ENSURE_REGISTERED (CcnxFloodingStrategy);
-
-TypeId CcnxFloodingStrategy::GetTypeId (void)
-{
- static TypeId tid = TypeId ("ns3::CcnxFloodingStrategy")
- .SetGroupName ("Ccnx")
- .SetParent <CcnxForwardingStrategy> ()
- .AddConstructor <CcnxFloodingStrategy> ()
+namespace ndnSIM {
- .AddAttribute ("SmartFlooding",
- "If true then if a GREEN face exists, Interests will be sent only to such face (!only to one green face!)",
- BooleanValue (false),
- MakeBooleanAccessor (&CcnxFloodingStrategy::m_smartFlooding),
- MakeBooleanChecker ())
+NS_OBJECT_ENSURE_REGISTERED (SmartFlooding);
+
+TypeId
+SmartFlooding::GetTypeId (void)
+{
+ static TypeId tid = TypeId ("ns3::ndnSIM::SmartFloodingy")
+ .SetGroupName ("Ccnx")
+ .SetParent <GreenYellowRed> ()
+ .AddConstructor <SmartFlooding> ()
;
return tid;
}
-CcnxFloodingStrategy::CcnxFloodingStrategy ()
+SmartFlooding::SmartFlooding ()
{
}
bool
-CcnxFloodingStrategy::PropagateInterest (Ptr<CcnxPitEntry> pitEntry,
- const Ptr<CcnxFace> &incomingFace,
- Ptr<CcnxInterestHeader> &header,
- const Ptr<const Packet> &packet)
+SmartFlooding::DoPropagateInterest (const Ptr<CcnxFace> &incomingFace,
+ Ptr<CcnxInterestHeader> &header,
+ const Ptr<const Packet> &packet,
+ Ptr<CcnxPitEntry> pitEntry)
{
NS_LOG_FUNCTION (this);
- if (m_smartFlooding)
- {
- // Try to work out with just green faces
- bool greenOk = PropagateInterestViaGreen (pitEntry, incomingFace, header, packet);
- if (greenOk)
- return true;
-
- // boo... :(
- }
+ // Try to work out with just green faces
+ bool greenOk = super::DoPropagateInterest (incomingFace, header, packet, pitEntry);
+ if (greenOk)
+ return true;
int propagatedCount = 0;
@@ -128,5 +118,6 @@
NS_LOG_INFO ("Propagated to " << propagatedCount << " faces");
return propagatedCount > 0;
}
-
-} //namespace ns3
+
+} // namespace ndnSIM
+} // namespace ns3
diff --git a/model/forwarding-strategy/smart-flooding.h b/model/forwarding-strategy/smart-flooding.h
new file mode 100644
index 0000000..3e1cca6
--- /dev/null
+++ b/model/forwarding-strategy/smart-flooding.h
@@ -0,0 +1,57 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef NDNSIM_SMART_FLOODING_H
+#define NDNSIM_SMART_FLOODING_H
+
+#include "green-yellow-red.h"
+
+namespace ns3 {
+namespace ndnSIM {
+
+/**
+ * \ingroup ccnx
+ */
+class SmartFlooding :
+ public GreenYellowRed
+{
+public:
+ static TypeId GetTypeId (void);
+
+ /**
+ * @brief Default constructor
+ */
+ SmartFlooding ();
+
+ // inherited
+ virtual bool
+ DoPropagateInterest (const Ptr<CcnxFace> &incomingFace,
+ Ptr<CcnxInterestHeader> &header,
+ const Ptr<const Packet> &packet,
+ Ptr<CcnxPitEntry> pitEntry);
+
+private:
+ typedef GreenYellowRed super;
+};
+
+} // namespace ndnSIM
+} // namespace ns3
+
+#endif // NDNSIM_SMART_FLOODING_H