satellite-beam-channel-pair.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 "satellite-enums.h"
24 
25 #include <ns3/fatal-error.h>
26 #include <ns3/log.h>
27 
28 NS_LOG_COMPONENT_DEFINE("SatChannelPair");
29 
30 namespace ns3
31 {
32 
33 NS_OBJECT_ENSURE_REGISTERED(SatChannelPair);
34 
35 TypeId
37 {
38  static TypeId tid =
39  TypeId("ns3::SatChannelPair").SetParent<Object>().AddConstructor<SatChannelPair>();
40  return tid;
41 }
42 
44  : m_frequencies(),
45  m_fwdChannels(),
46  m_rtnChannels()
47 {
48  NS_LOG_FUNCTION(this);
49 }
50 
52 {
53  NS_LOG_FUNCTION(this);
54  m_frequencies.clear();
55  m_fwdChannels.clear();
56  m_rtnChannels.clear();
57 }
58 
60 SatChannelPair::GetChannelPair(uint32_t satId, uint32_t beamId) const
61 {
62  NS_LOG_FUNCTION(this << beamId);
63 
64  std::map<std::pair<uint32_t, uint32_t>, std::pair<uint32_t, uint32_t>>::const_iterator
65  frequencyIterator = m_frequencies.find(std::make_pair(satId, beamId));
66  if (frequencyIterator == m_frequencies.end())
67  {
68  NS_FATAL_ERROR("No SatChannel stored for this beam");
69  }
70 
71  std::pair<uint32_t, uint32_t> frequenciesIds = frequencyIterator->second;
72 
73  return std::make_pair(GetForwardChannel(satId, frequenciesIds.first),
74  GetReturnChannel(satId, frequenciesIds.second));
75 }
76 
77 Ptr<SatChannel>
78 SatChannelPair::GetForwardChannel(uint32_t satId, uint32_t frequencyId) const
79 {
80  std::map<std::pair<uint32_t, uint32_t>, Ptr<SatChannel>>::const_iterator channelIterator =
81  m_fwdChannels.find(std::make_pair(satId, frequencyId));
82  if (channelIterator == m_fwdChannels.end())
83  {
84  NS_FATAL_ERROR("No SatChannel stored for the forward frequency "
85  << frequencyId << " and satellite " << satId);
86  }
87 
88  return channelIterator->second;
89 }
90 
91 Ptr<SatChannel>
92 SatChannelPair::GetReturnChannel(uint32_t satId, uint32_t frequencyId) const
93 {
94  std::map<std::pair<uint32_t, uint32_t>, Ptr<SatChannel>>::const_iterator channelIterator =
95  m_rtnChannels.find(std::make_pair(satId, frequencyId));
96  if (channelIterator == m_rtnChannels.end())
97  {
98  NS_FATAL_ERROR("No SatChannel stored for the return frequency "
99  << frequencyId << " and satellite " << satId);
100  }
101 
102  return channelIterator->second;
103 }
104 
105 bool
106 SatChannelPair::HasFwdChannel(uint32_t satId, uint32_t frequencyId) const
107 {
108  NS_LOG_FUNCTION(this << frequencyId);
109 
110  std::map<std::pair<uint32_t, uint32_t>, Ptr<SatChannel>>::const_iterator channel =
111  m_fwdChannels.find(std::make_pair(satId, frequencyId));
112  return channel != m_fwdChannels.end();
113 }
114 
115 bool
116 SatChannelPair::HasRtnChannel(uint32_t satId, uint32_t frequencyId) const
117 {
118  NS_LOG_FUNCTION(this << frequencyId);
119 
120  std::map<std::pair<uint32_t, uint32_t>, Ptr<SatChannel>>::const_iterator channel =
121  m_rtnChannels.find(std::make_pair(satId, frequencyId));
122  return channel != m_rtnChannels.end();
123 }
124 
125 void
127  uint32_t beamId,
128  uint32_t fwdFrequencyId,
129  uint32_t rtnFrequencyId)
130 {
131  NS_LOG_FUNCTION(this << satId << beamId << fwdFrequencyId << rtnFrequencyId);
132 
133  std::pair<uint32_t, uint32_t> frequenciesIds = std::make_pair(fwdFrequencyId, rtnFrequencyId);
134  std::pair<std::pair<uint32_t, uint32_t>, std::pair<uint32_t, uint32_t>> frequencyKey =
135  std::make_pair(std::make_pair(satId, beamId), frequenciesIds);
136  std::pair<std::map<std::pair<uint32_t, uint32_t>, std::pair<uint32_t, uint32_t>>::iterator,
137  bool>
138  frequencyCreated = m_frequencies.insert(frequencyKey);
139  if (!frequencyCreated.second)
140  {
141  NS_FATAL_ERROR("SatChannel pair already created for this beam");
142  }
143 }
144 
145 void
147  uint32_t beamId,
148  uint32_t fwdFrequencyId,
149  Ptr<SatChannel> fwdChannel,
150  uint32_t rtnFrequencyId,
151  Ptr<SatChannel> rtnChannel)
152 {
153  NS_LOG_FUNCTION(this << satId << beamId << fwdFrequencyId << fwdChannel << rtnFrequencyId
154  << rtnChannel);
155 
156  std::map<std::pair<uint32_t, uint32_t>, Ptr<SatChannel>>::iterator fwdChannelIterator =
157  m_fwdChannels.find(std::make_pair(satId, fwdFrequencyId));
158  if (fwdChannelIterator != m_fwdChannels.end() && fwdChannelIterator->second != fwdChannel)
159  {
160  NS_FATAL_ERROR("SatChannel already created for the forward frequency " << fwdFrequencyId);
161  }
162 
163  std::map<std::pair<uint32_t, uint32_t>, Ptr<SatChannel>>::iterator rtnChannelIterator =
164  m_rtnChannels.find(std::make_pair(satId, rtnFrequencyId));
165  if (rtnChannelIterator != m_rtnChannels.end() && rtnChannelIterator->second != rtnChannel)
166  {
167  NS_FATAL_ERROR("SatChannel already created for the return frequency " << rtnFrequencyId);
168  }
169 
170  m_fwdChannels.emplace(std::make_pair(satId, fwdFrequencyId), fwdChannel);
171  m_rtnChannels.emplace(std::make_pair(satId, rtnFrequencyId), rtnChannel);
172 
173  UpdateBeamsForFrequency(satId, beamId, fwdFrequencyId, rtnFrequencyId);
174 }
175 
176 } // namespace ns3
virtual ~SatChannelPair()
Destructor for SatChannel.
Ptr< SatChannel > GetForwardChannel(uint32_t satId, uint32_t frequencyId) const
Ptr< SatChannel > GetReturnChannel(uint32_t satId, uint32_t frequencyId) const
bool HasFwdChannel(uint32_t satId, uint32_t frequencyId) const
Test if a channel pair has been stored for a given color.
void UpdateBeamsForFrequency(uint32_t satId, uint32_t beamdId, uint32_t fwdFrequencyId, uint32_t rtnFrequencyId)
Associate a new beam to a given color.
std::map< std::pair< uint32_t, uint32_t >, Ptr< SatChannel > > m_fwdChannels
static TypeId GetTypeId(void)
Get the type ID.
bool HasRtnChannel(uint32_t satId, uint32_t frequencyId) const
std::map< std::pair< uint32_t, uint32_t >, Ptr< SatChannel > > m_rtnChannels
std::pair< Ptr< SatChannel >, Ptr< SatChannel > > ChannelPair_t
ChannelPair_t GetChannelPair(uint32_t satId, uint32_t beamId) const
Retrieve the channel pair associated to a beam.
std::map< std::pair< uint32_t, uint32_t >, std::pair< uint32_t, uint32_t > > m_frequencies
void StoreChannelPair(uint32_t satId, uint32_t beamId, uint32_t fwdFrequencyId, Ptr< SatChannel > fwdChannel, uint32_t rtnFrequencyId, Ptr< SatChannel > rtnChannel)
Store a pair of SatChannel for the given color and associate the given beam to said color.
SatChannelPair()
Default constructor.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.