Finalizing implementation of almost all events for forwarding strategy.
Implementing FwStats strategy that just calculates statistics for
pit entries and incoming/outgoing interests.
A serious testing is necessary to see if everything works.
diff --git a/model/forwarding-strategy/best-route.cc b/model/forwarding-strategy/best-route.cc
index 33d9cde..f109568 100644
--- a/model/forwarding-strategy/best-route.cc
+++ b/model/forwarding-strategy/best-route.cc
@@ -59,7 +59,7 @@
bool
BestRoute::DoPropagateInterest (const Ptr<CcnxFace> &incomingFace,
- Ptr<CcnxInterestHeader> &header,
+ Ptr<CcnxInterestHeader> header,
const Ptr<const Packet> &packet,
Ptr<CcnxPitEntry> pitEntry)
{
@@ -84,30 +84,17 @@
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_ERROR (outgoing->m_retxCount << " >= " << pitEntry->GetMaxRetxCount ());
- continue; // already forwarded before during this retransmission cycle
- }
-
- bool faceAvailable = metricFace.m_face->IsBelowLimit ();
- if (!faceAvailable) // huh...
+ if (!WillSendOutInterest (metricFace.m_face, header, pitEntry))
{
continue;
}
- pitEntry->AddOutgoing (metricFace.m_face);
-
- Ptr<Packet> packetToSend = packet->Copy ();
-
//transmission
+ Ptr<Packet> packetToSend = packet->Copy ();
metricFace.m_face->Send (packetToSend);
- m_outInterests (header, metricFace.m_face);
-
+
+ DidSendOutInterest (metricFace.m_face, header, pitEntry);
+
propagatedCount++;
break; // do only once
}
diff --git a/model/forwarding-strategy/best-route.h b/model/forwarding-strategy/best-route.h
index aec1147..01c9493 100644
--- a/model/forwarding-strategy/best-route.h
+++ b/model/forwarding-strategy/best-route.h
@@ -47,7 +47,7 @@
// inherited from CcnxForwardingStrategy
virtual bool
DoPropagateInterest (const Ptr<CcnxFace> &incomingFace,
- Ptr<CcnxInterestHeader> &header,
+ Ptr<CcnxInterestHeader> header,
const Ptr<const Packet> &packet,
Ptr<CcnxPitEntry> pitEntry);
diff --git a/model/forwarding-strategy/ccnx-forwarding-strategy.cc b/model/forwarding-strategy/ccnx-forwarding-strategy.cc
index 3d6f3de..e4b89f6 100644
--- a/model/forwarding-strategy/ccnx-forwarding-strategy.cc
+++ b/model/forwarding-strategy/ccnx-forwarding-strategy.cc
@@ -28,6 +28,7 @@
#include "ns3/ccnx-pit.h"
#include "ns3/ccnx-fib.h"
#include "ns3/ccnx-content-store.h"
+#include "ns3/ccnx-face.h"
#include "ns3/assert.h"
#include "ns3/ptr.h"
@@ -166,6 +167,11 @@
NS_ASSERT (contentObjectHeader != 0);
pitEntry->AddIncoming (incomingFace/*, Seconds (1.0)*/);
+
+ // Do data plane performance measurements
+ WillSatisfyPendingInterest (0, pitEntry);
+
+ // Actually satisfy pending interest
SatisfyPendingInterest (0, contentObjectHeader, payload, contentObject, pitEntry);
return;
}
@@ -379,7 +385,7 @@
void
CcnxForwardingStrategy::PropagateInterest (const Ptr<CcnxFace> &incomingFace,
- Ptr<CcnxInterestHeader> &header,
+ Ptr<CcnxInterestHeader> header,
const Ptr<const Packet> &packet,
Ptr<CcnxPitEntry> pitEntry)
{
@@ -410,4 +416,42 @@
}
}
+bool
+CcnxForwardingStrategy::WillSendOutInterest (const Ptr<CcnxFace> &outgoingFace,
+ Ptr<CcnxInterestHeader> header,
+ Ptr<CcnxPitEntry> pitEntry)
+{
+ CcnxPitEntryOutgoingFaceContainer::type::iterator outgoing =
+ pitEntry->GetOutgoing ().find (outgoingFace);
+
+ if (outgoing != pitEntry->GetOutgoing ().end () &&
+ outgoing->m_retxCount >= pitEntry->GetMaxRetxCount ())
+ {
+ NS_LOG_ERROR (outgoing->m_retxCount << " >= " << pitEntry->GetMaxRetxCount ());
+ return false; // already forwarded before during this retransmission cycle
+ }
+
+
+ bool ok = outgoingFace->IsBelowLimit ();
+ if (!ok)
+ return false;
+
+ pitEntry->AddOutgoing (outgoingFace);
+ return true;
+}
+
+void
+CcnxForwardingStrategy::DidSendOutInterest (const Ptr<CcnxFace> &outgoingFace,
+ Ptr<CcnxInterestHeader> header,
+ Ptr<CcnxPitEntry> pitEntry)
+{
+ m_outInterests (header, outgoingFace);
+}
+
+void
+CcnxForwardingStrategy::WillErasePendingInterest (Ptr<CcnxPitEntry> pitEntry)
+{
+ // do nothing for now. may be need to do some logging
+}
+
} //namespace ns3
diff --git a/model/forwarding-strategy/ccnx-forwarding-strategy.h b/model/forwarding-strategy/ccnx-forwarding-strategy.h
index 0683079..c46c70f 100644
--- a/model/forwarding-strategy/ccnx-forwarding-strategy.h
+++ b/model/forwarding-strategy/ccnx-forwarding-strategy.h
@@ -80,7 +80,10 @@
Ptr<CcnxContentObjectHeader> &header,
Ptr<Packet> &payload,
const Ptr<const Packet> &packet);
-
+
+ virtual void
+ WillErasePendingInterest (Ptr<CcnxPitEntry> pitEntry);
+
protected:
// events
virtual void
@@ -110,7 +113,8 @@
DetectRetransmittedInterest (const Ptr<CcnxFace> &incomingFace,
Ptr<CcnxPitEntry> pitEntry);
- // only for data received from network
+ // makes sense only for data received from network
+ // When Interest is satisfied from the cache, incoming face is 0
virtual void
WillSatisfyPendingInterest (const Ptr<CcnxFace> &incomingFace,
Ptr<CcnxPitEntry> pitEntry);
@@ -132,10 +136,28 @@
ShouldSuppressIncomingInterest (const Ptr<CcnxFace> &incomingFace,
Ptr<CcnxPitEntry> pitEntry);
+ /**
+ * @brief Event fired before actually sending out an interest
+ *
+ * If event returns false, then there is some kind of a problem (e.g., per-face limit reached)
+ */
+ virtual bool
+ WillSendOutInterest (const Ptr<CcnxFace> &outgoingFace,
+ Ptr<CcnxInterestHeader> header,
+ Ptr<CcnxPitEntry> pitEntry);
+
+ /**
+ * @brief Event fired just after sending out an interest
+ */
+ virtual void
+ DidSendOutInterest (const Ptr<CcnxFace> &outgoingFace,
+ Ptr<CcnxInterestHeader> header,
+ Ptr<CcnxPitEntry> pitEntry);
+
virtual void
PropagateInterest (const Ptr<CcnxFace> &incomingFace,
- Ptr<CcnxInterestHeader> &header,
+ Ptr<CcnxInterestHeader> header,
const Ptr<const Packet> &packet,
Ptr<CcnxPitEntry> pitEntry);
@@ -152,7 +174,7 @@
*/
virtual bool
DoPropagateInterest (const Ptr<CcnxFace> &incomingFace,
- Ptr<CcnxInterestHeader> &header,
+ Ptr<CcnxInterestHeader> header,
const Ptr<const Packet> &packet,
Ptr<CcnxPitEntry> pitEntry) = 0;
diff --git a/model/forwarding-strategy/flooding.cc b/model/forwarding-strategy/flooding.cc
index 79a29b9..545d1fb 100644
--- a/model/forwarding-strategy/flooding.cc
+++ b/model/forwarding-strategy/flooding.cc
@@ -61,7 +61,7 @@
bool
Flooding::DoPropagateInterest (const Ptr<CcnxFace> &incomingFace,
- Ptr<CcnxInterestHeader> &header,
+ Ptr<CcnxInterestHeader> header,
const Ptr<const Packet> &packet,
Ptr<CcnxPitEntry> pitEntry)
{
@@ -81,30 +81,16 @@
continue; // same face as incoming, don't forward
}
- CcnxPitEntryOutgoingFaceContainer::type::iterator outgoing =
- pitEntry->GetOutgoing ().find (metricFace.m_face);
-
- if (outgoing != pitEntry->GetOutgoing ().end () &&
- outgoing->m_retxCount >= pitEntry->GetMaxRetxCount ())
- {
- NS_LOG_DEBUG ("continue (same as previous outgoing)");
- continue; // already forwarded before during this retransmission cycle
- }
- NS_LOG_DEBUG ("max retx count: " << pitEntry->GetMaxRetxCount ());
-
- bool faceAvailable = metricFace.m_face->IsBelowLimit ();
- if (!faceAvailable) // huh...
+ if (!WillSendOutInterest (metricFace.m_face, header, pitEntry))
{
continue;
}
- pitEntry->AddOutgoing (metricFace.m_face);
-
- Ptr<Packet> packetToSend = packet->Copy ();
-
//transmission
+ Ptr<Packet> packetToSend = packet->Copy ();
metricFace.m_face->Send (packetToSend);
- m_outInterests (header, metricFace.m_face);
+
+ DidSendOutInterest (metricFace.m_face, header, pitEntry);
propagatedCount++;
}
diff --git a/model/forwarding-strategy/flooding.h b/model/forwarding-strategy/flooding.h
index 99a6b9c..71665c7 100644
--- a/model/forwarding-strategy/flooding.h
+++ b/model/forwarding-strategy/flooding.h
@@ -48,7 +48,7 @@
// inherited from Nacks/CcnxForwardingStrategy
virtual bool
DoPropagateInterest (const Ptr<CcnxFace> &incomingFace,
- Ptr<CcnxInterestHeader> &header,
+ Ptr<CcnxInterestHeader> header,
const Ptr<const Packet> &packet,
Ptr<CcnxPitEntry> pitEntry);
diff --git a/model/forwarding-strategy/fw-stats.cc b/model/forwarding-strategy/fw-stats.cc
new file mode 100644
index 0000000..1c1c873
--- /dev/null
+++ b/model/forwarding-strategy/fw-stats.cc
@@ -0,0 +1,100 @@
+/* -*- 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 "fw-stats.h"
+
+#include "ns3/ccnx-interest-header.h"
+#include "ns3/ccnx-content-object-header.h"
+#include "ns3/ccnx-pit.h"
+#include "ns3/ccnx-pit-entry.h"
+
+#include "ns3/assert.h"
+#include "ns3/log.h"
+
+#include <boost/foreach.hpp>
+#include <boost/lambda/lambda.hpp>
+#include <boost/lambda/bind.hpp>
+namespace ll = boost::lambda;
+
+NS_LOG_COMPONENT_DEFINE ("NdnSimFwStats");
+
+namespace ns3 {
+namespace ndnSIM {
+
+NS_OBJECT_ENSURE_REGISTERED (FwStats);
+
+TypeId
+FwStats::GetTypeId (void)
+{
+ static TypeId tid = TypeId ("ns3::ndnSIM::FwStats")
+ .SetGroupName ("Ccnx")
+ .SetParent <BestRoute> ()
+ .AddConstructor <FwStats> ()
+ ;
+ return tid;
+}
+
+FwStats::FwStats ()
+{
+}
+
+void
+FwStats::DidCreatePitEntry (const Ptr<CcnxFace> &incomingFace,
+ Ptr<CcnxInterestHeader> header,
+ const Ptr<const Packet> &packet,
+ Ptr<CcnxPitEntry> pitEntry)
+{
+ super::DidCreatePitEntry (incomingFace, header, packet, pitEntry);
+
+ m_stats.NewPitEntry (header->GetName ());
+ m_stats.Incoming (header->GetName (), incomingFace);
+}
+
+void
+FwStats::WillSatisfyPendingInterest (const Ptr<CcnxFace> &incomingFace,
+ Ptr<CcnxPitEntry> pitEntry)
+{
+ super::WillSatisfyPendingInterest (incomingFace, pitEntry);
+
+ m_stats.Satisfy (pitEntry->GetPrefix ());
+}
+
+void
+FwStats::DidSendOutInterest (const Ptr<CcnxFace> &outgoingFace,
+ Ptr<CcnxInterestHeader> header,
+ Ptr<CcnxPitEntry> pitEntry)
+{
+ super::DidSendOutInterest (outgoingFace, header, pitEntry);
+
+ m_stats.Outgoing (header->GetName (), outgoingFace);
+}
+
+void
+FwStats::WillErasePendingInterest (Ptr<CcnxPitEntry> pitEntry)
+{
+ super::WillErasePendingInterest (pitEntry);
+
+ m_stats.Timeout (pitEntry->GetPrefix ());
+}
+
+
+} // namespace ndnSIM
+} // namespace ns3
diff --git a/model/forwarding-strategy/fw-stats.h b/model/forwarding-strategy/fw-stats.h
new file mode 100644
index 0000000..e2432b0
--- /dev/null
+++ b/model/forwarding-strategy/fw-stats.h
@@ -0,0 +1,75 @@
+/* -*- 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_FW_STATS_H
+#define NDNSIM_FW_STATS_H
+
+#include "best-route.h"
+#include "../../utils/stats-tree.h"
+
+namespace ns3 {
+namespace ndnSIM {
+
+/**
+ * \ingroup ccnx
+ * \brief Best route strategy
+ */
+class FwStats :
+ public BestRoute
+{
+public:
+ static TypeId
+ GetTypeId (void);
+
+ /**
+ * @brief Default constructor
+ */
+ FwStats ();
+
+protected:
+ virtual void
+ DidCreatePitEntry (const Ptr<CcnxFace> &incomingFace,
+ Ptr<CcnxInterestHeader> header,
+ const Ptr<const Packet> &packet,
+ Ptr<CcnxPitEntry> pitEntry);
+
+ virtual void
+ WillSatisfyPendingInterest (const Ptr<CcnxFace> &incomingFace,
+ Ptr<CcnxPitEntry> pitEntry);
+
+ virtual void
+ DidSendOutInterest (const Ptr<CcnxFace> &outgoingFace,
+ Ptr<CcnxInterestHeader> header,
+ Ptr<CcnxPitEntry> pitEntry);
+
+ virtual void
+ WillErasePendingInterest (Ptr<CcnxPitEntry> pitEntry);
+
+private:
+ ::ndnSIM::StatsTree m_stats;
+
+ typedef BestRoute super;
+};
+
+} // namespace ndnSIM
+} // namespace ns3
+
+#endif // NDNSIM_FW_STATS_H
diff --git a/model/forwarding-strategy/green-yellow-red.cc b/model/forwarding-strategy/green-yellow-red.cc
index e3d4322..70ae829 100644
--- a/model/forwarding-strategy/green-yellow-red.cc
+++ b/model/forwarding-strategy/green-yellow-red.cc
@@ -66,7 +66,7 @@
bool
GreenYellowRed::DoPropagateInterest (const Ptr<CcnxFace> &incomingFace,
- Ptr<CcnxInterestHeader> &header,
+ Ptr<CcnxInterestHeader> header,
const Ptr<const Packet> &packet,
Ptr<CcnxPitEntry> pitEntry)
{
@@ -84,30 +84,16 @@
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 ())
+ if (!WillSendOutInterest (metricFace.m_face, header, pitEntry))
{
- 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
+ Ptr<Packet> packetToSend = packet->Copy ();
metricFace.m_face->Send (packetToSend);
- m_outInterests (header, metricFace.m_face);
+
+ DidSendOutInterest (metricFace.m_face, header, pitEntry);
propagatedCount++;
break; // propagate only one interest
diff --git a/model/forwarding-strategy/green-yellow-red.h b/model/forwarding-strategy/green-yellow-red.h
index 383f3f4..71002b9 100644
--- a/model/forwarding-strategy/green-yellow-red.h
+++ b/model/forwarding-strategy/green-yellow-red.h
@@ -42,7 +42,7 @@
virtual bool
DoPropagateInterest (const Ptr<CcnxFace> &incomingFace,
- Ptr<CcnxInterestHeader> &header,
+ Ptr<CcnxInterestHeader> header,
const Ptr<const Packet> &packet,
Ptr<CcnxPitEntry> pitEntry);
virtual void
diff --git a/model/forwarding-strategy/smart-flooding.cc b/model/forwarding-strategy/smart-flooding.cc
index 20bc7ba..6cc05e3 100644
--- a/model/forwarding-strategy/smart-flooding.cc
+++ b/model/forwarding-strategy/smart-flooding.cc
@@ -62,7 +62,7 @@
bool
SmartFlooding::DoPropagateInterest (const Ptr<CcnxFace> &incomingFace,
- Ptr<CcnxInterestHeader> &header,
+ Ptr<CcnxInterestHeader> header,
const Ptr<const Packet> &packet,
Ptr<CcnxPitEntry> pitEntry)
{
@@ -87,30 +87,16 @@
continue; // same face as incoming, don't forward
}
- CcnxPitEntryOutgoingFaceContainer::type::iterator outgoing =
- pitEntry->GetOutgoing ().find (metricFace.m_face);
-
- if (outgoing != pitEntry->GetOutgoing ().end () &&
- outgoing->m_retxCount >= pitEntry->GetMaxRetxCount ())
- {
- NS_LOG_DEBUG ("continue (same as previous outgoing)");
- continue; // already forwarded before during this retransmission cycle
- }
- NS_LOG_DEBUG ("max retx count: " << pitEntry->GetMaxRetxCount ());
-
- bool faceAvailable = metricFace.m_face->IsBelowLimit ();
- if (!faceAvailable) // huh...
+ if (!WillSendOutInterest (metricFace.m_face, header, pitEntry))
{
continue;
}
- pitEntry->AddOutgoing (metricFace.m_face);
-
- Ptr<Packet> packetToSend = packet->Copy ();
-
//transmission
+ Ptr<Packet> packetToSend = packet->Copy ();
metricFace.m_face->Send (packetToSend);
- m_outInterests (header, metricFace.m_face);
+
+ DidSendOutInterest (metricFace.m_face, header, pitEntry);
propagatedCount++;
}
diff --git a/model/forwarding-strategy/smart-flooding.h b/model/forwarding-strategy/smart-flooding.h
index 3e1cca6..840ce6a 100644
--- a/model/forwarding-strategy/smart-flooding.h
+++ b/model/forwarding-strategy/smart-flooding.h
@@ -43,7 +43,7 @@
// inherited
virtual bool
DoPropagateInterest (const Ptr<CcnxFace> &incomingFace,
- Ptr<CcnxInterestHeader> &header,
+ Ptr<CcnxInterestHeader> header,
const Ptr<const Packet> &packet,
Ptr<CcnxPitEntry> pitEntry);