Loading...
Searching...
No Matches
satellite-orbiter-user-mac.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2013 Magister Solutions Ltd.
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: Bastien Tauran <bastien.tauran@viveris.fr>
19 */
20
22
24#include "satellite-mac.h"
26#include "satellite-time-tag.h"
28#include "satellite-utils.h"
29
30#include "ns3/double.h"
31#include "ns3/enum.h"
32#include "ns3/log.h"
33#include "ns3/pointer.h"
34#include "ns3/simulator.h"
35#include "ns3/uinteger.h"
36
37NS_LOG_COMPONENT_DEFINE("SatOrbiterUserMac");
38
39namespace ns3
40{
41
42NS_OBJECT_ENSURE_REGISTERED(SatOrbiterUserMac);
43
44TypeId
46{
47 static TypeId tid = TypeId("ns3::SatOrbiterUserMac")
48 .SetParent<SatOrbiterMac>()
49 .AddConstructor<SatOrbiterUserMac>()
50 .AddAttribute("GuardTime",
51 "Guard time in this fwd user link scheduler",
52 TimeValue(MicroSeconds(1)),
53 MakeTimeAccessor(&SatOrbiterMac::GetGuardTime,
55 MakeTimeChecker());
56 return tid;
57}
58
60{
61 NS_LOG_FUNCTION(this);
62 NS_FATAL_ERROR("SatOrbiterUserMac default constructor is not allowed to use");
63}
64
65SatOrbiterUserMac::SatOrbiterUserMac(uint32_t satId, uint32_t beamId)
66 : SatOrbiterMac(satId, beamId)
67{
68 NS_LOG_FUNCTION(this << satId << beamId);
69}
70
72{
73 NS_LOG_FUNCTION(this);
74}
75
76void
78{
79 NS_LOG_FUNCTION(this);
80
81 m_peers.clear();
82
83 Object::DoDispose();
84}
85
86void
88{
89 NS_LOG_FUNCTION(this);
90 Object::DoInitialize();
91}
92
93void
95{
96 NS_LOG_FUNCTION(this << packet);
97
99 {
100 NS_LOG_INFO("Do not enque packet to this beam because it is disabled");
101 return;
102 }
103
104 SatAddressE2ETag addressE2ETag;
105 bool success = packet->PeekPacketTag(addressE2ETag);
106
107 SatMacTag mTag;
108 success &= packet->RemovePacketTag(mTag);
109
111 {
112 // MAC tag and E2E address tag found
113 if (success)
114 {
115 mTag.SetDestAddress(addressE2ETag.GetE2EDestAddress());
116 mTag.SetSourceAddress(m_nodeInfo->GetMacAddress());
117 packet->AddPacketTag(mTag);
118 }
119 }
120
121 uint8_t flowId = 1;
122 SatControlMsgTag ctrlTag;
123 if (packet->PeekPacketTag(ctrlTag))
124 {
125 flowId = 0;
126 }
127
128 m_llc->Enque(packet, addressE2ETag.GetE2EDestAddress(), flowId);
129
131}
132
133void
134SatOrbiterUserMac::Receive(SatPhy::PacketContainer_t packets, Ptr<SatSignalParameters> rxParams)
135{
136 NS_LOG_FUNCTION(this);
137
140 {
141 // Add packet trace entry:
142 m_packetTrace(Simulator::Now(),
144 m_nodeInfo->GetNodeType(),
145 m_nodeInfo->GetNodeId(),
146 m_nodeInfo->GetMacAddress(),
149 SatUtils::GetPacketInfo(packets));
150
151 RxTraces(packets);
152 }
153
154 rxParams->m_packetsInBurst.clear();
155 for (SatPhy::PacketContainer_t::iterator i = packets.begin(); i != packets.end(); i++)
156 {
157 // Remove packet tag
158 SatMacTag macTag;
159 bool mSuccess = (*i)->PeekPacketTag(macTag);
160 if (!mSuccess)
161 {
162 NS_FATAL_ERROR("MAC tag was not found from the packet!");
163 }
164
165 NS_LOG_INFO("Packet from " << macTag.GetSourceAddress() << " to "
166 << macTag.GetDestAddress());
167 NS_LOG_INFO("Receiver " << m_nodeInfo->GetMacAddress());
168
169 SatAddressE2ETag satAddressE2ETag;
170 mSuccess = (*i)->PeekPacketTag(satAddressE2ETag);
171 if (!mSuccess)
172 {
173 NS_FATAL_ERROR("SatAddressE2E tag was not found from the packet!");
174 }
175 Mac48Address destE2EAddress = satAddressE2ETag.GetE2EDestAddress();
176 if (destE2EAddress == m_nodeInfo->GetMacAddress())
177 {
178 // Remove control msg tag
179 SatControlMsgTag ctrlTag;
180 bool cSuccess = (*i)->PeekPacketTag(ctrlTag);
181
182 if (cSuccess)
183 {
185
187 {
189 }
190 else
191 {
192 NS_FATAL_ERROR("A control message received with not valid msg type!");
193 }
194 }
195 }
196 else
197 {
198 rxParams->m_packetsInBurst.push_back(*i);
199 }
200 }
201
203 {
204 for (SatPhy::PacketContainer_t::iterator i = rxParams->m_packetsInBurst.begin();
205 i != rxParams->m_packetsInBurst.end();
206 i++)
207 {
208 // Remove packet tag
209 SatMacTag macTag;
210 bool mSuccess = (*i)->PeekPacketTag(macTag);
211 if (!mSuccess)
212 {
213 NS_FATAL_ERROR("MAC tag was not found from the packet!");
214 }
215 Mac48Address destAddress = macTag.GetDestAddress();
216
217 NS_LOG_INFO("Packet from " << macTag.GetSourceAddress() << " to "
218 << macTag.GetDestAddress());
219 NS_LOG_INFO("Receiver " << m_nodeInfo->GetMacAddress());
220
221 if (destAddress == m_nodeInfo->GetMacAddress() || destAddress.IsBroadcast() ||
222 destAddress.IsGroup())
223 {
224 m_rxCallback(*i, macTag.GetSourceAddress(), macTag.GetDestAddress());
225 }
226 }
227 }
228 else
229 {
230 m_rxNetDeviceCallback(rxParams->m_packetsInBurst, rxParams);
231 }
232}
233
234void
236{
237 NS_LOG_FUNCTION(this << packet);
238
239 // Remove the mac tag
240 SatMacTag macTag;
241 packet->PeekPacketTag(macTag);
242
243 // Peek control msg tag
244 SatControlMsgTag ctrlTag;
245 bool cSuccess = packet->PeekPacketTag(ctrlTag);
246
247 if (!cSuccess)
248 {
249 NS_FATAL_ERROR("SatControlMsgTag not found in the packet!");
250 }
251
252 switch (ctrlTag.GetMsgType())
253 {
255 uint32_t msgId = ctrlTag.GetMsgId();
256 Ptr<SatCnoReportMessage> cnoReport =
257 DynamicCast<SatCnoReportMessage>(m_readCtrlCallback(msgId));
258
259 if (cnoReport != nullptr)
260 {
261 m_fwdScheduler->CnoInfoUpdated(macTag.GetSourceAddress(), cnoReport->GetCnoEstimate());
262 }
263 else
264 {
265 NS_LOG_WARN("Control message "
266 << ctrlTag.GetMsgType()
267 << " is not found from the RTN link control msg container!"
268 << " at: " << Now().GetSeconds() << "s");
269 }
270
271 packet->RemovePacketTag(macTag);
272 packet->RemovePacketTag(ctrlTag);
273
274 break;
275 }
276 default: {
277 NS_FATAL_ERROR("Control message unkonwn on user MAC");
278 }
279 }
280}
281
287
293
294Address
296{
297 NS_LOG_FUNCTION(this << packet);
298
299 Address utAddr; // invalid address.
300
301 SatAddressE2ETag addressE2ETag;
302 if (packet->PeekPacketTag(addressE2ETag))
303 {
304 NS_LOG_DEBUG(this << " contains a SatE2E tag");
305 utAddr = addressE2ETag.GetE2ESourceAddress();
306 }
307
308 return utAddr;
309}
310
311bool
312SatOrbiterUserMac::AddPeer(Mac48Address address)
313{
314 NS_LOG_FUNCTION(this << address);
315
316 NS_ASSERT(m_peers.find(address) == m_peers.end());
317
319 {
320 NS_LOG_INFO("Start beam " << m_beamId);
321 m_peers.insert(address);
323 }
324 else
325 {
326 m_peers.insert(address);
327 }
328
329 return true;
330}
331
332bool
333SatOrbiterUserMac::RemovePeer(Mac48Address address)
334{
335 NS_LOG_FUNCTION(this << address);
336
337 NS_ASSERT(m_peers.find(address) != m_peers.end());
338
339 m_peers.erase(address);
340
342 {
343 NS_LOG_INFO("Stop beam " << m_beamId);
345 }
346
347 return true;
348}
349
350bool
352{
353 NS_LOG_FUNCTION(this);
354
355 return !m_peers.empty();
356}
357
358} // namespace ns3
This class implements a tag that carries the satellite MAC of GW and UT.
Mac48Address GetE2ESourceAddress(void) const
Get E2E source MAC address.
Mac48Address GetE2EDestAddress(void) const
Get E2E destination MAC address.
This class implements a tag that is used to identify control messages (packages).
SatControlMsgType_t
Definition for different types of control messages.
@ SAT_NON_CTRL_MSG
SAT_NON_CTRL_MSG.
virtual uint32_t GetMsgId() const
Get message type specific identifier.
SatControlMsgType_t GetMsgType(void) const
Get type of the control message.
SatLinkDir_t
Link direction used for packet tracing.
TracedCallback< Time, SatEnums::SatPacketEvent_t, SatEnums::SatNodeType_t, uint32_t, Mac48Address, SatEnums::SatLogLevel_t, SatEnums::SatLinkDir_t, std::string > m_packetTrace
Trace callback used for packet tracing.
SatMac::ReceiveCallback m_rxCallback
The upper layer package receive callback.
SatMac::ReadCtrlMsgCallback m_readCtrlCallback
The read control message callback.
SatEnums::RegenerationMode_t m_forwardLinkRegenerationMode
Regeneration mode on forward link.
Ptr< SatNodeInfo > m_nodeInfo
Node info containing node related information, such as node type, node id and MAC address (of the Sat...
SatEnums::RegenerationMode_t m_returnLinkRegenerationMode
Regeneration mode on return link.
This class implements a tag that carries the satellite MAC specific information, such as source and d...
void SetDestAddress(Mac48Address dest)
Set destination MAC address.
Mac48Address GetSourceAddress(void) const
Get source MAC address.
Mac48Address GetDestAddress(void) const
Get destination MAC address.
void SetSourceAddress(Mac48Address source)
Set source MAC address.
bool m_disableSchedulingIfNoDeviceConnected
If true, the periodic calls of StartTransmission are not called when no devices are connected to this...
SatOrbiterMac(void)
Default constructor.
Ptr< SatOrbiterLlc > m_llc
LLC layer linked to this MAC.
uint32_t m_beamId
ID of beam for UT.
virtual Time GetGuardTime() const
bool m_periodicTransmissionEnabled
Indicated if periodic transmission is enabled.
virtual void SetGuardTime(Time guardTime)
virtual void StopPeriodicTransmissions()
Stop periodic transmission, until a pacquet in enqued.
ReceiveNetDeviceCallback m_rxNetDeviceCallback
void StartPeriodicTransmissions()
Starts periodical transmissions.
Ptr< SatFwdLinkScheduler > m_fwdScheduler
Scheduler for the forward link.
virtual void RxTraces(SatPhy::PacketContainer_t packets)
Invoke the Rx trace source for each received packet.
The SatOrbiterUserMac models the user link MAC layer of the satellite node.
virtual void EnquePacket(Ptr< Packet > packet)
Add new packet to the LLC queue.
virtual ~SatOrbiterUserMac()
Destructor for SatOrbiterUserMac.
virtual bool RemovePeer(Mac48Address address)
Remove a remote peer from this MAC.
virtual bool AddPeer(Mac48Address address)
Add a remote peer to this MAC.
std::set< Mac48Address > m_peers
List of UT MAC connected to this MAC.
void Receive(SatPhy::PacketContainer_t packets, Ptr< SatSignalParameters > txParams)
Receive packet from lower layer.
virtual void DoDispose(void)
Dispose of this class instance.
virtual SatEnums::SatLinkDir_t GetSatLinkRxDir()
Get the link RX direction.
SatOrbiterUserMac(void)
Default constructor.
virtual SatEnums::SatLinkDir_t GetSatLinkTxDir()
Get the link TX direction.
static TypeId GetTypeId(void)
inherited from Object
void ReceiveSignalingPacket(Ptr< Packet > packet)
virtual Address GetRxUtAddress(Ptr< Packet > packet)
Get the UT address associated to this RX packet.
virtual bool HasPeer()
Indicates if at least one device is connected in this beam.
SatSignalParameters::PacketsInBurst_t PacketContainer_t
Define PacketContainer in SatPhy.
static std::string GetPacketInfo(const Ptr< const Packet > p)
Get packet information in std::string for printing purposes.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.