Community discussions

 
lukkes
Member Candidate
Member Candidate
Topic Author
Posts: 163
Joined: Mon Jun 16, 2008 2:12 am
Location: Venezuela
Contact:

Solved Script to recreate the load balance mangle rules

Wed Mar 17, 2010 2:38 pm

Hi,

I make a 10 wan load balance (dsl) with PCC, but i have a big problem, in my country sometimes we have a intermitent down of a various adls at same time, sometimes i have 4 or 5 wand down at same time, this is a big problem because the RouterOS send all the traffic of this 5 down wan for the default gateway saturating this link, i make a script that first count the number of active routes and then re-create the mangle rules changing the PCC parameter and inserting the new rules. maybe is more easy to resolve this issue (i wait opinions) but this is the way i think by now.

i dont know much about scripting, maybe there is best and easy way to do this, i'll wait advices.
:global activeroutesold;
:local activeroutes 0;
:local route;
:local tes;
:local divs 0;
:local less;
:local routingmarks;
:local arrayrouting;
:local routemark;


:log info "BEGIN***********************************************************"

:foreach route in=[/ip route find where comment~"^[a-z]*balanceo" active=yes] do={
   :set tes [ /ip route get $route routing-mark ];
   :set activeroutes ($activeroutes + 1)
   :set routingmarks ($routingmarks, $tes);
 }
:log info $activeroutes;
:log info $activeroutesold;
:if ($activeroutes != $activeroutesold) do={
   /ip firewall 
      mangle {
         :foreach a in=[find where comment~"^[a-z]*balance" ] do={
            remove $a }
   }
   :set arrayrouting [:toarray $routingmarks]
   :set divs $activeroutes;
   :set less $activeroutes;
   :for i from=0 to=($activeroutes-1) do={
      :set routemark [:pick $routingmarks $i]
      :set divs ($activeroutes - $less);
      :set less ($less - 1);
      :log info "$routemark";
      :log info "$activeroutes/$divs"
       /ip firewall mangle
      :log info "Setting filters";
      add action=mark-connection chain=prerouting comment="balance conn $routemark" \
          disabled=no dst-address-type=!local in-interface=local \
          new-connection-mark="$routemark" passthrough=yes per-connection-classifier=\
          "both-addresses:$activeroutes/$divs" place-before=3
    
      add action=mark-routing chain=prerouting comment="balance route $routemark" \
         connection-mark="$routemark" disabled=no in-interface=local new-routing-mark=\
         "$routemark" passthrough=no place-before=3

    }
} else={:log info "routes has no changed"};
:log info ("$activeroute active routes");
:set activeroutesold $activeroutes;
:log info "END********************************************************************"
Last edited by janisk on Wed Mar 31, 2010 9:11 am, edited 2 times in total.
Reason: make script part more obvious
 
User avatar
chapex
Member Candidate
Member Candidate
Posts: 137
Joined: Wed May 30, 2007 1:23 am

Re: Solved Script to recreate the load balance mangle rules

Wed Mar 17, 2010 5:14 pm

your info is very usefull!. Tnks.

regards
Ubnet datacenter: bandwith transport
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8275
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: Solved Script to recreate the load balance mangle rules

Thu Mar 18, 2010 12:25 am

maybe, Wiki page? =) for example, at http://wiki.mikrotik.com/wiki/Scripts#M ... the_fly.27
Russian-speaking forum: https://forum.mikrotik.by/. Welcome!

For every complex problem, there is a solution that is simple, neat, and wrong.

MikroTik. Your life. Your routing.
 
User avatar
maximan
Trainer
Trainer
Posts: 549
Joined: Sat May 29, 2004 12:10 am
Location: Rio Cuarto, Argentina
Contact:

Re: Solved Script to recreate the load balance mangle rules

Thu Apr 08, 2010 1:01 am

Hi
I try to use this script and appear
syntax error (line 49 column 14)
I try to looking for the bug but i can't. Can you check the sintaxis? (i try with v3 and v4)

