satellite-per-fragment-interference.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2018 CNES
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: Mathias Ettinger <mettinger@toulouse.viveris.com>
19  */
20 
22 
23 #include <ns3/log.h>
24 #include <ns3/simulator.h>
25 
26 #include <cstddef>
27 #include <stdint.h>
28 #include <utility>
29 #include <vector>
30 
31 NS_LOG_COMPONENT_DEFINE("SatPerFragmentInterference");
32 
33 namespace ns3
34 {
35 
36 NS_OBJECT_ENSURE_REGISTERED(SatPerFragmentInterference);
37 
38 TypeId
40 {
41  static TypeId tid = TypeId("ns3::SatPerFragmentInterference")
42  .SetParent<SatPerPacketInterference>()
43  .AddConstructor<SatPerFragmentInterference>();
44 
45  return tid;
46 }
47 
48 TypeId
50 {
51  NS_LOG_FUNCTION(this);
52  return GetTypeId();
53 }
54 
57  m_ifPowerAtEventChangeW(),
58  m_maxFragmentsCount(1)
59 {
60  NS_LOG_FUNCTION(this);
61 }
62 
64  double rxBandwidthHz)
65  : SatPerPacketInterference(channelType, rxBandwidthHz),
66  m_ifPowerAtEventChangeW(),
67  m_maxFragmentsCount(1)
68 {
69  NS_LOG_FUNCTION(this);
70 }
71 
73 {
74  NS_LOG_FUNCTION(this);
75 }
76 
77 std::vector<std::pair<double, double>>
78 SatPerFragmentInterference::DoCalculate(Ptr<SatInterference::InterferenceChangeEvent> event)
79 {
80  NS_LOG_FUNCTION(this);
81 
84 
85  // Use the per packet interference computation hooks to store
86  // interferences at each event associated to the current packet
88 
89  std::size_t fragmentsCount = m_ifPowerAtEventChangeW.size();
90  if (!fragmentsCount)
91  {
92  NS_FATAL_ERROR("Interference computation did not find a single fragment");
93  }
94 
95  if (fragmentsCount > m_maxFragmentsCount)
96  {
97  m_maxFragmentsCount = fragmentsCount;
98  }
99 
100  // Convert time ratio into durations
101  std::vector<std::pair<double, double>> ifPowerPerFragment;
102  ifPowerPerFragment.reserve(fragmentsCount);
103 
104  std::vector<std::pair<double, double>>::const_iterator iter = m_ifPowerAtEventChangeW.begin();
105  std::pair<double, double> eventChangeInPower = *iter;
106  for (++iter; iter != m_ifPowerAtEventChangeW.end(); ++iter)
107  {
108  ifPowerPerFragment.emplace_back(iter->first - eventChangeInPower.first,
109  eventChangeInPower.second);
110  eventChangeInPower = *iter;
111  }
112 
113  // Account for the last fragment duration
114  if (eventChangeInPower.first != 1.0)
115  {
116  ifPowerPerFragment.emplace_back(1.0 - eventChangeInPower.first, eventChangeInPower.second);
117  }
118 
119  return ifPowerPerFragment;
120 }
121 
122 void
124 {
125  // Hook into per packet interference computation to store
126  // interference level at the beginning of the packet
127  m_ifPowerAtEventChangeW.emplace_back(0.0, ifPowerW);
128 }
129 
130 void
132  double interferenceValue,
133  double& ifPowerW)
134 {
135  // Hook into per packet interference computation to store
136  // interference level at each event change
137  ifPowerW += interferenceValue;
138  m_ifPowerAtEventChangeW.emplace_back(1.0 - timeRatio, ifPowerW);
139 }
140 
141 } // namespace ns3
ChannelType_t
Types of channel.
TypeId GetInstanceTypeId(void) const
Inherited from ObjectBase base class.
static TypeId GetTypeId()
Inherited from ObjectBase base class.
void onInterferentEvent(long double timeRatio, double interferenceValue, double &ifPowerW)
Helper function meant for subclasses to override.
std::vector< std::pair< double, double > > m_ifPowerAtEventChangeW
void onOwnStartReached(double ifPowerW)
Helper function meant for subclasses to override.
std::vector< std::pair< double, double > > DoCalculate(Ptr< SatInterference::InterferenceChangeEvent > event)
Calculates interference power for the given reference Sets final power at end time to finalPower.
virtual std::vector< std::pair< double, double > > DoCalculate(Ptr< SatInterference::InterferenceChangeEvent > event)
Calculates interference power for the given reference Sets final power at end time to finalPower.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.