mtu: Add MTU parameter to Routes

- Change route to update existing route
- MTU parameter added to AddRoute

Bug: 142892223
Test: unit test
Change-Id: I2164808ef628eb7c12e875f0bde7f5151bf6a5b5
Merged-In: Ie339d0cee5be12c2232a4631fed61219a0facc64
(cherry picked from commit e521f07e8b03102f1b510a3fb401993513d9c127)
This commit is contained in:
Lorenzo Colitti 2020-03-18 07:52:25 +00:00
commit 6ccc8aa265
2 changed files with 196 additions and 22 deletions

View file

@ -674,17 +674,29 @@ public final class LinkProperties implements Parcelable {
route.getDestination(),
route.getGateway(),
mIfaceName,
route.getType());
route.getType(),
route.getMtu());
}
private int findRouteIndexByDestination(RouteInfo route) {
for (int i = 0; i < mRoutes.size(); i++) {
if (mRoutes.get(i).isSameDestinationAs(route)) {
return i;
}
}
return -1;
}
/**
* Adds a {@link RouteInfo} to this {@code LinkProperties}, if not present. If the
* {@link RouteInfo} had an interface name set and that differs from the interface set for this
* {@code LinkProperties} an {@link IllegalArgumentException} will be thrown. The proper
* Adds a {@link RouteInfo} to this {@code LinkProperties}, if a {@link RouteInfo}
* with the same destination exists with different properties (e.g., different MTU),
* it will be updated. If the {@link RouteInfo} had an interface name set and
* that differs from the interface set for this {@code LinkProperties} an
* {@link IllegalArgumentException} will be thrown. The proper
* course is to add either un-named or properly named {@link RouteInfo}.
*
* @param route A {@link RouteInfo} to add to this object.
* @return {@code false} if the route was already present, {@code true} if it was added.
* @return {@code true} was added or updated, false otherwise.
*/
public boolean addRoute(@NonNull RouteInfo route) {
String routeIface = route.getInterface();
@ -694,11 +706,20 @@ public final class LinkProperties implements Parcelable {
+ " vs. " + mIfaceName);
}
route = routeWithInterface(route);
if (!mRoutes.contains(route)) {
int i = findRouteIndexByDestination(route);
if (i == -1) {
// Route was not present. Add it.
mRoutes.add(route);
return true;
} else if (mRoutes.get(i).equals(route)) {
// Route was present and has same properties. Do nothing.
return false;
} else {
// Route was present and has different properties. Update it.
mRoutes.set(i, route);
return true;
}
return false;
}
/**
@ -706,6 +727,7 @@ public final class LinkProperties implements Parcelable {
* specify an interface and the interface must match the interface of this
* {@code LinkProperties}, or it will not be removed.
*
* @param route A {@link RouteInfo} specifying the route to remove.
* @return {@code true} if the route was removed, {@code false} if it was not present.
*
* @hide

View file

@ -526,6 +526,26 @@ public final class RouteInfo implements Parcelable {
mType == target.getType() && mMtu == target.getMtu();
}
/**
* Compares this RouteInfo object against the specified object and indicates if the
* destinations of both routes are equal.
* @return {@code true} if the route destinations are equal, {@code false} otherwise.
*
* @hide
*/
public boolean isSameDestinationAs(@Nullable Object obj) {
if (this == obj) return true;
if (!(obj instanceof RouteInfo)) return false;
RouteInfo target = (RouteInfo) obj;
if (Objects.equals(mDestination, target.getDestination())) {
return true;
}
return false;
}
/**
* Returns a hashcode for this <code>RouteInfo</code> object.
*/