Community discussions

MikroTik App
 
msaid
just joined
Topic Author
Posts: 3
Joined: Sat Apr 08, 2023 10:14 pm

Automatic Simple Queue based on IPv6 Neighbors

Wed Feb 21, 2024 9:56 pm

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.
Last edited by msaid on Sat Feb 24, 2024 3:15 am, edited 2 times in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11995
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Automatic Simple Queue based on IPv6 Neighbors  [SOLVED]

Fri Feb 23, 2024 2:24 pm

Writing that "Apparently MikroTik doesn't understand <insert wrong syntax here>" 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"]
 
Mesquite
Member
Member
Posts: 420
Joined: Tue Jan 23, 2024 9:16 pm

Re: Automatic Simple Queue based on IPv6 Neighbors

Fri Feb 23, 2024 11:09 pm

Perhaps what AI bots are outputting these days for answers??
 
msaid
just joined
Topic Author
Posts: 3
Joined: Sat Apr 08, 2023 10:14 pm

Re: Automatic Simple Queue based on IPv6 Neighbors

Sat Feb 24, 2024 2:39 am

Writing that "Apparently MikroTik doesn't understand <insert wrong syntax here>" 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.
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.
This work correctly on both v6.48.7 and v7.13.5
 /ipv6 neighbor print where interface="bridge" and !(address~"^fe80:") and status!="failed"
Thank you. This successfully addresses issue #1 and #2.
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"]
Thank you. Apparently both code did the same thing. However, I assume your code is more CPU-efficient.

Perhaps what AI bots are outputting these days for answers??
No, I write the script myself, no AI involved.
 
gabrielpc1190
just joined
Posts: 3
Joined: Tue Nov 15, 2022 4:58 am

Re: Automatic Simple Queue based on IPv6 Neighbors

Sun Mar 10, 2024 9:40 am

Can you post the final script you are using?

Who is online

Users browsing this forum: sinisa and 12 guests