A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ns3::Ipv4Address Class Reference

Ipv4 addresses are stored in host order in this class. More...

#include "ipv4-address.h"

+ Collaboration diagram for ns3::Ipv4Address:

Public Member Functions

 Ipv4Address ()
 
 Ipv4Address (const char *address)
 Constructs an Ipv4Address by parsing a the input C-string.
 
 Ipv4Address (uint32_t address)
 input address is in host order.
 
Ipv4Address CombineMask (const Ipv4Mask &mask) const
 Combine this address with a network mask.
 
Address ConvertTo () const
 Convert to an Address type.
 
uint32_t Get () const
 Get the host-order 32-bit IP address.
 
Ipv4Address GetSubnetDirectedBroadcast (const Ipv4Mask &mask) const
 Generate subnet-directed broadcast address corresponding to mask.
 
bool IsAny () const
 
bool IsBroadcast () const
 
bool IsInitialized () const
 
bool IsLocalhost () const
 
bool IsLocalMulticast () const
 
bool IsMulticast () const
 
bool IsSubnetDirectedBroadcast (const Ipv4Mask &mask) const
 Generate subnet-directed broadcast address corresponding to mask.
 
 operator Address () const
 Convert an instance of this class to a polymorphic Address instance.
 
void Print (std::ostream &os) const
 Print this address to the given output stream.
 
void Serialize (uint8_t buf[4]) const
 Serialize this address to a 4-byte buffer.
 
void Set (const char *address)
 Sets an Ipv4Address by parsing a the input C-string.
 
void Set (uint32_t address)
 input address is in host order.
 

Static Public Member Functions

static Ipv4Address ConvertFrom (const Address &address)
 
static Ipv4Address Deserialize (const uint8_t buf[4])
 
static Ipv4Address GetAny ()
 
static Ipv4Address GetBroadcast ()
 
static Ipv4Address GetLoopback ()
 
static Ipv4Address GetZero ()
 
static bool IsMatchingType (const Address &address)
 

Static Private Member Functions

static uint8_t GetType ()
 Get the underlying address type (automatically assigned).
 

Private Attributes

uint32_t m_address
 IPv4 address.
 
bool m_initialized
 IPv4 address has been explicitly initialized to a valid value.
 

Friends

bool operator!= (const Ipv4Address &a, const Ipv4Address &b)
 Not equal to operator.
 
bool operator< (const Ipv4Address &a, const Ipv4Address &b)
 Less than to operator.
 
bool operator== (const Ipv4Address &a, const Ipv4Address &b)
 Equal to operator.
 

Detailed Description

Ipv4 addresses are stored in host order in this class.

See also
Ipv4Address Attribute

Definition at line 30 of file ipv4-address.h.

Constructor & Destructor Documentation

◆ Ipv4Address() [1/3]

ns3::Ipv4Address::Ipv4Address ( )

Definition at line 146 of file ipv4-address.cc.

References NS_LOG_FUNCTION.

Referenced by CombineMask(), and GetSubnetDirectedBroadcast().

+ Here is the caller graph for this function:

◆ Ipv4Address() [2/3]

ns3::Ipv4Address::Ipv4Address ( uint32_t address)
explicit

input address is in host order.

Parameters
addressThe host order 32-bit address

Definition at line 153 of file ipv4-address.cc.

References m_address, m_initialized, and NS_LOG_FUNCTION.

◆ Ipv4Address() [3/3]

ns3::Ipv4Address::Ipv4Address ( const char * address)

Constructs an Ipv4Address by parsing a the input C-string.

Input address is in format: hhh.xxx.xxx.lll where h is the high byte and l the low byte

Parameters
addressC-string containing the address as described above

Definition at line 160 of file ipv4-address.cc.

References m_address, m_initialized, NS_LOG_FUNCTION, and NS_LOG_LOGIC.

Member Function Documentation

◆ CombineMask()

