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 <ns3/callback.h>
30 #include <ns3/config.h>
31 #include <ns3/log.h>
32 #include <ns3/names.h>
33 #include <ns3/satellite-sinr-probe.h>
34 #include <ns3/simulator.h>
35 #include <ns3/traced-value.h>
36 
37 NS_LOG_COMPONENT_DEFINE("SatSinrProbe");
38 
39 namespace ns3
40 {
41 
42 NS_OBJECT_ENSURE_REGISTERED(SatSinrProbe);
43 
44 TypeId
46 {
47  static TypeId tid =
48  TypeId("ns3::SatSinrProbe")
49  .SetParent<Probe>()
50  .AddConstructor<SatSinrProbe>()
51  .AddTraceSource(
52  "Output",
53  "The SINR plus its socket address that serve as the output for this probe",
54  MakeTraceSourceAccessor(&SatSinrProbe::m_output),
55  "ns3::SatSinrProbe::SinrCallback")
56  .AddTraceSource("OutputSinr",
57  "The SINR",
58  MakeTraceSourceAccessor(&SatSinrProbe::m_outputSinr),
59  "ns3::TracedValue::DoubleCallback");
60  return tid;
61 }
62 
64 {
65  NS_LOG_FUNCTION(this);
66 }
67 
69 {
70  NS_LOG_FUNCTION(this);
71 }
72 
73 void
74 SatSinrProbe::SetValue(double sinrDb, const Address& address)
75 {
76  NS_LOG_FUNCTION(this << sinrDb << address);
77  m_output(sinrDb, address);
78  m_outputSinr(m_sinr, sinrDb);
79  m_sinr = sinrDb;
80  m_address = address;
81 }
82 
83 void
84 SatSinrProbe::SetValueByPath(std::string path, double sinrDb, const Address& address)
85 {
86  NS_LOG_FUNCTION(path << sinrDb << address);
87  Ptr<SatSinrProbe> probe = Names::Find<SatSinrProbe>(path);
88  NS_ASSERT_MSG(probe, "Error: Can't find probe for path " << path);
89  probe->SetValue(sinrDb, address);
90 }
91 
92 bool
93 SatSinrProbe::ConnectByObject(std::string traceSource, Ptr<Object> obj)
94 {
95  NS_LOG_FUNCTION(this << traceSource << obj);
96  NS_LOG_DEBUG("Name of probe (if any) in names database: " << Names::FindPath(obj));
97  bool connected =
98  obj->TraceConnectWithoutContext(traceSource,
99  MakeCallback(&ns3::SatSinrProbe::TraceSink, this));
100  return connected;
101 }
102 
103 void
105 {
106  NS_LOG_FUNCTION(this << path);
107  NS_LOG_DEBUG("Name of probe to search for in config database: " << path);
108  Config::ConnectWithoutContext(path, MakeCallback(&ns3::SatSinrProbe::TraceSink, this));
109 }
110 
111 void
112 SatSinrProbe::TraceSink(double sinrDb, const Address& address)
113 {
114  NS_LOG_FUNCTION(this << sinrDb << address);
115  if (IsEnabled())
116  {
117  m_output(sinrDb, address);
118  m_outputSinr(m_sinr, sinrDb);
119  m_sinr = sinrDb;
120  m_address = address;
121  }
122 }
123 
124 } // 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.