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 Mac8Address() = default;
37 /**
38 * Create Mac8Address object with address addr.
39 *
40 * @param addr Byte address to assign to this address.
41 */
42 Mac8Address(uint8_t addr);
43 /** Destructor */
44 virtual ~Mac8Address();
45
46 /**
47 * Convert a generic address to a Mac8Address.
48 *
49 * @param address Address to convert to Mac8Address address.
50 * @return Mac8Address from Address.
51 */
52 static Mac8Address ConvertFrom(const Address& address);
53
54 /**
55 * Convert to a generic Address.
56 *
57 * @return The Address value.
58 */
59 Address ConvertTo() const;
60
61 /**
62 * Check that a generic Address is compatible with Mac8Address.
63 *
64 * @param address Address to test.
65 * @return True if address given is consistent with Mac8Address.
66 */
67 static bool IsMatchingType(const Address& address);
68
69 /**
70 * Create a generic Address.
71 *
72 * @return The Address.
73 */
74 operator Address() const;
75
76 /**
77 * Sets address to address stored in parameter.
78 *
79 * @param pBuffer Buffer to extract address from.
80 */
81 void CopyFrom(const uint8_t* pBuffer);
82
83 /**
84 * Writes address to buffer parameter.
85 *
86 * @param pBuffer
87 */
88 void CopyTo(uint8_t* pBuffer) const;
89
90 /**
91 * Get the broadcast address (255).
92 *
93 * @return Broadcast address.
94 */
96
97 /**
98 * Allocates Mac8Address from 0-254
99 *
100 * Will wrap back to 0 if more than 254 are allocated.
101 * Excludes the broadcast address.
102 *
103 * @return The next sequential Mac8Address.
104 */
105 static Mac8Address Allocate();
106
107 /**
108 * Reset the Mac8Address allocation index.
109 *
110 * This function resets (to zero) the global integer
111 * that is used for unique address allocation.
112 * It is automatically called whenever
113 * @code
114 * SimulatorDestroy ();
115 * @endcode
116 * is called. It may also be optionally called
117 * by user code if there is a need to force a reset
118 * of this allocation index.
119 */
120 static void ResetAllocationIndex();
121
122 /**
123 * Spaceship comparison operator. All the other comparison operators
124 * are automatically generated from this one.
125 *
126 * @param other address to compare to this one
127 * @returns The result of the comparison.
128 */
129 constexpr std::strong_ordering operator<=>(const Mac8Address& other) const = default;
130
131 private:
132 static uint8_t m_allocationIndex; //!< Address allocation index
133 uint8_t m_address{255}; //!< The address.
134
135 /**
136 * Get the Mac8Address type.
137 *
138 * @return The type value.
139 */
140 static uint8_t GetType();
141
142 friend std::ostream& operator<<(std::ostream& os, const Mac8Address& address);
143 friend std::istream& operator>>(std::istream& is, Mac8Address& address);
144};
145
146/**
147 * Write \pname{address} to stream \pname{os} as 8 bit integer.
148 *
149 * @param os The output stream.
150 * @param address The address
151 * @return The output stream.
152 */
153std::ostream& operator<<(std::ostream& os, const Mac8Address& address);
154
155/**
156 * Read \pname{address} from stream \pname{is} as 8 bit integer.
157 *
158 * @param is The input stream.
159 * @param address The address variable to set.
160 * @return The input stream.
161 */
162std::istream& operator>>(std::istream& is, Mac8Address& address);
163
164} // namespace ns3
165
166#endif /* MAC8_ADDRESS_H */
a polymophic address class
Definition address.h:111
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.
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