model: Change NetDeviceFace into NetDeviceLinkService to match NFD 0.4+ Face model
ndnSIM (for now) intentionally uses LinkService instead of Transport for
optimization purposes and in order to preserve ns3::Packet Tags. This
may be fixed in the future when there is a different mechanism to
propagate ns3 Tags or Tags are no longer necessary.
Change-Id: I2aeef8f37d587374a1c9fe04386e33b6fde83fe0
Refs: #3560
diff --git a/model/ndn-common.hpp b/model/ndn-common.hpp
index 237fc3e..7397de3 100644
--- a/model/ndn-common.hpp
+++ b/model/ndn-common.hpp
@@ -17,8 +17,8 @@
* ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
**/
-#ifndef NDN_COMMON_H
-#define NDN_COMMON_H
+#ifndef NDNSIM_NDN_COMMON_H
+#define NDNSIM_NDN_COMMON_H
#include "ns3/nstime.h"
#include "ns3/simulator.h"
@@ -35,6 +35,8 @@
#include <ndn-cxx/util/time.hpp>
+#include "NFD/daemon/face/face.hpp"
+
namespace nfd {
}
@@ -50,6 +52,10 @@
using namespace ::ndn::time;
}
+namespace lp {
+using namespace ::ndn::lp;
+}
+
using ::ndn::Exclude;
using std::shared_ptr;
@@ -63,12 +69,30 @@
using ::ndn::Block;
using ::ndn::KeyChain;
+using ::nfd::Face;
+using ::ndn::util::FaceUri;
+
#ifndef DOXYGEN
// For python bindings
namespace nfd = ::nfd;
#endif // DOXYGEN
+using ::ndn::make_unique;
+
} // namespace ndn
} // namespace ns3
-#endif // NDN_COMMON_H
+namespace nfd {
+namespace face {
+
+inline std::ostream&
+operator<<(std::ostream& os, const Face& face)
+{
+ os << face.getLocalUri();
+ return os;
+}
+
+} // namespace face
+} // namespace nfd
+
+#endif // NDNSIM_NDN_COMMON_H
diff --git a/model/ndn-face.hpp b/model/ndn-face.hpp
deleted file mode 100644
index c532501..0000000
--- a/model/ndn-face.hpp
+++ /dev/null
@@ -1,46 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2011-2015 Regents of the University of California.
- *
- * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
- * contributors.
- *
- * ndnSIM is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * ndnSIM 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
- * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- **/
-
-#ifndef NDNSIM_NDN_FACE_HPP
-#define NDNSIM_NDN_FACE_HPP
-
-#include "ns3/ndnSIM/NFD/daemon/face/face.hpp"
-#include <ndn-cxx/util/face-uri.hpp>
-
-namespace ns3 {
-namespace ndn {
-
-using nfd::Face;
-using ::ndn::util::FaceUri;
-
-} // namespace ndn
-} // namespace ns3
-
-namespace nfd {
-
-inline std::ostream&
-operator<<(std::ostream& os, const Face& face)
-{
- os << face.getLocalUri();
- return os;
-}
-
-} // namespace nfd
-
-#endif // NDNSIM_NDN_FACE_HPP
diff --git a/model/ndn-l3-protocol.hpp b/model/ndn-l3-protocol.hpp
index 88b522e..0145d72 100644
--- a/model/ndn-l3-protocol.hpp
+++ b/model/ndn-l3-protocol.hpp
@@ -21,7 +21,6 @@
#define NDN_L3_PROTOCOL_H
#include "ns3/ndnSIM/model/ndn-common.hpp"
-#include "ns3/ndnSIM/model/ndn-face.hpp"
#include <list>
#include <vector>
diff --git a/model/ndn-net-device-face.cpp b/model/ndn-net-device-face.cpp
deleted file mode 100644
index e13f949..0000000
--- a/model/ndn-net-device-face.cpp
+++ /dev/null
@@ -1,143 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2011-2015 Regents of the University of California.
- *
- * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
- * contributors.
- *
- * ndnSIM is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * ndnSIM 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
- * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- **/
-
-#include "ndn-net-device-face.hpp"
-#include "ndn-l3-protocol.hpp"
-
-#include "ndn-ns3.hpp"
-
-#include "ns3/net-device.h"
-#include "ns3/log.h"
-#include "ns3/packet.h"
-#include "ns3/node.h"
-#include "ns3/pointer.h"
-
-// #include "ns3/address.h"
-#include "ns3/point-to-point-net-device.h"
-#include "ns3/channel.h"
-
-#include "../utils/ndn-fw-hop-count-tag.hpp"
-
-NS_LOG_COMPONENT_DEFINE("ndn.NetDeviceFace");
-
-namespace ns3 {
-namespace ndn {
-
-NetDeviceFace::NetDeviceFace(Ptr<Node> node, const Ptr<NetDevice>& netDevice)
- : Face(FaceUri("netDeviceFace://"), FaceUri("netDeviceFace://"))
- , m_node(node)
- , m_netDevice(netDevice)
-{
- NS_LOG_FUNCTION(this << netDevice);
-
- setMetric(1); // default metric
-
- NS_ASSERT_MSG(m_netDevice != 0, "NetDeviceFace needs to be assigned a valid NetDevice");
-
- m_node->RegisterProtocolHandler(MakeCallback(&NetDeviceFace::receiveFromNetDevice, this),
- L3Protocol::ETHERNET_FRAME_TYPE, m_netDevice,
- true /*promiscuous mode*/);
-}
-
-NetDeviceFace::~NetDeviceFace()
-{
- NS_LOG_FUNCTION_NOARGS();
- close();
-}
-
-void
-NetDeviceFace::close()
-{
- m_node->UnregisterProtocolHandler(MakeCallback(&NetDeviceFace::receiveFromNetDevice, this));
- this->fail("Close connection");
-}
-
-Ptr<NetDevice>
-NetDeviceFace::GetNetDevice() const
-{
- return m_netDevice;
-}
-
-void
-NetDeviceFace::send(Ptr<Packet> packet)
-{
- NS_ASSERT_MSG(packet->GetSize() <= m_netDevice->GetMtu(),
- "Packet size " << packet->GetSize() << " exceeds device MTU "
- << m_netDevice->GetMtu());
-
- FwHopCountTag tag;
- packet->RemovePacketTag(tag);
- tag.Increment();
- packet->AddPacketTag(tag);
-
- m_netDevice->Send(packet, m_netDevice->GetBroadcast(), L3Protocol::ETHERNET_FRAME_TYPE);
-}
-
-void
-NetDeviceFace::sendInterest(const Interest& interest)
-{
- NS_LOG_FUNCTION(this << &interest);
-
- this->emitSignal(onSendInterest, interest);
-
- Ptr<Packet> packet = Convert::ToPacket(interest);
- send(packet);
-}
-
-void
-NetDeviceFace::sendData(const Data& data)
-{
- NS_LOG_FUNCTION(this << &data);
-
- this->emitSignal(onSendData, data);
-
- Ptr<Packet> packet = Convert::ToPacket(data);
- send(packet);
-}
-
-// callback
-void
-NetDeviceFace::receiveFromNetDevice(Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol,
- const Address& from, const Address& to,
- NetDevice::PacketType packetType)
-{
- NS_LOG_FUNCTION(device << p << protocol << from << to << packetType);
-
- Ptr<Packet> packet = p->Copy();
- try {
- uint32_t type = Convert::getPacketType(p);
- if (type == ::ndn::tlv::Interest) {
- shared_ptr<const Interest> i = Convert::FromPacket<Interest>(packet);
- this->emitSignal(onReceiveInterest, *i);
- }
- else if (type == ::ndn::tlv::Data) {
- shared_ptr<const Data> d = Convert::FromPacket<Data>(packet);
- this->emitSignal(onReceiveData, *d);
- }
- else {
- NS_LOG_ERROR("Unsupported TLV packet");
- }
- }
- catch (::ndn::tlv::Error&) {
- NS_LOG_ERROR("Unrecognized TLV packet");
- }
-}
-
-} // namespace ndn
-} // namespace ns3
diff --git a/model/ndn-net-device-link-service.cpp b/model/ndn-net-device-link-service.cpp
new file mode 100644
index 0000000..ecb262a
--- /dev/null
+++ b/model/ndn-net-device-link-service.cpp
@@ -0,0 +1,154 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2011-2015 Regents of the University of California.
+ *
+ * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
+ * contributors.
+ *
+ * ndnSIM is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * ndnSIM 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
+ * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+#include "ndn-net-device-link-service.hpp"
+#include "ndn-l3-protocol.hpp"
+
+#include "ndn-ns3.hpp"
+
+#include "ns3/net-device.h"
+#include "ns3/log.h"
+#include "ns3/packet.h"
+#include "ns3/node.h"
+#include "ns3/pointer.h"
+
+// #include "ns3/address.h"
+#include "ns3/point-to-point-net-device.h"
+#include "ns3/channel.h"
+
+#include "../utils/ndn-fw-hop-count-tag.hpp"
+
+NS_LOG_COMPONENT_DEFINE("ndn.NetDeviceLinkService");
+
+namespace ns3 {
+namespace ndn {
+
+// TODO: remove as soon as L3Protocol is back
+const uint16_t L3Protocol::ETHERNET_FRAME_TYPE = 0x7777;
+const uint16_t L3Protocol::IP_STACK_PORT = 9695;
+
+NetDeviceLinkService::NetDeviceLinkService(Ptr<Node> node, const Ptr<NetDevice>& netDevice)
+ : m_node(node)
+ , m_netDevice(netDevice)
+{
+ NS_LOG_FUNCTION(this << netDevice);
+
+ NS_ASSERT_MSG(m_netDevice != 0, "NetDeviceFace needs to be assigned a valid NetDevice");
+
+ m_node->RegisterProtocolHandler(MakeCallback(&NetDeviceLinkService::receiveFromNetDevice, this),
+ L3Protocol::ETHERNET_FRAME_TYPE, m_netDevice,
+ true /*promiscuous mode*/);
+}
+
+NetDeviceLinkService::~NetDeviceLinkService()
+{
+ NS_LOG_FUNCTION_NOARGS();
+}
+
+Ptr<Node>
+NetDeviceLinkService::GetNode() const
+{
+ return m_node;
+}
+
+Ptr<NetDevice>
+NetDeviceLinkService::GetNetDevice() const
+{
+ return m_netDevice;
+}
+
+void
+NetDeviceLinkService::doSendInterest(const Interest& interest)
+{
+ NS_LOG_FUNCTION(this << &interest);
+
+ Ptr<Packet> packet = Convert::ToPacket(interest);
+ send(packet);
+}
+
+void
+NetDeviceLinkService::doSendData(const Data& data)
+{
+ NS_LOG_FUNCTION(this << &data);
+
+ Ptr<Packet> packet = Convert::ToPacket(data);
+ send(packet);
+}
+
+void
+NetDeviceLinkService::doSendNack(const lp::Nack& nack)
+{
+ NS_LOG_FUNCTION(this << &nack);
+
+ // TODO
+ // Ptr<Packet> packet = Convert::ToPacket(nack);
+ // send(packet);
+}
+
+// callback
+void
+NetDeviceLinkService::receiveFromNetDevice(Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol,
+ const Address& from, const Address& to,
+ NetDevice::PacketType packetType)
+{
+ NS_LOG_FUNCTION(device << p << protocol << from << to << packetType);
+
+ Ptr<Packet> packet = p->Copy();
+ try {
+ switch (Convert::getPacketType(p)) {
+ case ::ndn::tlv::Interest: {
+ shared_ptr<const Interest> i = Convert::FromPacket<Interest>(packet);
+ this->receiveInterest(*i);
+ break;
+ }
+ case ::ndn::tlv::Data: {
+ shared_ptr<const Data> d = Convert::FromPacket<Data>(packet);
+ this->receiveData(*d);
+ break;
+ }
+ // case ::ndn::tlv::Nack: {
+ // shared_ptr<const Nack> n = Convert::FromPacket<Nack>(packet);
+ // this->onReceiveNack(*n);
+ // }
+ default:
+ NS_LOG_ERROR("Unsupported TLV packet");
+ }
+ }
+ catch (const ::ndn::tlv::Error& e) {
+ NS_LOG_ERROR("Unrecognized TLV packet " << e.what());
+ }
+}
+
+void
+NetDeviceLinkService::send(Ptr<Packet> packet)
+{
+ NS_ASSERT_MSG(packet->GetSize() <= m_netDevice->GetMtu(),
+ "Packet size " << packet->GetSize() << " exceeds device MTU "
+ << m_netDevice->GetMtu());
+
+ FwHopCountTag tag;
+ packet->RemovePacketTag(tag);
+ tag.Increment();
+ packet->AddPacketTag(tag);
+
+ m_netDevice->Send(packet, m_netDevice->GetBroadcast(), L3Protocol::ETHERNET_FRAME_TYPE);
+}
+
+} // namespace face
+} // namespace nfd
diff --git a/model/ndn-net-device-face.hpp b/model/ndn-net-device-link-service.hpp
similarity index 63%
rename from model/ndn-net-device-face.hpp
rename to model/ndn-net-device-link-service.hpp
index 2908b9b..27e02d6 100644
--- a/model/ndn-net-device-face.hpp
+++ b/model/ndn-net-device-link-service.hpp
@@ -17,11 +17,11 @@
* ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
**/
-#ifndef NDN_NET_DEVICE_FACE_H
-#define NDN_NET_DEVICE_FACE_H
+#ifndef NDN_NET_DEVICE_LINK_SERVICE_HPP
+#define NDN_NET_DEVICE_LINK_SERVICE_HPP
#include "ns3/ndnSIM/model/ndn-common.hpp"
-#include "ns3/ndnSIM/model/ndn-face.hpp"
+#include "ns3/ndnSIM/NFD/daemon/face/link-service.hpp"
#include "ns3/net-device.h"
@@ -30,51 +30,60 @@
/**
* \ingroup ndn-face
- * \brief Implementation of layer-2 (Ethernet) Ndn face
+ * \brief Implementation of layer-2 (Ethernet) LinkService (current hack, to be changed eventually)
*
- * This class defines basic functionality of Ndn face. Face is core
- * component responsible for actual delivery of data packet to and
- * from Ndn stack
- *
- * NdnNetDevice face is permanently associated with one NetDevice
+ * NetDeviceLinkService is permanently associated with one NetDevice
* object and this object cannot be changed for the lifetime of the
* face
*
- * \see NdnAppFace, NdnNetDeviceFace, NdnIpv4Face, NdnUdpFace
+ * \see AppLinkService
*/
-class NetDeviceFace : public Face {
+class NetDeviceLinkService : public nfd::face::LinkService
+{
+
public:
/**
* \brief Constructor
*
* @param node Node associated with the face
- * @param netDevice a smart pointer to NetDevice object to which
- * this face will be associate
+ * @param netDevice a smart pointer to NetDevice object to which this NetDeviceLinkService will be associate
*/
- NetDeviceFace(Ptr<Node> node, const Ptr<NetDevice>& netDevice);
+ NetDeviceLinkService(Ptr<Node> node, const Ptr<NetDevice>& netDevice);
- virtual ~NetDeviceFace();
-
-public: // from nfd::Face
- virtual void
- sendInterest(const Interest& interest);
-
- virtual void
- sendData(const Data& data);
-
- virtual void
- close();
+ virtual
+ ~NetDeviceLinkService();
public:
/**
- * \brief Get NetDevice associated with the face
- *
- * \returns smart pointer to NetDevice associated with the face
+ * \brief Get Node associated with the LinkService
+ */
+ Ptr<Node>
+ GetNode() const;
+
+ /**
+ * \brief Get NetDevice associated with the LinkService
*/
Ptr<NetDevice>
GetNetDevice() const;
private:
+ virtual void
+ doSendInterest(const ::ndn::Interest& interest) override;
+
+ virtual void
+ doSendData(const ::ndn::Data& data) override;
+
+ virtual void
+ doSendNack(const ::ndn::lp::Nack& nack) override;
+
+ virtual void
+ doReceivePacket(nfd::face::Transport::Packet&& packet) override
+ {
+ // not used now
+ BOOST_ASSERT(false);
+ }
+
+private:
void
send(Ptr<Packet> packet);
@@ -91,4 +100,4 @@
} // namespace ndn
} // namespace ns3
-#endif // NDN_NET_DEVICE_FACE_H
+#endif // NDN_NET_DEVICE_LINK_SERVICE_HPP
diff --git a/model/null-transport.hpp b/model/null-transport.hpp
new file mode 100644
index 0000000..42ef9c6
--- /dev/null
+++ b/model/null-transport.hpp
@@ -0,0 +1,70 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2011-2015 Regents of the University of California.
+ *
+ * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
+ * contributors.
+ *
+ * ndnSIM is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * ndnSIM 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
+ * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+#ifndef NDN_NULL_TRANSPORT_HPP
+#define NDN_NULL_TRANSPORT_HPP
+
+#include "ns3/ndnSIM/model/ndn-common.hpp"
+#include "ns3/ndnSIM/NFD/daemon/face/transport.hpp"
+
+namespace ns3 {
+namespace ndn {
+
+/**
+ * \ingroup ndn-face
+ * \brief Null transport (does nothing, just fulfills requirements of the interface)
+ */
+class NullTransport : public nfd::face::Transport
+{
+public:
+ NullTransport(const std::string& localUri, const std::string& remoteUri,
+ ::ndn::nfd::FaceScope scope = ::ndn::nfd::FACE_SCOPE_NON_LOCAL,
+ ::ndn::nfd::FacePersistency persistency = ::ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
+ ::ndn::nfd::LinkType linkType = ::ndn::nfd::LINK_TYPE_POINT_TO_POINT)
+ {
+ this->setLocalUri(FaceUri(localUri));
+ this->setRemoteUri(FaceUri(remoteUri));
+ this->setScope(scope);
+ this->setPersistency(persistency);
+ this->setLinkType(linkType);
+ // this->setMtu(udp::computeMtu(m_socket.local_endpoint())); // not sure what should be here
+ }
+
+private:
+ virtual void
+ beforeChangePersistency(::ndn::nfd::FacePersistency newPersistency)
+ {
+ }
+
+ virtual void
+ doClose()
+ {
+ this->setState(nfd::face::TransportState::CLOSED);
+ }
+
+ virtual void
+ doSend(Packet&& packet)
+ {
+ }
+};
+
+} // namespace ndn
+} // namespace ns3
+
+#endif // NDN_NULL_TRANSPORT_HPP
diff --git a/tests/unit-tests/model/ndn-net-device-face.t.cpp b/tests/unit-tests/model/ndn-net-device-face.t.cpp
index 0fad181..aad8c01 100644
--- a/tests/unit-tests/model/ndn-net-device-face.t.cpp
+++ b/tests/unit-tests/model/ndn-net-device-face.t.cpp
@@ -18,7 +18,7 @@
**/
-#include "model/ndn-net-device-face.hpp"
+#include "model/ndn-net-device-link-service.hpp"
#include "../tests-common.hpp"
@@ -53,11 +53,11 @@
Simulator::Stop(Seconds(20.001));
Simulator::Run();
- BOOST_CHECK_EQUAL(getFace("1", "2")->getFaceStatus().getNOutInterests(), 100);
- BOOST_CHECK_EQUAL(getFace("1", "2")->getFaceStatus().getNInDatas(), 100);
+ BOOST_CHECK_EQUAL(getFace("1", "2")->getCounters().nOutInterests, 100);
+ BOOST_CHECK_EQUAL(getFace("1", "2")->getCounters().nInData, 100);
- BOOST_CHECK_EQUAL(getFace("2", "1")->getFaceStatus().getNInInterests(), 100);
- BOOST_CHECK_EQUAL(getFace("2", "1")->getFaceStatus().getNOutDatas(), 100);
+ BOOST_CHECK_EQUAL(getFace("2", "1")->getCounters().nInInterests, 100);
+ BOOST_CHECK_EQUAL(getFace("2", "1")->getCounters().nOutData, 100);
}
BOOST_AUTO_TEST_SUITE_END()
diff --git a/wscript b/wscript
index 40f1468..51ab7f4 100644
--- a/wscript
+++ b/wscript
@@ -139,9 +139,13 @@
module.source = bld.path.ant_glob(['%s/**/*.cpp' % dir for dir in module_dirs],
excl=[
'apps/*',
- 'model/**/*',
+ 'model/ndn-global-router.cpp',
+ 'model/ndn-app-face.cpp',
+ 'model/ndn-app-link-service.cpp',
+ 'model/ndn-l3-protocol.cpp',
'helper/*',
- 'utils/**/*',
+ 'utils/topology/*',
+ 'utils/tracers/*',
'model/ip-faces/*']) + ndnCxxSrc + nfdSrc
module_dirs = ['NFD/core', 'NFD/daemon', 'NFD/rib', 'apps', 'helper', 'model', 'utils']