Deprecate IsEqual for Ipv[4,6]Address, Ipv6Prefix, and Ipv4Mask

This commit is contained in:
Tommaso Pecorella
2020-02-15 19:22:05 +01:00
parent 6a27f55505
commit 8b91e2fbe9
13 changed files with 87 additions and 32 deletions

View File

@@ -228,7 +228,7 @@ ArpL3Protocol::Receive (Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t pro
break;
}
else if (arp.IsReply () &&
arp.GetDestinationIpv4Address ().IsEqual (cache->GetInterface ()->GetAddress (i).GetLocal ()) &&
arp.GetDestinationIpv4Address () == cache->GetInterface ()->GetAddress (i).GetLocal () &&
arp.GetDestinationHardwareAddress () == device->GetAddress ())
{
found = true;

View File

@@ -798,7 +798,7 @@ void Icmpv6L4Protocol::HandleRedirection (Ptr<Packet> packet, Ipv6Address const
{
entry = cache->Add (redirTarget);
/* destination and target different => necessarily a router */
entry->SetRouter (!redirTarget.IsEqual (redirDestination) ? true : false);
entry->SetRouter (redirTarget != redirDestination);
entry->SetMacAddress (llOptionHeader.GetAddress ());
entry->MarkStale ();
}
@@ -823,7 +823,7 @@ void Icmpv6L4Protocol::HandleRedirection (Ptr<Packet> packet, Ipv6Address const
/* add redirection in routing table */
Ptr<Ipv6> ipv6 = m_node->GetObject<Ipv6> ();
if (redirTarget.IsEqual (redirDestination))
if (redirTarget == redirDestination)
{
ipv6->GetRoutingProtocol ()->NotifyAddRoute (redirDestination, Ipv6Prefix (128), Ipv6Address ("::"), ipv6->GetInterfaceForAddress (dst));
}

View File

@@ -152,7 +152,7 @@ Ipv4GlobalRouting::LookupGlobal (Ipv4Address dest, Ptr<NetDevice> oif)
i++)
{
NS_ASSERT ((*i)->IsHost ());
if ((*i)->GetDest ().IsEqual (dest))
if ((*i)->GetDest () == dest)
{
if (oif != 0)
{

View File

@@ -954,7 +954,7 @@ Ipv4L3Protocol::SendRealOut (Ptr<Ipv4Route> route,
Ptr<Ipv4Interface> outInterface = GetInterface (interface);
NS_LOG_LOGIC ("Send via NetDevice ifIndex " << outDev->GetIfIndex () << " ipv4InterfaceIndex " << interface);
if (!route->GetGateway ().IsEqual (Ipv4Address ("0.0.0.0")))
if (route->GetGateway () != Ipv4Address ("0.0.0.0"))
{
if (outInterface->IsUp ())
{

View File

@@ -96,7 +96,7 @@ bool
Ipv4RoutingTableEntry::IsHost (void) const
{
NS_LOG_FUNCTION (this);
if (m_destNetworkMask.IsEqual (Ipv4Mask::GetOnes ()))
if (m_destNetworkMask == Ipv4Mask::GetOnes ())
{
return true;
}
@@ -121,7 +121,7 @@ bool
Ipv4RoutingTableEntry::IsDefault (void) const
{
NS_LOG_FUNCTION (this);
if (m_dest.IsEqual (Ipv4Address::GetZero ()))
if (m_dest == Ipv4Address::GetZero ())
{
return true;
}
@@ -146,7 +146,7 @@ bool
Ipv4RoutingTableEntry::IsGateway (void) const
{
NS_LOG_FUNCTION (this);
if (m_gateway.IsEqual (Ipv4Address::GetZero ()))
if (m_gateway == Ipv4Address::GetZero ())
{
return false;
}

View File

@@ -1064,7 +1064,7 @@ void Ipv6L3Protocol::Receive (Ptr<NetDevice> device, Ptr<const Packet> p, uint16
{
Ipv6InterfaceAddress iaddr = GetAddress (j, i);
Ipv6Address addr = iaddr.GetAddress ();
if (addr.IsEqual (hdr.GetDestinationAddress ()))
if (addr == hdr.GetDestinationAddress ())
{
if (j == interface)
{
@@ -1164,7 +1164,7 @@ void Ipv6L3Protocol::SendRealOut (Ptr<Ipv6Route> route, Ptr<Packet> packet, Ipv6
ipv6Fragment->GetFragments (packet, ipHeader, targetMtu, fragments);
}
if (!route->GetGateway ().IsEqual (Ipv6Address::GetAny ()))
if (route->GetGateway () != Ipv6Address::GetAny ())
{
if (outInterface->IsUp ())
{

View File

@@ -108,7 +108,7 @@ Ipv6RoutingTableEntry::~Ipv6RoutingTableEntry ()
bool Ipv6RoutingTableEntry::IsHost () const
{
if (m_destNetworkPrefix.IsEqual (Ipv6Prefix::GetOnes ()))
if (m_destNetworkPrefix == Ipv6Prefix::GetOnes ())
{
return true;
}
@@ -137,7 +137,7 @@ bool Ipv6RoutingTableEntry::IsNetwork () const
bool Ipv6RoutingTableEntry::IsDefault () const
{
if (m_dest.IsEqual (Ipv6Address::GetZero ()))
if (m_dest == Ipv6Address::GetZero ())
{
return true;
}
@@ -156,7 +156,7 @@ Ipv6Prefix Ipv6RoutingTableEntry::GetDestNetworkPrefix () const
bool Ipv6RoutingTableEntry::IsGateway () const
{
if (m_gateway.IsEqual (Ipv6Address::GetZero ()))
if (m_gateway == Ipv6Address::GetZero ())
{
return false;
}

View File

@@ -185,7 +185,11 @@ void LteIpv6RoutingTestCase::Checker ()
sourcePort = udpHeader2.GetSourcePort ();
destinationPort = udpHeader2.GetDestinationPort ();
//Check whether the uids, addresses and ports match
if ((p2->GetUid () == p1->GetUid ()) && sorceAddress.IsEqual (ipv6header1.GetDestinationAddress ()) && destinationAddress.IsEqual (ipv6header1.GetSourceAddress ()) && sourcePort == udpHeader1.GetDestinationPort () && destinationPort == udpHeader1.GetSourcePort ())
if ((p2->GetUid () == p1->GetUid ())
&& sorceAddress == ipv6header1.GetDestinationAddress ()
&& destinationAddress == ipv6header1.GetSourceAddress ()
&& sourcePort == udpHeader1.GetDestinationPort ()
&& destinationPort == udpHeader1.GetSourcePort ())
{
b = true;
break;

View File

@@ -436,15 +436,6 @@ std::istream & operator >> (std::istream &is, Ipv4Mask &mask)
return is;
}
bool operator == (Ipv4Mask const &a, Ipv4Mask const &b)
{
return a.IsEqual (b);
}
bool operator != (Ipv4Mask const &a, Ipv4Mask const &b)
{
return !a.IsEqual (b);
}
ATTRIBUTE_HELPER_CPP (Ipv4Address);
ATTRIBUTE_HELPER_CPP (Ipv4Mask);

View File

@@ -25,6 +25,7 @@
#include <ostream>
#include "ns3/address.h"
#include "ns3/attribute-helper.h"
#include "ns3/deprecated.h"
namespace ns3 {
@@ -77,9 +78,13 @@ public:
void Set (char const *address);
/**
* \brief Comparison operation between two Ipv4Addresses
*
* \deprecated Use the == operator (same functionality)
*
* \param other address to which to compare this address
* \return True if the addresses are equal. False otherwise.
*/
NS_DEPRECATED_3_31
bool IsEqual (const Ipv4Address &other) const
{
return m_address == other.m_address;
@@ -279,9 +284,13 @@ public:
*/
bool IsMatch (Ipv4Address a, Ipv4Address b) const;
/**
*
* \deprecated Use the == operator (same functionality)
*
* \param other a mask to compare
* \return true if the mask equals the mask passed as input parameter
*/
NS_DEPRECATED_3_31
bool IsEqual (Ipv4Mask other) const;
/**
* Get the host-order 32-bit IP mask
@@ -322,6 +331,25 @@ public:
*/
static Ipv4Mask GetOnes (void);
/**
* \brief Equal to operator.
*
* \param a the first operand.
* \param b the first operand.
* \returns true if the operands are equal.
*/
friend bool operator == (Ipv4Mask const &a, Ipv4Mask const &b);
/**
* \brief Not equal to operator.
*
* \param a the first operand.
* \param b the first operand.
* \returns true if the operands are not equal.
*/
friend bool operator != (Ipv4Mask const &a, Ipv4Mask const &b);
private:
uint32_t m_mask; //!< IP mask
};
@@ -418,7 +446,11 @@ public:
* \param b the first operand
* \returns true if the operands are equal
*/
bool operator == (Ipv4Mask const &a, Ipv4Mask const &b);
inline bool operator == (Ipv4Mask const &a, Ipv4Mask const &b)
{
return (a.m_mask == b.m_mask);
}
/**
* \brief Not equal to operator.
*
@@ -426,7 +458,11 @@ bool operator == (Ipv4Mask const &a, Ipv4Mask const &b);
* \param b the first operand
* \returns true if the operands are not equal
*/
bool operator != (Ipv4Mask const &a, Ipv4Mask const &b);
inline bool operator != (Ipv4Mask const &a, Ipv4Mask const &b)
{
return (a.m_mask != b.m_mask);
}
} // namespace ns3

View File

@@ -729,7 +729,7 @@ bool Ipv6Address::IsIpv4MappedAddress () const
return (false);
}
Ipv6Address Ipv6Address::CombinePrefix (Ipv6Prefix const& prefix)
Ipv6Address Ipv6Address::CombinePrefix (Ipv6Prefix const& prefix) const
{
NS_LOG_FUNCTION (this << prefix);
Ipv6Address ipv6;
@@ -811,6 +811,16 @@ bool Ipv6Address::IsDocumentation () const
return false;
}
bool Ipv6Address::HasPrefix (Ipv6Prefix const& prefix) const
{
NS_LOG_FUNCTION (this << prefix);
Ipv6Address masked = CombinePrefix (prefix);
Ipv6Address reference = Ipv6Address::GetOnes ().CombinePrefix (prefix);
return (masked == reference);
}
bool Ipv6Address::IsMatchingType (const Address& address)
{

View File

@@ -101,9 +101,12 @@ public:
/**
* \brief Comparison operation between two Ipv6Addresses.
*
* \param other the IPv6 address to which to compare thisaddress
* \deprecated Use the == operator (same functionality)
*
* \param other the IPv6 address to which to compare this address
* \return true if the addresses are equal, false otherwise
*/
NS_DEPRECATED_3_31
bool IsEqual (const Ipv6Address& other) const;
/**
@@ -311,13 +314,20 @@ public:
*/
bool IsDocumentation () const;
/**
* \brief Compares an address and a prefix.
* \param prefix the prefix to compare with
* \return true if the address has the given prefix
*/
bool HasPrefix (Ipv6Prefix const& prefix) const;
/**
* \brief Combine this address with a prefix.
* \param prefix a IPv6 prefix
* \return an IPv6 address that is this address combined
* (bitwise AND) with a prefix, yielding an IPv6 network address.
*/
Ipv6Address CombinePrefix (Ipv6Prefix const & prefix);
Ipv6Address CombinePrefix (Ipv6Prefix const & prefix) const;
/**
* \brief If the Address matches the type.
@@ -536,19 +546,23 @@ public:
* \brief Set prefix length.
* \param prefixLength the prefix length
*/
void SetPrefixLength (uint8_t prefixLength);
void SetPrefixLength (uint8_t prefixLength);
/**
* \brief Get the minimum prefix length, i.e., 128 - the length of the largest sequence trailing zeroes.
* \return minimum prefix length
*/
uint8_t GetMinimumPrefixLength () const;
uint8_t GetMinimumPrefixLength () const;
/**
* \brief Comparison operation between two Ipv6Prefix.
*
* \deprecated Use the == operator (same functionality)
*
* \param other the IPv6 prefix to which to compare this prefix
* \return true if the prefixes are equal, false otherwise
*/
NS_DEPRECATED_3_31
bool IsEqual (const Ipv6Prefix& other) const;
/**

View File

@@ -391,7 +391,7 @@ TapBridge::CreateTap (void)
if (wantIp
&& (ipv4 == 0)
&& m_tapIp.IsBroadcast ()
&& m_tapNetmask.IsEqual (Ipv4Mask::GetOnes ()))
&& m_tapNetmask == Ipv4Mask::GetOnes ())
{
NS_FATAL_ERROR ("TapBridge::CreateTap(): Tap device IP configuration requested but neither IP address nor IP netmask is provided");
}
@@ -464,7 +464,7 @@ TapBridge::CreateTap (void)
}
std::ostringstream ossNetmask;
if (m_tapNetmask.IsEqual (Ipv4Mask::GetOnes ()))
if (m_tapNetmask == Ipv4Mask::GetOnes ())
{
ossNetmask << "-n" << ipv4Mask;
}