public final class RouteInfo extends Object implements Parcelable
This is used both to describe static network configuration and live network configuration information. A route contains three pieces of information:
IpPrefix
specifying the network destinations covered by this route.
If this is null
it indicates a default route of the address family (IPv4 or IPv6)
implied by the gateway IP address.
InetAddress
indicating the next hop to use. If this is null
it
indicates a directly-connected route.
null
, but not both. If the
destination and gateway are both specified, they must be of the same address family
(IPv4 or IPv6).Parcelable.ClassLoaderCreator<T>, Parcelable.Creator<T>
Modifier and Type | Field and Description |
---|---|
static Parcelable.Creator<RouteInfo> |
CREATOR
Implement the Parcelable interface.
|
static int |
RTN_THROW
Throw route.
|
static int |
RTN_UNICAST
Unicast route.
|
static int |
RTN_UNREACHABLE
Unreachable route.
|
CONTENTS_FILE_DESCRIPTOR, PARCELABLE_ELIDE_DUPLICATES, PARCELABLE_WRITE_RETURN_VALUE
Constructor and Description |
---|
RouteInfo(InetAddress gateway)
Constructs a default
RouteInfo object. |
RouteInfo(IpPrefix destination)
Constructs a
RouteInfo object representing a direct connected subnet. |
RouteInfo(IpPrefix destination,
InetAddress gateway)
Constructs a
RouteInfo object. |
RouteInfo(IpPrefix destination,
InetAddress gateway,
String iface) |
RouteInfo(IpPrefix destination,
InetAddress gateway,
String iface,
int type)
Constructs a RouteInfo object.
|
RouteInfo(IpPrefix destination,
int type) |
RouteInfo(LinkAddress destination) |
RouteInfo(LinkAddress destination,
InetAddress gateway) |
RouteInfo(LinkAddress destination,
InetAddress gateway,
String iface) |
Modifier and Type | Method and Description |
---|---|
int |
describeContents()
Implement the Parcelable interface
|
boolean |
equals(Object obj)
Compares this RouteInfo object against the specified object and indicates if they are equal.
|
IpPrefix |
getDestination()
Retrieves the destination address and prefix length in the form of an
IpPrefix . |
LinkAddress |
getDestinationLinkAddress()
TODO: Convert callers to use IpPrefix and then remove.
|
InetAddress |
getGateway()
Retrieves the gateway or next hop
InetAddress for this route. |
String |
getInterface()
Retrieves the interface used for this route if specified, else
null . |
int |
getType()
Retrieves the type of this route.
|
boolean |
hasGateway()
Indicates if this route has a next hop (
true ) or is directly-connected
(false ). |
int |
hashCode()
Returns a hashcode for this
RouteInfo object. |
boolean |
isDefaultRoute()
Indicates if this route is a default route (ie, has no destination specified).
|
boolean |
isHostRoute()
Indicates if this route is a host route (ie, matches only a single host address).
|
boolean |
isIPv4Default()
Indicates if this route is an IPv4 default route.
|
boolean |
isIPv6Default()
Indicates if this route is an IPv6 default route.
|
static RouteInfo |
makeHostRoute(InetAddress host,
InetAddress gateway,
String iface) |
static RouteInfo |
makeHostRoute(InetAddress host,
String iface) |
boolean |
matches(InetAddress destination)
Determines whether the destination and prefix of this route includes the specified
address.
|
static RouteInfo |
selectBestRoute(Collection<RouteInfo> routes,
InetAddress dest)
Find the route from a Collection of routes that best matches a given address.
|
String |
toString()
Returns a human-readable description of this object.
|
void |
writeToParcel(Parcel dest,
int flags)
Implement the Parcelable interface
|
public static final int RTN_UNICAST
public static final int RTN_UNREACHABLE
public static final int RTN_THROW
public static final Parcelable.Creator<RouteInfo> CREATOR
public RouteInfo(IpPrefix destination, InetAddress gateway, String iface, int type)
0.0.0.0
if the gateway is an instance of Inet4Address
, or the IPv6 default
route ::/0
if gateway is an instance of
Inet6Address
.
destination and gateway may not both be null.
destination
- the destination prefixgateway
- the IP address to route packets throughiface
- the interface name to send packets onpublic RouteInfo(IpPrefix destination, InetAddress gateway, String iface)
public RouteInfo(LinkAddress destination, InetAddress gateway, String iface)
public RouteInfo(IpPrefix destination, InetAddress gateway)
RouteInfo
object.
If destination is null, then gateway must be specified and the
constructed route is either the IPv4 default route 0.0.0.0
if the gateway is an instance of Inet4Address
, or the IPv6 default
route ::/0
if gateway is an instance of Inet6Address
.
Destination and gateway may not both be null.
destination
- the destination address and prefix in an IpPrefix
gateway
- the InetAddress
to route packets throughpublic RouteInfo(LinkAddress destination, InetAddress gateway)
public RouteInfo(InetAddress gateway)
RouteInfo
object.gateway
- the InetAddress
to route packets throughpublic RouteInfo(IpPrefix destination)
RouteInfo
object representing a direct connected subnet.destination
- the IpPrefix
describing the address and prefix
length of the subnet.public RouteInfo(LinkAddress destination)
public RouteInfo(IpPrefix destination, int type)
public static RouteInfo makeHostRoute(InetAddress host, String iface)
public static RouteInfo makeHostRoute(InetAddress host, InetAddress gateway, String iface)
public IpPrefix getDestination()
IpPrefix
.IpPrefix
specifying the destination. This is never null
.public LinkAddress getDestinationLinkAddress()
public InetAddress getGateway()
InetAddress
for this route.InetAddress
specifying the gateway or next hop. This may be
null
for a directly-connected route."public String getInterface()
null
.public int getType()
RTN_xxx
constants defined in this class.public boolean isDefaultRoute()
true
if the destination has a prefix length of 0.public boolean isIPv4Default()
public boolean isIPv6Default()
public boolean isHostRoute()
true
if the destination has a prefix length of 32 or 128 for IPv4 or IPv6,
respectively.public boolean hasGateway()
true
) or is directly-connected
(false
).true
if a gateway is specifiedpublic boolean matches(InetAddress destination)
destination
- A InetAddress
to test to see if it would match this route.true
if the destination and prefix length cover the given address.public static RouteInfo selectBestRoute(Collection<RouteInfo> routes, InetAddress dest)
routes
- a Collection of RouteInfos to chose fromdest
- the InetAddress your trying to get topublic String toString()
public boolean equals(Object obj)
equals
in class Object
obj
- the reference object with which to compare.true
if the objects are equal, false
otherwise.Object.hashCode()
,
HashMap
public int hashCode()
RouteInfo
object.hashCode
in class Object
Object.equals(java.lang.Object)
,
System.identityHashCode(java.lang.Object)
public int describeContents()
describeContents
in interface Parcelable
Parcelable.CONTENTS_FILE_DESCRIPTOR
public void writeToParcel(Parcel dest, int flags)
writeToParcel
in interface Parcelable
dest
- The Parcel in which the object should be written.flags
- Additional flags about how the object should be written.
May be 0 or Parcelable.PARCELABLE_WRITE_RETURN_VALUE
.