OLD | NEW |
(Empty) | |
| 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-object.h" |
| 31 |
| 32 #include "trace-helper.h" |
| 33 |
| 34 NS_LOG_COMPONENT_DEFINE("TraceHelper"); |
| 35 |
| 36 namespace ns3 { |
| 37 |
| 38 PcapHelper::PcapHelper () |
| 39 { |
| 40 NS_LOG_FUNCTION_NOARGS (); |
| 41 } |
| 42 |
| 43 PcapHelper::~PcapHelper () |
| 44 { |
| 45 NS_LOG_FUNCTION_NOARGS (); |
| 46 } |
| 47 |
| 48 Ptr<PcapFileObject> |
| 49 PcapHelper::CreateFile ( |
| 50 std::string filename,· |
| 51 std::string filemode,·· |
| 52 uint32_t dataLinkType,· |
| 53 uint32_t snapLen,· |
| 54 int32_t tzCorrection) |
| 55 { |
| 56 NS_LOG_FUNCTION (filename << filemode << dataLinkType << snapLen << tzCorrecti
on); |
| 57 |
| 58 Ptr<PcapFileObject> file = CreateObject<PcapFileObject> (); |
| 59 bool err = file->Open (filename, filemode); |
| 60 NS_ABORT_MSG_IF (err, "Unable to Open " << filename << " for mode " << filemod
e); |
| 61 |
| 62 err = file->Init (dataLinkType, snapLen, tzCorrection); |
| 63 NS_ABORT_MSG_IF (err, "Unable to Init " << filename); |
| 64 |
| 65 // |
| 66 // Note that the pcap helper promptly forgets all about the pcap file. We |
| 67 // rely on the reference count of the file object which will soon be owned |
| 68 // by the caller to keep the object alive. If the caller uses the file· |
| 69 // object to hook a trace source, ownership of the file object will be |
| 70 // implicitly transferred to the callback which keeps the object alive. |
| 71 // When the callback is destroyed (when either the trace is disconnected or |
| 72 // the object with the trace source is deleted) the callback will be destroyed |
| 73 // and the file object will be destroyed, releasing the pointer and closing |
| 74 // the file. |
| 75 // |
| 76 return file; |
| 77 } |
| 78 |
| 79 std::string |
| 80 PcapHelper::GetFilenameFromDevice (std::string prefix, Ptr<NetDevice> device, bo
ol useObjectNames) |
| 81 { |
| 82 NS_LOG_FUNCTION (prefix << device << useObjectNames); |
| 83 NS_ABORT_MSG_UNLESS (prefix.size (), "Empty prefix string"); |
| 84 |
| 85 std::ostringstream oss; |
| 86 oss << prefix << "-"; |
| 87 |
| 88 std::string nodename; |
| 89 std::string devicename; |
| 90 |
| 91 Ptr<Node> node = device->GetNode (); |
| 92 |
| 93 if (useObjectNames) |
| 94 { |
| 95 nodename = Names::FindName (node); |
| 96 devicename = Names::FindName (device); |
| 97 } |
| 98 |
| 99 if (nodename.size ()) |
| 100 { |
| 101 oss << nodename; |
| 102 } |
| 103 else |
| 104 { |
| 105 oss << node->GetId (); |
| 106 } |
| 107 |
| 108 oss << "-"; |
| 109 |
| 110 if (devicename.size ()) |
| 111 { |
| 112 oss << devicename; |
| 113 } |
| 114 else |
| 115 { |
| 116 oss << device->GetIfIndex (); |
| 117 } |
| 118 |
| 119 oss << ".pcap"; |
| 120 |
| 121 return oss.str (); |
| 122 } |
| 123 |
| 124 std::string |
| 125 PcapHelper::GetFilenameFromInterfacePair (std::string prefix, Ptr<Object> object
, uint32_t interface, bool useObjectNames) |
| 126 { |
| 127 NS_LOG_FUNCTION (prefix << object << interface << useObjectNames); |
| 128 NS_ABORT_MSG_UNLESS (prefix.size (), "Empty prefix string"); |
| 129 |
| 130 std::ostringstream oss; |
| 131 oss << prefix << "-"; |
| 132 |
| 133 std::string objname; |
| 134 std::string nodename; |
| 135 |
| 136 Ptr<Node> node = object->GetObject<Node> (); |
| 137 |
| 138 if (useObjectNames) |
| 139 { |
| 140 objname = Names::FindName (object); |
| 141 nodename = Names::FindName (node); |
| 142 } |
| 143 |
| 144 if (objname.size ()) |
| 145 { |
| 146 oss << objname; |
| 147 } |
| 148 else if (nodename.size ()) |
| 149 { |
| 150 oss << nodename; |
| 151 } |
| 152 else |
| 153 { |
| 154 oss << "n" << node->GetId (); |
| 155 } |
| 156 |
| 157 oss << "-i" << interface << ".pcap"; |
| 158 |
| 159 return oss.str (); |
| 160 } |
| 161 |
| 162 // |
| 163 // The basic default trace sink. This one just writes the packet to the pcap |
| 164 // file which is good enough for most kinds of captures. |
| 165 // |
| 166 void |
| 167 PcapHelper::DefaultSink (Ptr<PcapFileObject> file, Ptr<const Packet> p) |
| 168 { |
| 169 NS_LOG_FUNCTION (file << p); |
| 170 file->Write(Simulator::Now(), p); |
| 171 } |
| 172 |
| 173 AsciiTraceHelper::AsciiTraceHelper () |
| 174 { |
| 175 NS_LOG_FUNCTION_NOARGS (); |
| 176 } |
| 177 |
| 178 AsciiTraceHelper::~AsciiTraceHelper () |
| 179 { |
| 180 NS_LOG_FUNCTION_NOARGS (); |
| 181 } |
| 182 |
| 183 Ptr<OutputStreamObject> |
| 184 AsciiTraceHelper::CreateFileStream (std::string filename, std::string filemode) |
| 185 { |
| 186 NS_LOG_FUNCTION (filename << filemode); |
| 187 |
| 188 std::ofstream *ofstream = new std::ofstream; |
| 189 std::ios_base::openmode mode; |
| 190 |
| 191 if (filemode == "a") |
| 192 { |
| 193 mode = std::ios_base::out | std::ios_base::app; |
| 194 } |
| 195 else if (filemode == "w") |
| 196 { |
| 197 mode = std::ios_base::out | std::ios_base::trunc; |
| 198 } |
| 199 else |
| 200 { |
| 201 NS_ABORT_MSG ("AsciiTraceHelper::CreateFileStream(): Unexpected file mode"
); |
| 202 } |
| 203 |
| 204 ofstream->open (filename.c_str (), mode); |
| 205 NS_ABORT_MSG_UNLESS (ofstream->is_open (), "AsciiTraceHelper::CreateFileStream
(): Unable to Open " <<· |
| 206 filename << " for mode " << filemode); |
| 207 ·· |
| 208 Ptr<OutputStreamObject> streamObject = CreateObject<OutputStreamObject> (); |
| 209 streamObject->SetStream (ofstream); |
| 210 |
| 211 // |
| 212 // Note that the ascii trace helper promptly forgets all about the trace file. |
| 213 // We rely on the reference count of the file object which will soon be owned |
| 214 // by the caller to keep the object alive. If the caller uses the stream· |
| 215 // object to hook a trace source, ownership of the stream object will be |
| 216 // implicitly transferred to the callback which keeps the object alive. |
| 217 // When the callback is destroyed (when either the trace is disconnected or |
| 218 // the object with the trace source is deleted) the callback will be destroyed |
| 219 // and the stream object will be destroyed, releasing the pointer and closing |
| 220 // the underlying file. |
| 221 // |
| 222 return streamObject; |
| 223 } |
| 224 |
| 225 std::string |
| 226 AsciiTraceHelper::GetFilenameFromDevice (std::string prefix, Ptr<NetDevice> devi
ce, bool useObjectNames) |
| 227 { |
| 228 NS_LOG_FUNCTION (prefix << device << useObjectNames); |
| 229 NS_ABORT_MSG_UNLESS (prefix.size (), "Empty prefix string"); |
| 230 |
| 231 std::ostringstream oss; |
| 232 oss << prefix << "-"; |
| 233 |
| 234 std::string nodename; |
| 235 std::string devicename; |
| 236 |
| 237 Ptr<Node> node = device->GetNode (); |
| 238 |
| 239 if (useObjectNames) |
| 240 { |
| 241 nodename = Names::FindName (node); |
| 242 devicename = Names::FindName (device); |
| 243 } |
| 244 |
| 245 if (nodename.size ()) |
| 246 { |
| 247 oss << nodename; |
| 248 } |
| 249 else |
| 250 { |
| 251 oss << node->GetId (); |
| 252 } |
| 253 |
| 254 oss << "-"; |
| 255 |
| 256 if (devicename.size ()) |
| 257 { |
| 258 oss << devicename; |
| 259 } |
| 260 else |
| 261 { |
| 262 oss << device->GetIfIndex (); |
| 263 } |
| 264 |
| 265 oss << ".tr"; |
| 266 |
| 267 return oss.str (); |
| 268 } |
| 269 |
| 270 std::string |
| 271 AsciiTraceHelper::GetFilenameFromInterfacePair ( |
| 272 std::string prefix,· |
| 273 Ptr<Object> object,· |
| 274 uint32_t interface,· |
| 275 bool useObjectNames) |
| 276 { |
| 277 NS_LOG_FUNCTION (prefix << object << interface << useObjectNames); |
| 278 NS_ABORT_MSG_UNLESS (prefix.size (), "Empty prefix string"); |
| 279 |
| 280 std::ostringstream oss; |
| 281 oss << prefix << "-"; |
| 282 |
| 283 std::string objname; |
| 284 std::string nodename; |
| 285 |
| 286 Ptr<Node> node = object->GetObject<Node> (); |
| 287 |
| 288 if (useObjectNames) |
| 289 { |
| 290 objname = Names::FindName (object); |
| 291 nodename = Names::FindName (node); |
| 292 } |
| 293 |
| 294 if (objname.size ()) |
| 295 { |
| 296 oss << objname; |
| 297 } |
| 298 else if (nodename.size ()) |
| 299 { |
| 300 oss << nodename; |
| 301 } |
| 302 else |
| 303 { |
| 304 oss << "n" << node->GetId (); |
| 305 } |
| 306 |
| 307 oss << "-i" << interface << ".tr"; |
| 308 |
| 309 return oss.str (); |
| 310 } |
| 311 |
| 312 // |
| 313 // One of the basic default trace sink sets. Enqueue: |
| 314 // |
| 315 // When a packet has been sent to a device for transmission, the device is |
| 316 // expected to place the packet onto a transmit queue even if it does not |
| 317 // have to delay the packet at all, if only to trigger this event. This· |
| 318 // event will eventually translate into a '+' operation in the trace file. |
| 319 // |
| 320 // This is typically implemented by hooking the "TxQueue/Enqueue" trace hook |
| 321 // in the device (actually the Queue in the device). |
| 322 // |
| 323 void |
| 324 AsciiTraceHelper::DefaultEnqueueSinkWithoutContext (Ptr<OutputStreamObject> stre
am, Ptr<const Packet> p) |
| 325 { |
| 326 NS_LOG_FUNCTION (stream << p); |
| 327 *stream->GetStream () << "+ " << Simulator::Now ().GetSeconds () << " " << *p
<< std::endl; |
| 328 } |
| 329 |
| 330 void |
| 331 AsciiTraceHelper::DefaultEnqueueSinkWithContext (Ptr<OutputStreamObject> stream,
std::string context, Ptr<const Packet> p) |
| 332 { |
| 333 NS_LOG_FUNCTION (stream << p); |
| 334 *stream->GetStream () << "+ " << Simulator::Now ().GetSeconds () << " " << con
text << " " << *p << std::endl; |
| 335 } |
| 336 |
| 337 // |
| 338 // One of the basic default trace sink sets. Drop: |
| 339 // |
| 340 // When a packet has been sent to a device for transmission, the device is |
| 341 // expected to place the packet onto a transmit queue. If this queue is· |
| 342 // full the packet will be dropped. The device is expected to trigger an |
| 343 // event to indicate that an outbound packet is being dropped. This event |
| 344 // will eventually translate into a 'd' operation in the trace file. |
| 345 // |
| 346 // This is typically implemented by hooking the "TxQueue/Drop" trace hook |
| 347 // in the device (actually the Queue in the device). |
| 348 // |
| 349 void |
| 350 AsciiTraceHelper::DefaultDropSinkWithoutContext (Ptr<OutputStreamObject> stream,
Ptr<const Packet> p) |
| 351 { |
| 352 NS_LOG_FUNCTION (stream << p); |
| 353 *stream->GetStream () << "d " << Simulator::Now ().GetSeconds () << " " << *p
<< std::endl; |
| 354 } |
| 355 |
| 356 void |
| 357 AsciiTraceHelper::DefaultDropSinkWithContext (Ptr<OutputStreamObject> stream, st
d::string context, Ptr<const Packet> p) |
| 358 { |
| 359 NS_LOG_FUNCTION (stream << p); |
| 360 *stream->GetStream () << "d " << Simulator::Now ().GetSeconds () << " " << con
text << " " << *p << std::endl; |
| 361 } |
| 362 |
| 363 // |
| 364 // One of the basic default trace sink sets. Dequeue: |
| 365 // |
| 366 // When a packet has been sent to a device for transmission, the device is |
| 367 // expected to place the packet onto a transmit queue even if it does not |
| 368 // have to delay the packet at all. The device removes the packet from the |
| 369 // transmit queue when the packet is ready to send, and this dequeue will· |
| 370 // fire a corresponding event. This event will eventually translate into a· |
| 371 // '-' operation in the trace file. |
| 372 // |
| 373 // This is typically implemented by hooking the "TxQueue/Dequeue" trace hook |
| 374 // in the device (actually the Queue in the device). |
| 375 // |
| 376 void |
| 377 AsciiTraceHelper::DefaultDequeueSinkWithoutContext (Ptr<OutputStreamObject> stre
am, Ptr<const Packet> p) |
| 378 { |
| 379 NS_LOG_FUNCTION (stream << p); |
| 380 *stream->GetStream () << "- " << Simulator::Now ().GetSeconds () << " " << *p
<< std::endl; |
| 381 } |
| 382 |
| 383 void |
| 384 AsciiTraceHelper::DefaultDequeueSinkWithContext (Ptr<OutputStreamObject> stream,
std::string context, Ptr<const Packet> p) |
| 385 { |
| 386 NS_LOG_FUNCTION (stream << p); |
| 387 *stream->GetStream () << "- " << Simulator::Now ().GetSeconds () << " " << con
text << " " << *p << std::endl; |
| 388 } |
| 389 |
| 390 // |
| 391 // One of the basic default trace sink sets. Receive: |
| 392 // |
| 393 // When a packet is received by a device for transmission, the device is |
| 394 // expected to trigger this event to indicate the reception has occurred. |
| 395 // This event will eventually translate into an 'r' operation in the trace· |
| 396 // file. |
| 397 // |
| 398 // This is typically implemented by hooking the "MacRx" trace hook in the |
| 399 // device. |
| 400 void |
| 401 AsciiTraceHelper::DefaultReceiveSinkWithoutContext (Ptr<OutputStreamObject> stre
am, Ptr<const Packet> p) |
| 402 { |
| 403 NS_LOG_FUNCTION (stream << p); |
| 404 *stream->GetStream () << "r " << Simulator::Now ().GetSeconds () << " " << *p
<< std::endl; |
| 405 } |
| 406 |
| 407 void |
| 408 AsciiTraceHelper::DefaultReceiveSinkWithContext (Ptr<OutputStreamObject> stream,
std::string context, Ptr<const Packet> p) |
| 409 { |
| 410 NS_LOG_FUNCTION (stream << p); |
| 411 *stream->GetStream () << "r " << Simulator::Now ().GetSeconds () << " " << con
text << " " << *p << std::endl; |
| 412 } |
| 413 |
| 414 void· |
| 415 PcapHelperForDevice::EnablePcap (std::string prefix, Ptr<NetDevice> nd, bool pro
miscuous) |
| 416 { |
| 417 EnablePcapInternal (prefix, nd, promiscuous); |
| 418 } |
| 419 |
| 420 void· |
| 421 PcapHelperForDevice::EnablePcap (std::string prefix, std::string ndName, bool pr
omiscuous) |
| 422 { |
| 423 Ptr<NetDevice> nd = Names::Find<NetDevice> (ndName); |
| 424 EnablePcap (prefix, nd, promiscuous); |
| 425 } |
| 426 |
| 427 void· |
| 428 PcapHelperForDevice::EnablePcap (std::string prefix, NetDeviceContainer d, bool
promiscuous) |
| 429 { |
| 430 for (NetDeviceContainer::Iterator i = d.Begin (); i != d.End (); ++i) |
| 431 { |
| 432 Ptr<NetDevice> dev = *i; |
| 433 EnablePcap (prefix, dev, promiscuous); |
| 434 } |
| 435 } |
| 436 |
| 437 void |
| 438 PcapHelperForDevice::EnablePcap (std::string prefix, NodeContainer n, bool promi
scuous) |
| 439 { |
| 440 NetDeviceContainer devs; |
| 441 for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i) |
| 442 { |
| 443 Ptr<Node> node = *i; |
| 444 for (uint32_t j = 0; j < node->GetNDevices (); ++j) |
| 445 { |
| 446 devs.Add (node->GetDevice (j)); |
| 447 } |
| 448 } |
| 449 EnablePcap (prefix, devs, promiscuous); |
| 450 } |
| 451 |
| 452 void |
| 453 PcapHelperForDevice::EnablePcapAll (std::string prefix, bool promiscuous) |
| 454 { |
| 455 EnablePcap (prefix, NodeContainer::GetGlobal (), promiscuous); |
| 456 } |
| 457 |
| 458 void· |
| 459 PcapHelperForDevice::EnablePcap (std::string prefix, uint32_t nodeid, uint32_t d
eviceid, bool promiscuous) |
| 460 { |
| 461 NodeContainer n = NodeContainer::GetGlobal (); |
| 462 |
| 463 for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i) |
| 464 { |
| 465 Ptr<Node> node = *i; |
| 466 if (node->GetId () != nodeid)· |
| 467 { |
| 468 continue; |
| 469 } |
| 470 ······ |
| 471 NS_ABORT_MSG_IF (deviceid >= node->GetNDevices (), "PcapHelperForDevice::E
nablePcap(): Unknown deviceid = "· |
| 472 << deviceid); |
| 473 Ptr<NetDevice> nd = node->GetDevice (deviceid); |
| 474 EnablePcap (prefix, nd, promiscuous); |
| 475 return; |
| 476 } |
| 477 } |
| 478 |
| 479 // |
| 480 // Public API |
| 481 // |
| 482 void· |
| 483 TraceHelperForDevice::EnableAscii (std::string prefix, Ptr<NetDevice> nd) |
| 484 { |
| 485 EnableAsciiInternal (Ptr<OutputStreamObject> (), prefix, nd); |
| 486 } |
| 487 |
| 488 // |
| 489 // Public API |
| 490 // |
| 491 void· |
| 492 TraceHelperForDevice::EnableAscii (Ptr<OutputStreamObject> stream, Ptr<NetDevice
> nd) |
| 493 { |
| 494 EnableAsciiInternal (stream, std::string (), nd); |
| 495 } |
| 496 |
| 497 // |
| 498 // Public API |
| 499 // |
| 500 void· |
| 501 TraceHelperForDevice::EnableAscii (std::string prefix, std::string ndName) |
| 502 { |
| 503 EnableAsciiImpl (Ptr<OutputStreamObject> (), prefix, ndName); |
| 504 } |
| 505 |
| 506 // |
| 507 // Public API |
| 508 // |
| 509 void· |
| 510 TraceHelperForDevice::EnableAscii (Ptr<OutputStreamObject> stream, std::string n
dName) |
| 511 { |
| 512 EnableAsciiImpl (stream, std::string (), ndName); |
| 513 } |
| 514 |
| 515 // |
| 516 // Private API |
| 517 // |
| 518 void· |
| 519 TraceHelperForDevice::EnableAsciiImpl (Ptr<OutputStreamObject> stream, std::stri
ng prefix, std::string ndName) |
| 520 { |
| 521 Ptr<NetDevice> nd = Names::Find<NetDevice> (ndName); |
| 522 EnableAsciiInternal (stream, prefix, nd); |
| 523 } |
| 524 |
| 525 // |
| 526 // Public API |
| 527 // |
| 528 void· |
| 529 TraceHelperForDevice::EnableAscii (std::string prefix, NetDeviceContainer d) |
| 530 { |
| 531 EnableAsciiImpl (Ptr<OutputStreamObject> (), prefix, d); |
| 532 } |
| 533 |
| 534 // |
| 535 // Public API |
| 536 // |
| 537 void· |
| 538 TraceHelperForDevice::EnableAscii (Ptr<OutputStreamObject> stream, NetDeviceCont
ainer d) |
| 539 { |
| 540 EnableAsciiImpl (stream, std::string (), d); |
| 541 } |
| 542 |
| 543 // |
| 544 // Private API |
| 545 // |
| 546 void· |
| 547 TraceHelperForDevice::EnableAsciiImpl (Ptr<OutputStreamObject> stream, std::stri
ng prefix, NetDeviceContainer d) |
| 548 { |
| 549 for (NetDeviceContainer::Iterator i = d.Begin (); i != d.End (); ++i) |
| 550 { |
| 551 Ptr<NetDevice> dev = *i; |
| 552 EnableAsciiInternal (stream, prefix, dev); |
| 553 } |
| 554 } |
| 555 |
| 556 // |
| 557 // Public API |
| 558 // |
| 559 void |
| 560 TraceHelperForDevice::EnableAscii (std::string prefix, NodeContainer n) |
| 561 { |
| 562 EnableAsciiImpl (Ptr<OutputStreamObject> (), prefix, n); |
| 563 } |
| 564 |
| 565 // |
| 566 // Public API |
| 567 // |
| 568 void |
| 569 TraceHelperForDevice::EnableAscii (Ptr<OutputStreamObject> stream, NodeContainer
n) |
| 570 { |
| 571 EnableAsciiImpl (stream, std::string (), n); |
| 572 } |
| 573 |
| 574 // |
| 575 // Private API |
| 576 // |
| 577 void |
| 578 TraceHelperForDevice::EnableAsciiImpl (Ptr<OutputStreamObject> stream, std::stri
ng prefix, NodeContainer n) |
| 579 { |
| 580 NetDeviceContainer devs; |
| 581 for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i) |
| 582 { |
| 583 Ptr<Node> node = *i; |
| 584 for (uint32_t j = 0; j < node->GetNDevices (); ++j) |
| 585 { |
| 586 devs.Add (node->GetDevice (j)); |
| 587 } |
| 588 } |
| 589 EnableAsciiImpl (stream, prefix, devs); |
| 590 } |
| 591 |
| 592 // |
| 593 // Public API |
| 594 // |
| 595 void |
| 596 TraceHelperForDevice::EnableAsciiAll (std::string prefix) |
| 597 { |
| 598 EnableAsciiImpl (Ptr<OutputStreamObject> (), prefix, NodeContainer::GetGlobal
()); |
| 599 } |
| 600 |
| 601 // |
| 602 // Public API |
| 603 // |
| 604 void |
| 605 TraceHelperForDevice::EnableAsciiAll (Ptr<OutputStreamObject> stream) |
| 606 { |
| 607 EnableAsciiImpl (stream, std::string (), NodeContainer::GetGlobal ()); |
| 608 } |
| 609 |
| 610 // |
| 611 // Public API |
| 612 // |
| 613 void· |
| 614 TraceHelperForDevice::EnableAscii (Ptr<OutputStreamObject> stream, uint32_t node
id, uint32_t deviceid) |
| 615 { |
| 616 EnableAsciiImpl (stream, std::string (), nodeid, deviceid); |
| 617 } |
| 618 |
| 619 // |
| 620 // Public API |
| 621 // |
| 622 void· |
| 623 TraceHelperForDevice::EnableAscii (std::string prefix, uint32_t nodeid, uint32_t
deviceid) |
| 624 { |
| 625 EnableAsciiImpl (Ptr<OutputStreamObject> (), prefix, nodeid, deviceid); |
| 626 } |
| 627 |
| 628 // |
| 629 // Private API |
| 630 // |
| 631 void· |
| 632 TraceHelperForDevice::EnableAsciiImpl ( |
| 633 Ptr<OutputStreamObject> stream,· |
| 634 std::string prefix,· |
| 635 uint32_t nodeid,· |
| 636 uint32_t deviceid) |
| 637 { |
| 638 NodeContainer n = NodeContainer::GetGlobal (); |
| 639 |
| 640 for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i) |
| 641 { |
| 642 Ptr<Node> node = *i; |
| 643 if (node->GetId () != nodeid)· |
| 644 { |
| 645 continue; |
| 646 } |
| 647 ······ |
| 648 NS_ABORT_MSG_IF (deviceid >= node->GetNDevices (),· |
| 649 "TraceHelperForDevice::EnableAscii(): Unknown deviceid =
" << deviceid); |
| 650 |
| 651 Ptr<NetDevice> nd = node->GetDevice (deviceid); |
| 652 |
| 653 EnableAsciiInternal (stream, prefix, nd); |
| 654 return; |
| 655 } |
| 656 } |
| 657 |
| 658 void· |
| 659 PcapHelperForIpv4::EnablePcapIpv4 (std::string prefix, Ptr<Ipv4> ipv4, uint32_t
interface) |
| 660 { |
| 661 EnablePcapIpv4Internal (prefix, ipv4, interface); |
| 662 } |
| 663 |
| 664 void· |
| 665 PcapHelperForIpv4::EnablePcapIpv4 (std::string prefix, std::string ipv4Name, uin
t32_t interface) |
| 666 { |
| 667 Ptr<Ipv4> ipv4 = Names::Find<Ipv4> (ipv4Name); |
| 668 EnablePcapIpv4 (prefix, ipv4, interface); |
| 669 } |
| 670 |
| 671 void· |
| 672 PcapHelperForIpv4::EnablePcapIpv4 (std::string prefix, Ipv4InterfaceContainer c) |
| 673 { |
| 674 for (Ipv4InterfaceContainer::Iterator i = c.Begin (); i != c.End (); ++i) |
| 675 { |
| 676 std::pair<Ptr<Ipv4>, uint32_t> pair = *i; |
| 677 EnablePcapIpv4 (prefix, pair.first, pair.second); |
| 678 } |
| 679 } |
| 680 |
| 681 void |
| 682 PcapHelperForIpv4::EnablePcapIpv4 (std::string prefix, NodeContainer n) |
| 683 { |
| 684 for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i) |
| 685 { |
| 686 Ptr<Node> node = *i; |
| 687 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); |
| 688 if (ipv4) |
| 689 { |
| 690 for (uint32_t j = 0; j < ipv4->GetNInterfaces (); ++j) |
| 691 { |
| 692 EnablePcapIpv4 (prefix, ipv4, j); |
| 693 } |
| 694 } |
| 695 } |
| 696 } |
| 697 |
| 698 void |
| 699 PcapHelperForIpv4::EnablePcapIpv4All (std::string prefix) |
| 700 { |
| 701 EnablePcapIpv4 (prefix, NodeContainer::GetGlobal ()); |
| 702 } |
| 703 |
| 704 void· |
| 705 PcapHelperForIpv4::EnablePcapIpv4 (std::string prefix, uint32_t nodeid, uint32_t
interface) |
| 706 { |
| 707 NodeContainer n = NodeContainer::GetGlobal (); |
| 708 |
| 709 for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i) |
| 710 { |
| 711 Ptr<Node> node = *i; |
| 712 if (node->GetId () != nodeid)· |
| 713 { |
| 714 continue; |
| 715 } |
| 716 ······ |
| 717 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); |
| 718 if (ipv4) |
| 719 { |
| 720 EnablePcapIpv4 (prefix, ipv4, interface); |
| 721 } |
| 722 return; |
| 723 } |
| 724 } |
| 725 |
| 726 // |
| 727 // Public API |
| 728 // |
| 729 void· |
| 730 PcapAndAsciiHelperForIpv4::EnableAsciiIpv4 (std::string prefix, Ptr<Ipv4> ipv4,
uint32_t interface) |
| 731 { |
| 732 EnableAsciiIpv4Internal (Ptr<OutputStreamObject> (), prefix, ipv4, interface); |
| 733 } |
| 734 |
| 735 // |
| 736 // Public API |
| 737 // |
| 738 void· |
| 739 PcapAndAsciiHelperForIpv4::EnableAsciiIpv4 (Ptr<OutputStreamObject> stream, Ptr<
Ipv4> ipv4, uint32_t interface) |
| 740 { |
| 741 EnableAsciiIpv4Internal (stream, std::string (), ipv4, interface); |
| 742 } |
| 743 |
| 744 // |
| 745 // Public API |
| 746 // |
| 747 void· |
| 748 PcapAndAsciiHelperForIpv4::EnableAsciiIpv4 (std::string prefix, std::string ipv4
Name, uint32_t interface) |
| 749 { |
| 750 EnableAsciiIpv4Impl (Ptr<OutputStreamObject> (), prefix, ipv4Name, interface); |
| 751 } |
| 752 |
| 753 // |
| 754 // Public API |
| 755 // |
| 756 void· |
| 757 PcapAndAsciiHelperForIpv4::EnableAsciiIpv4 (Ptr<OutputStreamObject> stream, std:
:string ipv4Name, uint32_t interface) |
| 758 { |
| 759 EnableAsciiIpv4Impl (stream, std::string (), ipv4Name, interface); |
| 760 } |
| 761 |
| 762 // |
| 763 // Private API |
| 764 // |
| 765 void· |
| 766 PcapAndAsciiHelperForIpv4::EnableAsciiIpv4Impl ( |
| 767 Ptr<OutputStreamObject> stream,· |
| 768 std::string prefix,· |
| 769 std::string ipv4Name,· |
| 770 uint32_t interface) |
| 771 { |
| 772 Ptr<Ipv4> ipv4 = Names::Find<Ipv4> (ipv4Name); |
| 773 EnableAsciiIpv4Internal (stream, prefix, ipv4, interface); |
| 774 } |
| 775 |
| 776 // |
| 777 // Public API |
| 778 // |
| 779 void· |
| 780 PcapAndAsciiHelperForIpv4::EnableAsciiIpv4 (std::string prefix, Ipv4InterfaceCon
tainer c) |
| 781 { |
| 782 EnableAsciiIpv4Impl (Ptr<OutputStreamObject> (), prefix, c); |
| 783 } |
| 784 |
| 785 // |
| 786 // Public API |
| 787 // |
| 788 void· |
| 789 PcapAndAsciiHelperForIpv4::EnableAsciiIpv4 (Ptr<OutputStreamObject> stream, Ipv4
InterfaceContainer c) |
| 790 { |
| 791 EnableAsciiIpv4Impl (stream, std::string (), c); |
| 792 } |
| 793 |
| 794 // |
| 795 // Private API |
| 796 // |
| 797 void· |
| 798 PcapAndAsciiHelperForIpv4::EnableAsciiIpv4Impl (Ptr<OutputStreamObject> stream,
std::string prefix, Ipv4InterfaceContainer c) |
| 799 { |
| 800 for (Ipv4InterfaceContainer::Iterator i = c.Begin (); i != c.End (); ++i) |
| 801 { |
| 802 std::pair<Ptr<Ipv4>, uint32_t> pair = *i; |
| 803 EnableAsciiIpv4Internal (stream, prefix, pair.first, pair.second); |
| 804 } |
| 805 } |
| 806 |
| 807 // |
| 808 // Public API |
| 809 // |
| 810 void |
| 811 PcapAndAsciiHelperForIpv4::EnableAsciiIpv4 (std::string prefix, NodeContainer n) |
| 812 { |
| 813 EnableAsciiIpv4Impl (Ptr<OutputStreamObject> (), prefix, n); |
| 814 } |
| 815 |
| 816 // |
| 817 // Public API |
| 818 // |
| 819 void |
| 820 PcapAndAsciiHelperForIpv4::EnableAsciiIpv4 (Ptr<OutputStreamObject> stream, Node
Container n) |
| 821 { |
| 822 EnableAsciiIpv4Impl (stream, std::string (), n); |
| 823 } |
| 824 |
| 825 // |
| 826 // Private API |
| 827 // |
| 828 void |
| 829 PcapAndAsciiHelperForIpv4::EnableAsciiIpv4Impl (Ptr<OutputStreamObject> stream,
std::string prefix, NodeContainer n) |
| 830 { |
| 831 for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i) |
| 832 { |
| 833 Ptr<Node> node = *i; |
| 834 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); |
| 835 if (ipv4) |
| 836 { |
| 837 for (uint32_t j = 0; j < ipv4->GetNInterfaces (); ++j) |
| 838 { |
| 839 EnableAsciiIpv4Internal (stream, prefix, ipv4, j); |
| 840 } |
| 841 } |
| 842 } |
| 843 } |
| 844 |
| 845 // |
| 846 // Public API |
| 847 // |
| 848 void |
| 849 PcapAndAsciiHelperForIpv4::EnableAsciiIpv4All (std::string prefix) |
| 850 { |
| 851 EnableAsciiIpv4Impl (Ptr<OutputStreamObject> (), prefix, NodeContainer::GetGlo
bal ()); |
| 852 } |
| 853 |
| 854 // |
| 855 // Public API |
| 856 // |
| 857 void |
| 858 PcapAndAsciiHelperForIpv4::EnableAsciiIpv4All (Ptr<OutputStreamObject> stream) |
| 859 { |
| 860 EnableAsciiIpv4Impl (stream, std::string (), NodeContainer::GetGlobal ()); |
| 861 } |
| 862 |
| 863 // |
| 864 // Public API |
| 865 // |
| 866 void· |
| 867 PcapAndAsciiHelperForIpv4::EnableAsciiIpv4 (Ptr<OutputStreamObject> stream, uint
32_t nodeid, uint32_t interface) |
| 868 { |
| 869 EnableAsciiIpv4Impl (stream, std::string (), nodeid, interface); |
| 870 } |
| 871 |
| 872 // |
| 873 // Public API |
| 874 // |
| 875 void· |
| 876 PcapAndAsciiHelperForIpv4::EnableAsciiIpv4 (std::string prefix, uint32_t nodeid,
uint32_t interface) |
| 877 { |
| 878 EnableAsciiIpv4Impl (Ptr<OutputStreamObject> (), prefix, nodeid, interface); |
| 879 } |
| 880 |
| 881 // |
| 882 // Private API |
| 883 // |
| 884 void· |
| 885 PcapAndAsciiHelperForIpv4::EnableAsciiIpv4Impl ( |
| 886 Ptr<OutputStreamObject> stream,· |
| 887 std::string prefix,· |
| 888 uint32_t nodeid,· |
| 889 uint32_t interface) |
| 890 { |
| 891 NodeContainer n = NodeContainer::GetGlobal (); |
| 892 |
| 893 for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i) |
| 894 { |
| 895 Ptr<Node> node = *i; |
| 896 if (node->GetId () != nodeid)· |
| 897 { |
| 898 continue; |
| 899 } |
| 900 |
| 901 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); |
| 902 if (ipv4) |
| 903 { |
| 904 EnableAsciiIpv4Internal (stream, prefix, ipv4, interface); |
| 905 } |
| 906 |
| 907 return; |
| 908 } |
| 909 } |
| 910 |
| 911 void· |
| 912 PcapAndAsciiHelperForIpv4AndPcapHelperForIpv6::EnablePcapIpv6 (std::string prefi
x, Ptr<Ipv6> ipv6, uint32_t interface) |
| 913 { |
| 914 EnablePcapIpv6Internal (prefix, ipv6, interface); |
| 915 } |
| 916 |
| 917 void· |
| 918 PcapAndAsciiHelperForIpv4AndPcapHelperForIpv6::EnablePcapIpv6 (std::string prefi
x, std::string ipv6Name, uint32_t interface) |
| 919 { |
| 920 Ptr<Ipv6> ipv6 = Names::Find<Ipv6> (ipv6Name); |
| 921 EnablePcapIpv6 (prefix, ipv6, interface); |
| 922 } |
| 923 |
| 924 void· |
| 925 PcapAndAsciiHelperForIpv4AndPcapHelperForIpv6::EnablePcapIpv6 (std::string prefi
x, Ipv6InterfaceContainer c) |
| 926 { |
| 927 for (Ipv6InterfaceContainer::Iterator i = c.Begin (); i != c.End (); ++i) |
| 928 { |
| 929 std::pair<Ptr<Ipv6>, uint32_t> pair = *i; |
| 930 EnablePcapIpv6 (prefix, pair.first, pair.second); |
| 931 } |
| 932 } |
| 933 |
| 934 void |
| 935 PcapAndAsciiHelperForIpv4AndPcapHelperForIpv6::EnablePcapIpv6 (std::string prefi
x, NodeContainer n) |
| 936 { |
| 937 for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i) |
| 938 { |
| 939 Ptr<Node> node = *i; |
| 940 Ptr<Ipv6> ipv6 = node->GetObject<Ipv6> (); |
| 941 if (ipv6) |
| 942 { |
| 943 for (uint32_t j = 0; j < ipv6->GetNInterfaces (); ++j) |
| 944 { |
| 945 EnablePcapIpv6 (prefix, ipv6, j); |
| 946 } |
| 947 } |
| 948 } |
| 949 } |
| 950 |
| 951 void |
| 952 PcapAndAsciiHelperForIpv4AndPcapHelperForIpv6::EnablePcapIpv6All (std::string pr
efix) |
| 953 { |
| 954 EnablePcapIpv6 (prefix, NodeContainer::GetGlobal ()); |
| 955 } |
| 956 |
| 957 void· |
| 958 PcapAndAsciiHelperForIpv4AndPcapHelperForIpv6::EnablePcapIpv6 (std::string prefi
x, uint32_t nodeid, uint32_t interface) |
| 959 { |
| 960 NodeContainer n = NodeContainer::GetGlobal (); |
| 961 |
| 962 for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i) |
| 963 { |
| 964 Ptr<Node> node = *i; |
| 965 if (node->GetId () != nodeid)· |
| 966 { |
| 967 continue; |
| 968 } |
| 969 ······ |
| 970 Ptr<Ipv6> ipv6 = node->GetObject<Ipv6> (); |
| 971 if (ipv6) |
| 972 { |
| 973 EnablePcapIpv6 (prefix, ipv6, interface); |
| 974 } |
| 975 return; |
| 976 } |
| 977 } |
| 978 |
| 979 // |
| 980 // Public API |
| 981 // |
| 982 void· |
| 983 TraceHelperForProtocol::EnableAsciiIpv6 (std::string prefix, Ptr<Ipv6> ipv6, uin
t32_t interface) |
| 984 { |
| 985 EnableAsciiIpv6Internal (Ptr<OutputStreamObject> (), prefix, ipv6, interface); |
| 986 } |
| 987 |
| 988 // |
| 989 // Public API |
| 990 // |
| 991 void· |
| 992 TraceHelperForProtocol::EnableAsciiIpv6 (Ptr<OutputStreamObject> stream, Ptr<Ipv
6> ipv6, uint32_t interface) |
| 993 { |
| 994 EnableAsciiIpv6Internal (stream, std::string (), ipv6, interface); |
| 995 } |
| 996 |
| 997 // |
| 998 // Public API |
| 999 // |
| 1000 void· |
| 1001 TraceHelperForProtocol::EnableAsciiIpv6 (std::string prefix, std::string ipv6Nam
e, uint32_t interface) |
| 1002 { |
| 1003 EnableAsciiIpv6Impl (Ptr<OutputStreamObject> (), prefix, ipv6Name, interface); |
| 1004 } |
| 1005 |
| 1006 // |
| 1007 // Public API |
| 1008 // |
| 1009 void· |
| 1010 TraceHelperForProtocol::EnableAsciiIpv6 (Ptr<OutputStreamObject> stream, std::st
ring ipv6Name, uint32_t interface) |
| 1011 { |
| 1012 EnableAsciiIpv6Impl (stream, std::string (), ipv6Name, interface); |
| 1013 } |
| 1014 |
| 1015 // |
| 1016 // Private API |
| 1017 // |
| 1018 void· |
| 1019 TraceHelperForProtocol::EnableAsciiIpv6Impl ( |
| 1020 Ptr<OutputStreamObject> stream,· |
| 1021 std::string prefix,· |
| 1022 std::string ipv6Name,· |
| 1023 uint32_t interface) |
| 1024 { |
| 1025 Ptr<Ipv6> ipv6 = Names::Find<Ipv6> (ipv6Name); |
| 1026 EnableAsciiIpv6Internal (stream, prefix, ipv6, interface); |
| 1027 } |
| 1028 |
| 1029 // |
| 1030 // Public API |
| 1031 // |
| 1032 void· |
| 1033 TraceHelperForProtocol::EnableAsciiIpv6 (std::string prefix, Ipv6InterfaceContai
ner c) |
| 1034 { |
| 1035 EnableAsciiIpv6Impl (Ptr<OutputStreamObject> (), prefix, c); |
| 1036 } |
| 1037 |
| 1038 // |
| 1039 // Public API |
| 1040 // |
| 1041 void· |
| 1042 TraceHelperForProtocol::EnableAsciiIpv6 (Ptr<OutputStreamObject> stream, Ipv6Int
erfaceContainer c) |
| 1043 { |
| 1044 EnableAsciiIpv6Impl (stream, std::string (), c); |
| 1045 } |
| 1046 |
| 1047 // |
| 1048 // Private API |
| 1049 // |
| 1050 void· |
| 1051 TraceHelperForProtocol::EnableAsciiIpv6Impl (Ptr<OutputStreamObject> stream, std
::string prefix, Ipv6InterfaceContainer c) |
| 1052 { |
| 1053 for (Ipv6InterfaceContainer::Iterator i = c.Begin (); i != c.End (); ++i) |
| 1054 { |
| 1055 std::pair<Ptr<Ipv6>, uint32_t> pair = *i; |
| 1056 EnableAsciiIpv6Internal (stream, prefix, pair.first, pair.second); |
| 1057 } |
| 1058 } |
| 1059 |
| 1060 // |
| 1061 // Public API |
| 1062 // |
| 1063 void |
| 1064 TraceHelperForProtocol::EnableAsciiIpv6 (std::string prefix, NodeContainer n) |
| 1065 { |
| 1066 EnableAsciiIpv6Impl (Ptr<OutputStreamObject> (), prefix, n); |
| 1067 } |
| 1068 |
| 1069 // |
| 1070 // Public API |
| 1071 // |
| 1072 void |
| 1073 TraceHelperForProtocol::EnableAsciiIpv6 (Ptr<OutputStreamObject> stream, NodeCon
tainer n) |
| 1074 { |
| 1075 EnableAsciiIpv6Impl (stream, std::string (), n); |
| 1076 } |
| 1077 |
| 1078 // |
| 1079 // Private API |
| 1080 // |
| 1081 void |
| 1082 TraceHelperForProtocol::EnableAsciiIpv6Impl (Ptr<OutputStreamObject> stream, std
::string prefix, NodeContainer n) |
| 1083 { |
| 1084 for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i) |
| 1085 { |
| 1086 Ptr<Node> node = *i; |
| 1087 Ptr<Ipv6> ipv6 = node->GetObject<Ipv6> (); |
| 1088 if (ipv6) |
| 1089 { |
| 1090 for (uint32_t j = 0; j < ipv6->GetNInterfaces (); ++j) |
| 1091 { |
| 1092 EnableAsciiIpv6Internal (stream, prefix, ipv6, j); |
| 1093 } |
| 1094 } |
| 1095 } |
| 1096 } |
| 1097 |
| 1098 // |
| 1099 // Public API |
| 1100 // |
| 1101 void |
| 1102 TraceHelperForProtocol::EnableAsciiIpv6All (std::string prefix) |
| 1103 { |
| 1104 EnableAsciiIpv6Impl (Ptr<OutputStreamObject> (), prefix, NodeContainer::GetGlo
bal ()); |
| 1105 } |
| 1106 |
| 1107 // |
| 1108 // Public API |
| 1109 // |
| 1110 void |
| 1111 TraceHelperForProtocol::EnableAsciiIpv6All (Ptr<OutputStreamObject> stream) |
| 1112 { |
| 1113 EnableAsciiIpv6Impl (stream, std::string (), NodeContainer::GetGlobal ()); |
| 1114 } |
| 1115 |
| 1116 // |
| 1117 // Public API |
| 1118 // |
| 1119 void· |
| 1120 TraceHelperForProtocol::EnableAsciiIpv6 (Ptr<OutputStreamObject> stream, uint32_
t nodeid, uint32_t interface) |
| 1121 { |
| 1122 EnableAsciiIpv6Impl (stream, std::string (), nodeid, interface); |
| 1123 } |
| 1124 |
| 1125 // |
| 1126 // Public API |
| 1127 // |
| 1128 void· |
| 1129 TraceHelperForProtocol::EnableAsciiIpv6 (std::string prefix, uint32_t nodeid, ui
nt32_t interface) |
| 1130 { |
| 1131 EnableAsciiIpv6Impl (Ptr<OutputStreamObject> (), prefix, nodeid, interface); |
| 1132 } |
| 1133 |
| 1134 // |
| 1135 // Private API |
| 1136 // |
| 1137 void· |
| 1138 TraceHelperForProtocol::EnableAsciiIpv6Impl ( |
| 1139 Ptr<OutputStreamObject> stream,· |
| 1140 std::string prefix,· |
| 1141 uint32_t nodeid,· |
| 1142 uint32_t interface) |
| 1143 { |
| 1144 NodeContainer n = NodeContainer::GetGlobal (); |
| 1145 |
| 1146 for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i) |
| 1147 { |
| 1148 Ptr<Node> node = *i; |
| 1149 if (node->GetId () != nodeid)· |
| 1150 { |
| 1151 continue; |
| 1152 } |
| 1153 |
| 1154 Ptr<Ipv6> ipv6 = node->GetObject<Ipv6> (); |
| 1155 if (ipv6) |
| 1156 { |
| 1157 EnableAsciiIpv6Internal (stream, prefix, ipv6, interface); |
| 1158 } |
| 1159 |
| 1160 return; |
| 1161 } |
| 1162 } |
| 1163 |
| 1164 } // namespace ns3 |
| 1165 |
OLD | NEW |