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 #include <algorithm>
28 #include <ostream>
29 
30 NS_LOG_COMPONENT_DEFINE("SatPPduHeader");
31 
32 namespace ns3
33 {
34 
35 NS_OBJECT_ENSURE_REGISTERED(SatPPduHeader);
36 
38  : m_startIndicator(0),
39  m_endIndicator(0),
40  m_ppduLengthInBytes(0),
41  m_fragmentId(0),
42  m_totalLengthInBytes(0),
43  m_fullPpduHeaderSize(2),
44  m_startPpduHeaderSize(4),
45  m_endPpduHeaderSize(2),
46  m_continuationPpduHeaderSize(2)
47 {
48 }
49 
51 {
52 }
53 
54 TypeId
56 {
57  static TypeId tid =
58  TypeId("ns3::SatPPduHeader").SetParent<Header>().AddConstructor<SatPPduHeader>();
59  return tid;
60 }
61 
62 uint32_t
64 {
65  NS_LOG_FUNCTION(this);
66 
67  if (m_startIndicator)
68  {
69  // FULL PDU
70  if (m_endIndicator)
71  {
72  return m_fullPpduHeaderSize;
73  }
74  // START PDU
75  else
76  {
77  return m_startPpduHeaderSize;
78  }
79  }
80  else
81  {
82  // END PDU
83  if (m_endIndicator)
84  {
85  return m_endPpduHeaderSize;
86  }
87  // CONTINUATION PDU
88  else
89  {
91  }
92  }
93 
94  return 0;
95 }
96 
97 void
98 SatPPduHeader::Serialize(Buffer::Iterator start) const
99 {
100  NS_LOG_FUNCTION(this);
101 
102  Buffer::Iterator i = start;
103 
104  // FULL PDU
106  {
107  i.WriteU16((m_startIndicator << 15) | (m_endIndicator << 14) | (m_ppduLengthInBytes << 3));
108  }
109  // START, CONTINUATION OR END PDU
110  else
111  {
112  // Fragment id
113  i.WriteU16((m_startIndicator << 15) | (m_endIndicator << 14) | (m_ppduLengthInBytes << 3) |
114  (m_fragmentId));
115  }
116 
117  // START PDU
119  {
120  i.WriteU16((0x0 << 15) | (m_totalLengthInBytes << 3));
121  }
122 
126 }
127 
128 uint32_t
129 SatPPduHeader::Deserialize(Buffer::Iterator start)
130 {
131  NS_LOG_FUNCTION(this);
132 
133  Buffer::Iterator i = start;
134  uint16_t field_16;
135 
136  // First two bytes
137  field_16 = i.ReadU16();
138  m_startIndicator = field_16 >> 15 & 0x1;
139  m_endIndicator = field_16 >> 14 & 0x1;
140  m_ppduLengthInBytes = (field_16 & 0x3FF8) >> 3;
141 
142  // NOT FULL PDU
144  {
145  m_fragmentId = field_16 & 0x0007;
146  }
147 
148  // START PDU
150  {
151  field_16 = i.ReadU16();
152  m_totalLengthInBytes = (field_16 & 0x7FF8) >> 3;
153  }
154 
159  return GetSerializedSize();
160 }
161 
162 void
163 SatPPduHeader::Print(std::ostream& os) const
164 {
165  NS_LOG_FUNCTION(this);
166 
167  os << m_startIndicator << " " << m_endIndicator << " " << m_ppduLengthInBytes << " "
168  << m_fragmentId << " " << m_totalLengthInBytes;
169 }
170 
171 TypeId
173 {
174  return GetTypeId();
175 }
176 
177 uint8_t
179 {
180  NS_LOG_FUNCTION(this);
181 
182  return m_startIndicator;
183 }
184 
185 uint8_t
187 {
188  NS_LOG_FUNCTION(this);
189 
190  return m_endIndicator;
191 }
192 
193 uint16_t
195 {
196  NS_LOG_FUNCTION(this);
197 
198  return m_ppduLengthInBytes;
199 }
200 
201 uint8_t
203 {
204  NS_LOG_FUNCTION(this);
205 
206  return m_fragmentId;
207 }
208 
209 uint16_t
211 {
212  NS_LOG_FUNCTION(this);
213 
214  return m_totalLengthInBytes;
215 }
216 
217 void
219 {
220  NS_LOG_FUNCTION(this);
221 
222  m_startIndicator = 1;
223 }
224 
225 void
227 {
228  NS_LOG_FUNCTION(this);
229 
230  m_endIndicator = 1;
231 }
232 
233 void
235 {
236  NS_LOG_FUNCTION(this << bytes);
237 
238  m_ppduLengthInBytes = bytes;
239 }
240 
241 void
243 {
244  NS_LOG_FUNCTION(this << (uint32_t)id);
245 
246  m_fragmentId = id;
247 }
248 
249 void
251 {
252  NS_LOG_FUNCTION(this << bytes);
253 
254  m_totalLengthInBytes = bytes;
255 }
256 
257 uint32_t
259 {
260  NS_LOG_FUNCTION(this << (uint32_t)type);
261 
262  uint32_t size(0);
263  switch (type)
264  {
266  size = m_startPpduHeaderSize;
267  break;
268  }
271  break;
272  }
274  size = m_endPpduHeaderSize;
275  break;
276  }
278  size = m_fullPpduHeaderSize;
279  break;
280  }
281  default: {
282  NS_FATAL_ERROR("Unsupported SatEncapPduStatusTag: " << type);
283  break;
284  }
285  }
286  return size;
287 }
288 
289 uint32_t
291 {
292  NS_LOG_FUNCTION(this);
293 
294  return std::max(std::max(m_startPpduHeaderSize, m_continuationPpduHeaderSize),
296 }
297 
298 } // 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.