A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
uan-address.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-address.h
"
22
#include "ns3/address.h"
23
24
namespace
ns3 {
25
26
UanAddress::UanAddress
()
27
{
28
m_address
= 255;
29
}
30
31
UanAddress::UanAddress
(uint8_t addr)
32
: m_address (addr)
33
{
34
}
35
36
UanAddress::~UanAddress
()
37
{
38
}
39
40
uint8_t
41
UanAddress::GetType
(
void
)
42
{
43
static
uint8_t type =
Address::Register
();
44
return
type;
45
}
46
47
Address
48
UanAddress::ConvertTo
(
void
)
const
49
{
50
return
Address
(
GetType
(), &
m_address
, 1);
51
}
52
53
UanAddress
54
UanAddress::ConvertFrom
(
const
Address
&address)
55
{
56
NS_ASSERT
(
IsMatchingType
(address));
57
UanAddress
uAddr;
58
address.
CopyTo
(&uAddr.
m_address
);
59
return
uAddr;
60
}
61
62
uint8_t
63
UanAddress::GetAsInt
(
void
)
const
64
{
65
return
m_address
;
66
}
67
bool
68
UanAddress::IsMatchingType
(
const
Address
&address)
69
{
70
return
address.
CheckCompatible
(
GetType
(), 1);
71
}
72
73
UanAddress::operator
Address
()
const
74
{
75
return
ConvertTo ();
76
}
77
78
void
79
UanAddress::CopyFrom
(
const
uint8_t *pBuffer)
80
{
81
m_address
= *pBuffer;
82
}
83
84
void
85
UanAddress::CopyTo
(uint8_t *pBuffer)
86
{
87
*pBuffer =
m_address
;
88
89
}
90
91
UanAddress
92
UanAddress::GetBroadcast
()
93
{
94
return
UanAddress
(255);
95
}
96
UanAddress
97
UanAddress::Allocate
()
98
{
99
static
uint8_t nextAllocated = 0;
100
101
uint32_t address = nextAllocated++;
102
if
(nextAllocated == 255)
103
{
104
nextAllocated = 0;
105
}
106
107
return
UanAddress
(address);
108
}
109
110
bool
111
operator ==
(
const
UanAddress
&a,
const
UanAddress
&b)
112
{
113
return
a.
m_address
== b.
m_address
;
114
}
115
116
bool
117
operator !=
(
const
UanAddress
&a,
const
UanAddress
&b)
118
{
119
return
!(a == b);
120
}
121
122
std::ostream&
123
operator<<
(std::ostream& os,
const
UanAddress
& address)
124
{
125
os << (int) address.
m_address
;
126
return
os;
127
}
128
std::istream&
129
operator>>
(std::istream& is,
UanAddress
& address)
130
{
131
int
x
;
132
is >>
x
;
133
NS_ASSERT
(0 <= x);
134
NS_ASSERT
(x <= 255);
135
address.
m_address
=
x
;
136
return
is;
137
}
138
139
}
// namespace ns3
src
uan
model
uan-address.cc
Generated on Tue May 14 2013 11:08:33 for ns-3 by
1.8.1.2