Ipv4Address ns3::Ipv4Address::CombineMask ( const Ipv4Mask & mask) const

Combine this address with a network mask.

This method returns an IPv4 address that is this address combined (bitwise and) with a network mask, yielding an IPv4 network address.

Parameters
maska network mask
Returns
the address combined with the mask

Definition at line 206 of file ipv4-address.cc.

References Ipv4Address(), Get(), ns3::Ipv4Mask::Get(), and NS_LOG_FUNCTION.

Referenced by ns3::IpcsClassifierRecord::CheckMatchDstAddr(), ns3::IpcsClassifierRecord::CheckMatchSrcAddr(), ns3::Rip::DoSendRouteUpdate(), ns3::Rip::HandleRequests(), ns3::Rip::HandleResponses(), ns3::Ipv4InterfaceAddress::IsInSameSubnet(), ns3::Ipv4AddressGeneratorImpl::IsNetworkAllocated(), ns3::Ipv4L3ClickProtocol::LocalDeliver(), ns3::Ipv4L3Protocol::LocalDeliver(), ns3::Ipv4EndPointDemux::Lookup(), ns3::Ipv4StaticRouting::NotifyInterfaceUp(), ns3::GlobalRouter::ProcessBridgedBroadcastLink(), ns3::GlobalRouter::ProcessSingleBroadcastLink(), ns3::Ipv4L3ClickProtocol::SelectSourceAddress(), ns3::Ipv4L3Protocol::SelectSourceAddress(), ns3::Ipv4L3Protocol::Send(), ns3::Ipv4L3ClickProtocol::SourceAddressSelection(), ns3::Ipv4L3Protocol::SourceAddressSelection(), ns3::GlobalRouteManagerImpl::SPFAddASExternal(), ns3::GlobalRouteManagerImpl::SPFIntraAddStub(), and ns3::GlobalRouteManagerImpl::SPFIntraAddTransit().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ConvertFrom()

Ipv4Address ns3::Ipv4Address::ConvertFrom ( const Address & address)
static
Parameters
addressa polymorphic address
Returns
a new Ipv4Address from the polymorphic address

This function performs a type check and asserts if the type of the input address is not compatible with an Ipv4Address.

Definition at line 342 of file ipv4-address.cc.

References Deserialize(), GetType(), NS_ASSERT, and NS_LOG_FUNCTION.

Referenced by PingTestCase::DoRun(), ns3::UdpSocketImpl::DoSend(), ns3::UdpSocketImpl::GetPeerName(), ns3::addressUtils::IsMulticast(), ns3::ThreeGppHttpClient::OpenConnection(), ns3::PbbAddressBlockIpv4::PrintAddress(), ns3::PbbMessageIpv4::PrintOriginatorAddress(), ns3::Ping::PrintReport(), ns3::Ping::Send(), ns3::UdpEchoClient::Send(), ns3::TcpL4Protocol::SendPacket(), ns3::UdpTraceClient::SendPacket(), ns3::PbbAddressBlockIpv4::SerializeAddress(), ns3::PbbMessageIpv4::SerializeOriginatorAddress(), ns3::Ping::StartApplication(), ns3::ThreeGppHttpServer::StartApplication(), ns3::UdpClient::StartApplication(), ns3::UdpEchoClient::StartApplication(), and ns3::UdpTraceClient::StartApplication().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ConvertTo()

Address ns3::Ipv4Address::ConvertTo ( ) const

Convert to an Address type.

Returns
the Address corresponding to this object.

Definition at line 333 of file ipv4-address.cc.

References GetType(), NS_LOG_FUNCTION, and Serialize().

+ Here is the call graph for this function:

◆ Deserialize()

Ipv4Address ns3::Ipv4Address::Deserialize ( const uint8_t buf[4])
static
Parameters
bufbuffer to read address from
Returns
an Ipv4Address

The input address is expected to be in network byte order format.

Definition at line 295 of file ipv4-address.cc.

References NS_LOG_FUNCTION.

