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.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
9
#include "
ipv4-interface-address.h
"
10
11
#include "ns3/assert.h"
12
#include "ns3/log.h"
13
14
namespace
ns3
15
{
16
17
NS_LOG_COMPONENT_DEFINE
(
"Ipv4InterfaceAddress"
);
18
19
Ipv4InterfaceAddress::Ipv4InterfaceAddress
()
20
: m_scope(GLOBAL),
21
m_secondary(false)
22
{
23
NS_LOG_FUNCTION
(
this
);
24
}
25
26
Ipv4InterfaceAddress::Ipv4InterfaceAddress
(
Ipv4Address
local,
Ipv4Mask
mask)
27
: m_scope(GLOBAL),
28
m_secondary(false)
29
{
30
NS_LOG_FUNCTION
(
this
<< local << mask);
31
m_local
= local;
32
if
(
m_local
==
Ipv4Address::GetLoopback
())
33
{
34
m_scope
=
HOST
;
35
}
36
m_mask
= mask;
37
m_broadcast
=
Ipv4Address
(local.
Get
() | (~mask.
Get
()));
38
}
39
40
Ipv4InterfaceAddress::Ipv4InterfaceAddress
(
const
Ipv4InterfaceAddress
& o)
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
50
void
51
Ipv4InterfaceAddress::SetLocal
(
Ipv4Address
local)
52
{
53
NS_LOG_FUNCTION
(
this
<< local);
54
m_local
= local;
55
}
56
57
void
58
Ipv4InterfaceAddress::SetAddress
(
Ipv4Address
address)
59
{
60
SetLocal
(address);
61
}
62
63
Ipv4Address
64
Ipv4InterfaceAddress::GetLocal
()
const
65
{
66
NS_LOG_FUNCTION
(
this
);
67
return
m_local
;
68
}
69
70
Ipv4Address
71
Ipv4InterfaceAddress::GetAddress
()
const
72
{
73
return
GetLocal
();
74
}
75
76
void
77
Ipv4InterfaceAddress::SetMask
(
Ipv4Mask
mask)
78
{
79
NS_LOG_FUNCTION
(
this
<< mask);
80
m_mask
= mask;
81
}
82
83
Ipv4Mask
84
Ipv4InterfaceAddress::GetMask
()
const
85
{
86
NS_LOG_FUNCTION
(
this
);
87
return
m_mask
;
88
}
89
90
void
91
Ipv4InterfaceAddress::SetBroadcast
(
Ipv4Address
broadcast)
92
{
93
NS_LOG_FUNCTION
(
this
<< broadcast);
94
m_broadcast
= broadcast;
95
}
96
97
Ipv4Address
98
Ipv4InterfaceAddress::GetBroadcast
()
const
99
{
100
NS_LOG_FUNCTION
(
this
);
101
return
m_broadcast
;
102
}
103
104
void
105
Ipv4InterfaceAddress::SetScope
(
Ipv4InterfaceAddress::InterfaceAddressScope_e
scope)
106
{
107
NS_LOG_FUNCTION
(
this
<< scope);
108
m_scope
= scope;
109
}
110
111
Ipv4InterfaceAddress::InterfaceAddressScope_e
112
Ipv4InterfaceAddress::GetScope
()
const
113
{
114
NS_LOG_FUNCTION
(
this
);
115
return
m_scope
;
116
}
117
118
bool
119
Ipv4InterfaceAddress::IsInSameSubnet
(
const
Ipv4Address
b)
const
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
129
bool
130
Ipv4InterfaceAddress::IsSecondary
()
const
131
{
132
NS_LOG_FUNCTION
(
this
);
133
return
m_secondary
;
134
}
135
136
void
137
Ipv4InterfaceAddress::SetSecondary
()
138
{
139
NS_LOG_FUNCTION
(
this
);
140
m_secondary
=
true
;
141
}
142
143
void
144
Ipv4InterfaceAddress::SetPrimary
()
145
{
146
NS_LOG_FUNCTION
(
this
);
147
m_secondary
=
false
;
148
}
149
150
std::ostream&
151
operator<<
(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
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition
ipv4-address.h:31
ns3::Ipv4Address::GetLoopback
static Ipv4Address GetLoopback()
Definition
ipv4-address.cc:384
ns3::Ipv4Address::CombineMask
Ipv4Address CombineMask(const Ipv4Mask &mask) const
Combine this address with a network mask.
Definition
ipv4-address.cc:206
ns3::Ipv4Address::Get
uint32_t Get() const
Get the host-order 32-bit IP address.
Definition
ipv4-address.cc:176
ns3::Ipv4InterfaceAddress
a class to store IPv4 address information on an interface
Definition
ipv4-interface-address.h:34
ns3::Ipv4InterfaceAddress::GetMask
Ipv4Mask GetMask() const
Get the network mask.
Definition
ipv4-interface-address.cc:84
ns3::Ipv4InterfaceAddress::SetMask
void SetMask(Ipv4Mask mask)
Set the network mask.
Definition
ipv4-interface-address.cc:77
ns3::Ipv4InterfaceAddress::SetBroadcast
void SetBroadcast(Ipv4Address broadcast)
Set the broadcast address.
Definition
ipv4-interface-address.cc:91
ns3::Ipv4InterfaceAddress::InterfaceAddressScope_e
InterfaceAddressScope_e
Address scope.
Definition
ipv4-interface-address.h:41
ns3::Ipv4InterfaceAddress::HOST
@ HOST
Definition
ipv4-interface-address.h:42
ns3::Ipv4InterfaceAddress::SetPrimary
void SetPrimary()
Make the address primary.
Definition
ipv4-interface-address.cc:144
ns3::Ipv4InterfaceAddress::IsInSameSubnet
bool IsInSameSubnet(const Ipv4Address b) const
Checks if the address is in the same subnet.
Definition
ipv4-interface-address.cc:119
ns3::Ipv4InterfaceAddress::GetAddress
Ipv4Address GetAddress() const
Get the local address.
Definition
ipv4-interface-address.cc:71
ns3::Ipv4InterfaceAddress::m_broadcast
Ipv4Address m_broadcast
Broadcast address.
Definition
ipv4-interface-address.h:161
ns3::Ipv4InterfaceAddress::GetScope
Ipv4InterfaceAddress::InterfaceAddressScope_e GetScope() const
Get address scope.
Definition
ipv4-interface-address.cc:112
ns3::Ipv4InterfaceAddress::m_secondary
bool m_secondary
For use in multihoming.
Definition
ipv4-interface-address.h:164
ns3::Ipv4InterfaceAddress::m_mask
Ipv4Mask m_mask
Network mask.
Definition
ipv4-interface-address.h:160
ns3::Ipv4InterfaceAddress::GetLocal
Ipv4Address GetLocal() const
Get the local address.
Definition
ipv4-interface-address.cc:64
ns3::Ipv4InterfaceAddress::SetLocal
void SetLocal(Ipv4Address local)
Set local address.
Definition
ipv4-interface-address.cc:51
ns3::Ipv4InterfaceAddress::IsSecondary
bool IsSecondary() const
Check if the address is a secondary address.
Definition
ipv4-interface-address.cc:130
ns3::Ipv4InterfaceAddress::SetScope
void SetScope(Ipv4InterfaceAddress::InterfaceAddressScope_e scope)
Set the scope.
Definition
ipv4-interface-address.cc:105
ns3::Ipv4InterfaceAddress::Ipv4InterfaceAddress
Ipv4InterfaceAddress()
Definition
ipv4-interface-address.cc:19
ns3::Ipv4InterfaceAddress::m_local
Ipv4Address m_local
Interface address.
Definition
ipv4-interface-address.h:157
ns3::Ipv4InterfaceAddress::m_scope
InterfaceAddressScope_e m_scope
Address scope.
Definition
ipv4-interface-address.h:163
ns3::Ipv4InterfaceAddress::SetSecondary
void SetSecondary()
Make the address secondary (used for multihoming)
Definition
ipv4-interface-address.cc:137
ns3::Ipv4InterfaceAddress::SetAddress
void SetAddress(Ipv4Address address)
Set local address.
Definition
ipv4-interface-address.cc:58
ns3::Ipv4InterfaceAddress::GetBroadcast
Ipv4Address GetBroadcast() const
Get the broadcast address.
Definition
ipv4-interface-address.cc:98
ns3::Ipv4Mask
a class to represent an Ipv4 address mask
Definition
ipv4-address.h:246
ns3::Ipv4Mask::Get
uint32_t Get() const
Get the host-order 32-bit IP mask.
Definition
ipv4-address.cc:74
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:191
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition
log-macros-enabled.h:229
ipv4-interface-address.h
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::operator<<
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition
angles.cc:148
src
internet
model
ipv4-interface-address.cc
Generated on Fri Nov 8 2024 13:59:01 for ns-3 by
1.11.0