A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
mac48-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 MAC48_ADDRESS_H
20#define MAC48_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-48 address
40 *
41 * This class can contain 48 bit IEEE addresses.
42 *
43 * \see attribute_Mac48Address
44 */
46{
47 public:
48 Mac48Address() = default;
49 /**
50 * \param str a string representing the new Mac48Address
51 *
52 * The format of the string is "xx:xx:xx:xx:xx:xx"
53 */
54 Mac48Address(const char* str);
55
56 /**
57 * \param buffer address in network order
58 *
59 * Copy the input address to our internal buffer.
60 */
61 void CopyFrom(const uint8_t buffer[6]);
62 /**
63 * \param buffer address in network order
64 *
65 * Copy the internal address to the input buffer.
66 */
67 void CopyTo(uint8_t buffer[6]) const;
68
69 /**
70 * \returns a new Address instance
71 *
72 * Convert an instance of this class to a polymorphic Address instance.
73 */
74 operator Address() const;
75 /**
76 * \param address a polymorphic address
77 * \returns a new Mac48Address from the polymorphic address
78 *
79 * This function performs a type check and asserts if the
80 * type of the input address is not compatible with an
81 * Mac48Address.
82 */
83 static Mac48Address ConvertFrom(const Address& address);
84 /**
85 * \returns a new Address instance
86 *
87 * Convert an instance of this class to a polymorphic Address instance.
88 */
89 Address ConvertTo() const;
90
91 /**
92 * \param address address to test
93 * \returns true if the address matches, false otherwise.
94 */
95 static bool IsMatchingType(const Address& address);
96 /**
97 * Allocate a new Mac48Address.
98 * \returns newly allocated mac48Address
99 */
100 static Mac48Address Allocate();
101
102 /**
103 * Reset the Mac48Address allocation index.
104 *
105 * This function resets (to zero) the global integer
106 * that is used for unique address allocation.
107 * It is automatically called whenever
108 * \code
109 * SimulatorDestroy ();
110 * \endcode
111 * is called. It may also be optionally called
112 * by user code if there is a need to force a reset
113 * of this allocation index.
114 */
115 static void ResetAllocationIndex();
116
117 /**
118 * \returns true if this is a broadcast address, false otherwise.
119 */
120 bool IsBroadcast() const;
121
122 /**
123 * \returns true if the group bit is set, false otherwise.
124 */
125 bool IsGroup() const;
126
127 /**
128 * \returns the broadcast address
129 */
130 static Mac48Address GetBroadcast();
131
132 /**
133 * \param address base IPv4 address
134 * \returns a multicast address
135 */
136 static Mac48Address GetMulticast(Ipv4Address address);
137
138 /**
139 * \brief Get multicast address from IPv6 address.
140 * \param address base IPv6 address
141 * \returns a multicast address
142 */
143 static Mac48Address GetMulticast(Ipv6Address address);
144
145 /**
146 * \returns the multicast prefix (01:00:5e:00:00:00).
147 */
149
150 /**
151 * \brief Get the multicast prefix for IPv6 (33:33:00:00:00:00).
152 * \returns a multicast address.
153 */
155
156 /**
157 * TracedCallback signature for Mac48Address
158 *
159 * \param [in] value Current value of the Mac48Address
160 */
161 typedef void (*TracedCallback)(Mac48Address value);
162
163 private:
164 /**
165 * \brief Return the Type of address.
166 * \return type of address
167 */
168 static uint8_t GetType();
169
170 /**
171 * \brief Equal to operator.
172 *
173 * \param a the first operand
174 * \param b the first operand
175 * \returns true if the operands are equal
176 */
177 friend bool operator==(const Mac48Address& a, const Mac48Address& b);
178
179 /**
180 * \brief Not equal to operator.
181 *
182 * \param a the first operand
183 * \param b the first operand
184 * \returns true if the operands are not equal
185 */
186 friend bool operator!=(const Mac48Address& a, const Mac48Address& b);
187
188 /**
189 * \brief Less than operator.
190 *
191 * \param a the first operand
192 * \param b the first operand
193 * \returns true if the operand a is less than operand b
194 */
195 friend bool operator<(const Mac48Address& a, const Mac48Address& b);
196
197 /**
198 * \brief Stream insertion operator.
199 *
200 * \param os the stream
201 * \param address the address
202 * \returns a reference to the stream
203 */
204 friend std::ostream& operator<<(std::ostream& os, const Mac48Address& address);
205
206 /**
207 * \brief Stream extraction operator.
208 *
209 * \param is the stream
210 * \param address the address
211 * \returns a reference to the stream
212 */
213 friend std::istream& operator>>(std::istream& is, Mac48Address& address);
214
215 static uint64_t m_allocationIndex; //!< Address allocation index
216 uint8_t m_address[6]{0}; //!< Address value
217};
218
220
221inline bool
223{
224 return memcmp(a.m_address, b.m_address, 6) == 0;
225}
226
227inline bool
229{
230 return memcmp(a.m_address, b.m_address, 6) != 0;
231}
232
233inline bool
234operator<(const Mac48Address& a, const Mac48Address& b)
235{
236 return memcmp(a.m_address, b.m_address, 6) < 0;
237}
238
239std::ostream& operator<<(std::ostream& os, const Mac48Address& address);
240std::istream& operator>>(std::istream& is, Mac48Address& address);
241
242} // namespace ns3
243
244#endif /* MAC48_ADDRESS_H */
a polymophic address class
Definition: address.h:101
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
Describes an IPv6 address.
Definition: ipv6-address.h:49
an EUI-48 address
Definition: mac48-address.h:46
static Mac48Address GetMulticast(Ipv4Address address)
friend std::ostream & operator<<(std::ostream &os, const Mac48Address &address)
Stream insertion operator.
static void ResetAllocationIndex()
Reset the Mac48Address allocation index.
Mac48Address()=default
bool IsGroup() const
static bool IsMatchingType(const Address &address)
void CopyFrom(const uint8_t buffer[6])
friend bool operator<(const Mac48Address &a, const Mac48Address &b)
Less than operator.
friend bool operator!=(const Mac48Address &a, const Mac48Address &b)
Not equal to operator.
static uint8_t GetType()
Return the Type of address.
static Mac48Address ConvertFrom(const Address &address)
uint8_t m_address[6]
Address value.
static Mac48Address GetBroadcast()
static Mac48Address Allocate()
Allocate a new Mac48Address.
static Mac48Address GetMulticast6Prefix()
Get the multicast prefix for IPv6 (33:33:00:00:00:00).
friend bool operator==(const Mac48Address &a, const Mac48Address &b)
Equal to operator.
void CopyTo(uint8_t buffer[6]) const
static Mac48Address GetMulticastPrefix()
static uint64_t m_allocationIndex
Address allocation index.
friend std::istream & operator>>(std::istream &is, Mac48Address &address)
Stream extraction operator.
Address ConvertTo() const
bool IsBroadcast() const
Forward calls to a chain of Callback.
#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