A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
mac8-address.h
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#ifndef MAC8_ADDRESS_H
10#define MAC8_ADDRESS_H
11
12#include "ns3/address.h"
13
14#include <compare>
15#include <iostream>
16
17namespace ns3
18{
19
20class Address;
21
22/**
23 * @ingroup network
24 *
25 * A class used for addressing MAC8 MAC's.
26 *
27 * This implementation uses a simple 8 bit flat addressing scheme.
28 * It is unlikely that perceived underwater networks will soon
29 * exceed 200 nodes (or the overlapping of two underwater networks
30 * - the ocean is big), so this should provide adequate addressing
31 * for most applications.
32 */
34{
35 public:
36 /// Address length when converted to an Address [bytes].
37 static constexpr uint8_t ADDRESS_LENGTH = 1;
38
39 Mac8Address() = default;
40 /**
41 * Create Mac8Address object with address addr.
42 *
43 * @param addr Byte address to assign to this address.
44 */
45 Mac8Address(uint8_t addr);
46 /** Destructor */
47 virtual ~Mac8Address();
48
49 /**
50 * Convert a generic address to a Mac8Address.
51 *
52 * @param address Address to convert to Mac8Address address.
53 * @return Mac8Address from Address.
54 */
55 static Mac8Address ConvertFrom(const Address& address);
56
57 /**
58 * Convert to a generic Address.
59 *
60 * @return The Address value.
61 */
62 Address ConvertTo() const;
63
64 /**
65 * Check that a generic Address is compatible with Mac8Address.
66 *
67 * @param address Address to test.
68 * @return True if address given is consistent with Mac8Address.
69 */
70 static bool IsMatchingType(const Address& address);
71
72 /**
73 * Create a generic Address.
74 *
75 * @return The Address.
76 */
77 operator Address() const;
78
79 /**
80 * Sets address to address stored in parameter.
81 *
82 * @param pBuffer Buffer to extract address from.
83 */
84 void CopyFrom(const uint8_t* pBuffer);
85
86 /**
87 * Writes address to buffer parameter.
88 *
89 * @param pBuffer
90 */
91 void CopyTo(uint8_t* pBuffer) const;
92
93 /**
94 * Get the broadcast address (255).
95 *
96 * @return Broadcast address.
97 */
99
100 /**
101 * Allocates Mac8Address from 0-254
102 *
103 * Will wrap back to 0 if more than 254 are allocated.
104 * Excludes the broadcast address.
105 *
106 * @return The next sequential Mac8Address.
107 */
108 static Mac8Address Allocate();
109
110 /**
111 * Reset the Mac8Address allocation index.
112 *
113 * This function resets (to zero) the global integer
114 * that is used for unique address allocation.
115 * It is automatically called whenever
116 * @code
117 * SimulatorDestroy ();
118 * @endcode
119 * is called. It may also be optionally called
120 * by user code if there is a need to force a reset
121 * of this allocation index.
122 */
123 static void ResetAllocationIndex();
124
125 /**
126 * Spaceship comparison operator. All the other comparison operators
127 * are automatically generated from this one.
128 *
129 * @param other address to compare to this one
130 * @returns The result of the comparison.
131 */
132 constexpr std::strong_ordering operator<=>(const Mac8Address& other) const = default;
133
134 private:
135 static uint8_t m_allocationIndex; //!< Address allocation index
136 uint8_t m_address{255}; //!< The address.
137
138 /**
139 * Get the Mac8Address type.
140 *
141 * @return The type value.
142 */
143 static uint8_t GetType();
144
145 friend std::ostream& operator<<(std::ostream& os, const Mac8Address& address);
146 friend std::istream& operator>>(std::istream& is, Mac8Address& address);
147};
148
149/**
150 * Write \pname{address} to stream \pname{os} as 8 bit integer.
151 *
152 * @param os The output stream.
153 * @param address The address
154 * @return The output stream.
155 */
156std::ostream& operator<<(std::ostream& os, const Mac8Address& address);
157
158/**
159 * Read \pname{address} from stream \pname{is} as 8 bit integer.
160 *
161 * @param is The input stream.
162 * @param address The address variable to set.
163 * @return The input stream.
164 */
165std::istream& operator>>(std::istream& is, Mac8Address& address);
166
167} // namespace ns3
168
169#endif /* MAC8_ADDRESS_H */
a polymophic address class
Definition address.h:114
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.
friend std::ostream & operator<<(std::ostream &os, const Mac8Address &address)
Write address to stream os as 8 bit integer.
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.
constexpr std::strong_ordering operator<=>(const Mac8Address &other) const =default
Spaceship comparison operator.
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 constexpr uint8_t ADDRESS_LENGTH
Address length when converted to an Address [bytes].
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