Regards

M.
MKE Solutions > Professional Support IT (Spanish / English)
FastNetMon / FNM Manager: DDoS Detection Tools.
 
lukkes
Member Candidate
Member Candidate
Topic Author
Posts: 163
Joined: Mon Jun 16, 2008 2:12 am
Location: Venezuela
Contact:

Re: Solved Script to recreate the load balance mangle rules

Thu Apr 08, 2010 2:49 am

Hi
I try to use this script and appear
syntax error (line 49 column 14)
I try to looking for the bug but i can't. Can you check the sintaxis? (i try with v3 and v4)

Regards

M.
Hi max, this is working in my router i dont know whats the problem..

hola, max nos conocimos en el mum de argentina, el script que esta alli lo copie y pegue de la configuracion actual, aca te pegare el mismo pero con algunas modificaciones que he hecho sobre la marcha, pero como te digo esta trabajando en una rb493 con v4.5
:global activeroutesold;
:local activeroutes 0;
:local route;
:local tes;
:local divs 0;
:local less;
:local routingmarks;
:local arrayrouting;
:local routemark;


:log info "BEGIN************"
:foreach route in=[/ip route find where comment~"^[a-z]*balanceo" active=yes] do={
   :set tes [ /ip route get $route routing-mark ];
   :set activeroutes ($activeroutes + 1)
   :set routingmarks ($routingmarks, $tes);
 }
:if ($activeroutes != $activeroutesold) do={
   /ip firewall 
      mangle {
         :foreach a in=[find where comment~"^[a-z]*balance" ] do={
            remove $a }
   }
   :set arrayrouting [:toarray $routingmarks]
   :set divs $activeroutes;
   :set less $activeroutes;



   :log info "email enviado";
   :for i from=0 to=($activeroutes-1) do={
      :set routemark [:pick $routingmarks $i]
      :set divs ($activeroutes - $less);
      :set less ($less - 1);
      :log info "$routemark";
      :log info "$activeroutes/$divs"
       /ip firewall mangle
      :log info "Setting filters";
      add action=mark-connection chain=prerouting comment="balance conn $routemark" \
          disabled=no dst-address-type=!local in-interface=local \
          new-connection-mark="$routemark" passthrough=yes per-connection-classifier=\
          "both-addresses:$activeroutes/$divs" place-before=3
      add action=mark-routing chain=prerouting comment="balance route $routemark" \
         connection-mark="$routemark" disabled=no in-interface=local new-routing-mark=\
         "$routemark" passthrough=no place-before=3
    }
} else={:log info "rutas no han cambiado"};
:log info ("$activeroutes rutas activas");
:set activeroutesold $activeroutes;
:log info "END**************"
Thanks Janisk for edit the code part and show me that it's possible, jejeje
Last edited by lukkes on Thu Apr 08, 2010 2:54 am, edited 1 time in total.
If you found this post useful don't forget about the karma viewtopic.php?f=1&t=41148

Feed Your FAITH Then Your Doubts Will Starve To Death...!!!
 
kazanova
Member
Member
Posts: 407
Joined: Tue Sep 06, 2005 11:52 am

Re: Solved Script to recreate the load balance mangle rules

Thu Jul 08, 2010 10:45 pm

chapex
bro waht picture
are u too small or anttena so big nice one
انا انزلنا التوراه فيها هدى ونور يحكم بها النبيون الذين اسلموا للذين هادوا والربانيون والاحبار بما استحفظوا من كتاب الله وكانوا عليه شهداء فلا تخشوا الناس واخشون ولا تشتروا باياتي ثمنا قليلا ومن لم يحكم بما انزل الله فاولئك هم الكافرون
 
User avatar
maximan
Trainer
Trainer
Posts: 549
Joined: Sat May 29, 2004 12:10 am
Location: Rio Cuarto, Argentina
Contact:

Re: Solved Script to recreate the load balance mangle rules

Tue Jul 13, 2010 6:10 pm

