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 
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("SatOrbiterUserMac");
38 
39 namespace ns3
40 {
41 
42 NS_OBJECT_ENSURE_REGISTERED(SatOrbiterUserMac);
43 
44 TypeId
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 
59 TypeId
61 {
62  NS_LOG_FUNCTION(this);
63 
64  return GetTypeId();
65 }
66 
68 {
69  NS_LOG_FUNCTION(this);
70  NS_FATAL_ERROR("SatOrbiterUserMac default constructor is not allowed to use");
71 }
72 
73 SatOrbiterUserMac::SatOrbiterUserMac(uint32_t satId, uint32_t beamId)
74  : SatOrbiterMac(satId, beamId)
75 {
76  NS_LOG_FUNCTION(this << satId << beamId);
77 }
78 
80 {
81  NS_LOG_FUNCTION(this);
82 }
83 
84 void
86 {
87  NS_LOG_FUNCTION(this);
88 
89  m_peers.clear();
90 
91  Object::DoDispose();
92 }
93 
94 void
96 {
97  NS_LOG_FUNCTION(this);
98  Object::DoInitialize();
99 }
100 
101 void
103 {
104  NS_LOG_FUNCTION(this << packet);
105 
107  {
108  NS_LOG_INFO("Do not enque packet to this beam because it is disabled");
109  return;
110  }
111 
112  SatAddressE2ETag addressE2ETag;
113  bool success = packet->PeekPacketTag(addressE2ETag);
114 
115  SatMacTag mTag;
116  success &= packet->RemovePacketTag(mTag);
117 
119  {
120  // MAC tag and E2E address tag found
121  if (success)
122  {
123  mTag.SetDestAddress(addressE2ETag.GetE2EDestAddress());
124  mTag.SetSourceAddress(m_nodeInfo->GetMacAddress());
125  packet->AddPacketTag(mTag);
126  }
127  }
128 
129  uint8_t flowId = 1;
130  SatControlMsgTag ctrlTag;
131  if (packet->PeekPacketTag(ctrlTag))
132  {
133  flowId = 0;
134  }
135 
136  m_llc->Enque(packet, addressE2ETag.GetE2EDestAddress(), flowId);
137 
139 }
140 
141 void
142 SatOrbiterUserMac::Receive(SatPhy::PacketContainer_t packets, Ptr<SatSignalParameters> rxParams)
143 {
144  NS_LOG_FUNCTION(this);
145 
148  {
149  // Add packet trace entry:
150  m_packetTrace(Simulator::Now(),
152  m_nodeInfo->GetNodeType(),
153  m_nodeInfo->GetNodeId(),
154  m_nodeInfo->GetMacAddress(),
157  SatUtils::GetPacketInfo(packets));
158 
159  RxTraces(packets);
160  }
161 
162  rxParams->m_packetsInBurst.clear();
163  for (SatPhy::PacketContainer_t::iterator i = packets.begin(); i != packets.end(); i++)
164  {
165  // Remove packet tag
166  SatMacTag macTag;
167  bool mSuccess = (*i)->PeekPacketTag(macTag);
168  if (!mSuccess)
169  {
170  NS_FATAL_ERROR("MAC tag was not found from the packet!");
171  }
172 
173  NS_LOG_INFO("Packet from " << macTag.GetSourceAddress() << " to "
174  << macTag.GetDestAddress());
175  NS_LOG_INFO("Receiver " << m_nodeInfo->GetMacAddress());
176 
177  SatAddressE2ETag satAddressE2ETag;
178  mSuccess = (*i)->PeekPacketTag(satAddressE2ETag);
179  if (!mSuccess)
180  {
181  NS_FATAL_ERROR("SatAddressE2E tag was not found from the packet!");
182  }
183  Mac48Address destE2EAddress = satAddressE2ETag.GetE2EDestAddress();
184  if (destE2EAddress == m_nodeInfo->GetMacAddress())
185  {
186  // Remove control msg tag
187  SatControlMsgTag ctrlTag;
188  bool cSuccess = (*i)->PeekPacketTag(ctrlTag);
189 
190  if (cSuccess)
191  {
193 
195  {
197  }
198  else
199  {
200  NS_FATAL_ERROR("A control message received with not valid msg type!");
201  }
202  }
203  }
204  else
205  {
206  rxParams->m_packetsInBurst.push_back(*i);
207  }
208  }
209 
211  {
212  for (SatPhy::PacketContainer_t::iterator i = rxParams->m_packetsInBurst.begin();
213  i != rxParams->m_packetsInBurst.end();
214  i++)
215  {
216  // Remove packet tag
217  SatMacTag macTag;
218  bool mSuccess = (*i)->PeekPacketTag(macTag);
219  if (!mSuccess)
220  {
221  NS_FATAL_ERROR("MAC tag was not found from the packet!");
222  }
223  Mac48Address destAddress = macTag.GetDestAddress();
224 
225  NS_LOG_INFO("Packet from " << macTag.GetSourceAddress() << " to "
226  << macTag.GetDestAddress());
227  NS_LOG_INFO("Receiver " << m_nodeInfo->GetMacAddress());
228 
229  if (destAddress == m_nodeInfo->GetMacAddress() || destAddress.IsBroadcast() ||
230  destAddress.IsGroup())
231  {
232  m_rxCallback(*i, macTag.GetSourceAddress(), macTag.GetDestAddress());
233  }
234  }
235  }
236  else
237  {
238  m_rxNetDeviceCallback(rxParams->m_packetsInBurst, rxParams);
239  }
240 }
241 
242 void
244 {
245  NS_LOG_FUNCTION(this << packet);
246 
247  // Remove the mac tag
248  SatMacTag macTag;
249  packet->PeekPacketTag(macTag);
250 
251  // Peek control msg tag
252  SatControlMsgTag ctrlTag;
253  bool cSuccess = packet->PeekPacketTag(ctrlTag);
254 
255  if (!cSuccess)
256  {
257  NS_FATAL_ERROR("SatControlMsgTag not found in the packet!");
258  }
259 
260  switch (ctrlTag.GetMsgType())
261  {
263  uint32_t msgId = ctrlTag.GetMsgId();
264  Ptr<SatCnoReportMessage> cnoReport =
265  DynamicCast<SatCnoReportMessage>(m_readCtrlCallback(msgId));
266 
267  if (cnoReport != nullptr)
268  {
269  m_fwdScheduler->CnoInfoUpdated(macTag.GetSourceAddress(), cnoReport->GetCnoEstimate());
270  }
271  else
272  {
273  NS_LOG_WARN("Control message "
274  << ctrlTag.GetMsgType()
275  << " is not found from the RTN link control msg container!"
276  << " at: " << Now().GetSeconds() << "s");
277  }
278 
279  packet->RemovePacketTag(macTag);
280  packet->RemovePacketTag(ctrlTag);
281 
282  break;
283  }
284  default: {
285  NS_FATAL_ERROR("Control message unkonwn on user MAC");
286  }
287  }
288 }
289 
292 {
293  return SatEnums::LD_FORWARD;
294 }
295 
298 {
299  return SatEnums::LD_RETURN;
300 }
301 
302 Address
304 {
305  NS_LOG_FUNCTION(this << packet);
306 
307  Address utAddr; // invalid address.
308 
309  SatAddressE2ETag addressE2ETag;
310  if (packet->PeekPacketTag(addressE2ETag))
311  {
312  NS_LOG_DEBUG(this << " contains a SatE2E tag");
313  utAddr = addressE2ETag.GetE2ESourceAddress();
314  }
315 
316  return utAddr;
317 }
318 
319 bool
320 SatOrbiterUserMac::AddPeer(Mac48Address address)
321 {
322  NS_LOG_FUNCTION(this << address);
323 
324  NS_ASSERT(m_peers.find(address) == m_peers.end());
325 
327  {
328  NS_LOG_INFO("Start beam " << m_beamId);
329  m_peers.insert(address);
331  }
332  else
333  {
334  m_peers.insert(address);
335  }
336 
337  return true;
338 }
339 
340 bool
341 SatOrbiterUserMac::RemovePeer(Mac48Address address)
342 {
343  NS_LOG_FUNCTION(this << address);
344 
345  NS_ASSERT(m_peers.find(address) != m_peers.end());
346 
347  m_peers.erase(address);
348 
350  {
351  NS_LOG_INFO("Stop beam " << m_beamId);
353  }
354 
355  return true;
356 }
357 
358 bool
360 {
361  NS_LOG_FUNCTION(this);
362 
363  return !m_peers.empty();
364 }
365 
366 } // 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.
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...
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.
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.
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.