Loading...
Searching...
No Matches
satellite-control-message.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 * Copyright (c) 2018 CNES
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation;
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Author: Sami Rantanen <sami.rantanen@magister.fi>
20 * Author: Mathias Ettinger <mettinger@toulouse.viveris.com>
21 */
22
24
25#include "satellite-enums.h"
26
27#include "ns3/address-utils.h"
28#include "ns3/enum.h"
29#include "ns3/log.h"
30#include "ns3/uinteger.h"
31
32#include <iostream>
33#include <map>
34#include <ostream>
35#include <utility>
36
37NS_LOG_COMPONENT_DEFINE("SatCtrlMessage");
38
39namespace ns3
40{
41
42NS_OBJECT_ENSURE_REGISTERED(SatControlMsgTag);
43
46 m_msgId(0)
47{
48 NS_LOG_FUNCTION(this);
49}
50
52{
53 NS_LOG_FUNCTION(this);
54}
55
56TypeId
58{
59 static TypeId tid =
60 TypeId("ns3::SatControlMsgTag").SetParent<Tag>().AddConstructor<SatControlMsgTag>();
61 return tid;
62}
63
64TypeId
66{
67 NS_LOG_FUNCTION(this);
68
69 return GetTypeId();
70}
71
72void
74{
75 NS_LOG_FUNCTION(this << type);
76 m_msgType = type;
77}
78
81{
82 NS_LOG_FUNCTION(this);
83 return m_msgType;
84}
85
86uint32_t
88{
89 NS_LOG_FUNCTION(this);
90
91 return (sizeof(m_msgType) + sizeof(m_msgId));
92}
93
94void
96{
97 NS_LOG_FUNCTION(this << &i);
98 i.WriteU32(m_msgType);
99 i.WriteU32(m_msgId);
100}
101
102void
104{
105 NS_LOG_FUNCTION(this << &i);
106 m_msgType = (SatControlMsgType_t)i.ReadU32();
107 m_msgId = i.ReadU32();
108}
109
110void
111SatControlMsgTag::Print(std::ostream& os) const
112{
113 NS_LOG_FUNCTION(this << &os);
114 os << "SatControlMsgType=" << m_msgType << m_msgId;
115}
116
117void
119{
120 NS_LOG_FUNCTION(this << m_msgId);
121 m_msgId = msgId;
122}
123
124uint32_t
126{
127 NS_LOG_FUNCTION(this);
128
129 return m_msgId;
130}
131
132// Control message
133
134NS_OBJECT_ENSURE_REGISTERED(SatControlMessage);
135
136TypeId
138{
139 static TypeId tid = TypeId("ns3::SatControlMessage").SetParent<Object>();
140 return tid;
141}
142
143// TBTP message
144
145NS_OBJECT_ENSURE_REGISTERED(SatTbtpMessage);
146
151{
152 NS_LOG_FUNCTION(this);
153}
154
157 m_superframeSeqId(seqId),
159{
160 NS_LOG_FUNCTION(this << (uint32_t)seqId);
161}
162
164{
165 NS_LOG_FUNCTION(this);
166
167 m_frameIds.clear();
168 m_daTimeSlots.clear();
169}
170
171TypeId
173{
174 static TypeId tid = TypeId("ns3::SatTbtpMessage")
175 .SetParent<SatControlMessage>()
176 .AddConstructor<SatTbtpMessage>()
177 .AddAttribute("AssigmentFormat",
178 "Assignment format of assignment IDs in TBTP.)",
179 UintegerValue(0),
180 MakeUintegerAccessor(&SatTbtpMessage::m_assignmentFormat),
181 MakeUintegerChecker<uint8_t>());
182 return tid;
183}
184
187{
188 NS_LOG_FUNCTION(this << utId);
189
190 DaTimeSlotMap_t::const_iterator it = m_daTimeSlots.find(utId);
191
192 if (it != m_daTimeSlots.end())
193 {
194 return it->second;
195 }
196
198}
199
200void
201SatTbtpMessage::SetDaTimeslot(Mac48Address utId, uint8_t frameId, Ptr<SatTimeSlotConf> conf)
202{
203 NS_LOG_FUNCTION(this << utId << frameId << conf);
204
205 // find container for the UT from map
206 DaTimeSlotMap_t::iterator it = m_daTimeSlots.find(utId);
207
208 // If not found, add new UT container to map,
209 // otherwise use container found from map
210 if (it == m_daTimeSlots.end())
211 {
212 std::pair<DaTimeSlotMap_t::iterator, bool> result =
213 m_daTimeSlots.insert(std::make_pair(utId, DaTimeSlotInfoItem_t()));
214
215 if (result.second)
216 {
217 it = result.first;
218 }
219 else
220 {
221 // container creation for UT has failed, so we need to crash
222 NS_FATAL_ERROR("Cannot insert slot to container!!!");
223 }
224 }
225
226 // store time slot info to user specific container
227 it->second.first = frameId;
228 it->second.second.push_back(conf);
229
230 // store frame ID to keep track of the used frames count
231 m_frameIds.insert(frameId);
232}
233
236{
237 NS_LOG_FUNCTION(this);
238
240
241 for (RaChannelMap_t::const_iterator it = m_raChannels.begin(); it != m_raChannels.end(); it++)
242 {
243 channels.insert(it->second);
244 }
245
246 return channels;
247}
248
249void
250SatTbtpMessage::SetRaChannel(uint32_t raChannel, uint8_t frameId, uint16_t timeSlotCount)
251{
252 NS_LOG_FUNCTION(this << raChannel << (uint32_t)frameId << timeSlotCount);
253
254 // find index for the RA channel from map
255 RaChannelMap_t::iterator it = m_raChannels.find(raChannel);
256
257 // If not found, add RA channel to map,
258 // otherwise raise error
259 if (it == m_raChannels.end())
260 {
261 std::pair<RaChannelMap_t::iterator, bool> result =
262 m_raChannels.insert(std::make_pair(raChannel, timeSlotCount));
263
264 if (result.second == false)
265 {
266 NS_FATAL_ERROR("RA channel insertion failed!!!");
267 }
268 }
269 else
270 {
271 NS_FATAL_ERROR("RA channel already exists in the container!!!");
272 }
273
274 // store frame ID to count used frames
275 m_frameIds.insert(frameId);
276}
277
278uint32_t
280{
281 uint32_t assignmentIdSizeInBytes = 0;
282
283 switch (m_assignmentFormat)
284 {
285 case 0:
286 // assignment id 48 bits
287 assignmentIdSizeInBytes = 6;
288 break;
289
290 case 1:
291 // assignment id 8 bits
292 assignmentIdSizeInBytes = 1;
293 break;
294
295 case 2:
296 // assignment id 16 bits
297 assignmentIdSizeInBytes = 2;
298 break;
299
300 case 3:
301 // assignment id 24 bits
302 assignmentIdSizeInBytes = 3;
303 break;
304
305 case 10:
306 // dynamic tx type 8 bits + assignment id 8 bits
307 assignmentIdSizeInBytes = 2;
308 break;
309
310 case 11:
311 // dynamic tx type 8 bits + assignment id 16 bits
312 assignmentIdSizeInBytes = 3;
313 break;
314
315 case 12:
316 // dynamic tx type 8 bits + assignment id 24 bits
317 assignmentIdSizeInBytes = 4;
318 break;
319
320 default:
321 NS_FATAL_ERROR("Assignment format=" << m_assignmentFormat << " not supported!!!");
322 break;
323 }
324
325 return assignmentIdSizeInBytes;
326}
327
328uint32_t
330{
331 NS_LOG_FUNCTION(this);
332
333 // see definition for TBTP2 from specification ETSI EN 301 545-2 (V1.1.1), chapter 6.4.9
334
335 uint32_t sizeInBytes = m_tbtpBodySizeInBytes + (m_frameIds.size() * m_tbtpFrameBodySizeInBytes);
336 uint32_t assignmentIdSizeInBytes = GetTimeSlotInfoSizeInBytes();
337
338 // add size of DA time slots
339 for (DaTimeSlotMap_t::const_iterator it = m_daTimeSlots.begin(); it != m_daTimeSlots.end();
340 it++)
341 {
342 sizeInBytes += (it->second.second.size() * assignmentIdSizeInBytes);
343 }
344
345 // add size of RA time slots
346 for (RaChannelMap_t::const_iterator it = m_raChannels.begin(); it != m_raChannels.end(); it++)
347 {
348 sizeInBytes += (it->second * assignmentIdSizeInBytes);
349 }
350
351 return sizeInBytes;
352}
353
354void
356{
357 std::cout << "Superframe counter: " << m_superframeCounter
358 << ", superframe sequence id: " << m_superframeSeqId
359 << ", assignment format: " << m_assignmentFormat << std::endl;
360
361 for (DaTimeSlotMap_t::const_iterator mit = m_daTimeSlots.begin(); mit != m_daTimeSlots.end();
362 ++mit)
363 {
364 std::cout << "UT: " << mit->first << ": ";
365 std::cout << "Frame ID: " << mit->second.first << ": ";
366 std::cout << mit->second.second.size() << " ";
367 std::cout << std::endl;
368 }
369}
370
371NS_OBJECT_ENSURE_REGISTERED(SatCrMessage);
372
373TypeId
375{
376 static TypeId tid = TypeId("ns3::SatCrMessage")
377 .SetParent<SatControlMessage>()
378 .AddConstructor<SatCrMessage>()
379 .AddAttribute("CrBlockType",
380 "Capacity request control block size type",
382 MakeEnumAccessor<SatCrMessage::SatCrBlockSize_t>(
384 MakeEnumChecker(SatCrMessage::CR_BLOCK_SMALL,
385 "Small",
387 "Large"));
388 return tid;
389}
390
394{
395 NS_LOG_FUNCTION(this);
396}
397
399{
400 NS_LOG_FUNCTION(this);
401}
402
403void
406 uint32_t value)
407{
408 NS_LOG_FUNCTION(this << (uint32_t)rcIndex << cac << value);
409
410 RequestDescriptor_t p = std::make_pair(rcIndex, cac);
411 m_requestData.insert(std::make_pair(p, value));
412}
413
419
420uint32_t
425
426double
428{
429 NS_LOG_FUNCTION(this);
430 return m_forwardLinkCNo;
431}
432
433void
435{
436 NS_LOG_FUNCTION(this << cno);
437 m_forwardLinkCNo = cno;
438}
439
440uint32_t
442{
443 NS_LOG_FUNCTION(this);
444
449 uint32_t crBlockSizeInBytes = (m_crBlockSizeType == SatCrMessage::CR_BLOCK_SMALL ? 2 : 3);
450
452 m_requestData.size() * crBlockSizeInBytes);
453 return size;
454}
455
456bool
458{
459 return !m_requestData.empty();
460}
461
462NS_OBJECT_ENSURE_REGISTERED(SatCnoReportMessage);
463
464TypeId
466{
467 static TypeId tid = TypeId("ns3::SatCnoReportMessage")
468 .SetParent<SatControlMessage>()
469 .AddConstructor<SatCnoReportMessage>();
470 return tid;
471}
472
474 : m_linkCNo(NAN)
475{
476 NS_LOG_FUNCTION(this);
477}
478
480{
481 NS_LOG_FUNCTION(this);
482}
483
484double
486{
487 NS_LOG_FUNCTION(this);
488 return m_linkCNo;
489}
490
491void
493{
494 NS_LOG_FUNCTION(this << cno);
495 m_linkCNo = cno;
496}
497
498uint32_t
500{
501 NS_LOG_FUNCTION(this);
502 return sizeof(m_linkCNo);
503}
504
505NS_OBJECT_ENSURE_REGISTERED(SatRaMessage);
506
507TypeId
509{
510 static TypeId tid =
511 TypeId("ns3::SatRaMessage").SetParent<SatControlMessage>().AddConstructor<SatRaMessage>();
512 return tid;
513}
514
519{
520 NS_LOG_FUNCTION(this);
521}
522
524{
525 NS_LOG_FUNCTION(this);
526}
527
528void
529SatRaMessage::SetAllocationChannelId(uint8_t allocationChannelId)
530{
531 NS_LOG_FUNCTION(this << (uint32_t)allocationChannelId);
532
533 m_allocationChannelId = allocationChannelId;
534}
535
536uint8_t
541
542void
543SatRaMessage::SetBackoffProbability(uint16_t backoffProbability)
544{
545 NS_LOG_FUNCTION(this << backoffProbability);
546
547 m_backoffProbability = backoffProbability;
548}
549
550void
551SatRaMessage::SetBackoffTime(uint16_t backoffTime)
552{
553 NS_LOG_FUNCTION(this << backoffTime);
554
555 m_backoffTime = backoffTime;
556}
557
558uint16_t
563
564uint16_t
566{
567 return m_backoffTime;
568}
569
570uint32_t
572{
573 NS_LOG_FUNCTION(this);
574
575 uint32_t size(RA_CONTROL_MSG_HEADER_SIZE_IN_BYTES + sizeof(uint8_t) + sizeof(uint16_t) +
576 sizeof(uint16_t));
577 return size;
578}
579
580NS_OBJECT_ENSURE_REGISTERED(SatArqAckMessage);
581
582TypeId
584{
585 static TypeId tid = TypeId("ns3::SatArqAckMessage")
586 .SetParent<SatControlMessage>()
587 .AddConstructor<SatArqAckMessage>();
588 return tid;
589}
590
592 : m_sequenceNumber(0),
593 m_flowId(0)
594{
595 NS_LOG_FUNCTION(this);
596}
597
599{
600 NS_LOG_FUNCTION(this);
601}
602
603void
605{
606 NS_LOG_FUNCTION(this);
607 m_sequenceNumber = sn;
608}
609
610uint8_t
615
616void
618{
619 NS_LOG_FUNCTION(this);
620 m_flowId = flowId;
621}
622
623uint8_t
625{
626 return m_flowId;
627}
628
629uint32_t
631{
632 NS_LOG_FUNCTION(this);
633
634 uint32_t size = 2 * sizeof(uint8_t);
635 return size;
636}
637
638NS_OBJECT_ENSURE_REGISTERED(SatTimuMessage);
639
640TypeId
642{
643 static TypeId tid = TypeId("ns3::SatTimuMessage")
644 .SetParent<SatControlMessage>()
645 .AddConstructor<SatTimuMessage>();
646 return tid;
647}
648
650 : m_beamId(0)
651{
652 NS_LOG_FUNCTION(this);
653}
654
656{
657 NS_LOG_FUNCTION(this);
658}
659
660void
662{
663 NS_LOG_FUNCTION(this);
664 m_beamId = beamId;
665}
666
667uint32_t
669{
670 NS_LOG_FUNCTION(this);
671 return m_beamId;
672}
673
674void
676{
677 NS_LOG_FUNCTION(this);
678 m_satId = satId;
679}
680
681uint32_t
683{
684 NS_LOG_FUNCTION(this);
685 return m_satId;
686}
687
688void
690{
691 NS_LOG_FUNCTION(this);
692 m_satAddress = address;
693}
694
695Address
697{
698 NS_LOG_FUNCTION(this);
699 return m_satAddress;
700}
701
702void
704{
705 NS_LOG_FUNCTION(this);
706 m_gwAddress = address;
707}
708
709Address
711{
712 NS_LOG_FUNCTION(this);
713 return m_gwAddress;
714}
715
716uint32_t
718{
719 NS_LOG_FUNCTION(this);
720
721 uint32_t size = sizeof(uint32_t) + 2 * sizeof(Address);
722 return size;
723}
724
725NS_OBJECT_ENSURE_REGISTERED(SatHandoverRecommendationMessage);
726
727TypeId
729{
730 static TypeId tid = TypeId("ns3::SatHandoverRecommendationMessage")
731 .SetParent<SatControlMessage>()
732 .AddConstructor<SatHandoverRecommendationMessage>();
733 return tid;
734}
735
737 : m_beamId(0),
738 m_satId(0)
739{
740 NS_LOG_FUNCTION(this);
741}
742
747
748void
750{
751 NS_LOG_FUNCTION(this << beamId);
752 m_beamId = beamId;
753}
754
755uint32_t
760
761void
763{
764 NS_LOG_FUNCTION(this << satId);
765 m_satId = satId;
766}
767
768uint32_t
773
774uint32_t
776{
777 NS_LOG_FUNCTION(this);
778
779 uint32_t size = 2 * sizeof(uint32_t);
780 return size;
781}
782
783NS_OBJECT_ENSURE_REGISTERED(SatSliceSubscriptionMessage);
784
785TypeId
787{
788 static TypeId tid = TypeId("ns3::SatSliceSubscriptionMessage")
789 .SetParent<SatControlMessage>()
790 .AddConstructor<SatSliceSubscriptionMessage>();
791 return tid;
792}
793
795 : m_sliceId(0)
796{
797 NS_LOG_FUNCTION(this);
798}
799
804
805void
807{
808 NS_LOG_FUNCTION(this);
809 m_sliceId = sliceId;
810}
811
812uint32_t
817
818Mac48Address
823
824void
826{
827 m_address = address;
828}
829
830uint32_t
832{
833 NS_LOG_FUNCTION(this);
834
835 uint32_t size = 1 * sizeof(uint8_t);
836 return size;
837}
838
839NS_OBJECT_ENSURE_REGISTERED(SatLogonMessage);
840
841TypeId
843{
844 static TypeId tid = TypeId("ns3::SatLogonMessage")
845 .SetParent<SatControlMessage>()
846 .AddConstructor<SatLogonMessage>();
847 return tid;
848}
849
851{
852 NS_LOG_FUNCTION(this);
853}
854
856{
857 NS_LOG_FUNCTION(this);
858}
859
860uint32_t
862{
863 NS_LOG_FUNCTION(this);
864
865 uint32_t size = 1 * sizeof(uint8_t);
866 return size;
867}
868
869NS_OBJECT_ENSURE_REGISTERED(SatLogonResponseMessage);
870
871TypeId
873{
874 static TypeId tid = TypeId("ns3::SatLogonResponseMessage")
875 .SetParent<SatControlMessage>()
876 .AddConstructor<SatLogonResponseMessage>();
877 return tid;
878}
879
881{
882 NS_LOG_FUNCTION(this);
883}
884
886{
887 NS_LOG_FUNCTION(this);
888}
889
890void
892{
893 NS_LOG_FUNCTION(this << raChannel);
894 m_raChannel = raChannel;
895}
896
897uint32_t
899{
900 NS_LOG_FUNCTION(this);
901 return m_raChannel;
902}
903
904uint32_t
906{
907 NS_LOG_FUNCTION(this);
908
909 uint32_t size = 1 * sizeof(uint8_t);
910 return size;
911}
912
913NS_OBJECT_ENSURE_REGISTERED(SatLogoffMessage);
914
915TypeId
917{
918 static TypeId tid = TypeId("ns3::SatLogoffMessage")
919 .SetParent<SatControlMessage>()
920 .AddConstructor<SatLogoffMessage>();
921 return tid;
922}
923
925{
926 NS_LOG_FUNCTION(this);
927}
928
930{
931 NS_LOG_FUNCTION(this);
932}
933
934uint32_t
936{
937 NS_LOG_FUNCTION(this);
938
939 uint32_t size = 1 * sizeof(uint8_t);
940 return size;
941}
942
943NS_OBJECT_ENSURE_REGISTERED(SatNcrMessage);
944
945TypeId
947{
948 static TypeId tid =
949 TypeId("ns3::SatNcrMessage").SetParent<SatControlMessage>().AddConstructor<SatNcrMessage>();
950 return tid;
951}
952
954{
955 NS_LOG_FUNCTION(this);
956}
957
959{
960 NS_LOG_FUNCTION(this);
961}
962
963void
965{
966 NS_LOG_FUNCTION(this << ncr);
967 m_ncrDateBase = (ncr / 300) % (1UL << 33);
968 m_ncrDateExtension = ncr % 300;
969}
970
971uint64_t
973{
974 NS_LOG_FUNCTION(this);
975 return 300 * m_ncrDateBase + m_ncrDateExtension;
976}
977
978uint32_t
980{
981 NS_LOG_FUNCTION(this);
982
983 // 33 bits for base, 9 bits for extension, 6 bits reserved
984 uint32_t size = 6;
985 return size;
986}
987
988NS_OBJECT_ENSURE_REGISTERED(SatCmtMessage);
989
990TypeId
992{
993 static TypeId tid =
994 TypeId("ns3::SatCmtMessage").SetParent<SatControlMessage>().AddConstructor<SatCmtMessage>();
995 return tid;
996}
997
999 : m_groupId(0),
1000 m_logonId(0),
1005{
1006 NS_LOG_FUNCTION(this);
1007}
1008
1010{
1011 NS_LOG_FUNCTION(this);
1012}
1013
1014uint8_t
1016{
1017 return m_groupId;
1018}
1019
1020void
1022{
1023 m_groupId = groupId;
1024}
1025
1026uint8_t
1028{
1029 return m_logonId;
1030}
1031
1032void
1034{
1035 m_logonId = logonId;
1036}
1037
1038int16_t
1043
1044void
1045SatCmtMessage::SetBurstTimeCorrection(int32_t burstTimeCorrection)
1046{
1047 if (burstTimeCorrection > 16256)
1048 {
1049 NS_FATAL_ERROR("Burst Time Correction too high, should be at most 16256, but got "
1050 << burstTimeCorrection);
1051 }
1052 if (burstTimeCorrection < -16256)
1053 {
1054 NS_FATAL_ERROR("Burst Time Correction too low, should be at least -16256, but got "
1055 << burstTimeCorrection);
1056 }
1058 if (burstTimeCorrection > 0)
1059 {
1060 for (uint8_t i = 0; i < 8; i++)
1061 {
1062 if (burstTimeCorrection > 127)
1063 {
1064 burstTimeCorrection >>= 1;
1066 }
1067 }
1068 }
1069 else
1070 {
1071 for (uint8_t i = 0; i < 8; i++)
1072 {
1073 if (-1 * burstTimeCorrection > 127)
1074 {
1075 burstTimeCorrection /= 2;
1077 }
1078 }
1079 }
1080
1081 m_burstTimeCorrection = burstTimeCorrection;
1082}
1083
1084uint8_t
1089
1090void
1092{
1093 m_powerCorrection = powerCorrection;
1094}
1095
1096int16_t
1101
1102void
1103SatCmtMessage::SetFrequencyCorrection(int16_t frequencyCorrection)
1104{
1105 m_frequencyCorrection = frequencyCorrection;
1106}
1107
1108uint32_t
1110{
1111 NS_LOG_FUNCTION(this);
1112
1113 // Content of message is
1114 // m_groupId: 8 bits
1115 // m_logonId: 16 bits
1116 // flags (time correction, power correction, frequency correction): 3 bits
1117 // slot type (always control here): 2 bits
1118 // m_burstTimeScaling: 3 bits
1119 // m_burstTimeCorrection: 8 bits
1120 // power control flag: 1 bit
1121 // m_powerCorrection: 7 bits
1122 // m_frequencyCorrection: 16 bits
1123 // Total is 64 bits = 8 bytes
1124 uint32_t size = 8;
1125 return size;
1126}
1127
1128// Control message container
1129
1130NS_LOG_COMPONENT_DEFINE("SatControlMsgContainer");
1131
1133 : m_sendId(0),
1134 m_recvId(0),
1135 m_storeTime(MilliSeconds(300)),
1136 m_deleteOnRead(false)
1137{
1138 NS_LOG_FUNCTION(this);
1139}
1140
1141SatControlMsgContainer::SatControlMsgContainer(Time storeTime, bool deleteOnRead)
1142 : m_sendId(0),
1143 m_recvId(0),
1144 m_storeTime(storeTime),
1145 m_deleteOnRead(deleteOnRead)
1146
1147{
1148 NS_LOG_FUNCTION(this);
1149}
1150
1152{
1153 NS_LOG_FUNCTION(this);
1154}
1155
1156uint32_t
1157SatControlMsgContainer::ReserveIdAndStore(Ptr<SatControlMessage> ctrlMsg)
1158{
1159 NS_LOG_FUNCTION(this << ctrlMsg);
1160
1161 NS_LOG_INFO("Reserve id (send id): " << m_sendId);
1162
1163 uint32_t id = m_sendId;
1164 m_sendId++;
1165
1166 m_reservedCtrlMsgs.insert(std::make_pair(id, ctrlMsg));
1167
1168 return id;
1169}
1170
1171uint32_t
1173{
1174 NS_LOG_FUNCTION(this << sendId);
1175
1176 uint32_t recvId = m_recvId;
1177
1178 ReservedCtrlMsgMap_t::iterator it = m_reservedCtrlMsgs.find(sendId);
1179
1180 // Found
1181 if (it != m_reservedCtrlMsgs.end())
1182 {
1183 Time now = Simulator::Now();
1184
1185 NS_LOG_INFO("Send id: " << sendId << ", recv id: " << m_recvId);
1186
1187 CtrlMsgMapValue_t mapValue = std::make_pair(now, it->second);
1188 std::pair<CtrlMsgMap_t::iterator, bool> cResult =
1189 m_ctrlMsgs.insert(std::make_pair(recvId, mapValue));
1190
1191 if (cResult.second == false)
1192 {
1193 NS_FATAL_ERROR("Control message cannot be added.");
1194 }
1195
1196 // Add it to id map for possible future use
1197 std::pair<CtrlIdMap_t::iterator, bool> idResult =
1198 m_ctrlIdMap.insert(std::make_pair(sendId, recvId));
1199 if (idResult.second == false)
1200 {
1201 NS_FATAL_ERROR("ID map entry cannot be added!");
1202 }
1203
1204 if (m_storeTimeout.IsExpired())
1205 {
1207 Simulator::Schedule(m_storeTime, &SatControlMsgContainer::EraseFirst, this);
1208 }
1209
1210 // Increase the receive id
1211 ++m_recvId;
1212
1213 // Erase the entry from the temporary reserved container
1214 m_reservedCtrlMsgs.erase(it);
1215 }
1216 // Not found
1217 else
1218 {
1219 // Try to find it from ID map
1220 CtrlIdMap_t::iterator idIter = m_ctrlIdMap.find(sendId);
1221 if (idIter != m_ctrlIdMap.end())
1222 {
1223 recvId = idIter->second;
1224 }
1225 else
1226 {
1227 NS_FATAL_ERROR("The id: "
1228 << sendId
1229 << " not found from either reserved control messages nor ID map!");
1230 }
1231 }
1232
1233 return recvId;
1234}
1235
1236Ptr<SatControlMessage>
1238{
1239 NS_LOG_FUNCTION(this << recvId);
1240
1241 Ptr<SatControlMessage> msg = NULL;
1242
1243 CtrlMsgMap_t::iterator it = m_ctrlMsgs.find(recvId);
1244
1245 NS_LOG_INFO("Receive id: " << recvId);
1246
1247 if (it != m_ctrlMsgs.end())
1248 {
1249 msg = it->second.second;
1250
1251 if (m_deleteOnRead)
1252 {
1253 if (it == m_ctrlMsgs.begin())
1254 {
1255 if (m_storeTimeout.IsPending())
1256 {
1257 m_storeTimeout.Cancel();
1258 }
1259
1260 EraseFirst();
1261 }
1262 else
1263 {
1264 NS_LOG_INFO("Remove id: " << recvId);
1265 CleanUpIdMap(recvId);
1266 m_ctrlMsgs.erase(it);
1267 }
1268 }
1269 }
1270 else
1271 {
1272 NS_FATAL_ERROR("Receive side control message id: "
1273 << recvId << " not found from SatControlMsgContainer (m_ctrlMsgs)!");
1274 }
1275
1276 return msg;
1277}
1278
1279void
1281{
1282 NS_LOG_FUNCTION(this);
1283
1284 CtrlMsgMap_t::iterator it = m_ctrlMsgs.begin();
1285 CleanUpIdMap(it->first);
1286 m_ctrlMsgs.erase(it);
1287
1288 it = m_ctrlMsgs.begin();
1289
1290 if (it != m_ctrlMsgs.end())
1291 {
1292 Time storedMoment = it->second.first;
1293 Time elapsedTime = Simulator::Now() - storedMoment;
1294
1295 m_storeTimeout = Simulator::Schedule(m_storeTime - elapsedTime,
1297 this);
1298 }
1299}
1300
1301void
1303{
1304 NS_LOG_FUNCTION(this << recvId);
1305
1306 CtrlIdMap_t::iterator it = m_ctrlIdMap.begin();
1307 for (; it != m_ctrlIdMap.end(); ++it)
1308 {
1309 if (it->second == recvId)
1310 {
1311 m_ctrlIdMap.erase(it);
1312 break;
1313 }
1314 }
1315}
1316
1317} // namespace ns3
The packet for the Automatic Repeat reQuest (ARQ) acknowledgment (ACK) messages.
uint8_t GetFlowId() const
Get the sequence number to be ACK'ed.
virtual uint32_t GetSizeInBytes() const
Get real size of the ACK message, which can be used to e.g.
void SetSequenceNumber(uint8_t sn)
Set the sequence number to be ACK'ed.
void SetFlowId(uint8_t sn)
Set the flow id to be ACK'ed.
static TypeId GetTypeId(void)
methods derived from base classes
uint8_t GetSequenceNumber() const
Get the sequence number to be ACK'ed.
SatArqAckMessage()
Constructor for SatArqAckMessage.
~SatArqAckMessage()
Destructor for SatArqAckMessage.
This control message is used to give time, power and frequency correction to UTs.
int16_t GetFrequencyCorrection() const
Get the frequency correction.
SatCmtMessage()
Constructor for SatCmtMessage.
uint8_t GetGroupId() const
Get the group ID.
void SetPowerCorrection(uint8_t powerCorrection)
Set the power correction.
~SatCmtMessage()
Destructor for SatCmtMessage.
void SetGroupId(uint8_t groupId)
Set the group ID.
void SetLogonId(uint8_t logonId)
Set the logon ID.
static TypeId GetTypeId(void)
methods derived from base classes
uint8_t GetLogonId() const
Get the logon ID.
virtual uint32_t GetSizeInBytes() const
Get real size of the message.
void SetBurstTimeCorrection(int32_t burstTimeCorrection)
Set the burst time correction.
void SetFrequencyCorrection(int16_t frequencyCorrection)
Set the frequency correction.
uint8_t GetPowerCorrection() const
Get the powercorrection.
int16_t GetBurstTimeCorrection() const
Get the burst time correction.
C/N0 (CNI) estimation report message.
void SetCnoEstimate(double cno)
Set C/N0 estimate.
double GetCnoEstimate() const
Get C/N0 estimate.
virtual uint32_t GetSizeInBytes() const
Get real size of the CR message, which can be used to e.g.
SatCnoReportMessage()
Constructor for SatCnoReportMessage.
~SatCnoReportMessage()
Destructor for SatCnoReportMessage.
static TypeId GetTypeId(void)
methods derived from base classes
Abstract satellite control message class.
static TypeId GetTypeId(void)
methods derived from base classes
SatControlMessage()
Default constructor for SatControlMessage.
Ptr< SatControlMessage > Read(uint32_t recvId)
Read a control message.
bool m_deleteOnRead
Flag to tell, if message is deleted from container when read (get).
uint32_t Send(uint32_t sendId)
Add a control message.
void CleanUpIdMap(uint32_t recvId)
Do clean up for the Ctrl msg id map.
uint32_t ReserveIdAndStore(Ptr< SatControlMessage > controlMsg)
Reserve an id and store a control message.
~SatControlMsgContainer()
Destructor for SatControlMsgContainer.
std::pair< Time, Ptr< SatControlMessage > > CtrlMsgMapValue_t
SatControlMsgContainer()
Default constructor for SatControlMsgContainer.
Time m_storeTime
Time to store a message in container.
void EraseFirst()
Erase first item from container.
This class implements a tag that is used to identify control messages (packages).
~SatControlMsgTag()
Destructor for SatControlMsgTag.
virtual void Serialize(TagBuffer i) const
Serializes information to buffer from this instance of methods.
virtual uint32_t GetSerializedSize(void) const
Get serialized size of methods.
virtual void Print(std::ostream &os) const
Print time stamp of this instance of methods.
static TypeId GetTypeId(void)
methods derived from base classes
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.
void SetMsgType(SatControlMsgType_t type)
Set type of the control message.
SatControlMsgType_t GetMsgType(void) const
Get type of the control message.
virtual TypeId GetInstanceTypeId(void) const
Get the type ID of instance.
virtual void SetMsgId(uint32_t msgId)
Set message type specific identifier.
virtual void Deserialize(TagBuffer i)
Deserializes information from buffer to this instance of methods.
SatControlMsgTag()
Constructor for SatControlMsgTag.
The packet for the Capacity Request (CR) messages.
static TypeId GetTypeId(void)
methods derived from base classes
virtual uint32_t GetSizeInBytes() const
Get real size of the CR message, which can be used to e.g.
RequestContainer_t m_requestData
std::map< RequestDescriptor_t, uint16_t > RequestContainer_t
Define type RequestContainer_t.
SatCrMessage()
Constructor for SatCrMessage.
static const uint32_t CONTROL_MSG_COMMON_HEADER_SIZE_IN_BYTES
RCST_status + power headroom = 1 Byte CNI = 1 Byte Least margin transmission mode request = 1 Byte.
uint32_t GetNumCapacityRequestElements() const
The number of capacity request elements.
static const uint32_t CONTROL_MSG_TYPE_VALUE_SIZE_IN_BYTES
Type field of the CR control element.
void SetCnoEstimate(double cno)
Set C/N0 estimate.
const RequestContainer_t GetCapacityRequestContent() const
Get the capacity request content.
std::pair< uint8_t, SatEnums::SatCapacityAllocationCategory_t > RequestDescriptor_t
Define type RequestDescriptor_t.
~SatCrMessage()
Destructor for SatCrMessage.
void AddControlElement(uint8_t rcIndex, SatEnums::SatCapacityAllocationCategory_t cac, uint32_t value)
Add a control element to capacity request.
bool IsNotEmpty() const
Has the CR non-zero content.
SatCrBlockSize_t m_crBlockSizeType
Control element size is defined by attribute.
double GetCnoEstimate() const
Get C/N0 estimate.
double m_forwardLinkCNo
C/N0 estimate.
SatCapacityAllocationCategory_t
Definition for different types of Capacity Request (CR) messages.
Handover recommendation control message (Tagged by SatControlMsgTag with type value SAT_HR_CTRL_MSG).
~SatHandoverRecommendationMessage()
Destructor for SatRaMessage.
uint32_t GetRecommendedBeamId() const
Get the recommended beam ID.
uint32_t GetRecommendedSatId() const
Get the recommended sat ID.
void SetRecommendedBeamId(uint32_t beamId)
Set recommended beam ID.
void SetRecommendedSatId(uint32_t beamId)
Set recommended sat ID.
virtual uint32_t GetSizeInBytes() const
Get real size of the random access message, which can be used to e.g.
SatHandoverRecommendationMessage()
Constructor for SatRaMessage.
static TypeId GetTypeId(void)
methods derived from base classes
This control message is used to inform the UT that it has been deconnected by GW (Tagged by SatContro...
SatLogoffMessage()
Constructor for SatLogoffMessage.
virtual uint32_t GetSizeInBytes() const
Get real size of the message.
~SatLogoffMessage()
Destructor for SatLogoffMessage.
static TypeId GetTypeId(void)
methods derived from base classes
This control message is used to inform the GW that a UT wants to connect (Tagged by SatControlMsgTag ...
~SatLogonMessage()
Destructor for SatLogonMessage.
static TypeId GetTypeId(void)
methods derived from base classes
SatLogonMessage()
Constructor for SatLogonMessage.
virtual uint32_t GetSizeInBytes() const
Get real size of the message.
This control message is used to inform the UT of a connection success (Tagged by SatControlMsgTag wit...
uint32_t GetRaChannel() const
Get the RA channel to talk into.
void SetRaChannel(uint32_t raChannel)
Set the RA channel to talk into.
~SatLogonResponseMessage()
Destructor for SatLogonResponseMessage.
static TypeId GetTypeId(void)
methods derived from base classes
virtual uint32_t GetSizeInBytes() const
Get real size of the message.
SatLogonResponseMessage()
Constructor for SatLogonResponseMessage.
This control message is used to broadcast NCR date to UTs.
void SetNcrDate(uint64_t ncr)
Set the NCR date (ticks 27MHz).
~SatNcrMessage()
Destructor for SatNcrMessage.
virtual uint32_t GetSizeInBytes() const
Get real size of the message.
SatNcrMessage()
Constructor for SatNcrMessage.
static TypeId GetTypeId(void)
methods derived from base classes
uint64_t GetNcrDate() const
Get the NCR date (ticks 27MHz).
Random access load control message (Tagged by SatControlMsgTag with type value SAT_RA_CTRL_MSG).
uint8_t GetAllocationChannelId() const
Get allocation chanel ID.
void SetBackoffProbability(uint16_t backoffProbability)
Set backoff probability.
uint16_t m_backoffProbability
Backoff probability.
static TypeId GetTypeId(void)
methods derived from base classes
SatRaMessage()
Constructor for SatRaMessage.
uint16_t GetBackoffProbability() const
Get backoff probability.
void SetAllocationChannelId(uint8_t allocationChannel)
Set allocation channel ID.
uint16_t GetBackoffTime() const
Get backoff time.
uint8_t m_allocationChannelId
Allocation channel ID.
static const uint32_t RA_CONTROL_MSG_HEADER_SIZE_IN_BYTES
Common header of the random access element.
virtual uint32_t GetSizeInBytes() const
Get real size of the random access message, which can be used to e.g.
void SetBackoffTime(uint16_t backoffTime)
Set backoff time.
uint16_t m_backoffTime
Backoff time.
~SatRaMessage()
Destructor for SatRaMessage.
This control message is used to inform the UT it has to subscribe to a new slice.
static TypeId GetTypeId(void)
methods derived from base classes
Mac48Address m_address
Address associated to this slice.
uint32_t GetSliceId() const
Get the new slice to subscribe.
void SetAddress(Mac48Address address)
Set the address associated to this slice.
Mac48Address GetAddress() const
Get the ddress associated to this slice.
virtual uint32_t GetSizeInBytes() const
Get real size of the message.
uint8_t m_sliceId
New slice to subscribe.
~SatSliceSubscriptionMessage()
Destructor for SatRaMessage.
SatSliceSubscriptionMessage()
Constructor for SatRaMessage.
void SetSliceId(uint8_t sliceId)
Set the new slice to subscribe.
The packet for the Terminal Burst Time Plan (TBTP) messages.
SatTbtpMessage()
Default constructor for SatTbtpHeader.
static const uint32_t m_tbtpFrameBodySizeInBytes
Size of the frame body.
~SatTbtpMessage()
Destructor for SatTbtpHeader.
void Dump() const
Dump all the contents of the TBTP.
void SetRaChannel(uint32_t raChannel, uint8_t frameId, uint16_t timeSlotCount)
Set a RA time slot information.
static TypeId GetTypeId(void)
methods derived from base classes
const DaTimeSlotInfoItem_t & GetDaTimeslots(Address utId)
Get the information of the DA time slots.
std::pair< uint8_t, DaTimeSlotConfContainer_t > DaTimeSlotInfoItem_t
Item for DA time slot information.
static const uint32_t m_tbtpBodySizeInBytes
Size of message body without frame info and slot assignment info.
uint32_t GetTimeSlotInfoSizeInBytes() const
Get size of the time slot in bytes.
const RaChannelInfoContainer_t GetRaChannels() const
Get the information of the RA channels.
virtual uint32_t GetSizeInBytes() const
Get real size of the TBTP message, which can be used to e.g.
std::set< uint8_t > RaChannelInfoContainer_t
Container for RA channel information.
const DaTimeSlotInfoItem_t m_emptyDaSlotContainer
Empty DA slot container to be returned if there are not DA time slots.
void SetDaTimeslot(Mac48Address utId, uint8_t frameId, Ptr< SatTimeSlotConf > conf)
Set a DA time slot information.
TIM unicast control message (Tagged by SatControlMsgTag with type value SAT_TIMU_CTRL_MSG).
void SetGwAddress(Address address)
virtual uint32_t GetSizeInBytes() const
Get real size of the random access message, which can be used to e.g.
static TypeId GetTypeId(void)
methods derived from base classes
Address m_satAddress
Satellite mac address of the new gateway.
uint32_t m_beamId
Allocated beam ID.
SatTimuMessage()
Constructor for SatRaMessage.
void SetAllocatedSatId(uint32_t beamId)
Set allocated sat ID.
void SetAllocatedBeamId(uint32_t beamId)
Set allocated beam ID.
Address m_gwAddress
Mac address of the new gateway.
uint32_t GetAllocatedSatId() const
Get the allocated sat ID.
uint32_t GetAllocatedBeamId() const
Get the allocated beam ID.
uint32_t m_satId
Allocated sat ID.
void SetSatAddress(Address address)
~SatTimuMessage()
Destructor for SatRaMessage.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.