satellite-packet-trace.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013 Magister Solutions Ltd.
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: Jani Puttonen <jani.puttonen@magister.fi>
19  */
20 
21 #include "satellite-packet-trace.h"
22 
23 #include "../utils/satellite-env-variables.h"
24 
25 #include <ns3/log.h>
26 #include <ns3/mac48-address.h>
27 #include <ns3/object.h>
28 #include <ns3/output-stream-wrapper.h>
29 #include <ns3/singleton.h>
30 #include <ns3/string.h>
31 #include <ns3/trace-helper.h>
32 
33 NS_LOG_COMPONENT_DEFINE("SatPacketTrace");
34 
35 namespace ns3
36 {
37 
38 NS_OBJECT_ENSURE_REGISTERED(SatPacketTrace);
39 
41 {
42  ObjectBase::ConstructSelf(AttributeConstructionList());
43 
44  AsciiTraceHelper asciiTraceHelper;
45 
46  std::stringstream outputPath;
47  outputPath << Singleton<SatEnvVariables>::Get()->GetOutputPath() << "/" << m_fileName << ".log";
48 
49  m_packetTraceStream = asciiTraceHelper.CreateFileStream(outputPath.str());
50 
51  PrintHeader();
52 }
53 
55 {
56  NS_LOG_FUNCTION(this);
57 }
58 
59 TypeId
61 {
62  NS_LOG_FUNCTION(this);
63  return GetTypeId();
64 }
65 
66 TypeId
68 {
69  static TypeId tid = TypeId("ns3::SatPacketTrace")
70  .SetParent<Object>()
71  .AddAttribute("FileName",
72  "File name for the packet trace output",
73  StringValue("PacketTrace"),
74  MakeStringAccessor(&SatPacketTrace::m_fileName),
75  MakeStringChecker());
76  return tid;
77 }
78 
79 void
81 {
82  NS_LOG_FUNCTION(this);
83  Object::DoDispose();
84 }
85 
86 void
88 {
89  NS_LOG_FUNCTION(this);
90 
91  *m_packetTraceStream->GetStream() << "COLUMN DESCRIPTIONS" << std::endl;
92  *m_packetTraceStream->GetStream() << "-------------------" << std::endl;
93  *m_packetTraceStream->GetStream() << "Time" << std::endl;
94  *m_packetTraceStream->GetStream() << "Packet event (SND, RCV, DRP, ENQ)" << std::endl;
95  *m_packetTraceStream->GetStream() << "Node type (UT, SAT, GW, NCC, TER)" << std::endl;
96  *m_packetTraceStream->GetStream() << "Node id" << std::endl;
97  *m_packetTraceStream->GetStream() << "MAC address" << std::endl;
98  *m_packetTraceStream->GetStream() << "Log level (ND, LLC, MAC, PHY, CH)" << std::endl;
99  *m_packetTraceStream->GetStream() << "Link direction (FWD, RTN)" << std::endl;
100  *m_packetTraceStream->GetStream()
101  << "Packet info (List of: Packet id, source MAC address, destination MAC address)"
102  << std::endl;
103  *m_packetTraceStream->GetStream() << "-------------------" << std::endl << std::endl;
104 }
105 
106 void
108  SatEnums::SatPacketEvent_t packetEvent,
109  SatEnums::SatNodeType_t nodeType,
110  uint32_t nodeId,
111  Mac48Address macAddress,
112  SatEnums::SatLogLevel_t logLevel,
113  SatEnums::SatLinkDir_t linkDir,
114  std::string packetInfo)
115 {
116  NS_LOG_FUNCTION(this << now.GetSeconds());
117 
129  std::ostringstream oss;
130  oss << now.GetSeconds() << " " << SatEnums::GetPacketEventName(packetEvent) << " "
131  << SatEnums::GetNodeTypeName(nodeType) << " " << nodeId << " " << macAddress << " "
132  << SatEnums::GetLogLevelName(logLevel) << " " << SatEnums::GetLinkDirName(linkDir) << " "
133  << packetInfo;
134 
135  *m_packetTraceStream->GetStream() << oss.str() << std::endl;
136 }
137 
138 } // namespace ns3
SatLinkDir_t
Link direction used for packet tracing.
static std::string GetNodeTypeName(SatNodeType_t nodeType)
SatNodeType_t
Node type used for packet tracing.
static std::string GetLinkDirName(SatLinkDir_t linkDir)
SatPacketEvent_t
Packet event used for packet tracing.
static std::string GetPacketEventName(SatPacketEvent_t packetEvent)
static std::string GetLogLevelName(SatLogLevel_t logLevel)
SatLogLevel_t
Log level used for packet tracing.
virtual ~SatPacketTrace()
Destructor.
Ptr< OutputStreamWrapper > m_packetTraceStream
Stream wrapper used for packet traces.
TypeId GetInstanceTypeId() const
virtual void DoDispose()
Dispose of this class instance.
std::string m_fileName
File name of the packet trace log.
void PrintHeader()
Print header to the packet trace log.
void AddTraceEntry(Time now, SatEnums::SatPacketEvent_t packetEvent, SatEnums::SatNodeType_t nodeType, uint32_t nodeId, Mac48Address macAddress, SatEnums::SatLogLevel_t logLevel, SatEnums::SatLinkDir_t linkDir, std::string packetInfo)
Add a packet trace entry to the log.
static TypeId GetTypeId(void)
Get the type ID.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.