blob: 9f1ad882b296079daab8d73e10c37712476d0b3a [file] [log] [blame]
Alexander Afanasyevf4e24522013-06-24 14:11:57 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2013 University of California, Los Angeles
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Authors: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19 */
20
21#ifndef NDN_TCP_FACE_H
22#define NDN_TCP_FACE_H
23
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070024#include "ns3/ndnSIM/model/ndn-common.hpp"
25
Alexander Afanasyev0c395372014-12-20 15:54:02 -080026#include "ns3/ndn-face.hpp"
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070027#include "ns3/socket.h"
28#include "ns3/ptr.h"
Alexander Afanasyevaa84fae2013-07-27 12:01:37 -070029#include "ns3/callback.h"
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070030
31#include <map>
32
33namespace ns3 {
34namespace ndn {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080035
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070036/**
37 * \ingroup ndn-face
38 * \brief Implementation of TCP/IP NDN face
39 *
40 * \see NdnAppFace, NdnNetDeviceFace, NdnIpv4Face, NdnUdpFace
41 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080042class TcpFace : public Face {
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070043public:
44 static TypeId
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080045 GetTypeId();
46
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070047 /**
48 * \brief Constructor
49 *
50 * @param node Node associated with the face
51 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080052 TcpFace(Ptr<Node> node, Ptr<Socket> socket, Ipv4Address address);
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070053 virtual ~TcpFace();
54
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070055 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080056 OnTcpConnectionClosed(Ptr<Socket> socket);
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070057
58 Ipv4Address
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080059 GetAddress() const;
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070060
61 static Ptr<TcpFace>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080062 GetFaceByAddress(const Ipv4Address& addr);
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070063
Alexander Afanasyevaa84fae2013-07-27 12:01:37 -070064 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080065 SetCreateCallback(Callback<void, Ptr<Face>> callback);
Alexander Afanasyevaa84fae2013-07-27 12:01:37 -070066
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070067 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080068 OnConnect(Ptr<Socket> socket);
Alexander Afanasyevd573af22013-07-27 12:57:08 -070069
70 ////////////////////////////////////////////////////////////////////
71 // methods overloaded from ndn::Face
72 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080073 RegisterProtocolHandlers(const InterestHandler& interestHandler, const DataHandler& dataHandler);
Alexander Afanasyevd573af22013-07-27 12:57:08 -070074
75 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080076 UnRegisterProtocolHandlers();
Alexander Afanasyevd573af22013-07-27 12:57:08 -070077
78 virtual std::ostream&
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080079 Print(std::ostream& os) const;
80
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070081protected:
Alexander Afanasyevaa84fae2013-07-27 12:01:37 -070082 // also from ndn::Face
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070083 virtual bool
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080084 Send(Ptr<Packet> p);
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070085
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080086private:
87 TcpFace(const TcpFace&); ///< \brief Disabled copy constructor
88 TcpFace&
89 operator=(const TcpFace&); ///< \brief Disabled copy operator
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070090
91 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080092 ReceiveFromTcp(Ptr<Socket> clientSocket);
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070093
94private:
95 Ptr<Socket> m_socket;
96 Ipv4Address m_address;
97 uint32_t m_pendingPacketLength;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080098 Callback<void, Ptr<Face>> m_onCreateCallback;
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070099};
100
101} // namespace ndn
102} // namespace ns3
103
104#endif // NDN_TCP_FACE_H