Referenced by ns3::InetSocketAddress::ConvertFrom(), ConvertFrom(), ns3::dsr::DsrOptionRrepHeader::Deserialize(), ns3::dsr::DsrOptionRreqHeader::Deserialize(), ns3::dsr::DsrOptionSRHeader::Deserialize(), ns3::Ipv4FlowProbeTag::Deserialize(), ns3::Ipv4PacketInfoTag::Deserialize(), ns3::PbbAddressBlockIpv4::DeserializeAddress(), ns3::PbbMessageIpv4::DeserializeOriginatorAddress(), and ns3::Ipv6Address::GetIpv4MappedAddress().

+ Here is the caller graph for this function:

◆ Get()

◆ GetAny()

Ipv4Address ns3::Ipv4Address::GetAny ( )
static
Returns
the 0.0.0.0 address

Definition at line 368 of file ipv4-address.cc.

References NS_LOG_FUNCTION_NOARGS.

Referenced by ns3::DhcpClient::DhcpClient(), ns3::DhcpClient::DhcpClient(), ns3::Ipv4RawSocketImpl::Ipv4RawSocketImpl(), ns3::NoBackhaulEpcHelper::NoBackhaulEpcHelper(), Tunnel::Tunnel(), ns3::Ipv4EndPointDemux::Allocate(), ns3::Ipv4EndPointDemux::Allocate(), ns3::Ipv4RawSocketImpl::Bind(), ns3::TcpSocketBase::Bind(), ns3::UdpSocketImpl::Bind(), BuildAppsTest(), BuildAppsTest(), Bug772ChainTest::CreateDevices(), ChainRegressionTest::CreateDevices(), ns3::olsr::Bug780Test::CreateNodes(), ns3::olsr::RoutingProtocol::DoInitialize(), BriteTopologyFunctionTestCase::DoRun(), BulkSendBasicTestCase::DoRun(), BulkSendSeqTsSizeTestCase::DoRun(), CsmaBridgeTestCase::DoRun(), CsmaBroadcastTestCase::DoRun(), CsmaMulticastTestCase::DoRun(), CsmaOneSubnetTestCase::DoRun(), CsmaStarTestCase::DoRun(), DualStackTestCase::DoRun(), EpcS1uDlTestCase::DoRun(), EpcS1uUlTestCase::DoRun(), IcmpEchoReplyTestCase::DoRun(), IcmpTimeExceedTestCase::DoRun(), Ipv4DeduplicationPerformanceTest::DoRun(), Ipv4DeduplicationTest::DoRun(), Ipv4DynamicGlobalRoutingTestCase::DoRun(), Ipv4PacketInfoTagTest::DoRun(), LenaCqaFfMacSchedulerTestCase1::DoRun(), LenaCqaFfMacSchedulerTestCase2::DoRun(), LenaFdTbfqFfMacSchedulerTestCase1::DoRun(), LenaFdTbfqFfMacSchedulerTestCase2::DoRun(), LenaPssFfMacSchedulerTestCase1::DoRun(), LenaPssFfMacSchedulerTestCase2::DoRun(), LenaTdTbfqFfMacSchedulerTestCase1::DoRun(), LenaTdTbfqFfMacSchedulerTestCase2::DoRun(), LteDistributedFfrAreaTestCase::DoRun(), LteEpcE2eDataTestCase::DoRun(), LteRadioLinkFailureTestCase::DoRun(), LteX2HandoverMeasuresTestCase::DoRun(), LteX2HandoverTestCase::DoRun(), ns3::LenaDeactivateBearerTestCase::DoRun(), ns3::TcpGeneralTest::DoRun(), Ns3TcpCubicTestCase::DoRun(), Ns3TcpLossTestCase::DoRun(), Ns3TcpNoDelayTestCase::DoRun(), Ns3TcpSocketTestCaseCsma::DoRun(), Ns3TcpSocketTestCaseP2P::DoRun(), Ns3TcpStateTestCase::DoRun(), TcpEndPointBug2211Test::DoRun(), UdpSocketLoopbackTest::DoRun(), WifiAcMappingTest::DoRun(), WifiMsduAggregatorThroughputTest::DoRun(), ns3::Rip::DoSendRouteUpdate(), ns3::UdpSocketImpl::DoSendTo(), experiment(), ns3::Ipv4RawSocketImpl::ForwardUp(), ns3::Ipv4RawSocketImpl::GetPeerName(), ns3::Rip::HandleRequests(), FlameRegressionTest::InstallApplications(), HwmpDoRfRegressionTest::InstallApplications(), HwmpProactiveRegressionTest::InstallApplications(), HwmpReactiveRegressionTest::InstallApplications(), HwmpSimplestRegressionTest::InstallApplications(), InstallPacketSink(), ns3::Ipv4L3Protocol::IpMulticastForward(), ns3::Ipv4EndPointDemux::Lookup(), ns3::dsdv::RoutingProtocol::NotifyAddAddress(), ns3::dsdv::RoutingProtocol::NotifyInterfaceUp(), ns3::dsdv::RoutingProtocol::NotifyRemoveAddress(), Experiment::Run(), NeighborCacheExample::Run(), ns3::Ipv4L3Protocol::Send(), ns3::Rip::SendRouteRequest(), ns3::Ipv4RawSocketImpl::SendTo(), TcpTestCase::SetupDefaultSim(), ns3::Ipv4EndPointDemux::SimpleLookup(), ns3::DhcpClient::StartApplication(), ns3::DhcpServer::StartApplication(), ns3::UdpEchoServer::StartApplication(), ns3::UdpServer::StartApplication(), ns3::V4TraceRoute::StartApplication(), Receiver::StartApplication(), and Ipv4FragmentationTest::StartServer().

