Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2010 University of Washington |
| 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 | |
| 19 | #include <stdint.h> |
| 20 | #include <string> |
| 21 | #include <fstream> |
| 22 | |
| 23 | #include "ns3/abort.h" |
| 24 | #include "ns3/assert.h" |
| 25 | #include "ns3/log.h" |
| 26 | #include "ns3/ptr.h" |
| 27 | #include "ns3/node.h" |
| 28 | #include "ns3/names.h" |
| 29 | #include "ns3/net-device.h" |
| 30 | #include "ns3/pcap-file-wrapper.h" |
| 31 | |
| 32 | #include "ccnx-trace-helper.h" |
| 33 | |
| 34 | NS_LOG_COMPONENT_DEFINE ("CcnxTraceHelper"); |
| 35 | |
| 36 | namespace ns3 { |
| 37 | |
| 38 | void |
| 39 | PcapHelperForCcnx::EnablePcapCcnx (std::string prefix, Ptr<Ccnx> ccnx, uint32_t interface, bool explicitFilename) |
| 40 | { |
| 41 | EnablePcapCcnxInternal (prefix, ccnx, interface, explicitFilename); |
| 42 | } |
| 43 | |
| 44 | void |
| 45 | PcapHelperForCcnx::EnablePcapCcnx (std::string prefix, std::string ccnxName, uint32_t interface, bool explicitFilename) |
| 46 | { |
| 47 | Ptr<Ccnx> ccnx = Names::Find<Ccnx> (ccnxName); |
| 48 | EnablePcapCcnx (prefix, ccnx, interface, explicitFilename); |
| 49 | } |
| 50 | |
Alexander Afanasyev | eface60 | 2011-08-17 17:50:12 -0700 | [diff] [blame] | 51 | /// \todo This call is broken |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 52 | void |
| 53 | PcapHelperForCcnx::EnablePcapCcnx (std::string prefix, CcnxFaceContainer c) |
| 54 | { |
| 55 | for (CcnxFaceContainer::Iterator i = c.Begin (); i != c.End (); ++i) |
| 56 | { |
Alexander Afanasyev | eface60 | 2011-08-17 17:50:12 -0700 | [diff] [blame] | 57 | // EnablePcapCcnx (prefix, (*i)->GetCcnx (), 0,false); |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 58 | } |
| 59 | } |
| 60 | |
| 61 | void |
| 62 | PcapHelperForCcnx::EnablePcapCcnx (std::string prefix, NodeContainer n) |
| 63 | { |
| 64 | for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i) |
| 65 | { |
| 66 | Ptr<Node> node = *i; |
| 67 | Ptr<Ccnx> ccnx = node->GetObject<Ccnx> (); |
| 68 | if (ccnx) |
| 69 | { |
| 70 | for (uint32_t j = 0; j < ccnx->GetNFaces (); ++j) |
| 71 | { |
| 72 | EnablePcapCcnx (prefix, ccnx, j, false); |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | void |
| 79 | PcapHelperForCcnx::EnablePcapCcnxAll (std::string prefix) |
| 80 | { |
| 81 | EnablePcapCcnx (prefix, NodeContainer::GetGlobal ()); |
| 82 | } |
| 83 | |
| 84 | void |
| 85 | PcapHelperForCcnx::EnablePcapCcnx (std::string prefix, uint32_t nodeid, uint32_t interface, bool explicitFilename) |
| 86 | { |
| 87 | NodeContainer n = NodeContainer::GetGlobal (); |
| 88 | |
| 89 | for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i) |
| 90 | { |
| 91 | Ptr<Node> node = *i; |
| 92 | if (node->GetId () != nodeid) |
| 93 | { |
| 94 | continue; |
| 95 | } |
| 96 | |
| 97 | Ptr<Ccnx> ccnx = node->GetObject<Ccnx> (); |
| 98 | if (ccnx) |
| 99 | { |
| 100 | EnablePcapCcnx (prefix, ccnx, interface, explicitFilename); |
| 101 | } |
| 102 | return; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | // |
| 107 | // Public API |
| 108 | // |
| 109 | void |
| 110 | AsciiTraceHelperForCcnx::EnableAsciiCcnx (std::string prefix, Ptr<Ccnx> ccnx, uint32_t interface, bool explicitFilename) |
| 111 | { |
| 112 | EnableAsciiCcnxInternal (Ptr<OutputStreamWrapper> (), prefix, ccnx, interface, explicitFilename); |
| 113 | } |
| 114 | |
| 115 | // |
| 116 | // Public API |
| 117 | // |
| 118 | void |
| 119 | AsciiTraceHelperForCcnx::EnableAsciiCcnx (Ptr<OutputStreamWrapper> stream, Ptr<Ccnx> ccnx, uint32_t interface) |
| 120 | { |
| 121 | EnableAsciiCcnxInternal (stream, std::string (), ccnx, interface, false); |
| 122 | } |
| 123 | |
| 124 | // |
| 125 | // Public API |
| 126 | // |
| 127 | void |
| 128 | AsciiTraceHelperForCcnx::EnableAsciiCcnx ( |
| 129 | std::string prefix, |
| 130 | std::string ccnxName, |
| 131 | uint32_t interface, |
| 132 | bool explicitFilename) |
| 133 | { |
| 134 | EnableAsciiCcnxImpl (Ptr<OutputStreamWrapper> (), prefix, ccnxName, interface, explicitFilename); |
| 135 | } |
| 136 | |
| 137 | // |
| 138 | // Public API |
| 139 | // |
| 140 | void |
| 141 | AsciiTraceHelperForCcnx::EnableAsciiCcnx (Ptr<OutputStreamWrapper> stream, std::string ccnxName, uint32_t interface) |
| 142 | { |
| 143 | EnableAsciiCcnxImpl (stream, std::string (), ccnxName, interface, false); |
| 144 | } |
| 145 | |
| 146 | // |
| 147 | // Private API |
| 148 | // |
| 149 | void |
| 150 | AsciiTraceHelperForCcnx::EnableAsciiCcnxImpl ( |
| 151 | Ptr<OutputStreamWrapper> stream, |
| 152 | std::string prefix, |
| 153 | std::string ccnxName, |
| 154 | uint32_t interface, |
| 155 | bool explicitFilename) |
| 156 | { |
| 157 | Ptr<Ccnx> ccnx = Names::Find<Ccnx> (ccnxName); |
| 158 | EnableAsciiCcnxInternal (stream, prefix, ccnx, interface, explicitFilename); |
| 159 | } |
| 160 | |
| 161 | // |
| 162 | // Public API |
| 163 | // |
| 164 | void |
| 165 | AsciiTraceHelperForCcnx::EnableAsciiCcnx (std::string prefix, CcnxFaceContainer c) |
| 166 | { |
| 167 | EnableAsciiCcnxImpl (Ptr<OutputStreamWrapper> (), prefix, c); |
| 168 | } |
| 169 | |
| 170 | // |
| 171 | // Public API |
| 172 | // |
| 173 | void |
| 174 | AsciiTraceHelperForCcnx::EnableAsciiCcnx (Ptr<OutputStreamWrapper> stream, CcnxFaceContainer c) |
| 175 | { |
| 176 | EnableAsciiCcnxImpl (stream, std::string (), c); |
| 177 | } |
| 178 | |
| 179 | // |
| 180 | // Private API |
Alexander Afanasyev | eface60 | 2011-08-17 17:50:12 -0700 | [diff] [blame] | 181 | // \todo This method is broken |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 182 | void |
| 183 | AsciiTraceHelperForCcnx::EnableAsciiCcnxImpl (Ptr<OutputStreamWrapper> stream, std::string prefix, CcnxFaceContainer c) |
| 184 | { |
| 185 | for (CcnxFaceContainer::Iterator i = c.Begin (); i != c.End (); ++i) |
| 186 | { |
Alexander Afanasyev | eface60 | 2011-08-17 17:50:12 -0700 | [diff] [blame] | 187 | // EnableAsciiCcnxInternal (stream, prefix, pair.first, pair.second, false); |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 188 | } |
| 189 | } |
| 190 | |
| 191 | // |
| 192 | // Public API |
| 193 | // |
| 194 | void |
| 195 | AsciiTraceHelperForCcnx::EnableAsciiCcnx (std::string prefix, NodeContainer n) |
| 196 | { |
| 197 | EnableAsciiCcnxImpl (Ptr<OutputStreamWrapper> (), prefix, n); |
| 198 | } |
| 199 | |
| 200 | // |
| 201 | // Public API |
| 202 | // |
| 203 | void |
| 204 | AsciiTraceHelperForCcnx::EnableAsciiCcnx (Ptr<OutputStreamWrapper> stream, NodeContainer n) |
| 205 | { |
| 206 | EnableAsciiCcnxImpl (stream, std::string (), n); |
| 207 | } |
| 208 | |
| 209 | // |
| 210 | // Private API |
| 211 | // |
| 212 | void |
| 213 | AsciiTraceHelperForCcnx::EnableAsciiCcnxImpl (Ptr<OutputStreamWrapper> stream, std::string prefix, NodeContainer n) |
| 214 | { |
| 215 | for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i) |
| 216 | { |
| 217 | Ptr<Node> node = *i; |
| 218 | Ptr<Ccnx> ccnx = node->GetObject<Ccnx> (); |
| 219 | if (ccnx) |
| 220 | { |
| 221 | for (uint32_t j = 0; j < ccnx->GetNFaces (); ++j) |
| 222 | { |
| 223 | EnableAsciiCcnxInternal (stream, prefix, ccnx, j, false); |
| 224 | } |
| 225 | } |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | // |
| 230 | // Public API |
| 231 | // |
| 232 | void |
| 233 | AsciiTraceHelperForCcnx::EnableAsciiCcnxAll (std::string prefix) |
| 234 | { |
| 235 | EnableAsciiCcnxImpl (Ptr<OutputStreamWrapper> (), prefix, NodeContainer::GetGlobal ()); |
| 236 | } |
| 237 | |
| 238 | // |
| 239 | // Public API |
| 240 | // |
| 241 | void |
| 242 | AsciiTraceHelperForCcnx::EnableAsciiCcnxAll (Ptr<OutputStreamWrapper> stream) |
| 243 | { |
| 244 | EnableAsciiCcnxImpl (stream, std::string (), NodeContainer::GetGlobal ()); |
| 245 | } |
| 246 | |
| 247 | // |
| 248 | // Public API |
| 249 | // |
| 250 | void |
| 251 | AsciiTraceHelperForCcnx::EnableAsciiCcnx ( |
| 252 | Ptr<OutputStreamWrapper> stream, |
| 253 | uint32_t nodeid, |
| 254 | uint32_t interface, |
| 255 | bool explicitFilename) |
| 256 | { |
| 257 | EnableAsciiCcnxImpl (stream, std::string (), nodeid, interface, explicitFilename); |
| 258 | } |
| 259 | |
| 260 | // |
| 261 | // Public API |
| 262 | // |
| 263 | void |
| 264 | AsciiTraceHelperForCcnx::EnableAsciiCcnx (std::string prefix, uint32_t nodeid, uint32_t interface, bool explicitFilename) |
| 265 | { |
| 266 | EnableAsciiCcnxImpl (Ptr<OutputStreamWrapper> (), prefix, nodeid, interface, explicitFilename); |
| 267 | } |
| 268 | |
| 269 | // |
| 270 | // Private API |
| 271 | // |
| 272 | void |
| 273 | AsciiTraceHelperForCcnx::EnableAsciiCcnxImpl ( |
| 274 | Ptr<OutputStreamWrapper> stream, |
| 275 | std::string prefix, |
| 276 | uint32_t nodeid, |
| 277 | uint32_t interface, |
| 278 | bool explicitFilename) |
| 279 | { |
| 280 | NodeContainer n = NodeContainer::GetGlobal (); |
| 281 | |
| 282 | for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i) |
| 283 | { |
| 284 | Ptr<Node> node = *i; |
| 285 | if (node->GetId () != nodeid) |
| 286 | { |
| 287 | continue; |
| 288 | } |
| 289 | |
| 290 | Ptr<Ccnx> ccnx = node->GetObject<Ccnx> (); |
| 291 | if (ccnx) |
| 292 | { |
| 293 | EnableAsciiCcnxInternal (stream, prefix, ccnx, interface, explicitFilename); |
| 294 | } |
| 295 | |
| 296 | return; |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | |
| 301 | } // namespace ns3 |
| 302 | |