Loading...
Searching...
No Matches
satellite-orbiter-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
37#include <utility>
38
39NS_LOG_COMPONENT_DEFINE("SatOrbiterMac");
40
41namespace ns3
42{
43
44NS_OBJECT_ENSURE_REGISTERED(SatOrbiterMac);
45
46TypeId
48{
49 static TypeId tid =
50 TypeId("ns3::SatOrbiterMac")
51 .SetParent<SatMac>()
52 .AddAttribute(
53 "DisableSchedulingIfNoDeviceConnected",
54 "If true, the periodic calls of StartTransmission are not called when no "
55 "devices are connected to this MAC",
56 BooleanValue(false),
58 MakeBooleanChecker())
59 .AddTraceSource("BBFrameTxTrace",
60 "Trace for transmitted BB Frames.",
61 MakeTraceSourceAccessor(&SatOrbiterMac::m_bbFrameTxTrace),
62 "ns3::SatBbFrame::BbFrameCallback");
63
64 return tid;
65}
66
68{
69 NS_LOG_FUNCTION(this);
70 NS_FATAL_ERROR("SatOrbiterMac default constructor is not allowed to use");
71}
72
73SatOrbiterMac::SatOrbiterMac(uint32_t satId, uint32_t beamId)
74 : SatMac(satId, beamId),
77 m_guardTime(MicroSeconds(1)),
78 m_satId(satId),
79 m_beamId(beamId),
81{
82 NS_LOG_FUNCTION(this);
83}
84
86{
87 NS_LOG_FUNCTION(this);
88}
89
90void
92{
93 NS_LOG_FUNCTION(this);
94 Object::DoDispose();
95}
96
97void
99{
100 NS_LOG_FUNCTION(this);
101 Object::DoInitialize();
102}
103
104void
106{
107 NS_LOG_FUNCTION(this);
108
110 {
111 NS_LOG_INFO("Do not start beam " << m_beamId << " because no device is connected");
112 return;
113 }
114
116 {
117 NS_LOG_INFO("Beam " << m_beamId << " already enabled");
118 return;
119 }
120
122
123 if (m_fwdScheduler == nullptr)
124 {
125 NS_FATAL_ERROR("Scheduler not set for orbiter MAC!!!");
126 }
127
128 m_llc->ClearQueues();
129
130 Simulator::Schedule(Seconds(0), &SatOrbiterMac::StartTransmission, this, 0);
131}
132
133void
135{
136 NS_LOG_FUNCTION(this << carrierId);
137
138 Time txDuration;
139
141 {
142 std::pair<Ptr<SatBbFrame>, const Time> bbFrameInfo = m_fwdScheduler->GetNextFrame();
143 Ptr<SatBbFrame> bbFrame = bbFrameInfo.first;
144 txDuration = bbFrameInfo.second;
145
146 // trace out BB frames sent
147 m_bbFrameTxTrace(bbFrame);
148
149 // Handle both dummy frames and normal frames
150 if (bbFrame != nullptr)
151 {
154 txInfo.modCod = bbFrame->GetModcod();
155 txInfo.sliceId = bbFrame->GetSliceId();
156 txInfo.frameType = bbFrame->GetFrameType();
157 txInfo.waveformId = 0;
158
162 SendPacket(bbFrame->GetPayload(), carrierId, txDuration - m_guardTime, txInfo);
163 }
164 }
165 else
166 {
171
172 NS_LOG_INFO("TX is disabled, thus nothing is transmitted!");
173 txDuration = m_fwdScheduler->GetDefaultFrameDuration();
174 }
175
177 {
178 Simulator::Schedule(txDuration, &SatOrbiterMac::StartTransmission, this, 0);
179 }
180}
181
182void
184 uint32_t carrierId,
185 Time duration,
187{
188 NS_LOG_FUNCTION(this);
189
190 // Add a SatMacTimeTag tag for packet delay computation at the receiver end.
191 SetTimeTag(packets);
192
193 // Add packet trace entry:
194 m_packetTrace(Simulator::Now(),
196 m_nodeInfo->GetNodeType(),
197 m_nodeInfo->GetNodeId(),
198 m_nodeInfo->GetMacAddress(),
201 SatUtils::GetPacketInfo(packets));
202
203 Ptr<SatSignalParameters> txParams = CreateObject<SatSignalParameters>();
204 txParams->m_duration = duration;
205 txParams->m_packetsInBurst = packets;
206 txParams->m_satId = m_satId;
207 txParams->m_beamId = m_beamId;
208 txParams->m_carrierId = carrierId;
209 txParams->m_txInfo = txInfo;
210
211 // Use call back to send packet to lower layer
212 m_txCallback(txParams);
213}
214
215void
217{
218 NS_LOG_FUNCTION(this);
219
221 {
222 for (SatPhy::PacketContainer_t::const_iterator it1 = packets.begin(); it1 != packets.end();
223 ++it1)
224 {
225 // Remove packet tag
226 SatMacTag macTag;
227 bool mSuccess = (*it1)->PeekPacketTag(macTag);
228 if (!mSuccess)
229 {
230 NS_FATAL_ERROR("MAC tag was not found from the packet!");
231 }
232
233 // If the packet is intended for this receiver
234 Mac48Address destAddress = macTag.GetDestAddress();
235
236 if (destAddress == m_nodeInfo->GetMacAddress())
237 {
238 Address addr = GetRxUtAddress(*it1);
239
240 m_rxTrace(*it1, addr);
241
242 SatMacLinkTimeTag linkTimeTag;
243 if ((*it1)->RemovePacketTag(linkTimeTag))
244 {
245 NS_LOG_DEBUG(this << " contains a SatMacLinkTimeTag tag");
246 Time delay = Simulator::Now() - linkTimeTag.GetSenderLinkTimestamp();
247 m_rxLinkDelayTrace(delay, addr);
248 if (m_lastLinkDelay.IsZero() == false)
249 {
250 Time jitter = Abs(delay - m_lastLinkDelay);
251 m_rxLinkJitterTrace(jitter, addr);
252 }
253 m_lastLinkDelay = delay;
254 }
255 } // end of `if (destAddress == m_nodeInfo->GetMacAddress () || destAddress.IsBroadcast
256 // ())`
257 } // end of `for it1 = packets.begin () -> packets.end ()`
258 } // end of `if (m_isStatisticsTagsEnabled)`
259}
260
261void
262SatOrbiterMac::SetFwdScheduler(Ptr<SatFwdLinkScheduler> fwdScheduler)
263{
264 m_fwdScheduler = fwdScheduler;
265}
266
267void
268SatOrbiterMac::SetLlc(Ptr<SatOrbiterLlc> llc)
269{
270 m_llc = llc;
271}
272
273Time
275{
276 return m_guardTime;
277}
278
279void
281{
282 m_guardTime = guardTime;
283}
284
285void
287{
288 NS_LOG_FUNCTION(this << &cb);
289 m_txCallback = cb;
290}
291
292void
294{
295 NS_LOG_FUNCTION(this << &cb);
297}
298
299void
301{
302 NS_LOG_FUNCTION(this);
303
305
306 m_llc->ClearQueues();
307}
308
309} // namespace ns3
bool m_isStatisticsTagsEnabled
EnableStatisticsTags attribute.
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.
void SetTimeTag(SatPhy::PacketContainer_t packets)
Set SatMacTimeTag of packets.
TracedCallback< const Time &, const Address & > m_rxLinkJitterTrace
Traced callback for all received packets, including link jitter information and the address of the se...
TracedCallback< Ptr< const Packet >, const Address & > m_rxTrace
Traced callback for all received packets, including the address of the senders.
bool m_txEnabled
Flag indicating whether the MAC is enabled, i.e.
TracedCallback< const Time &, const Address & > m_rxLinkDelayTrace
Traced callback for all received packets, including link delay information and the address of the sen...
SatMac()
Construct a SatMac.
Ptr< SatNodeInfo > m_nodeInfo
Node info containing node related information, such as node type, node id and MAC address (of the Sat...
Time m_lastLinkDelay
Last delay measurement for link.
This class implements a tag that carries the satellite MAC specific information, such as source and d...
Mac48Address GetDestAddress(void) const
Get destination MAC address.
The SatOrbiterMac models the global link MAC layer of the satellite node.
bool m_disableSchedulingIfNoDeviceConnected
If true, the periodic calls of StartTransmission are not called when no devices are connected to this...
uint32_t m_satId
ID of sat for UT.
SatOrbiterMac(void)
Default constructor.
virtual void SendPacket(SatPhy::PacketContainer_t packets, uint32_t carrierId, Time duration, SatSignalParameters::txInfo_s txInfo)
Send packets to lower layer by using a callback.
Ptr< SatOrbiterLlc > m_llc
LLC layer linked to this MAC.
Callback< void, SatPhy::PacketContainer_t, Ptr< SatSignalParameters > > ReceiveNetDeviceCallback
virtual Address GetRxUtAddress(Ptr< Packet > packet)=0
Get the UT address associated to this RX packet.
uint32_t m_beamId
ID of beam for UT.
virtual Time GetGuardTime() const
void SetTransmitCallback(SatOrbiterMac::TransmitCallback cb)
Time m_guardTime
Guard time for BB frames.
TransmitCallback m_txCallback
virtual ~SatOrbiterMac()
Destructor for SatOrbiterMac.
virtual void DoInitialize(void)
void StartTransmission(uint32_t carrierId)
Start sending a Packet Down the Wire.
void SetLlc(Ptr< SatOrbiterLlc > llc)
Set the orbiter LLC associated to this orbiter MAC layer.
virtual SatEnums::SatLinkDir_t GetSatLinkTxDir()=0
Get the link TX direction.
bool m_periodicTransmissionEnabled
Indicated if periodic transmission is enabled.
virtual void SetGuardTime(Time guardTime)
virtual void DoDispose(void)
Dispose of this class instance.
virtual void StopPeriodicTransmissions()
Stop periodic transmission, until a pacquet in enqued.
ReceiveNetDeviceCallback m_rxNetDeviceCallback
void StartPeriodicTransmissions()
Starts periodical transmissions.
static TypeId GetTypeId(void)
inherited from Object
void SetFwdScheduler(Ptr< SatFwdLinkScheduler > fwdScheduler)
Method to set link scheduler (forward or SCPC).
Callback< void, Ptr< SatSignalParameters > > TransmitCallback
TracedCallback< Ptr< SatBbFrame > > m_bbFrameTxTrace
Trace for transmitted BB frames.
Ptr< SatFwdLinkScheduler > m_fwdScheduler
Scheduler for the forward link.
void SetReceiveNetDeviceCallback(SatOrbiterMac::ReceiveNetDeviceCallback cb)
virtual void RxTraces(SatPhy::PacketContainer_t packets)
Invoke the Rx trace source for each received packet.
virtual bool HasPeer()=0
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.
Struct for storing the packet specific Tx information.