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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Leonard Tracy <lentracy@gmail.com>
7 */
8
9#include "uan-header-common.h"
10
11#include "ns3/mac8-address.h"
12
13static const uint16_t ARP_PROT_NUMBER = 0x0806;
14static const uint16_t IPV4_PROT_NUMBER = 0x0800;
15static const uint16_t IPV6_PROT_NUMBER = 0x86DD;
16static const uint16_t SIXLOWPAN_PROT_NUMBER = 0xA0ED;
17
18namespace ns3
19{
20
21NS_OBJECT_ENSURE_REGISTERED(UanHeaderCommon);
22
26
28 const Mac8Address dest,
29 uint8_t type,
30 uint8_t protocolNumber)
31 : Header(),
32 m_dest(dest),
33 m_src(src)
34{
35 SetProtocolNumber(protocolNumber);
37}
38
41{
42 static TypeId tid = TypeId("ns3::UanHeaderCommon")
44 .SetGroupName("Uan")
45 .AddConstructor<UanHeaderCommon>();
46 return tid;
47}
48
51{
52 return GetTypeId();
53}
54
58
59void
64
65void
70
71void
73{
75}
76
77void
78UanHeaderCommon::SetProtocolNumber(uint16_t protocolNumber)
79{
80 if (protocolNumber == 0)
81 {
83 }
84 else if (protocolNumber == IPV4_PROT_NUMBER)
85 {
87 }
88 else if (protocolNumber == ARP_PROT_NUMBER)
89 {
91 }
92 else if (protocolNumber == IPV6_PROT_NUMBER)
93 {
95 }
96 else if (protocolNumber == SIXLOWPAN_PROT_NUMBER)
97 {
99 }
100 else
101 {
102 NS_ASSERT_MSG(false, "UanHeaderCommon::SetProtocolNumber(): Protocol not supported");
103 }
104}
105
108{
109 return m_dest;
110}
111
114{
115 return m_src;
116}
117
118uint8_t
123
124uint16_t
126{
128 {
129 return IPV4_PROT_NUMBER;
130 }
132 {
133 return ARP_PROT_NUMBER;
134 }
136 {
137 return IPV6_PROT_NUMBER;
138 }
140 {
142 }
143 return 0;
144}
145
146// Inherited methods
147
150{
151 return 1 + 1 + 1;
152}
153
154void
156{
157 uint8_t address = 0;
158 m_src.CopyTo(&address);
159 start.WriteU8(address);
160 m_dest.CopyTo(&address);
161 start.WriteU8(address);
162 char tmp = m_uanProtocolBits.m_type;
163 tmp = tmp << 4;
165 start.WriteU8(tmp);
166}
167
170{
171 Buffer::Iterator rbuf = start;
172
173 m_src = Mac8Address(rbuf.ReadU8());
174 m_dest = Mac8Address(rbuf.ReadU8());
175 char tmp = rbuf.ReadU8();
176 m_uanProtocolBits.m_type = tmp >> 4;
178
179 return rbuf.GetDistanceFrom(start);
180}
181
182void
183UanHeaderCommon::Print(std::ostream& os) const
184{
185 os << "UAN src=" << m_src << " dest=" << m_dest
186 << " type=" << (uint32_t)m_uanProtocolBits.m_type
187 << "Protocol Number=" << (uint32_t)m_uanProtocolBits.m_protocolNumber;
188}
189
190} // namespace ns3
iterator in a Buffer instance
Definition buffer.h:89
uint32_t GetDistanceFrom(const Iterator &o) const
Definition buffer.cc:769
Protocol header serialization and deserialization.
Definition header.h:33
A class used for addressing MAC8 MAC's.
void CopyTo(uint8_t *pBuffer) const
Writes address to buffer parameter.
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
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:75
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
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