Shared DHCP message counters exist, and the DHCPv4 and DHCPv6 engines count every message they receive and every reply they send #113

Open
opened 2026-10-31 12:42:09 -04:00 by claude · 0 comments
Owner
  • Draft: PQ-36
  • Priority: high (source of the DHCP message-rate chart)
  • Agent: coder
  • Depends on: none
  • Decisions: Q-PQ-12, R2-DHCP-RELAY

Why

Nothing counts DHCP traffic today. The only DHCP figures are the per-scope utilisation computed on demand (src/dotnet/src/Ninlil.Dhcp.Server.Core/Statistics/DhcpScopeStatistics.cs:41-48). The local engines dispatch on the message type in one place each: Dhcpv4RequestHandler.HandleRequestAsync (src/dotnet/src/Ninlil.Dhcp.Server.Core/Dhcpv4RequestHandler.cs:58-131) and Dhcpv6RequestHandler (src/dotnet/src/Ninlil.Dhcp.Server.Core/Dhcpv6RequestHandler.cs:287-345). The relay agents (#114) must record into the same counters, and Ninlil.Dhcp.Server.Relay references only Ninlil.Dns.Common, Ninlil.Dhcp.Common and the two protocol projects (Ninlil.Dhcp.Server.Relay.csproj:40-70), not Ninlil.Dhcp.Server.Core.

What changes

  • src/dotnet/src/Ninlil.Dhcp.Common/Statistics/ (new folder; the shared library both the engines and the relay reference):
    • IDhcpMessageCounters with RecordV4(Dhcpv4MessageTypeEnum received, Dhcpv4MessageTypeEnum? sent), RecordV6(Dhcpv6MessageTypeEnum received, Dhcpv6MessageTypeEnum? sent), RecordV4Relay(DhcpRelayCountEnum kind), RecordV6Relay(DhcpRelayCountEnum kind) and DhcpMessageCountSnapshot Drain(), which returns the counts since the last drain and resets them.
    • DhcpRelayCountEnum: RequestForwarded, ReplyForwarded, Dropped.
    • DhcpMessageCounters: fixed arrays indexed by message type and relay kind, Interlocked increments and Interlocked.Exchange on drain, so a message costs no allocation and no lock.
    • A null sent type counts as "no reply" (no scope, no free address, or a message the server ignores).
  • Both handlers take IDhcpMessageCounters as an optional constructor parameter (null = no counting, so existing tests compile) and record once per handled message, after the switch, from the reply's own message type.
  • Register the singleton with TryAddSingleton in ServiceCollectionDhcpServerCoreExtension (DHCPv4 local engine) and the DHCPv6 core registration, so both engines share one instance. #114 adds the same TryAddSingleton to the relay registrations, so a node with one protocol local and the other relayed (src/dotnet/src/Ninlil.Web/Startup/DhcpServiceRegistration.cs:42-76) still has one instance.

Acceptance

  • Test fails first in src/dotnet/tests/Ninlil.Dhcp.Server.Core.Tests: a DISCOVER that gets an OFFER and a REQUEST that gets a NAK drain to received DISCOVER = 1, sent OFFER = 1, received REQUEST = 1, sent NAK = 1.
  • Test: a SOLICIT with no matching scope counts received SOLICIT = 1 and no reply = 1.
  • Test: relay counts recorded through RecordV4Relay drain separately from the engine counts; a second Drain() returns zeros.
  • src/dotnet/benchmarks/Ninlil.Benchmarks/Dhcp/DhcpOfferBenchmarks.cs before and after, numbers in the PR.
  • Ninlil.Dhcp.Common is shared: the whole solution passes. No schema, API or option change.

Source

  • Owner decision 2026-10-31 (Q-PQ-12): "DHCP charts when DHCP is on (… offers/acks/naks)".
  • Owner decision 2026-10-31, round 2 (R2-DHCP-RELAY): relayed traffic is counted, so the counters live where the relay can reach them.
  • RFC 2131 §3.1 (DHCPv4 message flow); RFC 9915 §7.3 (DHCPv6 message types).
- **Draft:** PQ-36 - **Priority:** high (source of the DHCP message-rate chart) - **Agent:** coder - **Depends on:** none - **Decisions:** Q-PQ-12, R2-DHCP-RELAY ### Why Nothing counts DHCP traffic today. The only DHCP figures are the per-scope utilisation computed on demand (`src/dotnet/src/Ninlil.Dhcp.Server.Core/Statistics/DhcpScopeStatistics.cs:41-48`). The local engines dispatch on the message type in one place each: `Dhcpv4RequestHandler.HandleRequestAsync` (`src/dotnet/src/Ninlil.Dhcp.Server.Core/Dhcpv4RequestHandler.cs:58-131`) and `Dhcpv6RequestHandler` (`src/dotnet/src/Ninlil.Dhcp.Server.Core/Dhcpv6RequestHandler.cs:287-345`). The relay agents (#114) must record into the same counters, and `Ninlil.Dhcp.Server.Relay` references only `Ninlil.Dns.Common`, `Ninlil.Dhcp.Common` and the two protocol projects (`Ninlil.Dhcp.Server.Relay.csproj:40-70`), not `Ninlil.Dhcp.Server.Core`. ### What changes - `src/dotnet/src/Ninlil.Dhcp.Common/Statistics/` (new folder; the shared library both the engines and the relay reference): - `IDhcpMessageCounters` with `RecordV4(Dhcpv4MessageTypeEnum received, Dhcpv4MessageTypeEnum? sent)`, `RecordV6(Dhcpv6MessageTypeEnum received, Dhcpv6MessageTypeEnum? sent)`, `RecordV4Relay(DhcpRelayCountEnum kind)`, `RecordV6Relay(DhcpRelayCountEnum kind)` and `DhcpMessageCountSnapshot Drain()`, which returns the counts since the last drain and resets them. - `DhcpRelayCountEnum`: `RequestForwarded`, `ReplyForwarded`, `Dropped`. - `DhcpMessageCounters`: fixed arrays indexed by message type and relay kind, `Interlocked` increments and `Interlocked.Exchange` on drain, so a message costs no allocation and no lock. - A `null` sent type counts as "no reply" (no scope, no free address, or a message the server ignores). - Both handlers take `IDhcpMessageCounters` as an optional constructor parameter (null = no counting, so existing tests compile) and record once per handled message, after the switch, from the reply's own message type. - Register the singleton with `TryAddSingleton` in `ServiceCollectionDhcpServerCoreExtension` (DHCPv4 local engine) and the DHCPv6 core registration, so both engines share one instance. #114 adds the same `TryAddSingleton` to the relay registrations, so a node with one protocol local and the other relayed (`src/dotnet/src/Ninlil.Web/Startup/DhcpServiceRegistration.cs:42-76`) still has one instance. ### Acceptance - [ ] Test fails first in `src/dotnet/tests/Ninlil.Dhcp.Server.Core.Tests`: a DISCOVER that gets an OFFER and a REQUEST that gets a NAK drain to `received DISCOVER = 1`, `sent OFFER = 1`, `received REQUEST = 1`, `sent NAK = 1`. - [ ] Test: a SOLICIT with no matching scope counts `received SOLICIT = 1` and `no reply = 1`. - [ ] Test: relay counts recorded through `RecordV4Relay` drain separately from the engine counts; a second `Drain()` returns zeros. - [ ] `src/dotnet/benchmarks/Ninlil.Benchmarks/Dhcp/DhcpOfferBenchmarks.cs` before and after, numbers in the PR. - [ ] `Ninlil.Dhcp.Common` is shared: the whole solution passes. No schema, API or option change. ### Source - Owner decision 2026-10-31 (Q-PQ-12): "DHCP charts when DHCP is on (… offers/acks/naks)". - Owner decision 2026-10-31, round 2 (R2-DHCP-RELAY): relayed traffic is counted, so the counters live where the relay can reach them. - RFC 2131 §3.1 (DHCPv4 message flow); RFC 9915 §7.3 (DHCPv6 message types).
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
lantea-one/ninlil#113
No description provided.