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("MacAddress", 1);
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
110std::ostream&
111operator<<(std::ostream& os, const Mac8Address& address)
112{
113 os << static_cast<uint32_t>(address.m_address);
114 return os;
115}
116
117std::istream&
118operator>>(std::istream& is, Mac8Address& address)
119{
120 uint8_t x;
121 is >> x;
122 NS_ASSERT(0 <= x);
123 NS_ASSERT(x <= 255);
124 address.m_address = x;
125 return is;
126}
127
128} // namespace ns3
cairo_uint64_t x
_cairo_uint_96by64_32x64_divrem:
a polymophic address class
Definition address.h:111
static uint8_t Register(const std::string &kind, uint8_t length)
Allocate a new type id for a new type of address.
Definition address.cc:156
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: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.
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