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,33 @@
|
||||
// Ported from filius-ipad (GPLv2/GPLv3):
|
||||
// State/TopologyNetworkRuntimeEngine.swift (TopologyNetworkRuntimeSpeed)
|
||||
// Java counterpart: filius.hardware.Verbindung (MIN_VERZOEGERUNG_IN_MILLIS,
|
||||
// verzoegerungsFaktor) and GUIMainMenu.updateLatency.
|
||||
|
||||
export const MINIMUM_SPEED_PERCENT = 1;
|
||||
export const MAXIMUM_SPEED_PERCENT = 100;
|
||||
export const DEFAULT_SPEED_PERCENT = 90;
|
||||
export const JAVA_MINIMUM_LINK_DELAY_MILLISECONDS = 5;
|
||||
|
||||
export class RuntimeSpeed {
|
||||
readonly percent: number;
|
||||
|
||||
constructor(percent: number = DEFAULT_SPEED_PERCENT) {
|
||||
this.percent = Math.min(MAXIMUM_SPEED_PERCENT, Math.max(MINIMUM_SPEED_PERCENT, Math.trunc(percent)));
|
||||
}
|
||||
|
||||
/** Java's delay factor: 1 at full speed, 100 at the slowest. */
|
||||
get javaDelayFactor(): number {
|
||||
return MAXIMUM_SPEED_PERCENT - this.percent + 1;
|
||||
}
|
||||
|
||||
/** How long a frame travels over one cable. */
|
||||
get linkTransmissionDelayMilliseconds(): number {
|
||||
return JAVA_MINIMUM_LINK_DELAY_MILLISECONDS * this.javaDelayFactor;
|
||||
}
|
||||
|
||||
/** A base delay scaled like a cable, or undefined past the safe integer range. */
|
||||
scaledLinkDelay(baseMilliseconds: number): number | undefined {
|
||||
const delay = baseMilliseconds * this.javaDelayFactor;
|
||||
return Number.isSafeInteger(delay) ? delay : undefined;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user