show interfaces reports what has crossed the port (#1251) #1252

Merged
jaylouisw merged 1 commit from fix/interface-counters into main 2026-11-09 19:00:00 +00:00
Owner

show interfaces reports what has crossed the port

Fixes #1251.

Gi0 (ethernet, 1G), MAC 02:00:00:00:00:00
  status: up, protocol: up
  ip: 10.0.0.1/24
  peer: sw/Fa0/1
  4 packets input, 196 bytes
  4 packets output, 196 bytes

Two defects were stacked underneath the missing lines.

Per device, not per port. flow.counterFor() keeps {bytesIn, bytesOut, packetsIn, packetsOut} keyed
by devId, so there was no per-port figure to print.

Ping was never counted at all. Both counting sites were guarded by if (frame.l4):

if (out.l4) flowLib.countPacket(this.flowState, dev.id, 'out', out.l4.bytes || 0);
if (f.l4)   flowLib.countPacket(this.flowState, dev.id, 'in',  f.l4.bytes || 0);

An ICMP echo carries icmp, ARP carries arp, LLDP carries lldp — none carry l4. Measured after three
answered pings on a two-device lab: counter keys after ping: []. The traffic this simulator exists to
generate was invisible to its own counters.

Now

  • countPacket() keeps a per-port tally beside the device totals.
  • Every frame is counted, whichever builder produced it, with a payload size that is modelled rather than
    assumed
    : transport payload, the echo payload, ARP's 28 bytes, and the TLVs an LLDP frame is made of —
    lldp.buildFrame() computes its own payload length, so no counted packet reports zero bytes.
  • show interfaces prints both directions per port. With no simulation run it prints
    counters: not measured (no simulation run) instead of zeros: "nothing has looked" and "nothing crossed"
    are different answers.
  • Interface accounting stays separate from flow accounting. Device totals remain transport-only, so a
    switch sending an LLDP frame cannot move a connection's byte count; the per-port tally keeps both, and
    transportPacketsIn / transportBytesIn are what reconcile with the device totals.

Evidence

test/interface-counters.test.js — 29 checks:

  • a ping is counted on every port it crosses, both directions, with bytes;
  • a port with no traffic reads zero, not "unknown";
  • a host nobody addressed counts the broadcasts it received and no echo payload — taken from the frame
    log, not from a byte total, and it is the case that proved "reads zero" was the wrong assertion;
  • the addressed host carried strictly more than the quiet one;
  • a frame denied by an ACL still counts as received (that is what a real counter does) while no echo reply
    leaves the port;
  • the two accountings reconcile: per-port transport tallies equal the device totals, and the per-port
    interface tallies exceed them by exactly the control frames;
  • counters accumulate across runs, like real ones;
  • without a simulation the command says so.

test/flow.test.js is unchanged and still asserts exact transport totals — that is what the split is
for. Reverting the engine changes fails the new suite.

docs/CLI.md gains a "Counters" section under show interfaces.

Suite: 139 suites, 5,993 assertions, 0 failed.

`show interfaces` reports what has crossed the port Fixes #1251. ``` Gi0 (ethernet, 1G), MAC 02:00:00:00:00:00 status: up, protocol: up ip: 10.0.0.1/24 peer: sw/Fa0/1 4 packets input, 196 bytes 4 packets output, 196 bytes ``` Two defects were stacked underneath the missing lines. **Per device, not per port.** `flow.counterFor()` keeps `{bytesIn, bytesOut, packetsIn, packetsOut}` keyed by `devId`, so there was no per-port figure to print. **Ping was never counted at all.** Both counting sites were guarded by `if (frame.l4)`: ```js if (out.l4) flowLib.countPacket(this.flowState, dev.id, 'out', out.l4.bytes || 0); if (f.l4) flowLib.countPacket(this.flowState, dev.id, 'in', f.l4.bytes || 0); ``` An ICMP echo carries `icmp`, ARP carries `arp`, LLDP carries `lldp` — none carry `l4`. Measured after three answered pings on a two-device lab: `counter keys after ping: []`. The traffic this simulator exists to generate was invisible to its own counters. ## Now * `countPacket()` keeps a per-port tally beside the device totals. * Every frame is counted, whichever builder produced it, with a payload size that is **modelled rather than assumed**: transport payload, the echo payload, ARP's 28 bytes, and the TLVs an LLDP frame is made of — `lldp.buildFrame()` computes its own payload length, so no counted packet reports zero bytes. * `show interfaces` prints both directions per port. With **no simulation run** it prints `counters: not measured (no simulation run)` instead of zeros: "nothing has looked" and "nothing crossed" are different answers. * **Interface accounting stays separate from flow accounting.** Device totals remain transport-only, so a switch sending an LLDP frame cannot move a connection's byte count; the per-port tally keeps both, and `transportPacketsIn` / `transportBytesIn` are what reconcile with the device totals. ## Evidence `test/interface-counters.test.js` — 29 checks: * a ping is counted on every port it crosses, both directions, with bytes; * a port with no traffic reads **zero, not "unknown"**; * a host nobody addressed counts the broadcasts it received and **no echo payload** — taken from the frame log, not from a byte total, and it is the case that proved "reads zero" was the wrong assertion; * the addressed host carried strictly more than the quiet one; * a frame denied by an ACL still counts as received (that is what a real counter does) while no echo reply leaves the port; * the two accountings reconcile: per-port transport tallies equal the device totals, and the per-port interface tallies exceed them by exactly the control frames; * counters accumulate across runs, like real ones; * without a simulation the command says so. `test/flow.test.js` is **unchanged** and still asserts exact transport totals — that is what the split is for. Reverting the engine changes fails the new suite. `docs/CLI.md` gains a "Counters" section under `show interfaces`. Suite: 139 suites, 5,993 assertions, 0 failed.
show interfaces reports what has crossed the port (#1251)
All checks were successful
CI / Classify the change (pull_request) Successful in 12s
PR rebase / Rebase onto main and arm auto-merge (pull_request) Successful in 14s
CI / Test (Node 20) (pull_request) Successful in 1m50s
CI / Test (Node 18) (pull_request) Successful in 1m55s
CI / Server smoke test (pull_request) Successful in 34s
CI / Docker build (pull_request) Successful in 42s
CI / Test (Node 22) (pull_request) Successful in 1m41s
ecfcc99c95
The command printed the link state, the address and the peer - and nothing about traffic, which is the one
question it is opened for when a link is quiet. Two defects underneath:

1. The counters were per device (`flow.counterFor()` keeps them keyed by devId), so no per-port figure
   existed to print.
2. Both counting sites were guarded by `if (frame.l4)`, and an ICMP echo carries `icmp`, an ARP frame
   carries `arp`, an LLDP frame carries `lldp`. Measured after three answered pings: `counter keys after
   ping: []`. The traffic a packet simulator exists to generate was invisible to its own counters.

Now:
* `countPacket()` also keeps a per-port tally, so a socket can be asked about on its own.
* Every frame is counted, whichever builder produced it, with a payload size that is modelled rather than
  assumed: transport payload, the echo payload, ARP's 28 bytes, and the TLVs an LLDP frame is made of
  (`lldp.buildFrame()` now computes its own payload length, so no counted packet reports zero bytes).
* `show interfaces` prints `N packets input, B bytes` / `N packets output, B bytes` per port; with no
  simulation run it prints `counters: not measured (no simulation run)` instead of zeros, because "nothing
  has looked" and "nothing crossed" are different answers.
* Interface accounting stays separate from flow accounting: the device totals remain transport-only, so a
  switch sending an LLDP frame cannot move a connection's byte count. The per-port tally keeps both, and
  `transportPacketsIn`/`transportBytesIn` are what reconcile with the device totals.

test/interface-counters.test.js (29 checks): a ping is counted on every port it crosses, in both
directions, with bytes; a port with no traffic reads zero rather than "unknown"; a host nobody addressed
counts the broadcasts it received and no echo payload (checked from the frame log, not from a byte total);
the addressed host carried strictly more than the quiet one; a frame denied by an ACL still counts as
received, while no echo reply leaves; the two accountings reconcile; counters accumulate across runs; and
without a simulation the command says so. Reverting the engine changes fails the suite.

test/flow.test.js is unchanged and still asserts exact transport totals - that is what the split is for.

Suite: 139 suites, 5,993 assertions, 0 failed.
jaylouisw scheduled this pull request to auto merge when all checks succeed 2026-11-09 18:59:58 +00:00
Sign in to join this conversation.
No reviewers
No milestone
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.

Dependencies

No dependencies set.

Reference
jaylouisw/packetforge!1252
No description provided.