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 <ostream>
18#include <stdint.h>
19
20namespace ns3
21{
22
23class Address;
24
25/**
26 * @ingroup address
27 *
28 * @brief an EUI-64 address
29 *
30 * This class can contain 64 bit IEEE addresses.
31 *
32 * @see attribute_Mac64Address
33 */
35{
36 public:
37 Mac64Address() = default;
38 /**
39 * @param str a string representing the new Mac64Address
40 *
41 * The format of the string is "xx:xx:xx:xx:xx:xx:xx:xx"
42 */
43 Mac64Address(const char* str);
44
45 /**
46 * @param addr The 64 bit unsigned integer used to create a Mac64Address object.
47 *
48 * Create a Mac64Address from an 64 bit unsigned integer.
49 */
50 Mac64Address(uint64_t addr);
51
52 /**
53 * @param buffer address in network order
54 *
55 * Copy the input address to our internal buffer.
56 */
57 void CopyFrom(const uint8_t buffer[8]);
58 /**
59 * @param buffer address in network order
60 *
61 * Copy the internal address to the input buffer.
62 */
63 void CopyTo(uint8_t buffer[8]) const;
64 /**
65 * @returns a new Address instance
66 *
67 * Convert an instance of this class to a polymorphic Address instance.
68 */
69 operator Address() const;
70 /**
71 * @param address a polymorphic address
72 * @returns a new Mac64Address from the polymorphic address
73 *
74 * This function performs a type check and asserts if the
75 * type of the input address is not compatible with an
76 * Mac64Address.
77 */
78 static Mac64Address ConvertFrom(const Address& address);
79 /**
80 * @returns a new Address instance
81 *
82 * Convert an instance of this class to a polymorphic Address instance.
83 */
84 Address ConvertTo() const;
85
86 /**
87 * @return the mac address in a 64 bit unsigned integer.
88 *
89 * Convert an instance of this class to a 64 bit unsigned integer.
90 */
91 uint64_t ConvertToInt() const;
92
93 /**
94 * @param address address to test
95 * @returns true if the address matches, false otherwise.
96 */
97 static bool IsMatchingType(const Address& address);
98 /**
99 * Allocate a new Mac64Address.
100 * @returns newly allocated mac64Address
101 */
102 static Mac64Address Allocate();
103
104 /**
105 * Reset the Mac64Address allocation index.
106 *
107 * This function resets (to zero) the global integer
108 * that is used for unique address allocation.
109 * It is automatically called whenever
110 * @code
111 * SimulatorDestroy ();
112 * @endcode
113 * is called. It may also be optionally called
114 * by user code if there is a need to force a reset
115 * of this allocation index.
116 */
117 static void ResetAllocationIndex();
118
119 private:
120 /**
121 * @brief Return the Type of address.
122 * @return type of address
123 */
124 static uint8_t GetType();
125
126 /**
127 * @brief Equal to operator.
128 *
129 * @param a the first operand
130 * @param b the first operand
131 * @returns true if the operands are equal
132 */
133 friend bool operator==(const Mac64Address& a, const Mac64Address& b);
134
135 /**
136 * @brief Not equal to operator.
137 *
138 * @param a the first operand
139 * @param b the first operand
140 * @returns true if the operands are not equal
141 */
142 friend bool operator!=(const Mac64Address& a, const Mac64Address& b);
143
144 /**
145 * @brief Less than operator.
146 *
147 * @param a the first operand
148 * @param b the first operand
149 * @returns true if the operand a is less than operand b
150 */
151 friend bool operator<(const Mac64Address& a, const Mac64Address& b);
152
153 /**
154 * @brief Stream insertion operator.
155 *
156 * @param os the stream
157 * @param address the address
158 * @returns a reference to the stream
159 */
160 friend std::ostream& operator<<(std::ostream& os, const Mac64Address& address);
161
162 /**
163 * @brief Stream extraction operator.
164 *
165 * @param is the stream
166 * @param address the address
167 * @returns a reference to the stream
168 */
169 friend std::istream& operator>>(std::istream& is, Mac64Address& address);
170
171 static uint64_t m_allocationIndex; //!< Address allocation index
172 uint8_t m_address[8]{0}; //!< Address value
173};
174
175/**
176 * @class ns3::Mac64AddressValue
177 * @brief hold objects of type ns3::Mac64Address
178 */
179
181
182inline bool
184{
185 return memcmp(a.m_address, b.m_address, 8) == 0;
186}
187
188inline bool
190{
191 return memcmp(a.m_address, b.m_address, 8) != 0;
192}
193
194inline bool
195operator<(const Mac64Address& a, const Mac64Address& b)
196{
197 return memcmp(a.m_address, b.m_address, 8) < 0;
198}
199
200std::ostream& operator<<(std::ostream& os, const Mac64Address& address);
201std::istream& operator>>(std::istream& is, Mac64Address& address);
202
203} // namespace ns3
204
205#endif /* MAC64_ADDRESS_H */
a polymophic address class
Definition address.h:90
an EUI-64 address
friend std::istream & operator>>(std::istream &is, Mac64Address &address)
Stream extraction operator.
uint8_t m_address[8]
Address value.
friend std::ostream & operator<<(std::ostream &os, const Mac64Address &address)
Stream insertion operator.
Address ConvertTo() const
uint64_t ConvertToInt() const
static bool IsMatchingType(const Address &address)
static Mac64Address Allocate()
Allocate a new Mac64Address.
void CopyFrom(const uint8_t buffer[8])
friend bool operator!=(const Mac64Address &a, const Mac64Address &b)
Not equal to operator.
friend bool operator==(const Mac64Address &a, const Mac64Address &b)
Equal to 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
friend bool operator<(const Mac64Address &a, const Mac64Address &b)
Less than operator.
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.
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