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 
21 #include "satellite-orbiter-mac.h"
22 
23 #include "satellite-address-tag.h"
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 
39 NS_LOG_COMPONENT_DEFINE("SatOrbiterMac");
40 
41 namespace ns3
42 {
43 
44 NS_OBJECT_ENSURE_REGISTERED(SatOrbiterMac);
45 
46 TypeId
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 
67 TypeId
69 {
70  NS_LOG_FUNCTION(this);
71 
72  return GetTypeId();
73 }
74 
76 {
77  NS_LOG_FUNCTION(this);
78  NS_FATAL_ERROR("SatOrbiterMac default constructor is not allowed to use");
79 }
80 
81 SatOrbiterMac::SatOrbiterMac(uint32_t satId, uint32_t beamId)
82  : SatMac(satId, beamId),
83  m_disableSchedulingIfNoDeviceConnected(false),
84  m_fwdScheduler(),
85  m_guardTime(MicroSeconds(1)),
86  m_satId(satId),
87  m_beamId(beamId),
88  m_periodicTransmissionEnabled(false)
89 {
90  NS_LOG_FUNCTION(this);
91 }
92 
94 {
95  NS_LOG_FUNCTION(this);
96 }
97 
98 void
100 {
101  NS_LOG_FUNCTION(this);
102  Object::DoDispose();
103 }
104 
105 void
107 {
108  NS_LOG_FUNCTION(this);
109  Object::DoInitialize();
110 }
111 
112 void
114 {
115  NS_LOG_FUNCTION(this);
116 
118  {
119  NS_LOG_INFO("Do not start beam " << m_beamId << " because no device is connected");
120  return;
121  }
122 
123  if (m_periodicTransmissionEnabled == true)
124  {
125  NS_LOG_INFO("Beam " << m_beamId << " already enabled");
126  return;
127  }
128 
130 
131  if (m_fwdScheduler == nullptr)
132  {
133  NS_FATAL_ERROR("Scheduler not set for orbiter MAC!!!");
134  }
135 
136  m_llc->ClearQueues();
137 
138  Simulator::Schedule(Seconds(0), &SatOrbiterMac::StartTransmission, this, 0);
139 }
140 
141 void
143 {
144  NS_LOG_FUNCTION(this << carrierId);
145 
146  Time txDuration;
147 
149  {
150  std::pair<Ptr<SatBbFrame>, const Time> bbFrameInfo = m_fwdScheduler->GetNextFrame();
151  Ptr<SatBbFrame> bbFrame = bbFrameInfo.first;
152  txDuration = bbFrameInfo.second;
153 
154  // trace out BB frames sent
155  m_bbFrameTxTrace(bbFrame);
156 
157  // Handle both dummy frames and normal frames
158  if (bbFrame != nullptr)
159  {
162  txInfo.modCod = bbFrame->GetModcod();
163  txInfo.sliceId = bbFrame->GetSliceId();
164  txInfo.frameType = bbFrame->GetFrameType();
165  txInfo.waveformId = 0;
166 
170  SendPacket(bbFrame->GetPayload(), carrierId, txDuration - m_guardTime, txInfo);
171  }
172  }
173  else
174  {
180  NS_LOG_INFO("TX is disabled, thus nothing is transmitted!");
181  txDuration = m_fwdScheduler->GetDefaultFrameDuration();
182  }
183 
185  {
186  Simulator::Schedule(txDuration, &SatOrbiterMac::StartTransmission, this, 0);
187  }
188 }
189 
190 void
192  uint32_t carrierId,
193  Time duration,
195 {
196  NS_LOG_FUNCTION(this);
197 
198  // Add a SatMacTimeTag tag for packet delay computation at the receiver end.
199  SetTimeTag(packets);
200 
201  // Add packet trace entry:
202  m_packetTrace(Simulator::Now(),
204  m_nodeInfo->GetNodeType(),
205  m_nodeInfo->GetNodeId(),
206  m_nodeInfo->GetMacAddress(),
208  GetSatLinkTxDir(),
209  SatUtils::GetPacketInfo(packets));
210 
211  Ptr<SatSignalParameters> txParams = Create<SatSignalParameters>();
212  txParams->m_duration = duration;
213  txParams->m_packetsInBurst = packets;
214  txParams->m_satId = m_satId;
215  txParams->m_beamId = m_beamId;
216  txParams->m_carrierId = carrierId;
217  txParams->m_txInfo = txInfo;
218 
219  // Use call back to send packet to lower layer
220  m_txCallback(txParams);
221 }
222 
223 void
225 {
226  NS_LOG_FUNCTION(this);
227 
229  {
230  for (SatPhy::PacketContainer_t::const_iterator it1 = packets.begin(); it1 != packets.end();
231  ++it1)
232  {
233  // Remove packet tag
234  SatMacTag macTag;
235  bool mSuccess = (*it1)->PeekPacketTag(macTag);
236  if (!mSuccess)
237  {
238  NS_FATAL_ERROR("MAC tag was not found from the packet!");
239  }
240 
241  // If the packet is intended for this receiver
242  Mac48Address destAddress = macTag.GetDestAddress();
243 
244  if (destAddress == m_nodeInfo->GetMacAddress())
245  {
246  Address addr = GetRxUtAddress(*it1);
247 
248  m_rxTrace(*it1, addr);
249 
250  SatMacLinkTimeTag linkTimeTag;
251  if ((*it1)->RemovePacketTag(linkTimeTag))
252  {
253  NS_LOG_DEBUG(this << " contains a SatMacLinkTimeTag tag");
254  Time delay = Simulator::Now() - linkTimeTag.GetSenderLinkTimestamp();
255  m_rxLinkDelayTrace(delay, addr);
256  if (m_lastLinkDelay.IsZero() == false)
257  {
258  Time jitter = Abs(delay - m_lastLinkDelay);
259  m_rxLinkJitterTrace(jitter, addr);
260  }
261  m_lastLinkDelay = delay;
262  }
263  } // end of `if (destAddress == m_nodeInfo->GetMacAddress () || destAddress.IsBroadcast
264  // ())`
265  } // end of `for it1 = packets.begin () -> packets.end ()`
266  } // end of `if (m_isStatisticsTagsEnabled)`
267 }
268 
269 void
270 SatOrbiterMac::SetFwdScheduler(Ptr<SatFwdLinkScheduler> fwdScheduler)
271 {
272  m_fwdScheduler = fwdScheduler;
273 }
274 
275 void
276 SatOrbiterMac::SetLlc(Ptr<SatOrbiterLlc> llc)
277 {
278  m_llc = llc;
279 }
280 
281 Time
283 {
284  return m_guardTime;
285 }
286 
287 void
289 {
290  m_guardTime = guardTime;
291 }
292 
293 void
295 {
296  NS_LOG_FUNCTION(this << &cb);
297  m_txCallback = cb;
298 }
299 
300 void
302 {
303  NS_LOG_FUNCTION(this << &cb);
305 }
306 
307 void
309 {
310  NS_LOG_FUNCTION(this);
311 
313 
314  m_llc->ClearQueues();
315 }
316 
317 } // namespace ns3
Base MAC class for SatNetDevices.
Definition: satellite-mac.h:57
Callback< void, SatPhy::PacketContainer_t, uint32_t, Time, SatSignalParameters::txInfo_s > TransmitCallback
Callback to send packet to lower layer.
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...
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.
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)
TracedCallback< Ptr< SatBbFrame > > m_bbFrameTxTrace
Trace for transmitted BB frames.
TypeId GetInstanceTypeId(void) const
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.
Definition: satellite-phy.h:79
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.