From ca83416d0736a7eff38e63ea055d9213ddd3d64e Mon Sep 17 00:00:00 2001 From: Tommaso Pecorella Date: Mon, 15 Jan 2024 16:37:10 -0600 Subject: [PATCH] internet: (fixes #1006) Remove InetSocketAddress ToS functions and replace with attributes --- CHANGES.md | 3 + examples/traffic-control/tbf-example.cc | 6 +- examples/traffic-control/traffic-control.cc | 5 +- examples/wireless/wifi-80211e-txop.cc | 8 +- examples/wireless/wifi-multi-tos.cc | 2 +- .../model/bulk-send-application.cc | 10 +++ .../model/bulk-send-application.h | 1 + src/applications/model/onoff-application.cc | 10 +++ src/applications/model/onoff-application.h | 1 + .../model/three-gpp-http-client.cc | 7 ++ .../model/three-gpp-http-client.h | 2 + .../model/three-gpp-http-server.cc | 12 +++ .../model/three-gpp-http-server.h | 2 + src/applications/model/udp-client.cc | 8 ++ src/applications/model/udp-client.h | 1 + src/applications/model/udp-echo-client.cc | 8 ++ src/applications/model/udp-echo-client.h | 1 + src/applications/model/udp-echo-server.cc | 7 ++ src/applications/model/udp-echo-server.h | 1 + src/applications/model/udp-server.cc | 7 ++ src/applications/model/udp-server.h | 1 + src/applications/model/udp-trace-client.cc | 8 ++ src/applications/model/udp-trace-client.h | 1 + src/internet-apps/model/ping.cc | 2 +- src/internet-apps/model/v4traceroute.cc | 88 ++++++++++--------- src/internet-apps/model/v4traceroute.h | 2 + src/internet/model/ipv4-raw-socket-impl.cc | 4 +- src/internet/model/tcp-socket-base.cc | 2 - src/internet/model/udp-socket-impl.cc | 9 +- src/internet/test/udp-test.cc | 4 +- src/network/model/socket.h | 4 +- src/network/utils/inet-socket-address.cc | 42 +++------ src/network/utils/inet-socket-address.h | 9 -- .../ns3wifi/wifi-ac-mapping-test-suite.cc | 2 +- 34 files changed, 170 insertions(+), 110 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 27c6d7458..35182d576 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -20,6 +20,9 @@ Changes from ns-3.41 to ns-3-dev ### Changes to existing API +* `InetSocketAddress::SetTos()` and `InetSocketAddress::GetTos()` have been removed. +Applications have a new Attribute to set the IPv4 ToS field. + ### Changes to build system * Removed support of the `experimental/filesystem` library, in favor of the official `filesystem` library. diff --git a/examples/traffic-control/tbf-example.cc b/examples/traffic-control/tbf-example.cc index 1344ae739..096e543a1 100644 --- a/examples/traffic-control/tbf-example.cc +++ b/examples/traffic-control/tbf-example.cc @@ -133,9 +133,9 @@ main(int argc, char* argv[]) ApplicationContainer apps; InetSocketAddress rmt(interfaces.GetAddress(0), port); - rmt.SetTos(0xb8); - AddressValue remoteAddress(rmt); - onoff.SetAttribute("Remote", remoteAddress); + onoff.SetAttribute("Remote", AddressValue(rmt)); + onoff.SetAttribute("Tos", UintegerValue(0xb8)); + apps.Add(onoff.Install(nodes.Get(1))); apps.Start(Seconds(1.0)); apps.Stop(Seconds(simulationTime + 0.1)); diff --git a/examples/traffic-control/traffic-control.cc b/examples/traffic-control/traffic-control.cc index 85fe47b14..ee1a1cf84 100644 --- a/examples/traffic-control/traffic-control.cc +++ b/examples/traffic-control/traffic-control.cc @@ -174,9 +174,8 @@ main(int argc, char* argv[]) ApplicationContainer apps; InetSocketAddress rmt(interfaces.GetAddress(0), port); - rmt.SetTos(0xb8); - AddressValue remoteAddress(rmt); - onoff.SetAttribute("Remote", remoteAddress); + onoff.SetAttribute("Remote", AddressValue(rmt)); + onoff.SetAttribute("Tos", UintegerValue(0xb8)); apps.Add(onoff.Install(nodes.Get(1))); apps.Start(Seconds(1.0)); apps.Stop(Seconds(simulationTime + 0.1)); diff --git a/examples/wireless/wifi-80211e-txop.cc b/examples/wireless/wifi-80211e-txop.cc index 9ebbd7486..dda10613f 100644 --- a/examples/wireless/wifi-80211e-txop.cc +++ b/examples/wireless/wifi-80211e-txop.cc @@ -299,13 +299,13 @@ main(int argc, char* argv[]) serverAppA.Stop(Seconds(simulationTime + 1)); InetSocketAddress destA(ApInterfaceA.GetAddress(0), port); - destA.SetTos(0x70); // AC_BE OnOffHelper clientA("ns3::UdpSocketFactory", destA); clientA.SetAttribute("OnTime", StringValue("ns3::ConstantRandomVariable[Constant=1]")); clientA.SetAttribute("OffTime", StringValue("ns3::ConstantRandomVariable[Constant=0]")); clientA.SetAttribute("DataRate", StringValue("100000kb/s")); clientA.SetAttribute("PacketSize", UintegerValue(payloadSize)); + clientA.SetAttribute("Tos", UintegerValue(0x70)); // AC_BE ApplicationContainer clientAppA = clientA.Install(wifiStaNodes.Get(0)); clientAppA.Start(Seconds(1.0)); @@ -317,13 +317,13 @@ main(int argc, char* argv[]) serverAppB.Stop(Seconds(simulationTime + 1)); InetSocketAddress destB(ApInterfaceB.GetAddress(0), port); - destB.SetTos(0x70); // AC_BE OnOffHelper clientB("ns3::UdpSocketFactory", destB); clientB.SetAttribute("OnTime", StringValue("ns3::ConstantRandomVariable[Constant=1]")); clientB.SetAttribute("OffTime", StringValue("ns3::ConstantRandomVariable[Constant=0]")); clientB.SetAttribute("DataRate", StringValue("100000kb/s")); clientB.SetAttribute("PacketSize", UintegerValue(payloadSize)); + clientB.SetAttribute("Tos", UintegerValue(0x70)); // AC_BE ApplicationContainer clientAppB = clientB.Install(wifiStaNodes.Get(1)); clientAppB.Start(Seconds(1.0)); @@ -335,13 +335,13 @@ main(int argc, char* argv[]) serverAppC.Stop(Seconds(simulationTime + 1)); InetSocketAddress destC(ApInterfaceC.GetAddress(0), port); - destC.SetTos(0xb8); // AC_VI OnOffHelper clientC("ns3::UdpSocketFactory", destC); clientC.SetAttribute("OnTime", StringValue("ns3::ConstantRandomVariable[Constant=1]")); clientC.SetAttribute("OffTime", StringValue("ns3::ConstantRandomVariable[Constant=0]")); clientC.SetAttribute("DataRate", StringValue("100000kb/s")); clientC.SetAttribute("PacketSize", UintegerValue(payloadSize)); + clientC.SetAttribute("Tos", UintegerValue(0xb8)); // AC_VI ApplicationContainer clientAppC = clientC.Install(wifiStaNodes.Get(2)); clientAppC.Start(Seconds(1.0)); @@ -353,13 +353,13 @@ main(int argc, char* argv[]) serverAppD.Stop(Seconds(simulationTime + 1)); InetSocketAddress destD(ApInterfaceD.GetAddress(0), port); - destD.SetTos(0xb8); // AC_VI OnOffHelper clientD("ns3::UdpSocketFactory", destD); clientD.SetAttribute("OnTime", StringValue("ns3::ConstantRandomVariable[Constant=1]")); clientD.SetAttribute("OffTime", StringValue("ns3::ConstantRandomVariable[Constant=0]")); clientD.SetAttribute("DataRate", StringValue("100000kb/s")); clientD.SetAttribute("PacketSize", UintegerValue(payloadSize)); + clientD.SetAttribute("Tos", UintegerValue(0xb8)); // AC_VI ApplicationContainer clientAppD = clientD.Install(wifiStaNodes.Get(3)); clientAppD.Start(Seconds(1.0)); diff --git a/examples/wireless/wifi-multi-tos.cc b/examples/wireless/wifi-multi-tos.cc index 17147bc63..3c2feaaa4 100644 --- a/examples/wireless/wifi-multi-tos.cc +++ b/examples/wireless/wifi-multi-tos.cc @@ -151,7 +151,6 @@ main(int argc, char* argv[]) auto ipv4 = wifiApNode.Get(0)->GetObject(); const auto address = ipv4->GetAddress(1, 0).GetLocal(); InetSocketAddress sinkSocket(address, portNumber++); - sinkSocket.SetTos(tosValue); OnOffHelper onOffHelper("ns3::UdpSocketFactory", sinkSocket); onOffHelper.SetAttribute("OnTime", StringValue("ns3::ConstantRandomVariable[Constant=1]")); @@ -159,6 +158,7 @@ main(int argc, char* argv[]) StringValue("ns3::ConstantRandomVariable[Constant=0]")); onOffHelper.SetAttribute("DataRate", DataRateValue(50000000 / nWifi)); onOffHelper.SetAttribute("PacketSize", UintegerValue(1472)); // bytes + onOffHelper.SetAttribute("Tos", UintegerValue(tosValue)); sourceApplications.Add(onOffHelper.Install(wifiStaNodes.Get(index))); PacketSinkHelper packetSinkHelper("ns3::UdpSocketFactory", sinkSocket); sinkApplications.Add(packetSinkHelper.Install(wifiApNode.Get(0))); diff --git a/src/applications/model/bulk-send-application.cc b/src/applications/model/bulk-send-application.cc index 9b2100a0b..e16338421 100644 --- a/src/applications/model/bulk-send-application.cc +++ b/src/applications/model/bulk-send-application.cc @@ -63,6 +63,12 @@ BulkSendApplication::GetTypeId() AddressValue(), MakeAddressAccessor(&BulkSendApplication::m_local), MakeAddressChecker()) + .AddAttribute("Tos", + "The Type of Service used to send IPv4 packets. " + "All 8 bits of the TOS byte are set (including ECN bits).", + UintegerValue(0), + MakeUintegerAccessor(&BulkSendApplication::m_tos), + MakeUintegerChecker()) .AddAttribute("MaxBytes", "The total number of bytes to send. " "Once these bytes are sent, " @@ -179,6 +185,10 @@ BulkSendApplication::StartApplication() // Called at time specified by Start NS_FATAL_ERROR("Failed to bind socket"); } + if (InetSocketAddress::IsMatchingType(m_peer)) + { + m_socket->SetIpTos(m_tos); // Affects only IPv4 sockets. + } m_socket->Connect(m_peer); m_socket->ShutdownRecv(); m_socket->SetConnectCallback(MakeCallback(&BulkSendApplication::ConnectionSucceeded, this), diff --git a/src/applications/model/bulk-send-application.h b/src/applications/model/bulk-send-application.h index 1e8a835d9..02a69f5fb 100644 --- a/src/applications/model/bulk-send-application.h +++ b/src/applications/model/bulk-send-application.h @@ -126,6 +126,7 @@ class BulkSendApplication : public Application Address m_peer; //!< Peer address Address m_local; //!< Local address to bind to bool m_connected; //!< True if connected + uint8_t m_tos; //!< The packets Type of Service uint32_t m_sendSize; //!< Size of data to send each time uint64_t m_maxBytes; //!< Limit total number of bytes sent uint64_t m_totBytes; //!< Total bytes sent so far diff --git a/src/applications/model/onoff-application.cc b/src/applications/model/onoff-application.cc index c250e9c7c..42b549e2b 100644 --- a/src/applications/model/onoff-application.cc +++ b/src/applications/model/onoff-application.cc @@ -79,6 +79,12 @@ OnOffApplication::GetTypeId() AddressValue(), MakeAddressAccessor(&OnOffApplication::m_local), MakeAddressChecker()) + .AddAttribute("Tos", + "The Type of Service used to send IPv4 packets. " + "All 8 bits of the TOS byte are set (including ECN bits).", + UintegerValue(0), + MakeUintegerAccessor(&OnOffApplication::m_tos), + MakeUintegerChecker()) .AddAttribute("OnTime", "A RandomVariableStream used to pick the duration of the 'On' state.", StringValue("ns3::ConstantRandomVariable[Constant=1.0]"), @@ -216,6 +222,10 @@ OnOffApplication::StartApplication() // Called at time specified by Start m_socket->SetConnectCallback(MakeCallback(&OnOffApplication::ConnectionSucceeded, this), MakeCallback(&OnOffApplication::ConnectionFailed, this)); + if (InetSocketAddress::IsMatchingType(m_peer)) + { + m_socket->SetIpTos(m_tos); // Affects only IPv4 sockets. + } m_socket->Connect(m_peer); m_socket->SetAllowBroadcast(true); m_socket->ShutdownRecv(); diff --git a/src/applications/model/onoff-application.h b/src/applications/model/onoff-application.h index eb69943c8..de7d4e928 100644 --- a/src/applications/model/onoff-application.h +++ b/src/applications/model/onoff-application.h @@ -163,6 +163,7 @@ class OnOffApplication : public Application Address m_peer; //!< Peer address Address m_local; //!< Local address to bind to bool m_connected; //!< True if connected + uint8_t m_tos; //!< The packets Type of Service Ptr m_onTime; //!< rng for On Time Ptr m_offTime; //!< rng for Off Time DataRate m_cbrRate; //!< Rate that data is generated diff --git a/src/applications/model/three-gpp-http-client.cc b/src/applications/model/three-gpp-http-client.cc index 2fde0d5df..ca4480c3c 100644 --- a/src/applications/model/three-gpp-http-client.cc +++ b/src/applications/model/three-gpp-http-client.cc @@ -80,6 +80,12 @@ ThreeGppHttpClient::GetTypeId() UintegerValue(80), // the default HTTP port MakeUintegerAccessor(&ThreeGppHttpClient::m_remoteServerPort), MakeUintegerChecker()) + .AddAttribute("Tos", + "The Type of Service used to send packets. " + "All 8 bits of the TOS byte are set (including ECN bits).", + UintegerValue(0), + MakeUintegerAccessor(&ThreeGppHttpClient::m_tos), + MakeUintegerChecker()) .AddTraceSource("RxPage", "A page has been received.", MakeTraceSourceAccessor(&ThreeGppHttpClient::m_rxPageTrace), @@ -375,6 +381,7 @@ ThreeGppHttpClient::OpenConnection() InetSocketAddress inetSocket = InetSocketAddress(ipv4, m_remoteServerPort); NS_LOG_INFO(this << " Connecting to " << ipv4 << " port " << m_remoteServerPort << " / " << inetSocket << "."); + m_socket->SetIpTos(m_tos); ret = m_socket->Connect(inetSocket); NS_LOG_DEBUG(this << " Connect() return value= " << ret << " GetErrNo= " << m_socket->GetErrno() << "."); diff --git a/src/applications/model/three-gpp-http-client.h b/src/applications/model/three-gpp-http-client.h index 344f9ec71..40de39798 100644 --- a/src/applications/model/three-gpp-http-client.h +++ b/src/applications/model/three-gpp-http-client.h @@ -393,6 +393,8 @@ class ThreeGppHttpClient : public Application Address m_remoteServerAddress; /// The `RemoteServerPort` attribute. uint16_t m_remoteServerPort; + /// The `Tos` attribute. + uint8_t m_tos; // TRACE SOURCES diff --git a/src/applications/model/three-gpp-http-server.cc b/src/applications/model/three-gpp-http-server.cc index 3f7caa76d..c17fb1c23 100644 --- a/src/applications/model/three-gpp-http-server.cc +++ b/src/applications/model/three-gpp-http-server.cc @@ -81,6 +81,12 @@ ThreeGppHttpServer::GetTypeId() UintegerValue(80), // the default HTTP port MakeUintegerAccessor(&ThreeGppHttpServer::m_localPort), MakeUintegerChecker()) + .AddAttribute("Tos", + "The Type of Service used to send packets. " + "All 8 bits of the TOS byte are set (including ECN bits).", + UintegerValue(0), + MakeUintegerAccessor(&ThreeGppHttpServer::m_tos), + MakeUintegerChecker()) .AddAttribute("Mtu", "Maximum transmission unit (in bytes) of the TCP sockets " "used in this application, excluding the compulsory 40 " @@ -214,6 +220,8 @@ ThreeGppHttpServer::StartApplication() int ret [[maybe_unused]] = m_initialSocket->Bind(inetSocket); NS_LOG_DEBUG(this << " Bind() return value= " << ret << " GetErrNo= " << m_initialSocket->GetErrno() << "."); + + m_initialSocket->SetIpTos(m_tos); // Affects only IPv4 sockets. } else if (Ipv6Address::IsMatchingType(m_localAddress)) { @@ -225,6 +233,10 @@ ThreeGppHttpServer::StartApplication() NS_LOG_DEBUG(this << " Bind() return value= " << ret << " GetErrNo= " << m_initialSocket->GetErrno() << "."); } + else + { + NS_ABORT_MSG("Incompatible local address"); + } int ret [[maybe_unused]] = m_initialSocket->Listen(); NS_LOG_DEBUG(this << " Listen () return value= " << ret diff --git a/src/applications/model/three-gpp-http-server.h b/src/applications/model/three-gpp-http-server.h index e2781ad9d..e43021573 100644 --- a/src/applications/model/three-gpp-http-server.h +++ b/src/applications/model/three-gpp-http-server.h @@ -272,6 +272,8 @@ class ThreeGppHttpServer : public Application Address m_localAddress; /// The `LocalPort` attribute. uint16_t m_localPort; + /// The `Tos` attribute. + uint8_t m_tos; /// The `Mtu` attribute. uint32_t m_mtuSize; diff --git a/src/applications/model/udp-client.cc b/src/applications/model/udp-client.cc index 1d374d9f4..7dc4872d4 100644 --- a/src/applications/model/udp-client.cc +++ b/src/applications/model/udp-client.cc @@ -71,6 +71,12 @@ UdpClient::GetTypeId() UintegerValue(100), MakeUintegerAccessor(&UdpClient::m_peerPort), MakeUintegerChecker()) + .AddAttribute("Tos", + "The Type of Service used to send IPv4 packets. " + "All 8 bits of the TOS byte are set (including ECN bits).", + UintegerValue(0), + MakeUintegerAccessor(&UdpClient::m_tos), + MakeUintegerChecker()) .AddAttribute("PacketSize", "Size of packets generated. The minimum packet size is 12 bytes which is " "the size of the header carrying the sequence number and the time stamp.", @@ -139,6 +145,7 @@ UdpClient::StartApplication() { NS_FATAL_ERROR("Failed to bind socket"); } + m_socket->SetIpTos(m_tos); // Affects only IPv4 sockets. m_socket->Connect( InetSocketAddress(Ipv4Address::ConvertFrom(m_peerAddress), m_peerPort)); } @@ -157,6 +164,7 @@ UdpClient::StartApplication() { NS_FATAL_ERROR("Failed to bind socket"); } + m_socket->SetIpTos(m_tos); // Affects only IPv4 sockets. m_socket->Connect(m_peerAddress); } else if (Inet6SocketAddress::IsMatchingType(m_peerAddress)) diff --git a/src/applications/model/udp-client.h b/src/applications/model/udp-client.h index d5a14d93a..ee4d9e249 100644 --- a/src/applications/model/udp-client.h +++ b/src/applications/model/udp-client.h @@ -98,6 +98,7 @@ class UdpClient : public Application Ptr m_socket; //!< Socket Address m_peerAddress; //!< Remote peer address uint16_t m_peerPort; //!< Remote peer port + uint8_t m_tos; //!< The packets Type of Service EventId m_sendEvent; //!< Event to send the next packet #ifdef NS3_LOG_ENABLE diff --git a/src/applications/model/udp-echo-client.cc b/src/applications/model/udp-echo-client.cc index abf302002..adb9cd0bd 100644 --- a/src/applications/model/udp-echo-client.cc +++ b/src/applications/model/udp-echo-client.cc @@ -65,6 +65,12 @@ UdpEchoClient::GetTypeId() UintegerValue(0), MakeUintegerAccessor(&UdpEchoClient::m_peerPort), MakeUintegerChecker()) + .AddAttribute("Tos", + "The Type of Service used to send IPv4 packets. " + "All 8 bits of the TOS byte are set (including ECN bits).", + UintegerValue(0), + MakeUintegerAccessor(&UdpEchoClient::m_tos), + MakeUintegerChecker()) .AddAttribute( "PacketSize", "Size of echo data in outbound packets", @@ -147,6 +153,7 @@ UdpEchoClient::StartApplication() { NS_FATAL_ERROR("Failed to bind socket"); } + m_socket->SetIpTos(m_tos); // Affects only IPv4 sockets. m_socket->Connect( InetSocketAddress(Ipv4Address::ConvertFrom(m_peerAddress), m_peerPort)); } @@ -165,6 +172,7 @@ UdpEchoClient::StartApplication() { NS_FATAL_ERROR("Failed to bind socket"); } + m_socket->SetIpTos(m_tos); // Affects only IPv4 sockets. m_socket->Connect(m_peerAddress); } else if (Inet6SocketAddress::IsMatchingType(m_peerAddress)) diff --git a/src/applications/model/udp-echo-client.h b/src/applications/model/udp-echo-client.h index ed7bed03d..d0d3540fe 100644 --- a/src/applications/model/udp-echo-client.h +++ b/src/applications/model/udp-echo-client.h @@ -167,6 +167,7 @@ class UdpEchoClient : public Application Ptr m_socket; //!< Socket Address m_peerAddress; //!< Remote peer address uint16_t m_peerPort; //!< Remote peer port + uint8_t m_tos; //!< The packets Type of Service EventId m_sendEvent; //!< Event to send the next packet /// Callbacks for tracing the packet Tx events diff --git a/src/applications/model/udp-echo-server.cc b/src/applications/model/udp-echo-server.cc index f00eed7b4..4aed5666f 100644 --- a/src/applications/model/udp-echo-server.cc +++ b/src/applications/model/udp-echo-server.cc @@ -51,6 +51,12 @@ UdpEchoServer::GetTypeId() UintegerValue(9), MakeUintegerAccessor(&UdpEchoServer::m_port), MakeUintegerChecker()) + .AddAttribute("Tos", + "The Type of Service used to send IPv4 packets. " + "All 8 bits of the TOS byte are set (including ECN bits).", + UintegerValue(0), + MakeUintegerAccessor(&UdpEchoServer::m_tos), + MakeUintegerChecker()) .AddTraceSource("Rx", "A packet has been received", MakeTraceSourceAccessor(&UdpEchoServer::m_rxTrace), @@ -134,6 +140,7 @@ UdpEchoServer::StartApplication() } } + m_socket->SetIpTos(m_tos); // Affects only IPv4 sockets. m_socket->SetRecvCallback(MakeCallback(&UdpEchoServer::HandleRead, this)); m_socket6->SetRecvCallback(MakeCallback(&UdpEchoServer::HandleRead, this)); } diff --git a/src/applications/model/udp-echo-server.h b/src/applications/model/udp-echo-server.h index d71963a92..eba83b9c6 100644 --- a/src/applications/model/udp-echo-server.h +++ b/src/applications/model/udp-echo-server.h @@ -69,6 +69,7 @@ class UdpEchoServer : public Application void HandleRead(Ptr socket); uint16_t m_port; //!< Port on which we listen for incoming packets. + uint8_t m_tos; //!< The packets Type of Service Ptr m_socket; //!< IPv4 Socket Ptr m_socket6; //!< IPv6 Socket Address m_local; //!< local multicast address diff --git a/src/applications/model/udp-server.cc b/src/applications/model/udp-server.cc index 940d94ca5..71131d99d 100644 --- a/src/applications/model/udp-server.cc +++ b/src/applications/model/udp-server.cc @@ -54,6 +54,12 @@ UdpServer::GetTypeId() UintegerValue(100), MakeUintegerAccessor(&UdpServer::m_port), MakeUintegerChecker()) + .AddAttribute("Tos", + "The Type of Service used to send IPv4 packets. " + "All 8 bits of the TOS byte are set (including ECN bits).", + UintegerValue(0), + MakeUintegerAccessor(&UdpServer::m_tos), + MakeUintegerChecker()) .AddAttribute("PacketWindowSize", "The size of the window used to compute the packet loss. This value " "should be a multiple of 8.", @@ -135,6 +141,7 @@ UdpServer::StartApplication() } } + m_socket->SetIpTos(m_tos); // Affects only IPv4 sockets. m_socket->SetRecvCallback(MakeCallback(&UdpServer::HandleRead, this)); if (!m_socket6) diff --git a/src/applications/model/udp-server.h b/src/applications/model/udp-server.h index a824b5d96..af4630fae 100644 --- a/src/applications/model/udp-server.h +++ b/src/applications/model/udp-server.h @@ -99,6 +99,7 @@ class UdpServer : public Application void HandleRead(Ptr socket); uint16_t m_port; //!< Port on which we listen for incoming packets. + uint8_t m_tos; //!< The packets Type of Service Ptr m_socket; //!< IPv4 Socket Ptr m_socket6; //!< IPv6 Socket uint64_t m_received; //!< Number of received packets diff --git a/src/applications/model/udp-trace-client.cc b/src/applications/model/udp-trace-client.cc index aa0e2deed..2eb319aad 100644 --- a/src/applications/model/udp-trace-client.cc +++ b/src/applications/model/udp-trace-client.cc @@ -79,6 +79,12 @@ UdpTraceClient::GetTypeId() UintegerValue(100), MakeUintegerAccessor(&UdpTraceClient::m_peerPort), MakeUintegerChecker()) + .AddAttribute("Tos", + "The Type of Service used to send IPv4 packets. " + "All 8 bits of the TOS byte are set (including ECN bits).", + UintegerValue(0), + MakeUintegerAccessor(&UdpTraceClient::m_tos), + MakeUintegerChecker()) .AddAttribute("MaxPacketSize", "The maximum size of a packet (including the SeqTsHeader, 12 bytes).", UintegerValue(1024), @@ -264,6 +270,7 @@ UdpTraceClient::StartApplication() { NS_FATAL_ERROR("Failed to bind socket"); } + m_socket->SetIpTos(m_tos); // Affects only IPv4 sockets. m_socket->Connect( InetSocketAddress(Ipv4Address::ConvertFrom(m_peerAddress), m_peerPort)); } @@ -282,6 +289,7 @@ UdpTraceClient::StartApplication() { NS_FATAL_ERROR("Failed to bind socket"); } + m_socket->SetIpTos(m_tos); // Affects only IPv4 sockets. m_socket->Connect(m_peerAddress); } else if (Inet6SocketAddress::IsMatchingType(m_peerAddress)) diff --git a/src/applications/model/udp-trace-client.h b/src/applications/model/udp-trace-client.h index c04f13828..c8918d0ce 100644 --- a/src/applications/model/udp-trace-client.h +++ b/src/applications/model/udp-trace-client.h @@ -166,6 +166,7 @@ class UdpTraceClient : public Application Ptr m_socket; //!< Socket Address m_peerAddress; //!< Remote peer address uint16_t m_peerPort; //!< Remote peer port + uint8_t m_tos; //!< The packets Type of Service EventId m_sendEvent; //!< Event to send the next packet std::vector m_entries; //!< Entries in the trace to send diff --git a/src/internet-apps/model/ping.cc b/src/internet-apps/model/ping.cc index 1b2d17e71..d7a9dbdbd 100644 --- a/src/internet-apps/model/ping.cc +++ b/src/internet-apps/model/ping.cc @@ -462,7 +462,6 @@ Ping::Send() } p->AddHeader(header); auto dest = InetSocketAddress(Ipv4Address::ConvertFrom(m_destination), 0); - dest.SetTos(m_tos); returnValue = m_socket->SendTo(p, 0, dest); } else @@ -563,6 +562,7 @@ Ping::StartApplication() NS_ASSERT_MSG(m_socket, "Ping::StartApplication: can not create socket."); m_socket->SetAttribute("Protocol", UintegerValue(1)); // icmp m_socket->SetRecvCallback(MakeCallback(&Ping::Receive, this)); + m_socket->SetIpTos(m_tos); m_useIpv6 = false; Ipv4Address dst = Ipv4Address::ConvertFrom(m_destination); diff --git a/src/internet-apps/model/v4traceroute.cc b/src/internet-apps/model/v4traceroute.cc index b63919379..eeb04d9c1 100644 --- a/src/internet-apps/model/v4traceroute.cc +++ b/src/internet-apps/model/v4traceroute.cc @@ -45,46 +45,53 @@ NS_OBJECT_ENSURE_REGISTERED(V4TraceRoute); TypeId V4TraceRoute::GetTypeId() { - static TypeId tid = TypeId("ns3::V4TraceRoute") - .SetParent() - .SetGroupName("Internet-Apps") - .AddConstructor() - .AddAttribute("Remote", - "The address of the machine we want to trace.", - Ipv4AddressValue(), - MakeIpv4AddressAccessor(&V4TraceRoute::m_remote), - MakeIpv4AddressChecker()) - .AddAttribute("Verbose", - "Produce usual output.", - BooleanValue(true), - MakeBooleanAccessor(&V4TraceRoute::m_verbose), - MakeBooleanChecker()) - .AddAttribute("Interval", - "Wait interval between sent packets.", - TimeValue(Seconds(0)), - MakeTimeAccessor(&V4TraceRoute::m_interval), - MakeTimeChecker()) - .AddAttribute("Size", - "The number of data bytes to be sent, real packet will " - "be 8 (ICMP) + 20 (IP) bytes longer.", - UintegerValue(56), - MakeUintegerAccessor(&V4TraceRoute::m_size), - MakeUintegerChecker()) - .AddAttribute("MaxHop", - "The maximum number of hops to trace.", - UintegerValue(30), - MakeUintegerAccessor(&V4TraceRoute::m_maxTtl), - MakeUintegerChecker()) - .AddAttribute("ProbeNum", - "The number of packets send to each hop.", - UintegerValue(3), - MakeUintegerAccessor(&V4TraceRoute::m_maxProbes), - MakeUintegerChecker()) - .AddAttribute("Timeout", - "The waiting time for a route response before a timeout.", - TimeValue(Seconds(5)), - MakeTimeAccessor(&V4TraceRoute::m_waitIcmpReplyTimeout), - MakeTimeChecker()); + static TypeId tid = + TypeId("ns3::V4TraceRoute") + .SetParent() + .SetGroupName("Internet-Apps") + .AddConstructor() + .AddAttribute("Remote", + "The address of the machine we want to trace.", + Ipv4AddressValue(), + MakeIpv4AddressAccessor(&V4TraceRoute::m_remote), + MakeIpv4AddressChecker()) + .AddAttribute("Tos", + "The Type of Service used to send IPv4 packets. " + "All 8 bits of the TOS byte are set (including ECN bits).", + UintegerValue(0), + MakeUintegerAccessor(&V4TraceRoute::m_tos), + MakeUintegerChecker()) + .AddAttribute("Verbose", + "Produce usual output.", + BooleanValue(true), + MakeBooleanAccessor(&V4TraceRoute::m_verbose), + MakeBooleanChecker()) + .AddAttribute("Interval", + "Wait interval between sent packets.", + TimeValue(Seconds(0)), + MakeTimeAccessor(&V4TraceRoute::m_interval), + MakeTimeChecker()) + .AddAttribute("Size", + "The number of data bytes to be sent, real packet will " + "be 8 (ICMP) + 20 (IP) bytes longer.", + UintegerValue(56), + MakeUintegerAccessor(&V4TraceRoute::m_size), + MakeUintegerChecker()) + .AddAttribute("MaxHop", + "The maximum number of hops to trace.", + UintegerValue(30), + MakeUintegerAccessor(&V4TraceRoute::m_maxTtl), + MakeUintegerChecker()) + .AddAttribute("ProbeNum", + "The number of packets send to each hop.", + UintegerValue(3), + MakeUintegerAccessor(&V4TraceRoute::m_maxProbes), + MakeUintegerChecker()) + .AddAttribute("Timeout", + "The waiting time for a route response before a timeout.", + TimeValue(Seconds(5)), + MakeTimeAccessor(&V4TraceRoute::m_waitIcmpReplyTimeout), + MakeTimeChecker()); return tid; } @@ -135,6 +142,7 @@ V4TraceRoute::StartApplication() m_socket = Socket::CreateSocket(GetNode(), TypeId::LookupByName("ns3::Ipv4RawSocketFactory")); m_socket->SetAttribute("Protocol", UintegerValue(Icmpv4L4Protocol::PROT_NUMBER)); + m_socket->SetIpTos(m_tos); // Affects only IPv4 sockets. NS_ASSERT(m_socket); m_socket->SetRecvCallback(MakeCallback(&V4TraceRoute::Receive, this)); diff --git a/src/internet-apps/model/v4traceroute.h b/src/internet-apps/model/v4traceroute.h index 151fddd92..9a6eaa019 100644 --- a/src/internet-apps/model/v4traceroute.h +++ b/src/internet-apps/model/v4traceroute.h @@ -118,6 +118,8 @@ class V4TraceRoute : public Application uint16_t m_maxProbes; /// The current TTL value uint16_t m_ttl; + /// The packets Type of Service + uint8_t m_tos; /// The maximum Ttl (Max number of hops to trace) uint32_t m_maxTtl; /// The wait time until the response is considered lost. diff --git a/src/internet/model/ipv4-raw-socket-impl.cc b/src/internet/model/ipv4-raw-socket-impl.cc index 9553a22f0..87839f013 100644 --- a/src/internet/model/ipv4-raw-socket-impl.cc +++ b/src/internet/model/ipv4-raw-socket-impl.cc @@ -202,7 +202,6 @@ Ipv4RawSocketImpl::Connect(const Address& address) } InetSocketAddress ad = InetSocketAddress::ConvertFrom(address); m_dst = ad.GetIpv4(); - SetIpTos(ad.GetTos()); NotifyConnectionSucceeded(); return 0; @@ -228,7 +227,6 @@ Ipv4RawSocketImpl::Send(Ptr p, uint32_t flags) { NS_LOG_FUNCTION(this << p << flags); InetSocketAddress to = InetSocketAddress(m_dst, m_protocol); - to.SetTos(GetIpTos()); return SendTo(p, flags, to); } @@ -250,7 +248,7 @@ Ipv4RawSocketImpl::SendTo(Ptr p, uint32_t flags, const Address& toAddres Ptr ipv4 = m_node->GetObject(); Ipv4Address dst = ad.GetIpv4(); Ipv4Address src = m_src; - uint8_t tos = ad.GetTos(); + uint8_t tos = GetIpTos(); uint8_t priority = GetPriority(); if (tos) diff --git a/src/internet/model/tcp-socket-base.cc b/src/internet/model/tcp-socket-base.cc index 16383e414..ad1ec1a78 100644 --- a/src/internet/model/tcp-socket-base.cc +++ b/src/internet/model/tcp-socket-base.cc @@ -575,7 +575,6 @@ TcpSocketBase::Bind(const Address& address) InetSocketAddress transport = InetSocketAddress::ConvertFrom(address); Ipv4Address ipv4 = transport.GetIpv4(); uint16_t port = transport.GetPort(); - SetIpTos(transport.GetTos()); if (ipv4 == Ipv4Address::GetAny() && port == 0) { m_endPoint = m_tcp->Allocate(); @@ -690,7 +689,6 @@ TcpSocketBase::Connect(const Address& address) } InetSocketAddress transport = InetSocketAddress::ConvertFrom(address); m_endPoint->SetPeer(transport.GetIpv4(), transport.GetPort()); - SetIpTos(transport.GetTos()); m_endPoint6 = nullptr; // Get the appropriate local address and port number from the routing protocol and set up diff --git a/src/internet/model/udp-socket-impl.cc b/src/internet/model/udp-socket-impl.cc index 868ddc514..e1daf13fd 100644 --- a/src/internet/model/udp-socket-impl.cc +++ b/src/internet/model/udp-socket-impl.cc @@ -280,7 +280,6 @@ UdpSocketImpl::Bind(const Address& address) InetSocketAddress transport = InetSocketAddress::ConvertFrom(address); Ipv4Address ipv4 = transport.GetIpv4(); uint16_t port = transport.GetPort(); - SetIpTos(transport.GetTos()); if (ipv4 == Ipv4Address::GetAny() && port == 0) { m_endPoint = m_udp->Allocate(); @@ -416,7 +415,6 @@ UdpSocketImpl::Connect(const Address& address) InetSocketAddress transport = InetSocketAddress::ConvertFrom(address); m_defaultAddress = Address(transport.GetIpv4()); m_defaultPort = transport.GetPort(); - SetIpTos(transport.GetTos()); m_connected = true; NotifyConnectionSucceeded(); } @@ -839,8 +837,7 @@ UdpSocketImpl::SendTo(Ptr p, uint32_t flags, const Address& address) InetSocketAddress transport = InetSocketAddress::ConvertFrom(address); Ipv4Address ipv4 = transport.GetIpv4(); uint16_t port = transport.GetPort(); - uint8_t tos = transport.GetTos(); - return DoSendTo(p, ipv4, port, tos); + return DoSendTo(p, ipv4, port, GetIpTos()); } else if (Inet6SocketAddress::IsMatchingType(address)) { @@ -931,9 +928,7 @@ UdpSocketImpl::GetPeerName(Address& address) const if (Ipv4Address::IsMatchingType(m_defaultAddress)) { Ipv4Address addr = Ipv4Address::ConvertFrom(m_defaultAddress); - InetSocketAddress inet(addr, m_defaultPort); - inet.SetTos(GetIpTos()); - address = inet; + address = InetSocketAddress(addr, m_defaultPort); } else if (Ipv6Address::IsMatchingType(m_defaultAddress)) { diff --git a/src/internet/test/udp-test.cc b/src/internet/test/udp-test.cc index b8de69720..be5f6fce2 100644 --- a/src/internet/test/udp-test.cc +++ b/src/internet/test/udp-test.cc @@ -490,10 +490,8 @@ UdpSocketImplTest::DoRun() MakeCallback(&UdpSocketImplTest::SentPkt, this)); // The socket is not connected. - txSocket->SetIpTos(0x28); // AF11 txSocket->SetPriority(6); // Interactive // Send a packet to a specified destination: - // - for not connected sockets, the tos specified in the destination address (0) is used // - since the tos is zero, the priority set for the socket is used SendDataTo(txSocket, "10.0.0.1"); NS_TEST_EXPECT_MSG_EQ(m_receivedPacket->GetSize(), 123, "trivial"); @@ -504,7 +502,7 @@ UdpSocketImplTest::DoRun() m_receivedPacket->RemoveAllByteTags(); InetSocketAddress dest("10.0.0.1", 1234); - dest.SetTos(0xb8); // EF + txSocket->SetIpTos(0xb8); // EF // the connect operation sets the tos (and priority) for the socket NS_TEST_EXPECT_MSG_EQ(txSocket->Connect(dest), 0, "the connect operation failed"); diff --git a/src/network/model/socket.h b/src/network/model/socket.h index 70633588e..b748aeb34 100644 --- a/src/network/model/socket.h +++ b/src/network/model/socket.h @@ -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 */ diff --git a/src/network/utils/inet-socket-address.cc b/src/network/utils/inet-socket-address.cc index f52462008..6b744d30e 100644 --- a/src/network/utils/inet-socket-address.cc +++ b/src/network/utils/inet-socket-address.cc @@ -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; } diff --git a/src/network/utils/inet-socket-address.h b/src/network/utils/inet-socket-address.h index bdc831c60..e7e8d348d 100644 --- a/src/network/utils/inet-socket-address.h +++ b/src/network/utils/inet-socket-address.h @@ -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 diff --git a/src/test/ns3wifi/wifi-ac-mapping-test-suite.cc b/src/test/ns3wifi/wifi-ac-mapping-test-suite.cc index 3d67543b0..7a717e811 100644 --- a/src/test/ns3wifi/wifi-ac-mapping-test-suite.cc +++ b/src/test/ns3wifi/wifi-ac-mapping-test-suite.cc @@ -206,9 +206,9 @@ WifiAcMappingTest::DoRun() // The packet source is an on-off application on the AP device InetSocketAddress dest(staNodeInterface.GetAddress(0), udpPort); - dest.SetTos(m_tos); OnOffHelper onoff("ns3::UdpSocketFactory", dest); onoff.SetConstantRate(DataRate("5kbps"), 500); + onoff.SetAttribute("Tos", UintegerValue(m_tos)); ApplicationContainer sourceApp = onoff.Install(ap.Get(0)); sourceApp.Start(Seconds(1.0)); sourceApp.Stop(Seconds(4.0));