A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ie-dot11s-peer-management.cc
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2008,2009 IITP RAS
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  * Authors: Kirill Andreev <andreev@iitp.ru>
19  * Aleksey Kovalenko <kovalenko@iitp.ru>
20  */
21 
22 #include "ie-dot11s-peer-management.h"
23 #include "ns3/assert.h"
24 #include "ns3/packet.h"
25 
26 namespace ns3 {
27 namespace dot11s {
28 
29 IePeerManagement::IePeerManagement () :
30  m_length (3), m_subtype (PEER_OPEN), m_localLinkId (0), m_peerLinkId (0), m_reasonCode (REASON11S_RESERVED)
31 {
32 }
35 {
36  return IE11S_PEERING_MANAGEMENT;
37 }
38 void
39 IePeerManagement::SetPeerOpen (uint16_t localLinkId)
40 {
41  m_length = 3;
42  m_subtype = PEER_OPEN;
43  m_localLinkId = localLinkId;
44 }
45 void
46 IePeerManagement::SetPeerClose (uint16_t localLinkId, uint16_t peerLinkId, PmpReasonCode reasonCode)
47 {
48  m_length = 7;
49  m_subtype = PEER_CLOSE;
50  m_localLinkId = localLinkId;
51  m_peerLinkId = peerLinkId;
52  m_reasonCode = reasonCode;
53 }
54 
55 void
56 IePeerManagement::SetPeerConfirm (uint16_t localLinkId, uint16_t peerLinkId)
57 {
58  m_length = 5;
59  m_subtype = PEER_CONFIRM;
60  m_localLinkId = localLinkId;
61  m_peerLinkId = peerLinkId;
62 }
63 
65 IePeerManagement::GetReasonCode () const
66 {
67  return m_reasonCode;
68 }
69 
70 uint16_t
71 IePeerManagement::GetLocalLinkId () const
72 {
73  return m_localLinkId;
74 }
75 
76 uint16_t
77 IePeerManagement::GetPeerLinkId () const
78 {
79  return m_peerLinkId;
80 }
81 
82 uint8_t
84 {
85  return m_length;
86 }
87 uint8_t
88 IePeerManagement::GetSubtype () const
89 {
90  return m_subtype;
91 }
92 bool
93 IePeerManagement::SubtypeIsOpen () const
94 {
95  return (m_subtype == PEER_OPEN);
96 }
97 bool
98 IePeerManagement::SubtypeIsClose () const
99 {
100  return (m_subtype == PEER_CLOSE);
101 }
102 bool
103 IePeerManagement::SubtypeIsConfirm () const
104 {
105  return (m_subtype == PEER_CONFIRM);
106 }
107 
108 void
110 {
111  i.WriteU8 (m_subtype);
112  i.WriteHtolsbU16 (m_localLinkId);
113  if (m_length > 3)
114  {
116  }
117  if (m_length > 5)
118  {
120  }
121 }
122 uint8_t
124 {
125  Buffer::Iterator i = start;
126  m_subtype = i.ReadU8 ();
127  m_length = length;
128  if (m_subtype == PEER_OPEN)
129  {
130  NS_ASSERT (length == 3);
131  }
132  if (m_subtype == PEER_CONFIRM)
133  {
134  NS_ASSERT (length == 5);
135  }
136  if (m_subtype == PEER_CLOSE)
137  {
138  NS_ASSERT (length == 7);
139  }
140  m_localLinkId = i.ReadLsbtohU16 ();
141  if (m_length > 3)
142  {
144  }
145  if (m_length > 5)
146  {
148  }
149  return i.GetDistanceFrom (start);
150 }
151 void
152 IePeerManagement::Print (std::ostream& os) const
153 {
154  os << std::endl << "<information_element id=" << ElementId () << ">" << std::endl;
155  os << " Subtype: = " << (uint16_t) m_subtype << std::endl;
156  os << " Length: = " << (uint16_t) m_length << std::endl;
157  os << " LocalLinkId: = " << m_localLinkId << std::endl;
158  os << " PeerLinkId: = " << m_peerLinkId << std::endl;
159  os << " ReasonCode: = " << m_reasonCode << std::endl;
160  os << "</information_element>" << std::endl;
161 }
162 bool
163 operator== (const IePeerManagement & a, const IePeerManagement & b)
164 {
165  return ((a.m_length == b.m_length) && (a.m_subtype == b.m_subtype) && (a.m_localLinkId == b.m_localLinkId)
166  && (a.m_peerLinkId == b.m_peerLinkId) && (a.m_reasonCode == b.m_reasonCode));
167 }
168 std::ostream &
169 operator << (std::ostream &os, const IePeerManagement &a)
170 {
171  a.Print (os);
172  return os;
173 }
174 } // namespace dot11s
175 } // namespace ns3
176 
#define NS_ASSERT(condition)
Definition: assert.h:64
virtual WifiInformationElementId ElementId() const
Own unique Element ID.
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:807
iterator in a Buffer instance
Definition: buffer.h:98
See 7.3.2.85 of draft 2.07.
virtual uint8_t GetInformationFieldSize(void) const
virtual uint8_t DeserializeInformationField(Buffer::Iterator i, uint8_t length)
virtual void Print(std::ostream &os) const
In addition, a subclass may optionally override the following...
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:43
void WriteHtolsbU16(uint16_t data)
Definition: buffer.cc:935
void WriteU8(uint8_t data)
Definition: buffer.h:690
PmpReasonCode
Codes used by 802.11s Peer Management Protocol.
uint8_t ReadU8(void)
Definition: buffer.h:819
uint16_t ReadLsbtohU16(void)
Definition: buffer.cc:1090
uint8_t WifiInformationElementId
virtual void SerializeInformationField(Buffer::Iterator i) const