/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

syntax = "proto2";
option java_multiple_files = true;

package com.android.networkstack.metrics;

import "frameworks/proto_logging/stats/enums/stats/connectivity/network_stack.proto";

message CapportApiData {
    // The TTL of the network connection provided by captive portal
    optional int32 remaining_ttl_secs = 1;

    // The limit traffic data of the network connection provided by captive portal
    optional int32 remaining_bytes = 2;

    // Is portal url option included in the DHCP packet (Yes, No)
    optional bool has_portal_url = 3;

    // Is venue info (e.g. store info, maps, flight status) included (Yes, No)
    optional bool has_venue_info = 4;
}

message ProbeEvent {
    // The probe type (http or https, or captive portal API...)
    optional .android.stats.connectivity.ProbeType probe_type = 1;

    // The latency in microseconds of the probe event
    optional int32 latency_micros = 2;

    // The result of the probe event
    optional .android.stats.connectivity.ProbeResult probe_result = 3;

    // The CaptivePortal API info
    optional CapportApiData capport_api_data = 4;
}

message ProbeEvents {
    // Record probe event during the validation
    repeated ProbeEvent probe_event = 1;
}

/**
 * The DHCP (Dynamic Host Configuration Protocol) session info
 * Logged from:
 * src/android/net/dhcp/DhcpClient.java
 */
message DhcpSession {
    // The DHCP Feature(s) enabled in this session
    repeated .android.stats.connectivity.DhcpFeature used_features = 1;

    // The discover packet (re)transmit count
    optional int32 discover_count = 2;

    // The request packet (re)transmit count
    optional int32 request_count = 3;

    // The IPv4 address conflict count
    // (only be meaningful when duplicate address detection is enabled)
    optional int32 conflict_count = 4;

    // The DHCP packet parsing error code in this session
    // (defined in android.net.metrics.DhcpErrorEvent)
    repeated .android.stats.connectivity.DhcpErrorCode error_code = 5;

    // The result of DHCP hostname transliteration
    optional .android.stats.connectivity.HostnameTransResult ht_result = 6;
}

/**
 * Logs Network IP provisioning event
 * Logged from:
 * src/com/android/networkstack/metrics/NetworkIpProvisioningMetrics.java
 */
message NetworkIpProvisioningReported {
    // Transport type (WIFI, CELLULAR, BLUETOOTH, ..)
    optional .android.stats.connectivity.TransportType transport_type = 1;

    // The latency in microseconds of IP Provisioning over IPV4
    optional int32 ipv4_latency_micros = 2;

    // The latency in microseconds of IP Provisioning over IPV6
    optional int32 ipv6_latency_micros = 3;

    // The time duration between provisioning start and end (success or failure)
    optional int64 provisioning_duration_micros = 4;

    // The specific disconnect reason for this IP provisioning
    optional .android.stats.connectivity.DisconnectCode disconnect_code = 5;

    // Log DHCP session info (Only valid for IPv4)
    optional DhcpSession dhcp_session = 6;

    // The random number between 0 ~ 999 for sampling
    optional int32 random_number = 7;

    // Check which IPv6 provisioning mode is used for current connection
    optional .android.stats.connectivity.Ipv6ProvisioningMode ipv6_provisioning_mode = 8;

    // The event count of ignoring the organic NUD failure within the IP provisioning
    // life cycle.
    optional int32 ignore_nud_failure_count = 9;

    // The event count of querying the NUD failure from database within the IP provisioning
    // life cycle.
    optional int32 query_nud_failure_count = 10;
}

/**
 * Logs Network DHCP Renew event
 * Logged from:
 * src/android/net/dhcp/DhcpClient.java
 */
message NetworkDhcpRenewReported {
    // Transport type (WIFI, CELLULAR, BLUETOOTH, ..)
    optional .android.stats.connectivity.TransportType transport_type = 1;

    // The request packet (re)transmit count
    optional int32 request_count = 2;

    // The latency in microseconds of DHCP Renew
    optional int32 latency_micros = 3;

    // The DHCP error code is defined in android.net.metrics.DhcpErrorEvent
    optional .android.stats.connectivity.DhcpErrorCode error_code = 4;

    // The result of DHCP renew
    optional .android.stats.connectivity.DhcpRenewResult renew_result = 5;

    // The random number between 0 ~ 999 for sampling
    optional int32 random_number = 6;
}

