DO NOT MERGE: IpConnectivityMetrics: rate limit ApfProgramEvents
This patch uses the previously introduced TokenBucket to rate limit
ApfProgramEvents, still allowing for burst of ApfProgramEvents when a
new interface is set up (due to ipv4 provisioning, multicast lock, ipv6 RAs
triggering new APF program events in short amounts of time).
Test: new test in IpConnectivityMetricsTest
Bug: 1550402
(cherry picked from commit e3f7299ce2)
Change-Id: Idb640dec13ba64180985544b9709a586af66eb6e
This commit is contained in:
committed by
Lorenzo Colitti
parent
834405cbe4
commit
6d442d82d0
@@ -19,6 +19,7 @@ package com.android.server.connectivity;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.ConnectivityMetricsEvent;
|
import android.net.ConnectivityMetricsEvent;
|
||||||
import android.net.IIpConnectivityMetrics;
|
import android.net.IIpConnectivityMetrics;
|
||||||
|
import android.net.metrics.ApfProgramEvent;
|
||||||
import android.net.metrics.ApfStats;
|
import android.net.metrics.ApfStats;
|
||||||
import android.net.metrics.DefaultNetworkEvent;
|
import android.net.metrics.DefaultNetworkEvent;
|
||||||
import android.net.metrics.DhcpClientEvent;
|
import android.net.metrics.DhcpClientEvent;
|
||||||
@@ -112,6 +113,27 @@ public class IpConnectivityMetricsTest extends TestCase {
|
|||||||
assertEquals("", output3);
|
assertEquals("", output3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testRateLimiting() {
|
||||||
|
final IpConnectivityLog logger = new IpConnectivityLog(mService.impl);
|
||||||
|
final ApfProgramEvent ev = new ApfProgramEvent(0, 0, 0, 0, 0);
|
||||||
|
final long fakeTimestamp = 1;
|
||||||
|
|
||||||
|
int attempt = 100; // More than burst quota, but less than buffer size.
|
||||||
|
for (int i = 0; i < attempt; i++) {
|
||||||
|
logger.log(ev);
|
||||||
|
}
|
||||||
|
|
||||||
|
String output1 = getdump("flush");
|
||||||
|
assertFalse("".equals(output1));
|
||||||
|
|
||||||
|
for (int i = 0; i < attempt; i++) {
|
||||||
|
assertFalse("expected event to be dropped", logger.log(fakeTimestamp, ev));
|
||||||
|
}
|
||||||
|
|
||||||
|
String output2 = getdump("flush");
|
||||||
|
assertEquals("", output2);
|
||||||
|
}
|
||||||
|
|
||||||
public void testEndToEndLogging() {
|
public void testEndToEndLogging() {
|
||||||
IpConnectivityLog logger = new IpConnectivityLog(mService.impl);
|
IpConnectivityLog logger = new IpConnectivityLog(mService.impl);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user