Search in sources :

Example 1 with ApfProgramEvent

use of android.net.metrics.ApfProgramEvent in project android_frameworks_base by crdroidandroid.

the class ApfFilter method installNewProgramLocked.

/**
     * Generate and install a new filter program.
     */
@GuardedBy("this")
@VisibleForTesting
void installNewProgramLocked() {
    purgeExpiredRasLocked();
    ArrayList<Ra> rasToFilter = new ArrayList<>();
    final byte[] program;
    long programMinLifetime = Long.MAX_VALUE;
    try {
        // Step 1: Determine how many RA filters we can fit in the program.
        ApfGenerator gen = beginProgramLocked();
        for (Ra ra : mRas) {
            ra.generateFilterLocked(gen);
            // Stop if we get too big.
            if (gen.programLengthOverEstimate() > mApfCapabilities.maximumApfProgramSize)
                break;
            rasToFilter.add(ra);
        }
        // Step 2: Actually generate the program
        gen = beginProgramLocked();
        for (Ra ra : rasToFilter) {
            programMinLifetime = Math.min(programMinLifetime, ra.generateFilterLocked(gen));
        }
        // Execution will reach the end of the program if no filters match, which will pass the
        // packet to the AP.
        program = gen.generate();
    } catch (IllegalInstructionException e) {
        Log.e(TAG, "Program failed to generate: ", e);
        return;
    }
    mLastTimeInstalledProgram = curTime();
    mLastInstalledProgramMinLifetime = programMinLifetime;
    mLastInstalledProgram = program;
    mNumProgramUpdates++;
    if (VDBG) {
        hexDump("Installing filter: ", program, program.length);
    }
    mIpManagerCallback.installPacketFilter(program);
    int flags = ApfProgramEvent.flagsFor(mIPv4Address != null, mMulticastFilter);
    mMetricsLog.log(new ApfProgramEvent(programMinLifetime, rasToFilter.size(), mRas.size(), program.length, flags));
}
Also used : IllegalInstructionException(android.net.apf.ApfGenerator.IllegalInstructionException) ApfGenerator(android.net.apf.ApfGenerator) ArrayList(java.util.ArrayList) ApfProgramEvent(android.net.metrics.ApfProgramEvent) VisibleForTesting(com.android.internal.annotations.VisibleForTesting) GuardedBy(com.android.internal.annotations.GuardedBy)

Example 2 with ApfProgramEvent

use of android.net.metrics.ApfProgramEvent in project platform_frameworks_base by android.

the class ApfFilter method installNewProgramLocked.

/**
     * Generate and install a new filter program.
     */
@GuardedBy("this")
@VisibleForTesting
void installNewProgramLocked() {
    purgeExpiredRasLocked();
    ArrayList<Ra> rasToFilter = new ArrayList<>();
    final byte[] program;
    long programMinLifetime = Long.MAX_VALUE;
    try {
        // Step 1: Determine how many RA filters we can fit in the program.
        ApfGenerator gen = beginProgramLocked();
        for (Ra ra : mRas) {
            ra.generateFilterLocked(gen);
            // Stop if we get too big.
            if (gen.programLengthOverEstimate() > mApfCapabilities.maximumApfProgramSize)
                break;
            rasToFilter.add(ra);
        }
        // Step 2: Actually generate the program
        gen = beginProgramLocked();
        for (Ra ra : rasToFilter) {
            programMinLifetime = Math.min(programMinLifetime, ra.generateFilterLocked(gen));
        }
        // Execution will reach the end of the program if no filters match, which will pass the
        // packet to the AP.
        program = gen.generate();
    } catch (IllegalInstructionException | IllegalStateException e) {
        Log.e(TAG, "Failed to generate APF program.", e);
        return;
    }
    mLastTimeInstalledProgram = currentTimeSeconds();
    mLastInstalledProgramMinLifetime = programMinLifetime;
    mLastInstalledProgram = program;
    mNumProgramUpdates++;
    if (VDBG) {
        hexDump("Installing filter: ", program, program.length);
    }
    mIpManagerCallback.installPacketFilter(program);
    int flags = ApfProgramEvent.flagsFor(mIPv4Address != null, mMulticastFilter);
    mMetricsLog.log(new ApfProgramEvent(programMinLifetime, rasToFilter.size(), mRas.size(), program.length, flags));
}
Also used : IllegalInstructionException(android.net.apf.ApfGenerator.IllegalInstructionException) ApfGenerator(android.net.apf.ApfGenerator) ArrayList(java.util.ArrayList) ApfProgramEvent(android.net.metrics.ApfProgramEvent) VisibleForTesting(com.android.internal.annotations.VisibleForTesting) GuardedBy(com.android.internal.annotations.GuardedBy)

Example 3 with ApfProgramEvent

use of android.net.metrics.ApfProgramEvent in project android_frameworks_base by DirtyUnicorns.

the class ApfFilter method installNewProgramLocked.

/**
     * Generate and install a new filter program.
     */
