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
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
uan-address.cc
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
ns3::operator>>
std::istream & operator>>(std::istream &is, Angles &a)
Definition:
angles.cc:49
ns3::UanAddress::IsMatchingType
static bool IsMatchingType(const Address &address)
Definition:
uan-address.cc:68
NS_ASSERT
#define NS_ASSERT(condition)
Definition:
assert.h:64
ns3::UanAddress::CopyFrom
void CopyFrom(const uint8_t *pBuffer)
Sets address to address stored in parameter.
Definition:
uan-address.cc:79
ns3::Address
a polymophic address class
Definition:
address.h:86
ns3::Address::CheckCompatible
bool CheckCompatible(uint8_t type, uint8_t len) const
Definition:
address.cc:122
ns3::UanAddress
Definition:
uan-address.h:37
ns3::UanAddress::ConvertFrom
static UanAddress ConvertFrom(const Address &address)
Definition:
uan-address.cc:54
ns3::UanAddress::GetBroadcast
static UanAddress GetBroadcast(void)
Definition:
uan-address.cc:92
ns3::operator<<
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition:
angles.cc:43
ns3::UanAddress::GetAsInt
uint8_t GetAsInt(void) const
Definition:
uan-address.cc:63
ns3::UanAddress::CopyTo
void CopyTo(uint8_t *pBuffer)
Writes address to buffer parameter.
Definition:
uan-address.cc:85
ns3::Address::CopyTo
uint32_t CopyTo(uint8_t buffer[MAX_SIZE]) const
Definition:
address.cc:82
ns3::UanAddress::Allocate
static UanAddress Allocate()
Allocates UanAddress from 0-254 (will wrap back to 0 if more than 255 are allocated) ...
Definition:
uan-address.cc:97
ns3::Address::Register
static uint8_t Register(void)
Definition:
address.cc:137
src
uan
model
uan-address.cc
Generated on Sun Mar 16 2014 11:25:11 for ns-3 by
1.8.6