src/internet-node/ascii-trace.cc
changeset 1376 ad7e61edfb9d
parent 1362 162bd608c970
parent 1281 9b2b6ead9df6
child 1381 6dd346ffeddc
equal deleted inserted replaced
1375:4f45bec005b8 1376:ad7e61edfb9d
    23 #include "ns3/trace-context.h"
    23 #include "ns3/trace-context.h"
    24 #include "ns3/simulator.h"
    24 #include "ns3/simulator.h"
    25 #include "ns3/node.h"
    25 #include "ns3/node.h"
    26 #include "ns3/node-list.h"
    26 #include "ns3/node-list.h"
    27 #include "ns3/packet.h"
    27 #include "ns3/packet.h"
       
    28 #include "ns3/queue.h"
    28 
    29 
    29 namespace ns3 {
    30 namespace ns3 {
    30 
    31 
    31 AsciiTrace::AsciiTrace (std::string filename)
    32 AsciiTrace::AsciiTrace (std::string filename)
    32 {
    33 {
    38 }
    39 }
    39 void
    40 void
    40 AsciiTrace::TraceAllQueues (void)
    41 AsciiTrace::TraceAllQueues (void)
    41 {
    42 {
    42   Packet::EnableMetadata ();
    43   Packet::EnableMetadata ();
    43   NodeList::Connect ("/nodes/*/devices/*/queue/*",
    44   NodeList::Connect ("/nodes/*/devices/*/queue/enqueue",
    44                      MakeCallback (&AsciiTrace::LogDevQueue, this));
    45                       MakeCallback (&AsciiTrace::LogDevQueueEnqueue, this));
       
    46   NodeList::Connect ("/nodes/*/devices/*/queue/dequeue",
       
    47                       MakeCallback (&AsciiTrace::LogDevQueueDequeue, this));
       
    48   NodeList::Connect ("/nodes/*/devices/*/queue/drop",
       
    49                       MakeCallback (&AsciiTrace::LogDevQueueDrop, this));
    45 }
    50 }
    46 void
    51 void
    47 AsciiTrace::TraceAllNetDeviceRx (void)
    52 AsciiTrace::TraceAllNetDeviceRx (void)
    48 {
    53 {
    49   Packet::EnableMetadata ();
    54   Packet::EnableMetadata ();
    50   NodeList::Connect ("/nodes/*/devices/*/rx",
    55   NodeList::Connect ("/nodes/*/devices/*/rx",
    51                      MakeCallback (&AsciiTrace::LogDevRx, this));
    56                      MakeCallback (&AsciiTrace::LogDevRx, this));
    52 }
    57 }
    53 
    58 
    54 void 
    59 void 
    55 AsciiTrace::LogDevQueue (TraceContext const &context, Packet const &packet)
    60 AsciiTrace::LogDevQueueEnqueue (TraceContext const &context, 
       
    61   Packet const &packet)
    56 {
    62 {
       
    63   m_os << "+ ";
       
    64   m_os << Simulator::Now ().GetSeconds () << " ";
       
    65   context.Print (m_os);
       
    66   m_os << " pkt-uid=" << packet.GetUid () << " ";
       
    67   packet.Print (m_os);
       
    68   m_os << std::endl;
       
    69 }
       
    70 
       
    71 void 
       
    72 AsciiTrace::LogDevQueueDequeue (TraceContext const &context, 
       
    73   Packet const &packet)
       
    74 {
       
    75   m_os << "- ";
       
    76   m_os << Simulator::Now ().GetSeconds () << " ";
       
    77   context.Print (m_os);
       
    78   m_os << " pkt-uid=" << packet.GetUid () << " ";
       
    79   packet.Print (m_os);
       
    80   m_os << std::endl;
       
    81 }
       
    82 
       
    83 void 
       
    84 AsciiTrace::LogDevQueueDrop (TraceContext const &context, 
       
    85   Packet const &packet)
       
    86 {
       
    87   m_os << "d ";
    57   m_os << Simulator::Now ().GetSeconds () << " ";
    88   m_os << Simulator::Now ().GetSeconds () << " ";
    58   context.Print (m_os);
    89   context.Print (m_os);
    59   m_os << " pkt-uid=" << packet.GetUid () << " ";
    90   m_os << " pkt-uid=" << packet.GetUid () << " ";
    60   packet.Print (m_os);
    91   packet.Print (m_os);
    61   m_os << std::endl;
    92   m_os << std::endl;
    62 }
    93 }
    63 void 
    94 void 
    64 AsciiTrace::LogDevRx (TraceContext const &context, Packet &p)
    95 AsciiTrace::LogDevRx (TraceContext const &context, Packet &p)
    65 {
    96 {
    66   m_os << Simulator::Now ().GetSeconds () << " ";
    97   m_os << "r " << Simulator::Now ().GetSeconds () << " ";
    67   context.Print (m_os);
    98   context.Print (m_os);
    68   m_os << " pkt-uid=" << p.GetUid () << " ";
    99   m_os << " pkt-uid=" << p.GetUid () << " ";
    69   p.Print (m_os);
   100   p.Print (m_os);
    70   m_os << std::endl;  
   101   m_os << std::endl;  
    71 }
   102 }