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 #include <sstream>
36 #include <string>
37 #include <utility>
38 
39 NS_LOG_COMPONENT_DEFINE("SatStatsBackloggedRequestHelper");
40 
41 namespace ns3
42 {
43 
44 NS_OBJECT_ENSURE_REGISTERED(SatStatsBackloggedRequestHelper);
45 
47  : SatStatsHelper(satHelper)
48 {
49  NS_LOG_FUNCTION(this << satHelper);
50 }
51 
53 {
54  NS_LOG_FUNCTION(this);
55 }
56 
57 TypeId // static
59 {
60  static TypeId tid = TypeId("ns3::SatStatsBackloggedRequestHelper").SetParent<SatStatsHelper>();
61  return tid;
62 }
63 
64 void
66 {
67  NS_LOG_FUNCTION(this);
68 
70  {
71  NS_FATAL_ERROR(GetOutputTypeName(GetOutputType())
72  << " is not a valid output type for this statistics.");
73  }
74 
77  {
79  << " is not a valid identifier type for this statistics.");
80  }
81 
82  // Setup aggregator.
83  m_aggregator = CreateAggregator("ns3::MultiFileAggregator",
84  "OutputFileName",
85  StringValue(GetOutputFileName()),
86  "GeneralHeading",
87  StringValue("% time_sec, beam_id, ut_id, type, requests"));
88  Ptr<MultiFileAggregator> multiFileAggregator = m_aggregator->GetObject<MultiFileAggregator>();
89  NS_ASSERT(multiFileAggregator != nullptr);
90  Callback<void, std::string, std::string> aggregatorSink =
91  MakeCallback(&MultiFileAggregator::WriteString, multiFileAggregator);
92 
93  // Setup probes.
94  Ptr<SatBeamHelper> beamHelper = GetSatHelper()->GetBeamHelper();
95  NS_ASSERT(beamHelper != nullptr);
96  Ptr<SatNcc> ncc = beamHelper->GetNcc();
97  NS_ASSERT(ncc != nullptr);
98  std::list<std::pair<uint32_t, uint32_t>> beams = beamHelper->GetBeams();
99 
100  for (std::list<std::pair<uint32_t, uint32_t>>::const_iterator it = beams.begin();
101  it != beams.end();
102  ++it)
103  {
104  std::ostringstream context;
105  switch (GetIdentifierType())
106  {
108  context << "0";
109  break;
111  context << GetIdentifierForBeam(it->first, it->second);
112  break;
114  context << GetIdentifierForBeam(it->first, it->second);
115  break;
116  default:
117  NS_FATAL_ERROR("SatStatsBackloggedRequestHelper - Invalid identifier type");
118  break;
119  }
120 
121  Ptr<SatBeamScheduler> s = ncc->GetBeamScheduler(it->first, it->second);
122  NS_ASSERT_MSG(s != nullptr, "Error finding beam " << it->second);
123  const bool ret = s->TraceConnect("BacklogRequestsTrace", context.str(), aggregatorSink);
124  NS_ASSERT_MSG(ret, "Error connecting to BacklogRequestsTrace of beam " << it->second);
125  NS_LOG_INFO(this << " successfully connected"
126  << " with beam " << it->second);
127  }
128 
129 } // end of `void DoInstall ();`
130 
131 } // 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.