blob: bc9ff3e3d108e9273f77e813319f1d32644546da [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"
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070034
35namespace ns3 {
36
37class Node;
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070038
39namespace ndn {
40
Alexander Afanasyevc17e4bd2013-02-17 14:31:56 -080041class NetDeviceFace;
42class L3Protocol;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070043
44/**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070045 * \ingroup ndn
46 * \defgroup ndn-helpers Helpers
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070047 */
48/**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070049 * \ingroup ndn-helpers
50 * \brief Adding Ndn functionality to existing Nodes.
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070051 *
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070052 * This helper enables pcap and ascii tracing of events in the ndn stack
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070053 * associated with a node. This is substantially similar to the tracing that
54 * happens in device helpers, but the important difference is that, well, there
55 * is no device. This means that the creation of output file names will change,
56 * and also the user-visible methods will not reference devices and therefore
57 * the number of trace enable methods is reduced.
58 *
59 * Normally we eschew multiple inheritance, however, the classes
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070060 * PcapUserHelperForNdn and AsciiTraceUserHelperForNdn are treated as
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070061 * "mixins". A mixin is a self-contained class that encapsulates a general
62 * attribute or a set of functionality that may be of interest to many other
63 * classes.
64 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080065class StackHelper {
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070066public:
67 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070068 * \brief Create a new NdnStackHelper with a default NDN_FLOODING forwarding stategy
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070069 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070070 StackHelper();
Alexander Afanasyev122f3782013-02-02 00:04:40 -080071
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070072 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070073 * \brief Destroy the NdnStackHelper
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070074 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080075 virtual ~StackHelper();
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070076
77 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070078 * @brief Set parameters of NdnL3Protocol
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -070079 */
80 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080081 SetStackAttributes(const std::string& attr1 = "", const std::string& value1 = "",
82 const std::string& attr2 = "", const std::string& value2 = "",
83 const std::string& attr3 = "", const std::string& value3 = "",
84 const std::string& attr4 = "", const std::string& value4 = "");
Alexander Afanasyev122f3782013-02-02 00:04:40 -080085
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -070086 typedef Callback<shared_ptr<NetDeviceFace>, Ptr<Node>, Ptr<L3Protocol>, Ptr<NetDevice>>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080087 NetDeviceFaceCreateCallback;
Alexander Afanasyev122f3782013-02-02 00:04:40 -080088
89 /**
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080090 * @brief Add callback to create and configure instance of the face, based on supplied Ptr<Node>
91 *and Ptr<NetDevice>
Alexander Afanasyev122f3782013-02-02 00:04:40 -080092 *
93 * It is possible to set up several callbacks for different NetDevice types.
94 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080095 * If none of the callbacks fit the TypeId of NetDevice, a default callback is used
96 *(DefaultNetDeviceCallback)
Alexander Afanasyev122f3782013-02-02 00:04:40 -080097 */
98 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080099 AddNetDeviceFaceCreateCallback(TypeId netDeviceType, NetDeviceFaceCreateCallback callback);
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800100
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -0700101 /**
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800102 * @brief Update callback to create and configure instance of the face, based on supplied
103 *Ptr<Node> and Ptr<NetDevice>
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700104 *
105 * It is possible to set up several callbacks for different NetDevice types.
106 *
107 * Using this method, it is possible to override Face creation for PointToPointNetDevices
108 */
109 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800110 UpdateNetDeviceFaceCreateCallback(TypeId netDeviceType, NetDeviceFaceCreateCallback callback);
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700111
112 /**
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800113 * @brief Remove callback to create and configure instance of the face, based on supplied
114 * Ptr<Node> and Ptr<NetDevice>
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700115 */
116 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800117 RemoveNetDeviceFaceCreateCallback(TypeId netDeviceType, NetDeviceFaceCreateCallback callback);
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700118
119 /**
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800120 * \brief Install Ndn stack on the node
121 *
122 * This method will assert if called on a node that already has Ndn object
123 * installed on it
124 *
125 * \param nodeName The name of the node on which to install the stack.
126 *
127 * \returns list of installed faces in the form of a smart pointer
128 * to NdnFaceContainer object
129 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700130 Ptr<FaceContainer>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800131 Install(const std::string& nodeName) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700132
133 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700134 * \brief Install Ndn stack on the node
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700135 *
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700136 * This method will assert if called on a node that already has Ndn object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700137 * installed on it
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800138 *
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700139 * \param node The node on which to install the stack.
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700140 *
141 * \returns list of installed faces in the form of a smart pointer
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700142 * to FaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700143 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700144 Ptr<FaceContainer>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800145 Install(Ptr<Node> node) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700146
147 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700148 * \brief Install Ndn stack on each node in the input container
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700149 *
150 * The program will assert if this method is called on a container with a node
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700151 * that already has an ndn object aggregated to it.
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800152 *
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700153 * \param c NodeContainer that holds the set of nodes on which to install the
154 * new stacks.
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700155 *
156 * \returns list of installed faces in the form of a smart pointer
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700157 * to FaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700158 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700159 Ptr<FaceContainer>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800160 Install(const NodeContainer& c) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700161
162 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700163 * \brief Install Ndn stack on all nodes in the simulation
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 InstallAll() const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700170
Spyridon Mastorakis588fd102014-11-20 19:50:02 -0800171 /**
172 * \brief Set flag indicating necessity to install default routes in FIB
173 */
174 void
175 SetDefaultRoutes(bool needSet);
176
Alexander Afanasyev34e13f32014-12-14 15:13:28 -0800177 static KeyChain&
178 getKeyChain();
179
Alexander Afanasyev11453142011-11-25 16:13:33 -0800180private:
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700181 shared_ptr<NetDeviceFace>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800182 DefaultNetDeviceCallback(Ptr<Node> node, Ptr<L3Protocol> ndn, Ptr<NetDevice> netDevice) const;
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800183
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700184 shared_ptr<NetDeviceFace>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800185 PointToPointNetDeviceCallback(Ptr<Node> node, Ptr<L3Protocol> ndn,
186 Ptr<NetDevice> netDevice) const;
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800187
Spyridon Mastorakis86edf6f2014-11-14 19:27:18 -0800188public:
189 void
190 setCustomNdnCxxClocks();
191
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800192private:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800193 StackHelper(const StackHelper&);
194 StackHelper&
195 operator=(const StackHelper& o);
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800196
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700197private:
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700198 ObjectFactory m_ndnFactory;
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700199 ObjectFactory m_contentStoreFactory;
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800200
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800201 bool m_needSetDefaultRoutes;
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800202
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800203 typedef std::list<std::pair<TypeId, NetDeviceFaceCreateCallback>> NetDeviceCallbackList;
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700204 NetDeviceCallbackList m_netDeviceCallbacks;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700205};
206
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700207} // namespace ndn
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700208} // namespace ns3
209
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700210#endif /* NDN_STACK_HELPER_H */