Loading...
Searching...
No Matches
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
22
24
25#include "ns3/log.h"
26#include "ns3/uinteger.h"
27
28#include <algorithm>
29#include <iostream>
30#include <ostream>
31
32NS_LOG_COMPONENT_DEFINE("SatGseHeader");
33
34namespace ns3
35{
36
37NS_OBJECT_ENSURE_REGISTERED(SatGseHeader);
38
54
58
59TypeId
61{
62 static TypeId tid =
63 TypeId("ns3::SatGseHeader").SetParent<Header>().AddConstructor<SatGseHeader>();
64 return tid;
65}
66
67uint32_t
69{
70 NS_LOG_FUNCTION(this);
71
73 {
74 // FULL PDU
76 {
78 }
79 // START PDU
80 else
81 {
83 }
84 }
85 else
86 {
87 // END PDU
89 {
90 return m_endGseHeaderSize;
91 }
92 // CONTINUATION PDU
93 else
94 {
96 }
97 }
98 return 0;
99}
100
101void
102SatGseHeader::Serialize(Buffer::Iterator start) const
103{
104 NS_LOG_FUNCTION(this);
105
106 Buffer::Iterator i = start;
107
108 // First two bytes
109 i.WriteU16((m_startIndicator << 15) | (m_endIndicator << 14) | (0x0 << 13) | (0x0 << 12) |
110 (m_gsePduLengthInBytes & 0x0FFF));
111
112 // NOT FULL PDU (START PDU OR CONTINUATION PDU OR END PDU)
114 {
115 i.WriteU8(m_fragmentId);
116 }
117
118 // START OR FULL PDU
120 {
121 // START PDU
122 if (!m_endIndicator)
123 {
124 i.WriteU16(m_totalLengthInBytes);
125 }
126
127 // Protocol type
128 i.WriteU16(m_protocolType);
129
130 for (uint32_t c = 0; c < m_labelFieldLengthInBytes; ++c)
131 {
132 i.WriteU8(m_labelByte);
133 }
134 }
135
136 // FULL OR END PDU
137 if (m_endIndicator)
138 {
139 i.WriteU32(m_crc);
140 }
141}
142
143uint32_t
144SatGseHeader::Deserialize(Buffer::Iterator start)
145{
146 NS_LOG_FUNCTION(this);
147
148 Buffer::Iterator i = start;
149 uint16_t field_16;
150
151 // First two bytes
152 field_16 = i.ReadU16();
153 m_startIndicator = field_16 >> 15 & 0x1;
154 m_endIndicator = field_16 >> 14 & 0x1;
155 m_gsePduLengthInBytes = field_16 & 0x0FFF;
156
157 // NOT FULL PDU
159 {
160 m_fragmentId = i.ReadU8();
161 }
162
163 // START OR FULL PDU
165 {
166 // START PDU
167 if (!m_endIndicator)
168 {
169 m_totalLengthInBytes = i.ReadU16();
170 }
171 }
172
178
179 return GetSerializedSize();
180}
181
182void
183SatGseHeader::Print(std::ostream& os) const
184{
185 NS_LOG_FUNCTION(this);
186
187 os << m_startIndicator << " " << m_endIndicator << " " << m_gsePduLengthInBytes << " "
188 << m_fragmentId << " " << m_totalLengthInBytes << " " << m_protocolType << " " << m_labelByte
189 << " " << m_crc << std::endl;
190}
191
192TypeId
194{
195 return GetTypeId();
196}
197
198uint8_t
200{
201 NS_LOG_FUNCTION(this);
202 return m_startIndicator;
203}
204
205uint8_t
207{
208 NS_LOG_FUNCTION(this);
209 return m_endIndicator;
210}
211
212uint32_t
214{
215 NS_LOG_FUNCTION(this);
217}
218
219uint32_t
221{
222 NS_LOG_FUNCTION(this);
223 return m_fragmentId;
224}
225
226uint32_t
228{
229 NS_LOG_FUNCTION(this);
231}
232
233void
235{
236 NS_LOG_FUNCTION(this);
238}
239
240void
242{
243 NS_LOG_FUNCTION(this);
244 m_endIndicator = 1;
245}
246
247void
249{
250 NS_LOG_FUNCTION(this << bytes);
251 m_gsePduLengthInBytes = bytes;
252}
253
254void
256{
257 NS_LOG_FUNCTION(this << id);
258 m_fragmentId = id;
259}
260
261void
263{
264 NS_LOG_FUNCTION(this << bytes);
265 m_totalLengthInBytes = bytes;
266}
267
268uint32_t
270{
271 NS_LOG_FUNCTION(this << (uint32_t)type);
272
273 uint32_t size(0);
274 switch (type)
275 {
278 break;
279 }
282 break;
283 }
285 size = m_endGseHeaderSize;
286 break;
287 }
290 break;
291 }
292 default: {
293 NS_FATAL_ERROR("Unsupported SatEncapPduStatusTag!");
294 break;
295 }
296 }
297 return size;
298}
299
300uint32_t
302{
303 NS_LOG_FUNCTION(this);
304
305 return std::max(std::max((m_fullGseHeaderSize + m_labelFieldLengthInBytes),
308}
309
310} // namespace ns3
SatGseHeader implementation.
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.
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.