satellite-frame-user-load-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 FrameUtLoadTrace trace source by:
26  * - Budiarto Herman (budiarto.herman@magister.fi)
27  */
28 
29 #include "ns3/satellite-frame-user-load-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 
37 NS_LOG_COMPONENT_DEFINE("SatFrameUserLoadProbe");
38 
39 namespace ns3
40 {
41 
42 NS_OBJECT_ENSURE_REGISTERED(SatFrameUserLoadProbe);
43 
44 TypeId
46 {
47  static TypeId tid =
48  TypeId("ns3::SatFrameUserLoadProbe")
49  .SetParent<Probe>()
50  .AddConstructor<SatFrameUserLoadProbe>()
51  .AddTraceSource("Output",
52  "The frame ID and the number of scheduled users that serve as the "
53  "output for this probe",
54  MakeTraceSourceAccessor(&SatFrameUserLoadProbe::m_output),
55  "ns3::SatFrameUserLoadProbe::FrameUserLoadCallback");
56  return tid;
57 }
58 
60 {
61  NS_LOG_FUNCTION(this);
62 }
63 
65 {
66  NS_LOG_FUNCTION(this);
67 }
68 
69 void
70 SatFrameUserLoadProbe::SetValue(uint32_t frameId, uint32_t utCount)
71 {
72  NS_LOG_FUNCTION(this << frameId << utCount);
73  m_output(frameId, utCount);
74 }
75 
76 void
77 SatFrameUserLoadProbe::SetValueByPath(std::string path, uint32_t frameId, uint32_t utCount)
78 {
79  NS_LOG_FUNCTION(path << frameId << utCount);
80  Ptr<SatFrameUserLoadProbe> probe = Names::Find<SatFrameUserLoadProbe>(path);
81  NS_ASSERT_MSG(probe, "Error: Can't find probe for path " << path);
82  probe->SetValue(frameId, utCount);
83 }
84 
85 bool
86 SatFrameUserLoadProbe::ConnectByObject(std::string traceSource, Ptr<Object> obj)
87 {
88  NS_LOG_FUNCTION(this << traceSource << obj);
89  NS_LOG_DEBUG("Name of probe (if any) in names database: " << Names::FindPath(obj));
90  bool connected =
91  obj->TraceConnectWithoutContext(traceSource,
92  MakeCallback(&ns3::SatFrameUserLoadProbe::TraceSink, this));
93  return connected;
94 }
95 
96 void
98 {
99  NS_LOG_FUNCTION(this << path);
100  NS_LOG_DEBUG("Name of probe to search for in config database: " << path);
101  Config::ConnectWithoutContext(path, MakeCallback(&ns3::SatFrameUserLoadProbe::TraceSink, this));
102 }
103 
104 void
105 SatFrameUserLoadProbe::TraceSink(uint32_t frameId, uint32_t utCount)
106 {
107  NS_LOG_FUNCTION(this << frameId << utCount);
108  if (IsEnabled())
109  {
110  m_output(frameId, utCount);
111  }
112 }
113 
114 } // namespace ns3
TracedCallback< uint32_t, uint32_t > m_output
Output trace, the frame ID and number of scheduled users.
virtual bool ConnectByObject(std::string traceSource, Ptr< Object > obj)
connect to a trace source attribute provided by a given object
void SetValue(uint32_t frameId, uint32_t utCount)
Set a probe value.
static TypeId GetTypeId()
Get the type ID.
static void SetValueByPath(std::string path, uint32_t frameId, uint32_t utCount)
Set a probe value by its name in the Config system.
virtual ~SatFrameUserLoadProbe()
Destructor for SatFrameUserLoadProbe.
void TraceSink(uint32_t frameId, uint32_t utCount)
Method to connect to an underlying ns3::TraceSource with arguments of type uint32_t and uint32_t.
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.