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 * 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
16namespace 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 */
34{
35 public:
36 /**
37 * @enum InterfaceAddressScope_e
38 * @brief Address scope.
39 */
46
48
49 /**
50 * @brief Configure local address, mask and broadcast address
51 * @param local the local address
52 * @param mask the network mask
53 */
55 /**
56 * Copy constructor
57 * @param o the object to copy
58 */
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 Functionally 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 Functionally 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 /**
106 * @brief Get the network mask
107 * @returns the network mask
108 */
109 Ipv4Mask GetMask() const;
110
111 /**
112 * @brief Get the broadcast address
113 * @returns the broadcast address
114 */
116
117 /**
118 * @brief Set the scope.
119 * @param scope the scope of address
120 */
122
123 /**
124 * @brief Get address scope.
125 * @return scope
126 */
128
129 /**
130 * @brief Checks if the address is in the same subnet.
131 * @param b the address to check
132 * @return true if the address is in the same subnet.
133 */
134 bool IsInSameSubnet(const Ipv4Address b) const;
135
136 private:
137 Ipv4Address m_local; //!< Interface address
138 // Note: m_peer may be added in future when necessary
139 // Ipv4Address m_peer; // Peer destination address (in Linux: m_address)
140 uint8_t m_prefixLength{24}; //!< Network mask length
141
143
144 /**
145 * @brief Equal to operator.
146 *
147 * @param a the first operand
148 * @param b the first operand
149 * @returns true if the operands are equal
150 */
151 friend bool operator==(const Ipv4InterfaceAddress& a, const Ipv4InterfaceAddress& b);
152};
153
154/**
155 * @brief Stream insertion operator.
156 *
157 * @param os the reference to the output stream
158 * @param addr the Ipv4InterfaceAddress
159 * @returns the reference to the output stream
160 */
161std::ostream& operator<<(std::ostream& os, const Ipv4InterfaceAddress& addr);
162
163inline bool
165{
166 return (a.m_local == b.m_local && a.m_prefixLength == b.m_prefixLength &&
167 a.m_scope == b.m_scope);
168}
169
170} // namespace ns3
171
172#endif /* IPV4_ADDRESS_H */
Ipv4 addresses are stored in host order in this class.
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.
bool IsInSameSubnet(const Ipv4Address b) const
Checks if the address is in the same subnet.
Ipv4Address GetAddress() const
Get the local address.
Ipv4InterfaceAddress::InterfaceAddressScope_e GetScope() const
Get address scope.
Ipv4Address GetLocal() const
Get the local address.
void SetLocal(Ipv4Address local)
Set local address.
uint8_t m_prefixLength
Network mask length.
void SetScope(Ipv4InterfaceAddress::InterfaceAddressScope_e scope)
Set the scope.
Ipv4Address m_local
Interface address.
InterfaceAddressScope_e m_scope
Address scope.
void SetAddress(Ipv4Address address)
Set local address.
Ipv4Address GetBroadcast() const
Get the broadcast address.
a class to represent an Ipv4 address mask
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool operator==(const EventId &a, const EventId &b)
Definition event-id.h:167
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition angles.cc:148