A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv4-interface-address.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2005 INRIA
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 */
8
10
11#include "ns3/assert.h"
12#include "ns3/log.h"
13
14namespace ns3
15{
16
17NS_LOG_COMPONENT_DEFINE("Ipv4InterfaceAddress");
18
25
27 : m_scope(GLOBAL),
28 m_secondary(false)
29{
30 NS_LOG_FUNCTION(this << local << mask);
31 m_local = local;
33 {
34 m_scope = HOST;
35 }
36 m_mask = mask;
37}
38
47
48void
50{
51 NS_LOG_FUNCTION(this << local);
52 m_local = local;
53}
54
55void
60
63{
64 NS_LOG_FUNCTION(this);
65 return m_local;
66}
67
70{
71 return GetLocal();
72}
73
74void
76{
77 NS_LOG_FUNCTION(this << mask);
78 m_mask = mask;
79}
80
83{
84 NS_LOG_FUNCTION(this);
85 return m_mask;
86}
87
90{
91 NS_LOG_FUNCTION(this);
92 return Ipv4Address(m_local.Get() | (~m_mask.Get()));
93}
94
95void
101
104{
105 NS_LOG_FUNCTION(this);
106 return m_scope;
107}
108
109bool
111{
112 Ipv4Address aAddr = m_local;
113 aAddr = aAddr.CombineMask(m_mask);
114 Ipv4Address bAddr = b;
115 bAddr = bAddr.CombineMask(m_mask);
116
117 return (aAddr == bAddr);
118}
119
120bool
122{
123 NS_LOG_FUNCTION(this);
124 return m_secondary;
125}
126
127void
133
134void
140
141std::ostream&
142operator<<(std::ostream& os, const Ipv4InterfaceAddress& addr)
143{
144 os << "m_local=" << addr.GetLocal() << "; m_mask=" << addr.GetMask()
145 << "; m_broadcast=" << addr.GetBroadcast() << "; m_scope=" << addr.GetScope()
146 << "; m_secondary=" << addr.IsSecondary();
147 return os;
148}
149
150} // namespace ns3
Ipv4 addresses are stored in host order in this class.
static Ipv4Address GetLoopback()
Ipv4Address CombineMask(const Ipv4Mask &mask) const
Combine this address with a network mask.
a class to store IPv4 address information on an interface
Ipv4Mask GetMask() const
Get the network mask.
void SetMask(Ipv4Mask mask)
Set the network mask.
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.
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.
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
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:194
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition angles.cc:148