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,50 @@
|
||||
// Test fixtures, ported from the private helpers of
|
||||
// filius-ipad ios/FiliusPadTests/TopologyNetworkRuntimeEngineTests.swift.
|
||||
|
||||
import {
|
||||
deviceConfiguration,
|
||||
NetworkRuntimeEngine,
|
||||
portSnapshot,
|
||||
topologySnapshot,
|
||||
type DeviceConfiguration,
|
||||
type Id,
|
||||
type LinkSnapshot,
|
||||
type NodeSnapshot,
|
||||
type TopologySnapshotInput,
|
||||
} from '../src/index.js';
|
||||
|
||||
let linkCounter = 0;
|
||||
|
||||
/** Swift uses a fresh `UUID()` per link; a counter keeps runs reproducible. */
|
||||
export function link(sourceNodeId: Id, sourcePortId: Id, targetNodeId: Id, targetPortId: Id): LinkSnapshot {
|
||||
linkCounter += 1;
|
||||
return {
|
||||
id: `ffffffff-0000-0000-0000-${linkCounter.toString(16).padStart(12, '0')}`,
|
||||
sourceNodeId,
|
||||
sourcePortId,
|
||||
targetNodeId,
|
||||
targetPortId,
|
||||
};
|
||||
}
|
||||
|
||||
export function pc(nodeId: Id, portId: Id): NodeSnapshot {
|
||||
return { id: nodeId, kind: 'pc', ports: [portSnapshot(portId, 'eth0')] };
|
||||
}
|
||||
|
||||
export function device(ipAddress: string, options: { mask?: string; gateway?: string } = {}): DeviceConfiguration {
|
||||
return deviceConfiguration(ipAddress, options.mask ?? '255.255.255.0', options.gateway ?? '');
|
||||
}
|
||||
|
||||
export function startedEngine(
|
||||
input: TopologySnapshotInput,
|
||||
seed: number = 14,
|
||||
): NetworkRuntimeEngine {
|
||||
const engine = new NetworkRuntimeEngine(seed);
|
||||
engine.handle({ type: 'start', snapshot: topologySnapshot(input), seed, initialTimeMilliseconds: 0 });
|
||||
return engine;
|
||||
}
|
||||
|
||||
/** `00000000-0000-0000-0000-` followed by twelve hex digits. */
|
||||
export function uuid(suffix: number): Id {
|
||||
return `00000000-0000-0000-0000-${suffix.toString(16).toUpperCase().padStart(12, '0')}`;
|
||||
}
|
||||
Reference in New Issue
Block a user