A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  .AddConstructor<UanHeaderCommon> ()
47  ;
48  return tid;
49 }
50 
51 TypeId
53 {
54  return GetTypeId ();
55 }
57 {
58 }
59 
60 
61 void
63 {
64  m_dest = dest;
65 }
66 void
68 {
69  m_src = src;
70 }
71 
72 void
74 {
75  m_type = type;
76 }
77 
80 {
81  return m_dest;
82 }
85 {
86  return m_src;
87 }
88 uint8_t
90 {
91  return m_type;
92 }
93 
94 // Inherrited methods
95 
96 uint32_t
98 {
99  return 1 + 1 + 1;
100 }
101 
102 void
104 {
105  start.WriteU8 (m_src.GetAsInt ());
106  start.WriteU8 (m_dest.GetAsInt ());
107  start.WriteU8 (m_type);
108 }
109 
110 uint32_t
112 {
113  Buffer::Iterator rbuf = start;
114 
115  m_src = UanAddress (rbuf.ReadU8 ());
116  m_dest = UanAddress (rbuf.ReadU8 ());
117  m_type = rbuf.ReadU8 ();
118 
119  return rbuf.GetDistanceFrom (start);
120 }
121 
122 void
123 UanHeaderCommon::Print (std::ostream &os) const
124 {
125  os << "UAN src=" << m_src << " dest=" << m_dest << " type=" << (uint32_t) m_type;
126 }
127 
128 
129 
130 
131 } // namespace ns3
Protocol header serialization and deserialization.
Definition: header.h:42
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register the class in the ns-3 factory.
Definition: object-base.h:38
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:811
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
UanAddress GetDest(void) const
Get the destination address.
void WriteU8(uint8_t data)
Definition: buffer.h:876
virtual TypeId GetInstanceTypeId(void) const
uint8_t ReadU8(void)
Definition: buffer.h:1028
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:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610