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