Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 884970e0 authored by Hugo Benichi's avatar Hugo Benichi
Browse files

Define PacketWakeup pushed events for statds

This patch pushes packet wakeup events collected by
NetdEventListenerService into the statds service.

Example logs from $ adb logcat -b stats
11-20 23:33:25.955   955   972 I [44]    : [10014,wlan0,34525,10:e:7e:26:3f:c1,2001:db8:400d:c0b::bc,2001:db8:4:fd00:a00a:dbc8:f5ba:4269,6,5228,49411]
11-20 23:37:05.809   955  1473 I [44]    : [10014,wlan0,2048,10:e:7e:26:3f:c1,192.168.0.142,192.168.0.39,6,443,45422]
11-20 23:42:09.233   955  1473 I [44]    : [10014,wlan0,2048,10:e:7e:26:3f:c1,192.168.12.238,192.168.0.39,6,443,40160]
11-20 23:55:28.162   955  1207 I [44]    : [10059,wlan0,34525,10:e:7e:26:3f:c1,2001:db8:4004:807::200a,2001:db8:4:fd00:a00a:dbc8:f5ba:4269,6,443,42492]
11-20 23:59:18.343   955  1888 I [44]    : [10059,wlan0,34525,10:e:7e:26:3f:c1,2001:db8:4004:807::200a,2001:db8:4:fd00:a00a:dbc8:f5ba:4269,6,443,42491]
11-21 00:00:17.952   955  3341 I [44]    : [10014,wlan0,34525,10:e:7e:26:3f:c1,2001:db8:400d:c0b::bc,2001:db8:4:fd00:a00a:dbc8:f5ba:4269,6,5228,49411]
11-21 00:13:05.552   955  1473 I [44]    : [-1,wlan0,34525,10:e:7e:26:3f:c1,2001:db8:4004:805::200a,2001:db8:4:fd00:a00a:dbc8:f5ba:4269,6,443,38098]
11-21 00:13:50.606   955  1207 I [44]    : [-1,wlan0,2048,10:e:7e:26:3f:c1,192.168.5.238,192.168.0.39,6,443,40802]

Bug: 28806131
Test: runtest frameworks-net
Change-Id: I5a3c76498a4b720f0d9308a65b5dd4b32377d0d1
parent b92f1eed
Loading
Loading
Loading
Loading
+30 −0
Original line number Original line Diff line number Diff line
@@ -73,6 +73,7 @@ message Atom {
        SettingChanged setting_changed = 41;
        SettingChanged setting_changed = 41;
        ActivityForegroundStateChanged activity_foreground_state_changed = 42;
        ActivityForegroundStateChanged activity_foreground_state_changed = 42;
        IsolatedUidChanged isolated_uid_changed = 43;
        IsolatedUidChanged isolated_uid_changed = 43;
        PacketWakeupOccurred packet_wakeup_occurred = 44;
        // TODO: Reorder the numbering so that the most frequent occur events occur in the first 15.
        // TODO: Reorder the numbering so that the most frequent occur events occur in the first 15.
    }
    }


@@ -906,3 +907,32 @@ message CpuTimePerUidFreqPulled {
    optional uint64 freq_idx = 2;
    optional uint64 freq_idx = 2;
    optional uint64 time_ms = 3;
    optional uint64 time_ms = 3;
}
}

/*
 * Logs the reception of an incoming network packet causing the main system to wake up for
 * processing that packet. These events are notified by the kernel via Netlink NFLOG to Netd
 * and processed by WakeupController.cpp.
 */