◆ GetBroadcast()

Ipv4Address ns3::Ipv4Address::GetBroadcast ( )
static
Returns
the 255.255.255.255 address

Definition at line 376 of file ipv4-address.cc.

References NS_LOG_FUNCTION_NOARGS.

Referenced by PingTestSuite::PingTestSuite(), IsSubnetDirectedBroadcast(), ns3::ArpL3Protocol::SendArpRequest(), Ipv4FragmentationTest::SendClient(), ns3::aodv::RoutingProtocol::SendRerrMessage(), and ns3::dsr::DsrRouting::Start().

+ Here is the caller graph for this function:

◆ GetLoopback()

◆ GetSubnetDirectedBroadcast()

Ipv4Address ns3::Ipv4Address::GetSubnetDirectedBroadcast ( const Ipv4Mask & mask) const

Generate subnet-directed broadcast address corresponding to mask.

The subnet-directed broadcast address has the host bits set to all ones. If this method is called with a mask of 255.255.255.255, (i.e., the address is a /32 address), the program will assert, since there is no subnet associated with a /32 address.

Parameters
maska network mask
Returns
a broadcast address for the subnet.

Definition at line 213 of file ipv4-address.cc.

References Ipv4Address(), Get(), ns3::Ipv4Mask::GetInverse(), ns3::Ipv4Mask::GetOnes(), NS_ASSERT_MSG, and NS_LOG_FUNCTION.

Referenced by ns3::Ipv4FlowProbe::DropLogger(), and ns3::olsr::RoutingProtocol::SendPacket().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetType()

uint8_t ns3::Ipv4Address::GetType ( )
staticprivate

Get the underlying address type (automatically assigned).

Returns
the address type

Definition at line 352 of file ipv4-address.cc.

References NS_LOG_FUNCTION_NOARGS, and ns3::Address::Register().

Referenced by ConvertFrom(), ConvertTo(), and IsMatchingType().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetZero()

◆ IsAny()

bool ns3::Ipv4Address::IsAny ( ) const
Returns
true if address is 0.0.0.0; false otherwise

