A Discrete-Event Network Simulator
API
mac48-address.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007 INRIA
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18  */
19 #ifndef MAC48_ADDRESS_H
20 #define MAC48_ADDRESS_H
21 
22 #include "ipv4-address.h"
23 #include "ipv6-address.h"
24 
25 #include "ns3/attribute-helper.h"
26 #include "ns3/attribute.h"
27 
28 #include <ostream>
29 #include <stdint.h>
30 
31 namespace ns3
32 {
33 
34 class Address;
35 
46 {
47  public:
48  Mac48Address() = default;
54  Mac48Address(const char* str);
55 
61  void CopyFrom(const uint8_t buffer[6]);
67  void CopyTo(uint8_t buffer[6]) const;
68 
74  operator Address() const;
83  static Mac48Address ConvertFrom(const Address& address);
89  Address ConvertTo() const;
90 
95  static bool IsMatchingType(const Address& address);
100  static Mac48Address Allocate();
101 
115  static void ResetAllocationIndex();
116 
120  bool IsBroadcast() const;
121 
125  bool IsGroup() const;
126 
130  static Mac48Address GetBroadcast();
131 
137 
144 
149 
155 
161  typedef void (*TracedCallback)(Mac48Address value);
162 
163  private:
168  static uint8_t GetType();
169 
177  friend bool operator==(const Mac48Address& a, const Mac48Address& b);
178 
186  friend bool operator!=(const Mac48Address& a, const Mac48Address& b);
187 
195  friend bool operator<(const Mac48Address& a, const Mac48Address& b);
196 
204  friend std::ostream& operator<<(std::ostream& os, const Mac48Address& address);
205 
213  friend std::istream& operator>>(std::istream& is, Mac48Address& address);
214 
215  static uint64_t m_allocationIndex;
216  uint8_t m_address[6]{0};
217 };
218 
220 
221 inline bool
223 {
224  return memcmp(a.m_address, b.m_address, 6) == 0;
225 }
226 
227 inline bool
229 {
230  return memcmp(a.m_address, b.m_address, 6) != 0;
231 }
232 
233 inline bool
234 operator<(const Mac48Address& a, const Mac48Address& b)
235 {
236  return memcmp(a.m_address, b.m_address, 6) < 0;
237 }
238 
239 std::ostream& operator<<(std::ostream& os, const Mac48Address& address);
240 std::istream& operator>>(std::istream& is, Mac48Address& address);
241 
242 } // namespace ns3
243 
244 #endif /* MAC48_ADDRESS_H */
a polymophic address class
Definition: address.h:101
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
Describes an IPv6 address.
Definition: ipv6-address.h:49
an EUI-48 address
Definition: mac48-address.h:46
static Mac48Address GetMulticast(Ipv4Address address)
static void ResetAllocationIndex()
Reset the Mac48Address allocation index.
Mac48Address()=default
bool IsGroup() const
friend std::istream & operator>>(std::istream &is, Mac48Address &address)
Stream extraction operator.
static bool IsMatchingType(const Address &address)
void CopyFrom(const uint8_t buffer[6])
friend bool operator<(const Mac48Address &a, const Mac48Address &b)
Less than operator.
friend bool operator!=(const Mac48Address &a, const Mac48Address &b)
Not equal to operator.
static uint8_t GetType()
Return the Type of address.
static Mac48Address ConvertFrom(const Address &address)
uint8_t m_address[6]
Address value.
static Mac48Address GetBroadcast()
friend std::ostream & operator<<(std::ostream &os, const Mac48Address &address)
Stream insertion operator.
static Mac48Address Allocate()
Allocate a new Mac48Address.
static Mac48Address GetMulticast6Prefix()
Get the multicast prefix for IPv6 (33:33:00:00:00:00).
friend bool operator==(const Mac48Address &a, const Mac48Address &b)
Equal to operator.
void CopyTo(uint8_t buffer[6]) const
static Mac48Address GetMulticastPrefix()
static uint64_t m_allocationIndex
Address allocation index.
Address ConvertTo() const
bool IsBroadcast() const
Forward calls to a chain of Callback.
address
Definition: first.py:47
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:678
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.h:157
ATTRIBUTE_HELPER_HEADER(ValueClassTest)
bool operator<(const EventId &a, const EventId &b)
Definition: event-id.h:170
std::istream & operator>>(std::istream &is, Angles &a)
Definition: angles.cc:183
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:159