A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
mac64-address.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007 INRIA
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18 */
19#ifndef MAC64_ADDRESS_H
20#define MAC64_ADDRESS_H
21
22#include "ipv4-address.h"
23#include "ipv6-address.h"
24
25#include "ns3/attribute-helper.h"
26#include "ns3/attribute.h"
27
28#include <ostream>
29#include <stdint.h>
30
31namespace ns3
32{
33
34class Address;
35
36/**
37 * \ingroup address
38 *
39 * \brief an EUI-64 address
40 *
41 * This class can contain 64 bit IEEE addresses.
42 *
43 * \see attribute_Mac64Address
44 */
46{
47 public:
48 Mac64Address() = default;
49 /**
50 * \param str a string representing the new Mac64Address
51 *
52 * The format of the string is "xx:xx:xx:xx:xx:xx:xx:xx"
53 */
54 Mac64Address(const char* str);
55
56 /**
57 * \param addr The 64 bit unsigned integer used to create a Mac64Address object.
58 *
59 * Create a Mac64Address from an 64 bit unsigned integer.
60 */
61 Mac64Address(uint64_t addr);
62
63 /**
64 * \param buffer address in network order
65 *
66 * Copy the input address to our internal buffer.
67 */
68 void CopyFrom(const uint8_t buffer[8]);
69 /**
70 * \param buffer address in network order
71 *
72 * Copy the internal address to the input buffer.
73 */
74 void CopyTo(uint8_t buffer[8]) const;
75 /**
76 * \returns a new Address instance
77 *
78 * Convert an instance of this class to a polymorphic Address instance.
79 */
80 operator Address() const;
81 /**
82 * \param address a polymorphic address
83 * \returns a new Mac64Address from the polymorphic address
84 *
85 * This function performs a type check and asserts if the
86 * type of the input address is not compatible with an
87 * Mac64Address.
88 */
89 static Mac64Address ConvertFrom(const Address& address);
90 /**
91 * \returns a new Address instance
92 *
93 * Convert an instance of this class to a polymorphic Address instance.
94 */
95 Address ConvertTo() const;
96
97 /**
98 * \return the mac address in a 64 bit unsigned integer.
99 *
100 * Convert an instance of this class to a 64 bit unsigned integer.
101 */
102 uint64_t ConvertToInt() const;
103
104 /**
105 * \param address address to test
106 * \returns true if the address matches, false otherwise.
107 */
108 static bool IsMatchingType(const Address& address);
109 /**
110 * Allocate a new Mac64Address.
111 * \returns newly allocated mac64Address
112 */
113 static Mac64Address Allocate();
114
115 /**
116 * Reset the Mac64Address allocation index.
117 *
118 * This function resets (to zero) the global integer
119 * that is used for unique address allocation.
120 * It is automatically called whenever
121 * \code
122 * SimulatorDestroy ();
123 * \endcode
124 * is called. It may also be optionally called
125 * by user code if there is a need to force a reset
126 * of this allocation index.
127 */
128 static void ResetAllocationIndex();
129
130 private:
131 /**
132 * \brief Return the Type of address.
133 * \return type of address
134 */
135 static uint8_t GetType();
136
137 /**
138 * \brief Equal to operator.
139 *
140 * \param a the first operand
141 * \param b the first operand
142 * \returns true if the operands are equal
143 */
144 friend bool operator==(const Mac64Address& a, const Mac64Address& b);
145
146 /**
147 * \brief Not equal to operator.
148 *
149 * \param a the first operand
150 * \param b the first operand
151 * \returns true if the operands are not equal
152 */
153 friend bool operator!=(const Mac64Address& a, const Mac64Address& b);
154
155 /**
156 * \brief Less than operator.
157 *
158 * \param a the first operand
159 * \param b the first operand
160 * \returns true if the operand a is less than operand b
161 */
162 friend bool operator<(const Mac64Address& a, const Mac64Address& b);
163
164 /**
165 * \brief Stream insertion operator.
166 *
167 * \param os the stream
168 * \param address the address
169 * \returns a reference to the stream
170 */
171 friend std::ostream& operator<<(std::ostream& os, const Mac64Address& address);
172
173 /**
174 * \brief Stream extraction operator.
175 *
176 * \param is the stream
177 * \param address the address
178 * \returns a reference to the stream
179 */
180 friend std::istream& operator>>(std::istream& is, Mac64Address& address);
181
182 static uint64_t m_allocationIndex; //!< Address allocation index
183 uint8_t m_address[8]{0}; //!< Address value
184};
185
186/**
187 * \class ns3::Mac64AddressValue
188 * \brief hold objects of type ns3::Mac64Address
189 */
190
192
193inline bool
195{
196 return memcmp(a.m_address, b.m_address, 8) == 0;
197}
198
199inline bool
201{
202 return memcmp(a.m_address, b.m_address, 8) != 0;
203}
204
205inline bool
206operator<(const Mac64Address& a, const Mac64Address& b)
207{
208 return memcmp(a.m_address, b.m_address, 8) < 0;
209}
210
211std::ostream& operator<<(std::ostream& os, const Mac64Address& address);
212std::istream& operator>>(std::istream& is, Mac64Address& address);
213
214} // namespace ns3
215
216#endif /* MAC64_ADDRESS_H */
a polymophic address class
Definition: address.h:101
an EUI-64 address
Definition: mac64-address.h:46
friend std::istream & operator>>(std::istream &is, Mac64Address &address)
Stream extraction operator.
uint8_t m_address[8]
Address value.
friend std::ostream & operator<<(std::ostream &os, const Mac64Address &address)
Stream insertion operator.
Address ConvertTo() const
uint64_t ConvertToInt() const
static bool IsMatchingType(const Address &address)
static Mac64Address Allocate()
Allocate a new Mac64Address.
void CopyFrom(const uint8_t buffer[8])
friend bool operator!=(const Mac64Address &a, const Mac64Address &b)
Not equal to operator.
friend bool operator==(const Mac64Address &a, const Mac64Address &b)
Equal to operator.
void CopyTo(uint8_t buffer[8]) const
static Mac64Address ConvertFrom(const Address &address)
static void ResetAllocationIndex()
Reset the Mac64Address allocation index.
static uint8_t GetType()
Return the Type of address.
Mac64Address()=default
friend bool operator<(const Mac64Address &a, const Mac64Address &b)
Less than operator.
static uint64_t m_allocationIndex
Address allocation index.
#define ATTRIBUTE_HELPER_HEADER(type)
Declare the attribute value, accessor and checkers for class type
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