A Discrete-Event Network Simulator
API
 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 
27 {
28  m_address = 255;
29 }
30 
31 UanAddress::UanAddress (uint8_t addr)
32  : m_address (addr)
33 {
34 }
35 
37 {
38 }
39 
40 uint8_t
42 {
43  static uint8_t type = Address::Register ();
44  return type;
45 }
46 
47 Address
49 {
50  return Address (GetType (), &m_address, 1);
51 }
52 
55 {
56  NS_ASSERT (IsMatchingType (address));
57  UanAddress uAddr;
58  address.CopyTo (&uAddr.m_address);
59  return uAddr;
60 }
61 
62 uint8_t
64 {
65  return m_address;
66 }
67 bool
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 
93 {
94  return UanAddress (255);
95 }
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.m_address == b.m_address;
120 }
121 
122 bool
123 operator != (const UanAddress &a, const UanAddress &b)
124 {
125  return !(a == b);
126 }
127 
128 std::ostream&
129 operator<< (std::ostream& os, const UanAddress & address)
130 {
131  os << (int) address.m_address;
132  return os;
133 }
134 std::istream&
135 operator>> (std::istream& is, UanAddress & address)
136 {
137  int x;
138  is >> x;
139  NS_ASSERT (0 <= x);
140  NS_ASSERT (x <= 255);
141  address.m_address = x;
142  return is;
143 }
144 
145 } // namespace ns3
std::istream & operator>>(std::istream &is, Angles &a)
initialize a struct Angles from input
Definition: angles.cc:49
static bool IsMatchingType(const Address &address)
Check that a generic Address is compatible with UanAddress.
Definition: uan-address.cc:68
#define NS_ASSERT(condition)
Definition: assert.h:64
void CopyFrom(const uint8_t *pBuffer)
Sets address to address stored in parameter.
Definition: uan-address.cc:79
bool operator<(const Room &a, const Room &b)
a polymophic address class
Definition: address.h:86
bool CheckCompatible(uint8_t type, uint8_t len) const
Definition: address.cc:122
A class used for addressing UAN MAC's.
Definition: uan-address.h:40
static uint8_t GetType(void)
Get the UanAddress type.
Definition: uan-address.cc:41
static UanAddress ConvertFrom(const Address &address)
Convert a generic address to a UanAddress.
Definition: uan-address.cc:54
virtual ~UanAddress()
Destructor.
Definition: uan-address.cc:36
static UanAddress GetBroadcast(void)
Get the broadcast address (255).
Definition: uan-address.cc:92
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:43
Address ConvertTo(void) const
Convert to a generic Address.
Definition: uan-address.cc:48
uint8_t GetAsInt(void) const
Convert to integer.
Definition: uan-address.cc:63
bool operator!=(Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 > a, Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 > b)
Inequality test.
Definition: callback.h:1213
void CopyTo(uint8_t *pBuffer)
Writes address to buffer parameter.
Definition: uan-address.cc:85
uint32_t CopyTo(uint8_t buffer[MAX_SIZE]) const
Definition: address.cc:82
static UanAddress Allocate()
Allocates UanAddress from 0-254.
Definition: uan-address.cc:97
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.cc:89
tuple address
Definition: first.py:37
UanAddress()
Constructor.
Definition: uan-address.cc:26
static uint8_t Register(void)
Allocate a new type id for a new type of address.
Definition: address.cc:138
uint8_t m_address
The address.
Definition: uan-address.h:117