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 Mac64Address() = default;
40 /**
41 * @param str a string representing the new Mac64Address
42 *
43 * The format of the string is "xx:xx:xx:xx:xx:xx:xx:xx"
44 */
45 Mac64Address(const char* str);
46
47 /**
48 * @param addr The 64 bit unsigned integer used to create a Mac64Address object.
49 *
50 * Create a Mac64Address from an 64 bit unsigned integer.
51 */
52 Mac64Address(uint64_t addr);
53
54 /**
55 * @param buffer address in network order
56 *
57 * Copy the input address to our internal buffer.
58 */
59 void CopyFrom(const uint8_t buffer[8]);
60 /**
61 * @param buffer address in network order
62 *
63 * Copy the internal address to the input buffer.
64 */
65 void CopyTo(uint8_t buffer[8]) const;
66 /**
67 * @returns a new Address instance
68 *
69 * Convert an instance of this class to a polymorphic Address instance.
70 */
71 operator Address() const;
72 /**
73 * @param address a polymorphic address
74 * @returns a new Mac64Address from the polymorphic address
75 *
76 * This function performs a type check and asserts if the
77 * type of the input address is not compatible with an
78 * Mac64Address.
79 */
80 static Mac64Address ConvertFrom(const Address& address);
81 /**
82 * @returns a new Address instance
83 *
84 * Convert an instance of this class to a polymorphic Address instance.
85 */
86 Address ConvertTo() const;
87
88 /**
89 * @return the mac address in a 64 bit unsigned integer.
90 *
91 * Convert an instance of this class to a 64 bit unsigned integer.
92 */
93 uint64_t ConvertToInt() const;
94
95 /**
96 * @param address address to test
97 * @returns true if the address matches, false otherwise.
98 */
99 static bool IsMatchingType(const Address& address);
100 /**
101 * Allocate a new Mac64Address.
102 * @returns newly allocated mac64Address
103 */
104 static Mac64Address Allocate();
105
106 /**
107 * Reset the Mac64Address allocation index.
108 *
109 * This function resets (to zero) the global integer
110 * that is used for unique address allocation.
111 * It is automatically called whenever
112 * @code
113 * SimulatorDestroy ();
114 * @endcode
115 * is called. It may also be optionally called
116 * by user code if there is a need to force a reset
117 * of this allocation index.
118 */
119 static void ResetAllocationIndex();
120
121 /**
122 * Spaceship comparison operator. All the other comparison operators
123 * are automatically generated from this one.
124 *
125 * @param other address to compare to this one
126 * @returns The result of the comparison.
127 */
128 constexpr std::strong_ordering operator<=>(const Mac64Address& other) const = default;
129
130 private:
131 /**
132 * @brief Return the Type of address.
133 * @return type of address
134 */
135 static uint8_t GetType();
136
137 /**
138 * @brief Stream insertion operator.
139 *
140 * @param os the stream
141 * @param address the address
142 * @returns a reference to the stream
143 */
144 friend std::ostream& operator<<(std::ostream& os, const Mac64Address& address);
145
146 /**
147 * @brief Stream extraction operator.
148 *
149 * @param is the stream
150 * @param address the address
151 * @returns a reference to the stream
152 */
153 friend std::istream& operator>>(std::istream& is, Mac64Address& address);
154
155 static uint64_t m_allocationIndex; //!< Address allocation index
156 std::array<uint8_t, 8> m_address{}; //!< Address value
157};
158
159/**
160 * @class ns3::Mac64AddressValue
161 * @brief hold objects of type ns3::Mac64Address
162 */
163
165
166std::ostream& operator<<(std::ostream& os, const Mac64Address& address);
167std::istream& operator>>(std::istream& is, Mac64Address& address);
168
169} // namespace ns3
170
171#endif /* MAC64_ADDRESS_H */
a polymophic address class
Definition address.h:111
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
std::array< uint8_t, 8 > m_address
Address value.
uint64_t ConvertToInt() const
static bool IsMatchingType(const Address &address)
static Mac64Address Allocate()
Allocate a new Mac64Address.
void CopyFrom(const uint8_t buffer[8])
constexpr std::strong_ordering operator<=>(const Mac64Address &other) const =default
Spaceship comparison operator.
void CopyTo(uint8_t buffer[8]) const
static Mac64Address ConvertFrom(const Address &address)
static void ResetAllocationIndex()
Reset the Mac64Address allocation index.
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