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();
51  Mac16Address(const char* str);
52 
58  void CopyFrom(const uint8_t buffer[2]);
64  void CopyTo(uint8_t buffer[2]) const;
70  operator Address() const;
79  static Mac16Address ConvertFrom(const Address& address);
85  Address ConvertTo() const;
86 
91  static bool IsMatchingType(const Address& address);
96  static Mac16Address Allocate();
97 
111  static void ResetAllocationIndex();
112 
116  static Mac16Address GetBroadcast();
117 
142 
149  bool IsBroadcast() const;
150 
157  bool IsMulticast() const;
158 
159  private:
164  static uint8_t GetType();
165 
173  friend bool operator==(const Mac16Address& a, const Mac16Address& b);
174 
182  friend bool operator!=(const Mac16Address& a, const Mac16Address& b);
183 
191  friend bool operator<(const Mac16Address& a, const Mac16Address& b);
192 
200  friend std::ostream& operator<<(std::ostream& os, const Mac16Address& address);
201 
209  friend std::istream& operator>>(std::istream& is, Mac16Address& address);
210 
211  static uint64_t m_allocationIndex;
212  uint8_t m_address[2];
213 };
214 
216 
217 inline bool
219 {
220  return memcmp(a.m_address, b.m_address, 2) == 0;
221 }
222 
223 inline bool
225 {
226  return memcmp(a.m_address, b.m_address, 2) != 0;
227 }
228 
229 inline bool
230 operator<(const Mac16Address& a, const Mac16Address& b)
231 {
232  return memcmp(a.m_address, b.m_address, 2) < 0;
233 }
234 
235 std::ostream& operator<<(std::ostream& os, const Mac16Address& address);
236 std::istream& operator>>(std::istream& is, Mac16Address& address);
237 
238 } // namespace ns3
239 
240 #endif /* MAC16_ADDRESS_H */
a polymophic address class
Definition: address.h:100
Describes an IPv6 address.
Definition: ipv6-address.h:50
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)
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:40
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:681
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:153
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:129