A Discrete-Event Network Simulator
API
mac8-address.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009 University of Washington
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: Leonard Tracy <lentracy@gmail.com>
18  */
19 
20 #ifndef MAC8_ADDRESS_H
21 #define MAC8_ADDRESS_H
22 
23 #include "ns3/address.h"
24 
25 #include <iostream>
26 
27 namespace ns3
28 {
29 
30 class Address;
31 
44 {
45  public:
46  Mac8Address() = default;
52  Mac8Address(uint8_t addr);
54  virtual ~Mac8Address();
55 
62  static Mac8Address ConvertFrom(const Address& address);
63 
69  Address ConvertTo() const;
70 
77  static bool IsMatchingType(const Address& address);
78 
84  operator Address() const;
85 
91  void CopyFrom(const uint8_t* pBuffer);
92 
98  void CopyTo(uint8_t* pBuffer) const;
99 
105  static Mac8Address GetBroadcast();
106 
115  static Mac8Address Allocate();
116 
130  static void ResetAllocationIndex();
131 
132  private:
133  static uint8_t m_allocationIndex;
134  uint8_t m_address{255};
135 
141  static uint8_t GetType();
142 
143  friend bool operator<(const Mac8Address& a, const Mac8Address& b);
144  friend bool operator==(const Mac8Address& a, const Mac8Address& b);
145  friend bool operator!=(const Mac8Address& a, const Mac8Address& b);
146  friend std::ostream& operator<<(std::ostream& os, const Mac8Address& address);
147  friend std::istream& operator>>(std::istream& is, Mac8Address& address);
148 
149 }; // class Mac8Address
150 
158 bool operator<(const Mac8Address& a, const Mac8Address& b);
159 
167 bool operator==(const Mac8Address& a, const Mac8Address& b);
168 
176 bool operator!=(const Mac8Address& a, const Mac8Address& b);
177 
185 std::ostream& operator<<(std::ostream& os, const Mac8Address& address);
186 
194 std::istream& operator>>(std::istream& is, Mac8Address& address);
195 
196 } // namespace ns3
197 
198 #endif /* MAC8_ADDRESS_H */
a polymophic address class
Definition: address.h:101
A class used for addressing MAC8 MAC's.
Definition: mac8-address.h:44
friend bool operator<(const Mac8Address &a, const Mac8Address &b)
Address comparison, less than.
static Mac8Address GetBroadcast()
Get the broadcast address (255).
Definition: mac8-address.cc:88
static Mac8Address ConvertFrom(const Address &address)
Convert a generic address to a Mac8Address.
Definition: mac8-address.cc:56
static void ResetAllocationIndex()
Reset the Mac8Address allocation index.
Address ConvertTo() const
Convert to a generic Address.
Definition: mac8-address.cc:50
static bool IsMatchingType(const Address &address)
Check that a generic Address is compatible with Mac8Address.
Definition: mac8-address.cc:65
static uint8_t GetType()
Get the Mac8Address type.
Definition: mac8-address.cc:43
uint8_t m_address
The address.
Definition: mac8-address.h:134
Mac8Address()=default
static uint8_t m_allocationIndex
Address allocation index.
Definition: mac8-address.h:133
void CopyTo(uint8_t *pBuffer) const
Writes address to buffer parameter.
Definition: mac8-address.cc:82
static Mac8Address Allocate()
Allocates Mac8Address from 0-254.
Definition: mac8-address.cc:94
friend bool operator==(const Mac8Address &a, const Mac8Address &b)
Address comparison, equality.
friend bool operator!=(const Mac8Address &a, const Mac8Address &b)
Address comparison, unequal.
friend std::istream & operator>>(std::istream &is, Mac8Address &address)
Read address from stream is as 8 bit integer.
friend std::ostream & operator<<(std::ostream &os, const Mac8Address &address)
Write address to stream os as 8 bit integer.
void CopyFrom(const uint8_t *pBuffer)
Sets address to address stored in parameter.
Definition: mac8-address.cc:76
virtual ~Mac8Address()
Destructor.
Definition: mac8-address.cc:38
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
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