blob: 40278d6e2534c6b636b108a504e16488dbd4a7e3 [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;
42class InterestHeader;
43class ContentObjectHeader;
44
45/**
46 * \defgroup ndn ndnSIM: NDN simulation module
47 *
48 * This is a simplified modular implementation of NDN protocol
49 */
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
58 *
59 * 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 Afanasyev2b4c9472012-08-09 15:00:38 -070066class L3Protocol :
67 public Object
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070068{
69public:
Alexander Afanasyevaebf5cf2012-08-28 17:32:17 -070070 typedef std::vector<Ptr<Face> > FaceList;
71
Alexander Afanasyev7112f482011-08-17 14:05:57 -070072 /**
73 * \brief Interface ID
74 *
75 * \return interface ID
76 */
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070077 static TypeId GetTypeId ();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070078
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070079 static const uint16_t ETHERNET_FRAME_TYPE; ///< \brief Ethernet Frame Type of Ndn
80 // static const uint16_t IP_PROTOCOL_TYPE; ///< \brief IP protocol type of Ndn
81 // static const uint16_t UDP_PORT; ///< \brief UDP port of Ndn
Alexander Afanasyev7112f482011-08-17 14:05:57 -070082
83 /**
84 * \brief Default constructor. Creates an empty stack without forwarding strategy set
85 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070086 L3Protocol();
87 virtual ~L3Protocol ();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070088
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070089 /**
90 * \brief Add face to Ndn stack
91 *
92 * \param face smart pointer to NdnFace-derived object
93 * (NdnLocalFace, NdnNetDeviceFace, NdnUdpFace) \returns the
94 * index of the Ndn interface added.
95 *
96 * \see NdnLocalFace, NdnNetDeviceFace, NdnUdpFace
97 */
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070098 virtual uint32_t
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070099 AddFace (const Ptr<Face> &face);
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700100
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700101 /**
102 * \brief Get current number of faces added to Ndn stack
103 *
104 * \returns the number of faces
105 */
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700106 virtual uint32_t
107 GetNFaces () const;
Alexander Afanasyevaebf5cf2012-08-28 17:32:17 -0700108
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700109 /**
110 * \brief Get face by face index
Alexander Afanasyevaebf5cf2012-08-28 17:32:17 -0700111 * \param face The face number (number in face list)
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700112 * \returns The NdnFace associated with the Ndn face number.
113 */
114 virtual Ptr<Face>
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700115 GetFace (uint32_t face) const;
Alexander Afanasyevaebf5cf2012-08-28 17:32:17 -0700116
117 /**
118 * \brief Get face by face ID
119 * \param face The face ID number
120 * \returns The NdnFace associated with the Ndn face number.
121 */
122 virtual Ptr<Face>
123 GetFaceById (uint32_t face) const;
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700124
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700125 /**
126 * \brief Remove face from ndn stack (remove callbacks)
127 */
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700128 virtual void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700129 RemoveFace (Ptr<Face> face);
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800130
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700131 /**
132 * \brief Get face for NetDevice
133 */
134 virtual Ptr<Face>
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800135 GetFaceByNetDevice (Ptr<NetDevice> netDevice) const;
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700136
Alexander Afanasyevff229772012-09-03 13:30:29 -0700137 static uint64_t
138 GetInterestCounter ();
139
140 static uint64_t
141 GetDataCounter ();
142
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800143private:
144 void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700145 Receive (const Ptr<Face> &face, const Ptr<const Packet> &p);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700146
147protected:
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700148 virtual void DoDispose (void); ///< @brief Do cleanup
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700149
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700150 /**
151 * This function will notify other components connected to the node that a new stack member is now connected
152 * This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them together.
153 */
154 virtual void NotifyNewAggregate ();
Alexander Afanasyev98256102011-08-14 01:00:02 -0700155
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700156private:
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700157 L3Protocol(const L3Protocol &); ///< copy constructor is disabled
158 L3Protocol &operator = (const L3Protocol &); ///< copy operator is disabled
Alexander Afanasyevff8c5d62012-04-25 15:14:51 -0700159
Alexander Afanasyev98256102011-08-14 01:00:02 -0700160private:
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700161 uint32_t m_faceCounter; ///< \brief counter of faces. Increased every time a new face is added to the stack
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700162 FaceList m_faces; ///< \brief list of faces that belongs to ndn stack on this node
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700163
Alexander Afanasyevff229772012-09-03 13:30:29 -0700164 static uint64_t s_interestCounter;
165 static uint64_t s_dataCounter;
166
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -0700167 // These objects are aggregated, but for optimization, get them here
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700168 Ptr<Node> m_node; ///< \brief node on which ndn stack is installed
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700169 Ptr<ForwardingStrategy> m_forwardingStrategy; ///< \brief smart pointer to the selected forwarding strategy
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700170};
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700171
172} // namespace ndn
173} // namespace ns3
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700174
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700175#endif /* NDN_L3_PROTOCOL_H */