blob: 2f3ea3bc085a76d057ed906f9d3b7d950d50ed8e [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"
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 Mastorakise4f0d3c2014-10-29 13:20:03 -070085 typedef Callback<shared_ptr<NetDeviceFace>, Ptr<Node>, Ptr<L3Protocol>, Ptr<NetDevice>>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080086 NetDeviceFaceCreateCallback;
Alexander Afanasyev122f3782013-02-02 00:04:40 -080087
88 /**
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080089 * @brief Add callback to create and configure instance of the face, based on supplied Ptr<Node>
90 *and Ptr<NetDevice>
Alexander Afanasyev122f3782013-02-02 00:04:40 -080091 *
92 * It is possible to set up several callbacks for different NetDevice types.
93 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080094 * If none of the callbacks fit the TypeId of NetDevice, a default callback is used
95 *(DefaultNetDeviceCallback)
Alexander Afanasyev122f3782013-02-02 00:04:40 -080096 */
97 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080098 AddNetDeviceFaceCreateCallback(TypeId netDeviceType, NetDeviceFaceCreateCallback callback);
Alexander Afanasyev122f3782013-02-02 00:04:40 -080099
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -0700100 /**
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800101 * @brief Update callback to create and configure instance of the face, based on supplied
102 *Ptr<Node> and Ptr<NetDevice>
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700103 *
104 * It is possible to set up several callbacks for different NetDevice types.
105 *
106 * Using this method, it is possible to override Face creation for PointToPointNetDevices
107 */
108 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800109 UpdateNetDeviceFaceCreateCallback(TypeId netDeviceType, NetDeviceFaceCreateCallback callback);
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700110
111 /**
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800112 * @brief Remove callback to create and configure instance of the face, based on supplied
113 * Ptr<Node> and Ptr<NetDevice>
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700114 */
115 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800116 RemoveNetDeviceFaceCreateCallback(TypeId netDeviceType, NetDeviceFaceCreateCallback callback);
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700117
118 /**
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800119 * \brief Install Ndn stack on the node
120 *
121 * This method will assert if called on a node that already has Ndn object
122 * installed on it
123 *
124 * \param nodeName The name of the node on which to install the stack.
125 *
126 * \returns list of installed faces in the form of a smart pointer
127 * to NdnFaceContainer object
128 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700129 Ptr<FaceContainer>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800130 Install(const std::string& nodeName) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700131
132 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700133 * \brief Install Ndn stack on the node
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700134 *
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700135 * This method will assert if called on a node that already has Ndn object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700136 * installed on it
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800137 *
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700138 * \param node The node on which to install the stack.
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700139 *
140 * \returns list of installed faces in the form of a smart pointer
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700141 * to FaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700142 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700143 Ptr<FaceContainer>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800144 Install(Ptr<Node> node) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700145
146 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700147 * \brief Install Ndn stack on each node in the input container
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700148 *
149 * The program will assert if this method is called on a container with a node
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700150 * that already has an ndn object aggregated to it.
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800151 *
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700152 * \param c NodeContainer that holds the set of nodes on which to install the
153 * new stacks.
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700154 *
155 * \returns list of installed faces in the form of a smart pointer
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700156 * to FaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700157 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700158 Ptr<FaceContainer>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800159 Install(const NodeContainer& c) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700160
161 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700162 * \brief Install Ndn stack on all nodes in the simulation
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700163 *
164 * \returns list of installed faces in the form of a smart pointer
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700165 * to FaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700166 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700167 Ptr<FaceContainer>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800168 InstallAll() const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700169
Alexander Afanasyev34e13f32014-12-14 15:13:28 -0800170 static KeyChain&
171 getKeyChain();
172
Alexander Afanasyev11453142011-11-25 16:13:33 -0800173private:
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700174 shared_ptr<NetDeviceFace>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800175 DefaultNetDeviceCallback(Ptr<Node> node, Ptr<L3Protocol> ndn, Ptr<NetDevice> netDevice) const;
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800176
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700177 shared_ptr<NetDeviceFace>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800178 PointToPointNetDeviceCallback(Ptr<Node> node, Ptr<L3Protocol> ndn,
179 Ptr<NetDevice> netDevice) const;
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800180
Spyridon Mastorakis86edf6f2014-11-14 19:27:18 -0800181public:
182 void
183 setCustomNdnCxxClocks();
184
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800185private:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800186 StackHelper(const StackHelper&);
187 StackHelper&
188 operator=(const StackHelper& o);
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800189
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700190private:
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700191 ObjectFactory m_ndnFactory;
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700192 ObjectFactory m_contentStoreFactory;
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800193
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800194 bool m_needSetDefaultRoutes;
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800195
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800196 typedef std::list<std::pair<TypeId, NetDeviceFaceCreateCallback>> NetDeviceCallbackList;
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700197 NetDeviceCallbackList m_netDeviceCallbacks;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700198};
199
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700200} // namespace ndn
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700201} // namespace ns3
202
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700203#endif /* NDN_STACK_HELPER_H */