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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Leonard Tracy <lentracy@gmail.com>
7 */
8
9#include "mac8-address.h"
10
11#include "ns3/address.h"
12#include "ns3/log.h"
13#include "ns3/simulator.h"
14
15namespace ns3
16{
17
18NS_LOG_COMPONENT_DEFINE("Mac8Address");
19
21
23 : m_address(addr)
24{
25}
26
30
31uint8_t
33{
34 static uint8_t type = Address::Register();
35 return type;
36}
37
40{
41 return Address(GetType(), &m_address, 1);
42}
43
46{
47 NS_ASSERT(IsMatchingType(address));
48 Mac8Address uAddr;
49 address.CopyTo(&uAddr.m_address);
50 return uAddr;
51}
52
53bool
55{
56 return address.CheckCompatible(GetType(), 1);
57}
58
59Mac8Address::operator Address() const
60{
61 return ConvertTo();
62}
63
64void
65Mac8Address::CopyFrom(const uint8_t* pBuffer)
66{
67 m_address = *pBuffer;
68}
69
70void
71Mac8Address::CopyTo(uint8_t* pBuffer) const
72{
73 *pBuffer = m_address;
74}
75
78{
79 return Mac8Address(255);
80}
81
84{
86
87 if (m_allocationIndex == 0)
88 {
90 }
91
92 uint8_t address = m_allocationIndex++;
93 if (m_allocationIndex == 255)
94 {
96 }
97
98 return Mac8Address(address);
99}
100
101void
108
109bool
110operator<(const Mac8Address& a, const Mac8Address& b)
111{
112 return a.m_address < b.m_address;
113}
114
115bool
117{
118 return a.m_address == b.m_address;
119}
120
121bool
123{
124 return !(a == b);
125}
126
127std::ostream&
128operator<<(std::ostream& os, const Mac8Address& address)
129{
130 os << (int)address.m_address;
131 return os;
132}
133
134std::istream&
135operator>>(std::istream& is, Mac8Address& address)
136{
137 uint8_t x;
138 is >> x;
139 NS_ASSERT(0 <= x);
140 NS_ASSERT(x <= 255);
141 address.m_address = x;
142 return is;
143}
144
145} // namespace ns3
a polymophic address class
Definition address.h:90
static uint8_t Register()
Allocate a new type id for a new type of address.
Definition address.cc:135
A class used for addressing MAC8 MAC's.
static Mac8Address GetBroadcast()
Get the broadcast address (255).
static Mac8Address ConvertFrom(const Address &address)
Convert a generic address to a Mac8Address.
static void ResetAllocationIndex()
Reset the Mac8Address allocation index.
Address ConvertTo() const
Convert to a generic Address.
static bool IsMatchingType(const Address &address)
Check that a generic Address is compatible with Mac8Address.
static uint8_t GetType()
Get the Mac8Address type.
uint8_t m_address
The address.
Mac8Address()=default
static uint8_t m_allocationIndex
Address allocation index.
void CopyTo(uint8_t *pBuffer) const
Writes address to buffer parameter.
static Mac8Address Allocate()
Allocates Mac8Address from 0-254.
void CopyFrom(const uint8_t *pBuffer)
Sets address to address stored in parameter.
virtual ~Mac8Address()
Destructor.
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:611
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#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:658
bool operator==(const EventId &a, const EventId &b)
Definition event-id.h:155
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition angles.cc:148
std::istream & operator>>(std::istream &is, Angles &a)
Definition angles.cc:172
bool operator<(const EventId &a, const EventId &b)
Definition event-id.h:168