model+helper: Converting L3Protocol and StackHelper to use NFD codebase
diff --git a/model/ndn-l3-protocol.cpp b/model/ndn-l3-protocol.cpp
index 4ea8189..f383477 100644
--- a/model/ndn-l3-protocol.cpp
+++ b/model/ndn-l3-protocol.cpp
@@ -1,4 +1,4 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:ni -*- */
/*
* Copyright (c) 2011 University of California, Los Angeles
*
@@ -33,10 +33,24 @@
#include "ns3/random-variable.h"
#include "ndn-face.hpp"
+
#include "ndn-net-device-face.hpp"
+#include "../helper/ndn-stack-helper.hpp"
#include <boost/foreach.hpp>
+#include "ns3/ndnSIM/NFD/daemon/fw/forwarder.hpp"
+#include "ns3/ndnSIM/NFD/daemon/mgmt/internal-face.hpp"
+#include "ns3/ndnSIM/NFD/daemon/mgmt/fib-manager.hpp"
+#include "ns3/ndnSIM/NFD/daemon/mgmt/face-manager.hpp"
+#include "ns3/ndnSIM/NFD/daemon/mgmt/strategy-choice-manager.hpp"
+#include "ns3/ndnSIM/NFD/daemon/mgmt/status-server.hpp"
+
+#include "ns3/ndnSIM/NFD/daemon/face/null-face.hpp"
+#include "ns3/ndnSIM/NFD/core/config-file.hpp"
+#include "ns3/ndnSIM/NFD/daemon/mgmt/general-config-section.hpp"
+#include "ns3/ndnSIM/NFD/daemon/mgmt/tables-config-section.hpp"
+
NS_LOG_COMPONENT_DEFINE("ndn.L3Protocol");
namespace ns3 {
@@ -55,14 +69,34 @@
.SetGroupName("ndn")
.SetParent<Object>()
.AddConstructor<L3Protocol>()
- ;
- // .AddAttribute("FaceList", "List of faces associated with ndn stack", ObjectVectorValue(),
- // MakeObjectVectorAccessor(&L3Protocol::m_faces),
- // MakeObjectVectorChecker<Face>());
+
+ .AddTraceSource("OutInterests", "OutInterests",
+ MakeTraceSourceAccessor(&L3Protocol::m_outInterests))
+ .AddTraceSource("InInterests", "InInterests",
+ MakeTraceSourceAccessor(&L3Protocol::m_inInterests))
+
+ ////////////////////////////////////////////////////////////////////
+
+ .AddTraceSource("OutData", "OutData", MakeTraceSourceAccessor(&L3Protocol::m_outData))
+ .AddTraceSource("InData", "InData", MakeTraceSourceAccessor(&L3Protocol::m_inData));
return tid;
}
+class L3Protocol::Impl {
+private:
+ friend class L3Protocol;
+
+ shared_ptr<nfd::Forwarder> m_forwarder;
+
+ shared_ptr<nfd::InternalFace> m_internalFace;
+ shared_ptr<nfd::FibManager> m_fibManager;
+ shared_ptr<nfd::FaceManager> m_faceManager;
+ shared_ptr<nfd::StrategyChoiceManager> m_strategyChoiceManager;
+ shared_ptr<nfd::StatusServer> m_statusServer;
+};
+
L3Protocol::L3Protocol()
+ : m_impl(new Impl())
{
NS_LOG_FUNCTION(this);
}
@@ -72,6 +106,75 @@
NS_LOG_FUNCTION(this);
}
+void
+L3Protocol::initialize()
+{
+ m_impl->m_forwarder = make_shared<nfd::Forwarder>();
+
+ initializeManagement();
+
+ m_impl->m_forwarder->getFaceTable().addReserved(make_shared<nfd::NullFace>(), nfd::FACEID_NULL);
+ m_impl->m_forwarder->getFaceTable().addReserved(make_shared<nfd::NullFace>(
+ FaceUri("contentstore://")),
+ nfd::FACEID_CONTENT_STORE);
+}
+
+void
+L3Protocol::initializeManagement()
+{
+ m_impl->m_internalFace = make_shared<nfd::InternalFace>();
+
+ m_impl->m_fibManager =
+ make_shared<nfd::FibManager>(ref(m_impl->m_forwarder->getFib()),
+ bind(&nfd::Forwarder::getFace, m_impl->m_forwarder.get(), _1),
+ m_impl->m_internalFace, std::ref(StackHelper::getKeyChain()));
+
+ m_impl->m_faceManager =
+ make_shared<nfd::FaceManager>(ref(m_impl->m_forwarder->getFaceTable()), m_impl->m_internalFace,
+ std::ref(StackHelper::getKeyChain()));
+
+ m_impl->m_strategyChoiceManager =
+ make_shared<nfd::StrategyChoiceManager>(ref(m_impl->m_forwarder->getStrategyChoice()),
+ m_impl->m_internalFace,
+ std::ref(StackHelper::getKeyChain()));
+
+ m_impl->m_statusServer =
+ make_shared<nfd::StatusServer>(m_impl->m_internalFace, ref(*m_impl->m_forwarder),
+ std::ref(StackHelper::getKeyChain()));
+
+ nfd::TablesConfigSection tablesConfig(m_impl->m_forwarder->getCs(),
+ m_impl->m_forwarder->getPit(),
+ m_impl->m_forwarder->getFib(),
+ m_impl->m_forwarder->getStrategyChoice(),
+ m_impl->m_forwarder->getMeasurements());
+
+ m_impl->m_forwarder->getFaceTable().addReserved(m_impl->m_internalFace,
+ nfd::FACEID_INTERNAL_FACE);
+
+ // add FIB entry for NFD Management Protocol
+ shared_ptr<::nfd::fib::Entry> entry =
+ m_impl->m_forwarder->getFib().insert("/localhost/nfd").first;
+ entry->addNextHop(m_impl->m_internalFace, 0);
+}
+
+shared_ptr<nfd::Forwarder>
+L3Protocol::getForwarder()
+{
+ return m_impl->m_forwarder;
+}
+
+shared_ptr<nfd::FibManager>
+L3Protocol::getFibManager()
+{
+ return m_impl->m_fibManager;
+}
+
+shared_ptr<nfd::StrategyChoiceManager>
+L3Protocol::getStrategyChoiceManager()
+{
+ return m_impl->m_strategyChoiceManager;
+}
+
/*
* This method is called by AddAgregate and completes the aggregation
* by setting the node in the ndn stack
@@ -79,14 +182,13 @@
void
L3Protocol::NotifyNewAggregate()
{
- // not really efficient, but this will work only once
- if (m_node == 0) {
+ if (m_node == nullptr) {
m_node = GetObject<Node>();
- if (m_node != 0) {
+ if (m_node != nullptr) {
}
}
- Object::NotifyNewAggregate ();
+ Object::NotifyNewAggregate();
}
void
@@ -99,43 +201,52 @@
Object::DoDispose();
}
-uint32_t
-L3Protocol::AddFace(const shared_ptr<Face>& face)
+nfd::FaceId
+L3Protocol::addFace(shared_ptr<Face> face)
{
- NS_LOG_FUNCTION(this << &face);
+ NS_LOG_FUNCTION(this << face.get());
- return 0;
+ m_impl->m_forwarder->addFace(face);
+
+ // Connect Signals to TraceSource
+ face->onReceiveInterest +=
+ [this, face](const Interest& interest) { this->m_inInterests(interest, *face); };
+
+ face->onSendInterest +=
+ [this, face](const Interest& interest) { this->m_outInterests(interest, *face); };
+
+ face->onReceiveData += [this, face](const Data& data) { this->m_inData(data, *face); };
+
+ face->onSendData += [this, face](const Data& data) { this->m_outData(data, *face); };
+
+ return face->getId();
}
-void
-L3Protocol::RemoveFace(shared_ptr<Face> face)
+// void
+// L3Protocol::removeFace(shared_ptr<Face> face)
+// {
+// NS_LOG_FUNCTION(this << std::cref(*face));
+// }
+
+shared_ptr<Face>
+L3Protocol::getFaceById(nfd::FaceId id) const
{
- NS_LOG_FUNCTION(this << std::cref(*face));
+ return m_impl->m_forwarder->getFaceTable().get(id);
}
shared_ptr<Face>
-L3Protocol::GetFace(uint32_t index) const
+L3Protocol::getFaceByNetDevice(Ptr<NetDevice> netDevice) const
{
- return nullptr;
-}
+ for (const auto& i : m_impl->m_forwarder->getFaceTable()) {
+ shared_ptr<NetDeviceFace> netDeviceFace = std::dynamic_pointer_cast<NetDeviceFace>(i);
+ if (netDeviceFace == nullptr)
+ continue;
-shared_ptr<Face>
-L3Protocol::GetFaceById(uint32_t index) const
-{
+ if (netDeviceFace->GetNetDevice() == netDevice)
+ return i;
+ }
return nullptr;
}
-shared_ptr<Face>
-L3Protocol::GetFaceByNetDevice(Ptr<NetDevice> netDevice) const
-{
- return nullptr;
-}
-
-uint32_t
-L3Protocol::GetNFaces(void) const
-{
- return 0;
-}
-
} // namespace ndn
} // namespace ns3
diff --git a/model/ndn-l3-protocol.hpp b/model/ndn-l3-protocol.hpp
index 03618d5..63e4ff2 100644
--- a/model/ndn-l3-protocol.hpp
+++ b/model/ndn-l3-protocol.hpp
@@ -30,6 +30,13 @@
#include "ns3/ptr.h"
#include "ns3/net-device.h"
#include "ns3/nstime.h"
+#include "ns3/traced-callback.h"
+
+namespace nfd {
+class Forwarder;
+class FibManager;
+class StrategyChoiceManager;
+} // namespace nfd
namespace ns3 {
@@ -60,7 +67,7 @@
*
* \see Face, ForwardingStrategy
*/
-class L3Protocol : public Object {
+class L3Protocol : boost::noncopyable, public Object {
public:
/**
* \brief Interface ID
@@ -81,52 +88,60 @@
virtual ~L3Protocol();
/**
- * \brief Add face to Ndn stack
- *
- * \param face smart pointer to NdnFace-derived object
- * (NdnLocalFace, NdnNetDeviceFace, NdnUdpFace) \returns the
- * index of the Ndn interface added.
- *
- * \see NdnLocalFace, NdnNetDeviceFace, NdnUdpFace
+ * \brief Initialize NFD instance
*/
- virtual uint32_t
- AddFace(const shared_ptr<Face>& face);
+ void
+ initialize();
/**
- * \brief Get current number of faces added to Ndn stack
- *
- * \returns the number of faces
+ * \brief Get smart pointer to nfd::Forwarder installed on the node
*/
- virtual uint32_t
- GetNFaces() const;
+ shared_ptr<nfd::Forwarder>
+ getForwarder();
/**
- * \brief Get face by face index
- * \param face The face number (number in face list)
- * \returns The NdnFace associated with the Ndn face number.
+ * \brief Get smart pointer to nfd::FibManager, used by node's NFD
*/
- virtual shared_ptr<Face>
- GetFace(uint32_t face) const;
+ shared_ptr<nfd::FibManager>
+ getFibManager();
+
+ /**
+ * \brief Get smart pointer to nfd::StrategyChoiceManager, used by node's NFD
+ */
+ shared_ptr<nfd::StrategyChoiceManager>
+ getStrategyChoiceManager();
+
+
+ /**
+ * \brief Add face to NDN stack
+ *
+ * \param face smart pointer to Face-derived object (AppFace, NetDeviceFace)
+ * \return nfd::FaceId
+ *
+ * \see AppFace, NetDeviceFace
+ */
+ nfd::FaceId
+ addFace(shared_ptr<Face> face);
/**
* \brief Get face by face ID
* \param face The face ID number
- * \returns The NdnFace associated with the Ndn face number.
+ * \returns The Face associated with the Ndn face number.
*/
- virtual shared_ptr<Face>
- GetFaceById(uint32_t face) const;
+ shared_ptr<Face>
+ getFaceById(nfd::FaceId face) const;
- /**
- * \brief Remove face from ndn stack (remove callbacks)
- */
- virtual void
- RemoveFace(shared_ptr<Face> face);
+ // /**
+ // * \brief Remove face from ndn stack (remove callbacks)
+ // */
+ // virtual void
+ // removeFace(shared_ptr<Face> face);
/**
* \brief Get face for NetDevice
*/
- virtual shared_ptr<Face>
- GetFaceByNetDevice(Ptr<NetDevice> netDevice) const;
+ shared_ptr<Face>
+ getFaceByNetDevice(Ptr<NetDevice> netDevice) const;
protected:
virtual void
@@ -142,13 +157,23 @@
NotifyNewAggregate();
private:
- L3Protocol(const L3Protocol&); ///< copy constructor is disabled
-
- L3Protocol&
- operator=(const L3Protocol&); ///< copy operator is disabled
+ void
+ initializeManagement();
private:
+ class Impl;
+ std::unique_ptr<Impl> m_impl;
+
+ // These objects are aggregated, but for optimization, get them here
Ptr<Node> m_node; ///< \brief node on which ndn stack is installed
+
+ TracedCallback<const Interest&, const Face&>
+ m_inInterests; ///< @brief trace of incoming Interests
+ TracedCallback<const Interest&, const Face&>
+ m_outInterests; ///< @brief Transmitted interests trace
+
+ TracedCallback<const Data&, const Face&> m_outData; ///< @brief trace of outgoing Data
+ TracedCallback<const Data&, const Face&> m_inData; ///< @brief trace of incoming Data
};
} // namespace ndn