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
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2 as
6
* published by the Free Software Foundation;
7
*
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
*
17
*/
18
19
#ifndef IPV4_INTERFACE_ADDRESS_H
20
#define IPV4_INTERFACE_ADDRESS_H
21
22
#include "ns3/ipv4-address.h"
23
24
#include <ostream>
25
#include <stdint.h>
26
27
namespace
ns3
28
{
29
30
/**
31
* \ingroup address
32
* \ingroup ipv4
33
*
34
* \brief a class to store IPv4 address information on an interface
35
*
36
* Corresponds to Linux struct in_ifaddr. A list of these addresses
37
* is stored in Ipv4Interface. This class is modelled after how current
38
* Linux handles IP aliasing for IPv4. Notably, aliasing of IPv4
39
* interfaces (e.g., "eth0:1") is not used, and instead an interface
40
* is assigned possibly multiple addresses, with each address being
41
* classified as being primary and secondary. See the iproute2
42
* documentation for this distinction.
43
*/
44
class
Ipv4InterfaceAddress
45
{
46
public
:
47
/**
48
* \enum InterfaceAddressScope_e
49
* \brief Address scope.
50
*/
51
enum
InterfaceAddressScope_e
52
{
53
HOST
,
54
LINK
,
55
GLOBAL
56
};
57
58
Ipv4InterfaceAddress
();
59
60
/**
61
* \brief Configure local address, mask and broadcast address
62
* \param local the local address
63
* \param mask the network mask
64
*/
65
Ipv4InterfaceAddress
(
Ipv4Address
local,
Ipv4Mask
mask);
66
/**
67
* Copy constructor
68
* \param o the object to copy
69
*/
70
Ipv4InterfaceAddress
(
const
Ipv4InterfaceAddress
& o);
71
72
/**
73
* \brief Set local address
74
* \param local the address
75
*
76
* \note Functionally identical to `Ipv4InterfaceAddress::SetAddress`.
77
* The method corresponds to the linux variable in_ifaddr.ifa_local
78
* `Ipv4InterfaceAddress::SetAddress` is to be preferred.
79
*/
80
void
SetLocal
(
Ipv4Address
local);
81
82
/**
83
* \brief Set local address
84
* \param address the address
85
*
86
* \note Functially identical to `Ipv4InterfaceAddress::SetLocal`.
87
* This function is consistent with `Ipv6InterfaceAddress::SetAddress`.
88
*/
89
void
SetAddress
(
Ipv4Address
address);
90
91
/**
92
* \brief Get the local address
93
* \returns the local address
94
*
95
* \note Functionally identical to `Ipv4InterfaceAddress::GetAddress`.
96
* The method corresponds to the linux variable in_ifaddr.ifa_local
97
* `Ipv4InterfaceAddress::GetAddress` is to be preferred.
98
*/
99
Ipv4Address
GetLocal
()
const
;
100
101
/**
102
* \brief Get the local address
103
* \returns the local address
104
*
105
* \note Functially identical to `Ipv4InterfaceAddress::GetLocal`.
106
* This function is consistent with `Ipv6InterfaceAddress::GetAddress`.
107
*/
108
Ipv4Address
GetAddress
()
const
;
109
110
/**
111
* \brief Set the network mask
112
* \param mask the network mask
113
*/
114
void
SetMask
(
Ipv4Mask
mask);
115
/**
116
* \brief Get the network mask
117
* \returns the network mask
118
*/
119
Ipv4Mask
GetMask
()
const
;
120
/**
121
* \brief Set the broadcast address
122
* \param broadcast the broadcast address
123
*/
124
void
SetBroadcast
(
Ipv4Address
broadcast);
125
/**
126
* \brief Get the broadcast address
127
* \returns the broadcast address
128
*/
129
Ipv4Address
GetBroadcast
()
const
;
130
131
/**
132
* \brief Set the scope.
133
* \param scope the scope of address
134
*/
135
void
SetScope
(
Ipv4InterfaceAddress::InterfaceAddressScope_e
scope);
136
137
/**
138
* \brief Get address scope.
139
* \return scope
140
*/
141
Ipv4InterfaceAddress::InterfaceAddressScope_e
GetScope
()
const
;
142
143
/**
144
* \brief Checks if the address is in the same subnet.
145
* \param b the address to check
146
* \return true if the address is in the same subnet.
147
*/
148
bool
IsInSameSubnet
(
const
Ipv4Address
b)
const
;
149
150
/**
151
* \brief Check if the address is a secondary address
152
*
153
* Secondary address is used for multihoming
154
* \returns true if the address is secondary
155
*/
156
bool
IsSecondary
()
const
;
157
158
/**
159
* \brief Make the address secondary (used for multihoming)
160
*/
161
void
SetSecondary
();
162
/**
163
* \brief Make the address primary
164
*/
165
void
SetPrimary
();
166
167
private
:
168
Ipv4Address
m_local
;
//!< Interface address
169
// Note: m_peer may be added in future when necessary
170
// Ipv4Address m_peer; // Peer destination address (in Linux: m_address)
171
Ipv4Mask
m_mask
;
//!< Network mask
172
Ipv4Address
m_broadcast
;
//!< Broadcast address
173
174
InterfaceAddressScope_e
m_scope
;
//!< Address scope
175
bool
m_secondary
;
//!< For use in multihoming
176
177
/**
178
* \brief Equal to operator.
179
*
180
* \param a the first operand
181
* \param b the first operand
182
* \returns true if the operands are equal
183
*/
184
friend
bool
operator==
(
const
Ipv4InterfaceAddress
& a,
const
Ipv4InterfaceAddress
& b);
185
186
/**
187
* \brief Not equal to operator.
188
*
189
* \param a the first operand
190
* \param b the first operand
191
* \returns true if the operands are not equal
192
*/
193
friend
bool
operator!=
(
const
Ipv4InterfaceAddress
& a,
const
Ipv4InterfaceAddress
& b);
194
};
195
196
/**
197
* \brief Stream insertion operator.
198
*
199
* \param os the reference to the output stream
200
* \param addr the Ipv4InterfaceAddress
201
* \returns the reference to the output stream
202
*/
203
std::ostream&
operator<<
(std::ostream& os,
const
Ipv4InterfaceAddress
& addr);
204
205
inline
bool
206
operator==
(
const
Ipv4InterfaceAddress
& a,
const
Ipv4InterfaceAddress
& b)
207
{
208
return
(a.
m_local
== b.
m_local
&& a.
m_mask
== b.
m_mask
&& a.
m_broadcast
== b.
m_broadcast
&&
209
a.
m_scope
== b.
m_scope
&& a.
m_secondary
== b.
m_secondary
);
210
}
211
212
inline
bool
213
operator!=
(
const
Ipv4InterfaceAddress
& a,
const
Ipv4InterfaceAddress
& b)
214
{
215
return
(a.
m_local
!= b.
m_local
|| a.
m_mask
!= b.
m_mask
|| a.
m_broadcast
!= b.
m_broadcast
||
216
a.
m_scope
!= b.
m_scope
|| a.
m_secondary
!= b.
m_secondary
);
217
}
218
219
}
// namespace ns3
220
221
#endif
/* IPV4_ADDRESS_H */
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition:
ipv4-address.h:42
ns3::Ipv4InterfaceAddress
a class to store IPv4 address information on an interface
Definition:
ipv4-interface-address.h:45
ns3::Ipv4InterfaceAddress::GetMask
Ipv4Mask GetMask() const
Get the network mask.
Definition:
ipv4-interface-address.cc:95
ns3::Ipv4InterfaceAddress::operator==
friend bool operator==(const Ipv4InterfaceAddress &a, const Ipv4InterfaceAddress &b)
Equal to operator.
Definition:
ipv4-interface-address.h:206
ns3::Ipv4InterfaceAddress::SetMask
void SetMask(Ipv4Mask mask)
Set the network mask.
Definition:
ipv4-interface-address.cc:88
ns3::Ipv4InterfaceAddress::SetBroadcast
void SetBroadcast(Ipv4Address broadcast)
Set the broadcast address.
Definition:
ipv4-interface-address.cc:102
ns3::Ipv4InterfaceAddress::InterfaceAddressScope_e
InterfaceAddressScope_e
Address scope.
Definition:
ipv4-interface-address.h:52
ns3::Ipv4InterfaceAddress::LINK
@ LINK
Definition:
ipv4-interface-address.h:54
ns3::Ipv4InterfaceAddress::HOST
@ HOST
Definition:
ipv4-interface-address.h:53
ns3::Ipv4InterfaceAddress::GLOBAL
@ GLOBAL
Definition:
ipv4-interface-address.h:55
ns3::Ipv4InterfaceAddress::SetPrimary
void SetPrimary()
Make the address primary.
Definition:
ipv4-interface-address.cc:155
ns3::Ipv4InterfaceAddress::IsInSameSubnet
bool IsInSameSubnet(const Ipv4Address b) const
Checks if the address is in the same subnet.
Definition:
ipv4-interface-address.cc:130
ns3::Ipv4InterfaceAddress::GetAddress
Ipv4Address GetAddress() const
Get the local address.
Definition:
ipv4-interface-address.cc:82
ns3::Ipv4InterfaceAddress::m_broadcast
Ipv4Address m_broadcast
Broadcast address.
Definition:
ipv4-interface-address.h:172
ns3::Ipv4InterfaceAddress::GetScope
Ipv4InterfaceAddress::InterfaceAddressScope_e GetScope() const
Get address scope.
Definition:
ipv4-interface-address.cc:123
ns3::Ipv4InterfaceAddress::m_secondary
bool m_secondary
For use in multihoming.
Definition:
ipv4-interface-address.h:175
ns3::Ipv4InterfaceAddress::m_mask
Ipv4Mask m_mask
Network mask.
Definition:
ipv4-interface-address.h:171
ns3::Ipv4InterfaceAddress::GetLocal
Ipv4Address GetLocal() const
Get the local address.
Definition:
ipv4-interface-address.cc:75
ns3::Ipv4InterfaceAddress::SetLocal
void SetLocal(Ipv4Address local)
Set local address.
Definition:
ipv4-interface-address.cc:62
ns3::Ipv4InterfaceAddress::operator!=
friend bool operator!=(const Ipv4InterfaceAddress &a, const Ipv4InterfaceAddress &b)
Not equal to operator.
Definition:
ipv4-interface-address.h:213
ns3::Ipv4InterfaceAddress::IsSecondary
bool IsSecondary() const
Check if the address is a secondary address.
Definition:
ipv4-interface-address.cc:141
ns3::Ipv4InterfaceAddress::SetScope
void SetScope(Ipv4InterfaceAddress::InterfaceAddressScope_e scope)
Set the scope.
Definition:
ipv4-interface-address.cc:116
ns3::Ipv4InterfaceAddress::Ipv4InterfaceAddress
Ipv4InterfaceAddress()
Definition:
ipv4-interface-address.cc:30
ns3::Ipv4InterfaceAddress::m_local
Ipv4Address m_local
Interface address.
Definition:
ipv4-interface-address.h:168
ns3::Ipv4InterfaceAddress::m_scope
InterfaceAddressScope_e m_scope
Address scope.
Definition:
ipv4-interface-address.h:174
ns3::Ipv4InterfaceAddress::SetSecondary
void SetSecondary()
Make the address secondary (used for multihoming)
Definition:
ipv4-interface-address.cc:148
ns3::Ipv4InterfaceAddress::SetAddress
void SetAddress(Ipv4Address address)
Set local address.
Definition:
ipv4-interface-address.cc:69
ns3::Ipv4InterfaceAddress::GetBroadcast
Ipv4Address GetBroadcast() const
Get the broadcast address.
Definition:
ipv4-interface-address.cc:109
ns3::Ipv4Mask
a class to represent an Ipv4 address mask
Definition:
ipv4-address.h:257
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:674
ns3::operator==
bool operator==(const EventId &a, const EventId &b)
Definition:
event-id.h:166
ns3::operator<<
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition:
angles.cc:159
src
internet
model
ipv4-interface-address.h
Generated on Tue May 28 2024 23:35:47 for ns-3 by
1.9.6