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 | |
| 22 | #ifndef CCNX_STACK_HELPER_H |
| 23 | #define CCNX_STACK_HELPER_H |
| 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 | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 33 | class CcnxFaceContainer; |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 34 | class CcnxFace; |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 35 | |
| 36 | /** |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 37 | * \ingroup ccnx |
| 38 | * \defgroup ccnx-helpers Helpers |
| 39 | */ |
| 40 | /** |
| 41 | * \ingroup ccnx-helpers |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 42 | * \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 Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 57 | class CcnxStackHelper |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 58 | { |
| 59 | public: |
| 60 | /** |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 61 | * \brief Create a new CcnxStackHelper with a default NDN_FLOODING forwarding stategy |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 62 | */ |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 63 | CcnxStackHelper(); |
| 64 | |
| 65 | /** |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 66 | * \brief Destroy the CcnxStackHelper |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 67 | */ |
| 68 | virtual ~CcnxStackHelper (); |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 69 | |
| 70 | /** |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 71 | * @brief Set forwarding strategy helper |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 72 | * |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 73 | * \param forwarding a new forwarding helper |
| 74 | * |
| 75 | * Set the forwarding helper to use during Install. The forwarding helper is |
| 76 | * really an object factory which is used to create an object of type |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 77 | * ns3::CcnxL3Protocol per node. This forwarding object is then associated to |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 78 | * a single ns3::Ccnx object through its ns3::Ccnx::SetforwardingProtocol. |
| 79 | */ |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 80 | void |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 81 | SetForwardingStrategy (std::string forwardingStrategy); |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 82 | |
| 83 | /** |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 84 | * @brief Enable Interest limits (disabled by default) |
Alexander Afanasyev | c39f0b4 | 2011-11-28 12:51:12 -0800 | [diff] [blame] | 85 | * |
| 86 | * @param enable Enable or disable limits |
| 87 | * @param avgRtt Average RTT |
| 88 | * @param avgContentObject Average size of contentObject packets (including all headers) |
| 89 | * @param avgInterest Average size of interest packets (including all headers) |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 90 | */ |
| 91 | void |
Alexander Afanasyev | c39f0b4 | 2011-11-28 12:51:12 -0800 | [diff] [blame] | 92 | 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] | 93 | |
| 94 | /** |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 95 | * \brief Install CCNx stack on the node |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 96 | * |
| 97 | * This method will assert if called on a node that already has Ccnx object |
| 98 | * installed on it |
| 99 | * |
| 100 | * \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] | 101 | * |
| 102 | * \returns list of installed faces in the form of a smart pointer |
| 103 | * to CcnxFaceContainer object |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 104 | */ |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 105 | Ptr<CcnxFaceContainer> |
| 106 | Install (std::string nodeName) const; |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 107 | |
| 108 | /** |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 109 | * \brief Install CCNx stack on the node |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 110 | * |
| 111 | * This method will assert if called on a node that already has Ccnx object |
| 112 | * installed on it |
| 113 | * |
| 114 | * \param node The node on which to install the stack. |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 115 | * |
| 116 | * \returns list of installed faces in the form of a smart pointer |
| 117 | * to CcnxFaceContainer object |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 118 | */ |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 119 | Ptr<CcnxFaceContainer> |
| 120 | Install (Ptr<Node> node) const; |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 121 | |
| 122 | /** |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 123 | * \brief Install CCNx stack on each node in the input container |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 124 | * |
| 125 | * The program will assert if this method is called on a container with a node |
| 126 | * that already has an ccnx object aggregated to it. |
| 127 | * |
| 128 | * \param c NodeContainer that holds the set of nodes on which to install the |
| 129 | * new stacks. |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 130 | * |
| 131 | * \returns list of installed faces in the form of a smart pointer |
| 132 | * to CcnxFaceContainer object |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 133 | */ |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 134 | Ptr<CcnxFaceContainer> |
| 135 | Install (NodeContainer c) const; |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 136 | |
| 137 | /** |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 138 | * \brief Install CCNx stack on all nodes in the simulation |
| 139 | * |
| 140 | * \returns list of installed faces in the form of a smart pointer |
| 141 | * to CcnxFaceContainer object |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 142 | */ |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 143 | Ptr<CcnxFaceContainer> |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 144 | InstallAll () const; |
| 145 | |
| 146 | /** |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 147 | * \brief Add forwarding entry in FIB |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 148 | * |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 149 | * \param nodeName Node name |
| 150 | * \param prefix Routing prefix |
| 151 | * \param faceId Face index |
| 152 | * \param metric Routing metric |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 153 | */ |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 154 | void |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame] | 155 | AddRoute (std::string nodeName, std::string prefix, uint32_t faceId, int32_t metric) const; |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 156 | |
| 157 | /** |
| 158 | * \brief Add forwarding entry in FIB |
| 159 | * |
| 160 | * \param node Node |
| 161 | * \param prefix Routing prefix |
| 162 | * \param face Face |
| 163 | * \param metric Routing metric |
| 164 | */ |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 165 | void |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame] | 166 | AddRoute (Ptr<Node> node, std::string prefix, Ptr<CcnxFace> face, int32_t metric) const; |
| 167 | |
| 168 | /** |
| 169 | * \brief Set flag indicating necessity to install default routes in FIB |
| 170 | */ |
| 171 | void |
| 172 | SetDefaultRoutes (bool needSet); |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 173 | |
| 174 | /** |
| 175 | * \brief Install fake IPv4 routes that could be used to find nexthops for CCNx routes |
| 176 | * |
| 177 | * This method adds fake routes to all nodes, where each route is /32 and IPv4 address equal to node number. |
| 178 | * For example, node 5 will have direct route to 0.0.0.5. |
| 179 | */ |
| 180 | void |
| 181 | InstallFakeGlobalRoutes (); |
| 182 | |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 183 | void |
| 184 | InstallFakeGlobalRoutesImpl (); |
| 185 | |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 186 | /** |
| 187 | * \brief Installs CCNx route to `node` based on fake IPv4 routes |
| 188 | * |
| 189 | * Actual route is "/<nodeId>" |
| 190 | * |
| 191 | * \param node Pointer to a node, which should be reached from all other nodes |
| 192 | */ |
| 193 | void |
| 194 | InstallRouteTo (Ptr<Node> node); |
| 195 | |
| 196 | /** |
| 197 | * \brief Installs CCNx route to all nodes based on fake IPv4 routes |
| 198 | * |
| 199 | * \see InstallRouteTo |
| 200 | */ |
| 201 | void |
| 202 | InstallRoutesToAll (); |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 203 | |
| 204 | private: |
| 205 | CcnxStackHelper (const CcnxStackHelper &); |
| 206 | CcnxStackHelper &operator = (const CcnxStackHelper &o); |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 207 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 208 | private: |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 209 | ObjectFactory m_strategyFactory; |
| 210 | bool m_limitsEnabled; |
Alexander Afanasyev | c39f0b4 | 2011-11-28 12:51:12 -0800 | [diff] [blame] | 211 | Time m_avgRtt; |
| 212 | uint32_t m_avgContentObjectSize; |
| 213 | uint32_t m_avgInterestSize; |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame] | 214 | bool m_needSetDefaultRoutes; |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 215 | |
| 216 | // /** |
| 217 | // * @brief Enable pcap output the indicated Ccnx and interface pair. |
| 218 | // * @internal |
| 219 | // * |
| 220 | // * @param prefix Filename prefix to use for pcap files. |
| 221 | // * @param ccnx Ptr to the Ccnx interface on which you want to enable tracing. |
| 222 | // * @param interface Interface ID on the Ccnx on which you want to enable tracing. |
| 223 | // */ |
| 224 | // virtual void EnablePcapCcnxInternal (std::string prefix, |
| 225 | // Ptr<Ccnx> ccnx, |
| 226 | // uint32_t interface, |
| 227 | // bool explicitFilename); |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 228 | |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 229 | // /** |
| 230 | // * @brief Enable ascii trace output on the indicated Ccnx and interface pair. |
| 231 | // * @internal |
| 232 | // * |
| 233 | // * @param stream An OutputStreamWrapper representing an existing file to use |
| 234 | // * when writing trace data. |
| 235 | // * @param prefix Filename prefix to use for ascii trace files. |
| 236 | // * @param ccnx Ptr to the Ccnx interface on which you want to enable tracing. |
| 237 | // * @param interface Interface ID on the Ccnx on which you want to enable tracing. |
| 238 | // */ |
| 239 | // virtual void EnableAsciiCcnxInternal (Ptr<OutputStreamWrapper> stream, |
| 240 | // std::string prefix, |
| 241 | // Ptr<Ccnx> ccnx, |
| 242 | // uint32_t interface, |
| 243 | // bool explicitFilename); |
| 244 | |
| 245 | // // /** |
| 246 | // // * \internal |
| 247 | // // */ |
| 248 | // // static void CreateAndAggregateObjectFromTypeId (Ptr<Node> node, const std::string typeId); |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 249 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 250 | // /** |
| 251 | // * \internal |
| 252 | // */ |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 253 | // static void Cleanup (void); |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 254 | |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 255 | // /** |
| 256 | // * \internal |
| 257 | // */ |
| 258 | // bool PcapHooked (Ptr<Ccnx> ccnx); |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 259 | |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 260 | // /** |
| 261 | // * \internal |
| 262 | // */ |
| 263 | // bool AsciiHooked (Ptr<Ccnx> ccnx); |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 264 | }; |
| 265 | |
| 266 | } // namespace ns3 |
| 267 | |
| 268 | #endif /* CCNX_STACK_HELPER_H */ |