satellite-stats-backlogged-request-helper.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014 Magister Solutions
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Budiarto Herman <budiarto.herman@magister.fi>
19  *
20  */
21 
23 
24 #include <ns3/data-collection-object.h>
25 #include <ns3/fatal-error.h>
26 #include <ns3/log.h>
27 #include <ns3/multi-file-aggregator.h>
28 #include <ns3/satellite-beam-helper.h>
29 #include <ns3/satellite-beam-scheduler.h>
30 #include <ns3/satellite-helper.h>
31 #include <ns3/satellite-ncc.h>
32 #include <ns3/string.h>
33 
34 #include <list>
35 
36 NS_LOG_COMPONENT_DEFINE("SatStatsBackloggedRequestHelper");
37 
38 namespace ns3
39 {
40 
41 NS_OBJECT_ENSURE_REGISTERED(SatStatsBackloggedRequestHelper);
42 
44  : SatStatsHelper(satHelper)
45 {
46  NS_LOG_FUNCTION(this << satHelper);
47 }
48 
50 {
51  NS_LOG_FUNCTION(this);
52 }
53 
54 TypeId // static
56 {
57  static TypeId tid = TypeId("ns3::SatStatsBackloggedRequestHelper").SetParent<SatStatsHelper>();
58  return tid;
59 }
60 
61 void
63 {
64  NS_LOG_FUNCTION(this);
65 
67  {
68  NS_FATAL_ERROR(GetOutputTypeName(GetOutputType())
69  << " is not a valid output type for this statistics.");
70  }
71 
74  {
76  << " is not a valid identifier type for this statistics.");
77  }
78 
79  // Setup aggregator.
80  m_aggregator = CreateAggregator("ns3::MultiFileAggregator",
81  "OutputFileName",
82  StringValue(GetOutputFileName()),
83  "GeneralHeading",
84  StringValue("% time_sec, beam_id, ut_id, type, requests"));
85  Ptr<MultiFileAggregator> multiFileAggregator = m_aggregator->GetObject<MultiFileAggregator>();
86  NS_ASSERT(multiFileAggregator != nullptr);
87  Callback<void, std::string, std::string> aggregatorSink =
88  MakeCallback(&MultiFileAggregator::WriteString, multiFileAggregator);
89 
90  // Setup probes.
91  Ptr<SatBeamHelper> beamHelper = GetSatHelper()->GetBeamHelper();
92  NS_ASSERT(beamHelper != nullptr);
93  Ptr<SatNcc> ncc = beamHelper->GetNcc();
94  NS_ASSERT(ncc != nullptr);
95  std::list<std::pair<uint32_t, uint32_t>> beams = beamHelper->GetBeams();
96 
97  for (std::list<std::pair<uint32_t, uint32_t>>::const_iterator it = beams.begin();
98  it != beams.end();
99  ++it)
100  {
101  std::ostringstream context;
102  switch (GetIdentifierType())
103  {
105  context << "0";
106  break;
108  context << GetIdentifierForBeam(it->first, it->second);
109  break;
111  context << GetIdentifierForBeam(it->first, it->second);
112  break;
113  default:
114  NS_FATAL_ERROR("SatStatsBackloggedRequestHelper - Invalid identifier type");
115  break;
116  }
117 
118  Ptr<SatBeamScheduler> s = ncc->GetBeamScheduler(it->first, it->second);
119  NS_ASSERT_MSG(s != nullptr, "Error finding beam " << it->second);
120  const bool ret = s->TraceConnect("BacklogRequestsTrace", context.str(), aggregatorSink);
121  NS_ASSERT_MSG(ret, "Error connecting to BacklogRequestsTrace of beam " << it->second);
122  NS_LOG_INFO(this << " successfully connected"
123  << " with beam " << it->second);
124  }
125 
126 } // end of `void DoInstall ();`
127 
128 } // end of namespace ns3
static TypeId GetTypeId()
inherited from ObjectBase base class
Ptr< DataCollectionObject > m_aggregator
The aggregator created by this helper.
void DoInstall()
Install the probes, collectors, and aggregators necessary to produce the statistics output.
Parent abstract class of all satellite statistics helpers.
uint32_t GetIdentifierForBeam(uint32_t satId, uint32_t beamId) const
Ptr< const SatHelper > GetSatHelper() const
IdentifierType_t GetIdentifierType() const
static std::string GetOutputTypeName(OutputType_t outputType)
static std::string GetIdentifierTypeName(IdentifierType_t identifierType)
Ptr< DataCollectionObject > CreateAggregator(std::string aggregatorTypeId, std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue())
Create the aggregator according to the output type.
virtual std::string GetOutputFileName() const
Compute the path and file name where statistics output should be written to.
OutputType_t GetOutputType() const
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.