blob: 5b71e3a7bc7ea776f85a95d977104c33acb3ce60 [file] [log] [blame]
Alexander Afanasyevc74a6022011-08-15 20:01:35 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Alexander Afanasyev7112f482011-08-17 14:05:57 -07002/*
3 * Copyright (c) 2011 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 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19 */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070020
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070021#ifndef NDN_L3_PROTOCOL_H
22#define NDN_L3_PROTOCOL_H
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070023
24#include <list>
25#include <vector>
Alexander Afanasyev4975f732011-12-20 17:52:19 -080026
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070027#include "ns3/ptr.h"
28#include "ns3/net-device.h"
Ilya Moiseenkod83eb0d2011-11-16 15:23:46 -080029#include "ns3/nstime.h"
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070030
31namespace ns3 {
32
33class Packet;
34class NetDevice;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070035class Node;
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070036class Header;
Ilya Moiseenko172763c2011-10-28 13:21:53 -070037
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070038namespace ndn {
39
40class Face;
41class ForwardingStrategy;
Alexander Afanasyev73f06f62013-03-15 15:41:38 -070042
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070043/**
44 * \defgroup ndn ndnSIM: NDN simulation module
45 *
Alexander Afanasyevb989b122013-07-10 17:15:46 -070046 * This is a modular implementation of NDN protocol for NS-3
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070047 */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070048/**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070049 * \ingroup ndn
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070050 * \brief Implementation network-layer of NDN stack
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070051 *
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070052 * This class defines the API to manipulate the following aspects of
53 * the NDN stack implementation:
54 * -# register a face (Face-derived object) for use by the NDN
55 * layer
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080056 *
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070057 * Each Face-derived object has conceptually a single NDN
58 * interface associated with it.
59 *
60 * In addition, this class defines NDN packet coding constants
61 *
62 * \see Face, ForwardingStrategy
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070063 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080064class L3Protocol : public Object {
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070065public:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080066 typedef std::vector<Ptr<Face>> FaceList;
Alexander Afanasyevaebf5cf2012-08-28 17:32:17 -070067
Alexander Afanasyev7112f482011-08-17 14:05:57 -070068 /**
69 * \brief Interface ID
70 *
71 * \return interface ID
72 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080073 static TypeId
74 GetTypeId();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070075
Alexander Afanasyev016a5d82013-07-15 10:41:29 -070076 static const uint16_t ETHERNET_FRAME_TYPE; ///< @brief Ethernet Frame Type of Ndn
77 static const uint16_t IP_STACK_PORT; ///< @brief TCP/UDP port for NDN stack
78 // static const uint16_t IP_PROTOCOL_TYPE; ///< \brief IP protocol type of NDN
Alexander Afanasyev7112f482011-08-17 14:05:57 -070079
80 /**
81 * \brief Default constructor. Creates an empty stack without forwarding strategy set
82 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070083 L3Protocol();
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080084 virtual ~L3Protocol();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070085
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070086 /**
87 * \brief Add face to Ndn stack
88 *
89 * \param face smart pointer to NdnFace-derived object
90 * (NdnLocalFace, NdnNetDeviceFace, NdnUdpFace) \returns the
91 * index of the Ndn interface added.
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080092 *
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070093 * \see NdnLocalFace, NdnNetDeviceFace, NdnUdpFace
94 */
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070095 virtual uint32_t
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080096 AddFace(const Ptr<Face>& face);
97
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070098 /**
99 * \brief Get current number of faces added to Ndn stack
100 *
101 * \returns the number of faces
102 */
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700103 virtual uint32_t
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800104 GetNFaces() const;
Alexander Afanasyevaebf5cf2012-08-28 17:32:17 -0700105
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700106 /**
107 * \brief Get face by face index
Alexander Afanasyevaebf5cf2012-08-28 17:32:17 -0700108 * \param face The face number (number in face list)
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700109 * \returns The NdnFace associated with the Ndn face number.
110 */
111 virtual Ptr<Face>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800112 GetFace(uint32_t face) const;
113
Alexander Afanasyevaebf5cf2012-08-28 17:32:17 -0700114 /**
115 * \brief Get face by face ID
116 * \param face The face ID number
117 * \returns The NdnFace associated with the Ndn face number.
118 */
119 virtual Ptr<Face>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800120 GetFaceById(uint32_t face) const;
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700121
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700122 /**
123 * \brief Remove face from ndn stack (remove callbacks)
124 */
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700125 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800126 RemoveFace(Ptr<Face> face);
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800127
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700128 /**
129 * \brief Get face for NetDevice
130 */
131 virtual Ptr<Face>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800132 GetFaceByNetDevice(Ptr<NetDevice> netDevice) const;
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700133
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700134protected:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800135 virtual void
136 DoDispose(void); ///< @brief Do cleanup
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700137
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700138 /**
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800139 * This function will notify other components connected to the node that a new stack member is now
140 * connected
141 * This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them
142 * together.
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700143 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800144 virtual void
145 NotifyNewAggregate();
Alexander Afanasyev98256102011-08-14 01:00:02 -0700146
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700147private:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800148 L3Protocol(const L3Protocol&); ///< copy constructor is disabled
149 L3Protocol&
150 operator=(const L3Protocol&); ///< copy operator is disabled
151
Alexander Afanasyev98256102011-08-14 01:00:02 -0700152private:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800153 uint32_t m_faceCounter; ///< \brief counter of faces. Increased every time a new face is added to
154 /// the stack
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700155 FaceList m_faces; ///< \brief list of faces that belongs to ndn stack on this node
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700156
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -0700157 // These objects are aggregated, but for optimization, get them here
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700158 Ptr<Node> m_node; ///< \brief node on which ndn stack is installed
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800159 Ptr<ForwardingStrategy>
160 m_forwardingStrategy; ///< \brief smart pointer to the selected forwarding strategy
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700161};
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700162
163} // namespace ndn
164} // namespace ns3
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700165
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700166#endif /* NDN_L3_PROTOCOL_H */