22 #include "ndn-tcp-face.h" 
   23 #include "ndn-ip-face-stack.h" 
   25 #include "ns3/ndn-l3-protocol.h" 
   28 #include "ns3/packet.h" 
   30 #include "ns3/pointer.h" 
   31 #include "ns3/tcp-socket-factory.h" 
   33 #include "ns3/ndn-name.h" 
   37 NS_LOG_COMPONENT_DEFINE (
"ndn.TcpFace");
 
   45   static TypeId GetTypeId (
void)
 
   47     static TypeId tid = TypeId (
"ns3::ndn::TcpFace::BoundaryHeader")
 
   60     : m_length (packet->GetSize ())
 
   77   GetInstanceTypeId (
void)
 const 
   79     return TcpBoundaryHeader::GetTypeId ();
 
   83   Print (std::ostream &os)
 const 
   85     os << 
"[" << m_length << 
"]";
 
   89   GetSerializedSize (
void)
 const 
   95   Serialize (Buffer::Iterator start)
 const 
   97     start.WriteU32 (m_length);
 
  101   Deserialize (Buffer::Iterator start)
 
  103     m_length = start.ReadU32 ();
 
  111 NS_OBJECT_ENSURE_REGISTERED (
TcpFace);
 
  114 TcpFace::GetTypeId ()
 
  116   static TypeId tid = TypeId (
"ns3::ndn::TcpFace")
 
  118     .SetGroupName (
"Ndn")
 
  127 TcpFace::TcpFace (Ptr<Node> node, Ptr<Socket> socket, Ipv4Address address)
 
  130   , m_address (address)
 
  131   , m_pendingPacketLength (0)
 
  138   NS_LOG_FUNCTION_NOARGS ();
 
  141 TcpFace& TcpFace::operator= (
const TcpFace &)
 
  149   NS_LOG_FUNCTION (
this);
 
  152   m_socket->SetRecvCallback (MakeCallback (&TcpFace::ReceiveFromTcp, 
this));
 
  158   m_socket->SetRecvCallback (MakeNullCallback< 
void, Ptr<Socket> > ());
 
  170   NS_LOG_FUNCTION (
this << packet);
 
  172   Ptr<Packet> boundary = Create<Packet> ();
 
  174   boundary->AddHeader (hdr);
 
  176   m_socket->Send (boundary);
 
  177   m_socket->Send (packet);
 
  183 TcpFace::ReceiveFromTcp (Ptr< Socket > clientSocket)
 
  185   NS_LOG_FUNCTION (
this << clientSocket);
 
  188   if (m_pendingPacketLength > 0)
 
  190       if (clientSocket->GetRxAvailable () >= m_pendingPacketLength)
 
  192           Ptr<Packet> realPacket = clientSocket->Recv (m_pendingPacketLength, 0);
 
  193           NS_LOG_DEBUG (
"+++ Expected " << m_pendingPacketLength << 
" bytes, got " << realPacket->GetSize () << 
" bytes");
 
  203   m_pendingPacketLength = 0;
 
  205   while (clientSocket->GetRxAvailable () >= hdr.GetSerializedSize ())
 
  207       Ptr<Packet> boundary = clientSocket->Recv (hdr.GetSerializedSize (), 0);
 
  211       NS_LOG_DEBUG (
"Expected 4 bytes, got " << boundary->GetSize () << 
" bytes");
 
  213       boundary->RemoveHeader (hdr);
 
  214       NS_LOG_DEBUG (
"Header specifies length: " << hdr.GetLength ());
 
  215       m_pendingPacketLength = hdr.GetLength ();
 
  217       if (clientSocket->GetRxAvailable () >= hdr.GetLength ())
 
  219           Ptr<Packet> realPacket = clientSocket->Recv (hdr.GetLength (), 0);
 
  222               NS_LOG_DEBUG (
"Got nothing, but requested at least " << hdr.GetLength ());
 
  226           NS_LOG_DEBUG (
"Receiving data " << hdr.GetLength () << 
" bytes, got " << realPacket->GetSize () << 
" bytes");
 
  229           m_pendingPacketLength = 0;
 
  239 TcpFace::OnTcpConnectionClosed (Ptr<Socket> socket)
 
  241   NS_LOG_FUNCTION (
this << socket);
 
  242   GetNode ()->GetObject<IpFaceStack> ()->DestroyTcpFace (
this);
 
  246 TcpFace::GetAddress ()
 const 
  252 TcpFace::SetCreateCallback (Callback< 
void, Ptr<Face> > callback)
 
  254   m_onCreateCallback = callback;
 
  258 TcpFace::OnConnect (Ptr<Socket> socket)
 
  260   NS_LOG_FUNCTION (
this << socket);
 
  262   Ptr<L3Protocol> ndn = 
GetNode ()->GetObject<L3Protocol> ();
 
  267   socket->SetCloseCallbacks (MakeCallback (&TcpFace::OnTcpConnectionClosed, 
this),
 
  268                              MakeCallback (&TcpFace::OnTcpConnectionClosed, 
this));
 
  270   if (!m_onCreateCallback.IsNull ())
 
  272       m_onCreateCallback (
this);
 
  273       m_onCreateCallback = IpFaceStack::NULL_CREATE_CALLBACK;
 
  280   os << 
"dev=tcp(" << 
GetId () << 
", " << m_address << 
")";
 
void SetUp(bool up=true)
These are face states and may be distinct from actual lower-layer device states, such as found in rea...
 
uint32_t GetId() const 
Get face Id. 
 
virtual std::ostream & Print(std::ostream &os) const 
Print information about the face into the stream. 
 
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) 
 
virtual bool Send(Ptr< Packet > packet)
Send packet down to the stack (towards app or network) 
 
virtual void UnRegisterProtocolHandlers()
Un-Register callback to call when new packet arrives on the face. 
 
Ptr< Node > GetNode() const 
Get node to which this face is associated. 
 
Implementation of TCP/IP NDN face. 
 
Callback< void, Ptr< Face >, Ptr< Interest > > InterestHandler
NDN protocol handlers. 
 
virtual bool Send(Ptr< Packet > p)
Send packet down to the stack (towards app or network) 
 
virtual void RegisterProtocolHandlers(const InterestHandler &interestHandler, const DataHandler &dataHandler)
Register callback to call when new packet arrives on the face.