satellite-geo-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-geo-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 NS_LOG_COMPONENT_DEFINE("SatGeoMac");
38 
39 namespace ns3
40 {
41 
42 NS_OBJECT_ENSURE_REGISTERED(SatGeoMac);
43 
44 TypeId
46 {
47  static TypeId tid = TypeId("ns3::SatGeoMac")
48  .SetParent<SatMac>()
49  .AddTraceSource("BBFrameTxTrace",
50  "Trace for transmitted BB Frames.",
51  MakeTraceSourceAccessor(&SatGeoMac::m_bbFrameTxTrace),
52  "ns3::SatBbFrame::BbFrameCallback");
53  return tid;
54 }
55 
56 TypeId
58 {
59  NS_LOG_FUNCTION(this);
60 
61  return GetTypeId();
62 }
63 
65 {
66  NS_LOG_FUNCTION(this);
67  NS_FATAL_ERROR("SatGeoMac default constructor is not allowed to use");
68 }
69 
70 SatGeoMac::SatGeoMac(uint32_t satId,
71  uint32_t beamId,
72  SatEnums::RegenerationMode_t forwardLinkRegenerationMode,
73  SatEnums::RegenerationMode_t returnLinkRegenerationMode)
74  : SatMac(satId, beamId, forwardLinkRegenerationMode, returnLinkRegenerationMode),
75  m_fwdScheduler(),
76  m_guardTime(MicroSeconds(1)),
77  m_satId(satId),
78  m_beamId(beamId)
79 {
80  NS_LOG_FUNCTION(this);
81 }
82 
84 {
85  NS_LOG_FUNCTION(this);
86 }
87 
88 void
90 {
91  NS_LOG_FUNCTION(this);
92  Object::DoDispose();
93 }
94 
95 void
97 {
98  NS_LOG_FUNCTION(this);
99  Object::DoInitialize();
100 }
101 
102 void
104 {
105  NS_LOG_FUNCTION(this);
106 
107  if (m_fwdScheduler == NULL)
108  {
109  NS_FATAL_ERROR("Scheduler not set for GEO FEEDER MAC!!!");
110  }
111 
112  Simulator::Schedule(Seconds(0), &SatGeoMac::StartTransmission, this, 0);
113 }
114 
115 void
116 SatGeoMac::StartTransmission(uint32_t carrierId)
117 {
118  NS_LOG_FUNCTION(this);
119 
120  Time txDuration;
121 
122  if (m_txEnabled)
123  {
124  std::pair<Ptr<SatBbFrame>, const Time> bbFrameInfo = m_fwdScheduler->GetNextFrame();
125  Ptr<SatBbFrame> bbFrame = bbFrameInfo.first;
126  txDuration = bbFrameInfo.second;
127 
128  // trace out BB frames sent.
129  m_bbFrameTxTrace(bbFrame);
130 
131  // Handle both dummy frames and normal frames
132  if (bbFrame != NULL)
133  {
136  txInfo.modCod = bbFrame->GetModcod();
137  txInfo.sliceId = bbFrame->GetSliceId();
138  txInfo.frameType = bbFrame->GetFrameType();
139  txInfo.waveformId = 0;
140 
144  SendPacket(bbFrame->GetPayload(), carrierId, txDuration - m_guardTime, txInfo);
145  }
146  }
147  else
148  {
154  NS_LOG_INFO("TX is disabled, thus nothing is transmitted!");
155  txDuration = m_fwdScheduler->GetDefaultFrameDuration();
156  }
157 
158  Simulator::Schedule(txDuration, &SatGeoMac::StartTransmission, this, 0);
159 }
160 
161 void
163  uint32_t carrierId,
164  Time duration,
166 {
167  NS_LOG_FUNCTION(this);
168 
169  // Add a SatMacTimeTag tag for packet delay computation at the receiver end.
170  SetTimeTag(packets);
171 
172  // Add packet trace entry:
173  m_packetTrace(Simulator::Now(),
175  m_nodeInfo->GetNodeType(),
176  m_nodeInfo->GetNodeId(),
177  m_nodeInfo->GetMacAddress(),
179  GetSatLinkTxDir(),
180  SatUtils::GetPacketInfo(packets));
181 
182  Ptr<SatSignalParameters> txParams = Create<SatSignalParameters>();
183  txParams->m_duration = duration;
184  txParams->m_packetsInBurst = packets;
185  txParams->m_satId = m_satId;
186  txParams->m_beamId = m_beamId;
187  txParams->m_carrierId = carrierId;
188  txParams->m_txInfo = txInfo;
189 
190  // Use call back to send packet to lower layer
191  m_txCallback(txParams);
192 }
193 
194 void
196 {
197  NS_LOG_FUNCTION(this);
198 
200  {
201  for (SatPhy::PacketContainer_t::const_iterator it1 = packets.begin(); it1 != packets.end();
202  ++it1)
203  {
204  // Remove packet tag
205  SatMacTag macTag;
206  bool mSuccess = (*it1)->PeekPacketTag(macTag);
207  if (!mSuccess)
208  {
209  NS_FATAL_ERROR("MAC tag was not found from the packet!");
210  }
211 
212  // If the packet is intended for this receiver
213  Mac48Address destAddress = macTag.GetDestAddress();
214 
215  if (destAddress == m_nodeInfo->GetMacAddress())
216  {
217  Address addr = GetRxUtAddress(*it1);
218 
219  m_rxTrace(*it1, addr);
220 
221  SatMacLinkTimeTag linkTimeTag;
222  if ((*it1)->RemovePacketTag(linkTimeTag))
223  {
224  NS_LOG_DEBUG(this << " contains a SatMacLinkTimeTag tag");
225  Time delay = Simulator::Now() - linkTimeTag.GetSenderLinkTimestamp();
226  m_rxLinkDelayTrace(delay, addr);
227  if (m_lastLinkDelay.IsZero() == false)
228  {
229  Time jitter = Abs(delay - m_lastLinkDelay);
230  m_rxLinkJitterTrace(jitter, addr);
231  }
232  m_lastLinkDelay = delay;
233  }
234  } // end of `if (destAddress == m_nodeInfo->GetMacAddress () || destAddress.IsBroadcast
235  // ())`
236  } // end of `for it1 = packets.begin () -> packets.end ()`
237  } // end of `if (m_isStatisticsTagsEnabled)`
238 }
239 
240 void
241 SatGeoMac::SetFwdScheduler(Ptr<SatFwdLinkScheduler> fwdScheduler)
242 {
243  m_fwdScheduler = fwdScheduler;
244 }
245 
246 void
247 SatGeoMac::SetLlc(Ptr<SatGeoLlc> llc)
248 {
249  m_llc = llc;
250 }
251 
252 Time
254 {
255  return m_guardTime;
256 }
257 
258 void
259 SatGeoMac::SetGuardTime(Time guardTime)
260 {
261  m_guardTime = guardTime;
262 }
263 
264 void
266 {
267  NS_LOG_FUNCTION(this << &cb);
268  m_txCallback = cb;
269 }
270 
271 void
273 {
274  NS_LOG_FUNCTION(this << &cb);
276 }
277 
278 } // namespace ns3
RegenerationMode_t
The regeneration mode used in satellites.
Callback< void, Ptr< SatSignalParameters > > TransmitCallback
Ptr< SatGeoLlc > m_llc
LLC layer linked to this MAC.
virtual void SetGuardTime(Time guardTime)
void StartTransmission(uint32_t carrierId)
Start sending a Packet Down the Wire.
virtual Time GetGuardTime() const
SatGeoMac(void)
Default constructor.
TracedCallback< Ptr< SatBbFrame > > m_bbFrameTxTrace
Trace for transmitted BB frames.
virtual void RxTraces(SatPhy::PacketContainer_t packets)
Invoke the Rx trace source for each received packet.
Time m_guardTime
Guard time for BB frames.
void StartPeriodicTransmissions()
Starts periodical transmissions.
uint32_t m_satId
ID of sat for UT.
TransmitCallback m_txCallback
virtual void DoInitialize(void)
virtual void DoDispose(void)
Dispose of this class instance.
void SetLlc(Ptr< SatGeoLlc > llc)
Set the Geo LLC associated to this Geo MAC layer.
uint32_t m_beamId
ID of beam for UT.
void SetTransmitCallback(SatGeoMac::TransmitCallback cb)
void SetReceiveNetDeviceCallback(SatGeoMac::ReceiveNetDeviceCallback cb)
Callback< void, SatPhy::PacketContainer_t, Ptr< SatSignalParameters > > ReceiveNetDeviceCallback
void SetFwdScheduler(Ptr< SatFwdLinkScheduler > fwdScheduler)
Method to set link scheduler (forward or SCPC)
Ptr< SatFwdLinkScheduler > m_fwdScheduler
Scheduler for the forward link.
ReceiveNetDeviceCallback m_rxNetDeviceCallback
TypeId GetInstanceTypeId(void) const
static TypeId GetTypeId(void)
inherited from Object
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.
virtual Address GetRxUtAddress(Ptr< Packet > packet)=0
Get the UT address associated to this RX packet.
virtual SatEnums::SatLinkDir_t GetSatLinkTxDir()=0
Get the link TX direction.
virtual ~SatGeoMac()
Destructor for SatGeoMac.
Base MAC class for SatNetDevices.
Definition: satellite-mac.h:52
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.
SatSignalParameters::PacketsInBurst_t PacketContainer_t
Define PacketContainer in SatPhy.
Definition: satellite-phy.h:78
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.