A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
mac8-address.cc
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#include "mac8-address.h"
21
22#include "ns3/address.h"
23#include "ns3/log.h"
24#include "ns3/simulator.h"
25
26namespace ns3
27{
28
29NS_LOG_COMPONENT_DEFINE("Mac8Address");
30
32
34{
35 m_address = 255;
36}
37
39 : m_address(addr)
40{
41}
42
44{
45}
46
47uint8_t
49{
50 static uint8_t type = Address::Register();
51 return type;
52}
53
56{
57 return Address(GetType(), &m_address, 1);
58}
59
62{
63 NS_ASSERT(IsMatchingType(address));
64 Mac8Address uAddr;
65 address.CopyTo(&uAddr.m_address);
66 return uAddr;
67}
68
69bool
71{
72 return address.CheckCompatible(GetType(), 1);
73}
74
75Mac8Address::operator Address() const
76{
77 return ConvertTo();
78}
79
80void
81Mac8Address::CopyFrom(const uint8_t* pBuffer)
82{
83 m_address = *pBuffer;
84}
85
86void
87Mac8Address::CopyTo(uint8_t* pBuffer) const
88{
89 *pBuffer = m_address;
90}
91
94{
95 return Mac8Address(255);
96}
97
100{
102
103 if (m_allocationIndex == 0)
104 {
106 }
107
108 uint8_t address = m_allocationIndex++;
109 if (m_allocationIndex == 255)
110 {
112 }
113
114 return Mac8Address(address);
115}
116
117void
119{
121
123}
124
125bool
126operator<(const Mac8Address& a, const Mac8Address& b)
127{
128 return a.m_address < b.m_address;
129}
130
131bool
133{
134 return a.m_address == b.m_address;
135}
136
137bool
139{
140 return !(a == b);
141}
142
143std::ostream&
144operator<<(std::ostream& os, const Mac8Address& address)
145{
146 os << (int)address.m_address;
147 return os;
148}
149
150std::istream&
151operator>>(std::istream& is, Mac8Address& address)
152{
153 uint8_t x;
154 is >> x;
155 NS_ASSERT(0 <= x);
156 NS_ASSERT(x <= 255);
157 address.m_address = x;
158 return is;
159}
160
161} // namespace ns3
a polymophic address class
Definition: address.h:100
static uint8_t Register()
Allocate a new type id for a new type of address.
Definition: address.cc:146
A class used for addressing MAC8 MAC's.
Definition: mac8-address.h:44
static Mac8Address GetBroadcast()
Get the broadcast address (255).
Definition: mac8-address.cc:93
static Mac8Address ConvertFrom(const Address &address)
Convert a generic address to a Mac8Address.
Definition: mac8-address.cc:61
static void ResetAllocationIndex()
Reset the Mac8Address allocation index.
Address ConvertTo() const
Convert to a generic Address.
Definition: mac8-address.cc:55
static bool IsMatchingType(const Address &address)
Check that a generic Address is compatible with Mac8Address.
Definition: mac8-address.cc:70
static uint8_t GetType()
Get the Mac8Address type.
Definition: mac8-address.cc:48
uint8_t m_address
The address.
Definition: mac8-address.h:135
static uint8_t m_allocationIndex
Address allocation index.
Definition: mac8-address.h:134
void CopyTo(uint8_t *pBuffer) const
Writes address to buffer parameter.
Definition: mac8-address.cc:87
static Mac8Address Allocate()
Allocates Mac8Address from 0-254.
Definition: mac8-address.cc:99
void CopyFrom(const uint8_t *pBuffer)
Sets address to address stored in parameter.
Definition: mac8-address.cc:81
virtual ~Mac8Address()
Destructor.
Definition: mac8-address.cc:43
Mac8Address()
Constructor.
Definition: mac8-address.cc:33
static EventId ScheduleDestroy(FUNC f, Ts &&... args)
Schedule an event to run at the end of the simulation, when Simulator::Destroy() is called.
Definition: simulator.h:625
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
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:676
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.h:157
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:129
std::istream & operator>>(std::istream &is, Angles &a)
Definition: angles.cc:153
bool operator<(const EventId &a, const EventId &b)
Definition: event-id.h:170