A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ofdm-downlink-frame-prefix.cc
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007,2008 INRIA
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: Jahanzeb Farooq <jahanzeb.farooq@sophia.inria.fr>
19  */
20 
21 #include <stdint.h>
22 #include <stdint.h>
23 #include "ofdm-downlink-frame-prefix.h"
24 #include "ns3/address-utils.h"
25 
26 namespace ns3 {
27 
28 DlFramePrefixIe::DlFramePrefixIe ()
29  : m_rateId (0),
30  m_diuc (0),
31  m_preamblePresent (0),
32  m_length (0),
33  m_startTime (0)
34 {
35 }
36 
37 DlFramePrefixIe::~DlFramePrefixIe ()
38 {
39 }
40 
41 void
42 DlFramePrefixIe::SetRateId (uint8_t rateId)
43 {
44  m_rateId = rateId;
45 }
46 
47 void
48 DlFramePrefixIe::SetDiuc (uint8_t diuc)
49 {
50  m_diuc = diuc;
51 }
52 
53 void
54 DlFramePrefixIe::SetPreamblePresent (uint8_t preamblePresent)
55 {
56  m_preamblePresent = preamblePresent;
57 }
58 
59 void
60 DlFramePrefixIe::SetLength (uint16_t length)
61 {
62  m_length = length;
63 }
64 
65 void
66 DlFramePrefixIe::SetStartTime (uint16_t startTime)
67 {
68  m_startTime = startTime;
69 }
70 
71 uint8_t
72 DlFramePrefixIe::GetRateId (void) const
73 {
74  return m_rateId;
75 }
76 
77 uint8_t
78 DlFramePrefixIe::GetDiuc (void) const
79 {
80  return m_diuc;
81 }
82 
83 uint8_t
84 DlFramePrefixIe::GetPreamblePresent (void) const
85 {
86  return m_preamblePresent;
87 }
88 
89 uint16_t
90 DlFramePrefixIe::GetLength (void) const
91 {
92  return m_length;
93 }
94 
95 uint16_t
96 DlFramePrefixIe::GetStartTime (void) const
97 {
98  return m_startTime;
99 }
100 
101 uint16_t
102 DlFramePrefixIe::GetSize (void) const
103 {
104  return 1 + 1 + 1 + 2 + 2;
105 }
106 
107 Buffer::Iterator
108 DlFramePrefixIe::Write (Buffer::Iterator start) const
109 {
110  Buffer::Iterator i = start;
111  i.WriteU8 (m_rateId);
112  i.WriteU8 (m_diuc);
113  i.WriteU8 (m_preamblePresent);
114  i.WriteU16 (m_length);
115  i.WriteU16 (m_startTime);
116  return i;
117 }
118 
119 Buffer::Iterator
120 DlFramePrefixIe::Read (Buffer::Iterator start)
121 {
122  Buffer::Iterator i = start;
123  m_rateId = i.ReadU8 ();
124  m_diuc = i.ReadU8 ();
125  m_preamblePresent = i.ReadU8 ();
126  m_length = i.ReadU16 ();
127  m_startTime = i.ReadU16 ();
128  return i;
129 }
130 
131 OfdmDownlinkFramePrefix::OfdmDownlinkFramePrefix ()
132  : m_baseStationId (Mac48Address ("00:00:00:00:00:00")),
133  m_frameNumber (0),
134  m_configurationChangeCount (0),
135  m_hcs (0)
136 {
137 }
138 
139 OfdmDownlinkFramePrefix::~OfdmDownlinkFramePrefix ()
140 {
141 }
142 
143 void
144 OfdmDownlinkFramePrefix::SetBaseStationId (Mac48Address baseStationId)
145 {
146  m_baseStationId = baseStationId;
147 }
148 
149 void
150 OfdmDownlinkFramePrefix::SetFrameNumber (uint32_t frameNumber)
151 {
152  m_frameNumber = frameNumber;
153 }
154 
155 void
156 OfdmDownlinkFramePrefix::SetConfigurationChangeCount (
157  uint8_t configurationChangeCount)
158 {
159  m_configurationChangeCount = configurationChangeCount;
160 }
161 
162 void
163 OfdmDownlinkFramePrefix::AddDlFramePrefixElement (
164  DlFramePrefixIe dlFramePrefixElement)
165 {
166  m_dlFramePrefixElements.push_back (dlFramePrefixElement);
167 }
168 
169 void
170 OfdmDownlinkFramePrefix::SetHcs (uint8_t hcs)
171 {
172  m_hcs = hcs;
173 }
174 
175 Mac48Address
176 OfdmDownlinkFramePrefix::GetBaseStationId (void) const
177 {
178  return m_baseStationId;
179 }
180 
181 uint32_t
182 OfdmDownlinkFramePrefix::GetFrameNumber (void) const
183 {
184  return m_frameNumber;
185 }
186 
187 uint8_t
188 OfdmDownlinkFramePrefix::GetConfigurationChangeCount (void) const
189 {
190  return m_configurationChangeCount;
191 }
192 
193 std::vector<DlFramePrefixIe>
194 OfdmDownlinkFramePrefix::GetDlFramePrefixElements (void) const
195 {
196  return m_dlFramePrefixElements;
197 }
198 
199 uint8_t
200 OfdmDownlinkFramePrefix::GetHcs (void) const
201 {
202  return m_hcs;
203 }
204 
205 std::string
206 OfdmDownlinkFramePrefix::GetName (void) const
207 {
208  return "OFDM Downlink Frame Prefix";
209 }
210 
211 void
212 OfdmDownlinkFramePrefix::Print (std::ostream &os) const
213 {
214  os << " base station id = " << m_baseStationId << ", frame number = "
215  << m_frameNumber << ", configuration change count = "
216  << (uint32_t) m_configurationChangeCount
217  << ", number of dl frame prefix elements = "
218  << m_dlFramePrefixElements.size () << ", hcs = " << (uint32_t) m_hcs;
219 }
220 
221 uint32_t
223 {
224  int dlFramePrefixElementsSize = 0;
225 
226  for (std::vector<DlFramePrefixIe>::const_iterator iter =
227  m_dlFramePrefixElements.begin (); iter != m_dlFramePrefixElements.end (); iter++)
228  {
229  DlFramePrefixIe dlFramePrefixElement = *iter;
230  dlFramePrefixElementsSize += dlFramePrefixElement.GetSize ();
231  }
232 
233  return 6 + 4 + 1 + dlFramePrefixElementsSize + 1;
234 }
235 
236 void
238 {
239  Buffer::Iterator i = start;
240  WriteTo (i, m_baseStationId);
241  i.WriteU32 (m_frameNumber);
242  i.WriteU8 (m_configurationChangeCount);
243 
244  for (std::vector<DlFramePrefixIe>::const_iterator iter =
245  m_dlFramePrefixElements.begin (); iter != m_dlFramePrefixElements.end (); iter++)
246  {
247  DlFramePrefixIe dlFramePrefixElement = *iter;
248  i = dlFramePrefixElement.Write (i);
249  }
250 
251  i.WriteU8 (m_hcs);
252 }
253 
254 uint32_t
256 {
257  Buffer::Iterator i = start;
258  ReadFrom (i, m_baseStationId);
259  m_frameNumber = i.ReadU32 ();
260  m_configurationChangeCount = i.ReadU8 ();
261 
262  bool end = false;
263 
264  while (!end)
265  {
266  DlFramePrefixIe dlFramePrefixElement;
267  i = dlFramePrefixElement.Read (i);
268 
269  AddDlFramePrefixElement (dlFramePrefixElement);
270 
271  if (dlFramePrefixElement.GetDiuc () == 14)
272  {
273  end = true;
274  }
275  }
276 
277  m_hcs = i.ReadU8 ();
278 
279  return GetSerializedSize ();
280 }
281 
282 } // namespace ns3
283 
uint32_t ReadU32(void)
Definition: buffer.cc:997
iterator in a Buffer instance
Definition: buffer.h:98
This class implements the DL Frame Prefix IE as described by IEEE-802.16 standard.
void WriteU8(uint8_t data)
Definition: buffer.h:690
uint8_t ReadU8(void)
Definition: buffer.h:819
void WriteU32(uint32_t data)
Definition: buffer.cc:903