From 8b91e2fbe9598bed7da3be03ec82533eb8b71c41 Mon Sep 17 00:00:00 2001 From: Tommaso Pecorella Date: Sat, 15 Feb 2020 19:22:05 +0100 Subject: [PATCH] Deprecate IsEqual for Ipv[4,6]Address, Ipv6Prefix, and Ipv4Mask --- src/internet/model/arp-l3-protocol.cc | 2 +- src/internet/model/icmpv6-l4-protocol.cc | 4 +- src/internet/model/ipv4-global-routing.cc | 2 +- src/internet/model/ipv4-l3-protocol.cc | 2 +- .../model/ipv4-routing-table-entry.cc | 6 +-- src/internet/model/ipv6-l3-protocol.cc | 4 +- .../model/ipv6-routing-table-entry.cc | 6 +-- src/lte/test/lte-test-ipv6-routing.cc | 6 ++- src/network/utils/ipv4-address.cc | 9 ----- src/network/utils/ipv4-address.h | 40 ++++++++++++++++++- src/network/utils/ipv6-address.cc | 12 +++++- src/network/utils/ipv6-address.h | 22 ++++++++-- src/tap-bridge/model/tap-bridge.cc | 4 +- 13 files changed, 87 insertions(+), 32 deletions(-) diff --git a/src/internet/model/arp-l3-protocol.cc b/src/internet/model/arp-l3-protocol.cc index 981127561..ed5bb0310 100644 --- a/src/internet/model/arp-l3-protocol.cc +++ b/src/internet/model/arp-l3-protocol.cc @@ -228,7 +228,7 @@ ArpL3Protocol::Receive (Ptr device, Ptr 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; diff --git a/src/internet/model/icmpv6-l4-protocol.cc b/src/internet/model/icmpv6-l4-protocol.cc index 0ee94a378..a3a8c7869 100644 --- a/src/internet/model/icmpv6-l4-protocol.cc +++ b/src/internet/model/icmpv6-l4-protocol.cc @@ -798,7 +798,7 @@ void Icmpv6L4Protocol::HandleRedirection (Ptr 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, Ipv6Address const /* add redirection in routing table */ Ptr ipv6 = m_node->GetObject (); - if (redirTarget.IsEqual (redirDestination)) + if (redirTarget == redirDestination) { ipv6->GetRoutingProtocol ()->NotifyAddRoute (redirDestination, Ipv6Prefix (128), Ipv6Address ("::"), ipv6->GetInterfaceForAddress (dst)); } diff --git a/src/internet/model/ipv4-global-routing.cc b/src/internet/model/ipv4-global-routing.cc index fcbb2df1b..e96ef4c8a 100644 --- a/src/internet/model/ipv4-global-routing.cc +++ b/src/internet/model/ipv4-global-routing.cc @@ -152,7 +152,7 @@ Ipv4GlobalRouting::LookupGlobal (Ipv4Address dest, Ptr oif) i++) { NS_ASSERT ((*i)->IsHost ()); - if ((*i)->GetDest ().IsEqual (dest)) + if ((*i)->GetDest () == dest) { if (oif != 0) { diff --git a/src/internet/model/ipv4-l3-protocol.cc b/src/internet/model/ipv4-l3-protocol.cc index 5b5c227ec..ef112c317 100644 --- a/src/internet/model/ipv4-l3-protocol.cc +++ b/src/internet/model/ipv4-l3-protocol.cc @@ -954,7 +954,7 @@ Ipv4L3Protocol::SendRealOut (Ptr route, Ptr 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 ()) { diff --git a/src/internet/model/ipv4-routing-table-entry.cc b/src/internet/model/ipv4-routing-table-entry.cc index 992b705ef..e873b2a0f 100644 --- a/src/internet/model/ipv4-routing-table-entry.cc +++ b/src/internet/model/ipv4-routing-table-entry.cc @@ -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; } diff --git a/src/internet/model/ipv6-l3-protocol.cc b/src/internet/model/ipv6-l3-protocol.cc index 6931782f6..68414d447 100644 --- a/src/internet/model/ipv6-l3-protocol.cc +++ b/src/internet/model/ipv6-l3-protocol.cc @@ -1064,7 +1064,7 @@ void Ipv6L3Protocol::Receive (Ptr device, Ptr 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 route, Ptr packet, Ipv6 ipv6Fragment->GetFragments (packet, ipHeader, targetMtu, fragments); } - if (!route->GetGateway ().IsEqual (Ipv6Address::GetAny ())) + if (route->GetGateway () != Ipv6Address::GetAny ()) { if (outInterface->IsUp ()) { diff --git a/src/internet/model/ipv6-routing-table-entry.cc b/src/internet/model/ipv6-routing-table-entry.cc index f79f1b4f2..89261cafb 100644 --- a/src/internet/model/ipv6-routing-table-entry.cc +++ b/src/internet/model/ipv6-routing-table-entry.cc @@ -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; } diff --git a/src/lte/test/lte-test-ipv6-routing.cc b/src/lte/test/lte-test-ipv6-routing.cc index a930a7033..56466d849 100644 --- a/src/lte/test/lte-test-ipv6-routing.cc +++ b/src/lte/test/lte-test-ipv6-routing.cc @@ -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; diff --git a/src/network/utils/ipv4-address.cc b/src/network/utils/ipv4-address.cc index 18d9ae429..d71c11b61 100644 --- a/src/network/utils/ipv4-address.cc +++ b/src/network/utils/ipv4-address.cc @@ -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); diff --git a/src/network/utils/ipv4-address.h b/src/network/utils/ipv4-address.h index 48a6d515e..a22f9c9fc 100644 --- a/src/network/utils/ipv4-address.h +++ b/src/network/utils/ipv4-address.h @@ -25,6 +25,7 @@ #include #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 diff --git a/src/network/utils/ipv6-address.cc b/src/network/utils/ipv6-address.cc index 331547d06..eed3070e3 100644 --- a/src/network/utils/ipv6-address.cc +++ b/src/network/utils/ipv6-address.cc @@ -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) { diff --git a/src/network/utils/ipv6-address.h b/src/network/utils/ipv6-address.h index 3e810186e..189fe9be1 100644 --- a/src/network/utils/ipv6-address.h +++ b/src/network/utils/ipv6-address.h @@ -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; /** diff --git a/src/tap-bridge/model/tap-bridge.cc b/src/tap-bridge/model/tap-bridge.cc index c2e23f907..a0ade6fcc 100644 --- a/src/tap-bridge/model/tap-bridge.cc +++ b/src/tap-bridge/model/tap-bridge.cc @@ -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; }