@GuardedBy("this")
@VisibleForTesting
void installNewProgramLocked() {
    purgeExpiredRasLocked();
    ArrayList<Ra> rasToFilter = new ArrayList<>();
    final byte[] program;
    long programMinLifetime = Long.MAX_VALUE;
    try {
        // Step 1: Determine how many RA filters we can fit in the program.
        ApfGenerator gen = beginProgramLocked();
        for (Ra ra : mRas) {
            ra.generateFilterLocked(gen);
            // Stop if we get too big.
            if (gen.programLengthOverEstimate() > mApfCapabilities.maximumApfProgramSize)
                break;
            rasToFilter.add(ra);
        }
        // Step 2: Actually generate the program
        gen = beginProgramLocked();
        for (Ra ra : rasToFilter) {
            programMinLifetime = Math.min(programMinLifetime, ra.generateFilterLocked(gen));
        }
        // Execution will reach the end of the program if no filters match, which will pass the
        // packet to the AP.
        program = gen.generate();
    } catch (IllegalInstructionException e) {
        Log.e(TAG, "Program failed to generate: ", e);
        return;
    }
    mLastTimeInstalledProgram = curTime();
    mLastInstalledProgramMinLifetime = programMinLifetime;
    mLastInstalledProgram = program;
    mNumProgramUpdates++;
    if (VDBG) {
        hexDump("Installing filter: ", program, program.length);
    }
    mIpManagerCallback.installPacketFilter(program);
    int flags = ApfProgramEvent.flagsFor(mIPv4Address != null, mMulticastFilter);
    mMetricsLog.log(new ApfProgramEvent(programMinLifetime, rasToFilter.size(), mRas.size(), program.length, flags));
}
Also used : IllegalInstructionException(android.net.apf.ApfGenerator.IllegalInstructionException) ApfGenerator(android.net.apf.ApfGenerator) ArrayList(java.util.ArrayList) ApfProgramEvent(android.net.metrics.ApfProgramEvent) VisibleForTesting(com.android.internal.annotations.VisibleForTesting) GuardedBy(com.android.internal.annotations.GuardedBy)

Example 4 with ApfProgramEvent

use of android.net.metrics.ApfProgramEvent in project android_frameworks_base by DirtyUnicorns.

the class IpConnectivityMetricsTest method testRateLimiting.

@SmallTest
public void testRateLimiting() {
    final IpConnectivityLog logger = new IpConnectivityLog(mService.impl);
    final ApfProgramEvent ev = new ApfProgramEvent(0, 0, 0, 0, 0);
    final long fakeTimestamp = 1;
    // More than burst quota, but less than buffer size.
    int attempt = 100;
    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);
}
Also used : IpConnectivityLog(android.net.metrics.IpConnectivityLog) ApfProgramEvent(android.net.metrics.ApfProgramEvent) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 5 with ApfProgramEvent

use of android.net.metrics.ApfProgramEvent in project android_frameworks_base by ResurrectionRemix.

the class ApfFilter method installNewProgramLocked.

/**
     * Generate and install a new filter program.
     */
@GuardedBy("this")
@VisibleForTesting
void installNewProgramLocked() {
    purgeExpiredRasLocked();
    ArrayList<Ra> rasToFilter = new ArrayList<>();
    final byte[] program;
    long programMinLifetime = Long.MAX_VALUE;
    try {
        // Step 1: Determine how many RA filters we can fit in the program.
        ApfGenerator gen = beginProgramLocked();
        for (Ra ra : mRas) {
            ra.generateFilterLocked(gen);
            // Stop if we get too big.
            if (gen.programLengthOverEstimate() > mApfCapabilities.maximumApfProgramSize)
                break;
            rasToFilter.add(ra);
        }
        // Step 2: Actually generate the program
        gen = beginProgramLocked();
        for (Ra ra : rasToFilter) {
            programMinLifetime = Math.min(programMinLifetime, ra.generateFilterLocked(gen));
        }
        // Execution will reach the end of the program if no filters match, which will pass the
        // packet to the AP.
        program = gen.generate();
    } catch (IllegalInstructionException e) {
        Log.e(TAG, "Program failed to generate: ", e);
        return;
    }
    mLastTimeInstalledProgram = curTime();
    mLastInstalledProgramMinLifetime = programMinLifetime;
    mLastInstalledProgram = program;
    mNumProgramUpdates++;
    if (VDBG) {
        hexDump("Installing filter: ", program, program.length);
    }
    mIpManagerCallback.installPacketFilter(program);
    int flags = ApfProgramEvent.flagsFor(mIPv4Address != null, mMulticastFilter);
    mMetricsLog.log(new ApfProgramEvent(programMinLifetime, rasToFilter.size(), mRas.size(), program.length, flags));
}
Also used : IllegalInstructionException(android.net.apf.ApfGenerator.IllegalInstructionException) ApfGenerator(android.net.apf.ApfGenerator) ArrayList(java.util.ArrayList) ApfProgramEvent(android.net.metrics.ApfProgramEvent) VisibleForTesting(com.android.internal.annotations.VisibleForTesting) GuardedBy(com.android.internal.annotations.GuardedBy)

Aggregations

ApfProgramEvent (android.net.metrics.ApfProgramEvent)8 ApfGenerator (android.net.apf.ApfGenerator)4 IllegalInstructionException (android.net.apf.ApfGenerator.IllegalInstructionException)4 IpConnectivityLog (android.net.metrics.IpConnectivityLog)4 GuardedBy (com.android.internal.annotations.GuardedBy)4 VisibleForTesting (com.android.internal.annotations.VisibleForTesting)4 ArrayList (java.util.ArrayList)4 SmallTest (android.test.suitebuilder.annotation.SmallTest)3