1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
|
2 /* |
|
3 * Copyright (c) 2007 INRIA |
|
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
|
19 */ |
|
20 #include "ascii-trace.h" |
|
21 |
|
22 #include "ns3/config.h" |
|
23 #include "ns3/simulator.h" |
|
24 #include "ns3/node.h" |
|
25 #include "ns3/packet.h" |
|
26 #include "ns3/queue.h" |
|
27 |
|
28 namespace ns3 { |
|
29 |
|
30 AsciiTrace::AsciiTrace (std::string filename) |
|
31 { |
|
32 m_os.open (filename.c_str ()); |
|
33 } |
|
34 AsciiTrace::~AsciiTrace () |
|
35 { |
|
36 m_os.close (); |
|
37 } |
|
38 void |
|
39 AsciiTrace::TraceAllQueues (void) |
|
40 { |
|
41 Packet::EnableMetadata (); |
|
42 Config::Connect ("/NodeList/*/DeviceList/*/TxQueue/Enqueue", |
|
43 MakeCallback (&AsciiTrace::LogDevQueueEnqueue, this)); |
|
44 Config::Connect ("/NodeList/*/DeviceList/*/TxQueue/Dequeue", |
|
45 MakeCallback (&AsciiTrace::LogDevQueueDequeue, this)); |
|
46 Config::Connect ("/NodeList/*/DeviceList/*/TxQueue/Drop", |
|
47 MakeCallback (&AsciiTrace::LogDevQueueDrop, this)); |
|
48 } |
|
49 void |
|
50 AsciiTrace::TraceAllNetDeviceRx (void) |
|
51 { |
|
52 Packet::EnableMetadata (); |
|
53 Config::Connect ("/NodeList/*/DeviceList/*/Rx", |
|
54 MakeCallback (&AsciiTrace::LogDevRx, this)); |
|
55 } |
|
56 |
|
57 void |
|
58 AsciiTrace::LogDevQueueEnqueue (std::string context, |
|
59 Ptr<const Packet> packet) |
|
60 { |
|
61 m_os << "+ "; |
|
62 m_os << Simulator::Now ().GetSeconds () << " "; |
|
63 m_os << context; |
|
64 m_os << " pkt-uid=" << packet->GetUid () << " "; |
|
65 packet->Print (m_os); |
|
66 m_os << std::endl; |
|
67 } |
|
68 |
|
69 void |
|
70 AsciiTrace::LogDevQueueDequeue (std::string context, |
|
71 Ptr<const Packet> packet) |
|
72 { |
|
73 m_os << "- "; |
|
74 m_os << Simulator::Now ().GetSeconds () << " "; |
|
75 m_os << context; |
|
76 m_os << " pkt-uid=" << packet->GetUid () << " "; |
|
77 packet->Print (m_os); |
|
78 m_os << std::endl; |
|
79 } |
|
80 |
|
81 void |
|
82 AsciiTrace::LogDevQueueDrop (std::string context, |
|
83 Ptr<const Packet> packet) |
|
84 { |
|
85 m_os << "d "; |
|
86 m_os << Simulator::Now ().GetSeconds () << " "; |
|
87 m_os << context; |
|
88 m_os << " pkt-uid=" << packet->GetUid () << " "; |
|
89 packet->Print (m_os); |
|
90 m_os << std::endl; |
|
91 } |
|
92 void |
|
93 AsciiTrace::LogDevRx (std::string context, |
|
94 Ptr<const Packet> p) |
|
95 { |
|
96 m_os << "r " << Simulator::Now ().GetSeconds () << " "; |
|
97 m_os << context; |
|
98 m_os << " pkt-uid=" << p->GetUid () << " "; |
|
99 p->Print (m_os); |
|
100 m_os << std::endl; |
|
101 } |
|
102 |
|
103 }//namespace ns3 |
|