Setting MTU size for specific network.

Able to config network specific MTU size. Normally, the default size of MTU is 1500.
 US - ATT 1410, TMUS 1440, SPRINT 1422
 KR - SKT 1440, KT 1450, LGU+ 1428
 JP - KDDI 1420, SoftBank 1340
 CA - RGS 1430, FIDO 1430, MTS 1430, BELL 1358, SaskTel 1358
 AU - TEL 1400

Bug: 10195070
Change-Id: Ie18650b37a3d44af944f2dae4aa97c04fb12cd5e
This commit is contained in:
sy.yun
2013-09-02 05:24:09 +09:00
committed by Robert Greenwalt
parent 1256d3e505
commit 4aa73924fd
3 changed files with 76 additions and 5 deletions

View File

@@ -66,6 +66,7 @@ public class LinkProperties implements Parcelable {
private String mDomains; private String mDomains;
private Collection<RouteInfo> mRoutes = new ArrayList<RouteInfo>(); private Collection<RouteInfo> mRoutes = new ArrayList<RouteInfo>();
private ProxyProperties mHttpProxy; private ProxyProperties mHttpProxy;
private int mMtu;
// Stores the properties of links that are "stacked" above this link. // Stores the properties of links that are "stacked" above this link.
// Indexed by interface name to allow modification and to prevent duplicates being added. // Indexed by interface name to allow modification and to prevent duplicates being added.
@@ -104,6 +105,7 @@ public class LinkProperties implements Parcelable {
for (LinkProperties l: source.mStackedLinks.values()) { for (LinkProperties l: source.mStackedLinks.values()) {
addStackedLink(l); addStackedLink(l);
} }
setMtu(source.getMtu());
} }
} }
@@ -223,6 +225,14 @@ public class LinkProperties implements Parcelable {
mDomains = domains; mDomains = domains;
} }
public void setMtu(int mtu) {
mMtu = mtu;
}
public int getMtu() {
return mMtu;
}
private RouteInfo routeWithInterface(RouteInfo route) { private RouteInfo routeWithInterface(RouteInfo route) {
return new RouteInfo( return new RouteInfo(
route.getDestination(), route.getDestination(),
@@ -322,6 +332,7 @@ public class LinkProperties implements Parcelable {
mRoutes.clear(); mRoutes.clear();
mHttpProxy = null; mHttpProxy = null;
mStackedLinks.clear(); mStackedLinks.clear();
mMtu = 0;
} }
/** /**
@@ -346,6 +357,8 @@ public class LinkProperties implements Parcelable {
String domainName = "Domains: " + mDomains; String domainName = "Domains: " + mDomains;
String mtu = "MTU: " + mMtu;
String routes = " Routes: ["; String routes = " Routes: [";
for (RouteInfo route : mRoutes) routes += route.toString() + ","; for (RouteInfo route : mRoutes) routes += route.toString() + ",";
routes += "] "; routes += "] ";
@@ -359,7 +372,8 @@ public class LinkProperties implements Parcelable {
} }
stacked += "] "; stacked += "] ";
} }
return "{" + ifaceName + linkAddresses + routes + dns + domainName + proxy + stacked + "}"; return "{" + ifaceName + linkAddresses + routes + dns + domainName + mtu
+ proxy + stacked + "}";
} }
/** /**
@@ -474,6 +488,16 @@ public class LinkProperties implements Parcelable {
return true; return true;
} }
/**
* Compares this {@code LinkProperties} MTU against the target
*
* @@param target LinkProperties to compare.
* @return {@code true} if both are identical, {@code false} otherwise.
*/
public boolean isIdenticalMtu(LinkProperties target) {
return getMtu() == target.getMtu();
}
@Override @Override
/** /**
* Compares this {@code LinkProperties} instance against the target * Compares this {@code LinkProperties} instance against the target
@@ -505,7 +529,8 @@ public class LinkProperties implements Parcelable {
isIdenticalDnses(target) && isIdenticalDnses(target) &&
isIdenticalRoutes(target) && isIdenticalRoutes(target) &&
isIdenticalHttpProxy(target) && isIdenticalHttpProxy(target) &&
isIdenticalStackedLinks(target); isIdenticalStackedLinks(target) &&
isIdenticalMtu(target);
} }
/** /**
@@ -607,7 +632,8 @@ public class LinkProperties implements Parcelable {
+ ((null == mDomains) ? 0 : mDomains.hashCode()) + ((null == mDomains) ? 0 : mDomains.hashCode())
+ mRoutes.size() * 41 + mRoutes.size() * 41
+ ((null == mHttpProxy) ? 0 : mHttpProxy.hashCode()) + ((null == mHttpProxy) ? 0 : mHttpProxy.hashCode())
+ mStackedLinks.hashCode() * 47); + mStackedLinks.hashCode() * 47)
+ mMtu * 51;
} }
/** /**
@@ -625,7 +651,7 @@ public class LinkProperties implements Parcelable {
dest.writeByteArray(d.getAddress()); dest.writeByteArray(d.getAddress());
} }
dest.writeString(mDomains); dest.writeString(mDomains);
dest.writeInt(mMtu);
dest.writeInt(mRoutes.size()); dest.writeInt(mRoutes.size());
for(RouteInfo route : mRoutes) { for(RouteInfo route : mRoutes) {
dest.writeParcelable(route, flags); dest.writeParcelable(route, flags);
@@ -664,6 +690,7 @@ public class LinkProperties implements Parcelable {
} catch (UnknownHostException e) { } } catch (UnknownHostException e) { }
} }
netProp.setDomains(in.readString()); netProp.setDomains(in.readString());
netProp.setMtu(in.readInt());
addressCount = in.readInt(); addressCount = in.readInt();
for (int i=0; i<addressCount; i++) { for (int i=0; i<addressCount; i++) {
netProp.addRoute((RouteInfo)in.readParcelable(null)); netProp.addRoute((RouteInfo)in.readParcelable(null));

View File

@@ -33,6 +33,7 @@ public class LinkPropertiesTest extends TestCase {
private static InetAddress GATEWAY1 = NetworkUtils.numericToInetAddress("75.208.8.1"); private static InetAddress GATEWAY1 = NetworkUtils.numericToInetAddress("75.208.8.1");
private static InetAddress GATEWAY2 = NetworkUtils.numericToInetAddress("69.78.8.1"); private static InetAddress GATEWAY2 = NetworkUtils.numericToInetAddress("69.78.8.1");
private static String NAME = "qmi0"; private static String NAME = "qmi0";
private static int MTU = 1500;
private static LinkAddress LINKADDRV4 = new LinkAddress(ADDRV4, 32); private static LinkAddress LINKADDRV4 = new LinkAddress(ADDRV4, 32);
private static LinkAddress LINKADDRV6 = new LinkAddress(ADDRV6, 128); private static LinkAddress LINKADDRV6 = new LinkAddress(ADDRV6, 128);
@@ -57,6 +58,9 @@ public class LinkPropertiesTest extends TestCase {
assertTrue(source.isIdenticalStackedLinks(target)); assertTrue(source.isIdenticalStackedLinks(target));
assertTrue(target.isIdenticalStackedLinks(source)); assertTrue(target.isIdenticalStackedLinks(source));
assertTrue(source.isIdenticalMtu(target));
assertTrue(target.isIdenticalMtu(source));
// Check result of equals(). // Check result of equals().
assertTrue(source.equals(target)); assertTrue(source.equals(target));
assertTrue(target.equals(source)); assertTrue(target.equals(source));
@@ -88,6 +92,7 @@ public class LinkPropertiesTest extends TestCase {
// set 2 gateways // set 2 gateways
source.addRoute(new RouteInfo(GATEWAY1)); source.addRoute(new RouteInfo(GATEWAY1));
source.addRoute(new RouteInfo(GATEWAY2)); source.addRoute(new RouteInfo(GATEWAY2));
source.setMtu(MTU);
LinkProperties target = new LinkProperties(); LinkProperties target = new LinkProperties();
@@ -99,6 +104,7 @@ public class LinkPropertiesTest extends TestCase {
target.addDns(DNS2); target.addDns(DNS2);
target.addRoute(new RouteInfo(GATEWAY1)); target.addRoute(new RouteInfo(GATEWAY1));
target.addRoute(new RouteInfo(GATEWAY2)); target.addRoute(new RouteInfo(GATEWAY2));
target.setMtu(MTU);
assertLinkPropertiesEqual(source, target); assertLinkPropertiesEqual(source, target);
@@ -111,6 +117,7 @@ public class LinkPropertiesTest extends TestCase {
target.addDns(DNS2); target.addDns(DNS2);
target.addRoute(new RouteInfo(GATEWAY1)); target.addRoute(new RouteInfo(GATEWAY1));
target.addRoute(new RouteInfo(GATEWAY2)); target.addRoute(new RouteInfo(GATEWAY2));
target.setMtu(MTU);
assertFalse(source.equals(target)); assertFalse(source.equals(target));
target.clear(); target.clear();
@@ -123,6 +130,7 @@ public class LinkPropertiesTest extends TestCase {
target.addDns(DNS2); target.addDns(DNS2);
target.addRoute(new RouteInfo(GATEWAY1)); target.addRoute(new RouteInfo(GATEWAY1));
target.addRoute(new RouteInfo(GATEWAY2)); target.addRoute(new RouteInfo(GATEWAY2));
target.setMtu(MTU);
assertFalse(source.equals(target)); assertFalse(source.equals(target));
target.clear(); target.clear();
@@ -134,6 +142,7 @@ public class LinkPropertiesTest extends TestCase {
target.addDns(DNS2); target.addDns(DNS2);
target.addRoute(new RouteInfo(GATEWAY1)); target.addRoute(new RouteInfo(GATEWAY1));
target.addRoute(new RouteInfo(GATEWAY2)); target.addRoute(new RouteInfo(GATEWAY2));
target.setMtu(MTU);
assertFalse(source.equals(target)); assertFalse(source.equals(target));
target.clear(); target.clear();
@@ -145,6 +154,19 @@ public class LinkPropertiesTest extends TestCase {
// change gateway // change gateway
target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress("75.208.8.2"))); target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress("75.208.8.2")));
target.addRoute(new RouteInfo(GATEWAY2)); target.addRoute(new RouteInfo(GATEWAY2));
target.setMtu(MTU);
assertFalse(source.equals(target));
target.clear();
target.setInterfaceName(NAME);
target.addLinkAddress(LINKADDRV4);
target.addLinkAddress(LINKADDRV6);
target.addDns(DNS1);
target.addDns(DNS2);
target.addRoute(GATEWAY1);
target.addRoute(GATEWAY2);
// change mtu
target.setMtu(1440);
assertFalse(source.equals(target)); assertFalse(source.equals(target));
} catch (Exception e) { } catch (Exception e) {
@@ -167,6 +189,7 @@ public class LinkPropertiesTest extends TestCase {
// set 2 gateways // set 2 gateways
source.addRoute(new RouteInfo(GATEWAY1)); source.addRoute(new RouteInfo(GATEWAY1));
source.addRoute(new RouteInfo(GATEWAY2)); source.addRoute(new RouteInfo(GATEWAY2));
source.setMtu(MTU);
LinkProperties target = new LinkProperties(); LinkProperties target = new LinkProperties();
// Exchange order // Exchange order
@@ -177,6 +200,7 @@ public class LinkPropertiesTest extends TestCase {
target.addDns(DNS1); target.addDns(DNS1);
target.addRoute(new RouteInfo(GATEWAY2)); target.addRoute(new RouteInfo(GATEWAY2));
target.addRoute(new RouteInfo(GATEWAY1)); target.addRoute(new RouteInfo(GATEWAY1));
target.setMtu(MTU);
assertLinkPropertiesEqual(source, target); assertLinkPropertiesEqual(source, target);
} catch (Exception e) { } catch (Exception e) {

View File

@@ -2299,6 +2299,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
} }
thisNet.setTeardownRequested(false); thisNet.setTeardownRequested(false);
updateNetworkSettings(thisNet); updateNetworkSettings(thisNet);
updateMtuSizeSettings(thisNet);
handleConnectivityChange(newNetType, false); handleConnectivityChange(newNetType, false);
sendConnectedBroadcastDelayed(info, getConnectivityChangeDelay()); sendConnectedBroadcastDelayed(info, getConnectivityChangeDelay());
@@ -2636,6 +2637,26 @@ public class ConnectivityService extends IConnectivityManager.Stub {
return routesChanged; return routesChanged;
} }
/**
* Reads the network specific MTU size from reources.
* and set it on it's iface.
*/
private void updateMtuSizeSettings(NetworkStateTracker nt) {
final String iface = nt.getLinkProperties().getInterfaceName();
final int mtu = nt.getLinkProperties().getMtu();
if (mtu < 68 || mtu > 10000) {
loge("Unexpected mtu value: " + nt);
return;
}
try {
if (VDBG) log("Setting MTU size: " + iface + ", " + mtu);
mNetd.setMtu(iface, mtu);
} catch (Exception e) {
Slog.e(TAG, "exception in setMtu()" + e);
}
}
/** /**
* Reads the network specific TCP buffer sizes from SystemProperties * Reads the network specific TCP buffer sizes from SystemProperties
@@ -4774,4 +4795,3 @@ public class ConnectivityService extends IConnectivityManager.Stub {
mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, wakeupTime, intent); mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, wakeupTime, intent);
} }
} }