Alexander Afanasyev | 141d131 | 2011-12-18 14:58:35 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 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: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | */ |
| 20 | |
| 21 | #ifndef CCNX_TRACE_HELPER_H |
| 22 | #define CCNX_TRACE_HELPER_H |
| 23 | |
| 24 | #include "ns3/ptr.h" |
| 25 | #include "ns3/simple-ref-count.h" |
| 26 | #include "ns3/ccnx.h" |
| 27 | |
| 28 | namespace ns3 { |
| 29 | |
| 30 | class CcnxApp; |
| 31 | |
| 32 | class CcnxAppTracer : public SimpleRefCount<CcnxAppTracer> |
| 33 | { |
| 34 | public: |
| 35 | CcnxAppTracer (const std::string &app, const std::string &node = "*", const std::string &appId = "*"); |
| 36 | virtual ~CcnxAppTracer () { }; |
| 37 | |
| 38 | virtual void |
| 39 | PrintHeader (std::ostream &os) const = 0; |
| 40 | |
| 41 | virtual void |
| 42 | Print (std::ostream &os) const = 0; |
| 43 | |
| 44 | virtual void |
| 45 | OutInterests (std::string context, |
| 46 | Ptr<const CcnxInterestHeader>, Ptr<CcnxApp>, Ptr<CcnxFace>) = 0; |
| 47 | |
| 48 | virtual void |
| 49 | InInterests (std::string context, |
| 50 | Ptr<const CcnxInterestHeader>, Ptr<CcnxApp>, Ptr<CcnxFace>) = 0; |
| 51 | |
| 52 | virtual void |
| 53 | InNacks (std::string context, |
| 54 | Ptr<const CcnxInterestHeader>, Ptr<CcnxApp>, Ptr<CcnxFace>) = 0; |
| 55 | |
| 56 | virtual void |
| 57 | OutData (std::string context, |
| 58 | Ptr<const CcnxContentObjectHeader>, Ptr<const Packet>, Ptr<CcnxApp>, Ptr<CcnxFace>) = 0; |
| 59 | |
| 60 | virtual void |
| 61 | InData (std::string context, |
| 62 | Ptr<const CcnxContentObjectHeader>, Ptr<const Packet>, Ptr<CcnxApp>, Ptr<CcnxFace>) = 0; |
| 63 | |
| 64 | protected: |
| 65 | std::string m_app; |
| 66 | std::string m_appId; |
| 67 | std::string m_node; |
| 68 | }; |
| 69 | |
| 70 | std::ostream& |
| 71 | operator << (std::ostream &os, const CcnxAppTracer &tracer) |
| 72 | { |
| 73 | os << "# "; |
| 74 | tracer.PrintHeader (os); |
| 75 | os << "\n"; |
| 76 | tracer.Print (os); |
| 77 | return os; |
| 78 | } |
| 79 | |
| 80 | class CcnxL3Tracer : public SimpleRefCount<CcnxL3Tracer> |
| 81 | { |
| 82 | public: |
| 83 | CcnxL3Tracer (const std::string &node = "*"); |
| 84 | virtual ~CcnxL3Tracer () { }; |
| 85 | |
| 86 | virtual void |
| 87 | PrintHeader (std::ostream &os) const = 0; |
| 88 | |
| 89 | virtual void |
| 90 | Print (std::ostream &os) const = 0; |
| 91 | |
| 92 | virtual void |
| 93 | OutInterests (std::string context, |
| 94 | Ptr<const CcnxInterestHeader>, Ptr<const CcnxFace>) = 0; |
| 95 | |
| 96 | virtual void |
| 97 | InInterests (std::string context, |
| 98 | Ptr<const CcnxInterestHeader>, Ptr<const CcnxFace>) = 0; |
| 99 | |
| 100 | virtual void |
| 101 | DropInterests (std::string context, |
| 102 | Ptr<const CcnxInterestHeader>, Ccnx::DropReason, Ptr<const CcnxFace>) = 0; |
| 103 | |
| 104 | virtual void |
| 105 | OutNacks (std::string context, |
| 106 | Ptr<const CcnxInterestHeader>, Ptr<const CcnxFace>) = 0; |
| 107 | |
| 108 | virtual void |
| 109 | InNacks (std::string context, |
| 110 | Ptr<const CcnxInterestHeader>, Ptr<const CcnxFace>) = 0; |
| 111 | |
| 112 | virtual void |
| 113 | DropNacks (std::string context, |
| 114 | Ptr<const CcnxInterestHeader>, Ccnx::DropReason, Ptr<const CcnxFace>) = 0; |
| 115 | |
| 116 | |
| 117 | virtual void |
| 118 | OutData (std::string context, |
| 119 | Ptr<const CcnxContentObjectHeader>, bool fromCache, Ptr<const CcnxFace>) = 0; |
| 120 | |
| 121 | virtual void |
| 122 | InData (std::string context, |
| 123 | Ptr<const CcnxContentObjectHeader>, Ptr<const CcnxFace>) = 0; |
| 124 | |
| 125 | virtual void |
| 126 | DropData (std::string context, |
| 127 | Ptr<const CcnxContentObjectHeader>, Ccnx::DropReason, Ptr<const CcnxFace>) = 0; |
| 128 | |
| 129 | protected: |
| 130 | std::string m_node; |
| 131 | }; |
| 132 | |
| 133 | std::ostream& |
| 134 | operator << (std::ostream &os, const CcnxL3Tracer &tracer) |
| 135 | { |
| 136 | os << "# "; |
| 137 | tracer.PrintHeader (os); |
| 138 | os << "\n"; |
| 139 | tracer.Print (os); |
| 140 | return os; |
| 141 | } |
| 142 | |
| 143 | //////////////////////////////////////////////////////////////////// |
| 144 | //////////////////////////////////////////////////////////////////// |
| 145 | //////////////////////////////////////////////////////////////////// |
| 146 | |
| 147 | class CcnxAggregateAppTracer : public CcnxAppTracer |
| 148 | { |
| 149 | public: |
| 150 | CcnxAggregateAppTracer (const std::string &app, const std::string &node = "*", const std::string &appId = "*"); |
| 151 | virtual ~CcnxAggregateAppTracer () { }; |
| 152 | |
| 153 | virtual void |
| 154 | PrintHeader (std::ostream &os) const; |
| 155 | |
| 156 | virtual void |
| 157 | Print (std::ostream &os) const; |
| 158 | |
| 159 | virtual void |
| 160 | OutInterests (std::string context, |
| 161 | Ptr<const CcnxInterestHeader>, Ptr<CcnxApp>, Ptr<CcnxFace>); |
| 162 | |
| 163 | virtual void |
| 164 | InInterests (std::string context, |
| 165 | Ptr<const CcnxInterestHeader>, Ptr<CcnxApp>, Ptr<CcnxFace>); |
| 166 | |
| 167 | virtual void |
| 168 | InNacks (std::string context, |
| 169 | Ptr<const CcnxInterestHeader>, Ptr<CcnxApp>, Ptr<CcnxFace>); |
| 170 | |
| 171 | virtual void |
| 172 | OutData (std::string context, |
| 173 | Ptr<const CcnxContentObjectHeader>, Ptr<const Packet>, Ptr<CcnxApp>, Ptr<CcnxFace>); |
| 174 | |
| 175 | virtual void |
| 176 | InData (std::string context, |
| 177 | Ptr<const CcnxContentObjectHeader>, Ptr<const Packet>, Ptr<CcnxApp>, Ptr<CcnxFace>); |
| 178 | |
| 179 | private: |
| 180 | uint64_t m_inInterests; |
| 181 | uint64_t m_outInterests; |
| 182 | uint64_t m_inNacks; |
| 183 | uint64_t m_inData; |
| 184 | uint64_t m_outData; |
| 185 | }; |
| 186 | |
| 187 | class CcnxAggregateL3Tracer : public CcnxL3Tracer |
| 188 | { |
| 189 | public: |
| 190 | CcnxAggregateL3Tracer (const std::string &node = "*"); |
| 191 | virtual ~CcnxAggregateL3Tracer () { }; |
| 192 | |
| 193 | virtual void |
| 194 | PrintHeader (std::ostream &os) const; |
| 195 | |
| 196 | virtual void |
| 197 | Print (std::ostream &os) const; |
| 198 | |
| 199 | virtual void |
| 200 | OutInterests (std::string context, |
| 201 | Ptr<const CcnxInterestHeader>, Ptr<const CcnxFace>); |
| 202 | |
| 203 | virtual void |
| 204 | InInterests (std::string context, |
| 205 | Ptr<const CcnxInterestHeader>, Ptr<const CcnxFace>); |
| 206 | |
| 207 | virtual void |
| 208 | DropInterests (std::string context, |
| 209 | Ptr<const CcnxInterestHeader>, Ccnx::DropReason, Ptr<const CcnxFace>); |
| 210 | |
| 211 | virtual void |
| 212 | OutNacks (std::string context, |
| 213 | Ptr<const CcnxInterestHeader>, Ptr<const CcnxFace>); |
| 214 | |
| 215 | virtual void |
| 216 | InNacks (std::string context, |
| 217 | Ptr<const CcnxInterestHeader>, Ptr<const CcnxFace>); |
| 218 | |
| 219 | virtual void |
| 220 | DropNacks (std::string context, |
| 221 | Ptr<const CcnxInterestHeader>, Ccnx::DropReason, Ptr<const CcnxFace>); |
| 222 | |
| 223 | virtual void |
| 224 | OutData (std::string context, |
| 225 | Ptr<const CcnxContentObjectHeader>, bool fromCache, Ptr<const CcnxFace>); |
| 226 | |
| 227 | virtual void |
| 228 | InData (std::string context, |
| 229 | Ptr<const CcnxContentObjectHeader>, Ptr<const CcnxFace>); |
| 230 | |
| 231 | virtual void |
| 232 | DropData (std::string context, |
| 233 | Ptr<const CcnxContentObjectHeader>, Ccnx::DropReason, Ptr<const CcnxFace>); |
| 234 | |
| 235 | private: |
| 236 | uint64_t m_inInterests; |
| 237 | uint64_t m_outInterests; |
| 238 | uint64_t m_dropInterests; |
| 239 | uint64_t m_inNacks; |
| 240 | uint64_t m_outNacks; |
| 241 | uint64_t m_dropNacks; |
| 242 | uint64_t m_inData; |
| 243 | uint64_t m_outData; |
| 244 | uint64_t m_dropData; |
| 245 | }; |
| 246 | |
| 247 | class CcnxTraceHelper |
| 248 | { |
| 249 | public: |
| 250 | /** |
| 251 | * @brief Destructor that invokes trace output procedures |
| 252 | */ |
| 253 | ~CcnxTraceHelper (); |
| 254 | |
| 255 | /** |
| 256 | * @brief Set filename to output app trace. |
| 257 | * |
| 258 | * By default, trace is output to NS_LOG_INFO stream |
| 259 | * |
| 260 | * @param file File where trace will be written to |
| 261 | */ |
| 262 | void |
| 263 | SetAppTraceFile (const std::string &appTrace = "apps.log"); |
| 264 | |
| 265 | /** |
| 266 | * @brief Set filename to output app trace. |
| 267 | * |
| 268 | * By default, trace is output to NS_LOG_INFO stream |
| 269 | * |
| 270 | * @param file File where trace will be written to |
| 271 | */ |
| 272 | void |
| 273 | SetL3TraceFile (const std::string &l3Trace = "l3.log"); |
| 274 | |
| 275 | /** |
| 276 | * @brief Enable aggregate app-level CCNx tracing on all CCNx applications (individual file per application) |
| 277 | * |
| 278 | * @param app Class name of the application of interest |
| 279 | */ |
| 280 | void |
| 281 | EnableAggregateAppAll (const std::string &app); |
| 282 | |
| 283 | /** |
| 284 | * @brief Enable aggregate network-level CCNx tracing on all CCNx nodes (individual file per node) |
| 285 | */ |
| 286 | void |
| 287 | EnableAggregateL3All (); |
| 288 | |
| 289 | private: |
| 290 | std::string m_appTrace; |
| 291 | std::list<Ptr<CcnxAggregateAppTracer> > m_apps; |
| 292 | |
| 293 | std::string m_l3Trace; |
| 294 | std::list<Ptr<CcnxAggregateL3Tracer> > m_l3s; |
| 295 | }; |
| 296 | |
| 297 | |
| 298 | } // namespace ns3 |
| 299 | |
| 300 | #endif /* CCNX_TRACE_HELPER_H */ |