/**
 * Logs Network Validation event
 * Logged from:
 * src/com/android/server/connectivity/NetworkMonitor.java
 */
message NetworkValidationReported {
    // Transport type (WIFI, CELLULAR, BLUETOOTH, ..)
    optional .android.stats.connectivity.TransportType transport_type = 1;

    // Record each probe event
    optional ProbeEvents probe_events = 2;

    // The result of the network validation
    optional .android.stats.connectivity.ValidationResult validation_result = 3;

    // The latency in microseconds of network validation
    optional int32 latency_micros = 4;

    // The validation index (the first validation attempt or second, third...)
    optional int32 validation_index = 5;

    // The random number between 0 ~ 999 for sampling
    optional int32 random_number = 6;
}

/**
 * Logs NetworkStack Quirk event
 * Logged from:
 * src/com/android/networkstack/
 * This will be defined as count metrics on server side
 */
message NetworkStackQuirkReported {
    // Transport type (WIFI, CELLULAR, BLUETOOTH, ..)
    optional .android.stats.connectivity.TransportType transport_type = 1;

    // Record each Quirk event
    optional .android.stats.connectivity.NetworkQuirkEvent event = 2;
}

/**
 * Logs Neighbor Unreachability Detection probe event.
 * Logged from:
 * src/com/android/networkstack/metrics/IpReachabilityMonitorMetrics.java
 */
message NetworkIpReachabilityMonitorReported {
    // Neighbor Unreachability Detection event.
    optional .android.stats.connectivity.NudEventType event_type = 1;

    // NUD probe based on IPv4 ARP or IPv6 ND packet.
    optional .android.stats.connectivity.IpType ip_type = 2;

    // NUD neighbor type, default gateway, DNS server or both.
    optional .android.stats.connectivity.NudNeighborType neighbor_type = 3;
}

/**
 * Logs Ip client RA(Router Advertisement) info
 * Logged from:
 * packages/modules/NetworkStack/src/android/net/ip/IpClient.java
 */
message IpClientRaInfoReported {
    // The maximum number of distinct RAs (Router Advertisements).
    optional int32 max_number_of_distinct_ras = 1;

    // The number of zero lifetime RAs (Router Advertisements).
    optional int32 number_of_zero_lifetime_ras = 2;

    // The number of parsing error for RAs (Router Advertisements).
    optional int32 number_of_parsing_error_ras = 3;

    // The lowest router lifetime in seconds, excluding 0.
    optional int32 lowest_router_lifetime_seconds = 4;

    // The lowest valid lifetime of PIO (Prefix Information Option) in seconds, excluding 0.
    optional int64 lowest_pio_valid_lifetime_seconds = 5;

    // The lowest route lifetime of RIO (Route Information Option) in seconds, excluding 0.
    optional int64 lowest_rio_route_lifetime_seconds = 6;

    // The lowest lifetime of RDNSS (Recursive DNS Server Option) in seconds, excluding 0.
    optional int64 lowest_rdnss_lifetime_seconds = 7;
}

/**
 * Logs value of the APF counter.
 */
message ApfCounter {
    // The name of APF counter.
    optional .android.stats.connectivity.CounterName counter_name = 1;

    // The value of APF counter.
    optional int64 counter_value = 2;
}

message ApfCounterList {
    repeated ApfCounter apf_counter = 1;
}

/**
 * Logs APF session information event.
 * Logged from:
 * packages/modules/NetworkStack/src/android/net/apf/ApfFilter.java
 */
message ApfSessionInfoReported {
    // The version of APF, where version = -1 equals APF disable.
    optional int32 version = 1;

    // The memory size of APF module.
    optional int32 memory_size = 2;

    // The values of all APF counters.
    optional ApfCounterList apf_counter_list = 3;

    // The duration of APF session in seconds.
    optional int32 apf_session_duration_seconds = 4;

    // Number of times APF program updated.
    optional int32 num_of_times_apf_program_updated = 5;

    // Record the maximum of program size.
    optional int32 max_program_size = 6;
}
