blob: 0543bd5c8453f9759f0c893bd645df6b138a94f6 [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
Alexander Afanasyev0c395372014-12-20 15:54:02 -080024#include "ns3/ndn-face.hpp"
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070025#include "ns3/socket.h"
26#include "ns3/ptr.h"
Alexander Afanasyevaa84fae2013-07-27 12:01:37 -070027#include "ns3/callback.h"
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070028
29#include <map>
30
31namespace ns3 {
32namespace ndn {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080033
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070034/**
35 * \ingroup ndn-face
36 * \brief Implementation of TCP/IP NDN face
37 *
38 * \see NdnAppFace, NdnNetDeviceFace, NdnIpv4Face, NdnUdpFace
39 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080040class TcpFace : public Face {
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070041public:
42 static TypeId
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080043 GetTypeId();
44
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070045 /**
46 * \brief Constructor
47 *
48 * @param node Node associated with the face
49 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080050 TcpFace(Ptr<Node> node, Ptr<Socket> socket, Ipv4Address address);
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070051 virtual ~TcpFace();
52
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070053 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080054 OnTcpConnectionClosed(Ptr<Socket> socket);
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070055
56 Ipv4Address
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080057 GetAddress() const;
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070058
59 static Ptr<TcpFace>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080060 GetFaceByAddress(const Ipv4Address& addr);
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070061
Alexander Afanasyevaa84fae2013-07-27 12:01:37 -070062 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080063 SetCreateCallback(Callback<void, Ptr<Face>> callback);
Alexander Afanasyevaa84fae2013-07-27 12:01:37 -070064
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070065 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080066 OnConnect(Ptr<Socket> socket);
Alexander Afanasyevd573af22013-07-27 12:57:08 -070067
68 ////////////////////////////////////////////////////////////////////
69 // methods overloaded from ndn::Face
70 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080071 RegisterProtocolHandlers(const InterestHandler& interestHandler, const DataHandler& dataHandler);
Alexander Afanasyevd573af22013-07-27 12:57:08 -070072
73 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080074 UnRegisterProtocolHandlers();
Alexander Afanasyevd573af22013-07-27 12:57:08 -070075
76 virtual std::ostream&
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080077 Print(std::ostream& os) const;
78
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070079protected:
Alexander Afanasyevaa84fae2013-07-27 12:01:37 -070080 // also from ndn::Face
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070081 virtual bool
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080082 Send(Ptr<Packet> p);
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070083
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080084private:
85 TcpFace(const TcpFace&); ///< \brief Disabled copy constructor
86 TcpFace&
87 operator=(const TcpFace&); ///< \brief Disabled copy operator
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070088
89 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080090 ReceiveFromTcp(Ptr<Socket> clientSocket);
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070091
92private:
93 Ptr<Socket> m_socket;
94 Ipv4Address m_address;
95 uint32_t m_pendingPacketLength;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080096 Callback<void, Ptr<Face>> m_onCreateCallback;
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070097};
98
99} // namespace ndn
100} // namespace ns3
101
102#endif // NDN_TCP_FACE_H