use of android.net.metrics.RaEvent in project platform_frameworks_base by android.
the class ApfTest method testApfFilterRa.
@SmallTest
public void testApfFilterRa() throws Exception {
MockIpManagerCallback ipManagerCallback = new MockIpManagerCallback();
TestApfFilter apfFilter = new TestApfFilter(ipManagerCallback, DROP_MULTICAST, mLog);
byte[] program = ipManagerCallback.getApfProgram();
final int ROUTER_LIFETIME = 1000;
final int PREFIX_VALID_LIFETIME = 200;
final int PREFIX_PREFERRED_LIFETIME = 100;
final int RDNSS_LIFETIME = 300;
final int ROUTE_LIFETIME = 400;
// Note that lifetime of 2000 will be ignored in favor of shorter route lifetime of 1000.
final int DNSSL_LIFETIME = 2000;
// Verify RA is passed the first time
ByteBuffer basePacket = ByteBuffer.wrap(new byte[ICMP6_RA_OPTION_OFFSET]);
basePacket.putShort(ETH_ETHERTYPE_OFFSET, (short) ETH_P_IPV6);
basePacket.put(IPV6_NEXT_HEADER_OFFSET, (byte) IPPROTO_ICMPV6);
basePacket.put(ICMP6_TYPE_OFFSET, (byte) ICMP6_ROUTER_ADVERTISEMENT);
basePacket.putShort(ICMP6_RA_ROUTER_LIFETIME_OFFSET, (short) ROUTER_LIFETIME);
basePacket.position(IPV6_DEST_ADDR_OFFSET);
basePacket.put(IPV6_ALL_NODES_ADDRESS);
assertPass(program, basePacket.array());
testRaLifetime(apfFilter, ipManagerCallback, basePacket, ROUTER_LIFETIME);
verifyRaEvent(new RaEvent(ROUTER_LIFETIME, -1, -1, -1, -1, -1));
// Ensure zero-length options cause the packet to be silently skipped.
// Do this before we test other packets. http://b/29586253
ByteBuffer zeroLengthOptionPacket = ByteBuffer.wrap(new byte[ICMP6_RA_OPTION_OFFSET + ICMP6_4_BYTE_OPTION_LEN]);
basePacket.clear();
zeroLengthOptionPacket.put(basePacket);
zeroLengthOptionPacket.put((byte) ICMP6_PREFIX_OPTION_TYPE);
zeroLengthOptionPacket.put((byte) 0);
assertInvalidRa(apfFilter, ipManagerCallback, zeroLengthOptionPacket);
// Generate several RAs with different options and lifetimes, and verify when
// ApfFilter is shown these packets, it generates programs to filter them for the
// appropriate lifetime.
ByteBuffer prefixOptionPacket = ByteBuffer.wrap(new byte[ICMP6_RA_OPTION_OFFSET + ICMP6_PREFIX_OPTION_LEN]);
basePacket.clear();
prefixOptionPacket.put(basePacket);
prefixOptionPacket.put((byte) ICMP6_PREFIX_OPTION_TYPE);
prefixOptionPacket.put((byte) (ICMP6_PREFIX_OPTION_LEN / 8));
prefixOptionPacket.putInt(ICMP6_RA_OPTION_OFFSET + ICMP6_PREFIX_OPTION_PREFERRED_LIFETIME_OFFSET, PREFIX_PREFERRED_LIFETIME);
prefixOptionPacket.putInt(ICMP6_RA_OPTION_OFFSET + ICMP6_PREFIX_OPTION_VALID_LIFETIME_OFFSET, PREFIX_VALID_LIFETIME);
testRaLifetime(apfFilter, ipManagerCallback, prefixOptionPacket, PREFIX_PREFERRED_LIFETIME);
verifyRaEvent(new RaEvent(ROUTER_LIFETIME, PREFIX_VALID_LIFETIME, PREFIX_PREFERRED_LIFETIME, -1, -1, -1));
ByteBuffer rdnssOptionPacket = ByteBuffer.wrap(new byte[ICMP6_RA_OPTION_OFFSET + ICMP6_4_BYTE_OPTION_LEN]);
basePacket.clear();
rdnssOptionPacket.put(basePacket);
rdnssOptionPacket.put((byte) ICMP6_RDNSS_OPTION_TYPE);
rdnssOptionPacket.put((byte) (ICMP6_4_BYTE_OPTION_LEN / 8));
rdnssOptionPacket.putInt(ICMP6_RA_OPTION_OFFSET + ICMP6_4_BYTE_LIFETIME_OFFSET, RDNSS_LIFETIME);
testRaLifetime(apfFilter, ipManagerCallback, rdnssOptionPacket, RDNSS_LIFETIME);
verifyRaEvent(new RaEvent(ROUTER_LIFETIME, -1, -1, -1, RDNSS_LIFETIME, -1));
ByteBuffer routeInfoOptionPacket = ByteBuffer.wrap(new byte[ICMP6_RA_OPTION_OFFSET + ICMP6_4_BYTE_OPTION_LEN]);
basePacket.clear();
routeInfoOptionPacket.put(basePacket);
routeInfoOptionPacket.put((byte) ICMP6_ROUTE_INFO_OPTION_TYPE);
routeInfoOptionPacket.put((byte) (ICMP6_4_BYTE_OPTION_LEN / 8));
routeInfoOptionPacket.putInt(ICMP6_RA_OPTION_OFFSET + ICMP6_4_BYTE_LIFETIME_OFFSET, ROUTE_LIFETIME);
testRaLifetime(apfFilter, ipManagerCallback, routeInfoOptionPacket, ROUTE_LIFETIME);
verifyRaEvent(new RaEvent(ROUTER_LIFETIME, -1, -1, ROUTE_LIFETIME, -1, -1));
ByteBuffer dnsslOptionPacket = ByteBuffer.wrap(new byte[ICMP6_RA_OPTION_OFFSET + ICMP6_4_BYTE_OPTION_LEN]);
basePacket.clear();
dnsslOptionPacket.put(basePacket);
dnsslOptionPacket.put((byte) ICMP6_DNSSL_OPTION_TYPE);
dnsslOptionPacket.put((byte) (ICMP6_4_BYTE_OPTION_LEN / 8));
dnsslOptionPacket.putInt(ICMP6_RA_OPTION_OFFSET + ICMP6_4_BYTE_LIFETIME_OFFSET, DNSSL_LIFETIME);
testRaLifetime(apfFilter, ipManagerCallback, dnsslOptionPacket, ROUTER_LIFETIME);
verifyRaEvent(new RaEvent(ROUTER_LIFETIME, -1, -1, -1, -1, DNSSL_LIFETIME));
// Verify that current program filters all five RAs:
program = ipManagerCallback.getApfProgram();
verifyRaLifetime(program, basePacket, ROUTER_LIFETIME);
verifyRaLifetime(program, prefixOptionPacket, PREFIX_PREFERRED_LIFETIME);
verifyRaLifetime(program, rdnssOptionPacket, RDNSS_LIFETIME);
verifyRaLifetime(program, routeInfoOptionPacket, ROUTE_LIFETIME);
verifyRaLifetime(program, dnsslOptionPacket, ROUTER_LIFETIME);
apfFilter.shutdown();
}
use of android.net.metrics.RaEvent in project platform_frameworks_base by android.
the class ApfTest method verifyRaEvent.
private void verifyRaEvent(RaEvent expected) {
ArgumentCaptor<Parcelable> captor = ArgumentCaptor.forClass(Parcelable.class);
verify(mLog, atLeastOnce()).log(captor.capture());
RaEvent got = lastRaEvent(captor.getAllValues());
if (!raEventEquals(expected, got)) {
// fail for printing an assertion error message.
assertEquals(expected, got);
}
}
Aggregations