NAME
Langertha::Holmgang::Sim::IOS - The simulator of device type ios — a Cisco IOS switch CLI
VERSION
version 0.001
SYNOPSIS
my $sims = Langertha::Holmgang::Simulators->new;
my ( $out, $ok, $gap ) = $sims->run_command( $state, 'sw-core', 'show vlan brief' );
# directly, as in cai-platform:
my ( $output, $ok ) = Langertha::Holmgang::Sim::IOS->run( $state->{'sw-core'},
"configure terminal\ninterface Gi1/0/24\nswitchport trunk allowed vlan add 30\nend",
{ host => 'sw-core', state => $state } );
DESCRIPTION
Simulates the command line of a Catalyst switch (IOS XE) for the test suites (contract in Langertha::Holmgang::Role::Simulator). A call of run is a fresh SSH session in privileged mode (sw#); several lines (separated by newlines) run one after another as if pasted. Empty lines and lines starting with ! are skipped.
The common show and configuration commands are really executed on the state. What the simulator does not know, it answers like IOS:
sw-core(config-if)#switchport trunk alowed vlan 30
^
% Invalid input detected at '^' marker.
as well as % Incomplete command. and % Ambiguous command: "…". On an error only the failing line is echoed with its prompt; successful lines give only their output. A failing line changes nothing, the remaining lines go on (IOS does not abort a pasted configuration); $ok is then false. After reload, exit or logout in privileged mode the session is closed and further lines are dropped.
Commands and keywords may be abbreviated as in IOS (unique prefixes: sh run, conf t, int Gi1/0/24, sw tr al vl add 30), interface names too (Gi, Gig, GigabitEthernet, Fa, Te, Po/Port-channel, Vlan, also with a space: gi 1/0/24). The state always holds the full names.
State
sw-core:
type: ios
hostname: sw-core
vlans: { "1": { name: default }, "10": { name: BUERO }, "30": { name: GAST } }
interfaces:
GigabitEthernet1/0/24:
description: Uplink to the router
mode: trunk # trunk | access (missing = access; dynamic auto is not modelled)
trunk_allowed: [10, 20] # list of numbers or "all" (missing = all)
native_vlan: 1 # missing = 1
access_vlan: 1 # missing = 1
shutdown: false
status: connected # connected | notconnect | disabled (shutdown -> disabled)
link: notconnect # optional: status after "no shutdown" (missing = connected)
reloads: 0 # optional, counts "reload"
Only what really changes is written (a no shutdown on an open interface creates no key). A list in trunk_allowed that contains all VLANs 1–4094 becomes all.
Commands
Privileged mode (and with do … in every configuration mode):
show running-config [interface X]
show interfaces [X [switchport|trunk|status] | trunk | status]
show vlan [brief | id N]
show ip interface brief
show version
… | include RE | exclude RE | begin RE | section RE | count RE
configure terminal
terminal length N, terminal width N, enable, end (no effect)
write [memory], copy running-config startup-config ("Building configuration...", state unchanged)
reload (reloads + 1, session closed)
ping ADDRESS (always the normal case: !!!!!, 100 percent)
exit, logout
Configuration ((config)#):
interface X | interface range Gi1/0/1 - 4[, Gi1/0/8]
vlan N[,M-K] no vlan N
hostname NAME exit end
Interface ((config-if)#, (config-if-range)#):
description TEXT no description
switchport mode trunk|access no switchport mode
switchport access vlan N no switchport access vlan
switchport trunk native vlan N no switchport trunk native vlan
switchport trunk allowed vlan LIST (REPLACES the list)
switchport trunk allowed vlan add|remove|except LIST
switchport trunk allowed vlan all|none no switchport trunk allowed vlan
shutdown no shutdown
exit end
VLAN ((config-vlan)#): name NAME, no name, exit, end.
A global configuration command in a submode (e.g. interface Gi1/0/2 in config-if) leaves the submode as in IOS.
Limits
No startup configuration (write memory and reload do not change the running configuration), no VTP, no spanning tree (the sections of show interfaces trunk show the allowed and present VLANs), no IP addresses, no no switchport, no port security, no voice VLAN. ping shows only the normal case — cases with faults bring their own observations. show vlan without brief shows the short form. Long lists in show running-config are not wrapped.
Pure functions, deterministic, neutral.
run
my ( $output, $ok ) = Langertha::Holmgang::Sim::IOS->run( $dev, $command, $ctx );
Runs a session (one or more lines in $command) and changes $dev. $ok is true when every line succeeded.
device_type
ios.
run_command
my ( $output, $ok, $gap ) = $sim->run_command( $dev, $command, $ctx );
"run_command" in Langertha::Holmgang::Role::Simulator: runs the session through "run". There is no write_file: an IOS device has only its CLI.
parse_vlan_list
my $list = parse_vlan_list('10,20,30-32'); # [10,20,30,31,32] or undef
format_vlan_list
format_vlan_list( 10, 11, 12, 20 ); # "10-12,20"
Compresses like IOS: runs of three or more numbers become a range.
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.