satellite-geo-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 
21 #include "satellite-geo-user-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("SatGeoUserMac");
38 
39 namespace ns3
40 {
41 
42 NS_OBJECT_ENSURE_REGISTERED(SatGeoUserMac);
43 
44 TypeId
46 {
47  static TypeId tid =
48  TypeId("ns3::SatGeoUserMac")
49  .SetParent<SatGeoMac>()
50  .AddConstructor<SatGeoUserMac>()
51  .AddAttribute("GuardTime",
52  "Guard time in this fwd user link scheduler",
53  TimeValue(MicroSeconds(1)),
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("SatGeoUserMac default constructor is not allowed to use");
71 }
72 
74  uint32_t beamId,
75  SatEnums::RegenerationMode_t forwardLinkRegenerationMode,
76  SatEnums::RegenerationMode_t returnLinkRegenerationMode)
77  : SatGeoMac(satId, beamId, forwardLinkRegenerationMode, returnLinkRegenerationMode)
78 {
79  NS_LOG_FUNCTION(this);
80 }
81 
83 {
84  NS_LOG_FUNCTION(this);
85 }
86 
87 void
89 {
90  NS_LOG_FUNCTION(this);
91  Object::DoDispose();
92 }
93 
94 void
96 {
97  NS_LOG_FUNCTION(this);
98  Object::DoInitialize();
99 }
100 
101 void
102 SatGeoUserMac::EnquePacket(Ptr<Packet> packet)
103 {
104  NS_LOG_FUNCTION(this);
105 
106  SatAddressE2ETag addressE2ETag;
107  bool success = packet->PeekPacketTag(addressE2ETag);
108 
109  SatMacTag mTag;
110  success &= packet->RemovePacketTag(mTag);
111 
113  {
114  // MAC tag and E2E address tag found
115  if (success)
116  {
117  mTag.SetDestAddress(addressE2ETag.GetE2EDestAddress());
118  mTag.SetSourceAddress(m_nodeInfo->GetMacAddress());
119  packet->AddPacketTag(mTag);
120  }
121  }
122 
123  uint8_t flowId = 1;
124  SatControlMsgTag ctrlTag;
125  if (packet->PeekPacketTag(ctrlTag))
126  {
127  flowId = 0;
128  }
129 
130  m_llc->Enque(packet, addressE2ETag.GetE2EDestAddress(), flowId);
131 }
132 
133 void
134 SatGeoUserMac::Receive(SatPhy::PacketContainer_t packets, Ptr<SatSignalParameters> rxParams)
135 {
136  NS_LOG_FUNCTION(this);
137 
140  {
141  // Add packet trace entry:
142  m_packetTrace(Simulator::Now(),
144  m_nodeInfo->GetNodeType(),
145  m_nodeInfo->GetNodeId(),
146  m_nodeInfo->GetMacAddress(),
149  SatUtils::GetPacketInfo(packets));
150 
151  RxTraces(packets);
152  }
153 
154  rxParams->m_packetsInBurst.clear();
155  for (SatPhy::PacketContainer_t::iterator i = packets.begin(); i != packets.end(); i++)
156  {
157  // Remove packet tag
158  SatMacTag macTag;
159  bool mSuccess = (*i)->PeekPacketTag(macTag);
160  if (!mSuccess)
161  {
162  NS_FATAL_ERROR("MAC tag was not found from the packet!");
163  }
164 
165  NS_LOG_INFO("Packet from " << macTag.GetSourceAddress() << " to "
166  << macTag.GetDestAddress());
167  NS_LOG_INFO("Receiver " << m_nodeInfo->GetMacAddress());
168 
169  SatAddressE2ETag satAddressE2ETag;
170  mSuccess = (*i)->PeekPacketTag(satAddressE2ETag);
171  if (!mSuccess)
172  {
173  NS_FATAL_ERROR("SatAddressE2E tag was not found from the packet!");
174  }
175  Mac48Address destE2EAddress = satAddressE2ETag.GetE2EDestAddress();
176  if (destE2EAddress == m_nodeInfo->GetMacAddress())
177  {
178  // Remove control msg tag
179  SatControlMsgTag ctrlTag;
180  bool cSuccess = (*i)->PeekPacketTag(ctrlTag);
181 
182  if (cSuccess)
183  {
185 
187  {
189  }
190  else
191  {
192  NS_FATAL_ERROR("A control message received with not valid msg type!");
193  }
194  }
195  }
196  else
197  {
198  rxParams->m_packetsInBurst.push_back(*i);
199  }
200  }
201 
203  {
204  for (SatPhy::PacketContainer_t::iterator i = rxParams->m_packetsInBurst.begin();
205  i != rxParams->m_packetsInBurst.end();
206  i++)
207  {
208  // Remove packet tag
209  SatMacTag macTag;
210  bool mSuccess = (*i)->PeekPacketTag(macTag);
211  if (!mSuccess)
212  {
213  NS_FATAL_ERROR("MAC tag was not found from the packet!");
214  }
215  Mac48Address destAddress = macTag.GetDestAddress();
216 
217  NS_LOG_INFO("Packet from " << macTag.GetSourceAddress() << " to "
218  << macTag.GetDestAddress());
219  NS_LOG_INFO("Receiver " << m_nodeInfo->GetMacAddress());
220 
221  if (destAddress == m_nodeInfo->GetMacAddress() || destAddress.IsBroadcast() ||
222  destAddress.IsGroup())
223  {
224  m_rxCallback(*i, macTag.GetSourceAddress(), macTag.GetDestAddress());
225  }
226  }
227  }
228  else
229  {
230  m_rxNetDeviceCallback(rxParams->m_packetsInBurst, rxParams);
231  }
232 }
233 
234 void
236 {
237  NS_LOG_FUNCTION(this << packet);
238 
239  // Remove the mac tag
240  SatMacTag macTag;
241  packet->PeekPacketTag(macTag);
242 
243  // Peek control msg tag
244  SatControlMsgTag ctrlTag;
245  bool cSuccess = packet->PeekPacketTag(ctrlTag);
246 
247  if (!cSuccess)
248  {
249  NS_FATAL_ERROR("SatControlMsgTag not found in the packet!");
250  }
251 
252  switch (ctrlTag.GetMsgType())
253  {
255  uint32_t msgId = ctrlTag.GetMsgId();
256  Ptr<SatCnoReportMessage> cnoReport =
257  DynamicCast<SatCnoReportMessage>(m_readCtrlCallback(msgId));
258 
259  if (cnoReport != NULL)
260  {
261  m_fwdScheduler->CnoInfoUpdated(macTag.GetSourceAddress(), cnoReport->GetCnoEstimate());
262  }
263  else
264  {
265  NS_LOG_WARN("Control message "
266  << ctrlTag.GetMsgType()
267  << " is not found from the RTN link control msg container!"
268  << " at: " << Now().GetSeconds() << "s");
269  }
270 
271  packet->RemovePacketTag(macTag);
272  packet->RemovePacketTag(ctrlTag);
273 
274  break;
275  }
276  default: {
277  NS_FATAL_ERROR("Control message unkonwn on user MAC");
278  }
279  }
280 }
281 
284 {
285  return SatEnums::LD_FORWARD;
286 }
287 
290 {
291  return SatEnums::LD_RETURN;
292 }
293 
294 Address
295 SatGeoUserMac::GetRxUtAddress(Ptr<Packet> packet)
296 {
297  NS_LOG_FUNCTION(this << packet);
298 
299  Address utAddr; // invalid address.
300 
301  SatAddressE2ETag addressE2ETag;
302  if (packet->PeekPacketTag(addressE2ETag))
303  {
304  NS_LOG_DEBUG(this << " contains a SatE2E tag");
305  utAddr = addressE2ETag.GetE2ESourceAddress();
306  }
307 
308  return utAddr;
309 }
310 
311 } // 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.
RegenerationMode_t
The regeneration mode used in satellites.
The SatGeoMac models the global link MAC layer of the satellite node.
Ptr< SatGeoLlc > m_llc
LLC layer linked to this MAC.
virtual void SetGuardTime(Time guardTime)
virtual Time GetGuardTime() const
virtual void RxTraces(SatPhy::PacketContainer_t packets)
Invoke the Rx trace source for each received packet.
Ptr< SatFwdLinkScheduler > m_fwdScheduler
Scheduler for the forward link.
ReceiveNetDeviceCallback m_rxNetDeviceCallback
SatGeoUserMac(void)
Default constructor.
virtual SatEnums::SatLinkDir_t GetSatLinkTxDir()
Get the link TX direction.
virtual ~SatGeoUserMac()
Destructor for SatGeoUserMac.
virtual void DoDispose(void)
Dispose of this class instance.
virtual void DoInitialize(void)
virtual SatEnums::SatLinkDir_t GetSatLinkRxDir()
Get the link RX direction.
TypeId GetInstanceTypeId(void) const
virtual Address GetRxUtAddress(Ptr< Packet > packet)
Get the UT address associated to this RX packet.
void Receive(SatPhy::PacketContainer_t packets, Ptr< SatSignalParameters > txParams)
Receive packet from lower layer.
static TypeId GetTypeId(void)
inherited from Object
virtual void EnquePacket(Ptr< Packet > packet)
Add new packet to the LLC queue.
void ReceiveSignalingPacket(Ptr< Packet > packet)
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.
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.