blob: a9322c685afc359f29bab9adc24861890c88b655 [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 * 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 Afanasyev0c395372014-12-20 15:54:02 -080029#include "ns3/ndn-name.hpp"
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070030
31#include <map>
32
33namespace ns3 {
34
35class Packet;
36
37namespace ndn {
38
39class Face;
Alexander Afanasyevd573af22013-07-27 12:57:08 -070040class TcpFace;
41class UdpFace;
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070042
43/**
44 * @ingroup ndn
45 * @brief Application that provides functionality of creating IP-based faces on NDN nodes
Alexander Afanasyevd573af22013-07-27 12:57:08 -070046 *
Alexander Afanasyev772f51b2013-08-01 18:53:25 -070047 * The class implements virtual calls onInterest, onNack, and onData
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070048 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080049class IpFaceStack : public Object {
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070050public:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080051 static TypeId
52 GetTypeId();
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070053
54 /**
55 * @brief Default constructor
56 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080057 IpFaceStack();
58 virtual ~IpFaceStack();
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070059
Alexander Afanasyevd573af22013-07-27 12:57:08 -070060 /**
61 * @brief Lookup TcpFace for a given address
62 */
63 Ptr<TcpFace>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080064 GetTcpFaceByAddress(const Ipv4Address& addr);
Alexander Afanasyevd573af22013-07-27 12:57:08 -070065
66 /**
67 * @brief Destroy TcpFace, e.g., after TCP connection got dropped
68 */
69 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080070 DestroyTcpFace(Ptr<TcpFace> face);
Alexander Afanasyevd573af22013-07-27 12:57:08 -070071
72 /**
73 * @brief Lookup UdpFace for a given address
74 */
75 Ptr<UdpFace>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080076 GetUdpFaceByAddress(const Ipv4Address& addr);
Alexander Afanasyevd573af22013-07-27 12:57:08 -070077
78 /**
79 * @brief Method allowing creation and lookup of faces
80 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080081 * 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 Afanasyevd573af22013-07-27 12:57:08 -070083 */
84 Ptr<TcpFace>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080085 CreateOrGetTcpFace(Ipv4Address address,
86 Callback<void, Ptr<Face>> onCreate = NULL_CREATE_CALLBACK);
Alexander Afanasyevd573af22013-07-27 12:57:08 -070087
88 /**
89 * @brief Method allowing creation and lookup of faces
90 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080091 * 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 Afanasyevd573af22013-07-27 12:57:08 -070093 */
94 Ptr<UdpFace>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080095 CreateOrGetUdpFace(Ipv4Address address);
Alexander Afanasyevd573af22013-07-27 12:57:08 -070096
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070097protected:
98 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080099 NotifyNewAggregate();
Alexander Afanasyevf4e24522013-06-24 14:11:57 -0700100
101private:
102 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800103 StartServer();
Alexander Afanasyevd573af22013-07-27 12:57:08 -0700104
Alexander Afanasyevf4e24522013-06-24 14:11:57 -0700105 bool
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800106 OnTcpConnectionRequest(Ptr<Socket> sock, const Address& addr);
Alexander Afanasyevf4e24522013-06-24 14:11:57 -0700107
108 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800109 OnTcpConnectionAccept(Ptr<Socket> sock, const Address& addr);
Alexander Afanasyevf4e24522013-06-24 14:11:57 -0700110
111 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800112 OnTcpConnectionClosed(Ptr<Socket> sock);
Alexander Afanasyevf4e24522013-06-24 14:11:57 -0700113
Alexander Afanasyevd573af22013-07-27 12:57:08 -0700114 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800115 OnUdpPacket(Ptr<Socket> sock);
Alexander Afanasyevd573af22013-07-27 12:57:08 -0700116
117public:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800118 const static Callback<void, Ptr<Face>> NULL_CREATE_CALLBACK;
Alexander Afanasyevd573af22013-07-27 12:57:08 -0700119
Alexander Afanasyevf4e24522013-06-24 14:11:57 -0700120protected:
121 Ptr<Node> m_node;
Alexander Afanasyevd573af22013-07-27 12:57:08 -0700122
Alexander Afanasyevf4e24522013-06-24 14:11:57 -0700123 bool m_enableTcp;
Alexander Afanasyev016a5d82013-07-15 10:41:29 -0700124 bool m_enableUdp;
Alexander Afanasyevd573af22013-07-27 12:57:08 -0700125
Alexander Afanasyevf4e24522013-06-24 14:11:57 -0700126 Ptr<Socket> m_tcpServer;
Alexander Afanasyev016a5d82013-07-15 10:41:29 -0700127 Ptr<Socket> m_udpServer;
Alexander Afanasyevd573af22013-07-27 12:57:08 -0700128
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800129 typedef std::map<Ipv4Address, Ptr<TcpFace>> TcpFaceMap;
130 typedef std::map<Ipv4Address, Ptr<UdpFace>> UdpFaceMap;
Alexander Afanasyevd573af22013-07-27 12:57:08 -0700131 TcpFaceMap m_tcpFaceMap;
132 UdpFaceMap m_udpFaceMap;
Alexander Afanasyevf4e24522013-06-24 14:11:57 -0700133};
134
135} // namespace ndn
136} // namespace ns3
137
138#endif // NDN_IP_FACE_STACK_H