Merge "Add MdnsNsecRecord"
This commit is contained in:
@@ -18,11 +18,13 @@ package com.android.server.connectivity.mdns;
|
||||
|
||||
import static com.android.testutils.DevSdkIgnoreRuleKt.SC_V2;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
@@ -269,6 +271,55 @@ public class MdnsRecordTests {
|
||||
assertEquals(dataInText, dataOutText);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNsecRecord() throws IOException {
|
||||
final byte[] dataIn = HexDump.hexStringToByteArray(
|
||||
// record.android.com
|
||||
"067265636F726407616E64726F696403636F6D00"
|
||||
// Type 0x002f (NSEC), cache flush set on class IN (0x8001)
|
||||
+ "002F8001"
|
||||
// TTL 0x0000003c (60 secs)
|
||||
+ "0000003C"
|
||||
// Data length
|
||||
+ "003C"
|
||||
// nextdomain.android.com
|
||||
+ "0A6E657874646F6D61696E07616E64726F696403636F6D00"
|
||||
// Type bitmaps: window block 0x00, bitmap length 0x05,
|
||||
// bits 16 (TXT) and 33 (SRV) set: 0x0000800040
|
||||
+ "00050000800040"
|
||||
// For 1234, 4*256 + 210 = 1234, so window block 0x04, bitmap length 27/0x1B
|
||||
// (26*8 + 2 = 210, need 27 bytes to set bit 210),
|
||||
// bit 2 set on byte 27 (0x20).
|
||||
+ "041B000000000000000000000000000000000000000000000000000020");
|
||||
assertNotNull(dataIn);
|
||||
String dataInText = HexDump.dumpHexString(dataIn, 0, dataIn.length);
|
||||
|
||||
// Decode
|
||||
DatagramPacket packet = new DatagramPacket(dataIn, dataIn.length);
|
||||
MdnsPacketReader reader = new MdnsPacketReader(packet);
|
||||
|
||||
String[] name = reader.readLabels();
|
||||
assertNotNull(name);
|
||||
assertEquals(3, name.length);
|
||||
String fqdn = MdnsRecord.labelsToString(name);
|
||||
assertEquals("record.android.com", fqdn);
|
||||
|
||||
int type = reader.readUInt16();
|
||||
assertEquals(MdnsRecord.TYPE_NSEC, type);
|
||||
|
||||
MdnsNsecRecord record = new MdnsNsecRecord(name, reader);
|
||||
assertTrue(record.getCacheFlush());
|
||||
assertEquals(60_000L, record.getTtl());
|
||||
assertEquals("nextdomain.android.com", MdnsRecord.labelsToString(record.getNextDomain()));
|
||||
assertArrayEquals(new int[] { MdnsRecord.TYPE_TXT,
|
||||
MdnsRecord.TYPE_SRV,
|
||||
// Non-existing record type, > 256
|
||||
1234 }, record.getTypes());
|
||||
|
||||
String dataOutText = toHex(record);
|
||||
assertEquals(dataInText, dataOutText);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTextRecord() throws IOException {
|
||||
final byte[] dataIn = HexDump.hexStringToByteArray(
|
||||
|
||||
Reference in New Issue
Block a user