Skip to content

feat(usid): Count VRF traffic in both directions - #846

Merged
privateip merged 1 commit into
mainfrom
feat/usid-vrf-direction-metrics
Oct 12, 2026
Merged

privateip merged 1 commit into
mainfrom
feat/usid-vrf-direction-metrics

Conversation

@privateip

@privateip privateip commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Operators could see a VPC's traffic only inbound, counted before drops and including tunnel headers, and nothing counted a VPC's outbound traffic or its datapath drops per VPC.

The datapath now counts forwarded packets, tenant bytes and drops for each VPC on each node, inbound and outbound, including traffic between two pods on the same node, which never crosses the fabric.

The counts live in a new per-CPU map that userspace keeps in step with the VRF map, so no existing map changes layout and no attachment loses its rows on upgrade.

Maps and metrics

added      vrf_traffic_counters   PERCPU_HASH, 8192 rows, keyed like vrf_table
recreated  none
unchanged  every other map, including the ones only CNI ADD writes:
           locator_table, function_table, vrf_table, ifindex_vrf_table,
           ifindex_egress_kind_table

new series, labels block, argument, vrf_table_id, vpc, vpc_attachment, direction
  galactic_usid_vrf_forwarded_packets_total
  galactic_usid_vrf_forwarded_bytes_total
  galactic_usid_vrf_dropped_packets_total
cardinality: at most 2 x vrf_table rows per node per metric

The names say "forwarded" because they count a packet once the datapath commits to forwarding it, unlike the existing per-VRF packet and byte counters, which count every claimed inbound packet, drops included, and stay as they are.

Lab results and the merge order with four overlapping PRs are in the first comment.

Test plan

  • Cross-site traffic moves inbound and outbound counters on both VPCs by exactly the packets and tenant bytes sent
  • Same-node traffic counts once in each direction, and traffic to a pod's own gateway counts in neither
  • An upgraded node reports series for its existing VPCs right after the CNI pod restarts
  • Lint, unit, privileged datapath and Kind e2e tests pass, with every program under the verifier cost budget

Related to #589

@privateip privateip self-assigned this Oct 12, 2026
@privateip
privateip force-pushed the feat/usid-vrf-direction-metrics branch from c5dbf5f to 2d178be Compare October 12, 2026 17:13
The uSID datapath counted per-VRF traffic only inbound, at the vrf_table
match and including packets dropped afterwards, and never exported its
per-VRF drop count. Outbound tenant traffic was not counted per VRF.

Add vrf_traffic_counters, a per-CPU hash keyed like vrf_table, holding
forwarded packets, tenant bytes and claimed drops for each direction:

- ingress at usid_ingress's warm and cold-neighbor redirects
- egress at usid_egress's encapsulating and VIP-reply redirects, which
  covers egress shards, and at the service path's redirects
- same-node traffic, which never reaches usid_ingress, once in each
  direction at the receiver's local pass-through entry, except traffic
  to the sender's own gateway
- drops at every count_claimed_drop site, split by direction

Bytes are the tenant packet alone in both directions. The map is
additive; no existing map changes layout. The datapath only looks rows
up. VRFTable creates a row with BPF_NOEXIST on Register, removes it on
Unregister and reconciles both maps on every GC pass, so every
vrf_table writer keeps them in step, and galactic-cni syncs them once
at load so an upgraded node counts from its first packet.

Export galactic_usid_vrf_forwarded_packets_total,
galactic_usid_vrf_forwarded_bytes_total and
galactic_usid_vrf_dropped_packets_total, each with a direction label.
The existing galactic_usid_vrf_{packets,bytes}_total are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@privateip
privateip force-pushed the feat/usid-vrf-direction-metrics branch from 2d178be to d48b138 Compare October 12, 2026 17:14
@privateip privateip changed the title feat(usid): Count each VRF's traffic in both directions feat(usid): Count VRF traffic in both directions Oct 12, 2026
@privateip

Copy link
Copy Markdown
Contributor Author

Lab results from the containerlab lab running this branch's CNI image: 20 ICMPv6 echoes of 148 bytes each. Site A to site B in VPC 10 crosses the fabric, and the two VPC 30 pods share one node, so each echo and each reply counts once in each direction there. Every series that stayed at zero is left out.

# site A node, VPC 10 (cross-site ping to site B)
galactic_usid_vrf_forwarded_bytes_total{argument="4",block="0x20010db8ff01",direction="egress",vpc="10",vpc_attachment="10",vrf_table_id="2"} 2960
galactic_usid_vrf_forwarded_bytes_total{argument="4",block="0x20010db8ff01",direction="ingress",vpc="10",vpc_attachment="10",vrf_table_id="2"} 2960
galactic_usid_vrf_forwarded_packets_total{argument="4",block="0x20010db8ff01",direction="egress",vpc="10",vpc_attachment="10",vrf_table_id="2"} 20
galactic_usid_vrf_forwarded_packets_total{argument="4",block="0x20010db8ff01",direction="ingress",vpc="10",vpc_attachment="10",vrf_table_id="2"} 20
# site B node, VPC 10
galactic_usid_vrf_forwarded_bytes_total{argument="1",block="0x20010db8ff02",direction="egress",vpc="10",vpc_attachment="10",vrf_table_id="1"} 2960
galactic_usid_vrf_forwarded_bytes_total{argument="1",block="0x20010db8ff02",direction="ingress",vpc="10",vpc_attachment="10",vrf_table_id="1"} 2960
galactic_usid_vrf_forwarded_packets_total{argument="1",block="0x20010db8ff02",direction="egress",vpc="10",vpc_attachment="10",vrf_table_id="1"} 20
galactic_usid_vrf_forwarded_packets_total{argument="1",block="0x20010db8ff02",direction="ingress",vpc="10",vpc_attachment="10",vrf_table_id="1"} 20
# site A node, VPC 30 (two pods on this node)
galactic_usid_vrf_forwarded_bytes_total{argument="2",block="0x20010db8ff01",direction="egress",vpc="30",vpc_attachment="30",vrf_table_id="4"} 5920
galactic_usid_vrf_forwarded_bytes_total{argument="2",block="0x20010db8ff01",direction="ingress",vpc="30",vpc_attachment="30",vrf_table_id="4"} 5920
galactic_usid_vrf_forwarded_packets_total{argument="2",block="0x20010db8ff01",direction="egress",vpc="30",vpc_attachment="30",vrf_table_id="4"} 40
galactic_usid_vrf_forwarded_packets_total{argument="2",block="0x20010db8ff01",direction="ingress",vpc="30",vpc_attachment="30",vrf_table_id="4"} 40

Merge order. #596 and #598 change the same datapath source, its metrics and the installer, #613 changes the installer, and #597 changes the CNI architecture doc. Each one that merges after this needs a rebase, and #596 and #598 also need a fresh verifier cost check. Which lands first is open.

@privateip
privateip marked this pull request as ready for review October 12, 2026 18:04
@privateip
privateip requested a review from a team as a code owner October 12, 2026 18:04
@privateip
privateip merged commit e4e5227 into main Oct 12, 2026
15 checks passed
@privateip
privateip deleted the feat/usid-vrf-direction-metrics branch October 12, 2026 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants