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