netstack3_ip/multicast_forwarding/
counters.rs

1// Copyright 2024 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5//! Declares counters for observability/debugging of multicast forwarding.
6
7use net_types::ip::{Ip, IpVersionMarker};
8use netstack3_base::{Counter, Inspectable, Inspector, InspectorExt as _};
9
10/// Multicast Forwarding counters.
11#[derive(Default)]
12pub struct MulticastForwardingCounters<I: Ip> {
13    _marker: IpVersionMarker<I>,
14
15    /// Count of packets that were received and consulted the multicast
16    /// forwarding engine.
17    pub(super) rx: Counter,
18    /// Count of packets that were forwarded.
19    ///
20    /// This does not include packets that were forwarded from the pending table
21    /// (i.e. `pending_packet_tx`).
22    ///
23    /// Note this counter is incremented once per packet, not once per target.
24    /// Forwarding a packet via a route with multiple targets will only increase
25    /// this counter by 1.
26    pub(super) tx: Counter,
27    /// Count of packets that were not forwarded because their src/dst addresses
28    /// did not constitute a valid multicast routing key.
29    pub(super) no_tx_invalid_key: Counter,
30    /// Count of packets that were not forwarded because their input device had
31    /// multicast forwarding disabled.
32    pub(super) no_tx_disabled_dev: Counter,
33    /// Count of packets that were not forwarded because multicast forwarding
34    /// is disabled stack wide.
35    pub(super) no_tx_disabled_stack_wide: Counter,
36    /// Count of packets that were not forwarded because their input device
37    /// does not match the route's expected input device.
38    pub(super) no_tx_wrong_dev: Counter,
39    /// Count of packets that did not have an applicable route and were
40    /// (attempted to be) added to the pending table.
41    pub(super) pending_packets: Counter,
42    /// Count of packets that failed to be added to the pending table because
43    /// the queue was full.
44    pub(super) pending_packet_drops_queue_full: Counter,
45    /// Count of pending packets that were forwarded.
46    pub(super) pending_packet_tx: Counter,
47    /// Count of pending packets that were dropped because their input device
48    /// had multicast forwarding disabled.
49    pub(super) pending_packet_drops_disabled_dev: Counter,
50    /// Count of pending packets that were dropped because their input device
51    /// does not match the route's expected input device.
52    pub(super) pending_packet_drops_wrong_dev: Counter,
53    /// Count of pending packets that were garbage collected before an
54    /// applicable route was installed.
55    pub(super) pending_packet_drops_gc: Counter,
56    /// Count of times the pending table has been garbage collected.
57    pub(super) pending_table_gc: Counter,
58}
59
60impl<I: Ip> Inspectable for MulticastForwardingCounters<I> {
61    fn record<II: Inspector>(&self, inspector: &mut II) {
62        let Self {
63            _marker,
64            rx,
65            tx,
66            no_tx_invalid_key,
67            no_tx_disabled_dev,
68            no_tx_disabled_stack_wide,
69            no_tx_wrong_dev,
70            pending_packets,
71            pending_packet_drops_queue_full,
72            pending_packet_tx,
73            pending_packet_drops_disabled_dev,
74            pending_packet_drops_wrong_dev,
75            pending_packet_drops_gc,
76            pending_table_gc,
77        } = self;
78        inspector.record_counter("PacketsReceived", rx);
79        inspector.record_counter("PacketsForwarded", tx);
80        inspector.record_child("PacketsNotForwardedWithReason", |inspector| {
81            inspector.record_counter("InvalidKey", no_tx_invalid_key);
82            inspector.record_counter("ForwardingDisabledOnInputDevice", no_tx_disabled_dev);
83            inspector.record_counter("ForwardingDisabledForStack", no_tx_disabled_stack_wide);
84            inspector.record_counter("WrongInputDevice", no_tx_wrong_dev);
85        });
86        inspector.record_counter("PendingPackets", pending_packets);
87        inspector.record_counter("PendingPacketsForwarded", pending_packet_tx);
88        inspector.record_child("PendingPacketsNotForwardedWithReason", |inspector| {
89            inspector.record_counter("QueueFull", pending_packet_drops_queue_full);
90            inspector.record_counter(
91                "ForwardingDisabledOnInputDevice",
92                pending_packet_drops_disabled_dev,
93            );
94            inspector.record_counter("WrongInputDevice", pending_packet_drops_wrong_dev);
95            inspector.record_counter("GarbageCollected", pending_packet_drops_gc);
96        });
97        inspector.record_counter("PendingTableGcRuns", pending_table_gc);
98    }
99}