src/internet-node/ascii-trace.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Tue, 11 Mar 2008 13:46:22 -0700
changeset 2594 a8f89acd17a1
parent 2542 a9b88fdc09d6
child 2834 1aab57845b07
permissions -rw-r--r--
Config::Connect -> Config::ConnectWithoutContext && Config::ConnectWithContext -> Config::Connect
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
389
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
     1
/* -*-	Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
     2
/*
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
     3
 * Copyright (c) 2007 INRIA
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
     4
 * All rights reserved.
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
     5
 *
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
     6
 * This program is free software; you can redistribute it and/or modify
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
     7
 * it under the terms of the GNU General Public License version 2 as
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
     8
 * published by the Free Software Foundation;
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
     9
 *
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    13
 * GNU General Public License for more details.
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    14
 *
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    16
 * along with this program; if not, write to the Free Software
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    18
 *
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    19
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    20
 */
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    21
#include "ascii-trace.h"
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    22
2535
08297f16760f port AsciiTrace to Config::ConnectWithContext
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1866
diff changeset
    23
#include "ns3/config.h"
389
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    24
#include "ns3/simulator.h"
729
b5e744285e92 rename i-node to node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 728
diff changeset
    25
#include "ns3/node.h"
1229
e4cfe4094c10 build with the new TraceContextElement API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1195
diff changeset
    26
#include "ns3/packet.h"
1281
9b2b6ead9df6 restore ns-2 .tr format
Tom Henderson <tomh@tomh.org>
parents: 1229
diff changeset
    27
