Skip to content
Snippets Groups Projects
Commit 60005585 authored by Yang Sun's avatar Yang Sun
Browse files

Add getRtmFamily for RtNetlinkRouteMessage

Test: atest NetworkStaticLibTests:com.android.net.moduletests.util.netlink.RtNetlinkRouteMessageTest
Change-Id: Ifdf5afc4f58ff55bd20cc60e23b17c3138754392
parent 08622b8e
No related branches found
No related tags found
No related merge requests found
......@@ -98,6 +98,13 @@ public class RtNetlinkRouteMessage extends NetlinkMessage {
mSinceLastUseMillis = -1;
}
/**
* Returns the rtnetlink family.
*/
public short getRtmFamily() {
return mRtmsg.family;
}
/**
* Returns if the route is resolved. This is always true for unicast,
* and may be false only for multicast routes.
......
......@@ -16,7 +16,9 @@
package com.android.net.module.util.netlink;
import static android.system.OsConstants.AF_INET6;
import static android.system.OsConstants.NETLINK_ROUTE;
import static com.android.net.module.util.netlink.NetlinkConstants.RTNL_FAMILY_IP6MR;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
......@@ -342,4 +344,24 @@ public class RtNetlinkRouteMessageTest {
+ "}";
assertEquals(expected, routeMsg.toString());
}
@Test
public void testGetRtmFamily_RTNL_FAMILY_IP6MR() {
final ByteBuffer byteBuffer = toByteBuffer(RTM_NEWROUTE_MULTICAST_IPV6_HEX);
byteBuffer.order(ByteOrder.LITTLE_ENDIAN); // For testing.
final NetlinkMessage msg = NetlinkMessage.parse(byteBuffer, NETLINK_ROUTE);
final RtNetlinkRouteMessage routeMsg = (RtNetlinkRouteMessage) msg;
assertEquals(RTNL_FAMILY_IP6MR, routeMsg.getRtmFamily());
}
@Test
public void testGetRtmFamily_AF_INET6() {
final ByteBuffer byteBuffer = toByteBuffer(RTM_NEWROUTE_HEX);
byteBuffer.order(ByteOrder.LITTLE_ENDIAN); // For testing.
final NetlinkMessage msg = NetlinkMessage.parse(byteBuffer, NETLINK_ROUTE);
final RtNetlinkRouteMessage routeMsg = (RtNetlinkRouteMessage) msg;
assertEquals(AF_INET6, routeMsg.getRtmFamily());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment