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 #include <iostream>
34 #include <sstream>
35 #include <string>
36 
37 NS_LOG_COMPONENT_DEFINE("SatPacketTrace");
38 
39 namespace ns3
40 {
41 
42 NS_OBJECT_ENSURE_REGISTERED(SatPacketTrace);
43 
45 {
46  ObjectBase::ConstructSelf(AttributeConstructionList());
47 
48  AsciiTraceHelper asciiTraceHelper;
49 
50  std::stringstream outputPath;
51  outputPath << Singleton<SatEnvVariables>::Get()->GetOutputPath() << "/" << m_fileName << ".log";
52 
53  m_packetTraceStream = asciiTraceHelper.CreateFileStream(outputPath.str());
54 
55  PrintHeader();
56 }
57 
59 {
60  NS_LOG_FUNCTION(this);
61 }
62 
63 TypeId
65 {
66  NS_LOG_FUNCTION(this);
67  return GetTypeId();
68 }
69 
70 TypeId
72 {
73  static TypeId tid = TypeId("ns3::SatPacketTrace")
74  .SetParent<Object>()
75  .AddAttribute("FileName",
76  "File name for the packet trace output",
77  StringValue("PacketTrace"),
78  MakeStringAccessor(&SatPacketTrace::m_fileName),
79  MakeStringChecker());
80  return tid;
81 }
82 
83 void
85 {
86  NS_LOG_FUNCTION(this);
87  Object::DoDispose();
88 }
89 
90 void
92 {
93  NS_LOG_FUNCTION(this);
94 
95  *m_packetTraceStream->GetStream() << "COLUMN DESCRIPTIONS" << std::endl;
96  *m_packetTraceStream->GetStream() << "-------------------" << std::endl;
97  *m_packetTraceStream->GetStream() << "Time" << std::endl;
98  *m_packetTraceStream->GetStream() << "Packet event (SND, RCV, DRP, ENQ)" << std::endl;
99  *m_packetTraceStream->GetStream() << "Node type (UT, SAT, GW, NCC, TER)" << std::endl;
100  *m_packetTraceStream->GetStream() << "Node id" << std::endl;
101  *m_packetTraceStream->GetStream() << "MAC address" << std::endl;
102  *m_packetTraceStream->GetStream() << "Log level (ND, LLC, MAC, PHY, CH)" << std::endl;
103  *m_packetTraceStream->GetStream() << "Link direction (FWD, RTN)" << std::endl;
104  *m_packetTraceStream->GetStream()
105  << "Packet info (List of: Packet id, source MAC address, destination MAC address)"
106  << std::endl;
107  *m_packetTraceStream->GetStream() << "-------------------" << std::endl << std::endl;
108 }
109 
110 void
112  SatEnums::SatPacketEvent_t packetEvent,
113  SatEnums::SatNodeType_t nodeType,
114  uint32_t nodeId,
115  Mac48Address macAddress,
116  SatEnums::SatLogLevel_t logLevel,
117  SatEnums::SatLinkDir_t linkDir,
118  std::string packetInfo)
119 {
120  NS_LOG_FUNCTION(this << now.GetSeconds());
121 
133  std::ostringstream oss;
134  oss << now.GetSeconds() << " " << SatEnums::GetPacketEventName(packetEvent) << " "
135  << SatEnums::GetNodeTypeName(nodeType) << " " << nodeId << " " << macAddress << " "
136  << SatEnums::GetLogLevelName(logLevel) << " " << SatEnums::GetLinkDirName(linkDir) << " "
137  << packetInfo;
138 
139  *m_packetTraceStream->GetStream() << oss.str() << std::endl;
140 }
141 
142 } // 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.