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 <map>
33 
34 NS_LOG_COMPONENT_DEFINE("SatCtrlMessage");
35 
36 namespace ns3
37 {
38 
39 NS_OBJECT_ENSURE_REGISTERED(SatControlMsgTag);
40 
42  : m_msgType(SAT_NON_CTRL_MSG),
43  m_msgId(0)
44 {
45  NS_LOG_FUNCTION(this);
46 }
47 
49 {
50  NS_LOG_FUNCTION(this);
51 }
52 
53 TypeId
55 {
56  static TypeId tid =
57  TypeId("ns3::SatControlMsgTag").SetParent<Tag>().AddConstructor<SatControlMsgTag>();
58  return tid;
59 }
60 
61 TypeId
63 {
64  NS_LOG_FUNCTION(this);
65 
66  return GetTypeId();
67 }
68 
69 void
71 {
72  NS_LOG_FUNCTION(this << type);
73  m_msgType = type;
74 }
75 
78 {
79  NS_LOG_FUNCTION(this);
80  return m_msgType;
81 }
82 
83 uint32_t
85 {
86  NS_LOG_FUNCTION(this);
87 
88  return (sizeof(m_msgType) + sizeof(m_msgId));
89 }
90 
91 void
92 SatControlMsgTag::Serialize(TagBuffer i) const
93 {
94  NS_LOG_FUNCTION(this << &i);
95  i.WriteU32(m_msgType);
96  i.WriteU32(m_msgId);
97 }
98 
99 void
101 {
102  NS_LOG_FUNCTION(this << &i);
103  m_msgType = (SatControlMsgType_t)i.ReadU32();
104  m_msgId = i.ReadU32();
105 }
106 
107 void
108 SatControlMsgTag::Print(std::ostream& os) const
109 {
110  NS_LOG_FUNCTION(this << &os);
111  os << "SatControlMsgType=" << m_msgType << m_msgId;
112 }
113 
114 void
116 {
117  NS_LOG_FUNCTION(this << m_msgId);
118  m_msgId = msgId;
119 }
120 
121 uint32_t
123 {
124  NS_LOG_FUNCTION(this);
125 
126  return m_msgId;
127 }
128 
129 // Control message
130 
131 NS_OBJECT_ENSURE_REGISTERED(SatControlMessage);
132 
133 TypeId
135 {
136  static TypeId tid = TypeId("ns3::SatControlMessage").SetParent<Object>();
137  return tid;
138 }
139 
140 // TBTP message
141 
142 NS_OBJECT_ENSURE_REGISTERED(SatTbtpMessage);
143 
145  : m_superframeCounter(0),
146  m_superframeSeqId(0),
147  m_assignmentFormat(0)
148 {
149  NS_LOG_FUNCTION(this);
150 }
151 
153  : m_superframeCounter(0),
154  m_superframeSeqId(seqId),
155  m_assignmentFormat(0)
156 {
157  NS_LOG_FUNCTION(this << (uint32_t)seqId);
158 }
159 
161 {
162  NS_LOG_FUNCTION(this);
163 
164  m_frameIds.clear();
165  m_daTimeSlots.clear();
166 }
167 
168 TypeId
170 {
171  static TypeId tid = TypeId("ns3::SatTbtpMessage")
172  .SetParent<SatControlMessage>()
173  .AddConstructor<SatTbtpMessage>()
174  .AddAttribute("AssigmentFormat",
175  "Assignment format of assignment IDs in TBTP.)",
176  UintegerValue(0),
177  MakeUintegerAccessor(&SatTbtpMessage::m_assignmentFormat),
178  MakeUintegerChecker<uint8_t>());
179  return tid;
180 }
181 
182 TypeId
184 {
185  NS_LOG_FUNCTION(this);
186 
187  return GetTypeId();
188 }
189 
192 {
193  NS_LOG_FUNCTION(this << utId);
194 
195  DaTimeSlotMap_t::const_iterator it = m_daTimeSlots.find(utId);
196 
197  if (it != m_daTimeSlots.end())
198  {
199  return it->second;
200  }
201 
202  return m_emptyDaSlotContainer;
203 }
204 
205 void
206 SatTbtpMessage::SetDaTimeslot(Mac48Address utId, uint8_t frameId, Ptr<SatTimeSlotConf> conf)
207 {
208  NS_LOG_FUNCTION(this << utId << frameId << conf);
209 
210  // find container for the UT from map
211  DaTimeSlotMap_t::iterator it = m_daTimeSlots.find(utId);
212 
213  // If not found, add new UT container to map,
214  // otherwise use container found from map
215  if (it == m_daTimeSlots.end())
216  {
217  std::pair<DaTimeSlotMap_t::iterator, bool> result =
218  m_daTimeSlots.insert(std::make_pair(utId, DaTimeSlotInfoItem_t()));
219 
220  if (result.second)
221  {
222  it = result.first;
223  }
224  else
225  {
226  // container creation for UT has failed, so we need to crash
227  NS_FATAL_ERROR("Cannot insert slot to container!!!");
228  }
229  }
230 
231  // store time slot info to user specific container
232  it->second.first = frameId;
233  it->second.second.push_back(conf);
234 
235  // store frame ID to keep track of the used frames count
236  m_frameIds.insert(frameId);
237 }
238 
241 {
242  NS_LOG_FUNCTION(this);
243 
245 
246  for (RaChannelMap_t::const_iterator it = m_raChannels.begin(); it != m_raChannels.end(); it++)
247  {
248  channels.insert(it->second);
249  }
250 
251  return channels;
252 }
253 
254 void
255 SatTbtpMessage::SetRaChannel(uint32_t raChannel, uint8_t frameId, uint16_t timeSlotCount)
256 {
257  NS_LOG_FUNCTION(this << raChannel << (uint32_t)frameId << timeSlotCount);
258 
259  // find index for the RA channel from map
260  RaChannelMap_t::iterator it = m_raChannels.find(raChannel);
261 
262  // If not found, add RA channel to map,
263  // otherwise raise error
264  if (it == m_raChannels.end())
265  {
266  std::pair<RaChannelMap_t::iterator, bool> result =
267  m_raChannels.insert(std::make_pair(raChannel, timeSlotCount));
268 
269  if (result.second == false)
270  {
271  NS_FATAL_ERROR("RA channel insertion failed!!!");
272  }
273  }
274  else
275  {
276  NS_FATAL_ERROR("RA channel already exists in the container!!!");
277  }
278 
279  // store frame ID to count used frames
280  m_frameIds.insert(frameId);
281 }
282 
283 uint32_t
285 {
286  uint32_t assignmentIdSizeInBytes = 0;
287 
288  switch (m_assignmentFormat)
289  {
290  case 0:
291  // assignment id 48 bits
292  assignmentIdSizeInBytes = 6;
293  break;
294 
295  case 1:
296  // assignment id 8 bits
297  assignmentIdSizeInBytes = 1;
298  break;
299 
300  case 2:
301  // assignment id 16 bits
302  assignmentIdSizeInBytes = 2;
303  break;
304 
305  case 3:
306  // assignment id 24 bits
307  assignmentIdSizeInBytes = 3;
308  break;
309 
310  case 10:
311  // dynamic tx type 8 bits + assignment id 8 bits
312  assignmentIdSizeInBytes = 2;
313  break;
314 
315  case 11:
316  // dynamic tx type 8 bits + assignment id 16 bits
317  assignmentIdSizeInBytes = 3;
318  break;
319 
320  case 12:
321  // dynamic tx type 8 bits + assignment id 24 bits
322  assignmentIdSizeInBytes = 4;
323  break;
324 
325  default:
326  NS_FATAL_ERROR("Assignment format=" << m_assignmentFormat << " not supported!!!");
327  break;
328  }
329 
330  return assignmentIdSizeInBytes;
331 }
332 
333 uint32_t
335 {
336  NS_LOG_FUNCTION(this);
337 
338  // see definition for TBTP2 from specification ETSI EN 301 545-2 (V1.1.1), chapter 6.4.9
339 
340  uint32_t sizeInBytes = m_tbtpBodySizeInBytes + (m_frameIds.size() * m_tbtpFrameBodySizeInBytes);
341  uint32_t assignmentIdSizeInBytes = GetTimeSlotInfoSizeInBytes();
342 
343  // add size of DA time slots
344  for (DaTimeSlotMap_t::const_iterator it = m_daTimeSlots.begin(); it != m_daTimeSlots.end();
345  it++)
346  {
347  sizeInBytes += (it->second.second.size() * assignmentIdSizeInBytes);
348  }
349 
350  // add size of RA time slots
351  for (RaChannelMap_t::const_iterator it = m_raChannels.begin(); it != m_raChannels.end(); it++)
352  {
353  sizeInBytes += (it->second * assignmentIdSizeInBytes);
354  }
355 
356  return sizeInBytes;
357 }
358 
359 void
361 {
362  std::cout << "Superframe counter: " << m_superframeCounter
363  << ", superframe sequence id: " << m_superframeSeqId
364  << ", assignment format: " << m_assignmentFormat << std::endl;
365 
366  for (DaTimeSlotMap_t::const_iterator mit = m_daTimeSlots.begin(); mit != m_daTimeSlots.end();
367  ++mit)
368  {
369  std::cout << "UT: " << mit->first << ": ";
370  std::cout << "Frame ID: " << mit->second.first << ": ";
371  std::cout << mit->second.second.size() << " ";
372  std::cout << std::endl;
373  }
374 }
375 
376 NS_OBJECT_ENSURE_REGISTERED(SatCrMessage);
377 
378 TypeId
380 {
381  static TypeId tid = TypeId("ns3::SatCrMessage")
382  .SetParent<SatControlMessage>()
383  .AddConstructor<SatCrMessage>()
384  .AddAttribute("CrBlockType",
385  "Capacity request control block size type",
386  EnumValue(SatCrMessage::CR_BLOCK_SMALL),
387  MakeEnumAccessor(&SatCrMessage::m_crBlockSizeType),
388  MakeEnumChecker(SatCrMessage::CR_BLOCK_SMALL,
389  "Small",
391  "Large"));
392  return tid;
393 }
394 
395 TypeId
397 {
398  NS_LOG_FUNCTION(this);
399 
400  return GetTypeId();
401 }
402 
404  : m_crBlockSizeType(SatCrMessage::CR_BLOCK_SMALL),
405  m_forwardLinkCNo(NAN)
406 {
407  NS_LOG_FUNCTION(this);
408 }
409 
411 {
412  NS_LOG_FUNCTION(this);
413 }
414 
415 void
418  uint32_t value)
419 {
420  NS_LOG_FUNCTION(this << (uint32_t)rcIndex << cac << value);
421 
422  RequestDescriptor_t p = std::make_pair(rcIndex, cac);
423  m_requestData.insert(std::make_pair(p, value));
424 }
425 
428 {
429  return m_requestData;
430 }
431 
432 uint32_t
434 {
435  return m_requestData.size();
436 }
437 
438 double
440 {
441  NS_LOG_FUNCTION(this);
442  return m_forwardLinkCNo;
443 }
444 
445 void
447 {
448  NS_LOG_FUNCTION(this << cno);
449  m_forwardLinkCNo = cno;
450 }
451 
452 uint32_t
454 {
455  NS_LOG_FUNCTION(this);
456 
461  uint32_t crBlockSizeInBytes = (m_crBlockSizeType == SatCrMessage::CR_BLOCK_SMALL ? 2 : 3);
462 
464  m_requestData.size() * crBlockSizeInBytes);
465  return size;
466 }
467 
468 bool
470 {
471  return !m_requestData.empty();
472 }
473 
474 NS_OBJECT_ENSURE_REGISTERED(SatCnoReportMessage);
475 
476 TypeId
478 {
479  static TypeId tid = TypeId("ns3::SatCnoReportMessage")
480  .SetParent<SatControlMessage>()
481  .AddConstructor<SatCnoReportMessage>();
482  return tid;
483 }
484 
485 TypeId
487 {
488  NS_LOG_FUNCTION(this);
489 
490  return GetTypeId();
491 }
492 
494  : m_linkCNo(NAN)
495 {
496  NS_LOG_FUNCTION(this);
497 }
498 
500 {
501  NS_LOG_FUNCTION(this);
502 }
503 
504 double
506 {
507  NS_LOG_FUNCTION(this);
508  return m_linkCNo;
509 }
510 
511 void
513 {
514  NS_LOG_FUNCTION(this << cno);
515  m_linkCNo = cno;
516 }
517 
518 uint32_t
520 {
521  NS_LOG_FUNCTION(this);
522  return sizeof(m_linkCNo);
523 }
524 
525 NS_OBJECT_ENSURE_REGISTERED(SatRaMessage);
526 
527 TypeId
529 {
530  static TypeId tid =
531  TypeId("ns3::SatRaMessage").SetParent<SatControlMessage>().AddConstructor<SatRaMessage>();
532  return tid;
533 }
534 
535 TypeId
537 {
538  NS_LOG_FUNCTION(this);
539 
540  return GetTypeId();
541 }
542 
544  : m_allocationChannelId(0),
545  m_backoffProbability(0),
546  m_backoffTime(0)
547 {
548  NS_LOG_FUNCTION(this);
549 }
550 
552 {
553  NS_LOG_FUNCTION(this);
554 }
555 
556 void
557 SatRaMessage::SetAllocationChannelId(uint8_t allocationChannelId)
558 {
559  NS_LOG_FUNCTION(this << (uint32_t)allocationChannelId);
560 
561  m_allocationChannelId = allocationChannelId;
562 }
563 
564 uint8_t
566 {
567  return m_allocationChannelId;
568 }
569 
570 void
571 SatRaMessage::SetBackoffProbability(uint16_t backoffProbability)
572 {
573  NS_LOG_FUNCTION(this << backoffProbability);
574 
575  m_backoffProbability = backoffProbability;
576 }
577 
578 void
579 SatRaMessage::SetBackoffTime(uint16_t backoffTime)
580 {
581  NS_LOG_FUNCTION(this << backoffTime);
582 
583  m_backoffTime = backoffTime;
584 }
585 
586 uint16_t
588 {
589  return m_backoffProbability;
590 }
591 
592 uint16_t
594 {
595  return m_backoffTime;
596 }
597 
598 uint32_t
600 {
601  NS_LOG_FUNCTION(this);
602 
603  uint32_t size(RA_CONTROL_MSG_HEADER_SIZE_IN_BYTES + sizeof(uint8_t) + sizeof(uint16_t) +
604  sizeof(uint16_t));
605  return size;
606 }
607 
608 NS_OBJECT_ENSURE_REGISTERED(SatArqAckMessage);
609 
610 TypeId
612 {
613  static TypeId tid = TypeId("ns3::SatArqAckMessage")
614  .SetParent<SatControlMessage>()
615  .AddConstructor<SatArqAckMessage>();
616  return tid;
617 }
618 
619 TypeId
621 {
622  NS_LOG_FUNCTION(this);
623 
624  return GetTypeId();
625 }
626 
628  : m_sequenceNumber(0),
629  m_flowId(0)
630 {
631  NS_LOG_FUNCTION(this);
632 }
633 
635 {
636  NS_LOG_FUNCTION(this);
637 }
638 
639 void
641 {
642  NS_LOG_FUNCTION(this);
643  m_sequenceNumber = sn;
644 }
645 
646 uint8_t
648 {
649  return m_sequenceNumber;
650 }
651 
652 void
654 {
655  NS_LOG_FUNCTION(this);
656  m_flowId = flowId;
657 }
658 
659 uint8_t
661 {
662  return m_flowId;
663 }
664 
665 uint32_t
667 {
668  NS_LOG_FUNCTION(this);
669 
670  uint32_t size = 2 * sizeof(uint8_t);
671  return size;
672 }
673 
674 NS_OBJECT_ENSURE_REGISTERED(SatTimuMessage);
675 
676 TypeId
678 {
679  static TypeId tid = TypeId("ns3::SatTimuMessage")
680  .SetParent<SatControlMessage>()
681  .AddConstructor<SatTimuMessage>();
682  return tid;
683 }
684 
685 TypeId
687 {
688  NS_LOG_FUNCTION(this);
689 
690  return GetTypeId();
691 }
692 
694  : m_beamId(0)
695 {
696  NS_LOG_FUNCTION(this);
697 }
698 
700 {
701  NS_LOG_FUNCTION(this);
702 }
703 
704 void
706 {
707  NS_LOG_FUNCTION(this);
708  m_beamId = beamId;
709 }
710 
711 uint32_t
713 {
714  NS_LOG_FUNCTION(this);
715  return m_beamId;
716 }
717 
718 void
720 {
721  NS_LOG_FUNCTION(this);
722  m_gwAddress = address;
723 }
724 
725 Address
727 {
728  NS_LOG_FUNCTION(this);
729  return m_gwAddress;
730 }
731 
732 uint32_t
734 {
735  NS_LOG_FUNCTION(this);
736 
737  uint32_t size = sizeof(uint32_t) + sizeof(Address);
738  return size;
739 }
740 
741 NS_OBJECT_ENSURE_REGISTERED(SatHandoverRecommendationMessage);
742 
743 TypeId
745 {
746  static TypeId tid = TypeId("ns3::SatHandoverRecommendationMessage")
747  .SetParent<SatControlMessage>()
748  .AddConstructor<SatHandoverRecommendationMessage>();
749  return tid;
750 }
751 
752 TypeId
754 {
755  NS_LOG_FUNCTION(this);
756 
757  return GetTypeId();
758 }
759 
761  : m_beamId(0)
762 {
763  NS_LOG_FUNCTION(this);
764 }
765 
767 {
768  NS_LOG_FUNCTION(this);
769 }
770 
771 void
773 {
774  NS_LOG_FUNCTION(this);
775  m_beamId = beamId;
776 }
777 
778 uint32_t
780 {
781  return m_beamId;
782 }
783 
784 uint32_t
786 {
787  NS_LOG_FUNCTION(this);
788 
789  uint32_t size = 1 * sizeof(uint32_t);
790  return size;
791 }
792 
793 NS_OBJECT_ENSURE_REGISTERED(SatSliceSubscriptionMessage);
794 
795 TypeId
797 {
798  static TypeId tid = TypeId("ns3::SatSliceSubscriptionMessage")
799  .SetParent<SatControlMessage>()
800  .AddConstructor<SatSliceSubscriptionMessage>();
801  return tid;
802 }
803 
804 TypeId
806 {
807  NS_LOG_FUNCTION(this);
808 
809  return GetTypeId();
810 }
811 
813  : m_sliceId(0)
814 {
815  NS_LOG_FUNCTION(this);
816 }
817 
819 {
820  NS_LOG_FUNCTION(this);
821 }
822 
823 void
825 {
826  NS_LOG_FUNCTION(this);
827  m_sliceId = sliceId;
828 }
829 
830 uint32_t
832 {
833  return m_sliceId;
834 }
835 
836 Mac48Address
838 {
839  return m_address;
840 }
841 
842 void
844 {
845  m_address = address;
846 }
847 
848 uint32_t
850 {
851  NS_LOG_FUNCTION(this);
852 
853  uint32_t size = 1 * sizeof(uint8_t);
854  return size;
855 }
856 
857 NS_OBJECT_ENSURE_REGISTERED(SatLogonMessage);
858 
859 TypeId
861 {
862  static TypeId tid = TypeId("ns3::SatLogonMessage")
863  .SetParent<SatControlMessage>()
864  .AddConstructor<SatLogonMessage>();
865  return tid;
866 }
867 
868 TypeId
870 {
871  NS_LOG_FUNCTION(this);
872 
873  return GetTypeId();
874 }
875 
877 {
878  NS_LOG_FUNCTION(this);
879 }
880 
882 {
883  NS_LOG_FUNCTION(this);
884 }
885 
886 uint32_t
888 {
889  NS_LOG_FUNCTION(this);
890 
891  uint32_t size = 1 * sizeof(uint8_t);
892  return size;
893 }
894 
895 NS_OBJECT_ENSURE_REGISTERED(SatLogonResponseMessage);
896 
897 TypeId
899 {
900  static TypeId tid = TypeId("ns3::SatLogonResponseMessage")
901  .SetParent<SatControlMessage>()
902  .AddConstructor<SatLogonResponseMessage>();
903  return tid;
904 }
905 
906 TypeId
908 {
909  NS_LOG_FUNCTION(this);
910 
911  return GetTypeId();
912 }
913 
915 {
916  NS_LOG_FUNCTION(this);
917 }
918 
920 {
921  NS_LOG_FUNCTION(this);
922 }
923 
924 void
926 {
927  NS_LOG_FUNCTION(this << raChannel);
928  m_raChannel = raChannel;
929 }
930 
931 uint32_t
933 {
934  NS_LOG_FUNCTION(this);
935  return m_raChannel;
936 }
937 
938 uint32_t
940 {
941  NS_LOG_FUNCTION(this);
942 
943  uint32_t size = 1 * sizeof(uint8_t);
944  return size;
945 }
946 
947 NS_OBJECT_ENSURE_REGISTERED(SatLogoffMessage);
948 
949 TypeId
951 {
952  static TypeId tid = TypeId("ns3::SatLogoffMessage")
953  .SetParent<SatControlMessage>()
954  .AddConstructor<SatLogoffMessage>();
955  return tid;
956 }
957 
958 TypeId
960 {
961  NS_LOG_FUNCTION(this);
962 
963  return GetTypeId();
964 }
965 
967 {
968  NS_LOG_FUNCTION(this);
969 }
970 
972 {
973  NS_LOG_FUNCTION(this);
974 }
975 
976 uint32_t
978 {
979  NS_LOG_FUNCTION(this);
980 
981  uint32_t size = 1 * sizeof(uint8_t);
982  return size;
983 }
984 
985 NS_OBJECT_ENSURE_REGISTERED(SatNcrMessage);
986 
987 TypeId
989 {
990  static TypeId tid =
991  TypeId("ns3::SatNcrMessage").SetParent<SatControlMessage>().AddConstructor<SatNcrMessage>();
992  return tid;
993 }
994 
995 TypeId
997 {
998  NS_LOG_FUNCTION(this);
999 
1000  return GetTypeId();
1001 }
1002 
1004 {
1005  NS_LOG_FUNCTION(this);
1006 }
1007 
1009 {
1010  NS_LOG_FUNCTION(this);
1011 }
1012 
1013 void
1015 {
1016  NS_LOG_FUNCTION(this << ncr);
1017  m_ncrDateBase = (ncr / 300) % (1UL << 33);
1018  m_ncrDateExtension = ncr % 300;
1019 }
1020 
1021 uint64_t
1023 {
1024  NS_LOG_FUNCTION(this);
1025  return 300 * m_ncrDateBase + m_ncrDateExtension;
1026 }
1027 
1028 uint32_t
1030 {
1031  NS_LOG_FUNCTION(this);
1032 
1033  // 33 bits for base, 9 bits for extension, 6 bits reserved
1034  uint32_t size = 6;
1035  return size;
1036 }
1037 
1038 NS_OBJECT_ENSURE_REGISTERED(SatCmtMessage);
1039 
1040 TypeId
1042 {
1043  static TypeId tid =
1044  TypeId("ns3::SatCmtMessage").SetParent<SatControlMessage>().AddConstructor<SatCmtMessage>();
1045  return tid;
1046 }
1047 
1048 TypeId
1050 {
1051  NS_LOG_FUNCTION(this);
1052 
1053  return GetTypeId();
1054 }
1055 
1057  : m_groupId(0),
1058  m_logonId(0),
1059  m_burstTimeScaling(0),
1060  m_burstTimeCorrection(0),
1061  m_powerCorrection(0),
1062  m_frequencyCorrection(0)
1063 {
1064  NS_LOG_FUNCTION(this);
1065 }
1066 
1068 {
1069  NS_LOG_FUNCTION(this);
1070 }
1071 
1072 uint8_t
1074 {
1075  return m_groupId;
1076 }
1077 
1078 void
1080 {
1081  m_groupId = groupId;
1082 }
1083 
1084 uint8_t
1086 {
1087  return m_logonId;
1088 }
1089 
1090 void
1092 {
1093  m_logonId = logonId;
1094 }
1095 
1096 int16_t
1098 {
1099  return m_burstTimeCorrection * (1 << m_burstTimeScaling);
1100 }
1101 
1102 void
1103 SatCmtMessage::SetBurstTimeCorrection(int32_t burstTimeCorrection)
1104 {
1105  if (burstTimeCorrection > 16256)
1106  {
1107  NS_FATAL_ERROR("Burst Time Correction too high, should be at most 16256, but got "
1108  << burstTimeCorrection);
1109  }
1110  if (burstTimeCorrection < -16256)
1111  {
1112  NS_FATAL_ERROR("Burst Time Correction too low, should be at least -16256, but got "
1113  << burstTimeCorrection);
1114  }
1115  m_burstTimeScaling = 0;
1116  if (burstTimeCorrection > 0)
1117  {
1118  for (uint8_t i = 0; i < 8; i++)
1119  {
1120  if (burstTimeCorrection > 127)
1121  {
1122  burstTimeCorrection >>= 1;
1124  }
1125  }
1126  }
1127  else
1128  {
1129  for (uint8_t i = 0; i < 8; i++)
1130  {
1131  if (-1 * burstTimeCorrection > 127)
1132  {
1133  burstTimeCorrection /= 2;
1135  }
1136  }
1137  }
1138 
1139  m_burstTimeCorrection = burstTimeCorrection;
1140 }
1141 
1142 uint8_t
1144 {
1145  return m_powerCorrection;
1146 }
1147 
1148 void
1149 SatCmtMessage::SetPowerCorrection(uint8_t powerCorrection)
1150 {
1151  m_powerCorrection = powerCorrection;
1152 }
1153 
1154 int16_t
1156 {
1157  return m_frequencyCorrection;
1158 }
1159 
1160 void
1161 SatCmtMessage::SetFrequencyCorrection(int16_t frequencyCorrection)
1162 {
1163  m_frequencyCorrection = frequencyCorrection;
1164 }
1165 
1166 uint32_t
1168 {
1169  NS_LOG_FUNCTION(this);
1170 
1171  // Content of message is
1172  // m_groupId: 8 bits
1173  // m_logonId: 16 bits
1174  // flags (time correction, power correction, frequency correction): 3 bits
1175  // slot type (always control here): 2 bits
1176  // m_burstTimeScaling: 3 bits
1177  // m_burstTimeCorrection: 8 bits
1178  // power control flag: 1 bit
1179  // m_powerCorrection: 7 bits
1180  // m_frequencyCorrection: 16 bits
1181  // Total is 64 bits = 8 bytes
1182  uint32_t size = 8;
1183  return size;
1184 }
1185 
1186 // Control message container
1187 
1188 NS_LOG_COMPONENT_DEFINE("SatControlMsgContainer");
1189 
1191  : m_sendId(0),
1192  m_recvId(0),
1193  m_storeTime(MilliSeconds(300)),
1194  m_deleteOnRead(false)
1195 {
1196  NS_LOG_FUNCTION(this);
1197 }
1198 
1199 SatControlMsgContainer::SatControlMsgContainer(Time storeTime, bool deleteOnRead)
1200  : m_sendId(0),
1201  m_recvId(0),
1202  m_storeTime(storeTime),
1203  m_deleteOnRead(deleteOnRead)
1204 
1205 {
1206  NS_LOG_FUNCTION(this);
1207 }
1208 
1210 {
1211  NS_LOG_FUNCTION(this);
1212 }
1213 
1214 uint32_t
1215 SatControlMsgContainer::ReserveIdAndStore(Ptr<SatControlMessage> ctrlMsg)
1216 {
1217  NS_LOG_FUNCTION(this << ctrlMsg);
1218 
1219  NS_LOG_INFO("Reserve id (send id): " << m_sendId);
1220 
1221  uint32_t id = m_sendId;
1222  m_sendId++;
1223 
1224  m_reservedCtrlMsgs.insert(std::make_pair(id, ctrlMsg));
1225 
1226  return id;
1227 }
1228 
1229 uint32_t
1231 {
1232  NS_LOG_FUNCTION(this << sendId);
1233 
1234  uint32_t recvId = m_recvId;
1235 
1236  ReservedCtrlMsgMap_t::iterator it = m_reservedCtrlMsgs.find(sendId);
1237 
1238  // Found
1239  if (it != m_reservedCtrlMsgs.end())
1240  {
1241  Time now = Simulator::Now();
1242 
1243  NS_LOG_INFO("Send id: " << sendId << ", recv id: " << m_recvId);
1244 
1245  CtrlMsgMapValue_t mapValue = std::make_pair(now, it->second);
1246  std::pair<CtrlMsgMap_t::iterator, bool> cResult =
1247  m_ctrlMsgs.insert(std::make_pair(recvId, mapValue));
1248 
1249  if (cResult.second == false)
1250  {
1251  NS_FATAL_ERROR("Control message cannot be added.");
1252  }
1253 
1254  // Add it to id map for possible future use
1255  std::pair<CtrlIdMap_t::iterator, bool> idResult =
1256  m_ctrlIdMap.insert(std::make_pair(sendId, recvId));
1257  if (idResult.second == false)
1258  {
1259  NS_FATAL_ERROR("ID map entry cannot be added!");
1260  }
1261 
1262  if (m_storeTimeout.IsExpired())
1263  {
1264  m_storeTimeout =
1265  Simulator::Schedule(m_storeTime, &SatControlMsgContainer::EraseFirst, this);
1266  }
1267 
1268  // Increase the receive id
1269  ++m_recvId;
1270 
1271  // Erase the entry from the temporary reserved container
1272  m_reservedCtrlMsgs.erase(it);
1273  }
1274  // Not found
1275  else
1276  {
1277  // Try to find it from ID map
1278  CtrlIdMap_t::iterator idIter = m_ctrlIdMap.find(sendId);
1279  if (idIter != m_ctrlIdMap.end())
1280  {
1281  recvId = idIter->second;
1282  }
1283  else
1284  {
1285  NS_FATAL_ERROR("The id: "
1286  << sendId
1287  << " not found from either reserved control messages nor ID map!");
1288  }
1289  }
1290 
1291  return recvId;
1292 }
1293 
1294 Ptr<SatControlMessage>
1296 {
1297  NS_LOG_FUNCTION(this << recvId);
1298 
1299  Ptr<SatControlMessage> msg = NULL;
1300 
1301  CtrlMsgMap_t::iterator it = m_ctrlMsgs.find(recvId);
1302 
1303  NS_LOG_INFO("Receive id: " << recvId);
1304 
1305  if (it != m_ctrlMsgs.end())
1306  {
1307  msg = it->second.second;
1308 
1309  if (m_deleteOnRead)
1310  {
1311  if (it == m_ctrlMsgs.begin())
1312  {
1313  if (m_storeTimeout.IsRunning())
1314  {
1315  m_storeTimeout.Cancel();
1316  }
1317 
1318  EraseFirst();
1319  }
1320  else
1321  {
1322  NS_LOG_INFO("Remove id: " << recvId);
1323  CleanUpIdMap(recvId);
1324  m_ctrlMsgs.erase(it);
1325  }
1326  }
1327  }
1328  else
1329  {
1330  NS_FATAL_ERROR("Receive side control message id: "
1331  << recvId << " not found from SatControlMsgContainer (m_ctrlMsgs)!");
1332  }
1333 
1334  return msg;
1335 }
1336 
1337 void
1339 {
1340  NS_LOG_FUNCTION(this);
1341 
1342  CtrlMsgMap_t::iterator it = m_ctrlMsgs.begin();
1343  CleanUpIdMap(it->first);
1344  m_ctrlMsgs.erase(it);
1345 
1346  it = m_ctrlMsgs.begin();
1347 
1348  if (it != m_ctrlMsgs.end())
1349  {
1350  Time storedMoment = it->second.first;
1351  Time elapsedTime = Simulator::Now() - storedMoment;
1352 
1353  m_storeTimeout = Simulator::Schedule(m_storeTime - elapsedTime,
1355  this);
1356  }
1357 }
1358 
1359 void
1361 {
1362  NS_LOG_FUNCTION(this << recvId);
1363 
1364  CtrlIdMap_t::iterator it = m_ctrlIdMap.begin();
1365  for (; it != m_ctrlIdMap.end(); ++it)
1366  {
1367  if (it->second == recvId)
1368  {
1369  m_ctrlIdMap.erase(it);
1370  break;
1371  }
1372  }
1373 }
1374 
1375 } // 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.
virtual TypeId GetInstanceTypeId(void) const
Get the type ID of instance.
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.
virtual TypeId GetInstanceTypeId(void) const
Get the type ID of instance.
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.
virtual TypeId GetInstanceTypeId(void) const
Get the type ID of instance.
~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
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.
~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.
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.
virtual TypeId GetInstanceTypeId(void) const
Get the type ID of instance.
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.
void SetRecommendedBeamId(uint32_t beamId)
Set recommended beam ID.
virtual TypeId GetInstanceTypeId(void) const
Get the type ID of instance.
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...
virtual TypeId GetInstanceTypeId(void) const
Get the type ID of instance.
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.
virtual TypeId GetInstanceTypeId(void) const
Get the type ID of instance.
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.
virtual TypeId GetInstanceTypeId(void) const
Get the type ID of instance.
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.
virtual TypeId GetInstanceTypeId(void) const
Get the type ID of instance.
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.
virtual TypeId GetInstanceTypeId(void) const
Get the type ID of instance.
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
virtual TypeId GetInstanceTypeId(void) const
Get the type ID of instance.
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.
virtual TypeId GetInstanceTypeId(void) const
Get the type ID of instance.
std::pair< uint8_t, DaTimeSlotConfContainer_t > DaTimeSlotInfoItem_t
Item for DA time slot information.
std::set< uint8_t > m_frameIds
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
uint32_t m_beamId
Allocated beam ID.
SatTimuMessage()
Constructor for SatRaMessage.
virtual TypeId GetInstanceTypeId(void) const
Get the type ID of instance.
void SetAllocatedBeamId(uint32_t beamId)
Set allocated beam ID.
Address m_gwAddress
Mac address of the new gateway.
uint32_t GetAllocatedBeamId() const
Get the allocated beam ID.
~SatTimuMessage()
Destructor for SatRaMessage.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.