Loading...
Searching...
No Matches
satellite-gw-mac.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2014 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: Jani Puttonen <jani.puttonen@magister.fi>
19 */
20
21#include "satellite-gw-mac.h"
22
23#include "satellite-bbframe.h"
27#include "satellite-log.h"
28#include "satellite-mac-tag.h"
31#include "satellite-time-tag.h"
32#include "satellite-topology.h"
34#include "satellite-utils.h"
35
36#include "ns3/address.h"
37#include "ns3/boolean.h"
38#include "ns3/log.h"
39#include "ns3/mac48-address.h"
40#include "ns3/packet.h"
41#include "ns3/pointer.h"
42#include "ns3/simulator.h"
43#include "ns3/singleton.h"
44#include "ns3/uinteger.h"
45
46#include <sstream>
47#include <utility>
48#include <vector>
49
50NS_LOG_COMPONENT_DEFINE("SatGwMac");
51
52namespace ns3
53{
54
55NS_OBJECT_ENSURE_REGISTERED(SatGwMac);
56
57TypeId
59{
60 static TypeId tid =
61 TypeId("ns3::SatGwMac")
62 .SetParent<SatMac>()
63 .AddConstructor<SatGwMac>()
64 .AddAttribute("Scheduler",
65 "Forward link scheduler used by this Sat GW MAC.",
66 PointerValue(),
67 MakePointerAccessor(&SatGwMac::m_fwdScheduler),
68 MakePointerChecker<SatFwdLinkScheduler>())
69 .AddAttribute("GuardTime",
70 "Guard time in forward link",
71 TimeValue(MicroSeconds(1)),
72 MakeTimeAccessor(&SatGwMac::m_guardTime),
73 MakeTimeChecker())
74 .AddAttribute("NcrBroadcastPeriod",
75 "Interval between two broadcast of NCR dates",
76 TimeValue(MilliSeconds(100)),
77 MakeTimeAccessor(&SatGwMac::m_ncrInterval),
78 MakeTimeChecker())
79 .AddAttribute("UseCmt",
80 "Use CMT control messages to correct time on the UTs",
81 BooleanValue(false),
82 MakeBooleanAccessor(&SatGwMac::m_useCmt),
83 MakeBooleanChecker())
84 .AddAttribute("CmtPeriodMin",
85 "Minimum interval between two CMT control messages for a same UT",
86 TimeValue(MilliSeconds(550)),
87 MakeTimeAccessor(&SatGwMac::m_cmtPeriodMin),
88 MakeTimeChecker())
89 .AddAttribute("SendNcrBroadcast",
90 "Broadcast NCR messages to all UTs",
91 BooleanValue(true),
92 MakeBooleanAccessor(&SatGwMac::m_broadcastNcr),
93 MakeBooleanChecker())
94 .AddAttribute("DisableSchedulingIfNoDeviceConnected",
95 "If true, the periodic calls of StartTransmission are not called when no "
96 "devices are connected to this MAC",
97 BooleanValue(false),
99 MakeBooleanChecker())
100 .AddTraceSource("BBFrameTxTrace",
101 "Trace for transmitted BB Frames.",
102 MakeTraceSourceAccessor(&SatGwMac::m_bbFrameTxTrace),
103 "ns3::SatBbFrame::BbFrameCallback");
104 return tid;
105}
106
108 : SatMac(),
110 m_guardTime(MicroSeconds(1)),
111 m_ncrInterval(MilliSeconds(100)),
112 m_useCmt(false),
114 m_cmtPeriodMin(MilliSeconds(550)),
115 m_broadcastNcr(true),
118{
119 NS_LOG_FUNCTION(this);
120
121 NS_FATAL_ERROR("SatUtMac::SatGwMac - Constructor not in use");
122}
123
124SatGwMac::SatGwMac(Ptr<Node> node,
125 uint32_t satId,
126 uint32_t beamId,
127 uint32_t feederSatId,
128 uint32_t feederBeamId)
129 : SatMac(satId, beamId),
130 m_node(node),
131 m_feederSatId(feederSatId),
132 m_feederBeamId(feederBeamId),
134 m_guardTime(MicroSeconds(1)),
135 m_ncrInterval(MilliSeconds(100)),
136 m_useCmt(false),
138 m_cmtPeriodMin(MilliSeconds(550)),
139 m_broadcastNcr(true),
142{
143 NS_LOG_FUNCTION(this);
144}
145
147{
148 NS_LOG_FUNCTION(this);
149}
150
151void
153{
154 NS_LOG_FUNCTION(this);
155
156 m_txOpportunityCallback.Nullify();
157 m_crReceiveCallback.Nullify();
158 m_handoverCallback.Nullify();
159 m_logonCallback.Nullify();
161
163}
164
165void
167{
168 NS_LOG_FUNCTION(this);
169
171 {
172 NS_LOG_INFO("Do not start beam " << m_beamId << " because no device is connected");
173 return;
174 }
175
177 {
178 NS_LOG_INFO("Beam " << m_beamId << " already enabled");
179 return;
180 }
181
183
184 if (m_fwdScheduler == nullptr)
185 {
186 NS_FATAL_ERROR("Scheduler not set for GW MAC!!!");
187 }
188
190 m_fwdScheduler->ClearAllPackets();
191
199 Simulator::Schedule(Seconds(0), &SatGwMac::StartTransmission, this, 0);
200
201 if (m_broadcastNcr)
202 {
203 Simulator::Schedule(MilliSeconds(50), &SatGwMac::StartNcrTransmission, this);
204 }
205}
206
207void
208SatGwMac::Receive(SatPhy::PacketContainer_t packets, Ptr<SatSignalParameters> rxParams)
209{
210 NS_LOG_FUNCTION(this);
211
212 // Add packet trace entry:
213 m_packetTrace(Simulator::Now(),
215 m_nodeInfo->GetNodeType(),
216 m_nodeInfo->GetNodeId(),
217 m_nodeInfo->GetMacAddress(),
220 SatUtils::GetPacketInfo(packets));
221
222 // Invoke the `Rx` and `RxDelay` trace sources.
223 RxTraces(packets);
224
225 Address utId;
226
227 for (SatPhy::PacketContainer_t::iterator i = packets.begin(); i != packets.end(); i++)
228 {
229 // Remove packet tag
230 SatMacTag macTag;
231 bool mSuccess = (*i)->PeekPacketTag(macTag);
232 if (!mSuccess)
233 {
234 NS_FATAL_ERROR("MAC tag was not found from the packet!");
235 }
236 SatAddressE2ETag addressE2ETag;
237 mSuccess = (*i)->PeekPacketTag(addressE2ETag);
238 if (!mSuccess)
239 {
240 NS_FATAL_ERROR("Address E2E tag was not found from the packet!");
241 }
242
243 NS_LOG_INFO("Packet from " << macTag.GetSourceAddress() << " to "
244 << macTag.GetDestAddress());
245 NS_LOG_INFO("Receiver " << m_nodeInfo->GetMacAddress());
246
247 // If the packet is intended for this receiver
248 Mac48Address destAddress = macTag.GetDestAddress();
249 utId = addressE2ETag.GetE2ESourceAddress();
250
251 if (destAddress == m_nodeInfo->GetMacAddress() || destAddress.IsBroadcast())
252 {
253 // Peek control msg tag
254 SatControlMsgTag ctrlTag;
255 bool cSuccess = (*i)->PeekPacketTag(ctrlTag);
256
257 if (cSuccess)
258 {
260
262 {
263 uint32_t beamId;
264 uint32_t satId;
266 {
269 beamId = rxParams->m_beamId;
270 satId = rxParams->m_satId;
271 break;
272 }
275 SatUplinkInfoTag satUplinkInfoTag;
276 if (!(*i)->PeekPacketTag(satUplinkInfoTag))
277 {
278 NS_FATAL_ERROR("SatUplinkInfoTag not found!");
279 }
280 beamId = satUplinkInfoTag.GetBeamId();
281 satId = satUplinkInfoTag.GetSatId();
282 break;
283 }
284 default:
285 NS_FATAL_ERROR("Unknown regeneration mode");
286 }
287 ReceiveSignalingPacket(*i, satId, beamId);
288 }
289 else
290 {
291 NS_FATAL_ERROR("A control message received with not valid msg type!");
292 }
293 }
294 else
295 {
296 // Pass the source address to LLC
297 m_rxCallback(*i,
298 addressE2ETag.GetE2ESourceAddress(),
299 addressE2ETag.GetE2EDestAddress());
300 }
301 }
302 else
303 {
304 NS_LOG_INFO(
305 "Packet intended for others received by MAC: " << m_nodeInfo->GetMacAddress());
306 }
307 }
308
309 if (m_useCmt)
310 {
312 {
314 if (rxParams->m_txInfo.waveformId == 2)
315 {
316 SendCmtMessage(utId,
317 rxParams->m_duration,
318 Seconds(0),
319 rxParams->m_satId,
320 rxParams->m_beamId);
321 m_controlMessageReceivedCallback(utId, rxParams->m_satId, rxParams->m_beamId);
322 }
323 break;
324 }
326 if (rxParams->m_txInfo.waveformId == 2)
327 {
328 for (SatPhy::PacketContainer_t::iterator i = packets.begin(); i != packets.end();
329 i++)
330 {
331 SatControlMsgTag ctrlTag;
332 if ((*i)->PeekPacketTag(ctrlTag))
333 {
334 // This is a NCR CTRL packet, do not use it
335 continue;
336 }
337 SatUplinkInfoTag satUplinkInfoTag;
338 if (!(*i)->PeekPacketTag(satUplinkInfoTag))
339 {
340 NS_FATAL_ERROR("SatUplinkInfoTag not found !");
341 }
342 Time satelliteReceptionTime = satUplinkInfoTag.GetSatelliteReceptionTime();
343 uint32_t beamId = satUplinkInfoTag.GetBeamId();
344 uint32_t satId = satUplinkInfoTag.GetSatId();
345
346 SendCmtMessage(utId, Seconds(0), satelliteReceptionTime, satId, beamId);
347 m_controlMessageReceivedCallback(utId, satId, beamId);
348 }
349 }
350 break;
351 }
354 for (SatPhy::PacketContainer_t::iterator i = packets.begin(); i != packets.end(); i++)
355 {
356 SatUplinkInfoTag satUplinkInfoTag;
357 if (!(*i)->PeekPacketTag(satUplinkInfoTag))
358 {
359 NS_FATAL_ERROR("SatUplinkInfoTag not found !");
360 }
361 Time satelliteReceptionTime = satUplinkInfoTag.GetSatelliteReceptionTime();
362 uint32_t beamId = satUplinkInfoTag.GetBeamId();
363 uint32_t satId = satUplinkInfoTag.GetSatId();
364 bool isControl = satUplinkInfoTag.IsControl();
365
366 if (isControl)
367 {
368 SendCmtMessage(utId, Seconds(0), satelliteReceptionTime, satId, beamId);
369 m_controlMessageReceivedCallback(utId, satId, beamId);
370 }
371 }
372 break;
373 }
374 default:
375 NS_FATAL_ERROR("Unknown regeneration mode, or received");
376 }
377 }
378}
379
380void
382{
383 NS_LOG_FUNCTION(this << carrierId);
384
385 if (m_handoverModule != nullptr)
386 {
387 if (m_handoverModule->CheckForHandoverRecommendation(m_feederSatId, m_feederBeamId))
388 {
389 NS_LOG_INFO("GW handover, old satellite is " << m_feederSatId << ", old beam is "
390 << m_feederBeamId);
391
392 Ptr<SatBeamScheduler> srcScheduler =
394
395 m_feederSatId = m_handoverModule->GetAskedSatId();
396 m_feederBeamId = m_handoverModule->GetAskedBeamId();
397
398 NS_LOG_INFO("GW handover, new satellite is " << m_feederSatId << ", new beam is "
399 << m_feederBeamId);
400
401 Ptr<SatBeamScheduler> dstScheduler =
403 srcScheduler->DisconnectGw(m_nodeInfo->GetMacAddress());
404 dstScheduler->ConnectGw(m_nodeInfo->GetMacAddress());
405
407
408 Ptr<SatOrbiterNetDevice> orbiterNetDevice = DynamicCast<SatOrbiterNetDevice>(
409 Singleton<SatTopology>::Get()->GetOrbiterNode(m_feederSatId)->GetDevice(0));
410 Mac48Address satFeederAddress = orbiterNetDevice->GetSatelliteFeederAddress(m_beamId);
411 SetSatelliteAddress(satFeederAddress);
412
413 Ptr<SatGwLlc> gwLlc =
414 Singleton<SatTopology>::Get()->GetGwLlc(m_node, m_satId, m_beamId);
415 gwLlc->SetSatelliteAddress(satFeederAddress);
416
417 Singleton<SatTopology>::Get()->UpdateGwSatAndBeam(m_node,
420
422
423 m_handoverModule->HandoverFinished();
424 }
425 }
426
427 if (m_nodeInfo->GetNodeType() == SatEnums::NT_GW)
428 {
429 m_lastSOF.push(Simulator::Now());
430 uint8_t lastSOFSize = m_ncrV2 ? 3 : 1;
431 if (m_lastSOF.size() > lastSOFSize)
432 {
433 m_lastSOF.pop();
434 }
435 }
436
437 Time txDuration;
438
440 {
441 std::pair<Ptr<SatBbFrame>, const Time> bbFrameInfo = m_fwdScheduler->GetNextFrame();
442 Ptr<SatBbFrame> bbFrame = bbFrameInfo.first;
443 txDuration = bbFrameInfo.second;
444
445 // trace out BB frames sent.
446 m_bbFrameTxTrace(bbFrame);
447
448 // Handle both dummy frames and normal frames
449 if (bbFrame != nullptr)
450 {
451 // Add packet trace entry:
452 m_packetTrace(Simulator::Now(),
454 m_nodeInfo->GetNodeType(),
455 m_nodeInfo->GetNodeId(),
456 m_nodeInfo->GetMacAddress(),
459 SatUtils::GetPacketInfo(bbFrame->GetPayload()));
460
463 txInfo.modCod = bbFrame->GetModcod();
464 txInfo.sliceId = bbFrame->GetSliceId();
465 txInfo.frameType = bbFrame->GetFrameType();
466 txInfo.waveformId = 0;
467
471 SendPacket(bbFrame->GetPayload(), carrierId, txDuration - m_guardTime, txInfo);
472 }
473 }
474 else
475 {
480
481 NS_LOG_INFO("TX is disabled, thus nothing is transmitted!");
482 txDuration = m_fwdScheduler->GetDefaultFrameDuration();
483 }
484
486 {
494 Simulator::Schedule(txDuration, &SatGwMac::StartTransmission, this, 0);
495 }
496}
497
498void
499SatGwMac::TbtpSent(Ptr<SatTbtpMessage> tbtp)
500{
501 NS_LOG_FUNCTION(this << tbtp);
502
503 uint32_t superframeCounter = tbtp->GetSuperframeCounter();
504
505 if (m_tbtps.find(superframeCounter) == m_tbtps.end())
506 {
507 m_tbtps[superframeCounter] = std::vector<Ptr<SatTbtpMessage>>();
508 }
509 m_tbtps[superframeCounter].push_back(tbtp);
510
511 Simulator::Schedule(Seconds(10), &SatGwMac::RemoveTbtp, this, superframeCounter);
512}
513
514uint32_t
516{
517 NS_LOG_FUNCTION(this);
518
519 return m_feederSatId;
520}
521
522uint32_t
524{
525 NS_LOG_FUNCTION(this);
526
527 return m_feederBeamId;
528}
529
530void
531SatGwMac::RemoveTbtp(uint32_t superframeCounter)
532{
533 m_tbtps.erase(superframeCounter);
534}
535
536void
538{
539 NS_LOG_FUNCTION(this);
540
542
544 {
545 Simulator::Schedule(m_ncrInterval, &SatGwMac::StartNcrTransmission, this);
546 }
547}
548
549void
550SatGwMac::ReceiveSignalingPacket(Ptr<Packet> packet, uint32_t satId, uint32_t beamId)
551{
552 NS_LOG_FUNCTION(this << packet << beamId);
553
554 // Remove the mac tag
555 SatMacTag macTag;
556 packet->PeekPacketTag(macTag);
557
558 SatAddressE2ETag addressE2ETag;
559 packet->PeekPacketTag(addressE2ETag);
560
561 // Peek control msg tag
562 SatControlMsgTag ctrlTag;
563 bool cSuccess = packet->PeekPacketTag(ctrlTag);
564
565 if (!cSuccess)
566 {
567 NS_FATAL_ERROR("SatControlMsgTag not found in the packet!");
568 }
569
570 switch (ctrlTag.GetMsgType())
571 {
573 uint32_t msgId = ctrlTag.GetMsgId();
574 Ptr<SatCrMessage> crMsg = DynamicCast<SatCrMessage>(m_readCtrlCallback(msgId));
575
576 if (crMsg != nullptr)
577 {
578 Mac48Address sourceAddress;
580 {
583 sourceAddress = addressE2ETag.GetE2ESourceAddress();
584 break;
585 }
587 sourceAddress = Mac48Address::ConvertFrom(m_satelliteAddress);
588 break;
589 }
590 default:
591 NS_FATAL_ERROR("Unknown regeneration mode");
592 }
593 m_fwdScheduler->CnoInfoUpdated(sourceAddress, crMsg->GetCnoEstimate());
594
595 if (m_crReceiveCallback.IsNull() == false)
596 {
597 m_crReceiveCallback(satId, beamId, addressE2ETag.GetE2ESourceAddress(), crMsg);
598 }
599 }
600 else
601 {
607 std::stringstream msg;
608 msg << "Control message " << ctrlTag.GetMsgType()
609 << " is not found from the RTN link control msg container!";
610 msg << " at: " << Now().GetSeconds() << "s";
611 Singleton<SatLog>::Get()->AddToLog(SatLog::LOG_WARNING, "", msg.str());
612 }
613
614 packet->RemovePacketTag(macTag);
615 packet->RemovePacketTag(addressE2ETag);
616 packet->RemovePacketTag(ctrlTag);
617
618 break;
619 }
621 uint32_t msgId = ctrlTag.GetMsgId();
622 Ptr<SatCnoReportMessage> cnoReport =
623 DynamicCast<SatCnoReportMessage>(m_readCtrlCallback(msgId));
624
625 if (cnoReport != nullptr)
626 {
627 m_fwdScheduler->CnoInfoUpdated(addressE2ETag.GetE2ESourceAddress(),
628 cnoReport->GetCnoEstimate());
629 }
630 else
631 {
637 std::stringstream msg;
638 msg << "Control message " << ctrlTag.GetMsgType()
639 << " is not found from the RTN link control msg container!";
640 msg << " at: " << Now().GetSeconds() << "s";
641 Singleton<SatLog>::Get()->AddToLog(SatLog::LOG_WARNING, "", msg.str());
642 }
643
644 packet->RemovePacketTag(macTag);
645 packet->RemovePacketTag(addressE2ETag);
646 packet->RemovePacketTag(ctrlTag);
647
648 break;
649 }
651 // ARQ ACK messages are forwarded to LLC, since they may be fragmented
652 m_rxCallback(packet, addressE2ETag.GetE2ESourceAddress(), macTag.GetDestAddress());
653 break;
654 }
656 uint32_t msgId = ctrlTag.GetMsgId();
657 Ptr<SatHandoverRecommendationMessage> handoverRecommendation =
658 DynamicCast<SatHandoverRecommendationMessage>(m_readCtrlCallback(msgId));
659
660 if (handoverRecommendation != nullptr)
661 {
662 uint32_t newSatId = handoverRecommendation->GetRecommendedSatId();
663 uint32_t newBeamId = handoverRecommendation->GetRecommendedBeamId();
665 satId,
666 beamId,
667 newSatId,
668 newBeamId);
669 }
670 else
671 {
677 std::stringstream msg;
678 msg << "Control message " << ctrlTag.GetMsgType()
679 << " is not found from the RTN link control msg container!";
680 msg << " at: " << Now().GetSeconds() << "s";
681 Singleton<SatLog>::Get()->AddToLog(SatLog::LOG_WARNING, "", msg.str());
682 }
683
684 break;
685 }
687 uint32_t msgId = ctrlTag.GetMsgId();
688 Ptr<SatLogonMessage> logonMessage = DynamicCast<SatLogonMessage>(m_readCtrlCallback(msgId));
689
690 if (logonMessage != nullptr)
691 {
692 Address utId = addressE2ETag.GetE2ESourceAddress();
693 Callback<void, uint32_t> raChannelCallback =
694 MakeBoundCallback(&SatGwMac::SendLogonResponseHelper, this, utId);
695 m_logonCallback(utId, satId, beamId, raChannelCallback);
696 }
697 else
698 {
704 std::stringstream msg;
705 msg << "Control message " << ctrlTag.GetMsgType()
706 << " is not found from the RTN link control msg container!";
707 msg << " at: " << Now().GetSeconds() << "s";
708 Singleton<SatLog>::Get()->AddToLog(SatLog::LOG_WARNING, "", msg.str());
709 }
710 break;
711 }
713 // We do nothing, from SAT to GW, these messages only add load on link
714 break;
715 }
716 default: {
717 NS_FATAL_ERROR("SatGwMac received a non-supported control packet!");
718 break;
719 }
720 }
721}
722
723void
725{
726 NS_LOG_FUNCTION(this);
727
728 Ptr<SatNcrMessage> ncrMessage = CreateObject<SatNcrMessage>();
729 m_fwdScheduler->SendControlMsg(ncrMessage, Mac48Address::GetBroadcast());
730 m_ncrMessagesToSend.push(ncrMessage);
731}
732
733void
735 Time burstDuration,
736 Time satelliteReceptionTime,
737 uint32_t satId,
738 uint32_t beamId)
739{
740 NS_LOG_FUNCTION(this << utId);
741
742 Time lastCmtSent = Seconds(0);
743 if (m_lastCmtSent.find(utId) != m_lastCmtSent.end())
744 {
745 lastCmtSent = m_lastCmtSent[utId];
746 }
747
748 Time timeReceived = satelliteReceptionTime;
749 if (satelliteReceptionTime == Seconds(0))
750 {
751 timeReceived = Simulator::Now();
752 }
753
754 if (timeReceived < lastCmtSent + m_cmtPeriodMin)
755 {
756 return;
757 }
758
759 uint32_t indexClosest = 0;
760 uint32_t tbtpIndexClosest = 0;
761 uint32_t timeSlotIndexClosest = 0;
762 Time differenceClosest = Seconds(1000000);
763 std::vector<Ptr<SatTbtpMessage>> tbtpsForCurrentSF;
764 Ptr<SatTbtpMessage> tbtp;
765 for (uint32_t i = 0; i < m_tbtps.size(); i++)
766 {
767 tbtpsForCurrentSF = m_tbtps[i];
768 for (uint32_t tbtpIndex = 0; tbtpIndex < tbtpsForCurrentSF.size(); tbtpIndex++)
769 {
770 tbtp = tbtpsForCurrentSF[tbtpIndex];
771 std::pair<uint8_t, std::vector<Ptr<SatTimeSlotConf>>> timeslots =
772 tbtp->GetDaTimeslots(utId);
773 for (uint32_t j = 0; j < timeslots.second.size(); j++)
774 {
775 Ptr<SatTimeSlotConf> tsConf = timeslots.second[j];
776 if (tsConf->GetSlotType() == SatTimeSlotConf::SLOT_TYPE_C)
777 {
778 Time frameStartTime = Singleton<SatRtnLinkTime>::Get()->GetSuperFrameTxTime(
780 i,
781 Seconds(0));
782 Time slotStartTime = tsConf->GetStartTime();
783 Time difference = timeReceived - frameStartTime - slotStartTime - burstDuration;
784 if (Abs(difference) < differenceClosest)
785 {
786 differenceClosest = Abs(difference);
787 indexClosest = i;
788 timeSlotIndexClosest = j;
789 tbtpIndexClosest = tbtpIndex;
790 }
791 }
792 }
793 }
794 }
795
796 if (indexClosest == 0)
797 {
798 return;
799 }
800
801 tbtp = m_tbtps[indexClosest][tbtpIndexClosest];
802 std::pair<uint8_t, std::vector<Ptr<SatTimeSlotConf>>> timeslots = tbtp->GetDaTimeslots(utId);
803
804 if (timeslots.second[timeSlotIndexClosest]->GetSlotType() == 0)
805 {
806 Time frameStartTime = Singleton<SatRtnLinkTime>::Get()->GetSuperFrameTxTime(
808 indexClosest,
809 Seconds(0));
810 Time slotStartTime = timeslots.second[timeSlotIndexClosest]->GetStartTime();
811
812 Time difference = frameStartTime + slotStartTime + burstDuration - timeReceived;
813 int32_t differenceNcr = difference.GetMicroSeconds() * 27;
814
815 if (differenceNcr > 16256 || differenceNcr < -16256)
816 {
817 NS_LOG_INFO("Burst Time Correction outside bounds, should be at least -16256 and at "
818 "most 16256, but got "
819 << differenceNcr << ". Forcing logoff of UT " << utId);
820 Ptr<SatLogoffMessage> logoffMsg = CreateObject<SatLogoffMessage>();
821 m_fwdScheduler->SendControlMsg(logoffMsg, utId);
822 m_removeUtCallback(utId, satId, beamId);
823 }
824 else
825 {
826 Ptr<SatCmtMessage> cmt = CreateObject<SatCmtMessage>();
827 cmt->SetBurstTimeCorrection(differenceNcr);
828 m_fwdScheduler->SendControlMsg(cmt, utId);
829 m_lastCmtSent[utId] = Simulator::Now();
830 }
831
832 return;
833 }
834}
835
836void
837SatGwMac::SendLogonResponse(Address utId, uint32_t raChannel)
838{
839 NS_LOG_FUNCTION(this << utId << raChannel);
840 Ptr<SatLogonResponseMessage> logonResponse = CreateObject<SatLogonResponseMessage>();
841 logonResponse->SetRaChannel(raChannel);
842 m_fwdScheduler->SendControlMsg(logonResponse, utId);
843}
844
845void
846SatGwMac::SendLogonResponseHelper(SatGwMac* self, Address utId, uint32_t raChannel)
847{
848 self->SendLogonResponse(utId, raChannel);
849}
850
851void
853{
854 NS_LOG_FUNCTION(this << &cb);
856}
857
858void
860{
861 NS_LOG_FUNCTION(this << &cb);
863}
864
865void
867{
868 NS_LOG_FUNCTION(this << &cb);
869 m_logonCallback = cb;
870}
871
872void
878
879void
881{
882 NS_LOG_FUNCTION(this << &cb);
884}
885
886void
888{
889 NS_LOG_FUNCTION(this << &cb);
891}
892
893void
895{
896 NS_LOG_FUNCTION(this << &cb);
897 m_beamCallback = cb;
898}
899
900void
901SatGwMac::SetFwdScheduler(Ptr<SatFwdLinkScheduler> fwdScheduler)
902{
903 m_fwdScheduler = fwdScheduler;
904
905 if (m_ncrV2)
906 {
907 m_fwdScheduler->SetDummyFrameSendingEnabled(true);
908 }
909}
910
911void
912SatGwMac::ChangeBeam(uint32_t satId, uint32_t beamId)
913{
914 NS_LOG_FUNCTION(this << satId << beamId);
915}
916
917void
918SatGwMac::ConnectUt(Mac48Address utAddress)
919{
920 NS_LOG_FUNCTION(this << utAddress);
921
922 NS_ASSERT(m_peers.find(utAddress) == m_peers.end());
923
925 {
926 NS_LOG_INFO("Start beam " << m_beamId);
927 m_peers.insert(utAddress);
929 }
930 else
931 {
932 m_peers.insert(utAddress);
933 }
934}
935
936void
937SatGwMac::DisconnectUt(Mac48Address utAddress)
938{
939 NS_LOG_FUNCTION(this << utAddress);
940
941 NS_ASSERT(m_peers.find(utAddress) != m_peers.end());
942
943 m_peers.erase(utAddress);
944
946 {
947 NS_LOG_INFO("Stop beam " << m_beamId);
949 }
950}
951
952void
954{
955 NS_LOG_FUNCTION(this);
956
958}
959
960bool
962{
963 NS_LOG_FUNCTION(this);
964
965 return !m_peers.empty();
966}
967
968} // 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.
@ SAT_LOGON_CTRL_MSG
SAT_LOGON_CTRL_MSG.
@ SAT_CMT_CTRL_MSG
SAT_CMT_CTRL_MSG.
virtual uint32_t GetMsgId() const
Get message type specific identifier.
SatControlMsgType_t GetMsgType(void) const
Get type of the control message.
GW specific Mac class for Sat Net Devices.
void SetLogonCallback(SatGwMac::LogonCallback cb)
Method to set logon callback.
bool m_disableSchedulingIfNoDeviceConnected
If true, the periodic calls of StartTransmission are not called when no devices are connected to this...
SatGwMac::HandoverCallback m_handoverCallback
Callback to query/apply handover on the terrestrial network.
Ptr< SatFwdLinkScheduler > m_fwdScheduler
Scheduler for the forward link.
void TbtpSent(Ptr< SatTbtpMessage > tbtp)
Function called when a TBTP has been sent by the SatBeamScheduler.
Callback< void > ClearQueuesCallback
Callback to clear LLC queues.
SatGwMac::TxOpportunityCallback m_txOpportunityCallback
Callback to notify the txOpportunity to upper layer Returns a packet Attributes: payload in bytes.
void SendLogonResponse(Address utId, uint32_t raChannel)
std::map< Address, Time > m_lastCmtSent
Time of last CMT sending for each UT.
void SetRemoveUtCallback(SatGwMac::RemoveUtCallback cb)
Method to set callback for UT removing.
Time m_cmtPeriodMin
Minimum interval between two CMT control messages for a same UT.
Callback< void, Address, uint32_t, uint32_t > RemoveUtCallback
Callback to indicate NCC a UT needs to be removed.
void SetFwdScheduler(Ptr< SatFwdLinkScheduler > fwdScheduler)
Method to set forward link scheduler.
static TypeId GetTypeId(void)
Get the type ID.
SatGwMac::PhyBeamCallback m_beamCallback
Callback to change phy-layer beam ID.
SatGwMac::CrReceiveCallback m_crReceiveCallback
Capacity request receive callback.
bool m_broadcastNcr
Broadcast NCR messages to all UTs.
void ChangeBeam(uint32_t satId, uint32_t beamId)
Method handling beam handover.
static void SendLogonResponseHelper(SatGwMac *self, Address utId, uint32_t raChannel)
void SetHandoverCallback(SatGwMac::HandoverCallback cb)
Method to set handover callback.
void ConnectUt(Mac48Address utAddress)
Connect a UT to this satellite.
bool HasPeer()
Indicates if at least one device is connected in this beam.
SatGwMac::ClearQueuesCallback m_clearQueuesCallback
Callback to clear LLC queues.
void SetCrReceiveCallback(SatGwMac::CrReceiveCallback cb)
Method to set read control message callback.
uint32_t m_feederBeamId
ID of beam linked to this GW.
SatGwMac::LogonCallback m_logonCallback
Callback to log a terminal on.
Callback< void, Address, uint32_t, uint32_t, Callback< void, uint32_t > > LogonCallback
Callback to register UT logon.
void StartNcrTransmission()
Send a NCR packet to the UTs.
void ReceiveSignalingPacket(Ptr< Packet > packet, uint32_t satId, uint32_t beamId)
Signaling packet receiver, which handles all the signaling packet receptions.
~SatGwMac()
Destroy a SatGwMac.
SatGwMac()
Default constructor, which is not used.
uint32_t GetFeederBeamId()
Get ID of beam linked to this GW.
TracedCallback< Ptr< SatBbFrame > > m_bbFrameTxTrace
Trace for transmitted BB frames.
void SendCmtMessage(Address utId, Time burstDuration, Time satelliteReceptionTime, uint32_t satId, uint32_t beamId)
void StartTransmission(uint32_t carrierId)
Start sending a Packet Down the Wire.
Callback< void, uint32_t, uint32_t, Address, Ptr< SatCrMessage > > CrReceiveCallback
Callback to receive capacity request (CR) messages.
SatGwMac::RemoveUtCallback m_removeUtCallback
Callback to indicate NCC a UT needs to be removed.
SatGwMac::ControlMessageReceivedCallback m_controlMessageReceivedCallback
Callback to indicate NCC a control burst has been received.
std::map< uint32_t, std::vector< Ptr< SatTbtpMessage > > > m_tbtps
List of TBTPs sent to UTs.
void Receive(SatPhy::PacketContainer_t packets, Ptr< SatSignalParameters >)
Receive packet from lower layer.
void SetControlMessageReceivedCallback(SatGwMac::ControlMessageReceivedCallback cb)
Method to set callback for control burst reception.
Callback< void, Address, uint32_t, uint32_t, uint32_t, uint32_t > HandoverCallback
Callback to query/apply handover on the terrestrial network.
bool m_useCmt
Use CMT control messages to correct time on the UTs.
uint32_t GetFeederSatId()
Get ID of satellite linked to this GW.
void RemoveTbtp(uint32_t superframeCounter)
Function used to clear old TBTP.
bool m_periodicTransmissionEnabled
Indicated if periodic transmission is enabled.
Callback< void, uint32_t, uint32_t > PhyBeamCallback
Callback to change phy-layer beam ID.
void StartPeriodicTransmissions()
Starts periodical transmissions.
void SetBeamCallback(SatGwMac::PhyBeamCallback cb)
Method to set phy-layer beam handover callback.
virtual void StopPeriodicTransmissions()
Stop periodic transmission, until a pacquet in enqued.
std::set< Mac48Address > m_peers
List of UT MAC connected to this MAC.
void DisconnectUt(Mac48Address utAddress)
Disconnect a UT to this satellite.
Ptr< Node > m_node
Node containing this MAC.
Time m_ncrInterval
Interval between two broadcast of NCR dates.
Callback< void, Address, uint32_t, uint32_t > ControlMessageReceivedCallback
Callback to inform NCC a control burst has been received.
uint32_t m_feederSatId
ID of satellite linked to this GW.
Time m_guardTime
Guard time for BB frames.
void SetClearQueuesCallback(SatGwMac::ClearQueuesCallback cb)
Method to set callback for LLC queues clearing.
@ LOG_WARNING
LOG_WARNING.
void RxTraces(SatPhy::PacketContainer_t packets)
Invoke the Rx trace source for each received packet.
uint32_t m_beamId
The ID of the beam where mac belongs.
virtual void SetSatelliteAddress(Address satelliteAddress)
Set the satellite MAC address on the other side of this link (if regenerative satellite).
SatMac::BeamSchedulerCallback m_beamSchedulerCallback
Callback to get the SatBeamScheduler linked to a beam ID.
std::queue< Ptr< SatNcrMessage > > m_ncrMessagesToSend
List of NCR control messages created but not sent yet.
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.
Address m_satelliteAddress
MAC address of satellite on other side of the link.
void DoDispose(void)
Dispose of SatMac.
SatMac::ReceiveCallback m_rxCallback
The upper layer package receive callback.
bool m_ncrV2
Use of version 2 of NCR dates.
Ptr< SatHandoverModule > m_handoverModule
Module used to perform handovers.
bool m_txEnabled
Flag indicating whether the MAC is enabled, i.e.
SatMac::ReadCtrlMsgCallback m_readCtrlCallback
The read control message callback.
SatMac()
Construct a SatMac.
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.
uint32_t m_satId
The ID of the sat where mac belongs.
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.
std::queue< Time > m_lastSOF
Store last 3 SOF date for Forward messages, to insert in NCR packets.
SatMac::UpdateIslCallback m_updateIslCallback
The update ISL routes callback.
This class implements a tag that carries the satellite MAC specific information, such as source and d...
Mac48Address GetSourceAddress(void) const
Get source MAC address.
Mac48Address GetDestAddress(void) const
Get destination MAC address.
SatSignalParameters::PacketsInBurst_t PacketContainer_t
Define PacketContainer in SatPhy.
static std::string GetPacketInfo(const Ptr< const Packet > p)
Get packet information in std::string for printing purposes.
constexpr uint8_t SUPERFRAME_SEQUENCE
Used superframe sequence in the RTN link.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
Struct for storing the packet specific Tx information.