24 #include "ns3/packet.h" 
   27 #include "ns3/assert.h" 
   28 #include "ns3/uinteger.h" 
   29 #include "ns3/double.h" 
   30 #include "ns3/boolean.h" 
   31 #include "ns3/simulator.h" 
   32 #include "ns3/random-variable.h" 
   33 #include "ns3/pointer.h" 
   35 #include "ns3/ndn-header-helper.h" 
   36 #include "ns3/ndnSIM/utils/ndn-fw-hop-count-tag.h" 
   38 #include "ns3/ndn-wire.h" 
   40 #include <boost/ref.hpp> 
   42 NS_LOG_COMPONENT_DEFINE (
"ndn.Face");
 
   47 NS_OBJECT_ENSURE_REGISTERED (Face);
 
   52   static TypeId tid = TypeId (
"ns3::ndn::Face")
 
   55     .AddAttribute (
"Id", 
"Face id (unique integer for the Ndn stack on this node)",
 
   58                    MakeUintegerAccessor (&Face::m_id),
 
   59                    MakeUintegerChecker<uint32_t> ())
 
   71   , m_upstreamInterestHandler (MakeNullCallback< void, Ptr<
Face>, Ptr<
Interest> > ())
 
   72   , m_upstreamDataHandler (MakeNullCallback< void, Ptr<
Face>, Ptr<
Data> > ())
 
   78   NS_LOG_FUNCTION (
this << node);
 
   80   NS_ASSERT_MSG (node != 0, 
"node cannot be NULL. Check the code");
 
   85   NS_LOG_FUNCTION_NOARGS ();
 
   92 Face& Face::operator= (
const Face &)
 
  106   NS_LOG_FUNCTION_NOARGS ();
 
  108   m_upstreamInterestHandler = interestHandler;
 
  109   m_upstreamDataHandler = dataHandler;
 
  115   NS_LOG_FUNCTION_NOARGS ();
 
  117   m_upstreamInterestHandler = MakeNullCallback< void, Ptr<Face>, Ptr<Interest> > ();
 
  118   m_upstreamDataHandler = MakeNullCallback< void, Ptr<Face>, Ptr<Data> > ();
 
  125   NS_LOG_FUNCTION (
this << boost::cref (*
this) << interest->GetName ());
 
  132   return Send (Wire::FromInterest (interest));
 
  138   NS_LOG_FUNCTION (
this << data);
 
  145   return Send (Wire::FromData (data));
 
  152   bool tagExists = packet->RemovePacketTag (hopCount);
 
  156       packet->AddPacketTag (hopCount);
 
  165   NS_LOG_FUNCTION (
this << p << p->GetSize ());
 
  173   Ptr<Packet> packet = p->Copy (); 
 
  179         case HeaderHelper::INTEREST_NDNSIM:
 
  180           return ReceiveInterest (Wire::ToInterest (packet, Wire::WIRE_FORMAT_NDNSIM));
 
  181         case HeaderHelper::INTEREST_CCNB:
 
  182           return ReceiveInterest (Wire::ToInterest (packet, Wire::WIRE_FORMAT_CCNB));
 
  183         case HeaderHelper::CONTENT_OBJECT_NDNSIM:
 
  184           return ReceiveData (Wire::ToData (packet, Wire::WIRE_FORMAT_NDNSIM));
 
  185         case HeaderHelper::CONTENT_OBJECT_CCNB:
 
  186           return ReceiveData (Wire::ToData (packet, Wire::WIRE_FORMAT_CCNB));
 
  188           NS_FATAL_ERROR (
"Not supported NDN header");
 
  196       NS_FATAL_ERROR (
"Unknown NDN header. Should not happen");
 
  212   m_upstreamInterestHandler (
this, interest);
 
  225   m_upstreamDataHandler (
this, data);
 
  232   NS_LOG_FUNCTION (metric);
 
  251   NS_ASSERT_MSG (
m_node->GetId () == face.
m_node->GetId (),
 
  252                  "Faces of different nodes should not be compared to each other: " << *
this << 
" == " << face);
 
  254   return (m_id == face.m_id);
 
  260   NS_ASSERT_MSG (
m_node->GetId () == face.
m_node->GetId (),
 
  261                  "Faces of different nodes should not be compared to each other: " << *
this << 
" == " << face);
 
  263   return (m_id < face.m_id);
 
  269   os << 
"id=" << 
GetId ();
 
  274 operator<< (std::ostream& os, 
const Face &face)
 
Ptr< Node > m_node
Smart pointer to Node. 
 
virtual std::ostream & Print(std::ostream &os) const 
Print information about the face into the stream. 
 
virtual bool SendData(Ptr< const Data > data)
Send out Dat packet through the face. 
 
void Increment()
Increment hop count. 
 
bool operator<(const Face &face) const 
Compare two faces. 
 
virtual bool SendInterest(Ptr< const Interest > interest)
Send out interest through the face. 
 
virtual bool ReceiveInterest(Ptr< Interest > interest)
Receive interest from application or another node and forward it up to the NDN stack. 
 
uint32_t GetId() const 
Get face Id. 
 
bool operator==(const Face &face) const 
Compare two faces. 
 
virtual void UnRegisterProtocolHandlers()
Un-Register callback to call when new packet arrives on the face. 
 
virtual void RegisterProtocolHandlers(const InterestHandler &interestHandler, const DataHandler &dataHandler)
Register callback to call when new packet arrives on the face. 
 
Virtual class defining NDN face. 
 
virtual void SetMetric(uint16_t metric)
Assign routing/forwarding metric with face. 
 
virtual bool Receive(Ptr< const Packet > p)
Send packet up to the stack (towards forwarding strategy) 
 
void SetFlags(uint32_t flags)
Set face flags. 
 
virtual uint16_t GetMetric(void) const 
Get routing/forwarding metric assigned to the face. 
 
virtual bool Send(Ptr< Packet > packet)
Send packet down to the stack (towards app or network) 
 
Face(Ptr< Node > node)
Default constructor. 
 
Ptr< Node > GetNode() const 
Get node to which this face is associated. 
 
NDN Interest (wire formats are defined in wire) 
 
virtual bool ReceiveData(Ptr< Data > data)
Receive Data packet from application or another node and forward it up to the NDN stack...
 
Packet tag that is used to track hop count for Interest-Data pairs. 
 
Callback< void, Ptr< Face >, Ptr< Interest > > InterestHandler
NDN protocol handlers. 
 
bool IsUp() const 
Returns true if this face is enabled, false otherwise.