Loading...
Searching...
No Matches
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#include <map>
29#include <utility>
30
31NS_LOG_COMPONENT_DEFINE("SatChannelPair");
32
33namespace ns3
34{
35
36NS_OBJECT_ENSURE_REGISTERED(SatChannelPair);
37
38TypeId
40{
41 static TypeId tid =
42 TypeId("ns3::SatChannelPair").SetParent<Object>().AddConstructor<SatChannelPair>();
43 return tid;
44}
45
47 : m_frequencies(),
50{
51 NS_LOG_FUNCTION(this);
52}
53
55{
56 NS_LOG_FUNCTION(this);
57 m_frequencies.clear();
58 m_fwdChannels.clear();
59 m_rtnChannels.clear();
60}
61
63SatChannelPair::GetChannelPair(uint32_t satId, uint32_t beamId) const
64{
65 NS_LOG_FUNCTION(this << beamId);
66
67 std::map<std::pair<uint32_t, uint32_t>, std::pair<uint32_t, uint32_t>>::const_iterator
68 frequencyIterator = m_frequencies.find(std::make_pair(satId, beamId));
69 if (frequencyIterator == m_frequencies.end())
70 {
71 NS_FATAL_ERROR("No SatChannel stored for this beam");
72 }
73
74 std::pair<uint32_t, uint32_t> frequenciesIds = frequencyIterator->second;
75
76 return std::make_pair(GetForwardChannel(satId, frequenciesIds.first),
77 GetReturnChannel(satId, frequenciesIds.second));
78}
79
80Ptr<SatChannel>
81SatChannelPair::GetForwardChannel(uint32_t satId, uint32_t frequencyId) const
82{
83 std::map<std::pair<uint32_t, uint32_t>, Ptr<SatChannel>>::const_iterator channelIterator =
84 m_fwdChannels.find(std::make_pair(satId, frequencyId));
85 if (channelIterator == m_fwdChannels.end())
86 {
87 NS_FATAL_ERROR("No SatChannel stored for the forward frequency "
88 << frequencyId << " and satellite " << satId);
89 }
90
91 return channelIterator->second;
92}
93
94Ptr<SatChannel>
95SatChannelPair::GetReturnChannel(uint32_t satId, uint32_t frequencyId) const
96{
97 std::map<std::pair<uint32_t, uint32_t>, Ptr<SatChannel>>::const_iterator channelIterator =
98 m_rtnChannels.find(std::make_pair(satId, frequencyId));
99 if (channelIterator == m_rtnChannels.end())
100 {
101 NS_FATAL_ERROR("No SatChannel stored for the return frequency "
102 << frequencyId << " and satellite " << satId);
103 }
104
105 return channelIterator->second;
106}
107
108bool
109SatChannelPair::HasFwdChannel(uint32_t satId, uint32_t frequencyId) const
110{
111 NS_LOG_FUNCTION(this << frequencyId);
112
113 std::map<std::pair<uint32_t, uint32_t>, Ptr<SatChannel>>::const_iterator channel =
114 m_fwdChannels.find(std::make_pair(satId, frequencyId));
115 return channel != m_fwdChannels.end();
116}
117
118bool
119SatChannelPair::HasRtnChannel(uint32_t satId, uint32_t frequencyId) const
120{
121 NS_LOG_FUNCTION(this << frequencyId);
122
123 std::map<std::pair<uint32_t, uint32_t>, Ptr<SatChannel>>::const_iterator channel =
124 m_rtnChannels.find(std::make_pair(satId, frequencyId));
125 return channel != m_rtnChannels.end();
126}
127
128void
130 uint32_t beamId,
131 uint32_t fwdFrequencyId,
132 uint32_t rtnFrequencyId)
133{
134 NS_LOG_FUNCTION(this << satId << beamId << fwdFrequencyId << rtnFrequencyId);
135
136 std::pair<uint32_t, uint32_t> frequenciesIds = std::make_pair(fwdFrequencyId, rtnFrequencyId);
137 std::pair<std::pair<uint32_t, uint32_t>, std::pair<uint32_t, uint32_t>> frequencyKey =
138 std::make_pair(std::make_pair(satId, beamId), frequenciesIds);
139 std::pair<std::map<std::pair<uint32_t, uint32_t>, std::pair<uint32_t, uint32_t>>::iterator,
140 bool>
141 frequencyCreated = m_frequencies.insert(frequencyKey);
142 if (!frequencyCreated.second)
143 {
144 NS_FATAL_ERROR("SatChannel pair already created for this beam");
145 }
146}
147
148void
150 uint32_t beamId,
151 uint32_t fwdFrequencyId,
152 Ptr<SatChannel> fwdChannel,
153 uint32_t rtnFrequencyId,
154 Ptr<SatChannel> rtnChannel)
155{
156 NS_LOG_FUNCTION(this << satId << beamId << fwdFrequencyId << fwdChannel << rtnFrequencyId
157 << rtnChannel);
158
159 std::map<std::pair<uint32_t, uint32_t>, Ptr<SatChannel>>::iterator fwdChannelIterator =
160 m_fwdChannels.find(std::make_pair(satId, fwdFrequencyId));
161 if (fwdChannelIterator != m_fwdChannels.end() && fwdChannelIterator->second != fwdChannel)
162 {
163 NS_FATAL_ERROR("SatChannel already created for the forward frequency " << fwdFrequencyId);
164 }
165
166 std::map<std::pair<uint32_t, uint32_t>, Ptr<SatChannel>>::iterator rtnChannelIterator =
167 m_rtnChannels.find(std::make_pair(satId, rtnFrequencyId));
168 if (rtnChannelIterator != m_rtnChannels.end() && rtnChannelIterator->second != rtnChannel)
169 {
170 NS_FATAL_ERROR("SatChannel already created for the return frequency " << rtnFrequencyId);
171 }
172
173 m_fwdChannels.emplace(std::make_pair(satId, fwdFrequencyId), fwdChannel);
174 m_rtnChannels.emplace(std::make_pair(satId, rtnFrequencyId), rtnChannel);
175
176 UpdateBeamsForFrequency(satId, beamId, fwdFrequencyId, rtnFrequencyId);
177}
178
179} // namespace ns3
Container of Satellite channels pairs.
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.