NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
ndn-net-device-transport.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
21 
22 #include "../helper/ndn-stack-helper.hpp"
23 #include "ndn-block-header.hpp"
24 #include "../utils/ndn-ns3-packet-tag.hpp"
25 
26 #include <ndn-cxx/encoding/block.hpp>
27 #include <ndn-cxx/interest.hpp>
28 #include <ndn-cxx/data.hpp>
29 
30 NS_LOG_COMPONENT_DEFINE("ndn.NetDeviceTransport");
31 
32 namespace ns3 {
33 namespace ndn {
34 
36  const Ptr<NetDevice>& netDevice,
37  const std::string& localUri,
38  const std::string& remoteUri,
39  ::ndn::nfd::FaceScope scope,
40  ::ndn::nfd::FacePersistency persistency,
41  ::ndn::nfd::LinkType linkType)
42  : m_netDevice(netDevice)
43  , m_node(node)
44 {
45  this->setLocalUri(FaceUri(localUri));
46  this->setRemoteUri(FaceUri(remoteUri));
47  this->setScope(scope);
48  this->setPersistency(persistency);
49  this->setLinkType(linkType);
50  // this->setMtu(udp::computeMtu(m_socket.local_endpoint())); // not sure what should be here
51 
52  NS_LOG_FUNCTION(this << "Creating an ndnSIM transport instance for netDevice with URI"
53  << this->getLocalUri());
54 
55  NS_ASSERT_MSG(m_netDevice != 0, "NetDeviceFace needs to be assigned a valid NetDevice");
56 
57  m_node->RegisterProtocolHandler(MakeCallback(&NetDeviceTransport::receiveFromNetDevice, this),
59  true /*promiscuous mode*/);
60 }
61 
63 {
64  NS_LOG_FUNCTION_NOARGS();
65 }
66 
67 void
68 NetDeviceTransport::doClose()
69 {
70  NS_LOG_FUNCTION(this << "Closing transport for netDevice with URI"
71  << this->getLocalUri());
72 
73  // set the state of the transport to "CLOSED"
75 }
76 
77 void
78 NetDeviceTransport::doSend(Packet&& packet)
79 {
80  NS_LOG_FUNCTION(this << "Sending packet from netDevice with URI"
81  << this->getLocalUri());
82 
83  // convert NFD packet to NS3 packet
84  BlockHeader header(packet);
85 
86  Ptr<ns3::Packet> ns3Packet = Create<ns3::Packet>();
87  ns3Packet->AddHeader(header);
88 
89  // send the NS3 packet
90  m_netDevice->Send(ns3Packet, m_netDevice->GetBroadcast(),
92 }
93 
94 // callback
95 void
96 NetDeviceTransport::receiveFromNetDevice(Ptr<NetDevice> device,
97  Ptr<const ns3::Packet> p,
98  uint16_t protocol,
99  const Address& from, const Address& to,
100  NetDevice::PacketType packetType)
101 {
102  NS_LOG_FUNCTION(device << p << protocol << from << to << packetType);
103 
104  // Convert NS3 packet to NFD packet
105  Ptr<ns3::Packet> packet = p->Copy();
106 
107  BlockHeader header;
108  packet->RemoveHeader(header);
109 
110  auto nfdPacket = Packet(std::move(header.getBlock()));
111 
112  this->receive(std::move(nfdPacket));
113 }
114 
115 Ptr<NetDevice>
117 {
118  return m_netDevice;
119 }
120 
121 } // namespace ndn
122 } // namespace ns3
void setPersistency(ndn::nfd::FacePersistency newPersistency)
changes face persistency setting
Definition: transport.cpp:151
Copyright (c) 2011-2015 Regents of the University of California.
static const uint16_t ETHERNET_FRAME_TYPE
Ethernet Frame Type of Ndn.
void setRemoteUri(const FaceUri &uri)
Definition: transport.hpp:396
Ptr< NetDevice > GetNetDevice() const
stores a packet along with the remote endpoint
Definition: transport.hpp:113
FaceUri getLocalUri() const
Definition: transport.hpp:378
void setLinkType(ndn::nfd::LinkType linkType)
Definition: transport.hpp:426
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)
void setScope(ndn::nfd::FaceScope scope)
Definition: transport.hpp:408
the transport is closed, and can be safely deallocated
Copyright (c) 2011-2015 Regents of the University of California.
void setLocalUri(const FaceUri &uri)
Definition: transport.hpp:384
void setState(TransportState newState)
set transport state
Definition: transport.cpp:174
void receive(Packet &&packet)
receive a link-layer packet
Definition: transport.cpp:117