A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
ipv4-interface-address.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2005 INRIA
3
*
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2 as
6
* published by the Free Software Foundation;
7
*
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
*
17
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18
*/
19
20
#include "
ipv4-interface-address.h
"
21
22
#include "ns3/assert.h"
23
#include "ns3/log.h"
24
25
namespace
ns3
26
{
27
28
NS_LOG_COMPONENT_DEFINE
(
"Ipv4InterfaceAddress"
);
29
30
Ipv4InterfaceAddress::Ipv4InterfaceAddress
()
31
: m_scope(GLOBAL),
32
m_secondary(false)
33
{
34
NS_LOG_FUNCTION
(
this
);
35
}
36
37
Ipv4InterfaceAddress::Ipv4InterfaceAddress
(
Ipv4Address
local,
Ipv4Mask
mask)
38
: m_scope(GLOBAL),
39
m_secondary(false)
40
{
41
NS_LOG_FUNCTION
(
this
<< local << mask);
42
m_local
= local;
43
if
(
m_local
==
Ipv4Address::GetLoopback
())
44
{
45
m_scope
=
HOST
;
46
}
47
m_mask
= mask;
48
m_broadcast
=
Ipv4Address
(local.
Get
() | (~mask.
Get
()));
49
}
50
51
Ipv4InterfaceAddress::Ipv4InterfaceAddress
(
const
Ipv4InterfaceAddress
& o)
52
: m_local(o.m_local),
53
m_mask(o.m_mask),
54
m_broadcast(o.m_broadcast),
55
m_scope(o.m_scope),
56
m_secondary(o.m_secondary)
57
{
58
NS_LOG_FUNCTION
(
this
<< &o);
59
}
60
61
void
62
Ipv4InterfaceAddress::SetLocal
(
Ipv4Address
local)
63
{
64
NS_LOG_FUNCTION
(
this
<< local);
65
m_local
= local;
66
}
67
68
void
69
Ipv4InterfaceAddress::SetAddress
(
Ipv4Address
address
)
70
{
71
SetLocal
(
address
);
72
}
73
74
Ipv4Address
75
Ipv4InterfaceAddress::GetLocal
()
const
76
{
77
NS_LOG_FUNCTION
(
this
);
78
return
m_local
;
79
}
80
81
Ipv4Address
82
Ipv4InterfaceAddress::GetAddress
()
const
83
{
84
return
GetLocal
();
85
}
86
87
void
88
Ipv4InterfaceAddress::SetMask
(
Ipv4Mask
mask)
89
{
90
NS_LOG_FUNCTION
(
this
<< mask);
91
m_mask
= mask;
92
}
93
94
Ipv4Mask
95
Ipv4InterfaceAddress::GetMask
()
const
96
{
97
NS_LOG_FUNCTION
(
this
);
98
return
m_mask
;
99
}
100
101
void
102
Ipv4InterfaceAddress::SetBroadcast
(
Ipv4Address
broadcast)
103
{
104
NS_LOG_FUNCTION
(
this
<< broadcast);
105
m_broadcast
= broadcast;
106
}
107
108
Ipv4Address
109
Ipv4InterfaceAddress::GetBroadcast
()
const
110
{
111
NS_LOG_FUNCTION
(
this
);
112
return
m_broadcast
;
113
}
114
115
void
116
Ipv4InterfaceAddress::SetScope
(
Ipv4InterfaceAddress::InterfaceAddressScope_e
scope)
117
{
118
NS_LOG_FUNCTION
(
this
<< scope);
119
m_scope
= scope;
120
}
121
122
Ipv4InterfaceAddress::InterfaceAddressScope_e
123
Ipv4InterfaceAddress::GetScope
()
const
124
{
125
NS_LOG_FUNCTION
(
this
);
126
return
m_scope
;
127
}
128
129
bool
130
Ipv4InterfaceAddress::IsInSameSubnet
(
const
Ipv4Address
b)
const
131
{
132
Ipv4Address
aAddr =
m_local
;
133
aAddr = aAddr.
CombineMask
(
m_mask
);
134
Ipv4Address
bAddr = b;
135
bAddr = bAddr.
CombineMask
(
m_mask
);
136
137
return
(aAddr == bAddr);
138
}
139
140
bool
141
Ipv4InterfaceAddress::IsSecondary
()
const
142
{
143
NS_LOG_FUNCTION
(
this
);
144
return
m_secondary
;
145
}
146
147
void
148
Ipv4InterfaceAddress::SetSecondary
()
149
{
150
NS_LOG_FUNCTION
(
this
);
151
m_secondary
=
true
;
152
}
153
154
void
155
Ipv4InterfaceAddress::SetPrimary
()
156
{
157
NS_LOG_FUNCTION
(
this
);
158
m_secondary
=
false
;
159
}
160
161
std::ostream&
162
operator<<
(std::ostream& os,
const
Ipv4InterfaceAddress
& addr)
163
{
164
os <<
"m_local="
<< addr.
GetLocal
() <<
"; m_mask="
<< addr.
GetMask
()
165
<<
"; m_broadcast="
<< addr.
GetBroadcast
() <<
"; m_scope="
<< addr.
GetScope
()
166
<<
"; m_secondary="
<< addr.
IsSecondary
();
167
return
os;
168
}
169
170
}
// namespace ns3
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition:
ipv4-address.h:42
ns3::Ipv4Address::GetLoopback
static Ipv4Address GetLoopback()
Definition:
ipv4-address.cc:394
ns3::Ipv4Address::CombineMask
Ipv4Address CombineMask(const Ipv4Mask &mask) const
Combine this address with a network mask.
Definition:
ipv4-address.cc:216
ns3::Ipv4Address::Get
uint32_t Get() const
Get the host-order 32-bit IP address.
Definition:
ipv4-address.cc:186
ns3::Ipv4InterfaceAddress
a class to store IPv4 address information on an interface
Definition:
ipv4-interface-address.h:45
ns3::Ipv4InterfaceAddress::GetMask
Ipv4Mask GetMask() const
Get the network mask.
Definition:
ipv4-interface-address.cc:95
ns3::Ipv4InterfaceAddress::SetMask
void SetMask(Ipv4Mask mask)
Set the network mask.
Definition:
ipv4-interface-address.cc:88
ns3::Ipv4InterfaceAddress::SetBroadcast
void SetBroadcast(Ipv4Address broadcast)
Set the broadcast address.
Definition:
ipv4-interface-address.cc:102
ns3::Ipv4InterfaceAddress::InterfaceAddressScope_e
InterfaceAddressScope_e
Address scope.
Definition:
ipv4-interface-address.h:52
ns3::Ipv4InterfaceAddress::HOST
@ HOST
Definition:
ipv4-interface-address.h:53
ns3::Ipv4InterfaceAddress::SetPrimary
void SetPrimary()
Make the address primary.
Definition:
ipv4-interface-address.cc:155
ns3::Ipv4InterfaceAddress::IsInSameSubnet
bool IsInSameSubnet(const Ipv4Address b) const
Checks if the address is in the same subnet.
Definition:
ipv4-interface-address.cc:130
ns3::Ipv4InterfaceAddress::GetAddress
Ipv4Address GetAddress() const
Get the local address.
Definition:
ipv4-interface-address.cc:82
ns3::Ipv4InterfaceAddress::m_broadcast
Ipv4Address m_broadcast
Broadcast address.
Definition:
ipv4-interface-address.h:172
ns3::Ipv4InterfaceAddress::GetScope
Ipv4InterfaceAddress::InterfaceAddressScope_e GetScope() const
Get address scope.
Definition:
ipv4-interface-address.cc:123
ns3::Ipv4InterfaceAddress::m_secondary
bool m_secondary
For use in multihoming.
Definition:
ipv4-interface-address.h:175
ns3::Ipv4InterfaceAddress::m_mask
Ipv4Mask m_mask
Network mask.
Definition:
ipv4-interface-address.h:171
ns3::Ipv4InterfaceAddress::GetLocal
Ipv4Address GetLocal() const
Get the local address.
Definition:
ipv4-interface-address.cc:75
ns3::Ipv4InterfaceAddress::SetLocal
void SetLocal(Ipv4Address local)
Set local address.
Definition:
ipv4-interface-address.cc:62
ns3::Ipv4InterfaceAddress::IsSecondary
bool IsSecondary() const
Check if the address is a secondary address.
Definition:
ipv4-interface-address.cc:141
ns3::Ipv4InterfaceAddress::SetScope
void SetScope(Ipv4InterfaceAddress::InterfaceAddressScope_e scope)
Set the scope.
Definition:
ipv4-interface-address.cc:116
ns3::Ipv4InterfaceAddress::Ipv4InterfaceAddress
Ipv4InterfaceAddress()
Definition:
ipv4-interface-address.cc:30
ns3::Ipv4InterfaceAddress::m_local
Ipv4Address m_local
Interface address.
Definition:
ipv4-interface-address.h:168
ns3::Ipv4InterfaceAddress::m_scope
InterfaceAddressScope_e m_scope
Address scope.
Definition:
ipv4-interface-address.h:174
ns3::Ipv4InterfaceAddress::SetSecondary
void SetSecondary()
Make the address secondary (used for multihoming)
Definition:
ipv4-interface-address.cc:148
ns3::Ipv4InterfaceAddress::SetAddress
void SetAddress(Ipv4Address address)
Set local address.
Definition:
ipv4-interface-address.cc:69
ns3::Ipv4InterfaceAddress::GetBroadcast
Ipv4Address GetBroadcast() const
Get the broadcast address.
Definition:
ipv4-interface-address.cc:109
ns3::Ipv4Mask
a class to represent an Ipv4 address mask
Definition:
ipv4-address.h:257
ns3::Ipv4Mask::Get
uint32_t Get() const
Get the host-order 32-bit IP mask.
Definition:
ipv4-address.cc:84
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:202
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:240
ipv4-interface-address.h
first.address
address
Definition:
first.py:47
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:159
src
internet
model
ipv4-interface-address.cc
Generated on Sun Mar 3 2024 17:10:58 for ns-3 by
1.9.1