satellite-gse-header.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013 Magister Solutions Ltd.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Jani Puttonen <jani.puttonen@magister.fi>
19  */
20 
21 #include "satellite-gse-header.h"
22 
24 
25 #include <ns3/log.h>
26 #include <ns3/uinteger.h>
27 
28 NS_LOG_COMPONENT_DEFINE("SatGseHeader");
29 
30 namespace ns3
31 {
32 
33 NS_OBJECT_ENSURE_REGISTERED(SatGseHeader);
34 
36  : m_startIndicator(0),
37  m_endIndicator(0),
38  m_gsePduLengthInBytes(0),
39  m_fragmentId(0),
40  m_totalLengthInBytes(0),
41  m_protocolType(0),
42  m_labelByte(0),
43  m_crc(0),
44  m_fullGseHeaderSize(8),
45  m_startGseHeaderSize(8),
46  m_endGseHeaderSize(8),
47  m_continuationGseHeaderSize(3)
48 {
49 }
50 
52 {
53 }
54 
55 TypeId
57 {
58  static TypeId tid =
59  TypeId("ns3::SatGseHeader").SetParent<Header>().AddConstructor<SatGseHeader>();
60  return tid;
61 }
62 
63 uint32_t
65 {
66  NS_LOG_FUNCTION(this);
67 
68  if (m_startIndicator)
69  {
70  // FULL PDU
71  if (m_endIndicator)
72  {
74  }
75  // START PDU
76  else
77  {
79  }
80  }
81  else
82  {
83  // END PDU
84  if (m_endIndicator)
85  {
86  return m_endGseHeaderSize;
87  }
88  // CONTINUATION PDU
89  else
90  {
92  }
93  }
94  return 0;
95 }
96 
97 void
98 SatGseHeader::Serialize(Buffer::Iterator start) const
99 {
100  NS_LOG_FUNCTION(this);
101 
102  Buffer::Iterator i = start;
103 
104  // First two bytes
105  i.WriteU16((m_startIndicator << 15) | (m_endIndicator << 14) | (0x0 << 13) | (0x0 << 12) |
106  (m_gsePduLengthInBytes & 0x0FFF));
107 
108  // NOT FULL PDU (START PDU OR CONTINUATION PDU OR END PDU)
110  {
111  i.WriteU8(m_fragmentId);
112  }
113 
114  // START OR FULL PDU
115  if (m_startIndicator)
116  {
117  // START PDU
118  if (!m_endIndicator)
119  {
120  i.WriteU16(m_totalLengthInBytes);
121  }
122 
123  // Protocol type
124  i.WriteU16(m_protocolType);
125 
126  for (uint32_t c = 0; c < m_labelFieldLengthInBytes; ++c)
127  {
128  i.WriteU8(m_labelByte);
129  }
130  }
131 
132  // FULL OR END PDU
133  if (m_endIndicator)
134  {
135  i.WriteU32(m_crc);
136  }
137 }
138 
139 uint32_t
140 SatGseHeader::Deserialize(Buffer::Iterator start)
141 {
142  NS_LOG_FUNCTION(this);
143 
144  Buffer::Iterator i = start;
145  uint16_t field_16;
146 
147  // First two bytes
148  field_16 = i.ReadU16();
149  m_startIndicator = field_16 >> 15 & 0x1;
150  m_endIndicator = field_16 >> 14 & 0x1;
151  m_gsePduLengthInBytes = field_16 & 0x0FFF;
152 
153  // NOT FULL PDU
155  {
156  m_fragmentId = i.ReadU8();
157  }
158 
159  // START OR FULL PDU
160  if (m_startIndicator)
161  {
162  // START PDU
163  if (!m_endIndicator)
164  {
165  m_totalLengthInBytes = i.ReadU16();
166  }
167  }
168 
175  return GetSerializedSize();
176 }
177 
178 void
179 SatGseHeader::Print(std::ostream& os) const
180 {
181  NS_LOG_FUNCTION(this);
182 
183  os << m_startIndicator << " " << m_endIndicator << " " << m_gsePduLengthInBytes << " "
184  << m_fragmentId << " " << m_totalLengthInBytes << " " << m_protocolType << " " << m_labelByte
185  << " " << m_crc << std::endl;
186 }
187 
188 TypeId
190 {
191  return GetTypeId();
192 }
193 
194 uint8_t
196 {
197  NS_LOG_FUNCTION(this);
198  return m_startIndicator;
199 }
200 
201 uint8_t
203 {
204  NS_LOG_FUNCTION(this);
205  return m_endIndicator;
206 }
207 
208 uint32_t
210 {
211  NS_LOG_FUNCTION(this);
212  return m_gsePduLengthInBytes;
213 }
214 
215 uint32_t
217 {
218  NS_LOG_FUNCTION(this);
219  return m_fragmentId;
220 }
221 
222 uint32_t
224 {
225  NS_LOG_FUNCTION(this);
226  return m_totalLengthInBytes;
227 }
228 
229 void
231 {
232  NS_LOG_FUNCTION(this);
233  m_startIndicator = 1;
234 }
235 
236 void
238 {
239  NS_LOG_FUNCTION(this);
240  m_endIndicator = 1;
241 }
242 
243 void
245 {
246  NS_LOG_FUNCTION(this << bytes);
247  m_gsePduLengthInBytes = bytes;
248 }
249 
250 void
252 {
253  NS_LOG_FUNCTION(this << id);
254  m_fragmentId = id;
255 }
256 
257 void
259 {
260  NS_LOG_FUNCTION(this << bytes);
261  m_totalLengthInBytes = bytes;
262 }
263 
264 uint32_t
266 {
267  NS_LOG_FUNCTION(this << (uint32_t)type);
268 
269  uint32_t size(0);
270  switch (type)
271  {
274  break;
275  }
278  break;
279  }
281  size = m_endGseHeaderSize;
282  break;
283  }
286  break;
287  }
288  default: {
289  NS_FATAL_ERROR("Unsupported SatEncapPduStatusTag!");
290  break;
291  }
292  }
293  return size;
294 }
295 
296 uint32_t
298 {
299  NS_LOG_FUNCTION(this);
300 
301  return std::max(std::max((m_fullGseHeaderSize + m_labelFieldLengthInBytes),
304 }
305 
306 } // namespace ns3
const uint32_t m_continuationGseHeaderSize
const uint32_t m_startGseHeaderSize
uint8_t m_startIndicator
GSE header content.
uint8_t GetEndIndicator() const
Get end indicator of GSE header.
uint32_t GetGsePduLength() const
Get GSE fragment length in bytes.
virtual void Print(std::ostream &os) const
Print time stamp of this instance of SatGseHeader.
static TypeId GetTypeId(void)
Get the type ID.
uint32_t GetTotalLength() const
Get total length of higher layer PDU.
uint32_t GetGseHeaderSizeInBytes(uint8_t type) const
Get the maximum GSE header size.
virtual uint32_t GetSerializedSize(void) const
Get serialized size of SatGseHeader.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserializes information from buffer to this instance of SatGseHeader.
void SetStartIndicator()
Set start indicator to GSE header.
uint8_t GetStartIndicator() const
Get start indicator of GSE header.
uint32_t GetMaxGseHeaderSizeInBytes() const
Get the maximum GSE header size.
const uint32_t m_fullGseHeaderSize
Constant variables for determining the header sizes of different GSE fragments.
const uint32_t m_endGseHeaderSize
uint32_t GetFragmentId() const
Get GSE fragment id.
~SatGseHeader()
Destructor for SatGseHeader.
virtual void Serialize(Buffer::Iterator start) const
Serializes information to buffer from this instance of SatGseHeader.
virtual TypeId GetInstanceTypeId(void) const
Get the type ID of instance.
SatGseHeader()
Constructor.
void SetTotalLength(uint32_t bytes)
Set total length of higher layer PDU.
void SetGsePduLength(uint32_t bytes)
Set GSE fragment length to PPDU header.
static const uint32_t m_labelFieldLengthInBytes
void SetEndIndicator()
Set end indicator to GSE header.
void SetFragmentId(uint32_t id)
Set fragment id to GSE header.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.