satellite-phy-rx-carrier-marsala.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 
24 
25 #include <ns3/boolean.h>
26 #include <ns3/log.h>
27 #include <ns3/simulator.h>
28 
29 #include <list>
30 #include <map>
31 #include <vector>
32 
33 NS_LOG_COMPONENT_DEFINE("SatPhyRxCarrierMarsala");
34 
35 namespace ns3
36 {
37 
38 NS_OBJECT_ENSURE_REGISTERED(SatPhyRxCarrierMarsala);
39 
41  Ptr<SatPhyRxCarrierConf> carrierConf,
42  Ptr<SatWaveformConf> waveformConf,
43  bool randomAccessEnabled)
44  : SatPhyRxCarrierPerFrame(carrierId, carrierConf, waveformConf, randomAccessEnabled)
45 {
46  NS_LOG_FUNCTION(this);
47 }
48 
50 {
51  NS_LOG_FUNCTION(this);
52 }
53 
54 TypeId
56 {
57  static TypeId tid =
58  TypeId("ns3::SatPhyRxCarrierMarsala")
59  .SetParent<SatPhyRxCarrierPerFrame>()
60  .AddTraceSource(
61  "MarsalaCorrelationRx",
62  "Correlate a CRDSA packet replica through Random Access",
64  "ns3::SatPhyRxCarrierPacketProbe::RxStatusCallback");
65  return tid;
66 }
67 
68 void
70  std::vector<SatPhyRxCarrierPerFrame::crdsaPacketRxParams_s>& combinedPacketsForFrame)
71 {
72  NS_LOG_FUNCTION(this);
73 
74  do
75  {
76  // Perform CRDSA SIC in its entirety, until no more packets can be decoded
77  SatPhyRxCarrierPerFrame::PerformSicCycles(combinedPacketsForFrame);
78  }
79  // Try to decode one more packet using MARSALA
80  while (PerformMarsala(combinedPacketsForFrame));
81 }
82 
85  const std::list<SatPhyRxCarrierPerFrame::crdsaPacketRxParams_s>& slotContent,
87 {
88  bool replicaFound = false;
90 
91  for (const SatPhyRxCarrierPerFrame::crdsaPacketRxParams_s& currentPacket : slotContent)
92  {
93  if (IsReplica(packet, currentPacket))
94  {
95  if (replicaFound)
96  {
97  NS_FATAL_ERROR("Found more than one replica in the same slot!");
98  }
99  replicaFound = true;
100  replica = currentPacket;
101  }
102  }
103 
104  if (!replicaFound)
105  {
106  NS_FATAL_ERROR("Could not find a replica of a packet in the given slot!");
107  }
108 
109  return replica;
110 }
111 
112 bool
114  std::vector<SatPhyRxCarrierPerFrame::crdsaPacketRxParams_s>& combinedPacketsForFrame)
115 {
116  NS_LOG_FUNCTION(this);
117 
118  const uint32_t nbSlots = GetCrdsaPacketContainer().size();
119  NS_LOG_INFO("Number of slots: " << nbSlots);
120 
121  std::map<uint32_t, std::list<SatPhyRxCarrierPerFrame::crdsaPacketRxParams_s>>::iterator iter;
122  for (iter = GetCrdsaPacketContainer().begin(); iter != GetCrdsaPacketContainer().end(); ++iter)
123  {
124  NS_LOG_INFO("Iterating slot: " << iter->first);
125 
126  std::list<SatPhyRxCarrierPerFrame::crdsaPacketRxParams_s>& slotContent = iter->second;
127  if (slotContent.size() < 1)
128  {
129  NS_FATAL_ERROR("No packet in slot! This should not happen");
130  }
131 
132  std::list<SatPhyRxCarrierPerFrame::crdsaPacketRxParams_s>::iterator currentPacket;
133  for (currentPacket = slotContent.begin(); currentPacket != slotContent.end();
134  ++currentPacket)
135  {
136  NS_LOG_INFO("Iterating packet in slot: " << currentPacket->ownSlotId);
137 
138  // process the packet
139  uint32_t otherReplicasCount = currentPacket->slotIdsForOtherReplicas.size();
140  uint32_t replicasCount = 1 + otherReplicasCount;
141  uint32_t replicasCountSquared = replicasCount * replicasCount;
142  uint32_t packetsInSlotsCount = slotContent.size();
143 
144  double replicasIfPower = currentPacket->rxParams->GetInterferencePower();
145  double replicasNoisePower = replicasCount * m_rxNoisePowerW;
146  double replicasAciIfPower = replicasCount * m_rxAciIfPowerW;
147  double replicasExtNoisePower = replicasCount * m_rxExtNoisePowerW;
148 
149  double replicasIfPowerInSatellite =
150  currentPacket->rxParams->GetInterferencePowerInSatellite();
151  double replicasNoisePowerInSatellite =
152  currentPacket->rxParams->GetRxNoisePowerInSatellite();
153  double replicasAciIfPowerInSatellite =
154  currentPacket->rxParams->GetRxAciIfPowerInSatellite();
155  double replicasExtNoisePowerInSatellite =
156  currentPacket->rxParams->GetRxExtNoisePowerInSatellite();
157 
158  // add informations from other replicas
159  for (uint16_t& replicaSlotId : currentPacket->slotIdsForOtherReplicas)
160  {
161  NS_LOG_INFO("Processing replica in slot: " << replicaSlotId);
162 
163  std::map<uint32_t,
164  std::list<SatPhyRxCarrierPerFrame::crdsaPacketRxParams_s>>::iterator
165  replicaSlot;
166  replicaSlot = GetCrdsaPacketContainer().find(replicaSlotId);
167  if (replicaSlot == GetCrdsaPacketContainer().end())
168  {
169  NS_FATAL_ERROR("Slot " << replicaSlotId << " not found in frame!");
170  }
171  packetsInSlotsCount += replicaSlot->second.size();
172 
174  FindReplicaInSlot(replicaSlot->second, *currentPacket);
175  replicasIfPower += replica.rxParams->GetInterferencePower();
176  replicasIfPowerInSatellite += replica.rxParams->GetInterferencePowerInSatellite();
177  replicasNoisePowerInSatellite += replica.rxParams->GetRxNoisePowerInSatellite();
178  replicasAciIfPowerInSatellite += replica.rxParams->GetRxAciIfPowerInSatellite();
179  replicasExtNoisePowerInSatellite +=
180  replica.rxParams->GetRxExtNoisePowerInSatellite();
181  }
182 
183  double sinr = CalculateSinr(replicasCountSquared * currentPacket->rxParams->m_rxPower_W,
184  replicasIfPower,
185  replicasNoisePower,
186  replicasAciIfPower,
187  replicasExtNoisePower,
189 
191  double cSinr;
193  {
194  double sinrSatellite = CalculateSinr(
195  replicasCountSquared * currentPacket->rxParams->GetRxPowerInSatellite(),
196  replicasIfPowerInSatellite,
197  replicasNoisePowerInSatellite,
198  replicasAciIfPowerInSatellite,
199  replicasExtNoisePowerInSatellite,
200  currentPacket->rxParams->GetAdditionalInterference());
201  cSinr = CalculateCompositeSinr(sinr, sinrSatellite);
202  }
203  else
204  {
205  cSinr = sinr;
206  }
207 
209  currentPacket->rxParams->m_packetsInBurst;
210  SatSignalParameters::PacketsInBurst_t::const_iterator i;
211  for (i = packets.begin(); i != packets.end(); i++)
212  {
213  SatUplinkInfoTag satUplinkInfoTag;
214  (*i)->RemovePacketTag(satUplinkInfoTag);
215  satUplinkInfoTag.SetSinr(sinr, m_additionalInterferenceCallback());
216  (*i)->AddPacketTag(satUplinkInfoTag);
217  }
218 
219  /*
220  * Update link specific SINR trace for the RETURN_FEEDER link. The RETURN_USER
221  * link SINR is already updated at the SatPhyRxCarrier::EndRxDataTransparent ()
222  * method!
223  */
224  m_linkSinrTrace(SatUtils::LinearToDb(cSinr), currentPacket->sourceAddress);
225 
226  NS_LOG_INFO("MARSALA correlation computation, Replicas: "
227  << replicasCount << " Interferents: "
228  << (packetsInSlotsCount - replicasCount) << " Correlated SINR: " << cSinr);
229 
230  currentPacket->phyError = CheckAgainstLinkResults(cSinr, currentPacket->rxParams);
231 
232  uint32_t correlations = 1;
233  for (uint32_t i = nbSlots - otherReplicasCount; i < nbSlots; ++i)
234  {
235  correlations *= i;
236  }
237  m_marsalaCorrelationRxTrace(correlations,
238  currentPacket->sourceAddress,
239  currentPacket->phyError);
240 
241  NS_LOG_INFO("Packet error: " << currentPacket->phyError);
242 
243  if (!currentPacket->phyError)
244  {
245  // Save packet for further processing
246  SatPhyRxCarrierPerFrame::crdsaPacketRxParams_s processedPacket = *currentPacket;
247  NS_LOG_INFO("Packet successfully received, removing its interference and "
248  "processing the replicas");
249 
250  slotContent.erase(currentPacket);
251  EliminateInterference(iter, processedPacket);
252  FindAndRemoveReplicas(processedPacket);
253  combinedPacketsForFrame.push_back(processedPacket);
254 
255  return true;
256  }
257  }
258  }
259 
260  return false;
261 }
262 
263 } // namespace ns3
double m_rxExtNoisePowerW
External noise power system RX noise.
TracedCallback< double, const Address & > m_linkSinrTrace
A callback for link specific SINR in dB.
SatPhyRxCarrierConf::AdditionalInterferenceCallback m_additionalInterferenceCallback
Callback to get additional interference.
virtual SatEnums::RegenerationMode_t GetLinkRegenerationMode()
Get the link regeneration mode.
double CalculateSinr(double rxPowerW, double ifPowerW, double rxNoisePowerW, double rxAciIfPowerW, double rxExtNoisePowerW, double otherInterference)
Function for calculating the SINR.
double m_rxAciIfPowerW
RX Adjacent channel interference.
bool CheckAgainstLinkResults(double cSinr, Ptr< SatSignalParameters > rxParams)
Function for checking the SINR against the link results.
double CalculateCompositeSinr(double sinr1, double sinr2)
Function for calculating the composite SINR.
static TypeId GetTypeId(void)
Get the TypeId of the class.
void PerformSicCycles(std::vector< SatPhyRxCarrierPerFrame::crdsaPacketRxParams_s > &combinedPacketsForFrame)
Function for receiving decodable packets and removing their interference from the other packets in th...
SatPhyRxCarrierMarsala(uint32_t carrierId, Ptr< SatPhyRxCarrierConf > carrierConf, Ptr< SatWaveformConf > waveformConf, bool randomAccessEnabled)
Constructor.
TracedCallback< uint32_t, const Address &, bool > m_marsalaCorrelationRxTrace
MarsalaCorrelationRx trace source.
bool PerformMarsala(std::vector< SatPhyRxCarrierPerFrame::crdsaPacketRxParams_s > &combinedPacketsForFrame)
Function for performing MARSALA corelation on remaining packets in the frame.
SatPhyRxCarrierPerFrame::crdsaPacketRxParams_s FindReplicaInSlot(const std::list< SatPhyRxCarrierPerFrame::crdsaPacketRxParams_s > &slotContent, const SatPhyRxCarrierPerFrame::crdsaPacketRxParams_s &packet) const
Function for verifying if a replica of a given packet is found in the given slot.
Inherited the functionality of ground station SatPhyRxCarriers and extended it with CRDSA functionali...
void EliminateInterference(std::map< uint32_t, std::list< SatPhyRxCarrierPerFrame::crdsaPacketRxParams_s >>::iterator iter, SatPhyRxCarrierPerFrame::crdsaPacketRxParams_s processedPacket)
Function for eliminating the interference to other packets in the slot from the correctly received pa...
bool IsReplica(const SatPhyRxCarrierPerFrame::crdsaPacketRxParams_s &packet, const SatPhyRxCarrierPerFrame::crdsaPacketRxParams_s &otherPacket) const
Function for identifying whether the packet is a replica of another packet.
virtual void PerformSicCycles(std::vector< SatPhyRxCarrierPerFrame::crdsaPacketRxParams_s > &combinedPacketsForFrame)
Function for receiving decodable packets and removing their interference from the other packets in th...
void FindAndRemoveReplicas(SatPhyRxCarrierPerFrame::crdsaPacketRxParams_s packet)
Function for finding and removing the replicas of the CRDSA packet.
std::map< uint32_t, std::list< SatPhyRxCarrierPerFrame::crdsaPacketRxParams_s > > & GetCrdsaPacketContainer()
std::vector< Ptr< Packet > > PacketsInBurst_t
Buffer for transmissions.
static T LinearToDb(T linear)
Converts linear to decibels.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
Struct for storing the CRDSA packet specific Rx parameters.