Community discussions

MikroTik App
 
florentleg
just joined
Topic Author
Posts: 9
Joined: Mon Oct 12, 2020 5:20 pm

LTE failover with L2TP, how to ?

Wed May 05, 2021 7:20 pm

Hello,
I recently bought the Mikrotik "Chateau", which is capable of LTE.

I would like to have such configuration profile :
DHCP-client on WAN_BRIDGE(ether1) + L2TP-client. If link fails : LTE interface goes up and L2TP reconnect through LTE


I have tried two different ways :
A) Using PPP profiles "On-up" and "On-down". But there I am facing an issue with this, whenever the link is down, it just repeats the "on-down script" causing LTE and L2TP to flap (looping over enabling LTE)
B) Using two different scripts.

The problem of my scripting is that it causes a service cut for sure.

The script below runs every 30 sec, checks if l2tp-out1 is running (LTE is disabled). If not, it enables LTE, disables WAN_BRIDGE (I found that it might be necessary to disable WAN_BRIDGE because of the default route causing the l2tp interface to be flapping) and then L2TP reconnects automatically through LTE.
:global l2tpout1disabled [ /interface get l2tp-out1 disabled ];
:global l2tpoutltestate [ /interface get l2tp-outlte running ];
:global ltedisabled [ /interface get lte1 disabled ];


:if ( $l2tpout1state = false ) do={
:log warning "l2tp-out1 is down"
:if ($ltedisabled = true) do={
:if ($l2tpoutltedisabled=true) do={
/interface set lte1 disabled=no
/interface set l2tp-outlte disabled=no
/interface set l2tp-out1 disabled=yes
/interface set WAN_BRIDGE disabled=yes
}
}
}
Second script : (running ever houry or so) : Disables LTE, enables WAN_BRIDGE back for DHCP client,
:global l2tpout1state [ /interface get l2tp-out1 running ];
:global l2tpout1disabled [ /interface get l2tp-out1 disabled ];
:global ltestate [ /interface get lte1 running ];
:global ltedisabled [ /interface get lte1 disabled ];
:global wandisabled [/interface get WAN_BRIDGE disabled];
:global wangateway [/ip dhcp-client get [find interface=WAN_BRIDGE] gateway]
:set wangateway [:pick $wangateway 0 [:find $wangateway "/" -1]]

/interface set lte1 disabled=yes
/interface set WAN_BRIDGE disabled=no
delay 30s;
:if ([/ping 8.8.8.8 interval=1 count=5]=0) do={
:log warning "wan_bridge still down"
/interface set WAN_BRIDGE disabled=yes
/interface set l2tp-out1 disabled=yes
/interface set lte1 disabled=no
} else {
:log warning "Ftth is back"
/interface set lte1 disabled=yes
/interface set WAN_BRIDGE disabled=no
/interface set l2tp-out1 disabled=no
}
I noticed that when LTE goes up because of a link down, the dhcp-client route is not being automatically removed (sometime causing l2tp interface to ignore and try to connect over dhcp-client, obviously failing.)

Is there another way of achieving what I am trying to do ? A more "stable" way of doing this ?
I am in 7.1beta5 version.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 4717
Joined: Tue Feb 25, 2014 12:49 pm
Location: Capalbio, Tuscany, Italy

Re: LTE failover with L2TP, how to ?

Wed May 05, 2021 7:25 pm

Copy-and-paste solution, remember to remove your script on events and scheduler,
it's for 6.47.9, but must work on 7,
more simply to all those scripts.

set dhcp client default route distance to 10
lte default route distance to 20
use netwatch to check 1.1.1.1, if stop responding, do release command to dhcp client

/ip dhcp-client set [find] default-route-distance=10
/interface lte apn set [find] default-route-distance=20
/tool netwatch add down-script="/ip dhcp-client release [find]" host=1.1.1.1 timeout=3s

when dhcp is released (automatically) all go over lte

when dhcp client is up again (automatically) all go again over dhcp client
 
florentleg
just joined
Topic Author
Posts: 9
Joined: Mon Oct 12, 2020 5:20 pm

Re: LTE failover with L2TP, how to ?

Thu May 06, 2021 11:25 am

/ip dhcp-client set [find] default-route-distance=10
/interface lte apn set [find] default-route-distance=20
/tool netwatch add down-script="/ip dhcp-client release [find]" host=1.1.1.1 timeout=3s
when dhcp is released (automatically) all go over lte

when dhcp client is up again (automatically) all go again over dhcp client
Works for switching from dhcp-client to LTE interface, but does not work for going backwards - continuous pinging shows activity still goes through LTE+L2TP instead of DHCP-Client+L2TP

Maybe it should be completed with a bit of scripting to add static routes to 8.8.8.8 through DHCP_client gateway, and if this works, deactivate LTE, and let L2TP reconnect through DHCP client, because here if I don't deactivate LTE interface, L2TP interface is still connected over LTE (And I want it to connect over DHCP client as soon as it is up)
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 4717
Joined: Tue Feb 25, 2014 12:49 pm
Location: Capalbio, Tuscany, Italy

Re: LTE failover with L2TP, how to ?

Thu May 06, 2021 12:03 pm

When service go up, the DHCP client got IP again and route are back, but still go trough lte?
 
florentleg
just joined
Topic Author
Posts: 9
Joined: Mon Oct 12, 2020 5:20 pm

Re: LTE failover with L2TP, how to ?

Thu May 06, 2021 12:23 pm

When service go up, the DHCP client got IP again and route are back, but still go trough lte?
Yes, the fact is that the DHCP client might be working 24/24 (So I always have an IP assigned to my WAN bridge) but the internet link might be down through this bridge
When service go up (I simulate it by plugging/unplugging the ethernet cable) the traffic still goes through LTE and I think it is because I need to make L2TP reconnect through dhcp client (it just remains stable on LTE instead)

Who is online

Users browsing this forum: No registered users and 12 guests