blob: 79583c13fd646d771afaf08744fd01d06afe65a9 [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"
Alexander Afanasyev82d5ffe2014-12-30 23:55:38 -080024#include "ns3/ndnSIM/model/ndn-face.hpp"
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070025
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070026#include <list>
27#include <vector>
Alexander Afanasyev4975f732011-12-20 17:52:19 -080028
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070029#include "ns3/ptr.h"
30#include "ns3/net-device.h"
Ilya Moiseenkod83eb0d2011-11-16 15:23:46 -080031#include "ns3/nstime.h"
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080032#include "ns3/traced-callback.h"
33
Alexander Afanasyevdde1e812015-01-06 14:26:09 -080034#include <boost/property_tree/ptree_fwd.hpp>
35
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080036namespace nfd {
37class Forwarder;
38class FibManager;
39class StrategyChoiceManager;
Alexander Afanasyevdde1e812015-01-06 14:26:09 -080040typedef boost::property_tree::ptree ConfigSection;
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080041} // namespace nfd
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070042
43namespace ns3 {
44
45class Packet;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070046class Node;
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070047class Header;
Ilya Moiseenko172763c2011-10-28 13:21:53 -070048
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070049namespace ndn {
50
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070051/**
52 * \defgroup ndn ndnSIM: NDN simulation module
53 *
Alexander Afanasyevb989b122013-07-10 17:15:46 -070054 * This is a modular implementation of NDN protocol for NS-3
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070055 */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070056/**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070057 * \ingroup ndn
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070058 * \brief Implementation network-layer of NDN stack
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070059 *
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070060 * This class defines the API to manipulate the following aspects of
61 * the NDN stack implementation:
62 * -# register a face (Face-derived object) for use by the NDN
63 * layer
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080064 *
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070065 * Each Face-derived object has conceptually a single NDN
66 * interface associated with it.
67 *
68 * In addition, this class defines NDN packet coding constants
69 *
70 * \see Face, ForwardingStrategy
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070071 */
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080072class L3Protocol : boost::noncopyable, public Object {
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070073public:
Alexander Afanasyev7112f482011-08-17 14:05:57 -070074 /**
75 * \brief Interface ID
76 *
77 * \return interface ID
78 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080079 static TypeId
80 GetTypeId();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070081
Alexander Afanasyev016a5d82013-07-15 10:41:29 -070082 static const uint16_t ETHERNET_FRAME_TYPE; ///< @brief Ethernet Frame Type of Ndn
83 static const uint16_t IP_STACK_PORT; ///< @brief TCP/UDP port for NDN stack
84 // static const uint16_t IP_PROTOCOL_TYPE; ///< \brief IP protocol type of NDN
Alexander Afanasyev7112f482011-08-17 14:05:57 -070085
86 /**
87 * \brief Default constructor. Creates an empty stack without forwarding strategy set
88 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070089 L3Protocol();
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080090 virtual ~L3Protocol();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070091
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070092 /**
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080093 * \brief Initialize NFD instance
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070094 */
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080095 void
Alexander Afanasyevdde1e812015-01-06 14:26:09 -080096 initialize();
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080097
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070098 /**
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080099 * \brief Get smart pointer to nfd::Forwarder installed on the node
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700100 */
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800101 shared_ptr<nfd::Forwarder>
102 getForwarder();
Alexander Afanasyevaebf5cf2012-08-28 17:32:17 -0700103
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700104 /**
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800105 * \brief Get smart pointer to nfd::FibManager, used by node's NFD
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700106 */
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800107 shared_ptr<nfd::FibManager>
108 getFibManager();
109
110 /**
111 * \brief Get smart pointer to nfd::StrategyChoiceManager, used by node's NFD
112 */
113 shared_ptr<nfd::StrategyChoiceManager>
114 getStrategyChoiceManager();
115
116
117 /**
118 * \brief Add face to NDN stack
119 *
120 * \param face smart pointer to Face-derived object (AppFace, NetDeviceFace)
121 * \return nfd::FaceId
122 *
123 * \see AppFace, NetDeviceFace
124 */
125 nfd::FaceId
126 addFace(shared_ptr<Face> face);
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800127
Alexander Afanasyevaebf5cf2012-08-28 17:32:17 -0700128 /**
129 * \brief Get face by face ID
130 * \param face The face ID number
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800131 * \returns The Face associated with the Ndn face number.
Alexander Afanasyevaebf5cf2012-08-28 17:32:17 -0700132 */
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800133 shared_ptr<Face>
134 getFaceById(nfd::FaceId face) const;
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700135
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800136 // /**
137 // * \brief Remove face from ndn stack (remove callbacks)
138 // */
139 // virtual void
140 // removeFace(shared_ptr<Face> face);
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800141
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700142 /**
143 * \brief Get face for NetDevice
144 */
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800145 shared_ptr<Face>
146 getFaceByNetDevice(Ptr<NetDevice> netDevice) const;
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700147
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800148 /**
149 * \brief Get NFD config (boost::property_tree)
150 */
151 nfd::ConfigSection&
152 getConfig();
153
Alexander Afanasyev6b2a3c02015-01-03 02:04:23 -0800154public: // Workaround for python bindings
155 static Ptr<L3Protocol>
156 getL3Protocol(Ptr<Object> node);
157
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700158protected:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800159 virtual void
160 DoDispose(void); ///< @brief Do cleanup
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700161
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700162 /**
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800163 * This function will notify other components connected to the node that a new stack member is now
164 * connected
165 * This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them
166 * together.
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700167 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800168 virtual void
169 NotifyNewAggregate();
Alexander Afanasyev98256102011-08-14 01:00:02 -0700170
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700171private:
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800172 void
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800173 initializeManagement();
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800174
Alexander Afanasyev98256102011-08-14 01:00:02 -0700175private:
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800176 class Impl;
177 std::unique_ptr<Impl> m_impl;
178
179 // These objects are aggregated, but for optimization, get them here
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700180 Ptr<Node> m_node; ///< \brief node on which ndn stack is installed
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800181
182 TracedCallback<const Interest&, const Face&>
183 m_inInterests; ///< @brief trace of incoming Interests
184 TracedCallback<const Interest&, const Face&>
185 m_outInterests; ///< @brief Transmitted interests trace
186
187 TracedCallback<const Data&, const Face&> m_outData; ///< @brief trace of outgoing Data
188 TracedCallback<const Data&, const Face&> m_inData; ///< @brief trace of incoming Data
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700189};
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700190
191} // namespace ndn
192} // namespace ns3
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700193
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700194#endif /* NDN_L3_PROTOCOL_H */