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
}
38
39
Ipv4InterfaceAddress::Ipv4InterfaceAddress
(
const
Ipv4InterfaceAddress
& o)
40
:
m_local
(o.
m_local
),
41
m_mask
(o.
m_mask
),
42
m_scope
(o.
m_scope
),
43
m_secondary
(o.
m_secondary
)
44
{
45
NS_LOG_FUNCTION
(
this
<< &o);
46
}
47
48
void
49
Ipv4InterfaceAddress::SetLocal
(
Ipv4Address
local)
50
{
51
NS_LOG_FUNCTION
(
this
<< local);
52
m_local
= local;
53
}
54
55
void
56
Ipv4InterfaceAddress::SetAddress
(
Ipv4Address
address)
57
{
58
SetLocal
(address);
59
}
60
61
Ipv4Address
62
Ipv4InterfaceAddress::GetLocal
()
const
63
{
64
NS_LOG_FUNCTION
(
this
);
65
return
m_local
;
66
}
67
68
Ipv4Address
69
Ipv4InterfaceAddress::GetAddress
()
const
70
{
71
return
GetLocal
();
72
}
73
74
void
75
Ipv4InterfaceAddress::SetMask
(
Ipv4Mask
mask)
76
{
77
NS_LOG_FUNCTION
(
this
<< mask);
78
m_mask
= mask;
79
}
80
81
Ipv4Mask
82
Ipv4InterfaceAddress::GetMask
()
const
83
{
84
NS_LOG_FUNCTION
(
this
);
85
return
m_mask
;
86
}
87
88
Ipv4Address
89
Ipv4InterfaceAddress::GetBroadcast
()
const
90
{
91
NS_LOG_FUNCTION
(
this
);
92
return
Ipv4Address
(
m_local
.Get() | (~
m_mask
.Get()));
93
}
94
95
void
96
Ipv4InterfaceAddress::SetScope
(
Ipv4InterfaceAddress::InterfaceAddressScope_e
scope)
97
{
98
NS_LOG_FUNCTION
(
this
<< scope);
99
m_scope
= scope;
100
}
101
102
Ipv4InterfaceAddress::InterfaceAddressScope_e
103
Ipv4InterfaceAddress::GetScope
()
const
104
{
105
NS_LOG_FUNCTION
(
this
);
106
return
m_scope
;
107
}
108
109
bool
110
Ipv4InterfaceAddress::IsInSameSubnet
(
const
Ipv4Address
b)
const
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
120
bool
121
Ipv4InterfaceAddress::IsSecondary
()
const
122
{
123
NS_LOG_FUNCTION
(
this
);
124
return
m_secondary
;
125
}
126
127
void
128
Ipv4InterfaceAddress::SetSecondary
()
129
{
130
NS_LOG_FUNCTION
(
this
);
131
m_secondary
=
true
;
132
}
133
134
void
135
Ipv4InterfaceAddress::SetPrimary
()
136
{
137
NS_LOG_FUNCTION
(
this
);
138
m_secondary
=
false
;
139
}
140
141
std::ostream&
142
operator<<
(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
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition
ipv4-address.h:32
ns3::Ipv4Address::GetLoopback
static Ipv4Address GetLoopback()
Definition
ipv4-address.cc:385
ns3::Ipv4Address::CombineMask
Ipv4Address CombineMask(const Ipv4Mask &mask) const
Combine this address with a network mask.
Definition
ipv4-address.cc:199
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:82
ns3::Ipv4InterfaceAddress::SetMask
void SetMask(Ipv4Mask mask)
Set the network mask.
Definition
ipv4-interface-address.cc:75
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::GLOBAL
@ GLOBAL
Definition
ipv4-interface-address.h:44
ns3::Ipv4InterfaceAddress::SetPrimary
void SetPrimary()
Make the address primary.
Definition
ipv4-interface-address.cc:135
ns3::Ipv4InterfaceAddress::IsInSameSubnet
bool IsInSameSubnet(const Ipv4Address b) const
Checks if the address is in the same subnet.
Definition
ipv4-interface-address.cc:110
ns3::Ipv4InterfaceAddress::GetAddress
Ipv4Address GetAddress() const
Get the local address.
Definition
ipv4-interface-address.cc:69
ns3::Ipv4InterfaceAddress::GetScope
Ipv4InterfaceAddress::InterfaceAddressScope_e GetScope() const
Get address scope.
Definition
ipv4-interface-address.cc:103
ns3::Ipv4InterfaceAddress::m_secondary
bool m_secondary
For use in multihoming.
Definition
ipv4-interface-address.h:160
ns3::Ipv4InterfaceAddress::m_mask
Ipv4Mask m_mask
Network mask.
Definition
ipv4-interface-address.h:157
ns3::Ipv4InterfaceAddress::GetLocal
Ipv4Address GetLocal() const
Get the local address.
Definition
ipv4-interface-address.cc:62
ns3::Ipv4InterfaceAddress::SetLocal
void SetLocal(Ipv4Address local)
Set local address.
Definition
ipv4-interface-address.cc:49
ns3::Ipv4InterfaceAddress::IsSecondary
bool IsSecondary() const
Check if the address is a secondary address.
Definition
ipv4-interface-address.cc:121
ns3::Ipv4InterfaceAddress::SetScope
void SetScope(Ipv4InterfaceAddress::InterfaceAddressScope_e scope)
Set the scope.
Definition
ipv4-interface-address.cc:96
ns3::Ipv4InterfaceAddress::Ipv4InterfaceAddress
Ipv4InterfaceAddress()
Definition
ipv4-interface-address.cc:19
ns3::Ipv4InterfaceAddress::m_local
Ipv4Address m_local
Interface address.
Definition
ipv4-interface-address.h:154
ns3::Ipv4InterfaceAddress::m_scope
InterfaceAddressScope_e m_scope
Address scope.
Definition
ipv4-interface-address.h:159
ns3::Ipv4InterfaceAddress::SetSecondary
void SetSecondary()
Make the address secondary (used for multihoming).
Definition
ipv4-interface-address.cc:128
ns3::Ipv4InterfaceAddress::SetAddress
void SetAddress(Ipv4Address address)
Set local address.
Definition
ipv4-interface-address.cc:56
ns3::Ipv4InterfaceAddress::GetBroadcast
Ipv4Address GetBroadcast() const
Get the broadcast address.
Definition
ipv4-interface-address.cc:89
ns3::Ipv4Mask
a class to represent an Ipv4 address mask
Definition
ipv4-address.h:275
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:194
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:231
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
for ns-3 by
1.15.0