Search in sources :

Example 1 with RtNetlinkNeighborMessage

use of android.net.netlink.RtNetlinkNeighborMessage in project platform_frameworks_base by android.

the class NetlinkSocketTest method testBasicWorkingGetNeighborsQuery.

@SmallTest
public void testBasicWorkingGetNeighborsQuery() throws Exception {
    NetlinkSocket s = new NetlinkSocket(OsConstants.NETLINK_ROUTE);
    assertNotNull(s);
    s.connectToKernel();
    NetlinkSocketAddress localAddr = s.getLocalAddress();
    assertNotNull(localAddr);
    assertEquals(0, localAddr.getGroupsMask());
    assertTrue(0 != localAddr.getPortId());
    final int TEST_SEQNO = 5;
    final byte[] request = RtNetlinkNeighborMessage.newGetNeighborsRequest(TEST_SEQNO);
    assertNotNull(request);
    final long TIMEOUT = 500;
    assertTrue(s.sendMessage(request, 0, request.length, TIMEOUT));
    int neighMessageCount = 0;
    int doneMessageCount = 0;
    while (doneMessageCount == 0) {
        ByteBuffer response = null;
        response = s.recvMessage(TIMEOUT);
        assertNotNull(response);
        assertTrue(StructNlMsgHdr.STRUCT_SIZE <= response.limit());
        assertEquals(0, response.position());
        assertEquals(ByteOrder.nativeOrder(), response.order());
        // Verify the messages at least appears minimally reasonable.
        while (response.remaining() > 0) {
            final NetlinkMessage msg = NetlinkMessage.parse(response);
            assertNotNull(msg);
            final StructNlMsgHdr hdr = msg.getHeader();
            assertNotNull(hdr);
            if (hdr.nlmsg_type == NetlinkConstants.NLMSG_DONE) {
                doneMessageCount++;
                continue;
            }
            assertEquals(NetlinkConstants.RTM_NEWNEIGH, hdr.nlmsg_type);
            assertTrue(msg instanceof RtNetlinkNeighborMessage);
            assertTrue((hdr.nlmsg_flags & StructNlMsgHdr.NLM_F_MULTI) != 0);
            assertEquals(TEST_SEQNO, hdr.nlmsg_seq);
            assertEquals(localAddr.getPortId(), hdr.nlmsg_pid);
            neighMessageCount++;
        }
    }
    assertEquals(1, doneMessageCount);
    // TODO: make sure this test passes sanely in airplane mode.
    assertTrue(neighMessageCount > 0);
    s.close();
}
Also used : StructNlMsgHdr(android.net.netlink.StructNlMsgHdr) NetlinkSocketAddress(android.system.NetlinkSocketAddress) NetlinkSocket(android.net.netlink.NetlinkSocket) ByteBuffer(java.nio.ByteBuffer) RtNetlinkNeighborMessage(android.net.netlink.RtNetlinkNeighborMessage) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 2 with RtNetlinkNeighborMessage

use of android.net.netlink.RtNetlinkNeighborMessage in project platform_frameworks_base by android.

the class RtNetlinkNeighborMessageTest method testParseRtmDelNeigh.

@SmallTest
public void testParseRtmDelNeigh() {
    final ByteBuffer byteBuffer = ByteBuffer.wrap(RTM_DELNEIGH);
    // For testing.
    byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
    final NetlinkMessage msg = NetlinkMessage.parse(byteBuffer);
    assertNotNull(msg);
    assertTrue(msg instanceof RtNetlinkNeighborMessage);
    final RtNetlinkNeighborMessage neighMsg = (RtNetlinkNeighborMessage) msg;
    final StructNlMsgHdr hdr = neighMsg.getHeader();
    assertNotNull(hdr);
    assertEquals(76, hdr.nlmsg_len);
    assertEquals(NetlinkConstants.RTM_DELNEIGH, hdr.nlmsg_type);
    assertEquals(0, hdr.nlmsg_flags);
    assertEquals(0, hdr.nlmsg_seq);
    assertEquals(0, hdr.nlmsg_pid);
    final StructNdMsg ndmsgHdr = neighMsg.getNdHeader();
    assertNotNull(ndmsgHdr);
    assertEquals((byte) OsConstants.AF_INET, ndmsgHdr.ndm_family);
    assertEquals(21, ndmsgHdr.ndm_ifindex);
    assertEquals(StructNdMsg.NUD_STALE, ndmsgHdr.ndm_state);
    final InetAddress destination = neighMsg.getDestination();
    assertNotNull(destination);
    assertEquals(InetAddress.parseNumericAddress("192.168.159.254"), destination);
}
Also used : StructNlMsgHdr(android.net.netlink.StructNlMsgHdr) StructNdMsg(android.net.netlink.StructNdMsg) NetlinkMessage(android.net.netlink.NetlinkMessage) ByteBuffer(java.nio.ByteBuffer) InetAddress(java.net.InetAddress) RtNetlinkNeighborMessage(android.net.netlink.RtNetlinkNeighborMessage) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 3 with RtNetlinkNeighborMessage

