satellite-sinr-probe.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 Bucknell University
4  * Copyright (c) 2014 Magister Solutions
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Authors of original work (application-packet-probe.cc) which this work
20  * derives from:
21  * - L. Felipe Perrone (perrone@bucknell.edu)
22  * - Tiago G. Rodrigues (tgr002@bucknell.edu)
23  * - Mitch Watrous (watrous@u.washington.edu)
24  *
25  * Modified for Sinr trace source by:
26  * - Budiarto Herman (budiarto.herman@magister.fi)
27  */
28 
29 #include "satellite-sinr-probe.h"
30 
31 #include <ns3/callback.h>
32 #include <ns3/config.h>
33 #include <ns3/log.h>
34 #include <ns3/names.h>
35 #include <ns3/simulator.h>
36 #include <ns3/traced-value.h>
37 
38 #include <string>
39 
40 NS_LOG_COMPONENT_DEFINE("SatSinrProbe");
41 
42 namespace ns3
43 {
44 
45 NS_OBJECT_ENSURE_REGISTERED(SatSinrProbe);
46 
47 TypeId
49 {
50  static TypeId tid =
51  TypeId("ns3::SatSinrProbe")
52  .SetParent<Probe>()
53  .AddConstructor<SatSinrProbe>()
54  .AddTraceSource(
55  "Output",
56  "The SINR plus its socket address that serve as the output for this probe",
57  MakeTraceSourceAccessor(&SatSinrProbe::m_output),
58  "ns3::SatSinrProbe::SinrCallback")
59  .AddTraceSource("OutputSinr",
60  "The SINR",
61  MakeTraceSourceAccessor(&SatSinrProbe::m_outputSinr),
62  "ns3::TracedValue::DoubleCallback");
63  return tid;
64 }
65 
67 {
68  NS_LOG_FUNCTION(this);
69 }
70 
72 {
73  NS_LOG_FUNCTION(this);
74 }
75 
76 void
77 SatSinrProbe::SetValue(double sinrDb, const Address& address)
78 {
79  NS_LOG_FUNCTION(this << sinrDb << address);
80  m_output(sinrDb, address);
81  m_outputSinr(m_sinr, sinrDb);
82  m_sinr = sinrDb;
83  m_address = address;
84 }
85 
86 void
87 SatSinrProbe::SetValueByPath(std::string path, double sinrDb, const Address& address)
88 {
89  NS_LOG_FUNCTION(path << sinrDb << address);
90  Ptr<SatSinrProbe> probe = Names::Find<SatSinrProbe>(path);
91  NS_ASSERT_MSG(probe, "Error: Can't find probe for path " << path);
92  probe->SetValue(sinrDb, address);
93 }
94 
95 bool
96 SatSinrProbe::ConnectByObject(std::string traceSource, Ptr<Object> obj)
97 {
98  NS_LOG_FUNCTION(this << traceSource << obj);
99  NS_LOG_DEBUG("Name of probe (if any) in names database: " << Names::FindPath(obj));
100  bool connected =
101  obj->TraceConnectWithoutContext(traceSource,
102  MakeCallback(&ns3::SatSinrProbe::TraceSink, this));
103  return connected;
104 }
105 
106 void
108 {
109  NS_LOG_FUNCTION(this << path);
110  NS_LOG_DEBUG("Name of probe to search for in config database: " << path);
111  Config::ConnectWithoutContext(path, MakeCallback(&ns3::SatSinrProbe::TraceSink, this));
112 }
113 
114 void
115 SatSinrProbe::TraceSink(double sinrDb, const Address& address)
116 {
117  NS_LOG_FUNCTION(this << sinrDb << address);
118  if (IsEnabled())
119  {
120  m_output(sinrDb, address);
121  m_outputSinr(m_sinr, sinrDb);
122  m_sinr = sinrDb;
123  m_address = address;
124  }
125 }
126 
127 } // namespace ns3
Address m_address
The socket address for the traced packet.
void TraceSink(double sinrDb, const Address &address)
Method to connect to an underlying ns3::TraceSource with arguments of type double and const Address&.
TracedCallback< double, double > m_outputSinr
Output trace, previous SINR and current SINR.
virtual bool ConnectByObject(std::string traceSource, Ptr< Object > obj)
connect to a trace source attribute provided by a given object
virtual ~SatSinrProbe()
Destructor for SatSinrProbe.
SatSinrProbe()
Default constructor.
static void SetValueByPath(std::string path, double sinrDb, const Address &address)
Set a probe value by its name in the Config system.
TracedCallback< double, const Address & > m_output
Output trace, the SINR and source address.
void SetValue(double sinrDb, const Address &address)
Set a probe value.
static TypeId GetTypeId()
Get the type ID.
double m_sinr
The traced SINR.
virtual void ConnectByPath(std::string path)
connect to a trace source provided by a config path
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.