blob: 77d3b5c050b384b6816cbe2014d68b8ea5248758 [file] [log] [blame]
Alexander Afanasyevc74a6022011-08-15 20:01:35 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Alexander Afanasyev45b92d42011-08-14 23:11:38 -07002/*
3 * Copyright (c) 2011 UCLA
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070018 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
Alexander Afanasyev122f3782013-02-02 00:04:40 -080019 * Ilya Moiseenko <iliamo@cs.ucla.edu>
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070020 */
21
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070022#ifndef NDN_STACK_HELPER_H
23#define NDN_STACK_HELPER_H
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070024
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070025#include "ns3/ndnSIM/model/ndn-common.hpp"
26
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070027#include "ns3/ptr.h"
28#include "ns3/object-factory.h"
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080029#include "ns3/node.h"
30#include "ns3/node-container.h"
31
32#include "ndn-face-container.hpp"
Spyridon Mastorakis588fd102014-11-20 19:50:02 -080033#include "ndn-fib-helper.hpp"
Spyridon Mastorakis592fcba2014-11-23 22:48:03 -080034#include "ndn-strategy-choice-helper.hpp"
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070035
36namespace ns3 {
37
38class Node;
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070039
40namespace ndn {
41
Alexander Afanasyevc17e4bd2013-02-17 14:31:56 -080042class NetDeviceFace;
43class L3Protocol;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070044
45/**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070046 * \ingroup ndn
47 * \defgroup ndn-helpers Helpers
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070048 */
49/**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070050 * \ingroup ndn-helpers
51 * \brief Adding Ndn functionality to existing Nodes.
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070052 *
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070053 * This helper enables pcap and ascii tracing of events in the ndn stack
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070054 * associated with a node. This is substantially similar to the tracing that
55 * happens in device helpers, but the important difference is that, well, there
56 * is no device. This means that the creation of output file names will change,
57 * and also the user-visible methods will not reference devices and therefore
58 * the number of trace enable methods is reduced.
59 *
60 * Normally we eschew multiple inheritance, however, the classes
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070061 * PcapUserHelperForNdn and AsciiTraceUserHelperForNdn are treated as
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070062 * "mixins". A mixin is a self-contained class that encapsulates a general
63 * attribute or a set of functionality that may be of interest to many other
64 * classes.
65 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080066class StackHelper {
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070067public:
68 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070069 * \brief Create a new NdnStackHelper with a default NDN_FLOODING forwarding stategy
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070070 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070071 StackHelper();
Alexander Afanasyev122f3782013-02-02 00:04:40 -080072
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070073 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070074 * \brief Destroy the NdnStackHelper
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070075 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080076 virtual ~StackHelper();
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070077
78 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070079 * @brief Set parameters of NdnL3Protocol
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -070080 */
81 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080082 SetStackAttributes(const std::string& attr1 = "", const std::string& value1 = "",
83 const std::string& attr2 = "", const std::string& value2 = "",
84 const std::string& attr3 = "", const std::string& value3 = "",
85 const std::string& attr4 = "", const std::string& value4 = "");
Alexander Afanasyev122f3782013-02-02 00:04:40 -080086
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -070087 typedef Callback<shared_ptr<NetDeviceFace>, Ptr<Node>, Ptr<L3Protocol>, Ptr<NetDevice>>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080088 NetDeviceFaceCreateCallback;
Alexander Afanasyev122f3782013-02-02 00:04:40 -080089
90 /**
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080091 * @brief Add callback to create and configure instance of the face, based on supplied Ptr<Node>
92 *and Ptr<NetDevice>
Alexander Afanasyev122f3782013-02-02 00:04:40 -080093 *
94 * It is possible to set up several callbacks for different NetDevice types.
95 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080096 * If none of the callbacks fit the TypeId of NetDevice, a default callback is used
97 *(DefaultNetDeviceCallback)
Alexander Afanasyev122f3782013-02-02 00:04:40 -080098 */
99 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800100 AddNetDeviceFaceCreateCallback(TypeId netDeviceType, NetDeviceFaceCreateCallback callback);
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800101
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -0700102 /**
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800103 * @brief Update callback to create and configure instance of the face, based on supplied
104 *Ptr<Node> and Ptr<NetDevice>
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700105 *
106 * It is possible to set up several callbacks for different NetDevice types.
107 *
108 * Using this method, it is possible to override Face creation for PointToPointNetDevices
109 */
110 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800111 UpdateNetDeviceFaceCreateCallback(TypeId netDeviceType, NetDeviceFaceCreateCallback callback);
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700112
113 /**
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800114 * @brief Remove callback to create and configure instance of the face, based on supplied
115 * Ptr<Node> and Ptr<NetDevice>
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700116 */
117 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800118 RemoveNetDeviceFaceCreateCallback(TypeId netDeviceType, NetDeviceFaceCreateCallback callback);
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700119
120 /**
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800121 * \brief Install Ndn stack on the node
122 *
123 * This method will assert if called on a node that already has Ndn object
124 * installed on it
125 *
126 * \param nodeName The name of the node on which to install the stack.
127 *
128 * \returns list of installed faces in the form of a smart pointer
129 * to NdnFaceContainer object
130 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700131 Ptr<FaceContainer>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800132 Install(const std::string& nodeName) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700133
134 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700135 * \brief Install Ndn stack on the node
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700136 *
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700137 * This method will assert if called on a node that already has Ndn object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700138 * installed on it
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800139 *
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700140 * \param node The node on which to install the stack.
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700141 *
142 * \returns list of installed faces in the form of a smart pointer
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700143 * to FaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700144 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700145 Ptr<FaceContainer>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800146 Install(Ptr<Node> node) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700147
148 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700149 * \brief Install Ndn stack on each node in the input container
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700150 *
151 * The program will assert if this method is called on a container with a node
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700152 * that already has an ndn object aggregated to it.
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800153 *
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700154 * \param c NodeContainer that holds the set of nodes on which to install the
155 * new stacks.
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700156 *
157 * \returns list of installed faces in the form of a smart pointer
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700158 * to FaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700159 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700160 Ptr<FaceContainer>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800161 Install(const NodeContainer& c) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700162
163 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700164 * \brief Install Ndn stack on all nodes in the simulation
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700165 *
166 * \returns list of installed faces in the form of a smart pointer
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700167 * to FaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700168 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700169 Ptr<FaceContainer>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800170 InstallAll() const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700171
Spyridon Mastorakis588fd102014-11-20 19:50:02 -0800172 /**
173 * \brief Set flag indicating necessity to install default routes in FIB
174 */
175 void
176 SetDefaultRoutes(bool needSet);
177
Alexander Afanasyev34e13f32014-12-14 15:13:28 -0800178 static KeyChain&
179 getKeyChain();
180
Alexander Afanasyev11453142011-11-25 16:13:33 -0800181private:
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700182 shared_ptr<NetDeviceFace>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800183 DefaultNetDeviceCallback(Ptr<Node> node, Ptr<L3Protocol> ndn, Ptr<NetDevice> netDevice) const;
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800184
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700185 shared_ptr<NetDeviceFace>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800186 PointToPointNetDeviceCallback(Ptr<Node> node, Ptr<L3Protocol> ndn,
187 Ptr<NetDevice> netDevice) const;
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800188
Spyridon Mastorakis86edf6f2014-11-14 19:27:18 -0800189public:
190 void
191 setCustomNdnCxxClocks();
192
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800193private:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800194 StackHelper(const StackHelper&);
195 StackHelper&
196 operator=(const StackHelper& o);
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800197
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700198private:
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700199 ObjectFactory m_ndnFactory;
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700200 ObjectFactory m_contentStoreFactory;
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800201
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800202 bool m_needSetDefaultRoutes;
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800203
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800204 typedef std::list<std::pair<TypeId, NetDeviceFaceCreateCallback>> NetDeviceCallbackList;
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700205 NetDeviceCallbackList m_netDeviceCallbacks;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700206};
207
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700208} // namespace ndn
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700209} // namespace ns3
210
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700211#endif /* NDN_STACK_HELPER_H */