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

@@ -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<uint8_t>())
.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),

View File

@@ -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

View File

@@ -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<uint8_t>())
.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();

View File

@@ -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<RandomVariableStream> m_onTime; //!< rng for On Time
Ptr<RandomVariableStream> m_offTime; //!< rng for Off Time
DataRate m_cbrRate; //!< Rate that data is generated

View File

@@ -80,6 +80,12 @@ ThreeGppHttpClient::GetTypeId()
UintegerValue(80), // the default HTTP port
MakeUintegerAccessor(&ThreeGppHttpClient::m_remoteServerPort),
MakeUintegerChecker<uint16_t>())
.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<uint8_t>())
.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() << ".");

View File

@@ -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

View File

@@ -81,6 +81,12 @@ ThreeGppHttpServer::GetTypeId()
UintegerValue(80), // the default HTTP port
MakeUintegerAccessor(&ThreeGppHttpServer::m_localPort),
MakeUintegerChecker<uint16_t>())
.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<uint8_t>())
.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

View File

@@ -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;

View File

@@ -71,6 +71,12 @@ UdpClient::GetTypeId()
UintegerValue(100),
MakeUintegerAccessor(&UdpClient::m_peerPort),
MakeUintegerChecker<uint16_t>())
.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<uint8_t>())
.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))

View File

@@ -98,6 +98,7 @@ class UdpClient : public Application
Ptr<Socket> 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

View File

@@ -65,6 +65,12 @@ UdpEchoClient::GetTypeId()
UintegerValue(0),
MakeUintegerAccessor(&UdpEchoClient::m_peerPort),
MakeUintegerChecker<uint16_t>())
.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<uint8_t>())
.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))

View File

@@ -167,6 +167,7 @@ class UdpEchoClient : public Application
Ptr<Socket> 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

View File

@@ -51,6 +51,12 @@ UdpEchoServer::GetTypeId()
UintegerValue(9),
MakeUintegerAccessor(&UdpEchoServer::m_port),
MakeUintegerChecker<uint16_t>())
.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<uint8_t>())
.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));
}

View File

@@ -69,6 +69,7 @@ class UdpEchoServer : public Application
void HandleRead(Ptr<Socket> socket);
uint16_t m_port; //!< Port on which we listen for incoming packets.
uint8_t m_tos; //!< The packets Type of Service
Ptr<Socket> m_socket; //!< IPv4 Socket
Ptr<Socket> m_socket6; //!< IPv6 Socket
Address m_local; //!< local multicast address

View File

@@ -54,6 +54,12 @@ UdpServer::GetTypeId()
UintegerValue(100),
MakeUintegerAccessor(&UdpServer::m_port),
MakeUintegerChecker<uint16_t>())
.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<uint8_t>())
.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)

View File

@@ -99,6 +99,7 @@ class UdpServer : public Application
void HandleRead(Ptr<Socket> socket);
uint16_t m_port; //!< Port on which we listen for incoming packets.
uint8_t m_tos; //!< The packets Type of Service
Ptr<Socket> m_socket; //!< IPv4 Socket
Ptr<Socket> m_socket6; //!< IPv6 Socket
uint64_t m_received; //!< Number of received packets

View File

@@ -79,6 +79,12 @@ UdpTraceClient::GetTypeId()
UintegerValue(100),
MakeUintegerAccessor(&UdpTraceClient::m_peerPort),
MakeUintegerChecker<uint16_t>())
.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<uint8_t>())
.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))

View File

@@ -166,6 +166,7 @@ class UdpTraceClient : public Application
Ptr<Socket> 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<TraceEntry> m_entries; //!< Entries in the trace to send

View File

@@ -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);

View File

@@ -45,46 +45,53 @@ NS_OBJECT_ENSURE_REGISTERED(V4TraceRoute);
TypeId
V4TraceRoute::GetTypeId()
{
static TypeId tid = TypeId("ns3::V4TraceRoute")
.SetParent<Application>()
.SetGroupName("Internet-Apps")
.AddConstructor<V4TraceRoute>()
.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<uint32_t>())
.AddAttribute("MaxHop",
"The maximum number of hops to trace.",
UintegerValue(30),
MakeUintegerAccessor(&V4TraceRoute::m_maxTtl),
MakeUintegerChecker<uint32_t>())
.AddAttribute("ProbeNum",
"The number of packets send to each hop.",
UintegerValue(3),
MakeUintegerAccessor(&V4TraceRoute::m_maxProbes),
MakeUintegerChecker<uint16_t>())
.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<Application>()
.SetGroupName("Internet-Apps")
.AddConstructor<V4TraceRoute>()
.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<uint8_t>())
.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<uint32_t>())
.AddAttribute("MaxHop",
"The maximum number of hops to trace.",
UintegerValue(30),
MakeUintegerAccessor(&V4TraceRoute::m_maxTtl),
MakeUintegerChecker<uint32_t>())
.AddAttribute("ProbeNum",
"The number of packets send to each hop.",
UintegerValue(3),
MakeUintegerAccessor(&V4TraceRoute::m_maxProbes),
MakeUintegerChecker<uint16_t>())
.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));

View File

@@ -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.

View File

@@ -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<Packet> 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<Packet> p, uint32_t flags, const Address& toAddres
Ptr<Ipv4> ipv4 = m_node->GetObject<Ipv4>();
Ipv4Address dst = ad.GetIpv4();
Ipv4Address src = m_src;
uint8_t tos = ad.GetTos();
uint8_t tos = GetIpTos();
uint8_t priority = GetPriority();
if (tos)

View File

@@ -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

View File

@@ -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<Packet> 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))
{

View File

@@ -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");

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

View File

@@ -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));