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