use of android.net.netlink.RtNetlinkNeighborMessage in project platform_frameworks_base by android.

the class RtNetlinkNeighborMessageTest method testParseRtmNewNeigh.

@SmallTest
public void testParseRtmNewNeigh() {
    final ByteBuffer byteBuffer = ByteBuffer.wrap(RTM_NEWNEIGH);
    // For testing.
    byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
    final NetlinkMessage msg = NetlinkMessage.parse(byteBuffer);
    assertNotNull(msg);
    assertTrue(msg instanceof RtNetlinkNeighborMessage);
    final RtNetlinkNeighborMessage neighMsg = (RtNetlinkNeighborMessage) msg;
    final StructNlMsgHdr hdr = neighMsg.getHeader();
    assertNotNull(hdr);
    assertEquals(88, hdr.nlmsg_len);
    assertEquals(NetlinkConstants.RTM_NEWNEIGH, hdr.nlmsg_type);
    assertEquals(0, hdr.nlmsg_flags);
    assertEquals(0, hdr.nlmsg_seq);
    assertEquals(0, hdr.nlmsg_pid);
    final StructNdMsg ndmsgHdr = neighMsg.getNdHeader();
    assertNotNull(ndmsgHdr);
    assertEquals((byte) OsConstants.AF_INET6, ndmsgHdr.ndm_family);
    assertEquals(21, ndmsgHdr.ndm_ifindex);
    assertEquals(StructNdMsg.NUD_STALE, ndmsgHdr.ndm_state);
    final InetAddress destination = neighMsg.getDestination();
    assertNotNull(destination);
    assertEquals(InetAddress.parseNumericAddress("fe80::86c9:b2ff:fe6a:ed4b"), destination);
}
Also used : StructNlMsgHdr(android.net.netlink.StructNlMsgHdr) StructNdMsg(android.net.netlink.StructNdMsg) NetlinkMessage(android.net.netlink.NetlinkMessage) ByteBuffer(java.nio.ByteBuffer) InetAddress(java.net.InetAddress) RtNetlinkNeighborMessage(android.net.netlink.RtNetlinkNeighborMessage) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 4 with RtNetlinkNeighborMessage

use of android.net.netlink.RtNetlinkNeighborMessage in project android_frameworks_base by DirtyUnicorns.

the class NetlinkSocketTest method testBasicWorkingGetNeighborsQuery.

