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 | |
Spyridon Mastorakis | 53e922f | 2014-10-17 17:29:26 -0700 | [diff] [blame^] | 25 | #include "ns3/ndnSIM/model/ndn-common.hpp" |
| 26 | |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 27 | #include "ns3/application.h" |
| 28 | #include "ns3/socket.h" |
| 29 | #include "ns3/inet-socket-address.h" |
| 30 | #include "ns3/ptr.h" |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 31 | |
| 32 | #include <map> |
| 33 | |
| 34 | namespace ns3 { |
| 35 | |
| 36 | class Packet; |
| 37 | |
| 38 | namespace ndn { |
| 39 | |
| 40 | class Face; |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 41 | class TcpFace; |
| 42 | class UdpFace; |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 43 | |
| 44 | /** |
| 45 | * @ingroup ndn |
| 46 | * @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] | 47 | * |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 48 | * The class implements virtual calls onInterest, onNack, and onData |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 49 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 50 | class IpFaceStack : public Object { |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 51 | public: |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 52 | static TypeId |
| 53 | GetTypeId(); |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 54 | |
| 55 | /** |
| 56 | * @brief Default constructor |
| 57 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 58 | IpFaceStack(); |
| 59 | virtual ~IpFaceStack(); |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 60 | |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 61 | /** |
| 62 | * @brief Lookup TcpFace for a given address |
| 63 | */ |
| 64 | Ptr<TcpFace> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 65 | GetTcpFaceByAddress(const Ipv4Address& addr); |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 66 | |
| 67 | /** |
| 68 | * @brief Destroy TcpFace, e.g., after TCP connection got dropped |
| 69 | */ |
| 70 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 71 | DestroyTcpFace(Ptr<TcpFace> face); |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 72 | |
| 73 | /** |
| 74 | * @brief Lookup UdpFace for a given address |
| 75 | */ |
| 76 | Ptr<UdpFace> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 77 | GetUdpFaceByAddress(const Ipv4Address& addr); |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 78 | |
| 79 | /** |
| 80 | * @brief Method allowing creation and lookup of faces |
| 81 | * |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 82 | * All created UDP faces are stored internally in the map, and if the same face is created, it |
| 83 | *will simply be looked up |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 84 | */ |
| 85 | Ptr<TcpFace> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 86 | CreateOrGetTcpFace(Ipv4Address address, |
| 87 | Callback<void, Ptr<Face>> onCreate = NULL_CREATE_CALLBACK); |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 88 | |
| 89 | /** |
| 90 | * @brief Method allowing creation and lookup of faces |
| 91 | * |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 92 | * All created TCP faces are stored internally in the map, and if the same face is created, it |
| 93 | *will simply be looked up |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 94 | */ |
| 95 | Ptr<UdpFace> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 96 | CreateOrGetUdpFace(Ipv4Address address); |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 97 | |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 98 | protected: |
| 99 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 100 | NotifyNewAggregate(); |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 101 | |
| 102 | private: |
| 103 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 104 | StartServer(); |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 105 | |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 106 | bool |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 107 | OnTcpConnectionRequest(Ptr<Socket> sock, const Address& addr); |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 108 | |
| 109 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 110 | OnTcpConnectionAccept(Ptr<Socket> sock, const Address& addr); |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 111 | |
| 112 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 113 | OnTcpConnectionClosed(Ptr<Socket> sock); |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 114 | |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 115 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 116 | OnUdpPacket(Ptr<Socket> sock); |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 117 | |
| 118 | public: |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 119 | const static Callback<void, Ptr<Face>> NULL_CREATE_CALLBACK; |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 120 | |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 121 | protected: |
| 122 | Ptr<Node> m_node; |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 123 | |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 124 | bool m_enableTcp; |
Alexander Afanasyev | 016a5d8 | 2013-07-15 10:41:29 -0700 | [diff] [blame] | 125 | bool m_enableUdp; |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 126 | |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 127 | Ptr<Socket> m_tcpServer; |
Alexander Afanasyev | 016a5d8 | 2013-07-15 10:41:29 -0700 | [diff] [blame] | 128 | Ptr<Socket> m_udpServer; |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 129 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 130 | typedef std::map<Ipv4Address, Ptr<TcpFace>> TcpFaceMap; |
| 131 | typedef std::map<Ipv4Address, Ptr<UdpFace>> UdpFaceMap; |
Alexander Afanasyev | d573af2 | 2013-07-27 12:57:08 -0700 | [diff] [blame] | 132 | TcpFaceMap m_tcpFaceMap; |
| 133 | UdpFaceMap m_udpFaceMap; |
Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame] | 134 | }; |
| 135 | |
| 136 | } // namespace ndn |
| 137 | } // namespace ns3 |
| 138 | |
| 139 | #endif // NDN_IP_FACE_STACK_H |