A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
mac8-address.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 University of Washington
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Leonard Tracy <lentracy@gmail.com>
18 */
19
20#ifndef MAC8_ADDRESS_H
21#define MAC8_ADDRESS_H
22
23#include "ns3/address.h"
24
25#include <iostream>
26
27namespace ns3
28{
29
30class Address;
31
32/**
33 * \ingroup network
34 *
35 * A class used for addressing MAC8 MAC's.
36 *
37 * This implementation uses a simple 8 bit flat addressing scheme.
38 * It is unlikely that perceived underwater networks will soon
39 * exceed 200 nodes (or the overlapping of two underwater networks
40 * - the ocean is big), so this should provide adequate addressing
41 * for most applications.
42 */
44{
45 public:
46 Mac8Address() = default;
47 /**
48 * Create Mac8Address object with address addr.
49 *
50 * \param addr Byte address to assign to this address.
51 */
52 Mac8Address(uint8_t addr);
53 /** Destructor */
54 virtual ~Mac8Address();
55
56 /**
57 * Convert a generic address to a Mac8Address.
58 *
59 * \param address Address to convert to Mac8Address address.
60 * \return Mac8Address from Address.
61 */
62 static Mac8Address ConvertFrom(const Address& address);
63
64 /**
65 * Convert to a generic Address.
66 *
67 * \return The Address value.
68 */
69 Address ConvertTo() const;
70
71 /**
72 * Check that a generic Address is compatible with Mac8Address.
73 *
74 * \param address Address to test.
75 * \return True if address given is consistent with Mac8Address.
76 */
77 static bool IsMatchingType(const Address& address);
78
79 /**
80 * Create a generic Address.
81 *
82 * \return The Address.
83 */
84 operator Address() const;
85
86 /**
87 * Sets address to address stored in parameter.
88 *
89 * \param pBuffer Buffer to extract address from.
90 */
91 void CopyFrom(const uint8_t* pBuffer);
92
93 /**
94 * Writes address to buffer parameter.
95 *
96 * \param pBuffer
97 */
98 void CopyTo(uint8_t* pBuffer) const;
99
100 /**
101 * Get the broadcast address (255).
102 *
103 * \return Broadcast address.
104 */
105 static Mac8Address GetBroadcast();
106
107 /**
108 * Allocates Mac8Address from 0-254
109 *
110 * Will wrap back to 0 if more than 254 are allocated.
111 * Excludes the broadcast address.
112 *
113 * \return The next sequential Mac8Address.
114 */
115 static Mac8Address Allocate();
116
117 /**
118 * Reset the Mac8Address allocation index.
119 *
120 * This function resets (to zero) the global integer
121 * that is used for unique address allocation.
122 * It is automatically called whenever
123 * \code
124 * SimulatorDestroy ();
125 * \endcode
126 * is called. It may also be optionally called
127 * by user code if there is a need to force a reset
128 * of this allocation index.
129 */
130 static void ResetAllocationIndex();
131
132 private:
133 static uint8_t m_allocationIndex; //!< Address allocation index
134 uint8_t m_address{255}; //!< The address.
135
136 /**
137 * Get the Mac8Address type.
138 *
139 * \return The type value.
140 */
141 static uint8_t GetType();
142
143 friend bool operator<(const Mac8Address& a, const Mac8Address& b);
144 friend bool operator==(const Mac8Address& a, const Mac8Address& b);
145 friend bool operator!=(const Mac8Address& a, const Mac8Address& b);
146 friend std::ostream& operator<<(std::ostream& os, const Mac8Address& address);
147 friend std::istream& operator>>(std::istream& is, Mac8Address& address);
148
149}; // class Mac8Address
150
151/**
152 * Address comparison, less than.
153 *
154 * \param a First address to compare.
155 * \param b Second address to compare.
156 * \return True if a < b.
157 */
158bool operator<(const Mac8Address& a, const Mac8Address& b);
159
160/**
161 * Address comparison, equality.
162 *
163 * \param a First address to compare.
164 * \param b Second address to compare.
165 * \return True if a == b.
166 */
167bool operator==(const Mac8Address& a, const Mac8Address& b);
168
169/**
170 * Address comparison, unequal.
171 *
172 * \param a First address to compare.
173 * \param b Second address to compare.
174 * \return True if a != b.
175 */
176bool operator!=(const Mac8Address& a, const Mac8Address& b);
177
178/**
179 * Write \pname{address} to stream \pname{os} as 8 bit integer.
180 *
181 * \param os The output stream.
182 * \param address The address
183 * \return The output stream.
184 */
185std::ostream& operator<<(std::ostream& os, const Mac8Address& address);
186
187/**
188 * Read \pname{address} from stream \pname{is} as 8 bit integer.
189 *
190 * \param is The input stream.
191 * \param address The address variable to set.
192 * \return The input stream.
193 */
194std::istream& operator>>(std::istream& is, Mac8Address& address);
195
196} // namespace ns3
197
198#endif /* MAC8_ADDRESS_H */
a polymophic address class
Definition: address.h:101
A class used for addressing MAC8 MAC's.
Definition: mac8-address.h:44
friend bool operator<(const Mac8Address &a, const Mac8Address &b)
Address comparison, less than.
static Mac8Address GetBroadcast()
Get the broadcast address (255).
Definition: mac8-address.cc:88
static Mac8Address ConvertFrom(const Address &address)
Convert a generic address to a Mac8Address.
Definition: mac8-address.cc:56
friend std::ostream & operator<<(std::ostream &os, const Mac8Address &address)
Write address to stream os as 8 bit integer.
static void ResetAllocationIndex()
Reset the Mac8Address allocation index.
Address ConvertTo() const
Convert to a generic Address.
Definition: mac8-address.cc:50
static bool IsMatchingType(const Address &address)
Check that a generic Address is compatible with Mac8Address.
Definition: mac8-address.cc:65
static uint8_t GetType()
Get the Mac8Address type.
Definition: mac8-address.cc:43
uint8_t m_address
The address.
Definition: mac8-address.h:134
Mac8Address()=default
static uint8_t m_allocationIndex
Address allocation index.
Definition: mac8-address.h:133
friend std::istream & operator>>(std::istream &is, Mac8Address &address)
Read address from stream is as 8 bit integer.
void CopyTo(uint8_t *pBuffer) const
Writes address to buffer parameter.
Definition: mac8-address.cc:82
static Mac8Address Allocate()
Allocates Mac8Address from 0-254.
Definition: mac8-address.cc:94
friend bool operator==(const Mac8Address &a, const Mac8Address &b)
Address comparison, equality.
friend bool operator!=(const Mac8Address &a, const Mac8Address &b)
Address comparison, unequal.
void CopyFrom(const uint8_t *pBuffer)
Sets address to address stored in parameter.
Definition: mac8-address.cc:76
virtual ~Mac8Address()
Destructor.
Definition: mac8-address.cc:38
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool operator!=(Callback< R, Args... > a, Callback< R, Args... > b)
Inequality test.
Definition: callback.h:680
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.h:157
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:159
std::istream & operator>>(std::istream &is, Angles &a)
Definition: angles.cc:183
bool operator<(const EventId &a, const EventId &b)
Definition: event-id.h:170