blob: a34d36f37766f8af6572ffb9336a7fdb294f75c3 [file] [log] [blame]
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2011-2015 Regents of the University of California.
Alexander Afanasyev7112f482011-08-17 14:05:57 -07004 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08005 * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
6 * contributors.
Alexander Afanasyev7112f482011-08-17 14:05:57 -07007 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08008 * 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 Afanasyev7112f482011-08-17 14:05:57 -070011 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080012 * 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 Afanasyev7112f482011-08-17 14:05:57 -070015 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080016 * 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 Afanasyev08d984e2011-08-13 19:20:22 -070019
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070020#ifndef NDN_L3_PROTOCOL_H
21#define NDN_L3_PROTOCOL_H
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070022
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070023#include "ns3/ndnSIM/model/ndn-common.hpp"
24
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070025#include <list>
26#include <vector>
Alexander Afanasyev4975f732011-12-20 17:52:19 -080027
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070028#include "ns3/ptr.h"
29#include "ns3/net-device.h"
Ilya Moiseenkod83eb0d2011-11-16 15:23:46 -080030#include "ns3/nstime.h"
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080031#include "ns3/traced-callback.h"
32
Alexander Afanasyevdde1e812015-01-06 14:26:09 -080033#include <boost/property_tree/ptree_fwd.hpp>
34
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080035namespace nfd {
36class Forwarder;
37class FibManager;
38class StrategyChoiceManager;
Alexander Afanasyevdde1e812015-01-06 14:26:09 -080039typedef boost::property_tree::ptree ConfigSection;
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -080040namespace pit {
41class Entry;
42} // namespace pit
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080043} // namespace nfd
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070044
45namespace ns3 {
46
47class Packet;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070048class Node;
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070049class Header;
Ilya Moiseenko172763c2011-10-28 13:21:53 -070050
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070051namespace ndn {
52
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070053/**
54 * \defgroup ndn ndnSIM: NDN simulation module
55 *
Alexander Afanasyevb989b122013-07-10 17:15:46 -070056 * This is a modular implementation of NDN protocol for NS-3
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070057 */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070058/**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070059 * \ingroup ndn
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070060 * \brief Implementation network-layer of NDN stack
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070061 *
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070062 * This class defines the API to manipulate the following aspects of
63 * the NDN stack implementation:
64 * -# register a face (Face-derived object) for use by the NDN
65 * layer
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080066 *
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070067 * Each Face-derived object has conceptually a single NDN
68 * interface associated with it.
69 *
70 * In addition, this class defines NDN packet coding constants
71 *
72 * \see Face, ForwardingStrategy
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070073 */
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080074class L3Protocol : boost::noncopyable, public Object {
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070075public:
Alexander Afanasyev7112f482011-08-17 14:05:57 -070076 /**
77 * \brief Interface ID
78 *
79 * \return interface ID
80 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080081 static TypeId
82 GetTypeId();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070083
Alexander Afanasyev016a5d82013-07-15 10:41:29 -070084 static const uint16_t ETHERNET_FRAME_TYPE; ///< @brief Ethernet Frame Type of Ndn
85 static const uint16_t IP_STACK_PORT; ///< @brief TCP/UDP port for NDN stack
86 // static const uint16_t IP_PROTOCOL_TYPE; ///< \brief IP protocol type of NDN
Alexander Afanasyev7112f482011-08-17 14:05:57 -070087
88 /**
89 * \brief Default constructor. Creates an empty stack without forwarding strategy set
90 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070091 L3Protocol();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070092
Spyridon Mastorakis8fde22b2015-08-19 23:12:44 -070093 virtual ~L3Protocol();
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080094
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070095 /**
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080096 * \brief Get smart pointer to nfd::Forwarder installed on the node
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070097 */
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080098 shared_ptr<nfd::Forwarder>
99 getForwarder();
Alexander Afanasyevaebf5cf2012-08-28 17:32:17 -0700100
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700101 /**
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800102 * \brief Get smart pointer to nfd::FibManager, used by node's NFD
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700103 */
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800104 shared_ptr<nfd::FibManager>
105 getFibManager();
106
107 /**
108 * \brief Get smart pointer to nfd::StrategyChoiceManager, used by node's NFD
109 */
110 shared_ptr<nfd::StrategyChoiceManager>
111 getStrategyChoiceManager();
112
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800113 /**
114 * \brief Add face to NDN stack
115 *
116 * \param face smart pointer to Face-derived object (AppFace, NetDeviceFace)
117 * \return nfd::FaceId
118 *
119 * \see AppFace, NetDeviceFace
120 */
121 nfd::FaceId
122 addFace(shared_ptr<Face> face);
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800123
Alexander Afanasyevaebf5cf2012-08-28 17:32:17 -0700124 /**
125 * \brief Get face by face ID
126 * \param face The face ID number
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800127 * \returns The Face associated with the Ndn face number.
Alexander Afanasyevaebf5cf2012-08-28 17:32:17 -0700128 */
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800129 shared_ptr<Face>
130 getFaceById(nfd::FaceId face) const;
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700131
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800132 // /**
133 // * \brief Remove face from ndn stack (remove callbacks)
134 // */
135 // virtual void
136 // removeFace(shared_ptr<Face> face);
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800137
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700138 /**
139 * \brief Get face for NetDevice
140 */
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800141 shared_ptr<Face>
142 getFaceByNetDevice(Ptr<NetDevice> netDevice) const;
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700143
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800144 /**
145 * \brief Get NFD config (boost::property_tree)
146 */
147 nfd::ConfigSection&
148 getConfig();
149
Alexander Afanasyevca3c67e2016-09-08 15:48:23 -0700150 /**
151 * \brief Inject interest through internal Face
152 */
153 void
154 injectInterest(const Interest& interest);
155
Alexander Afanasyev6b2a3c02015-01-03 02:04:23 -0800156public: // Workaround for python bindings
157 static Ptr<L3Protocol>
158 getL3Protocol(Ptr<Object> node);
159
Alexander Afanasyevd6453cd2015-08-20 21:45:36 -0700160public:
161 typedef void (*InterestTraceCallback)(const Interest&, const Face&);
162 typedef void (*DataTraceCallback)(const Data&, const Face&);
163
164 typedef void (*SatisfiedInterestsCallback)(const nfd::pit::Entry& pitEntry, const Face& inFace, const Data& data);
165 typedef void (*TimedOutInterestsCallback)(const nfd::pit::Entry& pitEntry);
166
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700167protected:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800168 virtual void
169 DoDispose(void); ///< @brief Do cleanup
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700170
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700171 /**
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800172 * This function will notify other components connected to the node that a new stack member is now
173 * connected
174 * This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them
175 * together.
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700176 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800177 virtual void
178 NotifyNewAggregate();
Alexander Afanasyev98256102011-08-14 01:00:02 -0700179
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700180private:
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800181 void
Spyridon Mastorakis8fde22b2015-08-19 23:12:44 -0700182 initialize();
183
184 void
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800185 initializeManagement();
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800186
Spyridon Mastorakis8fde22b2015-08-19 23:12:44 -0700187 void
188 initializeRibManager();
189
Alexander Afanasyev98256102011-08-14 01:00:02 -0700190private:
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800191 class Impl;
192 std::unique_ptr<Impl> m_impl;
193
194 // These objects are aggregated, but for optimization, get them here
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700195 Ptr<Node> m_node; ///< \brief node on which ndn stack is installed
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800196
197 TracedCallback<const Interest&, const Face&>
198 m_inInterests; ///< @brief trace of incoming Interests
199 TracedCallback<const Interest&, const Face&>
200 m_outInterests; ///< @brief Transmitted interests trace
201
202 TracedCallback<const Data&, const Face&> m_outData; ///< @brief trace of outgoing Data
203 TracedCallback<const Data&, const Face&> m_inData; ///< @brief trace of incoming Data
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800204
205 TracedCallback<const nfd::pit::Entry&, const Face&/*in face*/, const Data&> m_satisfiedInterests;
206 TracedCallback<const nfd::pit::Entry&> m_timedOutInterests;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700207};
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700208
209} // namespace ndn
210} // namespace ns3
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700211
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700212#endif /* NDN_L3_PROTOCOL_H */