A Discrete-Event Network Simulator
API
uan-header-common.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2009 University of Washington
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: Leonard Tracy <lentracy@gmail.com>
19 */
20
21#include "uan-header-common.h"
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;
27
28namespace ns3 {
29
30NS_OBJECT_ENSURE_REGISTERED (UanHeaderCommon);
31
33{
34}
35
36UanHeaderCommon::UanHeaderCommon (const Mac8Address src, const Mac8Address dest, uint8_t type, uint8_t protocolNumber)
37 : Header (),
38 m_dest (dest),
39 m_src (src)
40{
41 SetProtocolNumber (protocolNumber);
43}
44
47{
48 static TypeId tid = TypeId ("ns3::UanHeaderCommon")
49 .SetParent<Header> ()
50 .SetGroupName ("Uan")
51 .AddConstructor<UanHeaderCommon> ()
52 ;
53 return tid;
54}
55
58{
59 return GetTypeId ();
60}
62{
63}
64
65
66void
68{
69 m_dest = dest;
70}
71void
73{
74 m_src = src;
75}
76
77void
79{
81}
82
83void
84UanHeaderCommon::SetProtocolNumber (uint16_t protocolNumber)
85{
86 if (protocolNumber == 0)
88 else if (protocolNumber == IPV4_PROT_NUMBER)
90 else if (protocolNumber == ARP_PROT_NUMBER)
92 else if (protocolNumber == IPV6_PROT_NUMBER)
94 else
95 NS_ASSERT_MSG (false, "UanHeaderCommon::SetProtocolNumber(): Protocol not supported");
96}
97
100{
101 return m_dest;
102}
105{
106 return m_src;
107}
108uint8_t
110{
112}
113
114uint16_t
116{
118 return IPV4_PROT_NUMBER;
120 return ARP_PROT_NUMBER;
122 return IPV6_PROT_NUMBER;
123 return 0;
124}
125
126// Inherrited methods
127
130{
131 return 1 + 1 + 1;
132}
133
134void
136{
137 uint8_t address = 0;
139 start.WriteU8 (address);
141 start.WriteU8 (address);
142 char tmp = m_uanProtocolBits.m_type;
143 tmp = tmp << 4;
145 start.WriteU8 (tmp);
146}
147
150{
151 Buffer::Iterator rbuf = start;
152
153 m_src = Mac8Address (rbuf.ReadU8 ());
154 m_dest = Mac8Address (rbuf.ReadU8 ());
155 char tmp = rbuf.ReadU8 ();
156 m_uanProtocolBits.m_type = tmp >> 4;
158
159 return rbuf.GetDistanceFrom (start);
160}
161
162void
163UanHeaderCommon::Print (std::ostream &os) const
164{
165 os << "UAN src=" << m_src << " dest=" << m_dest << " type=" << (uint32_t) m_uanProtocolBits.m_type << "Protocol Number=" << (uint32_t) m_uanProtocolBits.m_protocolNumber;
166}
167
168
169
170
171} // namespace ns3
iterator in a Buffer instance
Definition: buffer.h:99
uint8_t ReadU8(void)
Definition: buffer.h:1021
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:788
Protocol header serialization and deserialization.
Definition: header.h:43
A class used for addressing MAC8 MAC's.
Definition: mac8-address.h:43
void CopyTo(uint8_t *pBuffer) const
Writes address to buffer parameter.
Definition: mac8-address.cc:86
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
Common packet header fields.
virtual ~UanHeaderCommon()
Destructor.
virtual void Print(std::ostream &os) const
void SetSrc(Mac8Address src)
Set the source address.
uint8_t GetType(void) const
Get the header type value.
virtual void Serialize(Buffer::Iterator start) const
Mac8Address m_dest
The destination address.
static TypeId GetTypeId(void)
Register this type.
Mac8Address m_src
The source address.
UanHeaderCommon()
Default constructor.
virtual uint32_t GetSerializedSize(void) const
virtual uint32_t Deserialize(Buffer::Iterator start)
Mac8Address GetSrc(void) const
Get the source address.
Mac8Address GetDest(void) const
Get the destination address.
void SetProtocolNumber(uint16_t protocolNumber)
Set the packet type.
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.
uint16_t GetProtocolNumber(void) const
Get the packet type value.
virtual TypeId GetInstanceTypeId(void) const
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:88
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
address
Definition: first.py:40
Every class exported by the ns3 library is enclosed in the ns3 namespace.
def start()
Definition: core.py:1852
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 ARP_PROT_NUMBER
static const uint16_t IPV6_PROT_NUMBER