satellite-orbiter-feeder-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"
27 #include "satellite-utils.h"
28 
29 #include <ns3/double.h>
30 #include <ns3/enum.h>
31 #include <ns3/log.h>
32 #include <ns3/pointer.h>
33 #include <ns3/simulator.h>
34 #include <ns3/uinteger.h>
35 
36 NS_LOG_COMPONENT_DEFINE("SatOrbiterFeederMac");
37 
38 namespace ns3
39 {
40 
41 NS_OBJECT_ENSURE_REGISTERED(SatOrbiterFeederMac);
42 
43 TypeId
45 {
46  static TypeId tid = TypeId("ns3::SatOrbiterFeederMac")
47  .SetParent<SatOrbiterMac>()
48  .AddConstructor<SatOrbiterFeederMac>()
49  .AddAttribute("GuardTime",
50  "Guard time in this SCPC scheduler",
51  TimeValue(MicroSeconds(1)),
52  MakeTimeAccessor(&SatOrbiterMac::GetGuardTime,
54  MakeTimeChecker());
55  return tid;
56 }
57 
58 TypeId
60 {
61  NS_LOG_FUNCTION(this);
62 
63  return GetTypeId();
64 }
65 
67 {
68  NS_LOG_FUNCTION(this);
69  NS_FATAL_ERROR("SatOrbiterFeederMac default constructor is not allowed to use");
70 }
71 
72 SatOrbiterFeederMac::SatOrbiterFeederMac(uint32_t satId, uint32_t beamId)
73  : SatOrbiterMac(satId, beamId)
74 {
75  NS_LOG_FUNCTION(this << satId << beamId);
76 }
77 
79 {
80  NS_LOG_FUNCTION(this);
81 }
82 
83 void
85 {
86  NS_LOG_FUNCTION(this);
87  Object::DoDispose();
88 }
89 
90 void
92 {
93  NS_LOG_FUNCTION(this);
94  Object::DoInitialize();
95 }
96 
97 void
99 {
100  NS_LOG_FUNCTION(this << packet);
101 
103  {
104  NS_LOG_INFO("Do not enque packet to this beam because it is disabled");
105  return;
106  }
107 
108  SatAddressE2ETag addressE2ETag;
109  bool success = packet->PeekPacketTag(addressE2ETag);
110 
111  SatMacTag mTag;
112  success &= packet->RemovePacketTag(mTag);
113 
115  {
116  // MAC tag and E2E address tag found
117  if (success)
118  {
119  mTag.SetDestAddress(addressE2ETag.GetE2EDestAddress());
120  mTag.SetSourceAddress(m_nodeInfo->GetMacAddress());
121  packet->AddPacketTag(mTag);
122  }
123  }
124 
125  uint8_t flowId = 1;
126  SatControlMsgTag ctrlTag;
127  if (packet->PeekPacketTag(ctrlTag))
128  {
129  flowId = 0;
130  }
131 
132  m_llc->Enque(packet, addressE2ETag.GetE2EDestAddress(), flowId);
133 
135 }
136 
137 void
138 SatOrbiterFeederMac::Receive(SatPhy::PacketContainer_t packets, Ptr<SatSignalParameters> rxParams)
139 {
140  NS_LOG_FUNCTION(this);
141 
144  {
145  // Add packet trace entry:
146  m_packetTrace(Simulator::Now(),
148  m_nodeInfo->GetNodeType(),
149  m_nodeInfo->GetNodeId(),
150  m_nodeInfo->GetMacAddress(),
153  SatUtils::GetPacketInfo(packets));
154 
155  RxTraces(packets);
156  }
157 
158  rxParams->m_packetsInBurst.clear();
159  for (SatPhy::PacketContainer_t::iterator i = packets.begin(); i != packets.end(); i++)
160  {
161  // Remove packet tag
162  SatMacTag macTag;
163  bool mSuccess = (*i)->PeekPacketTag(macTag);
164  if (!mSuccess)
165  {
166  NS_FATAL_ERROR("MAC tag was not found from the packet!");
167  }
168 
169  NS_LOG_INFO("Packet from " << macTag.GetSourceAddress() << " to "
170  << macTag.GetDestAddress());
171  NS_LOG_INFO("Receiver " << m_nodeInfo->GetMacAddress());
172 
173  SatAddressE2ETag satAddressE2ETag;
174  mSuccess = (*i)->PeekPacketTag(satAddressE2ETag);
175  if (!mSuccess)
176  {
177  NS_FATAL_ERROR("SatAddressE2E tag was not found from the packet!");
178  }
179  Mac48Address destE2EAddress = satAddressE2ETag.GetE2EDestAddress();
180  if (destE2EAddress == m_nodeInfo->GetMacAddress())
181  {
182  // Remove control msg tag
183  SatControlMsgTag ctrlTag;
184  bool cSuccess = (*i)->PeekPacketTag(ctrlTag);
185 
186  if (cSuccess)
187  {
189 
191  {
193  }
194  else
195  {
196  NS_FATAL_ERROR("A control message received with not valid msg type!");
197  }
198  }
199  }
200  else
201  {
202  rxParams->m_packetsInBurst.push_back(*i);
203  }
204  }
205 
207  {
208  for (SatPhy::PacketContainer_t::iterator i = rxParams->m_packetsInBurst.begin();
209  i != rxParams->m_packetsInBurst.end();
210  i++)
211  {
212  // Remove packet tag
213  SatMacTag macTag;
214  bool mSuccess = (*i)->PeekPacketTag(macTag);
215  if (!mSuccess)
216  {
217  NS_FATAL_ERROR("MAC tag was not found from the packet!");
218  }
219  Mac48Address destAddress = macTag.GetDestAddress();
220 
221  NS_LOG_INFO("Packet from " << macTag.GetSourceAddress() << " to "
222  << macTag.GetDestAddress());
223  NS_LOG_INFO("Receiver " << m_nodeInfo->GetMacAddress());
224 
225  if (destAddress == m_nodeInfo->GetMacAddress() || destAddress.IsBroadcast() ||
226  destAddress.IsGroup())
227  {
228  m_rxCallback(*i, macTag.GetSourceAddress(), macTag.GetDestAddress());
229  }
230  }
231  }
232  else
233  {
234  m_rxNetDeviceCallback(rxParams->m_packetsInBurst, rxParams);
235  }
236 }
237 
238 void
240 {
241  NS_LOG_FUNCTION(this << packet);
242 
243  // Remove the mac tag
244  SatMacTag macTag;
245  packet->PeekPacketTag(macTag);
246 
247  // Peek control msg tag
248  SatControlMsgTag ctrlTag;
249  bool cSuccess = packet->PeekPacketTag(ctrlTag);
250 
251  if (!cSuccess)
252  {
253  NS_FATAL_ERROR("SatControlMsgTag not found in the packet!");
254  }
255 
256  switch (ctrlTag.GetMsgType())
257  {
259  uint32_t msgId = ctrlTag.GetMsgId();
260  Ptr<SatCnoReportMessage> cnoReport =
261  DynamicCast<SatCnoReportMessage>(m_readCtrlCallback(msgId));
262 
263  if (cnoReport != nullptr)
264  {
265  m_fwdScheduler->CnoInfoUpdated(macTag.GetSourceAddress(), cnoReport->GetCnoEstimate());
266  }
267  else
268  {
269  NS_LOG_WARN("Control message "
270  << ctrlTag.GetMsgType()
271  << " is not found from the RTN link control msg container!"
272  << " at: " << Now().GetSeconds() << "s");
273  }
274 
275  packet->RemovePacketTag(macTag);
276  packet->RemovePacketTag(ctrlTag);
277 
278  break;
279  }
280  default: {
281  NS_FATAL_ERROR("Control message unkonwn on feeder MAC");
282  }
283  }
284 }
285 
288 {
289  return SatEnums::LD_RETURN;
290 }
291 
294 {
295  return SatEnums::LD_FORWARD;
296 }
297 
298 Address
300 {
301  NS_LOG_FUNCTION(this << packet);
302 
303  Address utAddr; // invalid address.
304 
305  SatAddressE2ETag addressE2ETag;
306  if (packet->PeekPacketTag(addressE2ETag))
307  {
308  NS_LOG_DEBUG(this << " contains a SatE2E tag");
309  utAddr = addressE2ETag.GetE2EDestAddress();
310  }
311 
312  return utAddr;
313 }
314 
315 bool
316 SatOrbiterFeederMac::AddPeer(Mac48Address address)
317 {
318  NS_LOG_FUNCTION(this << address);
319 
320  return false;
321 }
322 
323 bool
324 SatOrbiterFeederMac::RemovePeer(Mac48Address address)
325 {
326  NS_LOG_FUNCTION(this << address);
327 
328  return false;
329 }
330 
331 bool
333 {
334  NS_LOG_FUNCTION(this);
335 
336  return true;
337 }
338 
339 } // namespace ns3
This class implements a tag that carries the satellite MAC of GW and UT.
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.
void Receive(SatPhy::PacketContainer_t packets, Ptr< SatSignalParameters > rxParams)
Receive packet from lower layer.
virtual ~SatOrbiterFeederMac()
Destructor for SatOrbiterFeederMac.
virtual bool AddPeer(Mac48Address address)
Add a remote peer to this MAC.
SatOrbiterFeederMac(void)
Default constructor.
virtual bool RemovePeer(Mac48Address address)
Remove a remote peer from this MAC.
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 void DoDispose(void)
Dispose of this class instance.
virtual void EnquePacket(Ptr< Packet > packet)
Add new packet to the LLC queue.
virtual SatEnums::SatLinkDir_t GetSatLinkTxDir()
Get the link TX direction.
virtual bool HasPeer()
Indicates if at least one device is connected in this beam.
virtual SatEnums::SatLinkDir_t GetSatLinkRxDir()
Get the link RX direction.
The SatOrbiterMac models the global link MAC layer of the satellite node.
Ptr< SatOrbiterLlc > m_llc
LLC layer linked to this MAC.
virtual Time GetGuardTime() const
bool m_periodicTransmissionEnabled
Indicated if periodic transmission is enabled.
virtual void SetGuardTime(Time guardTime)
ReceiveNetDeviceCallback m_rxNetDeviceCallback
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.
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.