feat(core): event queue, Ethernet, switch, ARP, IPv4, ICMP, routing and firewall
First slice of the TypeScript port of the filius-ipad runtime engine, with 29 tests ported from the Swift suite. Parts not ported yet throw NotPortedError instead of guessing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
// Ported from filius-ipad (GPLv2/GPLv3):
|
||||
// State/TopologyNetworkRuntimeEngine.swift (packet trace model)
|
||||
// Java counterpart: filius.rahmenprogramm.nachrichten.Lauscher — here every
|
||||
// step a frame or packet takes is one trace event; the packet viewer groups them.
|
||||
|
||||
import type { Id } from '../ids.js';
|
||||
|
||||
export type TraceDirection = 'inbound' | 'outbound' | 'local';
|
||||
|
||||
export type TraceLayer = 'application' | 'transport' | 'network' | 'dataLink' | 'physical';
|
||||
|
||||
export type TraceOperation =
|
||||
| 'created'
|
||||
| 'sent'
|
||||
| 'received'
|
||||
| 'forwarded'
|
||||
| 'accepted'
|
||||
| 'dropped'
|
||||
| 'rewritten'
|
||||
| 'retransmitted'
|
||||
| 'compatibilityAdapter';
|
||||
|
||||
export interface HeaderField {
|
||||
readonly name: string;
|
||||
readonly value: string;
|
||||
}
|
||||
|
||||
export interface TraceEvent {
|
||||
readonly id: number;
|
||||
readonly timeMilliseconds: number;
|
||||
readonly frameIdentity?: number;
|
||||
readonly packetIdentity?: number;
|
||||
readonly nodeId: Id;
|
||||
readonly interfaceId?: Id;
|
||||
readonly direction: TraceDirection;
|
||||
readonly layer: TraceLayer;
|
||||
readonly operation: TraceOperation;
|
||||
readonly beforeHeaders: readonly HeaderField[];
|
||||
readonly afterHeaders: readonly HeaderField[];
|
||||
readonly detail?: string;
|
||||
}
|
||||
|
||||
/** How many trace events the runtime keeps, and how many it drops at once when full. */
|
||||
export interface TraceRetentionPolicy {
|
||||
readonly maximumEventCount: number;
|
||||
readonly evictionBatchSize: number;
|
||||
}
|
||||
|
||||
export function traceRetentionPolicy(maximumEventCount: number, evictionBatchSize: number): TraceRetentionPolicy {
|
||||
if (!(maximumEventCount > 0)) throw new RangeError('Packet-trace retention must keep at least one event');
|
||||
if (!(evictionBatchSize > 0)) throw new RangeError('Packet-trace eviction must remove at least one event');
|
||||
if (evictionBatchSize > maximumEventCount) {
|
||||
throw new RangeError('Packet-trace eviction cannot exceed the retention limit');
|
||||
}
|
||||
return { maximumEventCount, evictionBatchSize };
|
||||
}
|
||||
|
||||
export const PRODUCTION_TRACE_RETENTION = traceRetentionPolicy(10_000, 1_000);
|
||||
Reference in New Issue
Block a user