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 "uan-address.h"
23 
24 namespace ns3 {
25 
26 NS_OBJECT_ENSURE_REGISTERED (UanHeaderCommon);
27 
29 {
30 }
31 
32 UanHeaderCommon::UanHeaderCommon (const UanAddress src, const UanAddress dest, uint8_t type)
33  : Header (),
34  m_dest (dest),
35  m_src (src),
36  m_type (type)
37 {
38 
39 }
40 
41 TypeId
43 {
44  static TypeId tid = TypeId ("ns3::UanHeaderCommon")
45  .SetParent<Header> ()
46  .SetGroupName ("Uan")
47  .AddConstructor<UanHeaderCommon> ()
48  ;
49  return tid;
50 }
51 
52 TypeId
54 {
55  return GetTypeId ();
56 }
58 {
59 }
60 
61 
62 void
64 {
65  m_dest = dest;
66 }
67 void
69 {
70  m_src = src;
71 }
72 
73 void
75 {
76  m_type = type;
77 }
78 
81 {
82  return m_dest;
83 }
86 {
87  return m_src;
88 }
89 uint8_t
91 {
92  return m_type;
93 }
94 
95 // Inherrited methods
96 
97 uint32_t
99 {
100  return 1 + 1 + 1;
101 }
102 
103 void
105 {
106  start.WriteU8 (m_src.GetAsInt ());
107  start.WriteU8 (m_dest.GetAsInt ());
108  start.WriteU8 (m_type);
109 }
110 
111 uint32_t
113 {
114  Buffer::Iterator rbuf = start;
115 
116  m_src = UanAddress (rbuf.ReadU8 ());
117  m_dest = UanAddress (rbuf.ReadU8 ());
118  m_type = rbuf.ReadU8 ();
119 
120  return rbuf.GetDistanceFrom (start);
121 }
122 
123 void
124 UanHeaderCommon::Print (std::ostream &os) const
125 {
126  os << "UAN src=" << m_src << " dest=" << m_dest << " type=" << (uint32_t) m_type;
127 }
128 
129 
130 
131 
132 } // namespace ns3
Protocol header serialization and deserialization.
Definition: header.h:42
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
def start()
Definition: core.py:1790
virtual uint32_t Deserialize(Buffer::Iterator start)
uint8_t GetType(void) const
Get the header type value.
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:786
iterator in a Buffer instance
Definition: buffer.h:98
virtual void Print(std::ostream &os) const
A class used for addressing UAN MAC's.
Definition: uan-address.h:40
virtual uint32_t GetSerializedSize(void) const
UanAddress m_dest
The destination address.
virtual ~UanHeaderCommon()
Destructor.
void SetSrc(UanAddress src)
Set the source address.
UanHeaderCommon()
Default constructor.
void SetDest(UanAddress dest)
Set the destination address.
static TypeId GetTypeId(void)
Register this type.
uint8_t m_type
The type field.
virtual void Serialize(Buffer::Iterator start) const
uint8_t GetAsInt(void) const
Convert to integer.
Definition: uan-address.cc:63
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Common packet header fields.
UanAddress GetDest(void) const
Get the destination address.
void WriteU8(uint8_t data)
Definition: buffer.h:869
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
uint8_t ReadU8(void)
Definition: buffer.h:1021
void SetType(uint8_t type)
Set the header type.
UanAddress GetSrc(void) const
Get the source address.
UanAddress m_src
The source address.
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:914