#include "ns3/queue.h"
389
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    28
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    29
namespace ns3 {
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    30
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    31
AsciiTrace::AsciiTrace (std::string filename)
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    32
{
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    33
  m_os.open (filename.c_str ());
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    34
}
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    35
AsciiTrace::~AsciiTrace ()
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    36
{
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    37
  m_os.close ();
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    38
}
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    39
void
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    40
AsciiTrace::TraceAllQueues (void)
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    41
{
903
9ebdbfc46d48 use pretty printing in ascii output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 734
diff changeset
    42
  Packet::EnableMetadata ();
2594
a8f89acd17a1 Config::Connect -> Config::ConnectWithoutContext && Config::ConnectWithContext -> Config::Connect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2542
diff changeset
    43
  Config::Connect ("/NodeList/*/DeviceList/*/TxQueue/Enqueue",
2535
08297f16760f port AsciiTrace to Config::ConnectWithContext
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1866
diff changeset
    44
                              MakeCallback (&AsciiTrace::LogDevQueueEnqueue, this));
2594
a8f89acd17a1 Config::Connect -> Config::ConnectWithoutContext && Config::ConnectWithContext -> Config::Connect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2542
diff changeset
    45
  Config::Connect ("/NodeList/*/DeviceList/*/TxQueue/Dequeue",
2535
08297f16760f port AsciiTrace to Config::ConnectWithContext
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1866
diff changeset
    46
                              MakeCallback (&AsciiTrace::LogDevQueueDequeue, this));
2594
a8f89acd17a1 Config::Connect -> Config::ConnectWithoutContext && Config::ConnectWithContext -> Config::Connect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2542
diff changeset
    47
  Config::Connect ("/NodeList/*/DeviceList/*/TxQueue/Drop",
2535
08297f16760f port AsciiTrace to Config::ConnectWithContext
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1866
diff changeset
    48
                              MakeCallback (&AsciiTrace::LogDevQueueDrop, this));
389
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    49
}
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    50
void
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    51
AsciiTrace::TraceAllNetDeviceRx (void)
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    52
{
903
9ebdbfc46d48 use pretty printing in ascii output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 734
diff changeset
    53
  Packet::EnableMetadata ();
2594
a8f89acd17a1 Config::Connect -> Config::ConnectWithoutContext && Config::ConnectWithContext -> Config::Connect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2542
diff changeset
    54
  Config::Connect ("/NodeList/*/DeviceList/*/Rx",
2535
08297f16760f port AsciiTrace to Config::ConnectWithContext
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1866
diff changeset
    55
                              MakeCallback (&AsciiTrace::LogDevRx, this));
389
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    56
}
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    57
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    58
void 
2535
08297f16760f port AsciiTrace to Config::ConnectWithContext
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1866
diff changeset
    59
AsciiTrace::LogDevQueueEnqueue (std::string context,
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1381
diff changeset
    60
                                Ptr<const Packet> packet)
389
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    61
{
1281
9b2b6ead9df6 restore ns-2 .tr format
Tom Henderson <tomh@tomh.org>
parents: 1229
diff changeset
    62
  m_os << "+ ";
9b2b6ead9df6 restore ns-2 .tr format
Tom Henderson <tomh@tomh.org>
parents: 1229
diff changeset
    63
  m_os << Simulator::Now ().GetSeconds () << " ";
2535
08297f16760f port AsciiTrace to Config::ConnectWithContext
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1866
diff changeset
    64
  m_os << context;
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1381
diff changeset
    65
  m_os << " pkt-uid=" << packet->GetUid () << " ";
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1381
diff changeset
    66
  packet->Print (m_os);
1281
9b2b6ead9df6 restore ns-2 .tr format
Tom Henderson <tomh@tomh.org>
parents: 1229
diff changeset
    67
  m_os << std::endl;
9b2b6ead9df6 restore ns-2 .tr format
Tom Henderson <tomh@tomh.org>
parents: 1229
diff changeset
    68
}
9b2b6ead9df6 restore ns-2 .tr format
Tom Henderson <tomh@tomh.org>
parents: 1229
diff changeset
    69
9b2b6ead9df6 restore ns-2 .tr format
Tom Henderson <tomh@tomh.org>
parents: 1229
diff changeset
    70
void 
2535
08297f16760f port AsciiTrace to Config::ConnectWithContext
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1866
diff changeset
    71
AsciiTrace::LogDevQueueDequeue (std::string context,
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1381
diff changeset
    72
                                Ptr<const Packet> packet)
1281
9b2b6ead9df6 restore ns-2 .tr format
Tom Henderson <tomh@tomh.org>
parents: 1229
diff changeset
    73
{
9b2b6ead9df6 restore ns-2 .tr format
Tom Henderson <tomh@tomh.org>
parents: 1229
diff changeset
    74
  m_os << "- ";
9b2b6ead9df6 restore ns-2 .tr format
Tom Henderson <tomh@tomh.org>
parents: 1229
diff changeset
    75
  m_os << Simulator::Now ().GetSeconds () << " ";
2535
08297f16760f port AsciiTrace to Config::ConnectWithContext
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1866
diff changeset
    76
  m_os << context;
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1381
diff changeset
    77
  m_os << " pkt-uid=" << packet->GetUid () << " ";
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1381
diff changeset
    78
  packet->Print (m_os);
1281
9b2b6ead9df6 restore ns-2 .tr format
Tom Henderson <tomh@tomh.org>
parents: 1229
diff changeset
    79
  m_os << std::endl;
9b2b6ead9df6 restore ns-2 .tr format
Tom Henderson <tomh@tomh.org>
parents: 1229
diff changeset
    80
}
9b2b6ead9df6 restore ns-2 .tr format
Tom Henderson <tomh@tomh.org>
parents: 1229
diff changeset
    81
9b2b6ead9df6 restore ns-2 .tr format
Tom Henderson <tomh@tomh.org>
parents: 1229
diff changeset
    82
void 
2535
08297f16760f port AsciiTrace to Config::ConnectWithContext
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1866
diff changeset
    83
AsciiTrace::LogDevQueueDrop (std::string context,
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1381
diff changeset
    84
                             Ptr<const Packet> packet)
1281
9b2b6ead9df6 restore ns-2 .tr format
Tom Henderson <tomh@tomh.org>
parents: 1229
diff changeset
    85
{
9b2b6ead9df6 restore ns-2 .tr format
Tom Henderson <tomh@tomh.org>
parents: 1229
diff changeset
    86
  m_os << "d ";
389
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    87
  m_os << Simulator::Now ().GetSeconds () << " ";
2535
08297f16760f port AsciiTrace to Config::ConnectWithContext
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1866
diff changeset
    88
  m_os << context;
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1381
diff changeset
    89
  m_os << " pkt-uid=" << packet->GetUid () << " ";
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1381
diff changeset
    90
  packet->Print (m_os);
389
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    91
  m_os << std::endl;
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    92
}
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    93
void 
2535
08297f16760f port AsciiTrace to Config::ConnectWithContext
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1866
diff changeset
    94
AsciiTrace::LogDevRx (std::string context,
08297f16760f port AsciiTrace to Config::ConnectWithContext
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1866
diff changeset
    95
                      Ptr<const Packet> p)
389
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
    96
{
1281
9b2b6ead9df6 restore ns-2 .tr format
Tom Henderson <tomh@tomh.org>
parents: 1229
diff changeset
    97
  m_os << "r " << Simulator::Now ().GetSeconds () << " ";
2535
08297f16760f port AsciiTrace to Config::ConnectWithContext
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1866
diff changeset
    98
  m_os << context;
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1381
diff changeset
    99
  m_os << " pkt-uid=" << p->GetUid () << " ";
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1381
diff changeset
   100
  p->Print (m_os);
389
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
   101
  m_os << std::endl;  
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
   102
}
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
   103
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents:
diff changeset
   104
}//namespace ns3