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" |
| 24 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 25 | #include <list> |
| 26 | #include <vector> |
Alexander Afanasyev | 4975f73 | 2011-12-20 17:52:19 -0800 | [diff] [blame] | 27 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 28 | #include "ns3/ptr.h" |
| 29 | #include "ns3/net-device.h" |
Ilya Moiseenko | d83eb0d | 2011-11-16 15:23:46 -0800 | [diff] [blame] | 30 | #include "ns3/nstime.h" |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 31 | #include "ns3/traced-callback.h" |
| 32 | |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 33 | #include <boost/property_tree/ptree_fwd.hpp> |
| 34 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 35 | namespace nfd { |
| 36 | class Forwarder; |
| 37 | class FibManager; |
Alexander Afanasyev | 59090db | 2020-02-21 16:37:43 -0500 | [diff] [blame] | 38 | class FaceTable; |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 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 |
spirosmastorakis | 34eed98 | 2016-11-02 15:20:50 -0700 | [diff] [blame] | 44 | namespace cs { |
| 45 | class Policy; |
| 46 | } // namespace cs |
Alexander Afanasyev | dc3c3a3 | 2019-02-17 20:17:32 -0500 | [diff] [blame] | 47 | namespace rib { |
| 48 | class Service; |
| 49 | } |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 50 | } // namespace nfd |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 51 | |
| 52 | namespace ns3 { |
| 53 | |
| 54 | class Packet; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 55 | class Node; |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 56 | class Header; |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 57 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 58 | namespace ndn { |
| 59 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 60 | /** |
| 61 | * \defgroup ndn ndnSIM: NDN simulation module |
| 62 | * |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 63 | * This is a modular implementation of NDN protocol for NS-3 |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 64 | */ |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 65 | /** |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 66 | * \ingroup ndn |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 67 | * \brief Implementation network-layer of NDN stack |
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 | * This class defines the API to manipulate the following aspects of |
| 70 | * the NDN stack implementation: |
| 71 | * -# register a face (Face-derived object) for use by the NDN |
| 72 | * layer |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 73 | * |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 74 | * Each Face-derived object has conceptually a single NDN |
| 75 | * interface associated with it. |
| 76 | * |
| 77 | * In addition, this class defines NDN packet coding constants |
| 78 | * |
| 79 | * \see Face, ForwardingStrategy |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 80 | */ |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 81 | class L3Protocol : boost::noncopyable, public Object { |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 82 | public: |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 83 | /** |
| 84 | * \brief Interface ID |
| 85 | * |
| 86 | * \return interface ID |
| 87 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 88 | static TypeId |
| 89 | GetTypeId(); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 90 | |
Alexander Afanasyev | 016a5d8 | 2013-07-15 10:41:29 -0700 | [diff] [blame] | 91 | static const uint16_t ETHERNET_FRAME_TYPE; ///< @brief Ethernet Frame Type of Ndn |
| 92 | static const uint16_t IP_STACK_PORT; ///< @brief TCP/UDP port for NDN stack |
| 93 | // 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] | 94 | |
| 95 | /** |
| 96 | * \brief Default constructor. Creates an empty stack without forwarding strategy set |
| 97 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 98 | L3Protocol(); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 99 | |
Spyridon Mastorakis | 8fde22b | 2015-08-19 23:12:44 -0700 | [diff] [blame] | 100 | virtual ~L3Protocol(); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 101 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 102 | /** |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 103 | * \brief Get smart pointer to nfd::Forwarder installed on the node |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 104 | */ |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 105 | shared_ptr<nfd::Forwarder> |
| 106 | getForwarder(); |
Alexander Afanasyev | aebf5cf | 2012-08-28 17:32:17 -0700 | [diff] [blame] | 107 | |
Alexander Afanasyev | 59090db | 2020-02-21 16:37:43 -0500 | [diff] [blame] | 108 | nfd::FaceTable& |
| 109 | getFaceTable(); |
| 110 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 111 | /** |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 112 | * \brief Get smart pointer to nfd::FibManager, used by node's NFD |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 113 | */ |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 114 | shared_ptr<nfd::FibManager> |
| 115 | getFibManager(); |
| 116 | |
| 117 | /** |
Alexander Afanasyev | dc3c3a3 | 2019-02-17 20:17:32 -0500 | [diff] [blame] | 118 | * \brief Get nfd::StrategyChoiceManager, used by node's NFD |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 119 | */ |
Alexander Afanasyev | dc3c3a3 | 2019-02-17 20:17:32 -0500 | [diff] [blame] | 120 | nfd::StrategyChoiceManager& |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 121 | getStrategyChoiceManager(); |
| 122 | |
Alexander Afanasyev | dc3c3a3 | 2019-02-17 20:17:32 -0500 | [diff] [blame] | 123 | ::nfd::rib::Service& |
| 124 | getRibService(); |
| 125 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 126 | /** |
| 127 | * \brief Add face to NDN stack |
| 128 | * |
| 129 | * \param face smart pointer to Face-derived object (AppFace, NetDeviceFace) |
| 130 | * \return nfd::FaceId |
| 131 | * |
| 132 | * \see AppFace, NetDeviceFace |
| 133 | */ |
| 134 | nfd::FaceId |
| 135 | addFace(shared_ptr<Face> face); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 136 | |
Alexander Afanasyev | aebf5cf | 2012-08-28 17:32:17 -0700 | [diff] [blame] | 137 | /** |
| 138 | * \brief Get face by face ID |
| 139 | * \param face The face ID number |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 140 | * \returns The Face associated with the Ndn face number. |
Alexander Afanasyev | aebf5cf | 2012-08-28 17:32:17 -0700 | [diff] [blame] | 141 | */ |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 142 | shared_ptr<Face> |
| 143 | getFaceById(nfd::FaceId face) const; |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 144 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 145 | // /** |
| 146 | // * \brief Remove face from ndn stack (remove callbacks) |
| 147 | // */ |
| 148 | // virtual void |
| 149 | // removeFace(shared_ptr<Face> face); |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 150 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 151 | /** |
| 152 | * \brief Get face for NetDevice |
| 153 | */ |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 154 | shared_ptr<Face> |
| 155 | getFaceByNetDevice(Ptr<NetDevice> netDevice) const; |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 156 | |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 157 | /** |
| 158 | * \brief Get NFD config (boost::property_tree) |
| 159 | */ |
| 160 | nfd::ConfigSection& |
| 161 | getConfig(); |
| 162 | |
Alexander Afanasyev | ca3c67e | 2016-09-08 15:48:23 -0700 | [diff] [blame] | 163 | /** |
| 164 | * \brief Inject interest through internal Face |
| 165 | */ |
| 166 | void |
| 167 | injectInterest(const Interest& interest); |
| 168 | |
spirosmastorakis | 34eed98 | 2016-11-02 15:20:50 -0700 | [diff] [blame] | 169 | typedef std::function<std::unique_ptr<nfd::cs::Policy>()> PolicyCreationCallback; |
| 170 | |
| 171 | /** |
| 172 | * \brief Set the replacement policy of NFD's CS |
| 173 | */ |
| 174 | void |
| 175 | setCsReplacementPolicy(const PolicyCreationCallback& policy); |
| 176 | |
Alexander Afanasyev | 6b2a3c0 | 2015-01-03 02:04:23 -0800 | [diff] [blame] | 177 | public: // Workaround for python bindings |
| 178 | static Ptr<L3Protocol> |
| 179 | getL3Protocol(Ptr<Object> node); |
| 180 | |
Alexander Afanasyev | d6453cd | 2015-08-20 21:45:36 -0700 | [diff] [blame] | 181 | public: |
| 182 | typedef void (*InterestTraceCallback)(const Interest&, const Face&); |
| 183 | typedef void (*DataTraceCallback)(const Data&, const Face&); |
| 184 | |
| 185 | typedef void (*SatisfiedInterestsCallback)(const nfd::pit::Entry& pitEntry, const Face& inFace, const Data& data); |
| 186 | typedef void (*TimedOutInterestsCallback)(const nfd::pit::Entry& pitEntry); |
| 187 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 188 | protected: |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 189 | virtual void |
| 190 | DoDispose(void); ///< @brief Do cleanup |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 191 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 192 | /** |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 193 | * This function will notify other components connected to the node that a new stack member is now |
| 194 | * connected |
| 195 | * This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them |
| 196 | * together. |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 197 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 198 | virtual void |
| 199 | NotifyNewAggregate(); |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 200 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 201 | private: |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 202 | void |
Spyridon Mastorakis | 8fde22b | 2015-08-19 23:12:44 -0700 | [diff] [blame] | 203 | initialize(); |
| 204 | |
| 205 | void |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 206 | initializeManagement(); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 207 | |
Spyridon Mastorakis | 8fde22b | 2015-08-19 23:12:44 -0700 | [diff] [blame] | 208 | void |
| 209 | initializeRibManager(); |
| 210 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 211 | private: |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 212 | class Impl; |
| 213 | std::unique_ptr<Impl> m_impl; |
| 214 | |
| 215 | // These objects are aggregated, but for optimization, get them here |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 216 | Ptr<Node> m_node; ///< \brief node on which ndn stack is installed |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 217 | |
| 218 | TracedCallback<const Interest&, const Face&> |
| 219 | m_inInterests; ///< @brief trace of incoming Interests |
| 220 | TracedCallback<const Interest&, const Face&> |
| 221 | m_outInterests; ///< @brief Transmitted interests trace |
| 222 | |
| 223 | TracedCallback<const Data&, const Face&> m_outData; ///< @brief trace of outgoing Data |
| 224 | TracedCallback<const Data&, const Face&> m_inData; ///< @brief trace of incoming Data |
Alexander Afanasyev | dc6fae8 | 2015-01-08 21:44:15 -0800 | [diff] [blame] | 225 | |
Spyridon Mastorakis | 5ea3322 | 2016-12-07 14:33:53 -0800 | [diff] [blame] | 226 | TracedCallback<const lp::Nack&, const Face&> m_outNack; ///< @brief trace of outgoing Nack |
| 227 | TracedCallback<const lp::Nack&, const Face&> m_inNack; ///< @brief trace of incoming Nack |
| 228 | |
Alexander Afanasyev | dc6fae8 | 2015-01-08 21:44:15 -0800 | [diff] [blame] | 229 | TracedCallback<const nfd::pit::Entry&, const Face&/*in face*/, const Data&> m_satisfiedInterests; |
| 230 | TracedCallback<const nfd::pit::Entry&> m_timedOutInterests; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 231 | }; |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 232 | |
| 233 | } // namespace ndn |
| 234 | } // namespace ns3 |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 235 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 236 | #endif /* NDN_L3_PROTOCOL_H */ |