public void testBasicWorkingGetNeighborsQuery() throws Exception {
    NetlinkSocket s = new NetlinkSocket(OsConstants.NETLINK_ROUTE);
    assertNotNull(s);
    s.connectToKernel();
    NetlinkSocketAddress localAddr = s.getLocalAddress();
    assertNotNull(localAddr);
    assertEquals(0, localAddr.getGroupsMask());
    assertTrue(0 != localAddr.getPortId());
    final int TEST_SEQNO = 5;
    final byte[] request = RtNetlinkNeighborMessage.newGetNeighborsRequest(TEST_SEQNO);
    assertNotNull(request);
    final long TIMEOUT = 500;
    assertTrue(s.sendMessage(request, 0, request.length, TIMEOUT));
    int neighMessageCount = 0;
    int doneMessageCount = 0;
    while (doneMessageCount == 0) {
        ByteBuffer response = null;
        response = s.recvMessage(TIMEOUT);
        assertNotNull(response);
        assertTrue(StructNlMsgHdr.STRUCT_SIZE <= response.limit());
        assertEquals(0, response.position());
        assertEquals(ByteOrder.nativeOrder(), response.order());
        // Verify the messages at least appears minimally reasonable.
        while (response.remaining() > 0) {
            final NetlinkMessage msg = NetlinkMessage.parse(response);
            assertNotNull(msg);
            final StructNlMsgHdr hdr = msg.getHeader();
            assertNotNull(hdr);
            if (hdr.nlmsg_type == NetlinkConstants.NLMSG_DONE) {
                doneMessageCount++;
                continue;
            }
            assertEquals(NetlinkConstants.RTM_NEWNEIGH, hdr.nlmsg_type);
            assertTrue(msg instanceof RtNetlinkNeighborMessage);
            assertTrue((hdr.nlmsg_flags & StructNlMsgHdr.NLM_F_MULTI) != 0);
            assertEquals(TEST_SEQNO, hdr.nlmsg_seq);
            assertEquals(localAddr.getPortId(), hdr.nlmsg_pid);
            neighMessageCount++;
        }
    }
    assertEquals(1, doneMessageCount);
    // TODO: make sure this test passes sanely in airplane mode.
    assertTrue(neighMessageCount > 0);
    s.close();
}
Also used : StructNlMsgHdr(android.net.netlink.StructNlMsgHdr) NetlinkSocketAddress(android.system.NetlinkSocketAddress) NetlinkSocket(android.net.netlink.NetlinkSocket) ByteBuffer(java.nio.ByteBuffer) RtNetlinkNeighborMessage(android.net.netlink.RtNetlinkNeighborMessage)

Example 5 with RtNetlinkNeighborMessage

use of android.net.netlink.RtNetlinkNeighborMessage in project android_frameworks_base by DirtyUnicorns.

the class RtNetlinkNeighborMessageTest method testParseRtmGetNeighResponse.

public void testParseRtmGetNeighResponse() {
    final ByteBuffer byteBuffer = ByteBuffer.wrap(RTM_GETNEIGH_RESPONSE);
    // For testing.
    byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
    int messageCount = 0;
    while (byteBuffer.remaining() > 0) {
        final NetlinkMessage msg = NetlinkMessage.parse(byteBuffer);
        assertNotNull(msg);
        assertTrue(msg instanceof RtNetlinkNeighborMessage);
        final RtNetlinkNeighborMessage neighMsg = (RtNetlinkNeighborMessage) msg;
        final StructNlMsgHdr hdr = neighMsg.getHeader();
        assertNotNull(hdr);
        assertEquals(NetlinkConstants.RTM_NEWNEIGH, hdr.nlmsg_type);
        assertEquals(StructNlMsgHdr.NLM_F_MULTI, hdr.nlmsg_flags);
        assertEquals(0, hdr.nlmsg_seq);
        assertEquals(11070, hdr.nlmsg_pid);
        messageCount++;
    }
    // TODO: add more detailed spot checks.
    assertEquals(14, messageCount);
}
Also used : StructNlMsgHdr(android.net.netlink.StructNlMsgHdr) NetlinkMessage(android.net.netlink.NetlinkMessage) ByteBuffer(java.nio.ByteBuffer) RtNetlinkNeighborMessage(android.net.netlink.RtNetlinkNeighborMessage)

Aggregations

RtNetlinkNeighborMessage (android.net.netlink.RtNetlinkNeighborMessage)16 StructNlMsgHdr (android.net.netlink.StructNlMsgHdr)16 ByteBuffer (java.nio.ByteBuffer)16 NetlinkMessage (android.net.netlink.NetlinkMessage)12 StructNdMsg (android.net.netlink.StructNdMsg)8 InetAddress (java.net.InetAddress)8 NetlinkSocket (android.net.netlink.NetlinkSocket)4 NetlinkSocketAddress (android.system.NetlinkSocketAddress)4 SmallTest (android.test.suitebuilder.annotation.SmallTest)4