NAME

Langertha::Holmgang::Sim::RouterOS - The simulator of device type routeros — a RouterOS (MikroTik) console

VERSION

version 0.001

SYNOPSIS

my $sims = Langertha::Holmgang::Simulators->new;
my ( $out, $ok, $gap ) = $sims->run_command( $state, 'r1', '/ip firewall filter print' );

# directly, as in cai-platform:

my $dev = {
    type     => 'routeros',
    identity => 'r1',
    menus    => {
        '/ip firewall filter' => [
            { chain => 'forward', action => 'accept', 'connection-state' => 'established,related', comment => 'LAN raus' },
            { chain => 'forward', action => 'drop', disabled => 'yes' },
        ],
        '/ip address' => [ { address => '192.168.88.1/24', interface => 'bridge', network => '192.168.88.0' } ],
    },
    settings => { '/ip dns' => { servers => '9.9.9.9', 'allow-remote-requests' => 'yes' } },
};

my ( $output, $ok ) = Langertha::Holmgang::Sim::RouterOS->run( $dev,
    "/ip firewall filter\nmove 1 0\nprint", { host => 'r1' } );

DESCRIPTION

Simulator of the RouterOS console for the test suites (contract in Langertha::Holmgang::Role::Simulator). A model types real RouterOS commands through run_command(host, command); the common read and change commands are really executed on the state. What the simulator cannot do, it answers like a real RouterOS (bad command name …, expected end of command (line 1 column N), no such item, input does not match any value of action, failure: …) — never with a hint at a solution. Column numbers are approximate. There is no file access (no write).

State of a device

r1:
  type: routeros
  identity: r1                       # optional, else the host name
  menus:                             # list menus: ordered entries, values as text
    /ip firewall filter:
      - { chain: forward, action: accept, connection-state: "established,related", comment: "LAN raus" }
      - { chain: forward, action: drop, disabled: "yes" }
    /ip address: [ { address: 192.168.88.1/24, interface: bridge, network: 192.168.88.0 } ]
    /ip route:   [ { dst-address: 0.0.0.0/0, gateway: 203.0.113.1, distance: "1" } ]
    /ip dhcp-server lease: [ { address: 192.168.88.20, mac-address: "AA:BB:CC:00:00:01", server: dhcp1, dynamic: "yes" } ]
  settings:                          # settings menus: a hash
    /ip dns: { servers: "9.9.9.9", allow-remote-requests: "yes" }
  reboots: 1                         # set only by the simulator (/system reboot)
  shutdown: "yes"                    # set only by the simulator (/system shutdown)

Flags are properties: disabled (X, missing = no), dynamic (D, neither changeable nor removable — except by lease remove), invalid (I), on interfaces running (R). A known menu missing from the state counts as empty; it is created on the first add. Menus in the state that the simulator does not know are kept as lists without checking their properties. disabled=no is written only when the key was already there.

Lists: /ip firewall filter|nat|mangle|raw|address-list, /ip address, /ip route, /ip pool, /ip dhcp-server, /ip dhcp-server network, /ip dhcp-server lease, /ip dhcp-client, /ip dns static, /ip arp, /interface (no add/remove), /interface ethernet (no add/remove), /interface pppoe-client|vlan|bridge|bridge port|list|list member|wireguard|wireguard peers. Settings: /ip dns, /system identity (writes identity). Read only: /system resource. Each menu has a list of allowed properties (also the order in print); action only from the menu's value list; required properties on add (firewall: chain).

Commands

Paths with or without /, also /ip/firewall/filter; unique abbreviations of menus and commands (/ip fi fi pr); a line with only a path changes the menu for the following lines, / is the root, .. one level up. Several commands separated by newline or ;; lines with # are comments. When a command aborts, the earlier ones stay executed and the later ones do not run; each single command changes either completely or not at all.

Lists

print (numbered from 0 in the current order, header Flags: …, comment as ;;; text, then k=v), print detail, print terse, print count-only, print where …; add k=v … [place-before=N], set N[,M] k=v !k k="", remove, disable, enable, comment N comment="x", move N [destination=]M (entry N moves in front of the entry that now has number M; without a destination to the end; only firewall, DNS static, bridge ports), find, make-static (leases), reset-counters (firewall), export. Numbers: 0, 0,2, [find …], for menus with name also the name. Numbers always count over the whole list (also after print where).

find and where

[find], [find k=v k2=v2], [find where k=v and k2!=v2 or k~"re"], [find dynamic=yes], [find !disabled], [/ip firewall nat find …]; not, !, and/&&, or/|| (no parentheses; and before or).

Settings

print ( servers: 9.9.9.9, keys right-aligned), set k=v, export.

export

export (also compact, verbose, terse, hide-sensitive) in every menu, for the subtree; at the root everything. Blocks like RouterOS: path line, then add … or set …, properties in alphabetical order, values with spaces in quotes; dynamic entries are left out; /interface is not exported. export file=x prints nothing (no files).

System and diagnostics

/system reboot increments reboots, /system shutdown sets shutdown: yes (after that the device no longer answers); both end the call. /system identity print|set, /system resource print (fixed values). quit ends the call.

ping ADDRESS [count=N] (default 3, at most 10) and traceroute ADDRESS are not really simulated but derived from the state: replies come when the address is one of the device's own, lies in a connected network from /ip address, or an active route from /ip route leads to it (table main, gateway in a connected network or an interface; longest prefix, then lowest distance); otherwise no route to host, for blackhole timeout. Names are resolved only through /ip dns static. The case's observations (observe) take precedence and never reach the simulator.

Limits

No scripting language (:put, :foreach, variables), no edit, no get, no internal IDs (*1), no dynamic routes from connected networks in /ip route print, no table view, no wrapping of long lines, no logs, no /tool sniffer.

run

my ( $output, $ok ) = Langertha::Holmgang::Sim::RouterOS->run( $dev, $command, { host => 'r1' } );

Runs the command lines in $command one after another on the device state $dev ($dev is changed). Every call starts at the root (a new session). $ok is false as soon as a command fails; the output then ends with the error message.

device_type

routeros.

run_command

my ( $output, $ok, $gap ) = $sim->run_command( $dev, $command, $ctx );

"run_command" in Langertha::Holmgang::Role::Simulator: runs the lines through "run". There is no write_file: a RouterOS device has only its console.

my @paths = Langertha::Holmgang::Sim::RouterOS::menus();

The known menus (sorted), for documentation and for checking cases.

SUPPORT

Issues

Please report bugs and feature requests at https://github.com/Getty/langertha-holmgang/issues.

IRC

Join #langertha on irc.perl.org or message Getty directly.

CONTRIBUTING

Contributions are welcome! Please fork the repository and submit a pull request.

AUTHOR

Torsten Raudssus <torsten@raudssus.de>

COPYRIGHT AND LICENSE

This software is copyright (c) 2026 by Torsten Raudssus <torsten@raudssus.de> https://raudssus.de/.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.