Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 2 | /* |
| 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 Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 18 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | * Ilya Moiseenko <iliamo@cs.ucla.edu> |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 22 | #ifndef NDN_STACK_HELPER_H |
| 23 | #define NDN_STACK_HELPER_H |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 24 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 25 | #include "ns3/packet.h" |
| 26 | #include "ns3/ptr.h" |
| 27 | #include "ns3/object-factory.h" |
Alexander Afanasyev | c39f0b4 | 2011-11-28 12:51:12 -0800 | [diff] [blame] | 28 | #include "ns3/nstime.h" |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 29 | |
| 30 | namespace ns3 { |
| 31 | |
| 32 | class Node; |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 33 | class NdnFaceContainer; |
| 34 | class NdnFace; |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 35 | |
| 36 | /** |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 37 | * \ingroup ndn |
| 38 | * \defgroup ndn-helpers Helpers |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 39 | */ |
| 40 | /** |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 41 | * \ingroup ndn-helpers |
| 42 | * \brief Adding Ndn functionality to existing Nodes. |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 43 | * |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 44 | * This helper enables pcap and ascii tracing of events in the ndn stack |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 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 |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 52 | * PcapUserHelperForNdn and AsciiTraceUserHelperForNdn are treated as |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 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 Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 57 | class NdnStackHelper |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 58 | { |
| 59 | public: |
| 60 | /** |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 61 | * \brief Create a new NdnStackHelper with a default NDN_FLOODING forwarding stategy |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 62 | */ |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 63 | NdnStackHelper(); |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 64 | |
| 65 | /** |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 66 | * \brief Destroy the NdnStackHelper |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 67 | */ |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 68 | virtual ~NdnStackHelper (); |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 69 | |
| 70 | /** |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 71 | * @brief Set parameters of NdnL3Protocol |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 72 | */ |
| 73 | void |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 74 | SetNdnAttributes (const std::string &attr1 = "", const std::string &value1 = "", |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 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 Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 83 | * |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 84 | * Valid options are "ns3::NdnFloodingStrategy" (default) and "ns3::NdnBestRouteStrategy" |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 85 | * |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 86 | * Other strategies can be implemented, inheriting ns3::NdnForwardingStrategy class |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 87 | */ |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 88 | void |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 89 | 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 Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 94 | |
| 95 | /** |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 96 | * @brief Set content store class and its attributes |
| 97 | * @param contentStoreClass string, representing class of the content store |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 98 | */ |
| 99 | void |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 100 | 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 Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 116 | |
| 117 | /** |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 118 | * @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 Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 129 | * @brief Enable Interest limits (disabled by default) |
Alexander Afanasyev | c39f0b4 | 2011-11-28 12:51:12 -0800 | [diff] [blame] | 130 | * |
| 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 Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 135 | */ |
| 136 | void |
Alexander Afanasyev | c39f0b4 | 2011-11-28 12:51:12 -0800 | [diff] [blame] | 137 | EnableLimits (bool enable = true, Time avgRtt=Seconds(0.1), uint32_t avgContentObject=1100, uint32_t avgInterest=40); |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 138 | |
| 139 | /** |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 140 | * \brief Install Ndn stack on the node |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 141 | * |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 142 | * This method will assert if called on a node that already has Ndn object |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 143 | * installed on it |
| 144 | * |
| 145 | * \param nodeName The name of the node on which to install the stack. |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 146 | * |
| 147 | * \returns list of installed faces in the form of a smart pointer |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 148 | * to NdnFaceContainer object |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 149 | */ |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 150 | Ptr<NdnFaceContainer> |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 151 | Install (std::string nodeName) const; |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 152 | |
| 153 | /** |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 154 | * \brief Install Ndn stack on the node |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 155 | * |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 156 | * This method will assert if called on a node that already has Ndn object |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 157 | * installed on it |
| 158 | * |
| 159 | * \param node The node on which to install the stack. |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 160 | * |
| 161 | * \returns list of installed faces in the form of a smart pointer |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 162 | * to NdnFaceContainer object |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 163 | */ |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 164 | Ptr<NdnFaceContainer> |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 165 | Install (Ptr<Node> node) const; |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 166 | |
| 167 | /** |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 168 | * \brief Install Ndn stack on each node in the input container |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 169 | * |
| 170 | * The program will assert if this method is called on a container with a node |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 171 | * that already has an ndn object aggregated to it. |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 172 | * |
| 173 | * \param c NodeContainer that holds the set of nodes on which to install the |
| 174 | * new stacks. |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 175 | * |
| 176 | * \returns list of installed faces in the form of a smart pointer |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 177 | * to NdnFaceContainer object |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 178 | */ |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 179 | Ptr<NdnFaceContainer> |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 180 | Install (NodeContainer c) const; |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 181 | |
| 182 | /** |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 183 | * \brief Install Ndn stack on all nodes in the simulation |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 184 | * |
| 185 | * \returns list of installed faces in the form of a smart pointer |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 186 | * to NdnFaceContainer object |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 187 | */ |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 188 | Ptr<NdnFaceContainer> |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 189 | InstallAll () const; |
| 190 | |
| 191 | /** |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 192 | * \brief Add forwarding entry in FIB |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 193 | * |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 194 | * \param nodeName Node name |
| 195 | * \param prefix Routing prefix |
| 196 | * \param faceId Face index |
| 197 | * \param metric Routing metric |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 198 | */ |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 199 | static void |
| 200 | AddRoute (std::string nodeName, std::string prefix, uint32_t faceId, int32_t metric); |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 201 | |
| 202 | /** |
| 203 | * \brief Add forwarding entry in FIB |
| 204 | * |
Alexander Afanasyev | 8bedcaf | 2012-07-20 15:30:44 -0700 | [diff] [blame] | 205 | * \param nodeName Node |
| 206 | * \param prefix Routing prefix |
| 207 | * \param faceId Face index |
| 208 | * \param metric Routing metric |
| 209 | */ |
| 210 | static void |
| 211 | AddRoute (Ptr<Node> node, std::string prefix, uint32_t faceId, int32_t metric); |
| 212 | |
| 213 | /** |
| 214 | * \brief Add forwarding entry in FIB |
| 215 | * |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 216 | * \param node Node |
| 217 | * \param prefix Routing prefix |
| 218 | * \param face Face |
| 219 | * \param metric Routing metric |
| 220 | */ |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 221 | static void |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 222 | AddRoute (Ptr<Node> node, std::string prefix, Ptr<NdnFace> face, int32_t metric); |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame] | 223 | |
| 224 | /** |
| 225 | * \brief Set flag indicating necessity to install default routes in FIB |
| 226 | */ |
| 227 | void |
| 228 | SetDefaultRoutes (bool needSet); |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 229 | |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 230 | private: |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 231 | NdnStackHelper (const NdnStackHelper &); |
| 232 | NdnStackHelper &operator = (const NdnStackHelper &o); |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 233 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 234 | private: |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 235 | ObjectFactory m_ndnFactory; |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 236 | ObjectFactory m_strategyFactory; |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 237 | ObjectFactory m_contentStoreFactory; |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 238 | ObjectFactory m_pitFactory; |
| 239 | ObjectFactory m_fibFactory; |
| 240 | |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 241 | bool m_limitsEnabled; |
Alexander Afanasyev | c39f0b4 | 2011-11-28 12:51:12 -0800 | [diff] [blame] | 242 | Time m_avgRtt; |
| 243 | uint32_t m_avgContentObjectSize; |
| 244 | uint32_t m_avgInterestSize; |
Alexander Afanasyev | 8e2f112 | 2012-04-17 15:01:11 -0700 | [diff] [blame] | 245 | bool m_needSetDefaultRoutes; |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 246 | }; |
| 247 | |
| 248 | } // namespace ns3 |
| 249 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 250 | #endif /* NDN_STACK_HELPER_H */ |