summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Greenwalt <rgreenwalt@google.com>2014-08-06 12:00:25 -0700
committerRobert Greenwalt <rgreenwalt@google.com>2014-08-17 15:14:29 -0700
commit3f05bf4d7838cb719e78f9d93b22d7ce777392c5 (patch)
treefef628285eb91ea192d1181e30ce274478dfdb58
parent804322564b1b4e4ccff0b1c8cd312bac75ec5bb0 (diff)
downloadframeworks_base-3f05bf4d7838cb719e78f9d93b22d7ce777392c5.zip
frameworks_base-3f05bf4d7838cb719e78f9d93b22d7ce777392c5.tar.gz
frameworks_base-3f05bf4d7838cb719e78f9d93b22d7ce777392c5.tar.bz2
Add tcp buffer size conduit to NetworkAgent.
bug: 16549611 Change-Id: I7d97dedea2c7c1aed2eccb185645889424508591
-rw-r--r--core/java/android/net/LinkProperties.java53
-rw-r--r--services/core/java/com/android/server/ConnectivityService.java90
2 files changed, 85 insertions, 58 deletions
diff --git a/core/java/android/net/LinkProperties.java b/core/java/android/net/LinkProperties.java
index dcb2892..3d6a132 100644
--- a/core/java/android/net/LinkProperties.java
+++ b/core/java/android/net/LinkProperties.java
@@ -55,6 +55,8 @@ public final class LinkProperties implements Parcelable {
private ArrayList<RouteInfo> mRoutes = new ArrayList<RouteInfo>();
private ProxyInfo mHttpProxy;
private int mMtu;
+ // in the format "rmem_min,rmem_def,rmem_max,wmem_min,wmem_def,wmem_max"
+ private String mTcpBufferSizes;
private static final int MIN_MTU = 68;
private static final int MIN_MTU_V6 = 1280;
@@ -105,6 +107,7 @@ public final class LinkProperties implements Parcelable {
addStackedLink(l);
}
setMtu(source.getMtu());
+ mTcpBufferSizes = source.mTcpBufferSizes;
}
}
@@ -351,6 +354,29 @@ public final class LinkProperties implements Parcelable {
return mMtu;
}
+ /**
+ * Sets the tcp buffers sizes to be used when this link is the system default.
+ * Should be of the form "rmem_min,rmem_def,rmem_max,wmem_min,wmem_def,wmem_max".
+ *
+ * @param tcpBufferSizes The tcp buffers sizes to use.
+ *
+ * @hide
+ */
+ public void setTcpBufferSizes(String tcpBufferSizes) {
+ mTcpBufferSizes = tcpBufferSizes;
+ }
+
+ /**
+ * Gets the tcp buffer sizes.
+ *
+ * @return the tcp buffer sizes to use when this link is the system default.
+ *
+ * @hide
+ */
+ public String getTcpBufferSizes() {
+ return mTcpBufferSizes;
+ }
+
private RouteInfo routeWithInterface(RouteInfo route) {
return new RouteInfo(
route.getDestination(),
@@ -509,6 +535,7 @@ public final class LinkProperties implements Parcelable {
mHttpProxy = null;
mStackedLinks.clear();
mMtu = 0;
+ mTcpBufferSizes = null;
}
/**
@@ -534,6 +561,11 @@ public final class LinkProperties implements Parcelable {
String mtu = " MTU: " + mMtu;
+ String tcpBuffSizes = "";
+ if (mTcpBufferSizes != null) {
+ tcpBuffSizes = " TcpBufferSizes: " + mTcpBufferSizes;
+ }
+
String routes = " Routes: [";
for (RouteInfo route : mRoutes) routes += route.toString() + ",";
routes += "] ";
@@ -548,7 +580,7 @@ public final class LinkProperties implements Parcelable {
stacked += "] ";
}
return "{" + ifaceName + linkAddresses + routes + dns + domainName + mtu
- + proxy + stacked + "}";
+ + tcpBuffSizes + proxy + stacked + "}";
}
/**
@@ -756,6 +788,17 @@ public final class LinkProperties implements Parcelable {
return getMtu() == target.getMtu();
}
+ /**
+ * Compares this {@code LinkProperties} Tcp buffer sizes against the target.
+ *
+ * @param target LinkProperties to compare.
+ * @return {@code true} if both are identical, {@code false} otherwise.
+ * @hide
+ */
+ public boolean isIdenticalTcpBufferSizes(LinkProperties target) {
+ return Objects.equals(mTcpBufferSizes, target.mTcpBufferSizes);
+ }
+
@Override
/**
* Compares this {@code LinkProperties} instance against the target
@@ -788,7 +831,8 @@ public final class LinkProperties implements Parcelable {
isIdenticalRoutes(target) &&
isIdenticalHttpProxy(target) &&
isIdenticalStackedLinks(target) &&
- isIdenticalMtu(target);
+ isIdenticalMtu(target) &&
+ isIdenticalTcpBufferSizes(target);
}
/**
@@ -923,7 +967,8 @@ public final class LinkProperties implements Parcelable {
+ mRoutes.size() * 41
+ ((null == mHttpProxy) ? 0 : mHttpProxy.hashCode())
+ mStackedLinks.hashCode() * 47)
- + mMtu * 51;
+ + mMtu * 51
+ + ((null == mTcpBufferSizes) ? 0 : mTcpBufferSizes.hashCode());
}
/**
@@ -942,6 +987,7 @@ public final class LinkProperties implements Parcelable {
}
dest.writeString(mDomains);
dest.writeInt(mMtu);
+ dest.writeString(mTcpBufferSizes);
dest.writeInt(mRoutes.size());
for(RouteInfo route : mRoutes) {
dest.writeParcelable(route, flags);
@@ -981,6 +1027,7 @@ public final class LinkProperties implements Parcelable {
}
netProp.setDomains(in.readString());
netProp.setMtu(in.readInt());
+ netProp.setTcpBufferSizes(in.readString());
addressCount = in.readInt();
for (int i=0; i<addressCount; i++) {
netProp.addRoute((RouteInfo)in.readParcelable(null));
diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java
index 92953cc..5bef4bf 100644
--- a/services/core/java/com/android/server/ConnectivityService.java
+++ b/services/core/java/com/android/server/ConnectivityService.java
@@ -264,6 +264,8 @@ public class ConnectivityService extends IConnectivityManager.Stub {
private INetworkManagementService mNetd;
private INetworkPolicyManager mPolicyManager;
+ private String mCurrentTcpBufferSizes;
+
private static final int ENABLED = 1;
private static final int DISABLED = 0;
@@ -1553,30 +1555,40 @@ public class ConnectivityService extends IConnectivityManager.Stub {
}
}
- /**
- * Reads the network specific TCP buffer sizes from SystemProperties
- * net.tcp.buffersize.[default|wifi|umts|edge|gprs] and set them for system
- * wide use
- */
- private void updateNetworkSettings(NetworkStateTracker nt) {
- String key = nt.getTcpBufferSizesPropName();
- String bufferSizes = key == null ? null : SystemProperties.get(key);
+ private static final String DEFAULT_TCP_BUFFER_SIZES = "4096,87380,110208,4096,16384,110208";
- if (TextUtils.isEmpty(bufferSizes)) {
- if (VDBG) log(key + " not found in system properties. Using defaults");
+ private void updateTcpBufferSizes(NetworkAgentInfo nai) {
+ if (isDefaultNetwork(nai) == false) {
+ return;
+ }
- // Setting to default values so we won't be stuck to previous values
- key = "net.tcp.buffersize.default";
- bufferSizes = SystemProperties.get(key);
+ String tcpBufferSizes = nai.linkProperties.getTcpBufferSizes();
+ String[] values = null;
+ if (tcpBufferSizes != null) {
+ values = tcpBufferSizes.split(",");
}
- // Set values in kernel
- if (bufferSizes.length() != 0) {
- if (VDBG) {
- log("Setting TCP values: [" + bufferSizes
- + "] which comes from [" + key + "]");
- }
- setBufferSize(bufferSizes);
+ if (values == null || values.length != 6) {
+ if (VDBG) log("Invalid tcpBufferSizes string: " + tcpBufferSizes +", using defaults");
+ tcpBufferSizes = DEFAULT_TCP_BUFFER_SIZES;
+ values = tcpBufferSizes.split(",");
+ }
+
+ if (tcpBufferSizes.equals(mCurrentTcpBufferSizes)) return;
+
+ try {
+ if (VDBG) Slog.d(TAG, "Setting tx/rx TCP buffers to " + tcpBufferSizes);
+
+ final String prefix = "/sys/kernel/ipv4/tcp_";
+ FileUtils.stringToFile(prefix + "rmem_min", values[0]);
+ FileUtils.stringToFile(prefix + "rmem_def", values[1]);
+ FileUtils.stringToFile(prefix + "rmem_max", values[2]);
+ FileUtils.stringToFile(prefix + "wmem_min", values[3]);
+ FileUtils.stringToFile(prefix + "wmem_def", values[4]);
+ FileUtils.stringToFile(prefix + "wmem_max", values[5]);
+ mCurrentTcpBufferSizes = tcpBufferSizes;
+ } catch (IOException e) {
+ loge("Can't set TCP buffer sizes:" + e);
}
final String defaultRwndKey = "net.tcp.default_init_rwnd";
@@ -1589,33 +1601,6 @@ public class ConnectivityService extends IConnectivityManager.Stub {
}
}
- /**
- * Writes TCP buffer sizes to /sys/kernel/ipv4/tcp_[r/w]mem_[min/def/max]
- * which maps to /proc/sys/net/ipv4/tcp_rmem and tcpwmem
- *
- * @param bufferSizes in the format of "readMin, readInitial, readMax,
- * writeMin, writeInitial, writeMax"
- */
- private void setBufferSize(String bufferSizes) {
- try {
- String[] values = bufferSizes.split(",");
-
- if (values.length == 6) {
- final String prefix = "/sys/kernel/ipv4/tcp_";
- FileUtils.stringToFile(prefix + "rmem_min", values[0]);
- FileUtils.stringToFile(prefix + "rmem_def", values[1]);
- FileUtils.stringToFile(prefix + "rmem_max", values[2]);
- FileUtils.stringToFile(prefix + "wmem_min", values[3]);
- FileUtils.stringToFile(prefix + "wmem_def", values[4]);
- FileUtils.stringToFile(prefix + "wmem_max", values[5]);
- } else {
- loge("Invalid buffersize string: " + bufferSizes);
- }
- } catch (IOException e) {
- loge("Can't set tcp buffer sizes:" + e);
- }
- }
-
private void flushVmDnsCache() {
/*
* Tell the VMs to toss their DNS caches
@@ -1978,12 +1963,6 @@ public class ConnectivityService extends IConnectivityManager.Stub {
*/
break;
}
- case NetworkStateTracker.EVENT_NETWORK_SUBTYPE_CHANGED: {
- info = (NetworkInfo) msg.obj;
- int type = info.getType();
- if (mNetConfigs[type].isDefault()) updateNetworkSettings(mNetTrackers[type]);
- break;
- }
}
}
}
@@ -4152,6 +4131,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
updateInterfaces(newLp, oldLp, netId);
updateMtu(newLp, oldLp);
+ updateTcpBufferSizes(networkAgent);
// TODO - figure out what to do for clat
// for (LinkProperties lp : newLp.getStackedLinks()) {
// updateMtu(lp, null);
@@ -4377,6 +4357,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
loge("Exception setting default network :" + e);
}
handleApplyDefaultProxy(newNetwork.linkProperties.getHttpProxy());
+ updateTcpBufferSizes(newNetwork);
}
private void handleConnectionValidated(NetworkAgentInfo newNetwork) {
@@ -4434,6 +4415,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
isNewDefault = true;
updateActiveDefaultNetwork(newNetwork);
if (newNetwork.linkProperties != null) {
+ updateTcpBufferSizes(newNetwork);
setDefaultDnsSystemProperties(
newNetwork.linkProperties.getDnsServers());
} else {
@@ -4492,8 +4474,6 @@ public class ConnectivityService extends IConnectivityManager.Stub {
1000);
}
}
- // TODO - read the tcp buffer size config string from somewhere
- // updateNetworkSettings();
}
// Notify battery stats service about this network, both the normal