Index: test/jdk/javax/net/ssl/DTLS/DTLSOverDatagram.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- test/jdk/javax/net/ssl/DTLS/DTLSOverDatagram.java (revision d91550efad325b4a896b7cad4a8ed2a70405a112) +++ test/jdk/javax/net/ssl/DTLS/DTLSOverDatagram.java (date 1615533381748) @@ -77,6 +77,10 @@ private static ByteBuffer clientApp = ByteBuffer.wrap("Hi Server, I'm Client".getBytes()); + private int clientSocketTimeout = SOCKET_TIMEOUT; + private int serverSocketTimeout = SOCKET_TIMEOUT; + + /* * ============================================================= * The test case @@ -558,12 +562,20 @@ return true; } + public void setClientSocketTimeout(int clientSocketTimeout) { + this.clientSocketTimeout = clientSocketTimeout; + } + + public void setServerSocketTimeout(int serverSocketTimeout) { + this.serverSocketTimeout = serverSocketTimeout; + } + public final void runTest(DTLSOverDatagram testCase) throws Exception { try (DatagramSocket serverSocket = new DatagramSocket(); DatagramSocket clientSocket = new DatagramSocket()) { - serverSocket.setSoTimeout(SOCKET_TIMEOUT); - clientSocket.setSoTimeout(SOCKET_TIMEOUT); + serverSocket.setSoTimeout(serverSocketTimeout); + clientSocket.setSoTimeout(clientSocketTimeout); InetSocketAddress serverSocketAddr = new InetSocketAddress( InetAddress.getLocalHost(), serverSocket.getLocalPort()); Index: test/jdk/javax/net/ssl/DTLS/PacketLossRetransmission.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- test/jdk/javax/net/ssl/DTLS/PacketLossRetransmission.java (revision d91550efad325b4a896b7cad4a8ed2a70405a112) +++ test/jdk/javax/net/ssl/DTLS/PacketLossRetransmission.java (date 1615533811195) @@ -32,40 +32,42 @@ * @library /test/lib * @build DTLSOverDatagram * - * @run main/othervm PacketLossRetransmission client 0 hello_request - * @run main/othervm PacketLossRetransmission client 1 client_hello - * @run main/othervm PacketLossRetransmission client 2 server_hello - * @run main/othervm PacketLossRetransmission client 3 hello_verify_request - * @run main/othervm -Djdk.tls.client.enableSessionTicketExtension=false PacketLossRetransmission client 4 new_session_ticket - * @run main/othervm PacketLossRetransmission client 11 certificate - * @run main/othervm PacketLossRetransmission client 12 server_key_exchange - * @run main/othervm PacketLossRetransmission client 13 certificate_request - * @run main/othervm PacketLossRetransmission client 14 server_hello_done - * @run main/othervm PacketLossRetransmission client 15 certificate_verify - * @run main/othervm PacketLossRetransmission client 16 client_key_exchange - * @run main/othervm PacketLossRetransmission client 20 finished - * @run main/othervm PacketLossRetransmission client 21 certificate_url - * @run main/othervm PacketLossRetransmission client 22 certificate_status - * @run main/othervm PacketLossRetransmission client 23 supplemental_data - * @run main/othervm PacketLossRetransmission client -1 change_cipher_spec - * @run main/othervm PacketLossRetransmission server 0 hello_request - * @run main/othervm PacketLossRetransmission server 1 client_hello - * @run main/othervm PacketLossRetransmission server 2 server_hello - * @run main/othervm PacketLossRetransmission server 3 hello_verify_request - * @run main/othervm -Djdk.tls.client.enableSessionTicketExtension=false PacketLossRetransmission server 4 new_session_ticket - * @run main/othervm PacketLossRetransmission server 11 certificate - * @run main/othervm PacketLossRetransmission server 12 server_key_exchange - * @run main/othervm PacketLossRetransmission server 13 certificate_request - * @run main/othervm PacketLossRetransmission server 14 server_hello_done - * @run main/othervm PacketLossRetransmission server 15 certificate_verify - * @run main/othervm PacketLossRetransmission server 16 client_key_exchange - * @run main/othervm PacketLossRetransmission server 20 finished - * @run main/othervm PacketLossRetransmission server 21 certificate_url - * @run main/othervm PacketLossRetransmission server 22 certificate_status - * @run main/othervm PacketLossRetransmission server 23 supplemental_data - * @run main/othervm PacketLossRetransmission server -1 change_cipher_spec + * @run main/othervm PacketLossRetransmission client 0 2 hello_request + * @run main/othervm PacketLossRetransmission client 1 2 client_hello + * @run main/othervm PacketLossRetransmission client 2 2 server_hello + * @run main/othervm PacketLossRetransmission client 3 2 hello_verify_request + * @run main/othervm -Djdk.tls.client.enableSessionTicketExtension=false PacketLossRetransmission client 4 2 new_session_ticket + * @run main/othervm PacketLossRetransmission client 11 2 certificate + * @run main/othervm PacketLossRetransmission client 12 2 server_key_exchange + * @run main/othervm PacketLossRetransmission client 13 2 certificate_request + * @run main/othervm PacketLossRetransmission client 14 2 server_hello_done + * @run main/othervm PacketLossRetransmission client 15 2 certificate_verify + * @run main/othervm PacketLossRetransmission client 16 2 client_key_exchange + * @run main/othervm PacketLossRetransmission client 20 2 finished + * @run main/othervm PacketLossRetransmission client 21 2 certificate_url + * @run main/othervm PacketLossRetransmission client 22 2 certificate_status + * @run main/othervm PacketLossRetransmission client 23 2 supplemental_data + * @run main/othervm PacketLossRetransmission client -1 2 change_cipher_spec + * @run main/othervm PacketLossRetransmission server 0 2 hello_request + * @run main/othervm PacketLossRetransmission server 1 2 client_hello + * @run main/othervm PacketLossRetransmission server 2 2 server_hello + * @run main/othervm PacketLossRetransmission server 3 2 hello_verify_request + * @run main/othervm -Djdk.tls.client.enableSessionTicketExtension=false PacketLossRetransmission server 4 2 new_session_ticket + * @run main/othervm PacketLossRetransmission server 11 2 certificate + * @run main/othervm PacketLossRetransmission server 12 2 server_key_exchange + * @run main/othervm PacketLossRetransmission server 13 2 certificate_request + * @run main/othervm PacketLossRetransmission server 14 2 server_hello_done + * @run main/othervm PacketLossRetransmission server 15 2 certificate_verify + * @run main/othervm PacketLossRetransmission server 16 2 client_key_exchange + * @run main/othervm PacketLossRetransmission server 20 2 finished + * @run main/othervm PacketLossRetransmission server 21 2 certificate_url + * @run main/othervm PacketLossRetransmission server 22 2 certificate_status + * @run main/othervm PacketLossRetransmission server 23 2 supplemental_data + * @run main/othervm PacketLossRetransmission server -1 2 change_cipher_spec */ +import java.util.Collections; +import java.util.Iterator; import java.util.List; import java.util.ArrayList; import java.net.DatagramPacket; @@ -80,33 +82,48 @@ private static boolean isClient; private static byte handshakeType; - private boolean needPacketLoss = true; + private static int packetsToDrop; public static void main(String[] args) throws Exception { isClient = args[0].equals("client"); handshakeType = Byte.valueOf(args[1]); + packetsToDrop = Integer.parseInt(args[2]); PacketLossRetransmission testCase = new PacketLossRetransmission(); + //Test case relies on timeout for retransmission. In the case where packet loss occurs from the finished side + //of a handshake to an unfinished then finished side must stay open longer than unfinished side to allow + //for retransmission. + if(isClient) { + testCase.setClientSocketTimeout(1000); + testCase.setServerSocketTimeout(500); + } else { + testCase.setClientSocketTimeout(500); + testCase.setServerSocketTimeout(1000); + } testCase.runTest(testCase); + } @Override boolean produceHandshakePackets(SSLEngine engine, SocketAddress socketAddr, - String side, List packets) throws Exception { + String side, List packets) throws Exception { boolean finished = super.produceHandshakePackets( engine, socketAddr, side, packets); - if (needPacketLoss && (!(isClient ^ engine.getUseClientMode()))) { - DatagramPacket packet = getPacket(packets, handshakeType); - if (packet != null) { - needPacketLoss = false; - - System.out.println("Loss a packet of handshake messahe"); - packets.remove(packet); + Iterator packetIterator = packets.iterator(); + while (packetIterator.hasNext()) { + DatagramPacket packet = packetIterator.next(); + if ((packetsToDrop > 0) && (!(isClient ^ engine.getUseClientMode()))) { + packet = getPacket(Collections.singletonList(packet), handshakeType); + if (packet != null) { + packetsToDrop--; + System.out.println("Loss a packet of handshake message "); + packetIterator.remove(); + } } } return finished; } -} +} \ No newline at end of file