internet: (fixes #1006) Remove InetSocketAddress ToS functions and replace with attributes

This commit is contained in:
Tommaso Pecorella
2024-01-15 16:37:10 -06:00
parent c70cfd026e
commit ca83416d07
34 changed files with 170 additions and 110 deletions

View File

@@ -779,9 +779,11 @@ class Socket : public Object
* \brief Manually set IP Type of Service field
*
* This method corresponds to using setsockopt () IP_TOS of
* real network or BSD sockets. This option is for IPv4 only.
* real network or BSD sockets.
* Setting the IP TOS also changes the socket priority as
* stated in the man page.
* This option affects only IPv4 sockets, it has no effect
* on IPv6 sockets.
*
* \param ipTos The desired TOS value for IP headers
*/

View File

@@ -29,40 +29,35 @@ NS_LOG_COMPONENT_DEFINE("InetSocketAddress");
InetSocketAddress::InetSocketAddress(Ipv4Address ipv4, uint16_t port)
: m_ipv4(ipv4),
m_port(port),
m_tos(0)
m_port(port)
{
NS_LOG_FUNCTION(this << ipv4 << port);
}
InetSocketAddress::InetSocketAddress(Ipv4Address ipv4)
: m_ipv4(ipv4),
m_port(0),
m_tos(0)
m_port(0)
{
NS_LOG_FUNCTION(this << ipv4);
}
InetSocketAddress::InetSocketAddress(const char* ipv4, uint16_t port)
: m_ipv4(Ipv4Address(ipv4)),
m_port(port),
m_tos(0)
m_port(port)
{
NS_LOG_FUNCTION(this << ipv4 << port);
}
InetSocketAddress::InetSocketAddress(const char* ipv4)
: m_ipv4(Ipv4Address(ipv4)),
m_port(0),
m_tos(0)
m_port(0)
{
NS_LOG_FUNCTION(this << ipv4);
}
InetSocketAddress::InetSocketAddress(uint16_t port)
: m_ipv4(Ipv4Address::GetAny()),
m_port(port),
m_tos(0)
m_port(port)
{
NS_LOG_FUNCTION(this << port);
}
@@ -81,13 +76,6 @@ InetSocketAddress::GetIpv4() const
return m_ipv4;
}
uint8_t
InetSocketAddress::GetTos() const
{
NS_LOG_FUNCTION(this);
return m_tos;
}
void
InetSocketAddress::SetPort(uint16_t port)
{
@@ -102,18 +90,11 @@ InetSocketAddress::SetIpv4(Ipv4Address address)
m_ipv4 = address;
}
void
InetSocketAddress::SetTos(uint8_t tos)
{
NS_LOG_FUNCTION(this << tos);
m_tos = tos;
}
bool
InetSocketAddress::IsMatchingType(const Address& address)
{
NS_LOG_FUNCTION(&address);
return address.CheckCompatible(GetType(), 7);
return address.CheckCompatible(GetType(), 6);
}
InetSocketAddress::operator Address() const
@@ -125,26 +106,23 @@ Address
InetSocketAddress::ConvertTo() const
{
NS_LOG_FUNCTION(this);
uint8_t buf[7];
uint8_t buf[6];
m_ipv4.Serialize(buf);
buf[4] = m_port & 0xff;
buf[5] = (m_port >> 8) & 0xff;
buf[6] = m_tos;
return Address(GetType(), buf, 7);
return Address(GetType(), buf, 6);
}
InetSocketAddress
InetSocketAddress::ConvertFrom(const Address& address)
{
NS_LOG_FUNCTION(&address);
NS_ASSERT(address.CheckCompatible(GetType(), 7));
uint8_t buf[7];
NS_ASSERT(address.CheckCompatible(GetType(), 6)); /* 4 (address) + 2 (port) */
uint8_t buf[6];
address.CopyTo(buf);
Ipv4Address ipv4 = Ipv4Address::Deserialize(buf);
uint16_t port = buf[4] | (buf[5] << 8);
uint8_t tos = buf[6];
InetSocketAddress inet(ipv4, port);
inet.SetTos(tos);
return inet;
}

View File

@@ -77,10 +77,6 @@ class InetSocketAddress
* \returns the ipv4 address
*/
Ipv4Address GetIpv4() const;
/**
* \returns the ToS
*/
uint8_t GetTos() const;
/**
* \param port the new port number.
@@ -90,10 +86,6 @@ class InetSocketAddress
* \param address the new ipv4 address
*/
void SetIpv4(Ipv4Address address);
/**
* \param tos the new ToS.
*/
void SetTos(uint8_t tos);
/**
* \param address address to test
@@ -131,7 +123,6 @@ class InetSocketAddress
static uint8_t GetType();
Ipv4Address m_ipv4; //!< the IPv4 address
uint16_t m_port; //!< the port
uint8_t m_tos; //!< the ToS
};
} // namespace ns3