25 #include "ns3/net-device.h" 
   27 #include "ns3/packet.h" 
   29 #include "ns3/pointer.h" 
   32 #include "ns3/point-to-point-net-device.h" 
   33 #include "ns3/channel.h" 
   35 #include "../utils/ndn-fw-hop-count-tag.hpp" 
   37 NS_LOG_COMPONENT_DEFINE(
"ndn.NetDeviceFace");
 
   43   : 
Face(FaceUri(
"netDeviceFace://"), FaceUri(
"netDeviceFace://"))
 
   45   , m_netDevice(netDevice)
 
   47   NS_LOG_FUNCTION(
this << netDevice);
 
   51   NS_ASSERT_MSG(m_netDevice != 0, 
"NetDeviceFace needs to be assigned a valid NetDevice");
 
   53   m_node->RegisterProtocolHandler(MakeCallback(&NetDeviceFace::receiveFromNetDevice, 
this),
 
   60   NS_LOG_FUNCTION_NOARGS();
 
   67   m_node->UnregisterProtocolHandler(MakeCallback(&NetDeviceFace::receiveFromNetDevice, 
this));
 
   68   this->
fail(
"Close connection");
 
   78 NetDeviceFace::send(Ptr<Packet> packet)
 
   80   NS_ASSERT_MSG(packet->GetSize() <= m_netDevice->GetMtu(),
 
   81                 "Packet size " << packet->GetSize() << 
" exceeds device MTU " 
   82                                << m_netDevice->GetMtu());
 
   85   packet->RemovePacketTag(tag);
 
   87   packet->AddPacketTag(tag);
 
   95   NS_LOG_FUNCTION(
this << &interest);
 
  106   NS_LOG_FUNCTION(
this << &data);
 
  116 NetDeviceFace::receiveFromNetDevice(Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol,
 
  117                                     const Address& from, 
const Address& to,
 
  118                                     NetDevice::PacketType packetType)
 
  120   NS_LOG_FUNCTION(device << p << protocol << from << to << packetType);
 
  122   Ptr<Packet> packet = p->Copy();
 
  125     if (type == ::ndn::tlv::Interest) {
 
  126       shared_ptr<const Interest> i = Convert::FromPacket<Interest>(packet);
 
  129     else if (type == ::ndn::tlv::Data) {
 
  130       shared_ptr<const Data> d = Convert::FromPacket<Data>(packet);
 
  134       NS_LOG_ERROR(
"Unsupported TLV packet");
 
  137   catch (::ndn::tlv::Error&) {
 
  138     NS_LOG_ERROR(
"Unrecognized TLV packet");
 
static Ptr< Packet > ToPacket(const T &pkt)
 
virtual void close()
Close the face. 
 
Packet tag that is used to track hop count for Interest-Data pairs. 
 
Ptr< NetDevice > GetNetDevice() const 
Get NetDevice associated with the face. 
 
static const uint16_t ETHERNET_FRAME_TYPE
Ethernet Frame Type of Ndn. 
 
EventEmitter< Data > onReceiveData
fires when a Data is received 
 
EventEmitter< Interest > onSendInterest
fires when an Interest is sent out 
 
static uint32_t getPacketType(Ptr< const Packet > packet)
 
void fail(const std::string &reason)
fail the face and raise onFail event if it's UP; otherwise do nothing 
 
NetDeviceFace(Ptr< Node > node, const Ptr< NetDevice > &netDevice)
Constructor. 
 
EventEmitter< Data > onSendData
fires when a Data is sent out 
 
void setMetric(uint64_t metric)
 
virtual void sendData(const Data &data)
 
void Increment()
Increment hop count. 
 
EventEmitter< Interest > onReceiveInterest
fires when an Interest is received 
 
virtual void sendInterest(const Interest &interest)