Definition at line 245 of file ipv4-address.cc.

References m_address, and NS_LOG_FUNCTION.

Referenced by ns3::Rip::Lookup(), ns3::Ipv4L3Protocol::Send(), and ns3::Ipv4RawSocketImpl::SendTo().

+ Here is the caller graph for this function:

◆ IsBroadcast()

◆ IsInitialized()

bool ns3::Ipv4Address::IsInitialized ( ) const
Returns
true if address is initialized (i.e., set to something), false otherwise

Definition at line 238 of file ipv4-address.cc.

References m_initialized, and NS_LOG_FUNCTION.

Referenced by ns3::V4TraceRoute::StartApplication().

+ Here is the caller graph for this function:

◆ IsLocalhost()

bool ns3::Ipv4Address::IsLocalhost ( ) const
Returns
true if address is 127.0.0.1; false otherwise

Definition at line 252 of file ipv4-address.cc.

References m_address, and NS_LOG_FUNCTION.

◆ IsLocalMulticast()

bool ns3::Ipv4Address::IsLocalMulticast ( ) const
Returns
true only if address is in local multicast address scope, 224.0.0.0/24

Definition at line 277 of file ipv4-address.cc.

References m_address, and NS_LOG_FUNCTION.

Referenced by ns3::Rip::Lookup(), ns3::Ipv4StaticRouting::LookupStatic(), and ns3::Ipv4L3Protocol::Send().

+ Here is the caller graph for this function:

◆ IsMatchingType()

bool ns3::Ipv4Address::IsMatchingType ( const Address & address)
static
Parameters
addressan address to compare type with
Returns
true if the type of the address stored internally is compatible with the type of the input address, false otherwise.

Definition at line 321 of file ipv4-address.cc.

References GetType(), and NS_LOG_FUNCTION.

Referenced by ns3::TcpHeader::CalculateHeaderChecksum(), ns3::UdpHeader::CalculateHeaderChecksum(), ns3::UdpSocketImpl::DoSend(), ns3::UdpSocketImpl::GetPeerName(), ns3::addressUtils::IsMulticast(), ns3::ThreeGppHttpClient::OpenConnection(), ns3::Ping::PrintReport(), ns3::UdpEchoClient::Send(), ns3::TcpL4Protocol::SendPacket(), ns3::UdpTraceClient::SendPacket(), ns3::Ping::StartApplication(), ns3::ThreeGppHttpServer::StartApplication(), ns3::UdpClient::StartApplication(), ns3::UdpEchoClient::StartApplication(), and ns3::UdpTraceClient::StartApplication().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IsMulticast()

◆ IsSubnetDirectedBroadcast()

bool ns3::Ipv4Address::IsSubnetDirectedBroadcast ( const Ipv4Mask & mask) const

Generate subnet-directed broadcast address corresponding to mask.

The subnet-directed broadcast address has the host bits set to all ones. If this method is called with a mask of 255.255.255.255, (i.e., the address is a /32 address), the program will assert, since there is no subnet associated with a /32 address.

Parameters
maska network mask
Returns
true if the address, when combined with the input mask, has all of its host bits set to one

Definition at line 225 of file ipv4-address.cc.

References Get(), ns3::Ipv4Mask::Get(), GetBroadcast(), ns3::Ipv4Mask::GetOnes(), and NS_LOG_FUNCTION.

Referenced by ns3::Ipv4L3Protocol::IsUnicast(), ns3::Ipv4L3ClickProtocol::LocalDeliver(), ns3::Ipv4L3Protocol::LocalDeliver(), ns3::Ipv4Interface::Send(), and ns3::Ipv4L3Protocol::Send().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator Address()

ns3::Ipv4Address::operator Address ( ) const

Convert an instance of this class to a polymorphic Address instance.

Returns
a new Address instance

Definition at line 327 of file ipv4-address.cc.

◆ Print()

void ns3::Ipv4Address::Print ( std::ostream & os) const

