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 static Mac48Address ConvertFrom(const Address& address);
75 /**
76 * @returns a new Address instance
77 *
78 * Convert an instance of this class to a polymorphic Address instance.
79 */
80 Address ConvertTo() const;
81
82 /**
83 * @param address address to test
84 * @returns true if the address matches, false otherwise.
85 */
86 static bool IsMatchingType(const Address& address);
87 /**
88 * Allocate a new Mac48Address.
89 * @returns newly allocated mac48Address
90 */
91 static Mac48Address Allocate();
92
93 /**
94 * Reset the Mac48Address allocation index.
95 *
96 * This function resets (to zero) the global integer
97 * that is used for unique address allocation.
98 * It is automatically called whenever
99 * @code
100 * SimulatorDestroy ();
101 * @endcode
102 * is called. It may also be optionally called
103 * by user code if there is a need to force a reset
104 * of this allocation index.
105 */
106 static void ResetAllocationIndex();
107
108 /**
109 * @returns true if this is a broadcast address, false otherwise.
110 */
111 bool IsBroadcast() const;
112
113 /**
114 * @returns true if the group bit is set, false otherwise.
115 */
116 bool IsGroup() const;
117
118 /**
119 * @returns the broadcast address
120 */
121 static Mac48Address GetBroadcast();
122
123 /**
124 * @param address base IPv4 address
125 * @returns a multicast address
126 */
127 static Mac48Address GetMulticast(Ipv4Address address);
128
129 /**
130 * @brief Get multicast address from IPv6 address.
131 * @param address base IPv6 address
132 * @returns a multicast address
133 */
134 static Mac48Address GetMulticast(Ipv6Address address);
135
136 /**
137 * @returns the multicast prefix (01:00:5e:00:00:00).
138 */
140
141 /**
142 * @brief Get the multicast prefix for IPv6 (33:33:00:00:00:00).
143 * @returns a multicast address.
144 */
146
147 /**
148 * TracedCallback signature for Mac48Address
149 *
150 * @param [in] value Current value of the Mac48Address
151 */
152 typedef void (*TracedCallback)(Mac48Address value);
153
154 /**
155 * Spaceship comparison operator. All the other comparison operators
156 * are automatically generated from this one.
157 *
158 * @param other address to compare to this one
159 * @returns The result of the comparison.
160 */
161 constexpr std::strong_ordering operator<=>(const Mac48Address& other) const = default;
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 Stream insertion operator.
172 *
173 * @param os the stream
174 * @param address the address
175 * @returns a reference to the stream
176 */
177 friend std::ostream& operator<<(std::ostream& os, const Mac48Address& address);
178
179 /**
180 * @brief Stream extraction operator.
181 *
182 * @param is the stream
183 * @param address the address
184 * @returns a reference to the stream
185 */
186 friend std::istream& operator>>(std::istream& is, Mac48Address& address);
187
188 static uint64_t m_allocationIndex; //!< Address allocation index
189 std::array<uint8_t, 6> m_address{}; //!< Address value
190};
191
193
194std::ostream& operator<<(std::ostream& os, const Mac48Address& address);
195std::istream& operator>>(std::istream& is, Mac48Address& address);
196
197} // namespace ns3
198
199#endif /* MAC48_ADDRESS_H */
a polymophic address class
Definition address.h:111
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