test: F2 acceptance — five of FILIUS' examples run as Java FILIUS runs them
ExampleRun opens an example as FILIUS opens it (SzenarioVerwaltung.laden into the window's lists), starts it as the action mode does, plays a story and writes every card's frames and tables, the calls, the addresses and the RIP tables' changes. examplesJava.test.ts reads the same file with this package's reader and runs it in the core (projectSnapshot, new): routing (internetwork_komplett), DHCP (einfaches_rechnernetz_komplett), DNS (dns_server), NAT (nat_with_mapped_port) and firewall (Internet_Komplett_..._DE) match card by card. Found and fixed: a host's ipForwardingEnabled, which Java saves and obeys, was unknown to the reader, the model, the core, the writer, the export and FlsOracle; and Java's ARP learns only from a request for its own address or a reply. Named Java bugs: a ping without a gateway throws a NullPointerException; a home router drops the answer of a second remote end. Open: Java picks between equally long RIP routes by thread timing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,165 @@
|
||||
// Runs one of FILIUS' own example files (corpus/java-examples) in Java FILIUS,
|
||||
// loaded and started as FILIUS opens and starts it (ScenarioNetwork.fromFile),
|
||||
// plays a story on it and records every frame each card saw, the capture's
|
||||
// tables, the story's calls and each host's addresses at the end.
|
||||
//
|
||||
// ExampleRun <file.fls> <story> <milliseconds> <out.json>
|
||||
//
|
||||
// The stories:
|
||||
// routing internetwork_komplett: Notebook 1.10 pings Webserver 5.10 across
|
||||
// three routers; then Notebook 1.11, which has no gateway
|
||||
// dhcp einfaches_rechnernetz_komplett: four notebooks get addresses
|
||||
// from the server
|
||||
// dns dns_server: the notebook asks its DNS server (recursive) for
|
||||
// www.filius.de, then for the mail server of filius.de
|
||||
// nat nat_with_mapped_port: Notebook 1.10 (behind Heimrouter Paul)
|
||||
// pings Webserver www.jupiter.de, then Heimrouter Vincent's WAN
|
||||
// address
|
||||
// firewall Internet_Komplett_…_DE: when the DHCP clients have their
|
||||
// addresses (8 s), iPad 1 (its network dropped by the firewall,
|
||||
// which leaves ICMP to its own switch) pings mail.gmx.de, then
|
||||
// the first Notebook (accepted), then mail.gmx.de pings the
|
||||
// firewall's WAN address. Targets with one shortest RIP path
|
||||
// each: where two are equal, Java takes whichever its threads
|
||||
// learn first
|
||||
|
||||
import filius.hardware.knoten.Knoten;
|
||||
import filius.software.dns.Resolver;
|
||||
import filius.software.rip.RIPRoute;
|
||||
import filius.software.rip.RIPTable;
|
||||
import filius.software.system.VermittlungsrechnerBetriebssystem;
|
||||
import filius.software.system.InternetKnotenBetriebssystem;
|
||||
import filius.software.vermittlungsschicht.IcmpPaket;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ExampleRun {
|
||||
static ScenarioNetwork network;
|
||||
static final List<Object[]> events = new ArrayList<>();
|
||||
/** Every change of a RIP router's table: time, router, table. */
|
||||
static final List<Object[]> ripChanges = new ArrayList<>();
|
||||
static final Map<String, String> lastTables = new java.util.HashMap<>();
|
||||
|
||||
/** A RIP router's table as one line: `network/mask gateway interface hops; …`, in its order. */
|
||||
static String tableText(RIPTable table) {
|
||||
StringBuilder text = new StringBuilder();
|
||||
synchronized (table) {
|
||||
for (RIPRoute route : table.routes) {
|
||||
if (text.length() > 0) text.append("; ");
|
||||
text.append(route.getNetAddress()).append('/').append(route.getNetMask()).append(' ').append(route.getGateway())
|
||||
.append(' ').append(route.getInterfaceIpAddress()).append(' ').append(route.hops);
|
||||
}
|
||||
}
|
||||
return text.toString();
|
||||
}
|
||||
|
||||
static synchronized void pollTables() {
|
||||
for (Map.Entry<String, Knoten> entry : network.nodes.entrySet()) {
|
||||
if (!(entry.getValue().getSystemSoftware() instanceof VermittlungsrechnerBetriebssystem)) continue;
|
||||
RIPTable table = ((VermittlungsrechnerBetriebssystem) entry.getValue().getSystemSoftware()).getRIPTable();
|
||||
if (table == null) continue;
|
||||
String text = tableText(table);
|
||||
if (!text.equals(lastTables.get(entry.getKey()))) {
|
||||
lastTables.put(entry.getKey(), text);
|
||||
ripChanges.add(new Object[] { System.currentTimeMillis() - network.start, entry.getKey(), text });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static synchronized void event(String what) {
|
||||
events.add(new Object[] { System.currentTimeMillis() - network.start, what });
|
||||
}
|
||||
|
||||
interface Call {
|
||||
String run() throws Exception;
|
||||
}
|
||||
|
||||
static void call(String label, Call call) {
|
||||
event(label + " called");
|
||||
try {
|
||||
event(label + " returned " + call.run());
|
||||
} catch (Exception e) {
|
||||
event(label + " failed " + e.getClass().getSimpleName());
|
||||
}
|
||||
}
|
||||
|
||||
static String icmp(IcmpPaket packet) {
|
||||
return packet == null ? "null" : "ICMP " + packet.getIcmpType() + "/" + packet.getIcmpCode() + " from " + packet.getSender();
|
||||
}
|
||||
|
||||
static void ping(String node, String target, int sequence) {
|
||||
call("sendProbe " + target, () -> icmp(network.system(node).holeICMP().sendProbe(target, 64, 1, sequence)));
|
||||
}
|
||||
|
||||
static Resolver resolver(String node) {
|
||||
return network.system(node).holeDNSClient();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
network = ScenarioNetwork.fromFile(args[0]);
|
||||
String story = args[1];
|
||||
long end = Long.parseLong(args[2]);
|
||||
network.start();
|
||||
Thread poller = new Thread(() -> {
|
||||
while (true) {
|
||||
pollTables();
|
||||
try {
|
||||
Thread.sleep(2);
|
||||
} catch (InterruptedException e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
poller.setDaemon(true);
|
||||
poller.start();
|
||||
Thread.sleep(500);
|
||||
switch (story) {
|
||||
case "routing":
|
||||
ping("Notebook 1.10", "141.99.5.10", 1);
|
||||
ping("Notebook 1.11", "141.99.5.10", 2);
|
||||
break;
|
||||
case "dhcp":
|
||||
break;
|
||||
case "dns":
|
||||
call("holeIPAdresse www.filius.de", () -> resolver("Notebook").holeIPAdresse("www.filius.de"));
|
||||
call("holeIPAdresseMailServer filius.de", () -> resolver("Notebook").holeIPAdresseMailServer("filius.de"));
|
||||
break;
|
||||
case "nat":
|
||||
ping("Notebook 1.10", "141.99.4.10", 1);
|
||||
ping("Notebook 1.10", "141.99.5.10", 2);
|
||||
break;
|
||||
case "firewall":
|
||||
Thread.sleep(7500);
|
||||
ping("iPad 1", "130.100.200.25", 1);
|
||||
ping("Notebook", "130.100.200.25", 2);
|
||||
ping("mail.gmx.de (130.100.200.25)", "42.0.0.10", 3);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("unknown story " + story);
|
||||
}
|
||||
long rest = network.start + end - System.currentTimeMillis();
|
||||
if (rest > 0) Thread.sleep(rest);
|
||||
|
||||
ScenarioNetwork.Json out = new ScenarioNetwork.Json();
|
||||
out.open('{');
|
||||
network.writeFrames(out);
|
||||
network.writeDevices(out);
|
||||
// Every change of each RIP router's table (polled every 2 ms), as RipRun writes them.
|
||||
synchronized (ExampleRun.class) {
|
||||
out.key("ripTables").open('[');
|
||||
for (Object[] each : ripChanges) out.open('[').number((Long) each[0]).string((String) each[1]).string((String) each[2]).close(']');
|
||||
out.close(']');
|
||||
}
|
||||
synchronized (ExampleRun.class) {
|
||||
out.key("events").open('[');
|
||||
for (Object[] each : events) out.open('[').number((Long) each[0]).string((String) each[1]).close(']');
|
||||
out.close(']');
|
||||
}
|
||||
out.close('}');
|
||||
network.stop();
|
||||
ScenarioNetwork.write(args[3], out);
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
@@ -292,6 +292,7 @@ public class FlsOracle {
|
||||
json.put("fileSystem", system.getDateisystem() == null ? null : fileTree(system.getDateisystem().getRoot()));
|
||||
if (system instanceof Betriebssystem) json.put("applications", applications(system));
|
||||
json.put("dhcpClient", system.isDHCPKonfiguration());
|
||||
json.put("ipForwardingEnabled", system.isIpForwardingEnabled());
|
||||
DHCPServer server = system.getDHCPServer();
|
||||
if (server != null) {
|
||||
Map<String, Object> dhcp = new LinkedHashMap<>();
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
// DhcpRun and TcpRun.
|
||||
|
||||
import filius.gui.GUIContainer;
|
||||
import filius.gui.netzwerksicht.GUIKnotenItem;
|
||||
import filius.rahmenprogramm.SzenarioVerwaltung;
|
||||
import filius.hardware.Kabel;
|
||||
import filius.hardware.NetzwerkInterface;
|
||||
import filius.hardware.Port;
|
||||
@@ -54,8 +56,40 @@ public class ScenarioNetwork {
|
||||
/** Each card's MAC address, under its node's id (the first card) or `id#index` (the others). */
|
||||
final Map<String, String> macByNode = new LinkedHashMap<>();
|
||||
final List<String> servers = new ArrayList<>();
|
||||
/** Loaded from a .fls file (fromFile): started as the action mode starts it, in the file's order. */
|
||||
boolean fromFile;
|
||||
/** fromFile: each card's MAC address and its node's name with the card's index, `name/index`. */
|
||||
final Map<String, String> cardByMac = new LinkedHashMap<>();
|
||||
long start;
|
||||
|
||||
/**
|
||||
* A .fls file loaded as FILIUS opens it (SzenarioVerwaltung.laden into the
|
||||
* window's lists): the nodes under their names (a repeated name gets
|
||||
* `#2`, `#3`, …), each card's frames under its MAC address.
|
||||
*/
|
||||
static ScenarioNetwork fromFile(String path) throws Exception {
|
||||
GUIContainer gui = GUIContainer.getGUIContainer();
|
||||
if (!SzenarioVerwaltung.getInstance().laden(path, gui.getKnotenItems(), gui.getCableItems(), gui.getDocuItems())) {
|
||||
throw new IllegalStateException("FILIUS could not load " + path);
|
||||
}
|
||||
ScenarioNetwork network = new ScenarioNetwork();
|
||||
network.fromFile = true;
|
||||
for (GUIKnotenItem item : gui.getKnotenItems()) {
|
||||
Knoten knoten = item.getKnoten();
|
||||
String name = knoten.getName();
|
||||
for (int count = 2; network.nodes.containsKey(name); count++) name = knoten.getName() + "#" + count;
|
||||
network.nodes.put(name, knoten);
|
||||
if (knoten instanceof InternetKnoten) {
|
||||
List<NetzwerkInterface> nics = ((InternetKnoten) knoten).getNetzwerkInterfaces();
|
||||
for (int index = 0; index < nics.size(); index++) {
|
||||
network.macByNode.put(nics.get(index).getMac(), nics.get(index).getMac());
|
||||
network.cardByMac.put(nics.get(index).getMac(), name + "/" + index);
|
||||
}
|
||||
}
|
||||
}
|
||||
return network;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static ScenarioNetwork read(String path) throws Exception {
|
||||
Map<String, Object> scenario = (Map<String, Object>) new JsonReader(
|
||||
@@ -204,6 +238,12 @@ public class ScenarioNetwork {
|
||||
|
||||
/** Starts the simulation; times in the log count from here. */
|
||||
void start() throws InterruptedException {
|
||||
if (fromFile) {
|
||||
// GUIMainMenu.selectMode(MODUS_AKTION): every node in the window's order.
|
||||
start = System.currentTimeMillis();
|
||||
for (GUIKnotenItem item : GUIContainer.getGUIContainer().getKnotenItems()) item.getKnoten().getSystemSoftware().starten();
|
||||
return;
|
||||
}
|
||||
// Switches and DHCP servers first: FILIUS' client waits for every active
|
||||
// server to have started (waitUntilDhcpServerStarted, through the GUI's
|
||||
// node list, which this tool has not got).
|
||||
@@ -244,6 +284,11 @@ public class ScenarioNetwork {
|
||||
out.close('}');
|
||||
writeRows(out, "rows", true);
|
||||
writeRows(out, "layeredRows", false);
|
||||
if (fromFile) {
|
||||
out.key("cards").open('{');
|
||||
for (Map.Entry<String, String> entry : cardByMac.entrySet()) out.key(entry.getKey()).string(entry.getValue());
|
||||
out.close('}');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user