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::
60operator Address() const
61{
62 return ConvertTo();
63}
64
65void
66Mac8Address::CopyFrom(const uint8_t* pBuffer)
67{
68 m_address = *pBuffer;
69}
70
71void
72Mac8Address::CopyTo(uint8_t* pBuffer) const
73{
74 *pBuffer = m_address;
75}
76
79{
80 return Mac8Address(255);
81}
82
85{
87
88 if (m_allocationIndex == 0)
89 {
91 }
92
93 uint8_t address = m_allocationIndex++;
94 if (m_allocationIndex == 255)
95 {
97 }
98
99 return Mac8Address(address);
100}
101
102void
109
110bool
111operator<(const Mac8Address& a, const Mac8Address& b)
112{
113 return a.m_address < b.m_address;
114}
115
116bool
118{
119 return a.m_address == b.m_address;
120}
121
122bool
124{
125 return !(a == b);
126}
127
128std::ostream&
129operator<<(std::ostream& os, const Mac8Address& address)
130{
131 os << (int)address.m_address;
132 return os;
133}
134
135std::istream&
136operator>>(std::istream& is, Mac8Address& address)
137{
138 uint8_t x;
139 is >> x;
140 NS_ASSERT(0 <= x);
141 NS_ASSERT(x <= 255);
142 address.m_address = x;
143 return is;
144}
145
146} // 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.
friend std::istream & operator>>(std::istream &is, Mac8Address &address)
Read address from stream is as 8 bit integer.
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:612
#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:146
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition angles.cc:148
bool operator<(const EventId &a, const EventId &b)
Definition event-id.h:159