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 
24 static const uint16_t ARP_PROT_NUMBER = 0x0806;
25 static const uint16_t IPV4_PROT_NUMBER = 0x0800;
26 static const uint16_t IPV6_PROT_NUMBER = 0x86DD;
27 
28 namespace ns3 {
29 
30 NS_OBJECT_ENSURE_REGISTERED (UanHeaderCommon);
31 
33 {
34 }
35 
36 UanHeaderCommon::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 
45 TypeId
47 {
48  static TypeId tid = TypeId ("ns3::UanHeaderCommon")
49  .SetParent<Header> ()
50  .SetGroupName ("Uan")
51  .AddConstructor<UanHeaderCommon> ()
52  ;
53  return tid;
54 }
55 
56 TypeId
58 {
59  return GetTypeId ();
60 }
62 {
63 }
64 
65 
66 void
68 {
69  m_dest = dest;
70 }
71 void
73 {
74  m_src = src;
75 }
76 
77 void
79 {
81 }
82 
83 void
84 UanHeaderCommon::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 }
108 uint8_t
110 {
111  return m_uanProtocolBits.m_type;
112 }
113 
114 uint16_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 
128 uint32_t
130 {
131  return 1 + 1 + 1;
132 }
133 
134 void
136 {
137  uint8_t address = 0;
138  m_src.CopyTo (&address);
139  start.WriteU8 (address);
140  m_dest.CopyTo (&address);
141  start.WriteU8 (address);
142  char tmp = m_uanProtocolBits.m_type;
143  tmp = tmp << 4;
145  start.WriteU8 (tmp);
146 }
147 
148 uint32_t
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 
162 void
163 UanHeaderCommon::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
Protocol header serialization and deserialization.
Definition: header.h:42
virtual uint32_t GetSerializedSize(void) const
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
void SetSrc(Mac8Address src)
Set the source address.
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
def start()
Definition: core.py:1844
virtual uint32_t Deserialize(Buffer::Iterator start)
uint8_t GetType(void) const
Get the header type value.
iterator in a Buffer instance
Definition: buffer.h:98
static const uint16_t ARP_PROT_NUMBER
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:783
void SetProtocolNumber(uint16_t protocolNumber)
Set the packet type.
Mac8Address GetDest(void) const
Get the destination address.
static const uint16_t IPV6_PROT_NUMBER
virtual ~UanHeaderCommon()
Destructor.
A class used for addressing MAC8 MAC&#39;s.
Definition: mac8-address.h:42
UanHeaderCommon()
Default constructor.
static TypeId GetTypeId(void)
Register this type.
Mac8Address GetSrc(void) const
Get the source address.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Common packet header fields.
address
Definition: first.py:37
Mac8Address m_dest
The destination address.
UanProtocolBits m_uanProtocolBits
The type and protocol bits.
static const uint16_t IPV4_PROT_NUMBER
void SetDest(Mac8Address dest)
Set the destination address.
uint16_t GetProtocolNumber(void) const
Get the packet type value.
uint8_t ReadU8(void)
Definition: buffer.h:1021
virtual void Print(std::ostream &os) const
void SetType(uint8_t type)
Set the header type.
virtual void Serialize(Buffer::Iterator start) const
a unique identifier for an interface.
Definition: type-id.h:58
Mac8Address m_src
The source address.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
void CopyTo(uint8_t *pBuffer) const
Writes address to buffer parameter.
Definition: mac8-address.cc:80
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.