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 | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 28 | |
| 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" |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 32 | |
| 33 | namespace ns3 { |
| 34 | |
| 35 | class Node; |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 36 | class CcnxFaceContainer; |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 37 | |
| 38 | /** |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 39 | * \ingroup ccnx |
| 40 | * \defgroup ccnx-helpers Helpers |
| 41 | */ |
| 42 | /** |
| 43 | * \ingroup ccnx-helpers |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 44 | * \brief Adding CCNx functionality to existing Nodes. |
| 45 | * |
| 46 | * This helper enables pcap and ascii tracing of events in the ccnx stack |
| 47 | * associated with a node. This is substantially similar to the tracing that |
| 48 | * happens in device helpers, but the important difference is that, well, there |
| 49 | * is no device. This means that the creation of output file names will change, |
| 50 | * and also the user-visible methods will not reference devices and therefore |
| 51 | * the number of trace enable methods is reduced. |
| 52 | * |
| 53 | * Normally we eschew multiple inheritance, however, the classes |
| 54 | * PcapUserHelperForCcnx and AsciiTraceUserHelperForCcnx are treated as |
| 55 | * "mixins". A mixin is a self-contained class that encapsulates a general |
| 56 | * attribute or a set of functionality that may be of interest to many other |
| 57 | * classes. |
| 58 | */ |
| 59 | class CcnxStackHelper : public PcapHelperForCcnx, public AsciiTraceHelperForCcnx |
| 60 | { |
| 61 | public: |
| 62 | /** |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 63 | * \brief Create a new CcnxStackHelper with a default NDN_FLOODING forwarding stategy |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 64 | */ |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 65 | CcnxStackHelper(); |
| 66 | |
| 67 | /** |
| 68 | * \brief Create a new CcnxStackHelper with a specified forwarding strategy |
| 69 | */ |
| 70 | CcnxStackHelper (Ccnx::ForwardingStrategy); |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 71 | |
| 72 | /** |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 73 | * \brief Destroy the CcnxStackHelper |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 74 | */ |
| 75 | virtual ~CcnxStackHelper (); |
| 76 | CcnxStackHelper (const CcnxStackHelper &); |
| 77 | CcnxStackHelper &operator = (const CcnxStackHelper &o); |
| 78 | |
| 79 | /** |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 80 | * Set forwarding strategy helper |
| 81 | * |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 82 | * \param forwarding a new forwarding helper |
| 83 | * |
| 84 | * Set the forwarding helper to use during Install. The forwarding helper is |
| 85 | * really an object factory which is used to create an object of type |
| 86 | * ns3::CcnxFrProtocol per node. This forwarding object is then associated to |
| 87 | * a single ns3::Ccnx object through its ns3::Ccnx::SetforwardingProtocol. |
| 88 | */ |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 89 | void |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 90 | SetForwardingStrategy (Ccnx::ForwardingStrategy strategy); |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 91 | |
| 92 | /** |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 93 | * \brief Install CCNx stack on the node |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 94 | * |
| 95 | * This method will assert if called on a node that already has Ccnx object |
| 96 | * installed on it |
| 97 | * |
| 98 | * \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] | 99 | * |
| 100 | * \returns list of installed faces in the form of a smart pointer |
| 101 | * to CcnxFaceContainer object |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 102 | */ |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 103 | Ptr<CcnxFaceContainer> |
| 104 | Install (std::string nodeName) const; |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 105 | |
| 106 | /** |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 107 | * \brief Install CCNx stack on the node |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 108 | * |
| 109 | * This method will assert if called on a node that already has Ccnx object |
| 110 | * installed on it |
| 111 | * |
| 112 | * \param node The node on which to install the stack. |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 113 | * |
| 114 | * \returns list of installed faces in the form of a smart pointer |
| 115 | * to CcnxFaceContainer object |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 116 | */ |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 117 | Ptr<CcnxFaceContainer> |
| 118 | Install (Ptr<Node> node) const; |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 119 | |
| 120 | /** |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 121 | * \brief Install CCNx stack on each node in the input container |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 122 | * |
| 123 | * The program will assert if this method is called on a container with a node |
| 124 | * that already has an ccnx object aggregated to it. |
| 125 | * |
| 126 | * \param c NodeContainer that holds the set of nodes on which to install the |
| 127 | * new stacks. |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 128 | * |
| 129 | * \returns list of installed faces in the form of a smart pointer |
| 130 | * to CcnxFaceContainer object |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 131 | */ |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 132 | Ptr<CcnxFaceContainer> |
| 133 | Install (NodeContainer c) const; |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 134 | |
| 135 | /** |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 136 | * \brief Install CCNx stack on all nodes in the simulation |
| 137 | * |
| 138 | * \returns list of installed faces in the form of a smart pointer |
| 139 | * to CcnxFaceContainer object |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 140 | */ |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 141 | Ptr<CcnxFaceContainer> |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 142 | InstallAll () const; |
| 143 | |
| 144 | /** |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 145 | * \brief Add forwarding entry in FIB |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 146 | * |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 147 | * \param nodeName Node name |
| 148 | * \param prefix Routing prefix |
| 149 | * \param faceId Face index |
| 150 | * \param metric Routing metric |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 151 | */ |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 152 | void |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 153 | AddRoute (std::string nodeName, std::string prefix, uint32_t faceId, int32_t metric); |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 154 | |
| 155 | private: |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 156 | CcnxForwardingHelper m_forwardingHelper; |
| 157 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 158 | /** |
| 159 | * @brief Enable pcap output the indicated Ccnx and interface pair. |
| 160 | * @internal |
| 161 | * |
| 162 | * @param prefix Filename prefix to use for pcap files. |
| 163 | * @param ccnx Ptr to the Ccnx interface on which you want to enable tracing. |
| 164 | * @param interface Interface ID on the Ccnx on which you want to enable tracing. |
| 165 | */ |
| 166 | virtual void EnablePcapCcnxInternal (std::string prefix, |
| 167 | Ptr<Ccnx> ccnx, |
| 168 | uint32_t interface, |
| 169 | bool explicitFilename); |
| 170 | |
| 171 | /** |
| 172 | * @brief Enable ascii trace output on the indicated Ccnx and interface pair. |
| 173 | * @internal |
| 174 | * |
| 175 | * @param stream An OutputStreamWrapper representing an existing file to use |
| 176 | * when writing trace data. |
| 177 | * @param prefix Filename prefix to use for ascii trace files. |
| 178 | * @param ccnx Ptr to the Ccnx interface on which you want to enable tracing. |
| 179 | * @param interface Interface ID on the Ccnx on which you want to enable tracing. |
| 180 | */ |
| 181 | virtual void EnableAsciiCcnxInternal (Ptr<OutputStreamWrapper> stream, |
| 182 | std::string prefix, |
| 183 | Ptr<Ccnx> ccnx, |
| 184 | uint32_t interface, |
| 185 | bool explicitFilename); |
| 186 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 187 | // /** |
| 188 | // * \internal |
| 189 | // */ |
| 190 | // static void CreateAndAggregateObjectFromTypeId (Ptr<Node> node, const std::string typeId); |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 191 | |
| 192 | /** |
| 193 | * \internal |
| 194 | */ |
| 195 | static void Cleanup (void); |
| 196 | |
| 197 | /** |
| 198 | * \internal |
| 199 | */ |
| 200 | bool PcapHooked (Ptr<Ccnx> ccnx); |
| 201 | |
| 202 | /** |
| 203 | * \internal |
| 204 | */ |
| 205 | bool AsciiHooked (Ptr<Ccnx> ccnx); |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 206 | }; |
| 207 | |
| 208 | } // namespace ns3 |
| 209 | |
| 210 | #endif /* CCNX_STACK_HELPER_H */ |