message PacketWakeupOccurred {
    // The uid owning the socket into which the packet was delivered, or -1 if the packet was
    // delivered nowhere.
    optional int32 uid = 1;
    // The interface name on which the packet was received.
    optional string iface = 2;
    // The ethertype value of the packet.
    optional int32 ethertype = 3;
    // String representation of the destination MAC address of the packet.
    optional string destination_hardware_address = 4;
    // String representation of the source address of the packet if this was an IP packet.
    optional string source_ip = 5;
    // String representation of the destination address of the packet if this was an IP packet.
    optional string destination_ip = 6;
    // The value of the protocol field if this was an IPv4 packet or the value of the Next Header
    // field if this was an IPv6 packet. The range of possible values is the same for both IP
    // families.
    optional int32 ip_next_header = 7;
    // The source port if this was a TCP or UDP packet.
    optional int32 source_port = 8;
    // The destination port if this was a TCP or UDP packet.
    optional int32 destination_port = 9;
}
+2 −2
Original line number Original line Diff line number Diff line
@@ -29,7 +29,7 @@ public class WakeupEvent {
    public String iface;
    public String iface;
    public int uid;
    public int uid;
    public int ethertype;
    public int ethertype;
    public byte[] dstHwAddr;
    public MacAddress dstHwAddr;
    public String srcIp;
    public String srcIp;
    public String dstIp;
    public String dstIp;
    public int ipNextHeader;
    public int ipNextHeader;
@@ -44,7 +44,7 @@ public class WakeupEvent {
        j.add(iface);
        j.add(iface);
        j.add("uid: " + Integer.toString(uid));
        j.add("uid: " + Integer.toString(uid));
        j.add("eth=0x" + Integer.toHexString(ethertype));
        j.add("eth=0x" + Integer.toHexString(ethertype));
        j.add("dstHw=" + MacAddress.stringAddrFromByteAddr(dstHwAddr));
        j.add("dstHw=" + dstHwAddr);
        if (ipNextHeader > 0) {
        if (ipNextHeader > 0) {
            j.add("ipNxtHdr=" + ipNextHeader);
            j.add("ipNxtHdr=" + ipNextHeader);
            j.add("srcIp=" + srcIp);
            j.add("srcIp=" + srcIp);
+1 −2
Original line number Original line Diff line number Diff line
@@ -16,7 +16,6 @@


package android.net.metrics;
package android.net.metrics;


import android.net.MacAddress;
import android.os.Process;
import android.os.Process;
import android.os.SystemClock;
import android.os.SystemClock;
import android.util.SparseIntArray;
import android.util.SparseIntArray;
@@ -80,7 +79,7 @@ public class WakeupStats {
                break;
                break;
        }
        }


        switch (MacAddress.macAddressType(ev.dstHwAddr)) {
        switch (ev.dstHwAddr.addressType()) {
            case UNICAST:
            case UNICAST:
                l2UnicastCount++;
                l2UnicastCount++;
                break;
                break;
+7 −1
Original line number Original line Diff line number Diff line
@@ -21,6 +21,7 @@ import static android.util.TimeUtils.NANOS_PER_MS;
import android.content.Context;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.ConnectivityManager;
import android.net.INetdEventCallback;
import android.net.INetdEventCallback;
import android.net.MacAddress;
import android.net.Network;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkCapabilities;
import android.net.metrics.ConnectStats;
import android.net.metrics.ConnectStats;
@@ -35,6 +36,7 @@ import android.text.format.DateUtils;
import android.util.Log;
import android.util.Log;
import android.util.ArrayMap;
import android.util.ArrayMap;
import android.util.SparseArray;
import android.util.SparseArray;
import android.util.StatsLog;


import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting;
@@ -242,13 +244,17 @@ public class NetdEventListenerService extends INetdEventListener.Stub {
        event.timestampMs = timestampMs;
        event.timestampMs = timestampMs;
        event.uid = uid;
        event.uid = uid;
        event.ethertype = ethertype;
        event.ethertype = ethertype;
        event.dstHwAddr = dstHw;
        event.dstHwAddr = new MacAddress(dstHw);
        event.srcIp = srcIp;
        event.srcIp = srcIp;
        event.dstIp = dstIp;
        event.dstIp = dstIp;
        event.ipNextHeader = ipNextHeader;
        event.ipNextHeader = ipNextHeader;
        event.srcPort = srcPort;
        event.srcPort = srcPort;
        event.dstPort = dstPort;
        event.dstPort = dstPort;
        addWakeupEvent(event);
        addWakeupEvent(event);

        String dstMac = event.dstHwAddr.toString();
        StatsLog.write(StatsLog.PACKET_WAKEUP_OCCURRED,
                uid, iface, ethertype, dstMac, srcIp, dstIp, ipNextHeader, srcPort, dstPort);
    }
    }


    private void addWakeupEvent(WakeupEvent event) {
    private void addWakeupEvent(WakeupEvent event) {