satellite-rle-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-rle-header.h"
22 
24 
25 #include <ns3/log.h>
26 
27 NS_LOG_COMPONENT_DEFINE("SatPPduHeader");
28 
29 namespace ns3
30 {
31 
32 NS_OBJECT_ENSURE_REGISTERED(SatPPduHeader);
33 
35  : m_startIndicator(0),
36  m_endIndicator(0),
37  m_ppduLengthInBytes(0),
38  m_fragmentId(0),
39  m_totalLengthInBytes(0),
40  m_fullPpduHeaderSize(2),
41  m_startPpduHeaderSize(4),
42  m_endPpduHeaderSize(2),
43  m_continuationPpduHeaderSize(2)
44 {
45 }
46 
48 {
49 }
50 
51 TypeId
53 {
54  static TypeId tid =
55  TypeId("ns3::SatPPduHeader").SetParent<Header>().AddConstructor<SatPPduHeader>();
56  return tid;
57 }
58 
59 uint32_t
61 {
62  NS_LOG_FUNCTION(this);
63 
64  if (m_startIndicator)
65  {
66  // FULL PDU
67  if (m_endIndicator)
68  {
69  return m_fullPpduHeaderSize;
70  }
71  // START PDU
72  else
73  {
74  return m_startPpduHeaderSize;
75  }
76  }
77  else
78  {
79  // END PDU
80  if (m_endIndicator)
81  {
82  return m_endPpduHeaderSize;
83  }
84  // CONTINUATION PDU
85  else
86  {
88  }
89  }
90 
91  return 0;
92 }
93 
94 void
95 SatPPduHeader::Serialize(Buffer::Iterator start) const
96 {
97  NS_LOG_FUNCTION(this);
98 
99  Buffer::Iterator i = start;
100 
101  // FULL PDU
103  {
104  i.WriteU16((m_startIndicator << 15) | (m_endIndicator << 14) | (m_ppduLengthInBytes << 3));
105  }
106  // START, CONTINUATION OR END PDU
107  else
108  {
109  // Fragment id
110  i.WriteU16((m_startIndicator << 15) | (m_endIndicator << 14) | (m_ppduLengthInBytes << 3) |
111  (m_fragmentId));
112  }
113 
114  // START PDU
116  {
117  i.WriteU16((0x0 << 15) | (m_totalLengthInBytes << 3));
118  }
119 
123 }
124 
125 uint32_t
126 SatPPduHeader::Deserialize(Buffer::Iterator start)
127 {
128  NS_LOG_FUNCTION(this);
129 
130  Buffer::Iterator i = start;
131  uint16_t field_16;
132 
133  // First two bytes
134  field_16 = i.ReadU16();
135  m_startIndicator = field_16 >> 15 & 0x1;
136  m_endIndicator = field_16 >> 14 & 0x1;
137  m_ppduLengthInBytes = (field_16 & 0x3FF8) >> 3;
138 
139  // NOT FULL PDU
141  {
142  m_fragmentId = field_16 & 0x0007;
143  }
144 
145  // START PDU
147  {
148  field_16 = i.ReadU16();
149  m_totalLengthInBytes = (field_16 & 0x7FF8) >> 3;
150  }
151 
156  return GetSerializedSize();
157 }
158 
159 void
160 SatPPduHeader::Print(std::ostream& os) const
161 {
162  NS_LOG_FUNCTION(this);
163 
164  os << m_startIndicator << " " << m_endIndicator << " " << m_ppduLengthInBytes << " "
165  << m_fragmentId << " " << m_totalLengthInBytes;
166 }
167 
168 TypeId
170 {
171  return GetTypeId();
172 }
173 
174 uint8_t
176 {
177  NS_LOG_FUNCTION(this);
178 
179  return m_startIndicator;
180 }
181 
182 uint8_t
184 {
185  NS_LOG_FUNCTION(this);
186 
187  return m_endIndicator;
188 }
189 
190 uint16_t
192 {
193  NS_LOG_FUNCTION(this);
194 
195  return m_ppduLengthInBytes;
196 }
197 
198 uint8_t
200 {
201  NS_LOG_FUNCTION(this);
202 
203  return m_fragmentId;
204 }
205 
206 uint16_t
208 {
209  NS_LOG_FUNCTION(this);
210 
211  return m_totalLengthInBytes;
212 }
213 
214 void
216 {
217  NS_LOG_FUNCTION(this);
218 
219  m_startIndicator = 1;
220 }
221 
222 void
224 {
225  NS_LOG_FUNCTION(this);
226 
227  m_endIndicator = 1;
228 }
229 
230 void
232 {
233  NS_LOG_FUNCTION(this << bytes);
234 
235  m_ppduLengthInBytes = bytes;
236 }
237 
238 void
240 {
241  NS_LOG_FUNCTION(this << (uint32_t)id);
242 
243  m_fragmentId = id;
244 }
245 
246 void
248 {
249  NS_LOG_FUNCTION(this << bytes);
250 
251  m_totalLengthInBytes = bytes;
252 }
253 
254 uint32_t
256 {
257  NS_LOG_FUNCTION(this << (uint32_t)type);
258 
259  uint32_t size(0);
260  switch (type)
261  {
263  size = m_startPpduHeaderSize;
264  break;
265  }
268  break;
269  }
271  size = m_endPpduHeaderSize;
272  break;
273  }
275  size = m_fullPpduHeaderSize;
276  break;
277  }
278  default: {
279  NS_FATAL_ERROR("Unsupported SatEncapPduStatusTag: " << type);
280  break;
281  }
282  }
283  return size;
284 }
285 
286 uint32_t
288 {
289  NS_LOG_FUNCTION(this);
290 
291  return std::max(std::max(m_startPpduHeaderSize, m_continuationPpduHeaderSize),
293 }
294 
295 } // namespace ns3
uint32_t GetMaxHeaderSizeInBytes() const
Get maximum RLE header size.
void SetPPduLength(uint16_t bytes)
Set PPDU fragment length to PPDU header.
const uint32_t m_continuationPpduHeaderSize
uint16_t GetPPduLength() const
Get PPDU fragment length in bytes.
virtual void Print(std::ostream &os) const
Print time stamp of this instance of SatPPduHeader.
const uint32_t m_startPpduHeaderSize
void SetEndIndicator()
Set end indicator to PPDU header.
virtual void Serialize(Buffer::Iterator start) const
Serializes information to buffer from this instance of SatPPduHeader.
const uint32_t m_fullPpduHeaderSize
Constant variables for determining the header sizes of different RLE PPDU fragments.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserializes information from buffer to this instance of SatPPduHeader.
void SetTotalLength(uint16_t bytes)
Set total length of higher layer PDU.
uint32_t GetHeaderSizeInBytes(uint8_t type) const
Get the maximum RLE header size.
uint8_t GetEndIndicator() const
Get end indicator of PPDU header.
void SetStartIndicator()
Set start indicator to PPDU header.
uint8_t GetFragmentId() const
Get PPDU fragment id.
void SetFragmentId(uint8_t id)
Set fragment id to PPDU header.
const uint32_t m_endPpduHeaderSize
virtual uint32_t GetSerializedSize(void) const
Get serialized size of SatPPduHeader.
uint16_t GetTotalLength() const
Get total length of higher layer PDU.
virtual TypeId GetInstanceTypeId(void) const
Get the type ID of instance.
static TypeId GetTypeId(void)
Get the type ID.
uint8_t GetStartIndicator() const
Get start indicator of PPDU header.
~SatPPduHeader()
Destructor for SatPPduHeader.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.