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 NS_LOG_COMPONENT_DEFINE("SatPhyRxCarrierMarsala");
30 
31 namespace ns3
32 {
33 
34 NS_OBJECT_ENSURE_REGISTERED(SatPhyRxCarrierMarsala);
35 
37  Ptr<SatPhyRxCarrierConf> carrierConf,
38  Ptr<SatWaveformConf> waveformConf,
39  bool randomAccessEnabled)
40  : SatPhyRxCarrierPerFrame(carrierId, carrierConf, waveformConf, randomAccessEnabled)
41 {
42  NS_LOG_FUNCTION(this);
43 }
44 
46 {
47  NS_LOG_FUNCTION(this);
48 }
49 
50 TypeId
52 {
53  static TypeId tid =
54  TypeId("ns3::SatPhyRxCarrierMarsala")
55  .SetParent<SatPhyRxCarrierPerFrame>()
56  .AddTraceSource(
57  "MarsalaCorrelationRx",
58  "Correlate a CRDSA packet replica through Random Access",
60  "ns3::SatPhyRxCarrierPacketProbe::RxStatusCallback");
61  return tid;
62 }
63 
64 void
66  std::vector<SatPhyRxCarrierPerFrame::crdsaPacketRxParams_s>& combinedPacketsForFrame)
67 {
68  NS_LOG_FUNCTION(this);
69 
70  do
71  {
72  // Perform CRDSA SIC in its entirety, until no more packets can be decoded
73  SatPhyRxCarrierPerFrame::PerformSicCycles(combinedPacketsForFrame);
74  }
75  // Try to decode one more packet using MARSALA
76  while (PerformMarsala(combinedPacketsForFrame));
77 }
78 
81  const std::list<SatPhyRxCarrierPerFrame::crdsaPacketRxParams_s>& slotContent,
83 {
84  bool replicaFound = false;
86 
87  for (const SatPhyRxCarrierPerFrame::crdsaPacketRxParams_s& currentPacket : slotContent)
88  {
89  if (IsReplica(packet, currentPacket))
90  {
91  if (replicaFound)
92  {
93  NS_FATAL_ERROR("Found more than one replica in the same slot!");
94  }
95  replicaFound = true;
96  replica = currentPacket;
97  }
98  }
99 
100  if (!replicaFound)
101  {
102  NS_FATAL_ERROR("Could not find a replica of a packet in the given slot!");
103  }
104 
105  return replica;
106 }
107 
108 bool
110  std::vector<SatPhyRxCarrierPerFrame::crdsaPacketRxParams_s>& combinedPacketsForFrame)
111 {
112  NS_LOG_FUNCTION(this);
113 
114  const uint32_t nbSlots = GetCrdsaPacketContainer().size();
115  NS_LOG_INFO("Number of slots: " << nbSlots);
116 
117  std::map<uint32_t, std::list<SatPhyRxCarrierPerFrame::crdsaPacketRxParams_s>>::iterator iter;
118  for (iter = GetCrdsaPacketContainer().begin(); iter != GetCrdsaPacketContainer().end(); ++iter)
119  {
120  NS_LOG_INFO("Iterating slot: " << iter->first);
121 
122  std::list<SatPhyRxCarrierPerFrame::crdsaPacketRxParams_s>& slotContent = iter->second;
123  if (slotContent.size() < 1)
124  {
125  NS_FATAL_ERROR("No packet in slot! This should not happen");
126  }
127 
128  std::list<SatPhyRxCarrierPerFrame::crdsaPacketRxParams_s>::iterator currentPacket;
129  for (currentPacket = slotContent.begin(); currentPacket != slotContent.end();
130  ++currentPacket)
131  {
132  NS_LOG_INFO("Iterating packet in slot: " << currentPacket->ownSlotId);
133 
134  // process the packet
135  uint32_t otherReplicasCount = currentPacket->slotIdsForOtherReplicas.size();
136  uint32_t replicasCount = 1 + otherReplicasCount;
137  uint32_t replicasCountSquared = replicasCount * replicasCount;
138  uint32_t packetsInSlotsCount = slotContent.size();
139 
140  double replicasIfPower = currentPacket->rxParams->GetInterferencePower();
141  double replicasNoisePower = replicasCount * m_rxNoisePowerW;
142  double replicasAciIfPower = replicasCount * m_rxAciIfPowerW;
143  double replicasExtNoisePower = replicasCount * m_rxExtNoisePowerW;
144 
145  double replicasIfPowerInSatellite =
146  currentPacket->rxParams->GetInterferencePowerInSatellite();
147  double replicasNoisePowerInSatellite =
148  currentPacket->rxParams->GetRxNoisePowerInSatellite();
149  double replicasAciIfPowerInSatellite =
150  currentPacket->rxParams->GetRxAciIfPowerInSatellite();
151  double replicasExtNoisePowerInSatellite =
152  currentPacket->rxParams->GetRxExtNoisePowerInSatellite();
153 
154  // add informations from other replicas
155  for (uint16_t& replicaSlotId : currentPacket->slotIdsForOtherReplicas)
156  {
157  NS_LOG_INFO("Processing replica in slot: " << replicaSlotId);
158 
159  std::map<uint32_t,
160  std::list<SatPhyRxCarrierPerFrame::crdsaPacketRxParams_s>>::iterator
161  replicaSlot;
162  replicaSlot = GetCrdsaPacketContainer().find(replicaSlotId);
163  if (replicaSlot == GetCrdsaPacketContainer().end())
164  {
165  NS_FATAL_ERROR("Slot " << replicaSlotId << " not found in frame!");
166  }
167  packetsInSlotsCount += replicaSlot->second.size();
168 
170  FindReplicaInSlot(replicaSlot->second, *currentPacket);
171  replicasIfPower += replica.rxParams->GetInterferencePower();
172  replicasIfPowerInSatellite += replica.rxParams->GetInterferencePowerInSatellite();
173  replicasNoisePowerInSatellite += replica.rxParams->GetRxNoisePowerInSatellite();
174  replicasAciIfPowerInSatellite += replica.rxParams->GetRxAciIfPowerInSatellite();
175  replicasExtNoisePowerInSatellite +=
176  replica.rxParams->GetRxExtNoisePowerInSatellite();
177  }
178 
179  double sinr = CalculateSinr(replicasCountSquared * currentPacket->rxParams->m_rxPower_W,
180  replicasIfPower,
181  replicasNoisePower,
182  replicasAciIfPower,
183  replicasExtNoisePower,
185 
187  double cSinr;
189  {
190  double sinrSatellite = CalculateSinr(
191  replicasCountSquared * currentPacket->rxParams->GetRxPowerInSatellite(),
192  replicasIfPowerInSatellite,
193  replicasNoisePowerInSatellite,
194  replicasAciIfPowerInSatellite,
195  replicasExtNoisePowerInSatellite,
196  currentPacket->rxParams->GetAdditionalInterference());
197  cSinr = CalculateCompositeSinr(sinr, sinrSatellite);
198  }
199  else
200  {
201  cSinr = sinr;
202  }
203 
205  currentPacket->rxParams->m_packetsInBurst;
206  SatSignalParameters::PacketsInBurst_t::const_iterator i;
207  for (i = packets.begin(); i != packets.end(); i++)
208  {
209  SatUplinkInfoTag satUplinkInfoTag;
210  (*i)->RemovePacketTag(satUplinkInfoTag);
211  satUplinkInfoTag.SetSinr(sinr, m_additionalInterferenceCallback());
212  (*i)->AddPacketTag(satUplinkInfoTag);
213  }
214 
215  /*
216  * Update link specific SINR trace for the RETURN_FEEDER link. The RETURN_USER
217  * link SINR is already updated at the SatPhyRxCarrier::EndRxDataTransparent ()
218  * method!
219  */
220  m_linkSinrTrace(SatUtils::LinearToDb(cSinr), currentPacket->sourceAddress);
221 
222  NS_LOG_INFO("MARSALA correlation computation, Replicas: "
223  << replicasCount << " Interferents: "
224  << (packetsInSlotsCount - replicasCount) << " Correlated SINR: " << cSinr);
225 
226  currentPacket->phyError = CheckAgainstLinkResults(cSinr, currentPacket->rxParams);
227 
228  uint32_t correlations = 1;
229  for (uint32_t i = nbSlots - otherReplicasCount; i < nbSlots; ++i)
230  {
231  correlations *= i;
232  }
233  m_marsalaCorrelationRxTrace(correlations,
234  currentPacket->sourceAddress,
235  currentPacket->phyError);
236 
237  NS_LOG_INFO("Packet error: " << currentPacket->phyError);
238 
239  if (!currentPacket->phyError)
240  {
241  // Save packet for further processing
242  SatPhyRxCarrierPerFrame::crdsaPacketRxParams_s processedPacket = *currentPacket;
243  NS_LOG_INFO("Packet successfully received, removing its interference and "
244  "processing the replicas");
245 
246  slotContent.erase(currentPacket);
247  EliminateInterference(iter, processedPacket);
248  FindAndRemoveReplicas(processedPacket);
249  combinedPacketsForFrame.push_back(processedPacket);
250 
251  return true;
252  }
253  }
254  }
255 
256  return false;
257 }
258 
259 } // 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.