Merge "[KA03] Support tcp keepalive offload" am: 5f8ddc2eb1 am: 0b93464e32

am: d6cedf5ed3

Change-Id: I55d7b285a75946713986163fbaa166d4b02513d4
This commit is contained in:
Chalard Jean
2019-02-05 22:41:37 -08:00
committed by android-build-merger
11 changed files with 811 additions and 28 deletions

View File

@@ -22,18 +22,15 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import android.net.IpPrefix;
import android.net.LinkAddress;
import android.net.LinkProperties;
import android.net.LinkProperties.CompareResult;
import android.net.LinkProperties.ProvisioningChange;
import android.net.RouteInfo;
import android.os.Parcel;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.system.OsConstants;
import android.util.ArraySet;
import com.android.internal.util.TestUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -849,18 +846,6 @@ public class LinkPropertiesTest {
assertEquals(new ArraySet<>(expectRemoved), (new ArraySet<>(result.removed)));
}
private void assertParcelingIsLossless(LinkProperties source) {
Parcel p = Parcel.obtain();
source.writeToParcel(p, /* flags */ 0);
p.setDataPosition(0);
final byte[] marshalled = p.marshall();
p = Parcel.obtain();
p.unmarshall(marshalled, 0, marshalled.length);
p.setDataPosition(0);
LinkProperties dest = LinkProperties.CREATOR.createFromParcel(p);
assertEquals(source, dest);
}
@Test
public void testLinkPropertiesParcelable() throws Exception {
LinkProperties source = new LinkProperties();
@@ -882,12 +867,12 @@ public class LinkPropertiesTest {
source.setNat64Prefix(new IpPrefix("2001:db8:1:2:64:64::/96"));
assertParcelingIsLossless(source);
TestUtils.assertParcelingIsLossless(source, LinkProperties.CREATOR);
}
@Test
public void testParcelUninitialized() throws Exception {
LinkProperties empty = new LinkProperties();
assertParcelingIsLossless(empty);
TestUtils.assertParcelingIsLossless(empty, LinkProperties.CREATOR);
}
}

View File

@@ -0,0 +1,102 @@
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.net;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import android.net.SocketKeepalive.InvalidPacketException;
import android.net.TcpKeepalivePacketData.TcpSocketInfo;
import com.android.internal.util.TestUtils;
import libcore.net.InetAddressUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import java.net.InetAddress;
import java.nio.ByteBuffer;
@RunWith(JUnit4.class)
public final class TcpKeepalivePacketDataTest {
@Before
public void setUp() {}
@Test
public void testV4TcpKeepalivePacket() {
final InetAddress srcAddr = InetAddressUtils.parseNumericAddress("192.168.0.1");
final InetAddress dstAddr = InetAddressUtils.parseNumericAddress("192.168.0.10");
final int srcPort = 1234;
final int dstPort = 4321;
final int seq = 0x11111111;
final int ack = 0x22222222;
final int wnd = 8000;
final int wndScale = 2;
TcpKeepalivePacketData resultData = null;
TcpSocketInfo testInfo = new TcpSocketInfo(
srcAddr, srcPort, dstAddr, dstPort, seq, ack, wnd, wndScale);
try {
resultData = TcpKeepalivePacketData.tcpKeepalivePacket(testInfo);
} catch (InvalidPacketException e) {
fail("InvalidPacketException: " + e);
}
assertEquals(testInfo.srcAddress, resultData.srcAddress);
assertEquals(testInfo.dstAddress, resultData.dstAddress);
assertEquals(testInfo.srcPort, resultData.srcPort);
assertEquals(testInfo.dstPort, resultData.dstPort);
assertEquals(testInfo.seq, resultData.tcpSeq);
assertEquals(testInfo.ack, resultData.tcpAck);
assertEquals(testInfo.rcvWndScale, resultData.tcpWndScale);
TestUtils.assertParcelingIsLossless(resultData, TcpKeepalivePacketData.CREATOR);
final byte[] packet = resultData.getPacket();
// IP version and TOS.
ByteBuffer buf = ByteBuffer.wrap(packet);
assertEquals(buf.getShort(), 0x4500);
// Source IP address.
byte[] ip = new byte[4];
buf = ByteBuffer.wrap(packet, 12, 4);
buf.get(ip);
assertArrayEquals(ip, srcAddr.getAddress());
// Destination IP address.
buf = ByteBuffer.wrap(packet, 16, 4);
buf.get(ip);
assertArrayEquals(ip, dstAddr.getAddress());
buf = ByteBuffer.wrap(packet, 20, 12);
// Source port.
assertEquals(buf.getShort(), srcPort);
// Destination port.
assertEquals(buf.getShort(), dstPort);
// Sequence number.
assertEquals(buf.getInt(), seq);
// Ack.
assertEquals(buf.getInt(), ack);
// Window size.
buf = ByteBuffer.wrap(packet, 34, 2);
assertEquals(buf.getShort(), wnd >> wndScale);
}
//TODO: add ipv6 test when ipv6 supported
}