lib/Kernel/mikrotik_switch.pm

SYNOPSIS

REST API client for the lab's Mikrotik RouterOS switch.

VLAN AND NETWORK CONVENTIONS

Per progress#188433: pick a VLAN id below 10, and any subnet within 192.168.0.0/16 - both are only locally significant to this switch, not coordinated with any wider address plan, since the switch's uplink to the managed network stays untagged/access-only (see that ticket for why).

VLANs on the lab switch:

VLAN 3 (DEFAULT_VLAN): the default VLAN of all other ports. Tests do not create or remove it, they only move ports back to it.
VLANs 4..9 (MIN_TEST_VLAN_ID..MAX_VLAN_ID): test VLANs.

add_vlan() and remove_vlan() die for any VLAN id other than a test VLAN, set_port_pvid() also accepts DEFAULT_VLAN.

get_all_vlans

get_all_vlans();

Fetches every entry of the bridge VLAN table (/interface/bridge/vlan), each containing 'bridge', 'vlan-ids', 'tagged' and 'untagged' member lists.

Dies on any non-2xx response.

get_vlan

get_vlan($vlan_id);

Fetches the bridge VLAN table entry for a given VLAN id, e.g. get_vlan(5). Dies if no entry with that VLAN id exists.

Dies on any non-2xx response.

add_vlan

add_vlan(bridge => 'bridge1', vlan_id => 5, untagged => 'ether5', tagged => 'ether1');

Adds a new entry to the bridge VLAN table. 'bridge' and 'vlan_id' are required. 'tagged' and 'untagged' are optional comma-separated interface lists (as accepted by RouterOS) naming the bridge member ports to attach to the VLAN. Returns the created entry.

Dies if vlan_id is not a test VLAN (see "VLAN AND NETWORK CONVENTIONS").

Dies if an entry already exists for that bridge/vlan_id - use update_vlan() (not yet implemented) to change an existing VLAN's port membership.

Dies on any non-2xx response.

remove_vlan

remove_vlan($vlan_id);

Removes the bridge VLAN table entry for a given VLAN id, e.g. remove_vlan(5). Dies if no entry with that VLAN id exists, or if vlan_id is not a test VLAN (see "VLAN AND NETWORK CONVENTIONS").

Dies on any non-2xx response.

get_port_pvid

get_port_pvid($port_name);

Fetches the PVID (untagged/native VLAN id) currently configured for a bridge port, e.g. get_port_pvid('ether5'). Dies if the port is not a member of any bridge.

Dies on any non-2xx response.

set_port_pvid

set_port_pvid($port_name, $vlan_id);

Sets the PVID (untagged/native VLAN id) of a bridge port, e.g. set_port_pvid('ether5', 5). This is what makes a port an untagged member of a VLAN. Dies if the port is not a member of any bridge, or if vlan_id is neither a test VLAN nor DEFAULT_VLAN (see "VLAN AND NETWORK CONVENTIONS").

Dies on any non-2xx response.

create_vlan_network

create_vlan_network(vlan_id => 4, ports => ['sfp-sfpplus9', 'sfp-sfpplus23']);

Creates an isolated network for one test: a new VLAN on bridge (default 'bridge') with the ports as untagged members, and the PVID of each port set to the VLAN. Dies if the VLAN already exists, so that a test does not take over the network of another test.

remove_vlan_network

remove_vlan_network(vlan_id => 4, ports => ['sfp-sfpplus9', 'sfp-sfpplus23'], pvid => 3);

Removes the network that create_vlan_network created: sets the PVID of the ports back to pvid and removes the VLAN. Does not die if the VLAN does not exist, so that it can also clean up after a failed test.

pvid defaults to DEFAULT_VLAN (3). VLAN 1 is not allowed: it is the VLAN of the uplink to the lab network, so a test NIC in VLAN 1 gets a lab address, and a second NIC of the SUT in the lab network can break the connection of openQA to the SUT.