A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
ipv4-interface-address.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2008 University of Washington
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
*/
7
8
#ifndef IPV4_INTERFACE_ADDRESS_H
9
#define IPV4_INTERFACE_ADDRESS_H
10
11
#include "ns3/ipv4-address.h"
12
13
#include <ostream>
14
#include <stdint.h>
15
16
namespace
ns3
17
{
18
19
/**
20
* @ingroup address
21
* @ingroup ipv4
22
*
23
* @brief a class to store IPv4 address information on an interface
24
*
25
* Corresponds to Linux struct in_ifaddr. A list of these addresses
26
* is stored in Ipv4Interface. This class is modelled after how current
27
* Linux handles IP aliasing for IPv4. Notably, aliasing of IPv4
28
* interfaces (e.g., "eth0:1") is not used, and instead an interface
29
* is assigned possibly multiple addresses, with each address being
30
* classified as being primary and secondary. See the iproute2
31
* documentation for this distinction.
32
*/
33
class
Ipv4InterfaceAddress
34
{
35
public
:
36
/**
37
* @enum InterfaceAddressScope_e
38
* @brief Address scope.
39
*/
40
enum
InterfaceAddressScope_e
41
{
42
HOST
,
43
LINK
,
44
GLOBAL
45
};
46
47
Ipv4InterfaceAddress
();
48
49
/**
50
* @brief Configure local address, mask and broadcast address
51
* @param local the local address
52
* @param mask the network mask
53
*/
54
Ipv4InterfaceAddress
(
Ipv4Address
local,
Ipv4Mask
mask);
55
/**
56
* Copy constructor
57
* @param o the object to copy
58
*/
59
Ipv4InterfaceAddress
(
const
Ipv4InterfaceAddress
& o);
60
61
/**
62
* @brief Set local address
63
* @param local the address
64
*
65
* @note Functionally identical to `Ipv4InterfaceAddress::SetAddress`.
66
* The method corresponds to the linux variable in_ifaddr.ifa_local
67
* `Ipv4InterfaceAddress::SetAddress` is to be preferred.
68
*/
69
void
SetLocal
(
Ipv4Address
local);
70
71
/**
72
* @brief Set local address
73
* @param address the address
74
*
75
* @note Functially identical to `Ipv4InterfaceAddress::SetLocal`.
76
* This function is consistent with `Ipv6InterfaceAddress::SetAddress`.
77
*/
78
void
SetAddress
(
Ipv4Address
address);
79
80
/**
81
* @brief Get the local address
82
* @returns the local address
83
*
84
* @note Functionally identical to `Ipv4InterfaceAddress::GetAddress`.
85
* The method corresponds to the linux variable in_ifaddr.ifa_local
86
* `Ipv4InterfaceAddress::GetAddress` is to be preferred.
87
*/
88
Ipv4Address
GetLocal
()
const
;
89
90
/**
91
* @brief Get the local address
92
* @returns the local address
93
*
94
* @note Functially identical to `Ipv4InterfaceAddress::GetLocal`.
95
* This function is consistent with `Ipv6InterfaceAddress::GetAddress`.
96
*/
97
Ipv4Address
GetAddress
()
const
;
98
99
/**
100
* @brief Set the network mask
101
* @param mask the network mask
102
*/
103
void
SetMask
(
Ipv4Mask
mask);
104
/**
105
* @brief Get the network mask
106
* @returns the network mask
107
*/
108
Ipv4Mask
GetMask
()
const
;
109
/**
110
* @brief Set the broadcast address
111
* @param broadcast the broadcast address
112
*/
113
void
SetBroadcast
(
Ipv4Address
broadcast);
114
/**
115
* @brief Get the broadcast address
116
* @returns the broadcast address
117
*/
118
Ipv4Address
GetBroadcast
()
const
;
119
120
/**
121
* @brief Set the scope.
122
* @param scope the scope of address
123
*/
124
void
SetScope
(
Ipv4InterfaceAddress::InterfaceAddressScope_e
scope);
125
126
/**
127
* @brief Get address scope.
128
* @return scope
129
*/
130
Ipv4InterfaceAddress::InterfaceAddressScope_e
GetScope
()
const
;
131
132
/**
133
* @brief Checks if the address is in the same subnet.
134
* @param b the address to check
135
* @return true if the address is in the same subnet.
136
*/
137
bool
IsInSameSubnet
(
const
Ipv4Address
b)
const
;
138
139
/**
140
* @brief Check if the address is a secondary address
141
*
142
* Secondary address is used for multihoming
143
* @returns true if the address is secondary
144
*/
145
bool
IsSecondary
()
const
;
146
147
/**
148
* @brief Make the address secondary (used for multihoming)
149
*/
150
void
SetSecondary
();
151
/**
152
* @brief Make the address primary
153
*/
154
void
SetPrimary
();
155
156
private
:
157
Ipv4Address
m_local
;
//!< Interface address
158
// Note: m_peer may be added in future when necessary
159
// Ipv4Address m_peer; // Peer destination address (in Linux: m_address)
160
Ipv4Mask
m_mask
;
//!< Network mask
161
Ipv4Address
m_broadcast
;
//!< Broadcast address
162
163
InterfaceAddressScope_e
m_scope
;
//!< Address scope
164
bool
m_secondary
;
//!< For use in multihoming
165
166
/**
167
* @brief Equal to operator.
168
*
169
* @param a the first operand
170
* @param b the first operand
171
* @returns true if the operands are equal
172
*/
173
friend
bool
operator==
(
const
Ipv4InterfaceAddress
& a,
const
Ipv4InterfaceAddress
& b);
174
175
/**
176
* @brief Not equal to operator.
177
*
178
* @param a the first operand
179
* @param b the first operand
180
* @returns true if the operands are not equal
181
*/
182
friend
bool
operator!=
(
const
Ipv4InterfaceAddress
& a,
const
Ipv4InterfaceAddress
& b);
183
};
184
185
/**
186
* @brief Stream insertion operator.
187
*
188
* @param os the reference to the output stream
189
* @param addr the Ipv4InterfaceAddress
190
* @returns the reference to the output stream
191
*/
192
std::ostream&
operator<<
(std::ostream& os,
const
Ipv4InterfaceAddress
& addr);
193
194
inline
bool
195
operator==
(
const
Ipv4InterfaceAddress
& a,
const
Ipv4InterfaceAddress
& b)
196
{
197
return
(a.
m_local
== b.
m_local
&& a.
m_mask
== b.
m_mask
&& a.
m_broadcast
== b.
m_broadcast
&&
198
a.
m_scope
== b.
m_scope
&& a.
m_secondary
== b.
m_secondary
);
199
}
200
201
inline
bool
202
operator!=
(
const
Ipv4InterfaceAddress
& a,
const
Ipv4InterfaceAddress
& b)
203
{
204
return
(a.
m_local
!= b.
m_local
|| a.
m_mask
!= b.
m_mask
|| a.
m_broadcast
!= b.
m_broadcast
||
205
a.
m_scope
!= b.
m_scope
|| a.
m_secondary
!= b.
m_secondary
);
206
}
207
208
}
// namespace ns3
209
210
#endif
/* IPV4_ADDRESS_H */
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition
ipv4-address.h:31
ns3::Ipv4InterfaceAddress
a class to store IPv4 address information on an interface
Definition
ipv4-interface-address.h:34
ns3::Ipv4InterfaceAddress::GetMask
Ipv4Mask GetMask() const
Get the network mask.
Definition
ipv4-interface-address.cc:84
ns3::Ipv4InterfaceAddress::operator==
friend bool operator==(const Ipv4InterfaceAddress &a, const Ipv4InterfaceAddress &b)
Equal to operator.
Definition
ipv4-interface-address.h:195
ns3::Ipv4InterfaceAddress::SetMask
void SetMask(Ipv4Mask mask)
Set the network mask.
Definition
ipv4-interface-address.cc:77
ns3::Ipv4InterfaceAddress::SetBroadcast
void SetBroadcast(Ipv4Address broadcast)
Set the broadcast address.
Definition
ipv4-interface-address.cc:91
ns3::Ipv4InterfaceAddress::InterfaceAddressScope_e
InterfaceAddressScope_e
Address scope.
Definition
ipv4-interface-address.h:41
ns3::Ipv4InterfaceAddress::LINK
@ LINK
Definition
ipv4-interface-address.h:43
ns3::Ipv4InterfaceAddress::HOST
@ HOST
Definition
ipv4-interface-address.h:42
ns3::Ipv4InterfaceAddress::GLOBAL
@ GLOBAL
Definition
ipv4-interface-address.h:44
ns3::Ipv4InterfaceAddress::SetPrimary
void SetPrimary()
Make the address primary.
Definition
ipv4-interface-address.cc:144
ns3::Ipv4InterfaceAddress::IsInSameSubnet
bool IsInSameSubnet(const Ipv4Address b) const
Checks if the address is in the same subnet.
Definition
ipv4-interface-address.cc:119
ns3::Ipv4InterfaceAddress::GetAddress
Ipv4Address GetAddress() const
Get the local address.
Definition
ipv4-interface-address.cc:71
ns3::Ipv4InterfaceAddress::m_broadcast
Ipv4Address m_broadcast
Broadcast address.
Definition
ipv4-interface-address.h:161
ns3::Ipv4InterfaceAddress::GetScope
Ipv4InterfaceAddress::InterfaceAddressScope_e GetScope() const
Get address scope.
Definition
ipv4-interface-address.cc:112
ns3::Ipv4InterfaceAddress::m_secondary
bool m_secondary
For use in multihoming.
Definition
ipv4-interface-address.h:164
ns3::Ipv4InterfaceAddress::m_mask
Ipv4Mask m_mask
Network mask.
Definition
ipv4-interface-address.h:160
ns3::Ipv4InterfaceAddress::GetLocal
Ipv4Address GetLocal() const
Get the local address.
Definition
ipv4-interface-address.cc:64
ns3::Ipv4InterfaceAddress::SetLocal
void SetLocal(Ipv4Address local)
Set local address.
Definition
ipv4-interface-address.cc:51
ns3::Ipv4InterfaceAddress::operator!=
friend bool operator!=(const Ipv4InterfaceAddress &a, const Ipv4InterfaceAddress &b)
Not equal to operator.
Definition
ipv4-interface-address.h:202
ns3::Ipv4InterfaceAddress::IsSecondary
bool IsSecondary() const
Check if the address is a secondary address.
Definition
ipv4-interface-address.cc:130
ns3::Ipv4InterfaceAddress::SetScope
void SetScope(Ipv4InterfaceAddress::InterfaceAddressScope_e scope)
Set the scope.
Definition
ipv4-interface-address.cc:105
ns3::Ipv4InterfaceAddress::Ipv4InterfaceAddress
Ipv4InterfaceAddress()
Definition
ipv4-interface-address.cc:19
ns3::Ipv4InterfaceAddress::m_local
Ipv4Address m_local
Interface address.
Definition
ipv4-interface-address.h:157
ns3::Ipv4InterfaceAddress::m_scope
InterfaceAddressScope_e m_scope
Address scope.
Definition
ipv4-interface-address.h:163
ns3::Ipv4InterfaceAddress::SetSecondary
void SetSecondary()
Make the address secondary (used for multihoming)
Definition
ipv4-interface-address.cc:137
ns3::Ipv4InterfaceAddress::SetAddress
void SetAddress(Ipv4Address address)
Set local address.
Definition
ipv4-interface-address.cc:58
ns3::Ipv4InterfaceAddress::GetBroadcast
Ipv4Address GetBroadcast() const
Get the broadcast address.
Definition
ipv4-interface-address.cc:98
ns3::Ipv4Mask
a class to represent an Ipv4 address mask
Definition
ipv4-address.h:246
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::operator!=
bool operator!=(Callback< R, Args... > a, Callback< R, Args... > b)
Inequality test.
Definition
callback.h:658
ns3::operator==
bool operator==(const EventId &a, const EventId &b)
Definition
event-id.h:155
ns3::operator<<
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition
angles.cc:148
src
internet
model
ipv4-interface-address.h
Generated on Wed Dec 4 2024 18:20:41 for ns-3 by
1.11.0