A Discrete-Event Network Simulator
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 
30  : m_scope (GLOBAL),
31  m_secondary (false)
32 {
33  NS_LOG_FUNCTION (this);
34 }
35 
37  : m_scope (GLOBAL),
38  m_secondary (false)
39 {
40  NS_LOG_FUNCTION (this << local << mask);
41  m_local = local;
43  {
44  m_scope = HOST;
45  }
46  m_mask = mask;
47  m_broadcast = Ipv4Address (local.Get () | (~mask.Get ()));
48 }
49 
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
62 {
63  NS_LOG_FUNCTION (this << local);
64  m_local = local;
65 }
66 
69 {
70  NS_LOG_FUNCTION (this);
71  return m_local;
72 }
73 
74 void
76 {
77  NS_LOG_FUNCTION (this << mask);
78  m_mask = mask;
79 }
80 
81 Ipv4Mask
83 {
84  NS_LOG_FUNCTION (this);
85  return m_mask;
86 }
87 
88 void
90 {
91  NS_LOG_FUNCTION (this << broadcast);
92  m_broadcast = broadcast;
93 }
94 
97 {
98  NS_LOG_FUNCTION (this);
99  return m_broadcast;
100 }
101 
102 void
104 {
105  NS_LOG_FUNCTION (this << scope);
106  m_scope = scope;
107 }
108 
111 {
112  NS_LOG_FUNCTION (this);
113  return m_scope;
114 }
115 
116 bool
118 {
119  NS_LOG_FUNCTION (this);
120  return m_secondary;
121 }
122 
123 void
125 {
126  NS_LOG_FUNCTION (this);
127  m_secondary = true;
128 }
129 
130 void
132 {
133  NS_LOG_FUNCTION (this);
134  m_secondary = false;
135 }
136 
137 std::ostream& operator<< (std::ostream& os, const Ipv4InterfaceAddress &addr)
138 {
139  os << "m_local=" << addr.GetLocal () << "; m_mask=" <<
140  addr.GetMask () << "; m_broadcast=" << addr.GetBroadcast () << "; m_scope=" << addr.GetScope () <<
141  "; m_secondary=" << addr.IsSecondary ();
142  return os;
143 }
144 
145 } // namespace ns3
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
uint32_t Get(void) const
Get the host-order 32-bit IP address.
static Ipv4Address GetLoopback(void)
a class to store IPv4 address information on an interface
void SetMask(Ipv4Mask mask)
Set the network mask.
Ipv4Address GetBroadcast(void) const
Get the broadcast address.
void SetSecondary(void)
Make the address secondary (used for multihoming)
void SetBroadcast(Ipv4Address broadcast)
Set the broadcast address.
Ipv4InterfaceAddress::InterfaceAddressScope_e GetScope(void) const
Get address scope.
Ipv4Address m_broadcast
Broadcast address.
bool m_secondary
For use in multihoming.
void SetLocal(Ipv4Address local)
Set local address.
Ipv4Mask GetMask(void) const
Get the network mask.
Ipv4Address GetLocal(void) const
Get the local address.
bool IsSecondary(void) 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 SetPrimary(void)
Make the address primary.
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:269
uint32_t Get(void) const
Get the host-order 32-bit IP mask.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
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:137