internet: Set the TOS for ICMP Echo Requests/Replies

This commit is contained in:
Stefano Avallone
2023-11-26 18:59:37 +01:00
committed by Stefano Avallone
parent 2c8c6ccea1
commit d5f9dc201b
4 changed files with 21 additions and 6 deletions

View File

@@ -103,6 +103,12 @@ Ping::GetTypeId()
TimeValue(Seconds(1)),
MakeTimeAccessor(&Ping::m_timeout),
MakeTimeChecker())
.AddAttribute("Tos",
"The Type of Service used to send the ICMP Echo Requests. "
"All 8 bits of the TOS byte are set (including ECN bits).",
UintegerValue(0),
MakeUintegerAccessor(&Ping::m_tos),
MakeUintegerChecker<uint8_t>())
.AddTraceSource("Tx",
"The sequence number and ICMP echo response packet.",
MakeTraceSourceAccessor(&Ping::m_txTrace),
@@ -455,8 +461,9 @@ Ping::Send()
header.EnableChecksum();
}
p->AddHeader(header);
returnValue =
m_socket->SendTo(p, 0, InetSocketAddress(Ipv4Address::ConvertFrom(m_destination), 0));
auto dest = InetSocketAddress(Ipv4Address::ConvertFrom(m_destination), 0);
dest.SetTos(m_tos);
returnValue = m_socket->SendTo(p, 0, dest);
}
else
{

View File

@@ -213,6 +213,8 @@ class Ping : public Application
uint32_t m_size{56};
/// The socket we send packets from
Ptr<Socket> m_socket;
/// The Type of Service carried by ICMP ECHOs
uint8_t m_tos;
/// ICMP ECHO sequence number
uint16_t m_seq{0};
/// Callbacks for tracing the packet Tx events

View File

@@ -222,14 +222,18 @@ void
Icmpv4L4Protocol::HandleEcho(Ptr<Packet> p,
Icmpv4Header header,
Ipv4Address source,
Ipv4Address destination)
Ipv4Address destination,
uint8_t tos)
{
NS_LOG_FUNCTION(this << p << header << source << destination);
NS_LOG_FUNCTION(this << p << header << source << destination << tos);
Ptr<Packet> reply = Create<Packet>();
Icmpv4Echo echo;
p->RemoveHeader(echo);
reply->AddHeader(echo);
SocketIpTosTag ipTosTag;
ipTosTag.SetTos(tos);
reply->ReplacePacketTag(ipTosTag);
SendMessage(reply, destination, source, Icmpv4Header::ICMPV4_ECHO_REPLY, 0, nullptr);
}
@@ -327,7 +331,7 @@ Icmpv4L4Protocol::Receive(Ptr<Packet> p,
}
}
}
HandleEcho(p, icmp, header.GetSource(), dst);
HandleEcho(p, icmp, header.GetSource(), dst, header.GetTos());
break;
}
case Icmpv4Header::ICMPV4_DEST_UNREACH:

View File

@@ -143,11 +143,13 @@ class Icmpv4L4Protocol : public IpL4Protocol
* \param header the IP header
* \param source the source address
* \param destination the destination address
* \param tos the type of service
*/
void HandleEcho(Ptr<Packet> p,
Icmpv4Header header,
Ipv4Address source,
Ipv4Address destination);
Ipv4Address destination,
uint8_t tos);
/**
* \brief Handles an incoming ICMP Destination Unreachable packet
* \param p the packet