Print this address to the given output stream.

The print format is in the typical "192.168.1.1"

Parameters
osThe output stream to which this Ipv4Address is printed

Definition at line 313 of file ipv4-address.cc.

References m_address, and NS_LOG_FUNCTION.

Referenced by ns3::Ipv4ClickRouting::GetIpAddressFromInterfaceId(), ns3::PbbAddressBlockIpv4::PrintAddress(), ns3::PbbMessageIpv4::PrintOriginatorAddress(), and ns3::Ipv4ClickRouting::RouteOutput().

+ Here is the caller graph for this function:

◆ Serialize()

void ns3::Ipv4Address::Serialize ( uint8_t buf[4]) const

Serialize this address to a 4-byte buffer.

Parameters
bufoutput buffer to which this address gets overwritten with this Ipv4Address

Definition at line 285 of file ipv4-address.cc.

References m_address, and NS_LOG_FUNCTION.

Referenced by ns3::InetSocketAddress::ConvertTo(), ConvertTo(), ns3::Mac48Address::GetMulticast(), ns3::ArpQueueDiscItem::Hash(), ns3::Ipv4QueueDiscItem::Hash(), ns3::Ipv6Address::MakeIpv4MappedAddress(), ns3::Ipv4FlowProbeTag::Serialize(), ns3::Ipv4PacketInfoTag::Serialize(), ns3::PbbAddressBlockIpv4::SerializeAddress(), and ns3::PbbMessageIpv4::SerializeOriginatorAddress().

+ Here is the caller graph for this function:

◆ Set() [1/2]

void ns3::Ipv4Address::Set ( const char * address)

Sets an Ipv4Address by parsing a the input C-string.

Input address is in format: hhh.xxx.xxx.lll where h is the high byte and l the low byte

Parameters
addressC-string containing the address as described above

Definition at line 191 of file ipv4-address.cc.

References m_address, m_initialized, NS_LOG_FUNCTION, and NS_LOG_LOGIC.

◆ Set() [2/2]

void ns3::Ipv4Address::Set ( uint32_t address)

input address is in host order.

Parameters
addressThe host order 32-bit address

Definition at line 183 of file ipv4-address.cc.

References m_address, m_initialized, and NS_LOG_FUNCTION.

Referenced by EpcTftClassifierTestSuite::EpcTftClassifierTestSuite(), ns3::GlobalRouter::GlobalRouter(), ns3::Ipv4Header::Deserialize(), ns3::RipRte::Deserialize(), ns3::GtpcIes::DeserializeFteid(), ns3::GlobalRouter::ProcessBridgedBroadcastLink(), ns3::GlobalRouter::ProcessSingleBroadcastLink(), and ns3::ReadFrom().

+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ operator!=

bool operator!= ( const Ipv4Address & a,
const Ipv4Address & b )
friend

Not equal to operator.

Parameters
athe first operand.
bthe first operand.
Returns
true if the operands are not equal.

Definition at line 373 of file ipv4-address.h.

◆ operator<

bool operator< ( const Ipv4Address & a,
const Ipv4Address & b )
friend

Less than to operator.

Parameters
athe first operand.
bthe first operand.
Returns
true if the first operand is less than the second.

Definition at line 378 of file ipv4-address.h.

◆ operator==

bool operator== ( const Ipv4Address & a,
const Ipv4Address & b )
friend

Equal to operator.

Parameters
athe first operand.
bthe first operand.
Returns
true if the operands are equal.

Definition at line 367 of file ipv4-address.h.

Member Data Documentation

◆ m_address

uint32_t ns3::Ipv4Address::m_address
private

◆ m_initialized

bool ns3::Ipv4Address::m_initialized
private

IPv4 address has been explicitly initialized to a valid value.

Definition at line 204 of file ipv4-address.h.

Referenced by Ipv4Address(), Ipv4Address(), IsInitialized(), Set(), and Set().


The documentation for this class was generated from the following files: