satellite-stats-capacity-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/node-container.h>
29 #include <ns3/satellite-helper.h>
30 #include <ns3/satellite-net-device.h>
31 #include <ns3/satellite-request-manager.h>
32 #include <ns3/satellite-ut-llc.h>
33 #include <ns3/string.h>
34 
35 NS_LOG_COMPONENT_DEFINE("SatStatsCapacityRequestHelper");
36 
37 namespace ns3
38 {
39 
40 NS_OBJECT_ENSURE_REGISTERED(SatStatsCapacityRequestHelper);
41 
43  : SatStatsHelper(satHelper)
44 {
45  NS_LOG_FUNCTION(this << satHelper);
46 }
47 
49 {
50  NS_LOG_FUNCTION(this);
51 }
52 
53 TypeId // static
55 {
56  static TypeId tid = TypeId("ns3::SatStatsCapacityRequestHelper").SetParent<SatStatsHelper>();
57  return tid;
58 }
59 
60 void
62 {
63  NS_LOG_FUNCTION(this);
64 
66  {
67  NS_FATAL_ERROR(GetOutputTypeName(GetOutputType())
68  << " is not a valid output type for this statistics.");
69  }
70 
72  {
74  << " is not a valid identifier type for this statistics.");
75  }
76 
77  // Setup aggregator.
79  "ns3::MultiFileAggregator",
80  "OutputFileName",
81  StringValue(GetOutputFileName()),
82  "GeneralHeading",
83  StringValue("% time_sec, node_id, rc_id, type, kbps / bytes, queue_bytes"));
84  Ptr<MultiFileAggregator> multiFileAggregator = m_aggregator->GetObject<MultiFileAggregator>();
85  NS_ASSERT(multiFileAggregator != nullptr);
86  Callback<void, std::string, std::string> aggregatorSink =
87  MakeCallback(&MultiFileAggregator::WriteString, multiFileAggregator);
88 
89  // Setup probes.
90  NodeContainer uts = GetSatHelper()->GetBeamHelper()->GetUtNodes();
91  for (NodeContainer::Iterator it = uts.Begin(); it != uts.End(); ++it)
92  {
93  std::ostringstream context;
94  switch (GetIdentifierType())
95  {
97  context << "0";
98  break;
100  context << GetIdentifierForUt(*it);
101  break;
103  context << GetIdentifierForUt(*it);
104  break;
106  context << GetIdentifierForUt(*it);
107  break;
109  context << GetIdentifierForUt(*it);
110  break;
111  default:
112  NS_FATAL_ERROR("SatStatsCapacityRequestHelper - Invalid identifier type");
113  break;
114  }
115 
116  Ptr<NetDevice> dev = GetUtSatNetDevice(*it);
117  Ptr<SatNetDevice> satDev = dev->GetObject<SatNetDevice>();
118  NS_ASSERT(satDev != nullptr);
119  Ptr<SatLlc> satLlc = satDev->GetLlc();
120  NS_ASSERT(satLlc != nullptr);
121  Ptr<SatUtLlc> utLlc = satLlc->GetObject<SatUtLlc>();
122  NS_ASSERT(utLlc != nullptr);
123  Ptr<SatRequestManager> requestManager = utLlc->GetRequestManager();
124 
125  const bool ret = requestManager->TraceConnect("CrTraceLog", context.str(), aggregatorSink);
126  NS_ASSERT_MSG(ret, "Error connecting to CrTraceLog of node " << (*it)->GetId());
127  NS_LOG_INFO(this << " successfully connected"
128  << " with node ID " << (*it)->GetId());
129 
130  } // end of `for (NodeContainer::Iterator it = uts.Begin () -> uts.End ())`
131 
132 } // end of `void DoInstall ();`
133 
134 } // end of namespace ns3
SatNetDevice to be utilized in the UT and GW nodes.
SatStatsCapacityRequestHelper(Ptr< const SatHelper > satHelper)
static TypeId GetTypeId()
inherited from ObjectBase base class
void DoInstall()
Install the probes, collectors, and aggregators necessary to produce the statistics output.
Ptr< DataCollectionObject > m_aggregator
The aggregator created by this helper.
Parent abstract class of all satellite statistics helpers.
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.
static Ptr< NetDevice > GetUtSatNetDevice(Ptr< Node > utNode)
OutputType_t GetOutputType() const
uint32_t GetIdentifierForUt(Ptr< Node > utNode) const
SatUtLlc holds the UT implementation of LLC layer.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.