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 <array>
18#include <compare>
19#include <ostream>
20#include <stdint.h>
21
22namespace ns3
23{
24
25class Address;
26
27/**
28 * @ingroup address
29 *
30 * @brief an EUI-48 address
31 *
32 * This class can contain 48 bit IEEE addresses.
33 *
34 * @see attribute_Mac48Address
35 */
37{
38 public:
39 Mac48Address() = default;
40 /**
41 * @param str a string representing the new Mac48Address
42 *
43 * The format of the string is "xx:xx:xx:xx:xx:xx"
44 */
45 Mac48Address(const char* str);
46
47 /**
48 * @param buffer address in network order
49 *
50 * Copy the input address to our internal buffer.
51 */
52 void CopyFrom(const uint8_t buffer[6]);
53 /**
54 * @param buffer address in network order
55 *
56 * Copy the internal address to the input buffer.
57 */
58 void CopyTo(uint8_t buffer[6]) const;
59
60 /**
61 * @returns a new Address instance
62 *
63 * Convert an instance of this class to a polymorphic Address instance.
64 */
65 operator Address() const;
66 /**
67 * @param address a polymorphic address
68 * @returns a new Mac48Address from the polymorphic address
69 *
70 * This function performs a type check and asserts if the
71 * type of the input address is not compatible with an
72 * Mac48Address.
73 *
74 * @hidecaller
75 */
76 static Mac48Address ConvertFrom(const Address& address);
77 /**
78 * @returns a new Address instance
79 *
80 * Convert an instance of this class to a polymorphic Address instance.
81 */
82 Address ConvertTo() const;
83
84 /**
85 * @param address address to test
86 * @returns true if the address matches, false otherwise.
87 */
88 static bool IsMatchingType(const Address& address);
89 /**
90 * Allocate a new Mac48Address.
91 * @returns newly allocated mac48Address
92 */
93 static Mac48Address Allocate();
94
95 /**
96 * Reset the Mac48Address allocation index.
97 *
98 * This function resets (to zero) the global integer
99 * that is used for unique address allocation.
100 * It is automatically called whenever
101 * @code
102 * SimulatorDestroy ();
103 * @endcode
104 * is called. It may also be optionally called
105 * by user code if there is a need to force a reset
106 * of this allocation index.
107 */
108 static void ResetAllocationIndex();
109
110 /**
111 * @returns true if this is a broadcast address, false otherwise.
112 */
113 bool IsBroadcast() const;
114
115 /**
116 * @returns true if the group bit is set, false otherwise.
117 */
118 bool IsGroup() const;
119
120 /**
121 * @returns the broadcast address
122 * @hidecaller
123 */
124 static Mac48Address GetBroadcast();
125
126 /**
127 * @param address base IPv4 address
128 * @returns a multicast address
129 */
130 static Mac48Address GetMulticast(Ipv4Address address);
131
132 /**
133 * @brief Get multicast address from IPv6 address.
134 * @param address base IPv6 address
135 * @returns a multicast address
136 */
137 static Mac48Address GetMulticast(Ipv6Address address);
138
139 /**
140 * @returns the multicast prefix (01:00:5e:00:00:00).
141 */
143
144 /**
145 * @brief Get the multicast prefix for IPv6 (33:33:00:00:00:00).
146 * @returns a multicast address.
147 */
149
150 /**
151 * TracedCallback signature for Mac48Address
152 *
153 * @param [in] value Current value of the Mac48Address
154 */
155 typedef void (*TracedCallback)(Mac48Address value);
156
157 /**
158 * Spaceship comparison operator. All the other comparison operators
159 * are automatically generated from this one.
160 *
161 * @param other address to compare to this one
162 * @returns The result of the comparison.
163 */
164 constexpr std::strong_ordering operator<=>(const Mac48Address& other) const = default;
165
166 private:
167 /**
168 * @brief Return the Type of address.
169 * @return type of address
170 */
171 static uint8_t GetType();
172
173 /**
174 * @brief Stream insertion operator.
175 *
176 * @param os the stream
177 * @param address the address
178 * @returns a reference to the stream
179 */
180 friend std::ostream& operator<<(std::ostream& os, const Mac48Address& address);
181
182 /**
183 * @brief Stream extraction operator.
184 *
185 * @param is the stream
186 * @param address the address
187 * @returns a reference to the stream
188 */
189 friend std::istream& operator>>(std::istream& is, Mac48Address& address);
190
191 static uint64_t m_allocationIndex; //!< Address allocation index
192 std::array<uint8_t, 6> m_address{}; //!< Address value
193};
194
196
197std::ostream& operator<<(std::ostream& os, const Mac48Address& address);
198std::istream& operator>>(std::istream& is, Mac48Address& address);
199
200} // namespace ns3
201
202#endif /* MAC48_ADDRESS_H */
a polymophic address class
Definition address.h:114
Ipv4 addresses are stored in host order in this class.
Describes an IPv6 address.
an EUI-48 address
std::array< uint8_t, 6 > m_address
Address value.
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])
void(* TracedCallback)(Mac48Address value)
TracedCallback signature for Mac48Address.
static uint8_t GetType()
Return the Type of address.
static Mac48Address ConvertFrom(const Address &address)
static Mac48Address GetBroadcast()
constexpr std::strong_ordering operator<=>(const Mac48Address &other) const =default
Spaceship comparison operator.
static Mac48Address Allocate()
Allocate a new Mac48Address.
static Mac48Address GetMulticast6Prefix()
Get the multicast prefix for IPv6 (33:33:00:00:00:00).
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
#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.
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