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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 */
8#ifndef MAC48_ADDRESS_H
9#define MAC48_ADDRESS_H
10
11#include "ipv4-address.h"
12#include "ipv6-address.h"
13
14#include "ns3/attribute-helper.h"
15#include "ns3/attribute.h"
16
17#include <ostream>
18#include <stdint.h>
19
20namespace ns3
21{
22
23class Address;
24
25/**
26 * \ingroup address
27 *
28 * \brief an EUI-48 address
29 *
30 * This class can contain 48 bit IEEE addresses.
31 *
32 * \see attribute_Mac48Address
33 */
35{
36 public:
37 Mac48Address() = default;
38 /**
39 * \param str a string representing the new Mac48Address
40 *
41 * The format of the string is "xx:xx:xx:xx:xx:xx"
42 */
43 Mac48Address(const char* str);
44
45 /**
46 * \param buffer address in network order
47 *
48 * Copy the input address to our internal buffer.
49 */
50 void CopyFrom(const uint8_t buffer[6]);
51 /**
52 * \param buffer address in network order
53 *
54 * Copy the internal address to the input buffer.
55 */
56 void CopyTo(uint8_t buffer[6]) const;
57
58 /**
59 * \returns a new Address instance
60 *
61 * Convert an instance of this class to a polymorphic Address instance.
62 */
63 operator Address() const;
64 /**
65 * \param address a polymorphic address
66 * \returns a new Mac48Address from the polymorphic address
67 *
68 * This function performs a type check and asserts if the
69 * type of the input address is not compatible with an
70 * Mac48Address.
71 */
72 static Mac48Address ConvertFrom(const Address& address);
73 /**
74 * \returns a new Address instance
75 *
76 * Convert an instance of this class to a polymorphic Address instance.
77 */
78 Address ConvertTo() const;
79
80 /**
81 * \param address address to test
82 * \returns true if the address matches, false otherwise.
83 */
84 static bool IsMatchingType(const Address& address);
85 /**
86 * Allocate a new Mac48Address.
87 * \returns newly allocated mac48Address
88 */
89 static Mac48Address Allocate();
90
91 /**
92 * Reset the Mac48Address allocation index.
93 *
94 * This function resets (to zero) the global integer
95 * that is used for unique address allocation.
96 * It is automatically called whenever
97 * \code
98 * SimulatorDestroy ();
99 * \endcode
100 * is called. It may also be optionally called
101 * by user code if there is a need to force a reset
102 * of this allocation index.
103 */
104 static void ResetAllocationIndex();
105
106 /**
107 * \returns true if this is a broadcast address, false otherwise.
108 */
109 bool IsBroadcast() const;
110
111 /**
112 * \returns true if the group bit is set, false otherwise.
113 */
114 bool IsGroup() const;
115
116 /**
117 * \returns the broadcast address
118 */
119 static Mac48Address GetBroadcast();
120
121 /**
122 * \param address base IPv4 address
123 * \returns a multicast address
124 */
125 static Mac48Address GetMulticast(Ipv4Address address);
126
127 /**
128 * \brief Get multicast address from IPv6 address.
129 * \param address base IPv6 address
130 * \returns a multicast address
131 */
132 static Mac48Address GetMulticast(Ipv6Address address);
133
134 /**
135 * \returns the multicast prefix (01:00:5e:00:00:00).
136 */
138
139 /**
140 * \brief Get the multicast prefix for IPv6 (33:33:00:00:00:00).
141 * \returns a multicast address.
142 */
144
145 /**
146 * TracedCallback signature for Mac48Address
147 *
148 * \param [in] value Current value of the Mac48Address
149 */
150 typedef void (*TracedCallback)(Mac48Address value);
151
152 private:
153 /**
154 * \brief Return the Type of address.
155 * \return type of address
156 */
157 static uint8_t GetType();
158
159 /**
160 * \brief Equal to operator.
161 *
162 * \param a the first operand
163 * \param b the first operand
164 * \returns true if the operands are equal
165 */
166 friend bool operator==(const Mac48Address& a, const Mac48Address& b);
167
168 /**
169 * \brief Not equal to operator.
170 *
171 * \param a the first operand
172 * \param b the first operand
173 * \returns true if the operands are not equal
174 */
175 friend bool operator!=(const Mac48Address& a, const Mac48Address& b);
176
177 /**
178 * \brief Less than operator.
179 *
180 * \param a the first operand
181 * \param b the first operand
182 * \returns true if the operand a is less than operand b
183 */
184 friend bool operator<(const Mac48Address& a, const Mac48Address& b);
185
186 /**
187 * \brief Stream insertion operator.
188 *
189 * \param os the stream
190 * \param address the address
191 * \returns a reference to the stream
192 */
193 friend std::ostream& operator<<(std::ostream& os, const Mac48Address& address);
194
195 /**
196 * \brief Stream extraction operator.
197 *
198 * \param is the stream
199 * \param address the address
200 * \returns a reference to the stream
201 */
202 friend std::istream& operator>>(std::istream& is, Mac48Address& address);
203
204 static uint64_t m_allocationIndex; //!< Address allocation index
205 uint8_t m_address[6]{0}; //!< Address value
206};
207
209
210inline bool
212{
213 return memcmp(a.m_address, b.m_address, 6) == 0;
214}
215
216inline bool
218{
219 return memcmp(a.m_address, b.m_address, 6) != 0;
220}
221
222inline bool
223operator<(const Mac48Address& a, const Mac48Address& b)
224{
225 return memcmp(a.m_address, b.m_address, 6) < 0;
226}
227
228std::ostream& operator<<(std::ostream& os, const Mac48Address& address);
229std::istream& operator>>(std::istream& is, Mac48Address& address);
230
231} // namespace ns3
232
233#endif /* MAC48_ADDRESS_H */
a polymophic address class
Definition address.h:90
Ipv4 addresses are stored in host order in this class.
Describes an IPv6 address.
an EUI-48 address
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:658
bool operator==(const EventId &a, const EventId &b)
Definition event-id.h:155
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition angles.cc:148
std::istream & operator>>(std::istream &is, Angles &a)
Definition angles.cc:172
bool operator<(const EventId &a, const EventId &b)
Definition event-id.h:168