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" |
Ilya Moiseenko | fbd0a8b | 2011-10-28 13:07:16 -0700 | [diff] [blame] | 28 | #include "ns3/point-to-point-net-device.h" |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 29 | #include "ccnx-trace-helper.h" |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 30 | #include "ns3/ccnx-forwarding-helper.h" |
| 31 | #include "ns3/ccnx.h" |
Ilya Moiseenko | fbd0a8b | 2011-10-28 13:07:16 -0700 | [diff] [blame] | 32 | #include "ns3/data-rate.h" |
| 33 | #include "ns3/ccnx-interest-header.h" |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 34 | |
| 35 | namespace ns3 { |
| 36 | |
| 37 | class Node; |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 38 | class CcnxFaceContainer; |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 39 | |
| 40 | /** |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 41 | * \ingroup ccnx |
| 42 | * \defgroup ccnx-helpers Helpers |
| 43 | */ |
| 44 | /** |
| 45 | * \ingroup ccnx-helpers |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 46 | * \brief Adding CCNx functionality to existing Nodes. |
| 47 | * |
| 48 | * This helper enables pcap and ascii tracing of events in the ccnx stack |
| 49 | * associated with a node. This is substantially similar to the tracing that |
| 50 | * happens in device helpers, but the important difference is that, well, there |
| 51 | * is no device. This means that the creation of output file names will change, |
| 52 | * and also the user-visible methods will not reference devices and therefore |
| 53 | * the number of trace enable methods is reduced. |
| 54 | * |
| 55 | * Normally we eschew multiple inheritance, however, the classes |
| 56 | * PcapUserHelperForCcnx and AsciiTraceUserHelperForCcnx are treated as |
| 57 | * "mixins". A mixin is a self-contained class that encapsulates a general |
| 58 | * attribute or a set of functionality that may be of interest to many other |
| 59 | * classes. |
| 60 | */ |
| 61 | class CcnxStackHelper : public PcapHelperForCcnx, public AsciiTraceHelperForCcnx |
| 62 | { |
| 63 | public: |
| 64 | /** |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 65 | * \brief Create a new CcnxStackHelper with a default NDN_FLOODING forwarding stategy |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 66 | */ |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 67 | CcnxStackHelper(); |
| 68 | |
| 69 | /** |
| 70 | * \brief Create a new CcnxStackHelper with a specified forwarding strategy |
| 71 | */ |
| 72 | CcnxStackHelper (Ccnx::ForwardingStrategy); |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 73 | |
| 74 | /** |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 75 | * \brief Destroy the CcnxStackHelper |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 76 | */ |
| 77 | virtual ~CcnxStackHelper (); |
| 78 | CcnxStackHelper (const CcnxStackHelper &); |
| 79 | CcnxStackHelper &operator = (const CcnxStackHelper &o); |
| 80 | |
| 81 | /** |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 82 | * Set forwarding strategy helper |
| 83 | * |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 84 | * \param forwarding a new forwarding helper |
| 85 | * |
| 86 | * Set the forwarding helper to use during Install. The forwarding helper is |
| 87 | * really an object factory which is used to create an object of type |
| 88 | * ns3::CcnxFrProtocol per node. This forwarding object is then associated to |
| 89 | * a single ns3::Ccnx object through its ns3::Ccnx::SetforwardingProtocol. |
| 90 | */ |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 91 | void |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 92 | SetForwardingStrategy (Ccnx::ForwardingStrategy strategy); |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [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 | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 155 | AddRoute (std::string nodeName, std::string prefix, uint32_t faceId, int32_t metric); |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 156 | /* |
| 157 | void |
| 158 | AddRoute (Ptr<Node> node, std::string prefix, uint32_t faceId, int32_t metric); |
| 159 | */ |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 160 | private: |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 161 | CcnxForwardingHelper m_forwardingHelper; |
| 162 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 163 | /** |
| 164 | * @brief Enable pcap output the indicated Ccnx and interface pair. |
| 165 | * @internal |
| 166 | * |
| 167 | * @param prefix Filename prefix to use for pcap files. |
| 168 | * @param ccnx Ptr to the Ccnx interface on which you want to enable tracing. |
| 169 | * @param interface Interface ID on the Ccnx on which you want to enable tracing. |
| 170 | */ |
| 171 | virtual void EnablePcapCcnxInternal (std::string prefix, |
| 172 | Ptr<Ccnx> ccnx, |
| 173 | uint32_t interface, |
| 174 | bool explicitFilename); |
| 175 | |
| 176 | /** |
| 177 | * @brief Enable ascii trace output on the indicated Ccnx and interface pair. |
| 178 | * @internal |
| 179 | * |
| 180 | * @param stream An OutputStreamWrapper representing an existing file to use |
| 181 | * when writing trace data. |
| 182 | * @param prefix Filename prefix to use for ascii trace files. |
| 183 | * @param ccnx Ptr to the Ccnx interface on which you want to enable tracing. |
| 184 | * @param interface Interface ID on the Ccnx on which you want to enable tracing. |
| 185 | */ |
| 186 | virtual void EnableAsciiCcnxInternal (Ptr<OutputStreamWrapper> stream, |
| 187 | std::string prefix, |
| 188 | Ptr<Ccnx> ccnx, |
| 189 | uint32_t interface, |
| 190 | bool explicitFilename); |
| 191 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 192 | // /** |
| 193 | // * \internal |
| 194 | // */ |
| 195 | // static void CreateAndAggregateObjectFromTypeId (Ptr<Node> node, const std::string typeId); |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 196 | |
| 197 | /** |
| 198 | * \internal |
| 199 | */ |
| 200 | static void Cleanup (void); |
| 201 | |
| 202 | /** |
| 203 | * \internal |
| 204 | */ |
| 205 | bool PcapHooked (Ptr<Ccnx> ccnx); |
| 206 | |
| 207 | /** |
| 208 | * \internal |
| 209 | */ |
| 210 | bool AsciiHooked (Ptr<Ccnx> ccnx); |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 211 | }; |
| 212 | |
| 213 | } // namespace ns3 |
| 214 | |
| 215 | #endif /* CCNX_STACK_HELPER_H */ |