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
20 : m_scope(GLOBAL),
21 m_secondary(false)
22{
23 NS_LOG_FUNCTION(this);
24}
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 m_broadcast = Ipv4Address(local.Get() | (~mask.Get()));
38}
39
41 : m_local(o.m_local),
42 m_mask(o.m_mask),
43 m_broadcast(o.m_broadcast),
44 m_scope(o.m_scope),
45 m_secondary(o.m_secondary)
46{
47 NS_LOG_FUNCTION(this << &o);
48}
49
50void
52{
53 NS_LOG_FUNCTION(this << local);
54 m_local = local;
55}
56
57void
62
65{
66 NS_LOG_FUNCTION(this);
67 return m_local;
68}
69
72{
73 return GetLocal();
74}
75
76void
78{
79 NS_LOG_FUNCTION(this << mask);
80 m_mask = mask;
81}
82
85{
86 NS_LOG_FUNCTION(this);
87 return m_mask;
88}
89
90void
92{
93 NS_LOG_FUNCTION(this << broadcast);
94 m_broadcast = broadcast;
95}
96
99{
100 NS_LOG_FUNCTION(this);
101 return m_broadcast;
102}
103
104void
110
113{
114 NS_LOG_FUNCTION(this);
115 return m_scope;
116}
117
118bool
120{
121 Ipv4Address aAddr = m_local;
122 aAddr = aAddr.CombineMask(m_mask);
123 Ipv4Address bAddr = b;
124 bAddr = bAddr.CombineMask(m_mask);
125
126 return (aAddr == bAddr);
127}
128
129bool
131{
132 NS_LOG_FUNCTION(this);
133 return m_secondary;
134}
135
136void
142
143void
149
150std::ostream&
151operator<<(std::ostream& os, const Ipv4InterfaceAddress& addr)
152{
153 os << "m_local=" << addr.GetLocal() << "; m_mask=" << addr.GetMask()
154 << "; m_broadcast=" << addr.GetBroadcast() << "; m_scope=" << addr.GetScope()
155 << "; m_secondary=" << addr.IsSecondary();
156 return os;
157}
158
159} // 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.
uint32_t Get() const
Get the host-order 32-bit IP address.
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 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.
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
uint32_t Get() const
Get the host-order 32-bit IP mask.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#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