model+helper+tests: Create an ndnSIM-specific transport for the NFD face system
This commit replaces the previous hack of implementing NS-3's inter-node
communication using the LinkService abstraction of the NFD face system.
The new implementation has higher memory overhead, but allows simulation
of any LinkService versions, including GenericLinkService that
implements NDNLPv2 protocol (i.e., fragmentation, network NACKs, etc.).
Change-Id: I3d16bcf29f4858049d1040a3e421e1c7151b3ba2
Refs: #3871, #3873
diff --git a/model/ndn-app-link-service.cpp b/model/ndn-app-link-service.cpp
index 6b89b42..2dbce52 100644
--- a/model/ndn-app-link-service.cpp
+++ b/model/ndn-app-link-service.cpp
@@ -70,7 +70,7 @@
NS_LOG_FUNCTION(this << &nack);
// to decouple callbacks
- // Simulator::ScheduleNow(&App::OnNack, m_app, nack.shared_from_this());
+ Simulator::ScheduleNow(&App::OnNack, m_app, make_shared<lp::Nack>(nack));
}
//
diff --git a/model/ndn-block-header.cpp b/model/ndn-block-header.cpp
new file mode 100644
index 0000000..78d4f5c
--- /dev/null
+++ b/model/ndn-block-header.cpp
@@ -0,0 +1,171 @@
+/* -*- 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-block-header.hpp"
+
+#include <iosfwd>
+#include <boost/iostreams/concepts.hpp>
+#include <boost/iostreams/stream.hpp>
+
+#include <ndn-cxx/encoding/tlv.hpp>
+#include <ndn-cxx/interest.hpp>
+#include <ndn-cxx/data.hpp>
+#include <ndn-cxx/lp/packet.hpp>
+
+namespace io = boost::iostreams;
+namespace nfdFace = nfd::face;
+
+namespace ns3 {
+namespace ndn {
+
+ns3::TypeId
+BlockHeader::GetTypeId()
+{
+ static ns3::TypeId tid =
+ ns3::TypeId("ns3::ndn::Packet")
+ .SetGroupName("Ndn")
+ .SetParent<Header>()
+ .AddConstructor<BlockHeader>()
+ ;
+ return tid;
+}
+
+TypeId
+BlockHeader::GetInstanceTypeId(void) const
+{
+ return GetTypeId();
+}
+
+BlockHeader::BlockHeader()
+{
+}
+
+BlockHeader::BlockHeader(const nfdFace::Transport::Packet& packet)
+ : m_block(packet.packet)
+{
+}
+
+uint32_t
+BlockHeader::GetSerializedSize(void) const
+{
+ return m_block.size();
+}
+
+void
+BlockHeader::Serialize(ns3::Buffer::Iterator start) const
+{
+ start.Write(m_block.wire(), m_block.size());
+}
+
+class Ns3BufferIteratorSource : public io::source {
+public:
+ Ns3BufferIteratorSource(ns3::Buffer::Iterator& is)
+ : m_is(is)
+ {
+ }
+
+ std::streamsize
+ read(char* buf, std::streamsize nMaxRead)
+ {
+ std::streamsize i = 0;
+ for (; i < nMaxRead && !m_is.IsEnd(); ++i) {
+ buf[i] = m_is.ReadU8();
+ }
+ if (i == 0) {
+ return -1;
+ }
+ else {
+ return i;
+ }
+ }
+
+private:
+ ns3::Buffer::Iterator& m_is;
+};
+
+uint32_t
+BlockHeader::Deserialize(ns3::Buffer::Iterator start)
+{
+ io::stream<Ns3BufferIteratorSource> is(start);
+ m_block = ::ndn::Block::fromStream(is);
+ return m_block.size();
+}
+
+void
+BlockHeader::Print(std::ostream& os) const
+{
+ namespace tlv = ::ndn::tlv;
+ namespace lp = ::ndn::lp;
+
+ std::function<void(const Block& block)> decodeAndPrint = [&os, &decodeAndPrint] (const Block& block) {
+ switch (block.type()) {
+ case tlv::Interest: {
+ Interest i(block);
+ os << "Interest: " << i;
+ break;
+ }
+ case tlv::Data: {
+ Data d(block);
+ os << "Data: " << d.getName();
+ break;
+ }
+ case lp::tlv::LpPacket: {
+ os << "NDNLP(";
+ lp::Packet p(block);
+ if (p.has<lp::FragCountField>() && p.get<lp::FragCountField>() != 1) {
+ os << "fragment " << (p.get<lp::FragIndexField>() + 1) << " out of " << p.get<lp::FragCountField>();
+ }
+ else {
+ if (p.has<lp::NackField>()) {
+ lp::NackHeader nack = p.get<lp::NackField>();
+ os << "NACK(" << nack.getReason() << ") for ";
+ }
+
+ ::ndn::Buffer::const_iterator first, last;
+ std::tie(first, last) = p.get<lp::FragmentField>(0);
+ Block fragmentBlock(&*first, std::distance(first, last));
+ decodeAndPrint(fragmentBlock);
+ }
+ os << ")";
+ break;
+ }
+ default: {
+ os << "Unrecognized";
+ break;
+ }
+ }
+ };
+
+ decodeAndPrint(m_block);
+}
+
+Block&
+BlockHeader::getBlock()
+{
+ return m_block;
+}
+
+const Block&
+BlockHeader::getBlock() const
+{
+ return m_block;
+}
+
+} // namespace ndn
+} // namespace ns3
diff --git a/model/ndn-header.hpp b/model/ndn-block-header.hpp
similarity index 80%
rename from model/ndn-header.hpp
rename to model/ndn-block-header.hpp
index ea1f301..f2c73ab 100644
--- a/model/ndn-header.hpp
+++ b/model/ndn-block-header.hpp
@@ -17,18 +17,19 @@
* ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
**/
-#ifndef NDNSIM_NDN_HEADER_HPP
-#define NDNSIM_NDN_HEADER_HPP
+#ifndef NDNSIM_NDN_BLOCK_HEADER_HPP
+#define NDNSIM_NDN_BLOCK_HEADER_HPP
#include "ns3/header.h"
#include "ndn-common.hpp"
+namespace nfdFace = nfd::face;
+
namespace ns3 {
namespace ndn {
-template<class Pkt>
-class PacketHeader : public Header {
+class BlockHeader : public Header {
public:
static ns3::TypeId
GetTypeId();
@@ -36,9 +37,9 @@
virtual TypeId
GetInstanceTypeId(void) const;
- PacketHeader();
+ BlockHeader();
- PacketHeader(const Pkt& packet);
+ BlockHeader(const nfdFace::Transport::Packet& packet);
virtual uint32_t
GetSerializedSize(void) const;
@@ -52,14 +53,17 @@
virtual void
Print(std::ostream& os) const;
- shared_ptr<const Pkt>
- getPacket();
+ Block&
+ getBlock();
+
+ const Block&
+ getBlock() const;
private:
- shared_ptr<const Pkt> m_packet;
+ Block m_block;
};
} // namespace ndn
} // namespace ns3
-#endif // NDNSIM_NDN_HEADER_HPP
+#endif // NDNSIM_NDN_BLOCK_HEADER_HPP
diff --git a/model/ndn-header.cpp b/model/ndn-header.cpp
deleted file mode 100644
index 929b001..0000000
--- a/model/ndn-header.cpp
+++ /dev/null
@@ -1,158 +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-header.hpp"
-
-#include <iosfwd>
-#include <boost/iostreams/concepts.hpp>
-#include <boost/iostreams/stream.hpp>
-
-namespace io = boost::iostreams;
-
-namespace ns3 {
-namespace ndn {
-
-template<>
-ns3::TypeId
-PacketHeader<Interest>::GetTypeId()
-{
- static ns3::TypeId tid =
- ns3::TypeId("ns3::ndn::Interest")
- .SetGroupName("Ndn")
- .SetParent<Header>()
- .AddConstructor<PacketHeader<Interest>>()
- ;
-
- return tid;
-}
-
-template<>
-ns3::TypeId
-PacketHeader<Data>::GetTypeId()
-{
- static ns3::TypeId tid =
- ns3::TypeId("ns3::ndn::Data")
- .SetGroupName("Ndn")
- .SetParent<Header>()
- .AddConstructor<PacketHeader<Data>>()
- ;
- return tid;
-}
-
-template<class Pkt>
-TypeId
-PacketHeader<Pkt>::GetInstanceTypeId(void) const
-{
- return GetTypeId();
-}
-
-template<class Pkt>
-PacketHeader<Pkt>::PacketHeader()
-{
-}
-
-template<class Pkt>
-PacketHeader<Pkt>::PacketHeader(const Pkt& packet)
- : m_packet(packet.shared_from_this())
-{
-}
-
-template<class Pkt>
-uint32_t
-PacketHeader<Pkt>::GetSerializedSize(void) const
-{
- return m_packet->wireEncode().size();
-}
-
-template<class Pkt>
-void
-PacketHeader<Pkt>::Serialize(ns3::Buffer::Iterator start) const
-{
- start.Write(m_packet->wireEncode().wire(), m_packet->wireEncode().size());
-}
-
-class Ns3BufferIteratorSource : public io::source {
-public:
- Ns3BufferIteratorSource(ns3::Buffer::Iterator& is)
- : m_is(is)
- {
- }
-
- std::streamsize
- read(char* buf, std::streamsize nMaxRead)
- {
- std::streamsize i = 0;
- for (; i < nMaxRead && !m_is.IsEnd(); ++i) {
- buf[i] = m_is.ReadU8();
- }
- if (i == 0) {
- return -1;
- }
- else {
- return i;
- }
- }
-
-private:
- ns3::Buffer::Iterator& m_is;
-};
-
-template<class Pkt>
-uint32_t
-PacketHeader<Pkt>::Deserialize(ns3::Buffer::Iterator start)
-{
- auto packet = make_shared<Pkt>();
- io::stream<Ns3BufferIteratorSource> is(start);
- packet->wireDecode(::ndn::Block::fromStream(is));
- m_packet = packet;
- return packet->wireEncode().size();
-}
-
-template<>
-void
-PacketHeader<Interest>::Print(std::ostream& os) const
-{
- os << "I: " << *m_packet;
-}
-
-template<>
-void
-PacketHeader<Data>::Print(std::ostream& os) const
-{
- os << "D: " << *m_packet;
-}
-
-template<class Pkt>
-shared_ptr<const Pkt>
-PacketHeader<Pkt>::getPacket()
-{
- return m_packet;
-}
-
-typedef PacketHeader<Interest> InterestHeader;
-typedef PacketHeader<Data> DataHeader;
-
-NS_OBJECT_ENSURE_REGISTERED(InterestHeader);
-NS_OBJECT_ENSURE_REGISTERED(DataHeader);
-
-template class PacketHeader<Interest>;
-template class PacketHeader<Data>;
-
-} // namespace ndn
-} // namespace ns3
diff --git a/model/ndn-l3-protocol.cpp b/model/ndn-l3-protocol.cpp
index b6fa69c..74f18ca 100644
--- a/model/ndn-l3-protocol.cpp
+++ b/model/ndn-l3-protocol.cpp
@@ -29,7 +29,7 @@
#include "ns3/pointer.h"
#include "ns3/simulator.h"
-#include "ndn-net-device-link-service.hpp"
+#include "ndn-net-device-transport.hpp"
#include "../helper/ndn-stack-helper.hpp"
#include "cs/ndn-content-store.hpp"
@@ -91,6 +91,13 @@
////////////////////////////////////////////////////////////////////
+ .AddTraceSource("OutNack", "OutNack", MakeTraceSourceAccessor(&L3Protocol::m_outNack),
+ "ns3::ndn::L3Protocol::NackTraceCallback")
+ .AddTraceSource("InNack", "InNack", MakeTraceSourceAccessor(&L3Protocol::m_inNack),
+ "ns3::ndn::L3Protocol::NackTraceCallback")
+
+ ////////////////////////////////////////////////////////////////////
+
.AddTraceSource("SatisfiedInterests", "SatisfiedInterests",
MakeTraceSourceAccessor(&L3Protocol::m_satisfiedInterests),
"ns3::ndn::L3Protocol::SatisfiedInterestsCallback")
@@ -434,7 +441,13 @@
this->m_inData(data, *face);
}
});
- // TODO Add nack signals
+
+ face->afterReceiveNack.connect([this, weakFace](const lp::Nack& nack) {
+ shared_ptr<Face> face = weakFace.lock();
+ if (face != nullptr) {
+ this->m_inNack(nack, *face);
+ }
+ });
auto tracingLink = face->getLinkService();
NS_LOG_LOGIC("Adding trace sources for afterSendInterest and afterSendData");
@@ -452,7 +465,12 @@
}
});
- // TODO Add nack signals
+ tracingLink->afterSendNack.connect([this, weakFace](const lp::Nack& nack) {
+ shared_ptr<Face> face = weakFace.lock();
+ if (face != nullptr) {
+ this->m_outNack(nack, *face);
+ }
+ });
return face->getId();
}
@@ -467,11 +485,11 @@
L3Protocol::getFaceByNetDevice(Ptr<NetDevice> netDevice) const
{
for (auto& i : m_impl->m_forwarder->getFaceTable()) {
- auto linkService = dynamic_cast<NetDeviceLinkService*>(i.getLinkService());
- if (linkService == nullptr)
+ auto transport = dynamic_cast<NetDeviceTransport*>(i.getTransport());
+ if (transport == nullptr)
continue;
- if (linkService->GetNetDevice() == netDevice)
+ if (transport->GetNetDevice() == netDevice)
return i.shared_from_this();
}
return nullptr;
diff --git a/model/ndn-l3-protocol.hpp b/model/ndn-l3-protocol.hpp
index cca0277..c3619aa 100644
--- a/model/ndn-l3-protocol.hpp
+++ b/model/ndn-l3-protocol.hpp
@@ -213,6 +213,9 @@
TracedCallback<const Data&, const Face&> m_outData; ///< @brief trace of outgoing Data
TracedCallback<const Data&, const Face&> m_inData; ///< @brief trace of incoming Data
+ TracedCallback<const lp::Nack&, const Face&> m_outNack; ///< @brief trace of outgoing Nack
+ TracedCallback<const lp::Nack&, const Face&> m_inNack; ///< @brief trace of incoming Nack
+
TracedCallback<const nfd::pit::Entry&, const Face&/*in face*/, const Data&> m_satisfiedInterests;
TracedCallback<const nfd::pit::Entry&> m_timedOutInterests;
};
diff --git a/model/ndn-net-device-link-service.cpp b/model/ndn-net-device-link-service.cpp
deleted file mode 100644
index 09a03a0..0000000
--- a/model/ndn-net-device-link-service.cpp
+++ /dev/null
@@ -1,150 +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-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 {
-
-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-link-service.hpp b/model/ndn-net-device-link-service.hpp
deleted file mode 100644
index 27e02d6..0000000
--- a/model/ndn-net-device-link-service.hpp
+++ /dev/null
@@ -1,103 +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 NDN_NET_DEVICE_LINK_SERVICE_HPP
-#define NDN_NET_DEVICE_LINK_SERVICE_HPP
-
-#include "ns3/ndnSIM/model/ndn-common.hpp"
-#include "ns3/ndnSIM/NFD/daemon/face/link-service.hpp"
-
-#include "ns3/net-device.h"
-
-namespace ns3 {
-namespace ndn {
-
-/**
- * \ingroup ndn-face
- * \brief Implementation of layer-2 (Ethernet) LinkService (current hack, to be changed eventually)
- *
- * NetDeviceLinkService is permanently associated with one NetDevice
- * object and this object cannot be changed for the lifetime of the
- * face
- *
- * \see AppLinkService
- */
-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 NetDeviceLinkService will be associate
- */
- NetDeviceLinkService(Ptr<Node> node, const Ptr<NetDevice>& netDevice);
-
- virtual
- ~NetDeviceLinkService();
-
-public:
- /**
- * \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);
-
- /// \brief callback from lower layers
- void
- receiveFromNetDevice(Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol,
- const Address& from, const Address& to, NetDevice::PacketType packetType);
-
-private:
- Ptr<Node> m_node;
- Ptr<NetDevice> m_netDevice; ///< \brief Smart pointer to NetDevice
-};
-
-} // namespace ndn
-} // namespace ns3
-
-#endif // NDN_NET_DEVICE_LINK_SERVICE_HPP
diff --git a/model/ndn-net-device-transport.cpp b/model/ndn-net-device-transport.cpp
new file mode 100644
index 0000000..85684af
--- /dev/null
+++ b/model/ndn-net-device-transport.cpp
@@ -0,0 +1,130 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2011-2016 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-transport.hpp"
+
+#include "../helper/ndn-stack-helper.hpp"
+#include "ndn-block-header.hpp"
+#include "../utils/ndn-ns3-packet-tag.hpp"
+
+#include <ndn-cxx/encoding/block.hpp>
+#include <ndn-cxx/interest.hpp>
+#include <ndn-cxx/data.hpp>
+
+NS_LOG_COMPONENT_DEFINE("ndn.NetDeviceTransport");
+
+namespace ns3 {
+namespace ndn {
+
+NetDeviceTransport::NetDeviceTransport(Ptr<Node> node,
+ const Ptr<NetDevice>& netDevice,
+ const std::string& localUri,
+ const std::string& remoteUri,
+ ::ndn::nfd::FaceScope scope,
+ ::ndn::nfd::FacePersistency persistency,
+ ::ndn::nfd::LinkType linkType)
+ : m_netDevice(netDevice)
+ , m_node(node)
+{
+ 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
+
+ NS_LOG_FUNCTION(this << "Creating an ndnSIM transport instance for netDevice with URI"
+ << this->getLocalUri());
+
+ NS_ASSERT_MSG(m_netDevice != 0, "NetDeviceFace needs to be assigned a valid NetDevice");
+
+ m_node->RegisterProtocolHandler(MakeCallback(&NetDeviceTransport::receiveFromNetDevice, this),
+ L3Protocol::ETHERNET_FRAME_TYPE, m_netDevice,
+ true /*promiscuous mode*/);
+}
+
+NetDeviceTransport::~NetDeviceTransport()
+{
+ NS_LOG_FUNCTION_NOARGS();
+}
+
+void
+NetDeviceTransport::beforeChangePersistency(::ndn::nfd::FacePersistency newPersistency)
+{
+ NS_LOG_FUNCTION(this << "Changing persistency for netDevice with URI"
+ << this->getLocalUri() << "currently does nothing");
+ // do nothing for now
+}
+
+void
+NetDeviceTransport::doClose()
+{
+ NS_LOG_FUNCTION(this << "Closing transport for netDevice with URI"
+ << this->getLocalUri());
+
+ // set the state of the transport to "CLOSED"
+ this->setState(nfd::face::TransportState::CLOSED);
+}
+
+void
+NetDeviceTransport::doSend(Packet&& packet)
+{
+ NS_LOG_FUNCTION(this << "Sending packet from netDevice with URI"
+ << this->getLocalUri());
+
+ // convert NFD packet to NS3 packet
+ BlockHeader header(packet);
+
+ Ptr<ns3::Packet> ns3Packet = Create<ns3::Packet>();
+ ns3Packet->AddHeader(header);
+
+ // send the NS3 packet
+ m_netDevice->Send(ns3Packet, m_netDevice->GetBroadcast(),
+ L3Protocol::ETHERNET_FRAME_TYPE);
+}
+
+// callback
+void
+NetDeviceTransport::receiveFromNetDevice(Ptr<NetDevice> device,
+ Ptr<const ns3::Packet> p,
+ uint16_t protocol,
+ const Address& from, const Address& to,
+ NetDevice::PacketType packetType)
+{
+ NS_LOG_FUNCTION(device << p << protocol << from << to << packetType);
+
+ // Convert NS3 packet to NFD packet
+ Ptr<ns3::Packet> packet = p->Copy();
+
+ BlockHeader header;
+ packet->RemoveHeader(header);
+
+ auto nfdPacket = Packet(std::move(header.getBlock()));
+
+ this->receive(std::move(nfdPacket));
+}
+
+Ptr<NetDevice>
+NetDeviceTransport::GetNetDevice() const
+{
+ return m_netDevice;
+}
+
+} // namespace ndn
+} // namespace ns3
diff --git a/model/ndn-net-device-transport.hpp b/model/ndn-net-device-transport.hpp
new file mode 100644
index 0000000..b502d4f
--- /dev/null
+++ b/model/ndn-net-device-transport.hpp
@@ -0,0 +1,81 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2011-2016 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_NET_DEVICE_TRANSPORT_HPP
+#define NDN_NET_DEVICE_TRANSPORT_HPP
+
+#include "ns3/ndnSIM/model/ndn-common.hpp"
+#include "ns3/ndnSIM/NFD/daemon/face/transport.hpp"
+
+#include "ns3/net-device.h"
+#include "ns3/log.h"
+#include "ns3/packet.h"
+#include "ns3/node.h"
+#include "ns3/pointer.h"
+
+#include "ns3/point-to-point-net-device.h"
+#include "ns3/channel.h"
+
+namespace ns3 {
+namespace ndn {
+
+/**
+ * \ingroup ndn-face
+ * \brief ndnSIM-specific transport
+ */
+class NetDeviceTransport : public nfd::face::Transport
+{
+public:
+ NetDeviceTransport(Ptr<Node> node, const Ptr<NetDevice>& netDevice,
+ 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);
+
+ ~NetDeviceTransport();
+
+ Ptr<NetDevice>
+ GetNetDevice() const;
+
+private:
+ virtual void
+ beforeChangePersistency(::ndn::nfd::FacePersistency newPersistency) override;
+
+ virtual void
+ doClose() override;
+
+ virtual void
+ doSend(Packet&& packet) override;
+
+ void
+ receiveFromNetDevice(Ptr<NetDevice> device,
+ Ptr<const ns3::Packet> p,
+ uint16_t protocol,
+ const Address& from, const Address& to,
+ NetDevice::PacketType packetType);
+
+ Ptr<NetDevice> m_netDevice; ///< \brief Smart pointer to NetDevice
+ Ptr<Node> m_node;
+};
+
+} // namespace ndn
+} // namespace ns3
+
+#endif // NDN_NULL_TRANSPORT_HPP
diff --git a/model/ndn-ns3.cpp b/model/ndn-ns3.cpp
deleted file mode 100644
index 7e0996a..0000000
--- a/model/ndn-ns3.cpp
+++ /dev/null
@@ -1,95 +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-ns3.hpp"
-
-#include <ndn-cxx/encoding/block.hpp>
-#include <ndn-cxx/interest.hpp>
-#include <ndn-cxx/data.hpp>
-
-#include "ndn-header.hpp"
-#include "../utils/ndn-ns3-packet-tag.hpp"
-
-namespace ns3 {
-namespace ndn {
-
-template<class T>
-std::shared_ptr<const T>
-Convert::FromPacket(Ptr<Packet> packet)
-{
- PacketHeader<T> header;
- packet->RemoveHeader(header);
-
- auto pkt = header.getPacket();
- pkt->setTag(make_shared<Ns3PacketTag>(packet));
-
- return pkt;
-}
-
-template std::shared_ptr<const Interest>
-Convert::FromPacket<Interest>(Ptr<Packet> packet);
-
-template std::shared_ptr<const Data>
-Convert::FromPacket<Data>(Ptr<Packet> packet);
-
-template<class T>
-Ptr<Packet>
-Convert::ToPacket(const T& pkt)
-{
- PacketHeader<T> header(pkt);
-
- Ptr<Packet> packet;
-
- auto tag = pkt.template getTag<Ns3PacketTag>();
- if (tag != nullptr) {
- packet = tag->getPacket()->Copy();
- }
- else {
- packet = Create<Packet>();
- }
-
- packet->AddHeader(header);
- return packet;
-}
-
-template Ptr<Packet>
-Convert::ToPacket<Interest>(const Interest& packet);
-
-template Ptr<Packet>
-Convert::ToPacket<Data>(const Data& packet);
-
-uint32_t
-Convert::getPacketType(Ptr<const Packet> packet)
-{
- uint8_t type;
- uint32_t nRead = packet->CopyData(&type, 1);
- if (nRead != 1) {
- throw ::ndn::tlv::Error("Unknown header");
- }
-
- if (type == ::ndn::tlv::Interest || type == ::ndn::tlv::Data) {
- return type;
- }
- else {
- throw ::ndn::tlv::Error("Unknown header");
- }
-}
-
-} // namespace ndn
-} // namespace ns3
diff --git a/model/ndn-ns3.hpp b/model/ndn-ns3.hpp
deleted file mode 100644
index b292fca..0000000
--- a/model/ndn-ns3.hpp
+++ /dev/null
@@ -1,47 +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 NDN_NS3_HPP
-#define NDN_NS3_HPP
-
-#include "ns3/packet.h"
-#include "ns3/ptr.h"
-#include <memory>
-
-namespace ns3 {
-namespace ndn {
-
-class Convert {
-public:
- template<class T>
- static std::shared_ptr<const T>
- FromPacket(Ptr<Packet> packet);
-
- template<class T>
- static Ptr<Packet>
- ToPacket(const T& pkt);
-
- static uint32_t
- getPacketType(Ptr<const Packet> packet);
-};
-
-} // namespace ndn
-} // namespace ns3
-
-#endif