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 | * |
| 18 | * Author: |
| 19 | */ |
| 20 | |
| 21 | #ifndef CCNX_STACK_HELPER_H |
| 22 | #define CCNX_STACK_HELPER_H |
| 23 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 24 | #include "ns3/packet.h" |
| 25 | #include "ns3/ptr.h" |
| 26 | #include "ns3/object-factory.h" |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 27 | |
| 28 | #include "ccnx-trace-helper.h" |
| 29 | |
| 30 | namespace ns3 { |
| 31 | |
| 32 | class Node; |
| 33 | class CcnxForwardingHelper; |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 34 | class CcnxFaceContainer; |
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 | */ |
| 57 | class CcnxStackHelper : public PcapHelperForCcnx, public AsciiTraceHelperForCcnx |
| 58 | { |
| 59 | public: |
| 60 | /** |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 61 | * \brief Create a new CcnxStackHelper with empty forwarding by default. |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 62 | * |
| 63 | * \todo set non-empty default forwarding |
| 64 | */ |
| 65 | CcnxStackHelper (); |
| 66 | |
| 67 | /** |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 68 | * \brief Destroy the CcnxStackHelper |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 69 | */ |
| 70 | virtual ~CcnxStackHelper (); |
| 71 | CcnxStackHelper (const CcnxStackHelper &); |
| 72 | CcnxStackHelper &operator = (const CcnxStackHelper &o); |
| 73 | |
| 74 | /** |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 75 | * Set forwarding strategy helper |
| 76 | * |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 77 | * \param forwarding a new forwarding helper |
| 78 | * |
| 79 | * Set the forwarding helper to use during Install. The forwarding helper is |
| 80 | * really an object factory which is used to create an object of type |
| 81 | * ns3::CcnxFrProtocol per node. This forwarding object is then associated to |
| 82 | * a single ns3::Ccnx object through its ns3::Ccnx::SetforwardingProtocol. |
| 83 | */ |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 84 | void |
| 85 | SetForwardingHelper (const CcnxForwardingHelper &forwarding); |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 86 | |
| 87 | /** |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 88 | * \brief Install CCNx stack on the node |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 89 | * |
| 90 | * This method will assert if called on a node that already has Ccnx object |
| 91 | * installed on it |
| 92 | * |
| 93 | * \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] | 94 | * |
| 95 | * \returns list of installed faces in the form of a smart pointer |
| 96 | * to CcnxFaceContainer object |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 97 | */ |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 98 | Ptr<CcnxFaceContainer> |
| 99 | Install (std::string nodeName) const; |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 100 | |
| 101 | /** |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 102 | * \brief Install CCNx stack on the node |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 103 | * |
| 104 | * This method will assert if called on a node that already has Ccnx object |
| 105 | * installed on it |
| 106 | * |
| 107 | * \param node The node on which to install the stack. |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 108 | * |
| 109 | * \returns list of installed faces in the form of a smart pointer |
| 110 | * to CcnxFaceContainer object |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 111 | */ |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 112 | Ptr<CcnxFaceContainer> |
| 113 | Install (Ptr<Node> node) const; |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 114 | |
| 115 | /** |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 116 | * \brief Install CCNx stack on each node in the input container |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 117 | * |
| 118 | * The program will assert if this method is called on a container with a node |
| 119 | * that already has an ccnx object aggregated to it. |
| 120 | * |
| 121 | * \param c NodeContainer that holds the set of nodes on which to install the |
| 122 | * new stacks. |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 123 | * |
| 124 | * \returns list of installed faces in the form of a smart pointer |
| 125 | * to CcnxFaceContainer object |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 126 | */ |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 127 | Ptr<CcnxFaceContainer> |
| 128 | Install (NodeContainer c) const; |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 129 | |
| 130 | /** |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 131 | * \brief Install CCNx stack on all nodes in the simulation |
| 132 | * |
| 133 | * \returns list of installed faces in the form of a smart pointer |
| 134 | * to CcnxFaceContainer object |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 135 | */ |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 136 | Ptr<CcnxFaceContainer> |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 137 | InstallAll () const; |
| 138 | |
| 139 | /** |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 140 | * \brief Add forwarding entry in FIB |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 141 | * |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 142 | * \param nodeName Node name |
| 143 | * \param prefix Routing prefix |
| 144 | * \param faceId Face index |
| 145 | * \param metric Routing metric |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 146 | */ |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 147 | void |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 148 | 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] | 149 | |
| 150 | private: |
| 151 | /** |
| 152 | * @brief Enable pcap output the indicated Ccnx and interface pair. |
| 153 | * @internal |
| 154 | * |
| 155 | * @param prefix Filename prefix to use for pcap files. |
| 156 | * @param ccnx Ptr to the Ccnx interface on which you want to enable tracing. |
| 157 | * @param interface Interface ID on the Ccnx on which you want to enable tracing. |
| 158 | */ |
| 159 | virtual void EnablePcapCcnxInternal (std::string prefix, |
| 160 | Ptr<Ccnx> ccnx, |
| 161 | uint32_t interface, |
| 162 | bool explicitFilename); |
| 163 | |
| 164 | /** |
| 165 | * @brief Enable ascii trace output on the indicated Ccnx and interface pair. |
| 166 | * @internal |
| 167 | * |
| 168 | * @param stream An OutputStreamWrapper representing an existing file to use |
| 169 | * when writing trace data. |
| 170 | * @param prefix Filename prefix to use for ascii trace files. |
| 171 | * @param ccnx Ptr to the Ccnx interface on which you want to enable tracing. |
| 172 | * @param interface Interface ID on the Ccnx on which you want to enable tracing. |
| 173 | */ |
| 174 | virtual void EnableAsciiCcnxInternal (Ptr<OutputStreamWrapper> stream, |
| 175 | std::string prefix, |
| 176 | Ptr<Ccnx> ccnx, |
| 177 | uint32_t interface, |
| 178 | bool explicitFilename); |
| 179 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 180 | // /** |
| 181 | // * \internal |
| 182 | // */ |
| 183 | // static void CreateAndAggregateObjectFromTypeId (Ptr<Node> node, const std::string typeId); |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 184 | |
| 185 | /** |
| 186 | * \internal |
| 187 | */ |
| 188 | static void Cleanup (void); |
| 189 | |
| 190 | /** |
| 191 | * \internal |
| 192 | */ |
| 193 | bool PcapHooked (Ptr<Ccnx> ccnx); |
| 194 | |
| 195 | /** |
| 196 | * \internal |
| 197 | */ |
| 198 | bool AsciiHooked (Ptr<Ccnx> ccnx); |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 199 | }; |
| 200 | |
| 201 | } // namespace ns3 |
| 202 | |
| 203 | #endif /* CCNX_STACK_HELPER_H */ |