A Discrete-Event Network Simulator
API
mac16-address.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007 INRIA
3  * Copyright (c) 2011 The Boeing Company
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  */
19 #ifndef MAC16_ADDRESS_H
20 #define MAC16_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 
44 {
45  public:
46  Mac16Address() = default;
52  Mac16Address(const char* str);
53 
59  Mac16Address(uint16_t addr);
60 
66  void CopyFrom(const uint8_t buffer[2]);
67 
73  void CopyTo(uint8_t buffer[2]) const;
74 
80  operator Address() const;
81 
90  static Mac16Address ConvertFrom(const Address& address);
91 
97  Address ConvertTo() const;
98 
104  uint16_t ConvertToInt() const;
105 
110  static bool IsMatchingType(const Address& address);
111 
116  static Mac16Address Allocate();
117 
131  static void ResetAllocationIndex();
132 
136  static Mac16Address GetBroadcast();
137 
162 
169  bool IsBroadcast() const;
170 
177  bool IsMulticast() const;
178 
179  private:
184  static uint8_t GetType();
185 
193  friend bool operator==(const Mac16Address& a, const Mac16Address& b);
194 
202  friend bool operator!=(const Mac16Address& a, const Mac16Address& b);
203 
211  friend bool operator<(const Mac16Address& a, const Mac16Address& b);
212 
220  friend std::ostream& operator<<(std::ostream& os, const Mac16Address& address);
221 
229  friend std::istream& operator>>(std::istream& is, Mac16Address& address);
230 
231  static uint64_t m_allocationIndex;
232  uint8_t m_address[2]{0};
233 };
234 
236 
237 inline bool
239 {
240  return memcmp(a.m_address, b.m_address, 2) == 0;
241 }
242 
243 inline bool
245 {
246  return memcmp(a.m_address, b.m_address, 2) != 0;
247 }
248 
249 inline bool
250 operator<(const Mac16Address& a, const Mac16Address& b)
251 {
252  return memcmp(a.m_address, b.m_address, 2) < 0;
253 }
254 
255 std::ostream& operator<<(std::ostream& os, const Mac16Address& address);
256 std::istream& operator>>(std::istream& is, Mac16Address& address);
257 
258 } // namespace ns3
259 
260 #endif /* MAC16_ADDRESS_H */
a polymophic address class
Definition: address.h:101
Describes an IPv6 address.
Definition: ipv6-address.h:49
This class can contain 16 bit addresses.
Definition: mac16-address.h:44
friend bool operator<(const Mac16Address &a, const Mac16Address &b)
Less than operator.
static Mac16Address GetMulticast(Ipv6Address address)
Returns the multicast address associated with an IPv6 address according to RFC 4944 Section 9.
static bool IsMatchingType(const Address &address)
static uint64_t m_allocationIndex
Address allocation index.
friend bool operator!=(const Mac16Address &a, const Mac16Address &b)
Not equal to operator.
friend std::ostream & operator<<(std::ostream &os, const Mac16Address &address)
Stream insertion operator.
static Mac16Address ConvertFrom(const Address &address)
Mac16Address()=default
uint16_t ConvertToInt() const
void CopyTo(uint8_t buffer[2]) const
friend bool operator==(const Mac16Address &a, const Mac16Address &b)
Equal to operator.
static Mac16Address Allocate()
Allocate a new Mac16Address.
friend std::istream & operator>>(std::istream &is, Mac16Address &address)
Stream extraction operator.
Address ConvertTo() const
void CopyFrom(const uint8_t buffer[2])
bool IsMulticast() const
Checks if the address is a multicast address according to RFC 4944 Section 9 (i.e....
uint8_t m_address[2]
Address value.
static void ResetAllocationIndex()
Reset the Mac16Address allocation index.
static Mac16Address GetBroadcast()
bool IsBroadcast() const
Checks if the address is a broadcast address according to 802.15.4 scheme (i.e., 0xFFFF).
static uint8_t GetType()
Return the Type of address.
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