Start of serious reorganization
The whole forwarding logic is (will be) moved to the Forwarding Strategy
class.
diff --git a/model/pit/ccnx-pit-entry.cc b/model/pit/ccnx-pit-entry.cc
new file mode 100644
index 0000000..081b155
--- /dev/null
+++ b/model/pit/ccnx-pit-entry.cc
@@ -0,0 +1,203 @@
+/* -*- 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 "ccnx-pit-entry.h"
+
+#include "ns3/ccnx-fib.h"
+#include "ns3/ccnx-name-components.h"
+#include "ns3/ccnx-interest-header.h"
+
+#include "ns3/simulator.h"
+#include "ns3/log.h"
+
+#include <boost/lambda/lambda.hpp>
+#include <boost/lambda/bind.hpp>
+#include <boost/foreach.hpp>
+namespace ll = boost::lambda;
+
+NS_LOG_COMPONENT_DEFINE ("CcnxPitEntry");
+
+namespace ns3
+{
+
+CcnxPitEntry::CcnxPitEntry (CcnxPit &container,
+ Ptr<const CcnxInterestHeader> header,
+ Ptr<CcnxFibEntry> fibEntry)
+ : m_container (container)
+ , m_prefix (header->GetNamePtr ())
+ , m_fibEntry (fibEntry)
+ , m_expireTime (Simulator::Now () + (!header->GetInterestLifetime ().IsZero ()?
+ header->GetInterestLifetime ():
+ Seconds (1.0)))
+ , m_maxRetxCount (0)
+{
+ // note that if interest lifetime is not set, the behavior is undefined
+}
+
+void
+CcnxPitEntry::UpdateLifetime (const Time &offsetTime)
+{
+ NS_LOG_FUNCTION (offsetTime.ToDouble (Time::S));
+
+ Time newExpireTime = Simulator::Now () + offsetTime;
+ if (newExpireTime > m_expireTime)
+ m_expireTime = newExpireTime;
+
+ NS_LOG_INFO ("Updated lifetime to " << m_expireTime.ToDouble (Time::S));
+}
+
+CcnxPitEntry::in_iterator
+CcnxPitEntry::AddIncoming (Ptr<CcnxFace> face)
+{
+ std::pair<in_iterator,bool> ret =
+ m_incoming.insert (CcnxPitEntryIncomingFace (face));
+
+ NS_ASSERT_MSG (ret.second, "Something is wrong");
+
+ return ret.first;
+}
+
+void
+CcnxPitEntry::RemoveIncoming (Ptr<CcnxFace> face)
+{
+ m_incoming.erase (face);
+}
+
+
+CcnxPitEntry::out_iterator
+CcnxPitEntry::AddOutgoing (Ptr<CcnxFace> face)
+{
+ std::pair<out_iterator,bool> ret =
+ m_outgoing.insert (CcnxPitEntryOutgoingFace (face));
+
+ if (!ret.second)
+ { // outgoing face already exists
+ m_outgoing.modify (ret.first,
+ ll::bind (&CcnxPitEntryOutgoingFace::UpdateOnRetransmit, ll::_1));
+ }
+
+ return ret.first;
+}
+
+void
+CcnxPitEntry::RemoveAllReferencesToFace (Ptr<CcnxFace> face)
+{
+ in_iterator incoming = m_incoming.find (face);
+
+ if (incoming != m_incoming.end ())
+ m_incoming.erase (incoming);
+
+ out_iterator outgoing =
+ m_outgoing.find (face);
+
+ if (outgoing != m_outgoing.end ())
+ m_outgoing.erase (outgoing);
+}
+
+void
+CcnxPitEntry::SetWaitingInVain (CcnxPitEntry::out_iterator face)
+{
+ NS_LOG_DEBUG (boost::cref (*face->m_face));
+
+ m_outgoing.modify (face,
+ (&ll::_1)->*&CcnxPitEntryOutgoingFace::m_waitingInVain = true);
+}
+
+bool
+CcnxPitEntry::AreAllOutgoingInVain () const
+{
+ NS_LOG_DEBUG (m_outgoing.size ());
+
+ bool inVain = true;
+ std::for_each (m_outgoing.begin (), m_outgoing.end (),
+ ll::var(inVain) &= (&ll::_1)->*&CcnxPitEntryOutgoingFace::m_waitingInVain);
+
+ NS_LOG_DEBUG ("inVain " << inVain);
+ return inVain;
+}
+
+bool
+CcnxPitEntry::AreTherePromisingOutgoingFacesExcept (Ptr<CcnxFace> face) const
+{
+ bool inVain = true;
+ std::for_each (m_outgoing.begin (), m_outgoing.end (),
+ ll::var(inVain) &=
+ ((&ll::_1)->*&CcnxPitEntryOutgoingFace::m_face == face ||
+ (&ll::_1)->*&CcnxPitEntryOutgoingFace::m_waitingInVain));
+
+ return !inVain;
+}
+
+void
+CcnxPitEntry::IncreaseAllowedRetxCount ()
+{
+ NS_LOG_ERROR (this);
+ if (Simulator::Now () - m_lastRetransmission >= MilliSeconds (100))
+ {
+ // cheat:
+ // don't allow retransmission faster than every 100ms
+ m_maxRetxCount++;
+ m_lastRetransmission = Simulator::Now ();
+ }
+}
+
+std::ostream& operator<< (std::ostream& os, const CcnxPitEntry &entry)
+{
+ os << "Prefix: " << *entry.m_prefix << "\n";
+ os << "In: ";
+ bool first = true;
+ BOOST_FOREACH (const CcnxPitEntryIncomingFace &face, entry.m_incoming)
+ {
+ if (!first)
+ os << ",";
+ else
+ first = false;
+
+ os << *face.m_face;
+ }
+
+ os << "\nOut: ";
+ first = true;
+ BOOST_FOREACH (const CcnxPitEntryOutgoingFace &face, entry.m_outgoing)
+ {
+ if (!first)
+ os << ",";
+ else
+ first = false;
+
+ os << *face.m_face;
+ }
+ os << "\nNonces: ";
+ first = true;
+ BOOST_FOREACH (uint32_t nonce, entry.m_seenNonces)
+ {
+ if (!first)
+ os << ",";
+ else
+ first = false;
+
+ os << nonce;
+ }
+
+ return os;
+}
+
+
+}