Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 2 | /* |
| 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 Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 20 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 21 | #ifndef NDN_L3_PROTOCOL_H |
| 22 | #define NDN_L3_PROTOCOL_H |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 23 | |
| 24 | #include <list> |
| 25 | #include <vector> |
Alexander Afanasyev | 4975f73 | 2011-12-20 17:52:19 -0800 | [diff] [blame] | 26 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 27 | #include "ns3/ptr.h" |
| 28 | #include "ns3/net-device.h" |
Ilya Moiseenko | d83eb0d | 2011-11-16 15:23:46 -0800 | [diff] [blame] | 29 | #include "ns3/nstime.h" |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 30 | |
| 31 | namespace ns3 { |
| 32 | |
| 33 | class Packet; |
| 34 | class NetDevice; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 35 | class Node; |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 36 | class Header; |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 37 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 38 | namespace ndn { |
| 39 | |
| 40 | class Face; |
| 41 | class ForwardingStrategy; |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 42 | class Interest; |
| 43 | class ContentObject; |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 44 | |
Alexander Afanasyev | 73f06f6 | 2013-03-15 15:41:38 -0700 | [diff] [blame] | 45 | typedef Interest InterestHeader; |
| 46 | typedef ContentObject ContentObjectHeader; |
| 47 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 48 | /** |
| 49 | * \defgroup ndn ndnSIM: NDN simulation module |
| 50 | * |
| 51 | * This is a simplified modular implementation of NDN protocol |
| 52 | */ |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 53 | /** |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 54 | * \ingroup ndn |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 55 | * \brief Implementation network-layer of NDN stack |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 56 | * |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 57 | * This class defines the API to manipulate the following aspects of |
| 58 | * the NDN stack implementation: |
| 59 | * -# register a face (Face-derived object) for use by the NDN |
| 60 | * layer |
| 61 | * |
| 62 | * Each Face-derived object has conceptually a single NDN |
| 63 | * interface associated with it. |
| 64 | * |
| 65 | * In addition, this class defines NDN packet coding constants |
| 66 | * |
| 67 | * \see Face, ForwardingStrategy |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 68 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 69 | class L3Protocol : |
| 70 | public Object |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 71 | { |
| 72 | public: |
Alexander Afanasyev | aebf5cf | 2012-08-28 17:32:17 -0700 | [diff] [blame] | 73 | typedef std::vector<Ptr<Face> > FaceList; |
| 74 | |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 75 | /** |
| 76 | * \brief Interface ID |
| 77 | * |
| 78 | * \return interface ID |
| 79 | */ |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 80 | static TypeId GetTypeId (); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 81 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 82 | static const uint16_t ETHERNET_FRAME_TYPE; ///< \brief Ethernet Frame Type of Ndn |
| 83 | // static const uint16_t IP_PROTOCOL_TYPE; ///< \brief IP protocol type of Ndn |
| 84 | // static const uint16_t UDP_PORT; ///< \brief UDP port of Ndn |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 85 | |
| 86 | /** |
| 87 | * \brief Default constructor. Creates an empty stack without forwarding strategy set |
| 88 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 89 | L3Protocol(); |
| 90 | virtual ~L3Protocol (); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 91 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 92 | /** |
| 93 | * \brief Add face to Ndn stack |
| 94 | * |
| 95 | * \param face smart pointer to NdnFace-derived object |
| 96 | * (NdnLocalFace, NdnNetDeviceFace, NdnUdpFace) \returns the |
| 97 | * index of the Ndn interface added. |
| 98 | * |
| 99 | * \see NdnLocalFace, NdnNetDeviceFace, NdnUdpFace |
| 100 | */ |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 101 | virtual uint32_t |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 102 | AddFace (const Ptr<Face> &face); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 103 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 104 | /** |
| 105 | * \brief Get current number of faces added to Ndn stack |
| 106 | * |
| 107 | * \returns the number of faces |
| 108 | */ |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 109 | virtual uint32_t |
| 110 | GetNFaces () const; |
Alexander Afanasyev | aebf5cf | 2012-08-28 17:32:17 -0700 | [diff] [blame] | 111 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 112 | /** |
| 113 | * \brief Get face by face index |
Alexander Afanasyev | aebf5cf | 2012-08-28 17:32:17 -0700 | [diff] [blame] | 114 | * \param face The face number (number in face list) |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 115 | * \returns The NdnFace associated with the Ndn face number. |
| 116 | */ |
| 117 | virtual Ptr<Face> |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 118 | GetFace (uint32_t face) const; |
Alexander Afanasyev | aebf5cf | 2012-08-28 17:32:17 -0700 | [diff] [blame] | 119 | |
| 120 | /** |
| 121 | * \brief Get face by face ID |
| 122 | * \param face The face ID number |
| 123 | * \returns The NdnFace associated with the Ndn face number. |
| 124 | */ |
| 125 | virtual Ptr<Face> |
| 126 | GetFaceById (uint32_t face) const; |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 127 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 128 | /** |
| 129 | * \brief Remove face from ndn stack (remove callbacks) |
| 130 | */ |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 131 | virtual void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 132 | RemoveFace (Ptr<Face> face); |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 133 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 134 | /** |
| 135 | * \brief Get face for NetDevice |
| 136 | */ |
| 137 | virtual Ptr<Face> |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 138 | GetFaceByNetDevice (Ptr<NetDevice> netDevice) const; |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 139 | |
Alexander Afanasyev | ff22977 | 2012-09-03 13:30:29 -0700 | [diff] [blame] | 140 | static uint64_t |
| 141 | GetInterestCounter (); |
| 142 | |
| 143 | static uint64_t |
| 144 | GetDataCounter (); |
| 145 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 146 | private: |
| 147 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 148 | Receive (const Ptr<Face> &face, const Ptr<const Packet> &p); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 149 | |
| 150 | protected: |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 151 | virtual void DoDispose (void); ///< @brief Do cleanup |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 152 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 153 | /** |
| 154 | * This function will notify other components connected to the node that a new stack member is now connected |
| 155 | * This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them together. |
| 156 | */ |
| 157 | virtual void NotifyNewAggregate (); |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 158 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 159 | private: |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 160 | L3Protocol(const L3Protocol &); ///< copy constructor is disabled |
| 161 | L3Protocol &operator = (const L3Protocol &); ///< copy operator is disabled |
Alexander Afanasyev | ff8c5d6 | 2012-04-25 15:14:51 -0700 | [diff] [blame] | 162 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 163 | private: |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 164 | uint32_t m_faceCounter; ///< \brief counter of faces. Increased every time a new face is added to the stack |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 165 | FaceList m_faces; ///< \brief list of faces that belongs to ndn stack on this node |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 166 | |
Alexander Afanasyev | ff22977 | 2012-09-03 13:30:29 -0700 | [diff] [blame] | 167 | static uint64_t s_interestCounter; |
| 168 | static uint64_t s_dataCounter; |
| 169 | |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 170 | // These objects are aggregated, but for optimization, get them here |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 171 | Ptr<Node> m_node; ///< \brief node on which ndn stack is installed |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 172 | Ptr<ForwardingStrategy> m_forwardingStrategy; ///< \brief smart pointer to the selected forwarding strategy |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 173 | }; |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 174 | |
| 175 | } // namespace ndn |
| 176 | } // namespace ns3 |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 177 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 178 | #endif /* NDN_L3_PROTOCOL_H */ |