blob: cf3d19ae449f9c04fa82f84b3df663a72bafffa0 [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
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070024#include "ns3/ndnSIM/model/ndn-common.hpp"
25
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070026#include <list>
27#include <vector>
Alexander Afanasyev4975f732011-12-20 17:52:19 -080028
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070029#include "ns3/ptr.h"
30#include "ns3/net-device.h"
Ilya Moiseenkod83eb0d2011-11-16 15:23:46 -080031#include "ns3/nstime.h"
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070032
33namespace ns3 {
34
35class Packet;
36class NetDevice;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070037class Node;
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070038class Header;
Ilya Moiseenko172763c2011-10-28 13:21:53 -070039
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070040namespace ndn {
41
42class Face;
43class ForwardingStrategy;
Alexander Afanasyev73f06f62013-03-15 15:41:38 -070044
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070045/**
46 * \defgroup ndn ndnSIM: NDN simulation module
47 *
Alexander Afanasyevb989b122013-07-10 17:15:46 -070048 * This is a modular implementation of NDN protocol for NS-3
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070049 */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070050/**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070051 * \ingroup ndn
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070052 * \brief Implementation network-layer of NDN stack
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070053 *
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070054 * This class defines the API to manipulate the following aspects of
55 * the NDN stack implementation:
56 * -# register a face (Face-derived object) for use by the NDN
57 * layer
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080058 *
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070059 * Each Face-derived object has conceptually a single NDN
60 * interface associated with it.
61 *
62 * In addition, this class defines NDN packet coding constants
63 *
64 * \see Face, ForwardingStrategy
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070065 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080066class L3Protocol : public Object {
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070067public:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080068 typedef std::vector<Ptr<Face>> FaceList;
Alexander Afanasyevaebf5cf2012-08-28 17:32:17 -070069
Alexander Afanasyev7112f482011-08-17 14:05:57 -070070 /**
71 * \brief Interface ID
72 *
73 * \return interface ID
74 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080075 static TypeId
76 GetTypeId();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070077
Alexander Afanasyev016a5d82013-07-15 10:41:29 -070078 static const uint16_t ETHERNET_FRAME_TYPE; ///< @brief Ethernet Frame Type of Ndn
79 static const uint16_t IP_STACK_PORT; ///< @brief TCP/UDP port for NDN stack
80 // static const uint16_t IP_PROTOCOL_TYPE; ///< \brief IP protocol type of NDN
Alexander Afanasyev7112f482011-08-17 14:05:57 -070081
82 /**
83 * \brief Default constructor. Creates an empty stack without forwarding strategy set
84 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070085 L3Protocol();
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080086 virtual ~L3Protocol();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070087
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070088 /**
89 * \brief Add face to Ndn stack
90 *
91 * \param face smart pointer to NdnFace-derived object
92 * (NdnLocalFace, NdnNetDeviceFace, NdnUdpFace) \returns the
93 * index of the Ndn interface added.
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080094 *
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070095 * \see NdnLocalFace, NdnNetDeviceFace, NdnUdpFace
96 */
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070097 virtual uint32_t
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080098 AddFace(const Ptr<Face>& face);
99
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700100 /**
101 * \brief Get current number of faces added to Ndn stack
102 *
103 * \returns the number of faces
104 */
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700105 virtual uint32_t
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800106 GetNFaces() const;
Alexander Afanasyevaebf5cf2012-08-28 17:32:17 -0700107
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700108 /**
109 * \brief Get face by face index
Alexander Afanasyevaebf5cf2012-08-28 17:32:17 -0700110 * \param face The face number (number in face list)
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700111 * \returns The NdnFace associated with the Ndn face number.
112 */
113 virtual Ptr<Face>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800114 GetFace(uint32_t face) const;
115
Alexander Afanasyevaebf5cf2012-08-28 17:32:17 -0700116 /**
117 * \brief Get face by face ID
118 * \param face The face ID number
119 * \returns The NdnFace associated with the Ndn face number.
120 */
121 virtual Ptr<Face>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800122 GetFaceById(uint32_t face) const;
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700123
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700124 /**
125 * \brief Remove face from ndn stack (remove callbacks)
126 */
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700127 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800128 RemoveFace(Ptr<Face> face);
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800129
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700130 /**
131 * \brief Get face for NetDevice
132 */
133 virtual Ptr<Face>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800134 GetFaceByNetDevice(Ptr<NetDevice> netDevice) const;
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700135
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700136protected:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800137 virtual void
138 DoDispose(void); ///< @brief Do cleanup
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700139
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700140 /**
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800141 * This function will notify other components connected to the node that a new stack member is now
142 * connected
143 * This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them
144 * together.
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700145 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800146 virtual void
147 NotifyNewAggregate();
Alexander Afanasyev98256102011-08-14 01:00:02 -0700148
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700149private:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800150 L3Protocol(const L3Protocol&); ///< copy constructor is disabled
151 L3Protocol&
152 operator=(const L3Protocol&); ///< copy operator is disabled
153
Alexander Afanasyev98256102011-08-14 01:00:02 -0700154private:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800155 uint32_t m_faceCounter; ///< \brief counter of faces. Increased every time a new face is added to
156 /// the stack
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700157 FaceList m_faces; ///< \brief list of faces that belongs to ndn stack on this node
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700158
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -0700159 // These objects are aggregated, but for optimization, get them here
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700160 Ptr<Node> m_node; ///< \brief node on which ndn stack is installed
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800161 Ptr<ForwardingStrategy>
162 m_forwardingStrategy; ///< \brief smart pointer to the selected forwarding strategy
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700163};
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700164
165} // namespace ndn
166} // namespace ns3
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700167
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700168#endif /* NDN_L3_PROTOCOL_H */