A Discrete-Event Network Simulator
API
erp-information.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2015 S├ębastien Deronne
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: S├ębastien Deronne <sebastien.deronne@gmail.com>
19  */
20 
21 #include "erp-information.h"
22 #include "ns3/assert.h"
23 #include "ns3/log.h"
24 
25 namespace ns3 {
26 
27 NS_LOG_COMPONENT_DEFINE ("ErpInformation");
28 
30  : m_erpInformation (0),
31  m_erpSupported (0)
32 {
33 }
34 
37 {
38  return IE_ERP_INFORMATION;
39 }
40 
41 void
42 ErpInformation::SetErpSupported (uint8_t erpSupported)
43 {
44  m_erpSupported = erpSupported;
45 }
46 
47 void
48 ErpInformation::SetBarkerPreambleMode (uint8_t barkerPreambleMode)
49 {
50  m_erpInformation |= (barkerPreambleMode & 0x01) << 2;
51 }
52 
53 void
54 ErpInformation::SetUseProtection (uint8_t useProtection)
55 {
56  m_erpInformation |= (useProtection & 0x01) << 1;
57 }
58 
59 void
60 ErpInformation::SetNonErpPresent (uint8_t nonErpPresent)
61 {
62  m_erpInformation |= nonErpPresent & 0x01;
63 }
64 
65 uint8_t
67 {
68  return ((m_erpInformation >> 2) & 0x01);
69 }
70 
71 uint8_t
73 {
74  return ((m_erpInformation >> 1) & 0x01);
75 }
76 
77 uint8_t
79 {
80  return (m_erpInformation & 0x01);
81 }
82 
83 uint8_t
85 {
87  return 1;
88 }
89 
92 {
93  if (m_erpSupported < 1)
94  {
95  return i;
96  }
98 }
99 
100 uint16_t
102 {
103  if (m_erpSupported < 1)
104  {
105  return 0;
106  }
108 }
109 
110 void
112 {
113  if (m_erpSupported == 1)
114  {
115  start.WriteU8 (m_erpInformation);
116  }
117 }
118 
119 uint8_t
121  uint8_t length)
122 {
124  m_erpInformation = i.ReadU8 ();
125  return length;
126 }
127 
129 
130 std::ostream &
131 operator << (std::ostream &os, const ErpInformation &erpinformation)
132 {
133  os << bool (erpinformation.GetBarkerPreambleMode ())
134  << "|" << bool (erpinformation.GetUseProtection ())
135  << "|" << bool (erpinformation.GetNonErpPresent ());
136 
137  return os;
138 }
139 
140 std::istream &operator >> (std::istream &is, ErpInformation &erpinformation)
141 {
142  bool c1, c2, c3;
143  is >> c1 >> c2 >> c3;
144  erpinformation.SetBarkerPreambleMode (c1);
145  erpinformation.SetUseProtection (c2);
146  erpinformation.SetNonErpPresent (c3);
147 
148  return is;
149 }
150 
151 } //namespace ns3
std::istream & operator>>(std::istream &is, Angles &a)
initialize a struct Angles from input
Definition: angles.cc:48
Buffer::Iterator Serialize(Buffer::Iterator start) const
This information element is a bit special in that it is only included if the STA is an ERP STA...
void SetErpSupported(uint8_t erpSupported)
#define ATTRIBUTE_HELPER_CPP(type)
Define the attribute value, accessor and checkers for class type.
uint8_t GetInformationFieldSize() const
Length of serialized information (i.e., the length of the body of the IE, not including the Element I...
def start()
Definition: core.py:1482
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
void SetBarkerPreambleMode(uint8_t barkerPreambleMode)
Set the Barker_Preamble_Mode field in the ErpInformation information element.
uint16_t GetSerializedSize() const
Get the size of the serialized IE including Element ID and length fields.
iterator in a Buffer instance
Definition: buffer.h:98
uint8_t DeserializeInformationField(Buffer::Iterator start, uint8_t length)
Deserialize information (i.e., the body of the IE, not including the Element ID and length octets) ...
uint8_t GetBarkerPreambleMode(void) const
void SerializeInformationField(Buffer::Iterator start) const
Serialize information (i.e., the body of the IE, not including the Element ID and length octets) ...
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:42
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetUseProtection(uint8_t useProtection)
Set the Use_Protection field in the ErpInformation information element.
void WriteU8(uint8_t data)
Definition: buffer.h:868
uint8_t GetNonErpPresent(void) const
WifiInformationElementId ElementId() const
Own unique Element ID.
uint8_t ReadU8(void)
Definition: buffer.h:1020
The ErpInformation Information ElementThis class knows how to serialise and deserialise the ErpInform...
uint8_t WifiInformationElementId
This type is used to represent an Information Element ID.
#define IE_ERP_INFORMATION
uint8_t GetUseProtection(void) const
void SetNonErpPresent(uint8_t nonErpPresent)
Set the Non_Erp_Present field in the ErpInformation information element.
uint16_t GetSerializedSize() const
Return the serialized size of this ErpInformation information element.
Buffer::Iterator Serialize(Buffer::Iterator i) const
Serialize entire IE including Element ID and length fields.