Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2011-2015 Regents of the University of California. |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 4 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 5 | * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and |
| 6 | * contributors. |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 7 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 8 | * ndnSIM is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, |
| 10 | * either version 3 of the License, or (at your option) any later version. |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 11 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 12 | * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 15 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | **/ |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 19 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 20 | #ifndef NDN_L3_PROTOCOL_H |
| 21 | #define NDN_L3_PROTOCOL_H |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 22 | |
Spyridon Mastorakis | 53e922f | 2014-10-17 17:29:26 -0700 | [diff] [blame] | 23 | #include "ns3/ndnSIM/model/ndn-common.hpp" |
Alexander Afanasyev | 82d5ffe | 2014-12-30 23:55:38 -0800 | [diff] [blame] | 24 | #include "ns3/ndnSIM/model/ndn-face.hpp" |
Spyridon Mastorakis | 53e922f | 2014-10-17 17:29:26 -0700 | [diff] [blame] | 25 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 26 | #include <list> |
| 27 | #include <vector> |
Alexander Afanasyev | 4975f73 | 2011-12-20 17:52:19 -0800 | [diff] [blame] | 28 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 29 | #include "ns3/ptr.h" |
| 30 | #include "ns3/net-device.h" |
Ilya Moiseenko | d83eb0d | 2011-11-16 15:23:46 -0800 | [diff] [blame] | 31 | #include "ns3/nstime.h" |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 32 | #include "ns3/traced-callback.h" |
| 33 | |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 34 | #include <boost/property_tree/ptree_fwd.hpp> |
| 35 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 36 | namespace nfd { |
| 37 | class Forwarder; |
| 38 | class FibManager; |
| 39 | class StrategyChoiceManager; |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 40 | typedef boost::property_tree::ptree ConfigSection; |
Alexander Afanasyev | dc6fae8 | 2015-01-08 21:44:15 -0800 | [diff] [blame] | 41 | namespace pit { |
| 42 | class Entry; |
| 43 | } // namespace pit |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 44 | } // namespace nfd |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 45 | |
| 46 | namespace ns3 { |
| 47 | |
| 48 | class Packet; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 49 | class Node; |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 50 | class Header; |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 51 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 52 | namespace ndn { |
| 53 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 54 | /** |
| 55 | * \defgroup ndn ndnSIM: NDN simulation module |
| 56 | * |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 57 | * This is a modular implementation of NDN protocol for NS-3 |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 58 | */ |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 59 | /** |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 60 | * \ingroup ndn |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 61 | * \brief Implementation network-layer of NDN stack |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 62 | * |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 63 | * This class defines the API to manipulate the following aspects of |
| 64 | * the NDN stack implementation: |
| 65 | * -# register a face (Face-derived object) for use by the NDN |
| 66 | * layer |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 67 | * |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 68 | * Each Face-derived object has conceptually a single NDN |
| 69 | * interface associated with it. |
| 70 | * |
| 71 | * In addition, this class defines NDN packet coding constants |
| 72 | * |
| 73 | * \see Face, ForwardingStrategy |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 74 | */ |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 75 | class L3Protocol : boost::noncopyable, public Object { |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 76 | public: |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 77 | /** |
| 78 | * \brief Interface ID |
| 79 | * |
| 80 | * \return interface ID |
| 81 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 82 | static TypeId |
| 83 | GetTypeId(); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 84 | |
Alexander Afanasyev | 016a5d8 | 2013-07-15 10:41:29 -0700 | [diff] [blame] | 85 | static const uint16_t ETHERNET_FRAME_TYPE; ///< @brief Ethernet Frame Type of Ndn |
| 86 | static const uint16_t IP_STACK_PORT; ///< @brief TCP/UDP port for NDN stack |
| 87 | // static const uint16_t IP_PROTOCOL_TYPE; ///< \brief IP protocol type of NDN |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 88 | |
| 89 | /** |
| 90 | * \brief Default constructor. Creates an empty stack without forwarding strategy set |
| 91 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 92 | L3Protocol(); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 93 | virtual ~L3Protocol(); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 94 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 95 | /** |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 96 | * \brief Initialize NFD instance |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 97 | */ |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 98 | void |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 99 | initialize(); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 100 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 101 | /** |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 102 | * \brief Get smart pointer to nfd::Forwarder installed on the node |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 103 | */ |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 104 | shared_ptr<nfd::Forwarder> |
| 105 | getForwarder(); |
Alexander Afanasyev | aebf5cf | 2012-08-28 17:32:17 -0700 | [diff] [blame] | 106 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 107 | /** |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 108 | * \brief Get smart pointer to nfd::FibManager, used by node's NFD |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 109 | */ |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 110 | shared_ptr<nfd::FibManager> |
| 111 | getFibManager(); |
| 112 | |
| 113 | /** |
| 114 | * \brief Get smart pointer to nfd::StrategyChoiceManager, used by node's NFD |
| 115 | */ |
| 116 | shared_ptr<nfd::StrategyChoiceManager> |
| 117 | getStrategyChoiceManager(); |
| 118 | |
| 119 | |
| 120 | /** |
| 121 | * \brief Add face to NDN stack |
| 122 | * |
| 123 | * \param face smart pointer to Face-derived object (AppFace, NetDeviceFace) |
| 124 | * \return nfd::FaceId |
| 125 | * |
| 126 | * \see AppFace, NetDeviceFace |
| 127 | */ |
| 128 | nfd::FaceId |
| 129 | addFace(shared_ptr<Face> face); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 130 | |
Alexander Afanasyev | aebf5cf | 2012-08-28 17:32:17 -0700 | [diff] [blame] | 131 | /** |
| 132 | * \brief Get face by face ID |
| 133 | * \param face The face ID number |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 134 | * \returns The Face associated with the Ndn face number. |
Alexander Afanasyev | aebf5cf | 2012-08-28 17:32:17 -0700 | [diff] [blame] | 135 | */ |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 136 | shared_ptr<Face> |
| 137 | getFaceById(nfd::FaceId face) const; |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 138 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 139 | // /** |
| 140 | // * \brief Remove face from ndn stack (remove callbacks) |
| 141 | // */ |
| 142 | // virtual void |
| 143 | // removeFace(shared_ptr<Face> face); |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 144 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 145 | /** |
| 146 | * \brief Get face for NetDevice |
| 147 | */ |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 148 | shared_ptr<Face> |
| 149 | getFaceByNetDevice(Ptr<NetDevice> netDevice) const; |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 150 | |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 151 | /** |
| 152 | * \brief Get NFD config (boost::property_tree) |
| 153 | */ |
| 154 | nfd::ConfigSection& |
| 155 | getConfig(); |
| 156 | |
Alexander Afanasyev | 6b2a3c0 | 2015-01-03 02:04:23 -0800 | [diff] [blame] | 157 | public: // Workaround for python bindings |
| 158 | static Ptr<L3Protocol> |
| 159 | getL3Protocol(Ptr<Object> node); |
| 160 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 161 | protected: |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 162 | virtual void |
| 163 | DoDispose(void); ///< @brief Do cleanup |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 164 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 165 | /** |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 166 | * This function will notify other components connected to the node that a new stack member is now |
| 167 | * connected |
| 168 | * This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them |
| 169 | * together. |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 170 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 171 | virtual void |
| 172 | NotifyNewAggregate(); |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 173 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 174 | private: |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 175 | void |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 176 | initializeManagement(); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 177 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 178 | private: |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 179 | class Impl; |
| 180 | std::unique_ptr<Impl> m_impl; |
| 181 | |
| 182 | // These objects are aggregated, but for optimization, get them here |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 183 | Ptr<Node> m_node; ///< \brief node on which ndn stack is installed |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 184 | |
| 185 | TracedCallback<const Interest&, const Face&> |
| 186 | m_inInterests; ///< @brief trace of incoming Interests |
| 187 | TracedCallback<const Interest&, const Face&> |
| 188 | m_outInterests; ///< @brief Transmitted interests trace |
| 189 | |
| 190 | TracedCallback<const Data&, const Face&> m_outData; ///< @brief trace of outgoing Data |
| 191 | TracedCallback<const Data&, const Face&> m_inData; ///< @brief trace of incoming Data |
Alexander Afanasyev | dc6fae8 | 2015-01-08 21:44:15 -0800 | [diff] [blame] | 192 | |
| 193 | TracedCallback<const nfd::pit::Entry&, const Face&/*in face*/, const Data&> m_satisfiedInterests; |
| 194 | TracedCallback<const nfd::pit::Entry&> m_timedOutInterests; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 195 | }; |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 196 | |
| 197 | } // namespace ndn |
| 198 | } // namespace ns3 |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 199 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 200 | #endif /* NDN_L3_PROTOCOL_H */ |