A Discrete-Event Network Simulator
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 
31  : m_scope(GLOBAL),
32  m_secondary(false)
33 {
34  NS_LOG_FUNCTION(this);
35 }
36 
38  : m_scope(GLOBAL),
39  m_secondary(false)
40 {
41  NS_LOG_FUNCTION(this << local << mask);
42  m_local = local;
44  {
45  m_scope = HOST;
46  }
47  m_mask = mask;
48  m_broadcast = Ipv4Address(local.Get() | (~mask.Get()));
49 }
50 
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
63 {
64  NS_LOG_FUNCTION(this << local);
65  m_local = local;
66 }
67 
68 void
70 {
72 }
73 
76 {
77  NS_LOG_FUNCTION(this);
78  return m_local;
79 }
80 
83 {
84  return GetLocal();
85 }
86 
87 void
89 {
90  NS_LOG_FUNCTION(this << mask);
91  m_mask = mask;
92 }
93 
96 {
97  NS_LOG_FUNCTION(this);
98  return m_mask;
99 }
100 
101 void
103 {
104  NS_LOG_FUNCTION(this << broadcast);
105  m_broadcast = broadcast;
106 }
107 
110 {
111  NS_LOG_FUNCTION(this);
112  return m_broadcast;
113 }
114 
115 void
117 {
118  NS_LOG_FUNCTION(this << scope);
119  m_scope = scope;
120 }
121 
124 {
125  NS_LOG_FUNCTION(this);
126  return m_scope;
127 }
128 
129 bool
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
142 {
143  NS_LOG_FUNCTION(this);
144  return m_secondary;
145 }
146 
147 void
149 {
150  NS_LOG_FUNCTION(this);
151  m_secondary = true;
152 }
153 
154 void
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
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
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
Definition: ipv4-address.h:257
uint32_t Get() const
Get the host-order 32-bit IP mask.
Definition: ipv4-address.cc:84
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
address
Definition: first.py:47
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:159