satellite-phy-rx-carrier-packet-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 the signature of SatPhyRxCarrier trace sources 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-phy-rx-carrier-packet-probe.h>
34 #include <ns3/simulator.h>
35 #include <ns3/traced-value.h>
36 
37 NS_LOG_COMPONENT_DEFINE("SatPhyRxCarrierPacketProbe");
38 
39 namespace ns3
40 {
41 
42 NS_OBJECT_ENSURE_REGISTERED(SatPhyRxCarrierPacketProbe);
43 
44 TypeId
46 {
47  static TypeId tid =
48  TypeId("ns3::SatPhyRxCarrierPacketProbe")
49  .SetParent<Probe>()
50  .AddConstructor<SatPhyRxCarrierPacketProbe>()
51  .AddTraceSource("Output",
52  "The number of packets in the packet burst, its "
53  "associated socket address, and a status flag, that "
54  "serve as the output for this probe",
55  MakeTraceSourceAccessor(&SatPhyRxCarrierPacketProbe::m_output),
56  "ns3::SatPhyRxCarrierPacketProbe::RxStatusCallback")
57  .AddTraceSource("OutputUinteger",
58  "The number of packets",
59  MakeTraceSourceAccessor(&SatPhyRxCarrierPacketProbe::m_outputUinteger),
60  "ns3::TracedValue::UintCallback")
61  .AddTraceSource("OutputBool",
62  "The status flag",
63  MakeTraceSourceAccessor(&SatPhyRxCarrierPacketProbe::m_outputBool),
64  "ns3::TracedValue::BoolCallback");
65  return tid;
66 }
67 
69 {
70  NS_LOG_FUNCTION(this);
71 }
72 
74 {
75  NS_LOG_FUNCTION(this);
76 }
77 
78 void
79 SatPhyRxCarrierPacketProbe::SetValue(uint32_t nPackets, const Address& address, bool statusFlag)
80 {
81  NS_LOG_FUNCTION(this << nPackets << address << statusFlag);
82  m_output(nPackets, address, statusFlag);
83  m_outputUinteger(m_nPackets, nPackets);
84  m_outputBool(m_statusFlag, statusFlag);
85  m_nPackets = nPackets;
86  m_address = address;
87  m_statusFlag = statusFlag;
88 }
89 
90 void
92  uint32_t nPackets,
93  const Address& address,
94  bool statusFlag)
95 {
96  NS_LOG_FUNCTION(path << nPackets << address << statusFlag);
97  Ptr<SatPhyRxCarrierPacketProbe> probe = Names::Find<SatPhyRxCarrierPacketProbe>(path);
98  NS_ASSERT_MSG(probe, "Error: Can't find probe for path " << path);
99  probe->SetValue(nPackets, address, statusFlag);
100 }
101 
102 bool
103 SatPhyRxCarrierPacketProbe::ConnectByObject(std::string traceSource, Ptr<Object> obj)
104 {
105  NS_LOG_FUNCTION(this << traceSource << obj);
106  NS_LOG_DEBUG("Name of probe (if any) in names database: " << Names::FindPath(obj));
107  bool connected = obj->TraceConnectWithoutContext(
108  traceSource,
109  MakeCallback(&ns3::SatPhyRxCarrierPacketProbe::TraceSink, this));
110  return connected;
111 }
112 
113 void
115 {
116  NS_LOG_FUNCTION(this << path);
117  NS_LOG_DEBUG("Name of probe to search for in config database: " << path);
118  Config::ConnectWithoutContext(path,
119  MakeCallback(&ns3::SatPhyRxCarrierPacketProbe::TraceSink, this));
120 }
121 
122 void
123 SatPhyRxCarrierPacketProbe::TraceSink(uint32_t nPackets, const Address& address, bool statusFlag)
124 {
125  NS_LOG_FUNCTION(this << nPackets << address << statusFlag);
126  if (IsEnabled())
127  {
128  m_output(nPackets, address, statusFlag);
129  m_outputUinteger(m_nPackets, nPackets);
130  m_outputBool(m_statusFlag, statusFlag);
131  m_nPackets = nPackets;
132  m_address = address;
133  m_statusFlag = statusFlag;
134  }
135 }
136 
137 } // namespace ns3
bool m_statusFlag
The traced packet burst status flag.
uint32_t m_nPackets
The traced number of packets in the packet burst.
TracedCallback< uint32_t, const Address &, bool > m_output
Output trace, the number of packets, source address, and status flag.
virtual void ConnectByPath(std::string path)
connect to a trace source provided by a config path
virtual bool ConnectByObject(std::string traceSource, Ptr< Object > obj)
connect to a trace source attribute provided by a given object
void SetValue(uint32_t nPackets, const Address &address, bool statusFlag)
Set a probe value.
TracedCallback< uint32_t, uint32_t > m_outputUinteger
Output trace, previous and current number of packets.
virtual ~SatPhyRxCarrierPacketProbe()
Destructor for SatPhyRxCarrierPacketProbe.
static void SetValueByPath(std::string path, uint32_t nPackets, const Address &address, bool statusFlag)
Set a probe value by its name in the Config system.
Address m_address
The socket address for the traced packet burst.
void TraceSink(uint32_t nPackets, const Address &address, bool statusFlag)
Method to connect to an underlying ns3::TraceSource with arguments of type double and const Address&.
TracedCallback< bool, bool > m_outputBool
Output trace, previous and current status flag.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.