Automatic Simple Queue based on IPv6 Neighbors

To control bandwith used by each client, I use simple queues.
For IPv4 clients, each queue is automatically created (upon lease bound), updated (upon IP address change), and removed (upon lease expiry) by /ip/dhcp-server lease-script.
For IPv6 clients, we don’t use DHCP, so I plan to periodically scan /ipv6/neighbor and create & remove queues based on its entries.

My proposed script is as follows, it should be run on a schedule:

# Clean up existing queues; this part is working fine
/queue simple
:foreach x in=[find comment~"IPv6 Client Queue"] do={
   :local queuename [get $x name];
   /queue simple remove $queuename;}

# Generate new queues, issues listed below
/ipv6 neighbor
:foreach y in=[find interface=bridge address!~"fe80:" status!="failed"] do={
   :local addr [get $y address];
   :local mac [get $y mac-address];
   :local host [/ip arp get [find where mac-address=$mac] host-name]
   :local queueName "Client - $mac";
   /queue simple add name=$queueName target=($addr."/128") queue=client/client limit-at=1M/1M max-limit=10M/10M priority=8/8 parent="Gateway IPv6" comment="IPv6 Client Queue - $host";}

Issue list:

  1. Apparently MikroTik doesn’t implement address!~“fe80:” (address that doesn’t start with fe80:).
    Is there another way to implement this? I confirmed that address~“fe80:” works (address that starts with fe80:).
    Issue solved on the next post.
  2. Apparently MikroTik doesn’t implement status!=“failed”.
    Is there another way to implement this? I confirmed that status=“failed” works.
    Issue solved on the next post.
  3. Even though WinBox displays host name in IP → ARP window, it is not provided on /ip/arp print. Therefore, /ip/arp get [find where mac-address=$mac] host-name fails.
    I confirmed that /ip/arp get [find where mac-address=$mac] interface works. Are there other ways to lookup host name from a MAC address?
    We can get host name from IPv4 DHCP leases using /ip/dhcp-server/lease get [find where active-mac-address=$mac] host-name. Therefore, this issue is also solved.

Thanks in advance.

Writing that “Apparently MikroTik doesn’t understand ” is quite arrogant.
It’s not up to RouterOS (MikroTik is the company) to figure out what you wanted to do and try to guess the commands you wanted executed.

  • Apparently you doesn’t understand script syntax.

This work correctly on both v6.48.7 and v7.13.5

 /ipv6 neighbor print where interface="bridge" and !(address~"^fe80:") and status!="failed"

This is totally bad style and wrong concept:

# Clean up existing queues; this part is working fine
/queue simple
:foreach x in=[find comment~"IPv6 Client Queue"] do={
   :local queuename [get $x name];
   /queue simple remove $queuename;}

Must be SIMPLY

/queue simple remove [find where comment~"IPv6 Client Queue"]

Perhaps what AI bots are outputting these days for answers??

You're correct. My understanding of ROS script syntax and English language is low, therefore the apparent arrogance. I have edited the first post to reduce my apparent arrogance.

Thank you. This successfully addresses issue #1 and #2.

Thank you. Apparently both code did the same thing. However, I assume your code is more CPU-efficient.


No, I write the script myself, no AI involved.

Can you post the final script you are using?

# Automatic Simple Queue based on IPv6 Neighbors
# Copyright (C)2024 MSaid
 
# Disable logging temporarily
/system logging disable [find topics~"info"];

# Clean up existing queues
/queue simple remove [find where name~"6Client - "];

# Generate new queues
:local counter 0;
/ipv6 neighbor
:foreach y in=[find interface="bridge" and address~"2001:2002:2003:2004:" and status!="failed" and status!="noarp"] do={
   :local addr [get $y address];
   :local mac [get $y mac-address];
   :set counter ($counter + 1);
   :do {/queue simple add name=("6Client - ".$mac." - ".$counter)  target=($addr."/128") queue=client/client limit-at=10M/10M max-limit=215M/215M burst-limit=216M/216M burst-threshold=45M/45M burst-time=120/120 priority=8/8 parent="Gateway6" comment=("v6 Client - ".[/ip dhcp-server lease get [find where active-mac-address=$mac] host-name]); } on-error={/queue simple add name=("6Client - ".$mac." - ".$counter)  target=($addr."/128") queue=client/client limit-at=10M/10M max-limit=215M/215M burst-limit=216M/216M burst-threshold=45M/45M burst-time=120/120 priority=8/8 parent="Gateway6"}
}

# Re-enable logging
/system logging enable [find topics~"info"];