🧐 example of automating VLAN creation/removal/inspecting using $mkvlan & friends...

Some points of clarifications:



$lsbridge is just a large function. While it lives in /system/script, run the script will ONLY load the function in the CLI to be used. So ā€œ/system/script/runā€ does nothing directly - except if that ā€œrunā€ gets an error message… that means there is a bug in the script and it does not compile.



7.18 (or eventually newer). So even 7.17.2 will not work. In last few V7 release there have been some tiny, potentially esoteric, additions to :convert and :serialize/:deserialize that actually reduce the amount of code needed to do these things.


The generated ā€œtable viewā€ depends on this, since, essentially, :put ā€œone\ttwo\t\threeā€ will automatically align on 8 char tabs. So $lsbridge uses :serialize to add ā€œ\tā€ to RouterOS array lists, as what other languages might call .join(ā€œ\tā€).

And as you see here, already bug reports on 7.18…



You need a $ before lsbridge, so:

$lsbridge

As explained above, it a function, which is also a :global variable. So /script/script stores the ā€œcodeā€, but cannot show UI. And in compliance with GOST-RSC-23, there is a ā€œhelpā€ subcommand, that explains in terse-terms:

[amm0@forum] > $lsbridge help
$lsbridge [ports|vlans] [show-ids] [as-value] [trim=yes*|no] [color=yes*|no]

The ā€œas-valueā€ allows ā€œdumpingā€ located information to a RouterOS array (i.e. the kinds of array that make @Dru’s head hurt)… So VERY theoretically use it’s calculations in further scripts by consulting the returned array - but it’s structure is designed to deal with UI presentation needs (see spaces in flags elements like " X")


And thanks all for testing! I do want to add some interactive controls to it one day, like my see my $PIANO script or $ROKU. But kinda wanted to know it generally worked before messing with it more…

Also if anyone had feedback on the information displayed, be open to suggestions. Also, I know some of the code needs cleanup, since it duplicative in a few areas - but [partially/opinionatedly] unwinding the bridge mysteries, in RouterOS script, is not so easy. There is subtle things that it shows, like the ā€œrunningā€ status for BOTH the /interface/bridge/port and /interface/vlan as IP- and MAC- & and also why it’s 48K worth of script (*actually, the colors add the most code).

FWIW, I tested this on pretty stock KNOT this AM with one VLAN, and the above steps did work:
7.18 on KNOT one-vlan defconf with $lsbridge .png
Now I’ve only tested on hEX-S, RB1100AHx4, RB5009, and KNOT at this point. So it’s totally possible the code does not correctly deal with all bridge configurations. And a vlan-filtering=yes bridge is required - but should prompt if there isn’t one…