1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.networkstack.metrics; 18 19 /** 20 * Class to record the network stack IpClientRaInfo metrics into statsd. 21 * 22 * This class is not thread-safe, and should always be accessed from the same thread. 23 * 24 * @hide 25 */ 26 public class IpClientRaInfoMetrics { 27 private final IpClientRaInfoReported.Builder mStatsBuilder = 28 IpClientRaInfoReported.newBuilder(); 29 30 /** 31 * Write the maximum number of distinct RAs into mStatsBuilder. 32 */ setMaxNumberOfDistinctRas(final int maxNum)33 public void setMaxNumberOfDistinctRas(final int maxNum) { 34 mStatsBuilder.setMaxNumberOfDistinctRas(maxNum); 35 } 36 37 /** 38 * Write the number of zero lifetime RAs into mStatsBuilder. 39 */ setNumberOfZeroLifetimeRas(final int number)40 public void setNumberOfZeroLifetimeRas(final int number) { 41 mStatsBuilder.setNumberOfZeroLifetimeRas(number); 42 } 43 44 /** 45 * Write the number of parsing error RAs into mStatsBuilder. 46 */ setNumberOfParsingErrorRas(final int number)47 public void setNumberOfParsingErrorRas(final int number) { 48 mStatsBuilder.setNumberOfParsingErrorRas(number); 49 } 50 51 /** 52 * Write the lowest router lifetime into mStatsBuilder. 53 */ setLowestRouterLifetimeSeconds(final int lifetime)54 public void setLowestRouterLifetimeSeconds(final int lifetime) { 55 mStatsBuilder.setLowestRouterLifetimeSeconds(lifetime); 56 } 57 58 /** 59 * Write the lowest valid lifetime of PIOs into mStatsBuilder. 60 */ setLowestPioValidLifetimeSeconds(final long lifetime)61 public void setLowestPioValidLifetimeSeconds(final long lifetime) { 62 mStatsBuilder.setLowestPioValidLifetimeSeconds(lifetime); 63 } 64 65 /** 66 * Write the lowest route lifetime of RIOs into mStatsBuilder. 67 */ setLowestRioRouteLifetimeSeconds(final long lifetime)68 public void setLowestRioRouteLifetimeSeconds(final long lifetime) { 69 mStatsBuilder.setLowestRioRouteLifetimeSeconds(lifetime); 70 } 71 72 /** 73 * Write the lowest lifetime of RDNSSs into mStatsBuilder. 74 */ setLowestRdnssLifetimeSeconds(final long lifetime)75 public void setLowestRdnssLifetimeSeconds(final long lifetime) { 76 mStatsBuilder.setLowestRdnssLifetimeSeconds(lifetime); 77 } 78 79 /** 80 * Write the IpClientRaInfoReported proto into statsd. 81 */ statsWrite()82 public IpClientRaInfoReported statsWrite() { 83 final IpClientRaInfoReported stats = mStatsBuilder.build(); 84 NetworkStackStatsLog.write(NetworkStackStatsLog.IP_CLIENT_RA_INFO_REPORTED, 85 stats.getMaxNumberOfDistinctRas(), 86 stats.getNumberOfZeroLifetimeRas(), 87 stats.getNumberOfParsingErrorRas(), 88 stats.getLowestRouterLifetimeSeconds(), 89 stats.getLowestPioValidLifetimeSeconds(), 90 stats.getLowestRioRouteLifetimeSeconds(), 91 stats.getLowestRdnssLifetimeSeconds()); 92 return stats; 93 } 94 } 95