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