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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 */
8#ifndef MAC64_ADDRESS_H
9#define MAC64_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-64 address
31 *
32 * This class can contain 64 bit IEEE addresses.
33 *
34 * @see attribute_Mac64Address
35 */
37{
38 public:
39 /// Address length when converted to an Address [bytes].
40 static constexpr uint8_t ADDRESS_LENGTH = 8;
41
42 Mac64Address() = default;
43 /**
44 * @param str a string representing the new Mac64Address
45 *
46 * The format of the string is "xx:xx:xx:xx:xx:xx:xx:xx"
47 */
48 Mac64Address(const char* str);
49
50 /**
51 * @param addr The 64 bit unsigned integer used to create a Mac64Address object.
52 *
53 * Create a Mac64Address from an 64 bit unsigned integer.
54 */
55 Mac64Address(uint64_t addr);
56
57 /**
58 * @param buffer address in network order
59 *
60 * Copy the input address to our internal buffer.
61 */
62 void CopyFrom(const uint8_t buffer[ADDRESS_LENGTH]);
63 /**
64 * @param buffer address in network order
65 *
66 * Copy the internal address to the input buffer.
67 */
68 void CopyTo(uint8_t buffer[ADDRESS_LENGTH]) const;
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 Mac64Address 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 * Mac64Address.
82 */
83 static Mac64Address 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 * @return the mac address in a 64 bit unsigned integer.
93 *
94 * Convert an instance of this class to a 64 bit unsigned integer.
95 */
96 uint64_t ConvertToInt() const;
97
98 /**
99 * @param address address to test
100 * @returns true if the address matches, false otherwise.
101 */
102 static bool IsMatchingType(const Address& address);
103 /**
104 * Allocate a new Mac64Address.
105 * @returns newly allocated mac64Address
106 */
107 static Mac64Address Allocate();
108
109 /**
110 * Reset the Mac64Address allocation index.
111 *
112 * This function resets (to zero) the global integer
113 * that is used for unique address allocation.
114 * It is automatically called whenever
115 * @code
116 * SimulatorDestroy ();
117 * @endcode
118 * is called. It may also be optionally called
119 * by user code if there is a need to force a reset
120 * of this allocation index.
121 */
122 static void ResetAllocationIndex();
123
124 /**
125 * Spaceship comparison operator. All the other comparison operators
126 * are automatically generated from this one.
127 *
128 * @param other address to compare to this one
129 * @returns The result of the comparison.
130 */
131 constexpr std::strong_ordering operator<=>(const Mac64Address& other) const = default;
132
133 private:
134 /**
135 * @brief Return the Type of address.
136 * @return type of address
137 */
138 static uint8_t GetType();
139
140 /**
141 * @brief Stream insertion operator.
142 *
143 * @param os the stream
144 * @param address the address
145 * @returns a reference to the stream
146 */
147 friend std::ostream& operator<<(std::ostream& os, const Mac64Address& address);
148
149 /**
150 * @brief Stream extraction operator.
151 *
152 * @param is the stream
153 * @param address the address
154 * @returns a reference to the stream
155 */
156 friend std::istream& operator>>(std::istream& is, Mac64Address& address);
157
158 static uint64_t m_allocationIndex; //!< Address allocation index
159 std::array<uint8_t, ADDRESS_LENGTH> m_address{}; //!< Address value
160};
161
162/**
163 * @class ns3::Mac64AddressValue
164 * @brief hold objects of type ns3::Mac64Address
165 */
166
168
169std::ostream& operator<<(std::ostream& os, const Mac64Address& address);
170std::istream& operator>>(std::istream& is, Mac64Address& address);
171
172} // namespace ns3
173
174#endif /* MAC64_ADDRESS_H */
a polymophic address class
Definition address.h:114
an EUI-64 address
friend std::istream & operator>>(std::istream &is, Mac64Address &address)
Stream extraction operator.
friend std::ostream & operator<<(std::ostream &os, const Mac64Address &address)
Stream insertion operator.
Address ConvertTo() const
static constexpr uint8_t ADDRESS_LENGTH
Address length when converted to an Address [bytes].
uint64_t ConvertToInt() const
static bool IsMatchingType(const Address &address)
static Mac64Address Allocate()
Allocate a new Mac64Address.
constexpr std::strong_ordering operator<=>(const Mac64Address &other) const =default
Spaceship comparison operator.
std::array< uint8_t, ADDRESS_LENGTH > m_address
Address value.
void CopyFrom(const uint8_t buffer[ADDRESS_LENGTH])
static Mac64Address ConvertFrom(const Address &address)
static void ResetAllocationIndex()
Reset the Mac64Address allocation index.
void CopyTo(uint8_t buffer[ADDRESS_LENGTH]) const
static uint8_t GetType()
Return the Type of address.
Mac64Address()=default
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.
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