blob: 577ad5a5ac4674e73043298d6707b3fb4cb73cfd [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
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070025#include "ns3/ndnSIM/model/ndn-common.hpp"
26
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070027#include "ns3/application.h"
28#include "ns3/socket.h"
29#include "ns3/inet-socket-address.h"
30#include "ns3/ptr.h"
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070031
32#include <map>
33
34namespace ns3 {
35
36class Packet;
37
38namespace ndn {
39
40class Face;
Alexander Afanasyevd573af22013-07-27 12:57:08 -070041class TcpFace;
42class UdpFace;
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070043
44/**
45 * @ingroup ndn
46 * @brief Application that provides functionality of creating IP-based faces on NDN nodes
Alexander Afanasyevd573af22013-07-27 12:57:08 -070047 *
Alexander Afanasyev772f51b2013-08-01 18:53:25 -070048 * The class implements virtual calls onInterest, onNack, and onData
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070049 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080050class IpFaceStack : public Object {
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070051public:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080052 static TypeId
53 GetTypeId();
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070054
55 /**
56 * @brief Default constructor
57 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080058 IpFaceStack();
59 virtual ~IpFaceStack();
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070060
Alexander Afanasyevd573af22013-07-27 12:57:08 -070061 /**
62 * @brief Lookup TcpFace for a given address
63 */
64 Ptr<TcpFace>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080065 GetTcpFaceByAddress(const Ipv4Address& addr);
Alexander Afanasyevd573af22013-07-27 12:57:08 -070066
67 /**
68 * @brief Destroy TcpFace, e.g., after TCP connection got dropped
69 */
70 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080071 DestroyTcpFace(Ptr<TcpFace> face);
Alexander Afanasyevd573af22013-07-27 12:57:08 -070072
73 /**
74 * @brief Lookup UdpFace for a given address
75 */
76 Ptr<UdpFace>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080077 GetUdpFaceByAddress(const Ipv4Address& addr);
Alexander Afanasyevd573af22013-07-27 12:57:08 -070078
79 /**
80 * @brief Method allowing creation and lookup of faces
81 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080082 * 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 Afanasyevd573af22013-07-27 12:57:08 -070084 */
85 Ptr<TcpFace>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080086 CreateOrGetTcpFace(Ipv4Address address,
87 Callback<void, Ptr<Face>> onCreate = NULL_CREATE_CALLBACK);
Alexander Afanasyevd573af22013-07-27 12:57:08 -070088
89 /**
90 * @brief Method allowing creation and lookup of faces
91 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080092 * 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 Afanasyevd573af22013-07-27 12:57:08 -070094 */
95 Ptr<UdpFace>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080096 CreateOrGetUdpFace(Ipv4Address address);
Alexander Afanasyevd573af22013-07-27 12:57:08 -070097
Alexander Afanasyevf4e24522013-06-24 14:11:57 -070098protected:
99 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800100 NotifyNewAggregate();
Alexander Afanasyevf4e24522013-06-24 14:11:57 -0700101
102private:
103 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800104 StartServer();
Alexander Afanasyevd573af22013-07-27 12:57:08 -0700105
Alexander Afanasyevf4e24522013-06-24 14:11:57 -0700106 bool
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800107 OnTcpConnectionRequest(Ptr<Socket> sock, const Address& addr);
Alexander Afanasyevf4e24522013-06-24 14:11:57 -0700108
109 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800110 OnTcpConnectionAccept(Ptr<Socket> sock, const Address& addr);
Alexander Afanasyevf4e24522013-06-24 14:11:57 -0700111
112 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800113 OnTcpConnectionClosed(Ptr<Socket> sock);
Alexander Afanasyevf4e24522013-06-24 14:11:57 -0700114
Alexander Afanasyevd573af22013-07-27 12:57:08 -0700115 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800116 OnUdpPacket(Ptr<Socket> sock);
Alexander Afanasyevd573af22013-07-27 12:57:08 -0700117
118public:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800119 const static Callback<void, Ptr<Face>> NULL_CREATE_CALLBACK;
Alexander Afanasyevd573af22013-07-27 12:57:08 -0700120
Alexander Afanasyevf4e24522013-06-24 14:11:57 -0700121protected:
122 Ptr<Node> m_node;
Alexander Afanasyevd573af22013-07-27 12:57:08 -0700123
Alexander Afanasyevf4e24522013-06-24 14:11:57 -0700124 bool m_enableTcp;
Alexander Afanasyev016a5d82013-07-15 10:41:29 -0700125 bool m_enableUdp;
Alexander Afanasyevd573af22013-07-27 12:57:08 -0700126
Alexander Afanasyevf4e24522013-06-24 14:11:57 -0700127 Ptr<Socket> m_tcpServer;
Alexander Afanasyev016a5d82013-07-15 10:41:29 -0700128 Ptr<Socket> m_udpServer;
Alexander Afanasyevd573af22013-07-27 12:57:08 -0700129
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800130 typedef std::map<Ipv4Address, Ptr<TcpFace>> TcpFaceMap;
131 typedef std::map<Ipv4Address, Ptr<UdpFace>> UdpFaceMap;
Alexander Afanasyevd573af22013-07-27 12:57:08 -0700132 TcpFaceMap m_tcpFaceMap;
133 UdpFaceMap m_udpFaceMap;
Alexander Afanasyevf4e24522013-06-24 14:11:57 -0700134};
135
136} // namespace ndn
137} // namespace ns3
138
139#endif // NDN_IP_FACE_STACK_H