A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
uan-header-common.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 University of Washington
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Leonard Tracy <lentracy@gmail.com>
18 */
19
20#include "uan-header-common.h"
21
22#include "ns3/mac8-address.h"
23
24static const uint16_t ARP_PROT_NUMBER = 0x0806;
25static const uint16_t IPV4_PROT_NUMBER = 0x0800;
26static const uint16_t IPV6_PROT_NUMBER = 0x86DD;
27static const uint16_t SIXLOWPAN_PROT_NUMBER = 0xA0ED;
28
29namespace ns3
30{
31
32NS_OBJECT_ENSURE_REGISTERED(UanHeaderCommon);
33
35{
36}
37
39 const Mac8Address dest,
40 uint8_t type,
41 uint8_t protocolNumber)
42 : Header(),
43 m_dest(dest),
44 m_src(src)
45{
46 SetProtocolNumber(protocolNumber);
48}
49
52{
53 static TypeId tid = TypeId("ns3::UanHeaderCommon")
55 .SetGroupName("Uan")
56 .AddConstructor<UanHeaderCommon>();
57 return tid;
58}
59
62{
63 return GetTypeId();
64}
65
67{
68}
69
70void
72{
73 m_dest = dest;
74}
75
76void
78{
79 m_src = src;
80}
81
82void
84{
86}
87
88void
89UanHeaderCommon::SetProtocolNumber(uint16_t protocolNumber)
90{
91 if (protocolNumber == 0)
92 {
94 }
95 else if (protocolNumber == IPV4_PROT_NUMBER)
96 {
98 }
99 else if (protocolNumber == ARP_PROT_NUMBER)
100 {
102 }
103 else if (protocolNumber == IPV6_PROT_NUMBER)
104 {
106 }
107 else if (protocolNumber == SIXLOWPAN_PROT_NUMBER)
108 {
110 }
111 else
112 {
113 NS_ASSERT_MSG(false, "UanHeaderCommon::SetProtocolNumber(): Protocol not supported");
114 }
115}
116
119{
120 return m_dest;
121}
122
125{
126 return m_src;
127}
128
129uint8_t
131{
133}
134
135uint16_t
137{
139 {
140 return IPV4_PROT_NUMBER;
141 }
143 {
144 return ARP_PROT_NUMBER;
145 }
147 {
148 return IPV6_PROT_NUMBER;
149 }
151 {
153 }
154 return 0;
155}
156
157// Inherited methods
158
161{
162 return 1 + 1 + 1;
163}
164
165void
167{
168 uint8_t address = 0;
169 m_src.CopyTo(&address);
170 start.WriteU8(address);
171 m_dest.CopyTo(&address);
172 start.WriteU8(address);
173 char tmp = m_uanProtocolBits.m_type;
174 tmp = tmp << 4;
176 start.WriteU8(tmp);
177}
178
181{
182 Buffer::Iterator rbuf = start;
183
184 m_src = Mac8Address(rbuf.ReadU8());
185 m_dest = Mac8Address(rbuf.ReadU8());
186 char tmp = rbuf.ReadU8();
187 m_uanProtocolBits.m_type = tmp >> 4;
189
190 return rbuf.GetDistanceFrom(start);
191}
192
193void
194UanHeaderCommon::Print(std::ostream& os) const
195{
196 os << "UAN src=" << m_src << " dest=" << m_dest
197 << " type=" << (uint32_t)m_uanProtocolBits.m_type
198 << "Protocol Number=" << (uint32_t)m_uanProtocolBits.m_protocolNumber;
199}
200
201} // namespace ns3
iterator in a Buffer instance
Definition: buffer.h:100
uint8_t ReadU8()
Definition: buffer.h:1027
uint32_t GetDistanceFrom(const Iterator &o) const
Definition: buffer.cc:780
Protocol header serialization and deserialization.
Definition: header.h:44
A class used for addressing MAC8 MAC's.
Definition: mac8-address.h:44
void CopyTo(uint8_t *pBuffer) const
Writes address to buffer parameter.
Definition: mac8-address.cc:82
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
Common packet header fields.
static TypeId GetTypeId()
Register this type.
void SetSrc(Mac8Address src)
Set the source address.
uint32_t Deserialize(Buffer::Iterator start) override
uint32_t GetSerializedSize() const override
Mac8Address m_dest
The destination address.
uint8_t GetType() const
Get the header type value.
Mac8Address m_src
The source address.
Mac8Address GetDest() const
Get the destination address.
UanHeaderCommon()
Default constructor.
void SetProtocolNumber(uint16_t protocolNumber)
Set the packet type.
void Serialize(Buffer::Iterator start) const override
Mac8Address GetSrc() const
Get the source address.
UanProtocolBits m_uanProtocolBits
The type and protocol bits.
void SetDest(Mac8Address dest)
Set the destination address.
void SetType(uint8_t type)
Set the header type.
~UanHeaderCommon() override
Destructor.
void Print(std::ostream &os) const override
uint16_t GetProtocolNumber() const
Get the packet type value.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:86
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t m_protocolNumber
protocol number (4 bits)
uint8_t m_type
type (4 bits)
static const uint16_t IPV4_PROT_NUMBER
static const uint16_t SIXLOWPAN_PROT_NUMBER
static const uint16_t ARP_PROT_NUMBER
static const uint16_t IPV6_PROT_NUMBER