Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 1 | /* -*- 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 Mastorakis | 53e922f | 2014-10-17 17:29:26 -0700 | [diff] [blame^] | 24 | #include "ns3/ndnSIM/model/ndn-common.hpp" |
| 25 | |
Alexander Afanasyev | 0c39537 | 2014-12-20 15:54:02 -0800 | [diff] [blame] | 26 | #include "ns3/ndn-face.hpp" |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 27 | #include "ns3/socket.h" |
| 28 | #include "ns3/ptr.h" |
Alexander Afanasyev | aa84fae | 2013-07-27 12:01:37 -0700 | [diff] [blame] | 29 | #include "ns3/callback.h" |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 30 | |
| 31 | #include <map> |
| 32 | |
| 33 | namespace ns3 { |
| 34 | namespace ndn { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 35 | |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 36 | /** |
| 37 | * \ingroup ndn-face |
| 38 | * \brief Implementation of TCP/IP NDN face |
| 39 | * |
| 40 | * \see NdnAppFace, NdnNetDeviceFace, NdnIpv4Face, NdnUdpFace |
| 41 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 42 | class TcpFace : public Face { |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 43 | public: |
| 44 | static TypeId |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 45 | GetTypeId(); |
| 46 | |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 47 | /** |
| 48 | * \brief Constructor |
| 49 | * |
| 50 | * @param node Node associated with the face |
| 51 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 52 | TcpFace(Ptr<Node> node, Ptr<Socket> socket, Ipv4Address address); |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 53 | virtual ~TcpFace(); |
| 54 | |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 55 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 56 | OnTcpConnectionClosed(Ptr<Socket> socket); |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 57 | |
| 58 | Ipv4Address |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 59 | GetAddress() const; |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 60 | |
| 61 | static Ptr<TcpFace> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 62 | GetFaceByAddress(const Ipv4Address& addr); |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 63 | |
Alexander Afanasyev | aa84fae | 2013-07-27 12:01:37 -0700 | [diff] [blame] | 64 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 65 | SetCreateCallback(Callback<void, Ptr<Face>> callback); |
Alexander Afanasyev | aa84fae | 2013-07-27 12:01:37 -0700 | [diff] [blame] | 66 | |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 67 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 68 | OnConnect(Ptr<Socket> socket); |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 69 | |
| 70 | //////////////////////////////////////////////////////////////////// |
| 71 | // methods overloaded from ndn::Face |
| 72 | virtual void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 73 | RegisterProtocolHandlers(const InterestHandler& interestHandler, const DataHandler& dataHandler); |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 74 | |
| 75 | virtual void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 76 | UnRegisterProtocolHandlers(); |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 77 | |
| 78 | virtual std::ostream& |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 79 | Print(std::ostream& os) const; |
| 80 | |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 81 | protected: |
Alexander Afanasyev | aa84fae | 2013-07-27 12:01:37 -0700 | [diff] [blame] | 82 | // also from ndn::Face |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 83 | virtual bool |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 84 | Send(Ptr<Packet> p); |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 85 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 86 | private: |
| 87 | TcpFace(const TcpFace&); ///< \brief Disabled copy constructor |
| 88 | TcpFace& |
| 89 | operator=(const TcpFace&); ///< \brief Disabled copy operator |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 90 | |
| 91 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 92 | ReceiveFromTcp(Ptr<Socket> clientSocket); |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 93 | |
| 94 | private: |
| 95 | Ptr<Socket> m_socket; |
| 96 | Ipv4Address m_address; |
| 97 | uint32_t m_pendingPacketLength; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 98 | Callback<void, Ptr<Face>> m_onCreateCallback; |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | } // namespace ndn |
| 102 | } // namespace ns3 |
| 103 | |
| 104 | #endif // NDN_TCP_FACE_H |