Loading...
Searching...
No Matches
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
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
40NS_LOG_COMPONENT_DEFINE("SatPhyRxCarrierPacketProbe");
41
42namespace ns3
43{
44
45NS_OBJECT_ENSURE_REGISTERED(SatPhyRxCarrierPacketProbe);
46
47TypeId
49{
50 static TypeId tid =
51 TypeId("ns3::SatPhyRxCarrierPacketProbe")
52 .SetParent<Probe>()
53 .AddConstructor<SatPhyRxCarrierPacketProbe>()
54 .AddTraceSource("Output",
55 "The number of packets in the packet burst, its "
56 "associated socket address, and a status flag, that "
57 "serve as the output for this probe",
58 MakeTraceSourceAccessor(&SatPhyRxCarrierPacketProbe::m_output),
59 "ns3::SatPhyRxCarrierPacketProbe::RxStatusCallback")
60 .AddTraceSource("OutputUinteger",
61 "The number of packets",
62 MakeTraceSourceAccessor(&SatPhyRxCarrierPacketProbe::m_outputUinteger),
63 "ns3::TracedValue::UintCallback")
64 .AddTraceSource("OutputBool",
65 "The status flag",
66 MakeTraceSourceAccessor(&SatPhyRxCarrierPacketProbe::m_outputBool),
67 "ns3::TracedValue::BoolCallback");
68 return tid;
69}
70
75
80
81void
82SatPhyRxCarrierPacketProbe::SetValue(uint32_t nPackets, const Address& address, bool statusFlag)
83{
84 NS_LOG_FUNCTION(this << nPackets << address << statusFlag);
85 m_output(nPackets, address, statusFlag);
87 m_outputBool(m_statusFlag, statusFlag);
88 m_nPackets = nPackets;
89 m_address = address;
90 m_statusFlag = statusFlag;
91}
92
93void
95 uint32_t nPackets,
96 const Address& address,
97 bool statusFlag)
98{
99 NS_LOG_FUNCTION(path << nPackets << address << statusFlag);
100 Ptr<SatPhyRxCarrierPacketProbe> probe = Names::Find<SatPhyRxCarrierPacketProbe>(path);
101 NS_ASSERT_MSG(probe, "Error: Can't find probe for path " << path);
102 probe->SetValue(nPackets, address, statusFlag);
103}
104
105bool
106SatPhyRxCarrierPacketProbe::ConnectByObject(std::string traceSource, Ptr<Object> obj)
107{
108 NS_LOG_FUNCTION(this << traceSource << obj);
109 NS_LOG_DEBUG("Name of probe (if any) in names database: " << Names::FindPath(obj));
110 bool connected = obj->TraceConnectWithoutContext(
111 traceSource,
112 MakeCallback(&ns3::SatPhyRxCarrierPacketProbe::TraceSink, this));
113 return connected;
114}
115
116void
118{
119 NS_LOG_FUNCTION(this << path);
120 NS_LOG_DEBUG("Name of probe to search for in config database: " << path);
121 Config::ConnectWithoutContext(path,
122 MakeCallback(&ns3::SatPhyRxCarrierPacketProbe::TraceSink, this));
123}
124
125void
126SatPhyRxCarrierPacketProbe::TraceSink(uint32_t nPackets, const Address& address, bool statusFlag)
127{
128 NS_LOG_FUNCTION(this << nPackets << address << statusFlag);
129 if (IsEnabled())
130 {
131 m_output(nPackets, address, statusFlag);
132 m_outputUinteger(m_nPackets, nPackets);
133 m_outputBool(m_statusFlag, statusFlag);
134 m_nPackets = nPackets;
135 m_address = address;
136 m_statusFlag = statusFlag;
137 }
138}
139
140} // namespace ns3
Probe to translate from a TraceSource to two more easily parsed TraceSources.
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.