show interfaces now says what the port threw away, and why (#1257) #1258

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

show interfaces now says what the port threw away, and why

Fixes #1257.

Gi0 (ethernet, 1G), MAC 02:00:00:00:00:00
  status: down (peer shut down), protocol: down
  ip: 10.0.0.1/24
  peer: pc/eth0
  0 packets input, 0 bytes
  3 packets output, 152 bytes
  2 drops (no ARP reply from 10.0.0.9 x2)

Three silences, not one

The command reported what crossed a port and nothing about what was discarded there, so two datagrams dropped
for want of a route read exactly like a port nothing had ever touched. Underneath that:

  1. No per-port discard counters. 25 sites emit drop with a reason; every reason was thrown away with
    the event log.
  2. An ACL deny emitted no drop event at all — it emits acl-deny, a different type, counted by
    nothing. The commonest discard of all left the port looking completely idle:
    access-list 101 deny icmp any any + ip access-group 101 in + two denied pings = 0 of everything.
  3. An unanswered ARP produced nothing. The packet sat in dev.pending forever: no event, no counter, and
    ping reported success: false, reason: null. Ping an address whose port is shut and the simulator said,
    in effect, "no".

Now

  • flowLib.countDrop() tallies the device and — when the event named one — the port; dropsFor() reads it;
  • counting happens in _emit(), the funnel every discard already passes through, so a discard site added
    later is counted by construction rather than by whoever remembers;
  • _discardReason() is one table of which events mean "this frame was discarded": drop, acl-deny,
    vlan-drop, nat-drop, and anything carrying discard: true. stp-block is deliberately not in the
    table
    — the same type also fires once per blocked candidate port while a frame is flooding, and counting
    each of those would report one lost frame three times — so the frame-level ingress site opts in explicitly;
  • _sweepPending() runs when the queue empties and reports every packet whose next hop never answered as
    no ARP reply from <ip>, on the port that asked;
  • ping reports that same sentence as the reply's reason instead of null (converging still wins);
  • show interfaces prints N drops (reason xN, …) — reasons longest-first, overflow counted rather than
    silently cut, and nothing at all on a clean port — plus discards that never named a port once at the end
    as device-wide …, rather than inventing a port for them.

Evidence

test/interface-drops.test.js — 38 checks:

  • a clean port prints no drops line; a device with no run still says counters: not measured;
  • an ACL deny is counted with the ACL and its direction, charged to the ingress port and to no other;
  • a no-route drop is device-wide, charged to no port, and named once;
  • an unanswered ARP is a counted discard on the port that asked, clears the pending queue, and gives the
    failed ping its reason;
  • the tally and the event log cannot disagree: every discard event has a tally entry, and the reasons
    match one for one;
  • the STP tallies never exceed the events that caused them, and a per-candidate skip is not counted as a
    dropped frame;
  • interface drop accounting does not move the flow accounting (the split #1252 established still holds);
  • _dropSummary() reads identically for identical input.

Reverting engine/cli.js fails 5 of the 38; reverting engine/flow.js or engine/simulator.js fails the
suite outright (the API it measures is gone).

docs/CLI.md gains a "What the port threw away" subsection.

Suite: 142 suites, 6,080 assertions, 0 failed.

`show interfaces` now says what the port threw away, and why Fixes #1257. ``` Gi0 (ethernet, 1G), MAC 02:00:00:00:00:00 status: down (peer shut down), protocol: down ip: 10.0.0.1/24 peer: pc/eth0 0 packets input, 0 bytes 3 packets output, 152 bytes 2 drops (no ARP reply from 10.0.0.9 x2) ``` ## Three silences, not one The command reported what crossed a port and nothing about what was discarded there, so two datagrams dropped for want of a route read exactly like a port nothing had ever touched. Underneath that: 1. **No per-port discard counters.** 25 sites emit `drop` with a reason; every reason was thrown away with the event log. 2. **An ACL deny emitted no `drop` event at all** — it emits `acl-deny`, a different type, counted by nothing. The commonest discard of all left the port looking completely idle: `access-list 101 deny icmp any any` + `ip access-group 101 in` + two denied pings = `0` of everything. 3. **An unanswered ARP produced nothing.** The packet sat in `dev.pending` forever: no event, no counter, and `ping` reported `success: false, reason: null`. Ping an address whose port is shut and the simulator said, in effect, "no". ## Now * `flowLib.countDrop()` tallies the device and — when the event named one — the port; `dropsFor()` reads it; * counting happens in **`_emit()`**, the funnel every discard already passes through, so a discard site added later is counted by construction rather than by whoever remembers; * `_discardReason()` is one table of which events mean "this frame was discarded": `drop`, `acl-deny`, `vlan-drop`, `nat-drop`, and anything carrying `discard: true`. **`stp-block` is deliberately not in the table** — the same type also fires once per blocked candidate port while a frame is flooding, and counting each of those would report one lost frame three times — so the frame-level ingress site opts in explicitly; * `_sweepPending()` runs when the queue empties and reports every packet whose next hop never answered as `no ARP reply from <ip>`, on the port that asked; * `ping` reports that same sentence as the reply's reason instead of `null` (`converging` still wins); * `show interfaces` prints `N drops (reason xN, …)` — reasons longest-first, overflow counted rather than silently cut, and **nothing at all** on a clean port — plus discards that never named a port once at the end as `device-wide …`, rather than inventing a port for them. ## Evidence `test/interface-drops.test.js` — 38 checks: * a clean port prints no drops line; a device with no run still says `counters: not measured`; * an ACL deny is counted with **the ACL and its direction**, charged to the ingress port and to no other; * a no-route drop is device-wide, charged to no port, and named once; * an unanswered ARP is a counted discard on the port that asked, clears the pending queue, and gives the failed ping its reason; * the tally and the event log **cannot disagree**: every discard event has a tally entry, and the reasons match one for one; * the STP tallies never exceed the events that caused them, and a per-candidate skip is not counted as a dropped frame; * interface drop accounting does not move the flow accounting (the split #1252 established still holds); * `_dropSummary()` reads identically for identical input. Reverting `engine/cli.js` fails 5 of the 38; reverting `engine/flow.js` or `engine/simulator.js` fails the suite outright (the API it measures is gone). `docs/CLI.md` gains a "What the port threw away" subsection. Suite: 142 suites, 6,080 assertions, 0 failed.
show interfaces now says what the port threw away, and why (#1257)
Some checks failed
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 18) (pull_request) Failing after 1m52s
CI / Test (Node 20) (pull_request) Successful in 1m48s
CI / Server smoke test (pull_request) Successful in 33s
CI / Docker build (pull_request) Successful in 42s
CI / Test (Node 22) (pull_request) Successful in 1m43s
1646afc114
The block reported what crossed a port and nothing about what was discarded there, so two datagrams dropped
for want of a route read exactly like a port nothing had touched. Three silences underneath:

1. 25 sites emitted `drop` with a reason and nothing tallied them per port.
2. An ACL deny emitted `acl-deny`, a different type, counted by nothing - so the commonest discard of all
   left the port looking idle.
3. A packet waiting on an ARP reply that never came sat in `dev.pending` forever: no event, no counter, and
   `ping` reported `reason: null`.

Now:
* `flowLib.countDrop()` tallies the device and, when the event named one, the port; `dropsFor()` reads it.
* counting happens in `_emit()`, the one funnel every discard passes through, so a discard site added later
  is counted by construction rather than by whoever remembers.
* `_discardReason()` is a single table of which events mean "this frame was discarded": `drop`, `acl-deny`,
  `vlan-drop`, `nat-drop`, and anything carrying `discard: true`. `stp-block` is NOT in the table - it also
  fires once per blocked candidate port during a flood, and counting each would report one lost frame three
  times - so the frame-level ingress site opts in explicitly.
* `_sweepPending()` runs when the queue empties and reports every packet whose next hop never answered as
  `no ARP reply from <ip>`, on the port that asked.
* `ping` reports that same sentence as the reply's reason instead of `null`; `converging` still wins.
* `show interfaces` prints `N drops (reason xN, ...)` - reasons longest-first, overflow counted, nothing at
  all on a clean port - and reports discards that never named a port once at the end as `device-wide …`.

test/interface-drops.test.js (38 checks): a clean port prints no drops line and a device with no run still
says "not measured"; an ACL deny is counted with the ACL and direction and charged to the ingress port only;
a no-route drop is device-wide and charged to no port; an unanswered ARP is a counted discard that lands on
the port that asked, clears the pending queue, and gives the failed ping its reason; the two-table agreement
holds (every discard event has a tally entry and the reasons match one for one); the STP tallies never
exceed the events that caused them and a per-candidate skip is not counted; interface drop accounting does
not move the flow accounting; and `_dropSummary()` reads the same for the same input.

Suite: 142 suites, 6,080 assertions, 0 failed.
jaylouisw scheduled this pull request to auto merge when all checks succeed 2026-11-09 19:30:30 +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!1258
No description provided.