blob: 63cc564783e127d309aa019559a4fb8e151bf069 [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 Afanasyev45b92d42011-08-14 23:11:38 -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 Afanasyev45b92d42011-08-14 23:11:38 -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 Afanasyev45b92d42011-08-14 23:11:38 -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 Afanasyev45b92d42011-08-14 23:11:38 -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 Afanasyev45b92d42011-08-14 23:11:38 -070019
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070020#ifndef NDN_STACK_HELPER_H
21#define NDN_STACK_HELPER_H
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070022
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070023#include "ns3/ndnSIM/model/ndn-common.hpp"
24
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070025#include "ns3/ptr.h"
26#include "ns3/object-factory.h"
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080027#include "ns3/node.h"
28#include "ns3/node-container.h"
29
30#include "ndn-face-container.hpp"
Spyridon Mastorakis588fd102014-11-20 19:50:02 -080031#include "ndn-fib-helper.hpp"
Spyridon Mastorakis592fcba2014-11-23 22:48:03 -080032#include "ndn-strategy-choice-helper.hpp"
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070033
34namespace ns3 {
35
36class Node;
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070037
38namespace ndn {
39
Alexander Afanasyevc17e4bd2013-02-17 14:31:56 -080040class NetDeviceFace;
41class L3Protocol;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070042
43/**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070044 * \ingroup ndn
45 * \defgroup ndn-helpers Helpers
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070046 */
47/**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070048 * \ingroup ndn-helpers
49 * \brief Adding Ndn functionality to existing Nodes.
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070050 *
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070051 * This helper enables pcap and ascii tracing of events in the ndn stack
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070052 * associated with a node. This is substantially similar to the tracing that
53 * happens in device helpers, but the important difference is that, well, there
54 * is no device. This means that the creation of output file names will change,
55 * and also the user-visible methods will not reference devices and therefore
56 * the number of trace enable methods is reduced.
57 *
58 * Normally we eschew multiple inheritance, however, the classes
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070059 * PcapUserHelperForNdn and AsciiTraceUserHelperForNdn are treated as
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070060 * "mixins". A mixin is a self-contained class that encapsulates a general
61 * attribute or a set of functionality that may be of interest to many other
62 * classes.
63 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080064class StackHelper {
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070065public:
66 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070067 * \brief Create a new NdnStackHelper with a default NDN_FLOODING forwarding stategy
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070068 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070069 StackHelper();
Alexander Afanasyev122f3782013-02-02 00:04:40 -080070
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070071 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070072 * \brief Destroy the NdnStackHelper
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070073 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080074 virtual ~StackHelper();
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070075
76 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070077 * @brief Set parameters of NdnL3Protocol
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -070078 */
79 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080080 SetStackAttributes(const std::string& attr1 = "", const std::string& value1 = "",
81 const std::string& attr2 = "", const std::string& value2 = "",
82 const std::string& attr3 = "", const std::string& value3 = "",
83 const std::string& attr4 = "", const std::string& value4 = "");
Alexander Afanasyev122f3782013-02-02 00:04:40 -080084
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -080085 /**
86 * @brief Set content store class and its attributes
87 * @param contentStoreClass string, representing class of the content store
88 */
89 void
90 SetContentStore(const std::string& contentStoreClass, const std::string& attr1 = "",
91 const std::string& value1 = "", const std::string& attr2 = "",
92 const std::string& value2 = "", const std::string& attr3 = "",
93 const std::string& value3 = "", const std::string& attr4 = "",
94 const std::string& value4 = "");
95
96 /**
97 * @brief Set to use native NFD's content store or ndnSIM provided CS implementations
98 *
99 * @note ndnSIM CS implementations have limited support for NDN selectors
100 */
101 void
102 SetContentStoreChoice(const bool shouldUseNfdCs);
103
104 /**
105 * @brief Check if stack is using native NFD content store implementation
106 */
107 bool
108 shouldUseNfdCs() const;
109
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700110 typedef Callback<shared_ptr<NetDeviceFace>, Ptr<Node>, Ptr<L3Protocol>, Ptr<NetDevice>>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800111 NetDeviceFaceCreateCallback;
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800112
113 /**
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800114 * @brief Add callback to create and configure instance of the face, based on supplied Ptr<Node>
115 *and Ptr<NetDevice>
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800116 *
117 * It is possible to set up several callbacks for different NetDevice types.
118 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800119 * If none of the callbacks fit the TypeId of NetDevice, a default callback is used
120 *(DefaultNetDeviceCallback)
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800121 */
122 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800123 AddNetDeviceFaceCreateCallback(TypeId netDeviceType, NetDeviceFaceCreateCallback callback);
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800124
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -0700125 /**
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800126 * @brief Update callback to create and configure instance of the face, based on supplied
127 *Ptr<Node> and Ptr<NetDevice>
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700128 *
129 * It is possible to set up several callbacks for different NetDevice types.
130 *
131 * Using this method, it is possible to override Face creation for PointToPointNetDevices
132 */
133 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800134 UpdateNetDeviceFaceCreateCallback(TypeId netDeviceType, NetDeviceFaceCreateCallback callback);
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700135
136 /**
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800137 * @brief Remove callback to create and configure instance of the face, based on supplied
138 * Ptr<Node> and Ptr<NetDevice>
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700139 */
140 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800141 RemoveNetDeviceFaceCreateCallback(TypeId netDeviceType, NetDeviceFaceCreateCallback callback);
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700142
143 /**
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800144 * \brief Install Ndn stack on the node
145 *
146 * This method will assert if called on a node that already has Ndn object
147 * installed on it
148 *
149 * \param nodeName The name of the node on which to install the stack.
150 *
151 * \returns list of installed faces in the form of a smart pointer
152 * to NdnFaceContainer object
153 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700154 Ptr<FaceContainer>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800155 Install(const std::string& nodeName) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700156
157 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700158 * \brief Install Ndn stack on the node
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700159 *
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700160 * This method will assert if called on a node that already has Ndn object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700161 * installed on it
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800162 *
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700163 * \param node The node on which to install the stack.
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700164 *
165 * \returns list of installed faces in the form of a smart pointer
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700166 * to FaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700167 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700168 Ptr<FaceContainer>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800169 Install(Ptr<Node> node) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700170
171 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700172 * \brief Install Ndn stack on each node in the input container
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700173 *
174 * The program will assert if this method is called on a container with a node
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700175 * that already has an ndn object aggregated to it.
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800176 *
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700177 * \param c NodeContainer that holds the set of nodes on which to install the
178 * new stacks.
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700179 *
180 * \returns list of installed faces in the form of a smart pointer
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700181 * to FaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700182 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700183 Ptr<FaceContainer>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800184 Install(const NodeContainer& c) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700185
186 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700187 * \brief Install Ndn stack on all nodes in the simulation
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700188 *
189 * \returns list of installed faces in the form of a smart pointer
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700190 * to FaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700191 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700192 Ptr<FaceContainer>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800193 InstallAll() const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700194
Spyridon Mastorakis588fd102014-11-20 19:50:02 -0800195 /**
196 * \brief Set flag indicating necessity to install default routes in FIB
197 */
198 void
199 SetDefaultRoutes(bool needSet);
200
Alexander Afanasyev34e13f32014-12-14 15:13:28 -0800201 static KeyChain&
202 getKeyChain();
203
Alexander Afanasyev11453142011-11-25 16:13:33 -0800204private:
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700205 shared_ptr<NetDeviceFace>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800206 DefaultNetDeviceCallback(Ptr<Node> node, Ptr<L3Protocol> ndn, Ptr<NetDevice> netDevice) const;
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800207
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700208 shared_ptr<NetDeviceFace>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800209 PointToPointNetDeviceCallback(Ptr<Node> node, Ptr<L3Protocol> ndn,
210 Ptr<NetDevice> netDevice) const;
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800211
Spyridon Mastorakis86edf6f2014-11-14 19:27:18 -0800212public:
213 void
214 setCustomNdnCxxClocks();
215
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800216private:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800217 StackHelper(const StackHelper&);
218 StackHelper&
219 operator=(const StackHelper& o);
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800220
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700221private:
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700222 ObjectFactory m_ndnFactory;
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700223 ObjectFactory m_contentStoreFactory;
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800224
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800225 bool m_needSetDefaultRoutes;
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -0800226 bool m_shouldUseNfdCs;
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800227
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800228 typedef std::list<std::pair<TypeId, NetDeviceFaceCreateCallback>> NetDeviceCallbackList;
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700229 NetDeviceCallbackList m_netDeviceCallbacks;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700230};
231
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700232} // namespace ndn
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700233} // namespace ns3
234
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700235#endif /* NDN_STACK_HELPER_H */