blob: 764a982a365b965445af2858c2b079f0b1ab4231 [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>
19 * Ilya Moiseenko <iliamo@cs.ucla.edu>
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070020 */
21
22#ifndef CCNX_STACK_HELPER_H
23#define CCNX_STACK_HELPER_H
24
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070025#include "ns3/packet.h"
26#include "ns3/ptr.h"
27#include "ns3/object-factory.h"
Alexander Afanasyevc39f0b42011-11-28 12:51:12 -080028#include "ns3/nstime.h"
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070029
30namespace ns3 {
31
32class Node;
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070033class CcnxFaceContainer;
Alexander Afanasyev07827182011-12-13 01:07:32 -080034class CcnxFace;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070035
36/**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070037 * \ingroup ccnx
38 * \defgroup ccnx-helpers Helpers
39 */
40/**
41 * \ingroup ccnx-helpers
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070042 * \brief Adding CCNx functionality to existing Nodes.
43 *
44 * This helper enables pcap and ascii tracing of events in the ccnx stack
45 * associated with a node. This is substantially similar to the tracing that
46 * happens in device helpers, but the important difference is that, well, there
47 * is no device. This means that the creation of output file names will change,
48 * and also the user-visible methods will not reference devices and therefore
49 * the number of trace enable methods is reduced.
50 *
51 * Normally we eschew multiple inheritance, however, the classes
52 * PcapUserHelperForCcnx and AsciiTraceUserHelperForCcnx are treated as
53 * "mixins". A mixin is a self-contained class that encapsulates a general
54 * attribute or a set of functionality that may be of interest to many other
55 * classes.
56 */
Alexander Afanasyev07827182011-12-13 01:07:32 -080057class CcnxStackHelper
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070058{
59public:
60 /**
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070061 * \brief Create a new CcnxStackHelper with a default NDN_FLOODING forwarding stategy
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070062 */
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070063 CcnxStackHelper();
64
65 /**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070066 * \brief Destroy the CcnxStackHelper
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070067 */
68 virtual ~CcnxStackHelper ();
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070069
70 /**
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -070071 * @brief Set parameters of CcnxL3Protocol
72 */
73 void
74 SetCcnxAttributes (const std::string &attr1 = "", const std::string &value1 = "",
75 const std::string &attr2 = "", const std::string &value2 = "",
76 const std::string &attr3 = "", const std::string &value3 = "",
77 const std::string &attr4 = "", const std::string &value4 = "");
78
79
80 /**
81 * @brief Set forwarding strategy class and its attributes
82 * @param forwardingStrategyClass string containing name of the forwarding strategy class
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070083 *
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070084 * Valid options are "ns3::CcnxFloodingStrategy" (default) and "ns3::CcnxBestRouteStrategy"
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070085 *
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070086 * Other strategies can be implemented, inheriting ns3::CcnxForwardingStrategy class
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070087 */
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070088 void
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -070089 SetForwardingStrategy (const std::string &forwardingStrategyClass,
90 const std::string &attr1 = "", const std::string &value1 = "",
91 const std::string &attr2 = "", const std::string &value2 = "",
92 const std::string &attr3 = "", const std::string &value3 = "",
93 const std::string &attr4 = "", const std::string &value4 = "");
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070094
95 /**
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -070096 * @brief Set content store class and its attributes
97 * @param contentStoreClass string, representing class of the content store
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070098 */
99 void
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -0700100 SetContentStore (const std::string &contentStoreClass,
101 const std::string &attr1 = "", const std::string &value1 = "",
102 const std::string &attr2 = "", const std::string &value2 = "",
103 const std::string &attr3 = "", const std::string &value3 = "",
104 const std::string &attr4 = "", const std::string &value4 = "");
105
106 /**
107 * @brief Set PIT class and its attributes
108 * @param pitClass string, representing class of PIT
109 */
110 void
111 SetPit (const std::string &pitClass,
112 const std::string &attr1 = "", const std::string &value1 = "",
113 const std::string &attr2 = "", const std::string &value2 = "",
114 const std::string &attr3 = "", const std::string &value3 = "",
115 const std::string &attr4 = "", const std::string &value4 = "");
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700116
117 /**
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -0700118 * @brief Set FIB class and its attributes
119 * @param pitClass string, representing class of FIB
120 */
121 void
122 SetFib (const std::string &fibClass,
123 const std::string &attr1 = "", const std::string &value1 = "",
124 const std::string &attr2 = "", const std::string &value2 = "",
125 const std::string &attr3 = "", const std::string &value3 = "",
126 const std::string &attr4 = "", const std::string &value4 = "");
127
128 /**
Alexander Afanasyev11453142011-11-25 16:13:33 -0800129 * @brief Enable Interest limits (disabled by default)
Alexander Afanasyevc39f0b42011-11-28 12:51:12 -0800130 *
131 * @param enable Enable or disable limits
132 * @param avgRtt Average RTT
133 * @param avgContentObject Average size of contentObject packets (including all headers)
134 * @param avgInterest Average size of interest packets (including all headers)
Alexander Afanasyev11453142011-11-25 16:13:33 -0800135 */
136 void
Alexander Afanasyevc39f0b42011-11-28 12:51:12 -0800137 EnableLimits (bool enable = true, Time avgRtt=Seconds(0.1), uint32_t avgContentObject=1100, uint32_t avgInterest=40);
Alexander Afanasyev11453142011-11-25 16:13:33 -0800138
139 /**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700140 * \brief Install CCNx stack on the node
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700141 *
142 * This method will assert if called on a node that already has Ccnx object
143 * installed on it
144 *
145 * \param nodeName The name of the node on which to install the stack.
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700146 *
147 * \returns list of installed faces in the form of a smart pointer
148 * to CcnxFaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700149 */
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700150 Ptr<CcnxFaceContainer>
151 Install (std::string nodeName) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700152
153 /**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700154 * \brief Install CCNx stack on the node
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700155 *
156 * This method will assert if called on a node that already has Ccnx object
157 * installed on it
158 *
159 * \param node The node on which to install the stack.
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700160 *
161 * \returns list of installed faces in the form of a smart pointer
162 * to CcnxFaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700163 */
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700164 Ptr<CcnxFaceContainer>
165 Install (Ptr<Node> node) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700166
167 /**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700168 * \brief Install CCNx stack on each node in the input container
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700169 *
170 * The program will assert if this method is called on a container with a node
171 * that already has an ccnx object aggregated to it.
172 *
173 * \param c NodeContainer that holds the set of nodes on which to install the
174 * new stacks.
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700175 *
176 * \returns list of installed faces in the form of a smart pointer
177 * to CcnxFaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700178 */
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700179 Ptr<CcnxFaceContainer>
180 Install (NodeContainer c) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700181
182 /**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700183 * \brief Install CCNx stack on all nodes in the simulation
184 *
185 * \returns list of installed faces in the form of a smart pointer
186 * to CcnxFaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700187 */
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700188 Ptr<CcnxFaceContainer>
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700189 InstallAll () const;
190
191 /**
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700192 * \brief Add forwarding entry in FIB
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700193 *
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700194 * \param nodeName Node name
195 * \param prefix Routing prefix
196 * \param faceId Face index
197 * \param metric Routing metric
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700198 */
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800199 static void
200 AddRoute (std::string nodeName, std::string prefix, uint32_t faceId, int32_t metric);
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800201
202 /**
203 * \brief Add forwarding entry in FIB
204 *
205 * \param node Node
206 * \param prefix Routing prefix
207 * \param face Face
208 * \param metric Routing metric
209 */
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800210 static void
211 AddRoute (Ptr<Node> node, std::string prefix, Ptr<CcnxFace> face, int32_t metric);
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800212
213 /**
214 * \brief Set flag indicating necessity to install default routes in FIB
215 */
216 void
217 SetDefaultRoutes (bool needSet);
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800218
Alexander Afanasyev11453142011-11-25 16:13:33 -0800219private:
220 CcnxStackHelper (const CcnxStackHelper &);
221 CcnxStackHelper &operator = (const CcnxStackHelper &o);
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800222
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700223private:
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -0700224 ObjectFactory m_ccnxFactory;
Alexander Afanasyev11453142011-11-25 16:13:33 -0800225 ObjectFactory m_strategyFactory;
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700226 ObjectFactory m_contentStoreFactory;
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -0700227 ObjectFactory m_pitFactory;
228 ObjectFactory m_fibFactory;
229
Alexander Afanasyev11453142011-11-25 16:13:33 -0800230 bool m_limitsEnabled;
Alexander Afanasyevc39f0b42011-11-28 12:51:12 -0800231 Time m_avgRtt;
232 uint32_t m_avgContentObjectSize;
233 uint32_t m_avgInterestSize;
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700234 bool m_needSetDefaultRoutes;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700235};
236
237} // namespace ns3
238
239#endif /* CCNX_STACK_HELPER_H */