Loading...
Searching...
No Matches
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
22
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
37NS_LOG_COMPONENT_DEFINE("SatPacketTrace");
38
39namespace ns3
40{
41
42NS_OBJECT_ENSURE_REGISTERED(SatPacketTrace);
43
45{
46 NS_LOG_FUNCTION(this);
47}
48
49void
51{
52 NS_LOG_FUNCTION(this);
53
54 Object::NotifyConstructionCompleted();
55
56 AsciiTraceHelper asciiTraceHelper;
57
58 std::stringstream outputPath;
59 outputPath << SatEnvVariables::GetInstance()->GetOutputPath() << "/" << m_fileName << ".log";
60
61 m_packetTraceStream = asciiTraceHelper.CreateFileStream(outputPath.str());
62
64}
65
67{
68 NS_LOG_FUNCTION(this);
69}
70
71TypeId
73{
74 static TypeId tid = TypeId("ns3::SatPacketTrace")
75 .SetParent<Object>()
76 .AddAttribute("FileName",
77 "File name for the packet trace output",
78 StringValue("PacketTrace"),
79 MakeStringAccessor(&SatPacketTrace::m_fileName),
80 MakeStringChecker());
81 return tid;
82}
83
84void
86{
87 NS_LOG_FUNCTION(this);
88 Object::DoDispose();
89}
90
91void
93{
94 NS_LOG_FUNCTION(this);
95
96 *m_packetTraceStream->GetStream() << "COLUMN DESCRIPTIONS" << std::endl;
97 *m_packetTraceStream->GetStream() << "-------------------" << std::endl;
98 *m_packetTraceStream->GetStream() << "Time" << std::endl;
99 *m_packetTraceStream->GetStream() << "Packet event (SND, RCV, DRP, ENQ)" << std::endl;
100 *m_packetTraceStream->GetStream() << "Node type (UT, SAT, GW, NCC, TER)" << std::endl;
101 *m_packetTraceStream->GetStream() << "Node id" << std::endl;
102 *m_packetTraceStream->GetStream() << "MAC address" << std::endl;
103 *m_packetTraceStream->GetStream() << "Log level (ND, LLC, MAC, PHY, CH)" << std::endl;
104 *m_packetTraceStream->GetStream() << "Link direction (FWD, RTN)" << std::endl;
105 *m_packetTraceStream->GetStream()
106 << "Packet info (List of: Packet id, source MAC address, destination MAC address)"
107 << std::endl;
108 *m_packetTraceStream->GetStream() << "-------------------" << std::endl << std::endl;
109}
110
111void
113 SatEnums::SatPacketEvent_t packetEvent,
115 uint32_t nodeId,
116 Mac48Address macAddress,
119 std::string packetInfo)
120{
121 NS_LOG_FUNCTION(this << now.GetSeconds());
122
133
134 std::ostringstream oss;
135 oss << now.GetSeconds() << " " << SatEnums::GetPacketEventName(packetEvent) << " "
136 << SatEnums::GetNodeTypeName(nodeType) << " " << nodeId << " " << macAddress << " "
137 << SatEnums::GetLogLevelName(logLevel) << " " << SatEnums::GetLinkDirName(linkDir) << " "
138 << packetInfo;
139
140 *m_packetTraceStream->GetStream() << oss.str() << std::endl;
141}
142
143} // 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.
static Ptr< SatEnvVariables > GetInstance()
The SatPacketTrace implements a packet trace functionality.
virtual ~SatPacketTrace()
Destructor.
Ptr< OutputStreamWrapper > m_packetTraceStream
Stream wrapper used for packet traces.
virtual void NotifyConstructionCompleted() override
Notifier called once the ObjectBase is fully constructed.
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.