chapex
bro waht picture
are u too small or anttena so big nice one
chapex is gordero

M.
MKE Solutions > Professional Support IT (Spanish / English)
FastNetMon / FNM Manager: DDoS Detection Tools.
 
User avatar
chapex
Member Candidate
Member Candidate
Posts: 137
Joined: Wed May 30, 2007 1:23 am

Re: Solved Script to recreate the load balance mangle rules

Tue Jul 13, 2010 6:17 pm

chapex
bro waht picture
are u too small or anttena so big nice one
say I'm too small :lol: is a joke, the antenna is about 2 m radius :o
chapex
bro waht picture
are u too small or anttena so big nice one
chapex is gordero

M.
long live the Fatterssssssssssss!!!! hahahah
Ubnet datacenter: bandwith transport
 
plisken
Forum Guru
Forum Guru
Posts: 2388
Joined: Sun May 15, 2011 12:24 am
Location: Belgium
Contact:

Re: Solved Script to recreate the load balance mangle rules

Sat Mar 16, 2019 1:06 pm

Load balancing and failover does not work properly.
Until 2019, load balancing and failover not worked properly.
High time to do something about it.
This would be a great asset for the Mikrotik routers
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8275
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: Solved Script to recreate the load balance mangle rules

Sat Mar 16, 2019 6:06 pm

What are you talking about?

Generally, load balancing and failover have always been working properly since the very beginning :)

Have your account been compromised?..
Russian-speaking forum: https://forum.mikrotik.by/. Welcome!

For every complex problem, there is a solution that is simple, neat, and wrong.

MikroTik. Your life. Your routing.
 
anav
Forum Guru
Forum Guru
Posts: 2832
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada

Re: Solved Script to recreate the load balance mangle rules

Mon Mar 18, 2019 2:05 pm

No Chupaka, he has been unable to get mangling and PCC working in another thread so he bitches about it like spam everywhere else. :-)
However, if you want to help out, I would ask that you join us at this thread as I have been unable to solve what should be straightforward........
viewtopic.php?f=2&t=145970

What I find interesting on this thread is that the configuration is designed to deal with not all the WANs being available and thus I see no need for a script??
In the mangled routes, we check gateway = ping. Thus if one is not available the load is distributed amongst the remaining mangled routes and so on?
What am I missing in the logic??

Caveat: I cannot script or MT config myself out of a paper bag.
I'd rather manage rats than software. Follow my advice at your own risk! (Sob & mkx forced me to write that!)
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8275
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: Solved Script to recreate the load balance mangle rules

Mon Mar 18, 2019 3:18 pm

However, if you want to help out, I would ask that you join us at this thread as I have been unable to solve what should be straightforward........
viewtopic.php?f=2&t=145970
Yeah, I saw that topic recently. The problem is, there are many questions and no answers, no technical/diagnostic info, etc... Just complaints :)
Russian-speaking forum: https://forum.mikrotik.by/. Welcome!

For every complex problem, there is a solution that is simple, neat, and wrong.

MikroTik. Your life. Your routing.
 
plisken
Forum Guru
Forum Guru
Posts: 2388
Joined: Sun May 15, 2011 12:24 am
Location: Belgium
Contact:

Re: Solved Script to recreate the load balance mangle rules

Mon Mar 18, 2019 11:28 pm

What are you talking about?

Generally, load balancing and failover have always been working properly since the very beginning :)

Have your account been compromised?..
Hello Chupaka,

I am talking about the tutorials that were made and in which year. Steve Discher's tutorial is not working.
Something must have changed in the Mikrotik routers.
In RouterOS 6.37 the load balancing and failover worked perfectly.
There is also a failover tutorial made in 2019 (PDF file) and this does not work either. This is what I mean.
If I send a supout.rif to Mikrotik they are very vague and give no concrete solution.

What do you mean with my account hacked.
My Mikrotik account or forum account?

Greatings

Who is online

Users browsing this forum: No registered users and 12 guests