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 | * Alexander Afanasyev |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation; |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | * |
| 19 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 20 | */ |
| 21 | |
| 22 | #ifndef NDN_IP_FACE_STACK_H |
| 23 | #define NDN_IP_FACE_STACK_H |
| 24 | |
| 25 | #include "ns3/application.h" |
| 26 | #include "ns3/socket.h" |
| 27 | #include "ns3/inet-socket-address.h" |
| 28 | #include "ns3/ptr.h" |
Alexander Afanasyev | 0c39537 | 2014-12-20 15:54:02 -0800 | [diff] [blame] | 29 | #include "ns3/ndn-name.hpp" |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 30 | |
| 31 | #include <map> |
| 32 | |
| 33 | namespace ns3 { |
| 34 | |
| 35 | class Packet; |
| 36 | |
| 37 | namespace ndn { |
| 38 | |
| 39 | class Face; |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 40 | class TcpFace; |
| 41 | class UdpFace; |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 42 | |
| 43 | /** |
| 44 | * @ingroup ndn |
| 45 | * @brief Application that provides functionality of creating IP-based faces on NDN nodes |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 46 | * |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 47 | * The class implements virtual calls onInterest, onNack, and onData |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 48 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 49 | class IpFaceStack : public Object { |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 50 | public: |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 51 | static TypeId |
| 52 | GetTypeId(); |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 53 | |
| 54 | /** |
| 55 | * @brief Default constructor |
| 56 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 57 | IpFaceStack(); |
| 58 | virtual ~IpFaceStack(); |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 59 | |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 60 | /** |
| 61 | * @brief Lookup TcpFace for a given address |
| 62 | */ |
| 63 | Ptr<TcpFace> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 64 | GetTcpFaceByAddress(const Ipv4Address& addr); |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 65 | |
| 66 | /** |
| 67 | * @brief Destroy TcpFace, e.g., after TCP connection got dropped |
| 68 | */ |
| 69 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 70 | DestroyTcpFace(Ptr<TcpFace> face); |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 71 | |
| 72 | /** |
| 73 | * @brief Lookup UdpFace for a given address |
| 74 | */ |
| 75 | Ptr<UdpFace> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 76 | GetUdpFaceByAddress(const Ipv4Address& addr); |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 77 | |
| 78 | /** |
| 79 | * @brief Method allowing creation and lookup of faces |
| 80 | * |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 81 | * All created UDP faces are stored internally in the map, and if the same face is created, it |
| 82 | *will simply be looked up |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 83 | */ |
| 84 | Ptr<TcpFace> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 85 | CreateOrGetTcpFace(Ipv4Address address, |
| 86 | Callback<void, Ptr<Face>> onCreate = NULL_CREATE_CALLBACK); |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 87 | |
| 88 | /** |
| 89 | * @brief Method allowing creation and lookup of faces |
| 90 | * |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 91 | * All created TCP faces are stored internally in the map, and if the same face is created, it |
| 92 | *will simply be looked up |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 93 | */ |
| 94 | Ptr<UdpFace> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 95 | CreateOrGetUdpFace(Ipv4Address address); |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 96 | |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 97 | protected: |
| 98 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 99 | NotifyNewAggregate(); |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 100 | |
| 101 | private: |
| 102 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 103 | StartServer(); |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 104 | |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 105 | bool |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 106 | OnTcpConnectionRequest(Ptr<Socket> sock, const Address& addr); |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 107 | |
| 108 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 109 | OnTcpConnectionAccept(Ptr<Socket> sock, const Address& addr); |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 110 | |
| 111 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 112 | OnTcpConnectionClosed(Ptr<Socket> sock); |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 113 | |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 114 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 115 | OnUdpPacket(Ptr<Socket> sock); |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 116 | |
| 117 | public: |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 118 | const static Callback<void, Ptr<Face>> NULL_CREATE_CALLBACK; |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 119 | |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 120 | protected: |
| 121 | Ptr<Node> m_node; |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 122 | |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 123 | bool m_enableTcp; |
Alexander Afanasyev | 016a5d8 | 2013-07-15 10:41:29 -0700 | [diff] [blame] | 124 | bool m_enableUdp; |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 125 | |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 126 | Ptr<Socket> m_tcpServer; |
Alexander Afanasyev | 016a5d8 | 2013-07-15 10:41:29 -0700 | [diff] [blame] | 127 | Ptr<Socket> m_udpServer; |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 128 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 129 | typedef std::map<Ipv4Address, Ptr<TcpFace>> TcpFaceMap; |
| 130 | typedef std::map<Ipv4Address, Ptr<UdpFace>> UdpFaceMap; |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 131 | TcpFaceMap m_tcpFaceMap; |
| 132 | UdpFaceMap m_udpFaceMap; |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 133 | }; |
| 134 | |
| 135 | } // namespace ndn |
| 136 | } // namespace ns3 |
| 137 | |
| 138 | #endif // NDN_IP_FACE_STACK_H |