A Discrete-Event Network Simulator
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
27namespace 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 */
45{
46 public:
47 /**
48 * \enum InterfaceAddressScope_e
49 * \brief Address scope.
50 */
52 {
55 GLOBAL
56 };
57
59
60 /**
61 * \brief Configure local address, mask and broadcast address
62 * \param local the local address
63 * \param mask the network mask
64 */
66 /**
67 * Copy constructor
68 * \param o the object to copy
69 */
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 */
130
131 /**
132 * \brief Set the scope.
133 * \param scope the scope of address
134 */
136
137 /**
138 * \brief Get address scope.
139 * \return scope
140 */
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
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 */
203std::ostream& operator<<(std::ostream& os, const Ipv4InterfaceAddress& addr);
204
205inline bool
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
212inline bool
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 */
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
a class to store IPv4 address information on an interface
Ipv4Mask GetMask() const
Get the network mask.
friend bool operator==(const Ipv4InterfaceAddress &a, const Ipv4InterfaceAddress &b)
Equal to operator.
void SetMask(Ipv4Mask mask)
Set the network mask.
void SetBroadcast(Ipv4Address broadcast)
Set the broadcast address.
void SetPrimary()
Make the address primary.
bool IsInSameSubnet(const Ipv4Address b) const
Checks if the address is in the same subnet.
Ipv4Address GetAddress() const
Get the local address.
Ipv4Address m_broadcast
Broadcast address.
Ipv4InterfaceAddress::InterfaceAddressScope_e GetScope() const
Get address scope.
bool m_secondary
For use in multihoming.
Ipv4Address GetLocal() const
Get the local address.
void SetLocal(Ipv4Address local)
Set local address.
friend bool operator!=(const Ipv4InterfaceAddress &a, const Ipv4InterfaceAddress &b)
Not equal to operator.
bool IsSecondary() const
Check if the address is a secondary address.
void SetScope(Ipv4InterfaceAddress::InterfaceAddressScope_e scope)
Set the scope.
Ipv4Address m_local
Interface address.
InterfaceAddressScope_e m_scope
Address scope.
void SetSecondary()
Make the address secondary (used for multihoming)
void SetAddress(Ipv4Address address)
Set local address.
Ipv4Address GetBroadcast() const
Get the broadcast address.
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:257
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:678
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.h:157
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:159