Skip to content

Serial registration#1083

Merged
alfredh merged 19 commits intobaresip:masterfrom
cspiel1:serial_registration
Sep 29, 2020
Merged

Serial registration#1083
alfredh merged 19 commits intobaresip:masterfrom
cspiel1:serial_registration

Conversation

@cspiel1
Copy link
Collaborator

@cspiel1 cspiel1 commented Sep 9, 2020

Consider a setup with one or more main SIP proxies and one or more fallback proxies.

Serial registration mode

  • Accounts optionally have priorities (default prio=0). Accounts with prio 0 are registered at startup.
  • Prio 1 accounts are fallback accounts and are registered if all of the prio 0 accounts registrations fail.
  • Prio 2 accounts are fallback accounts second stage, and so on.
  • If a (re-)REGISTER fails, then serreg switches to the next priority UA.

Cisco mode

  • Additionally to the serial mode sends Cisco REGISTER keep-alives to not-registered UAs in order to poll their availability. This is only a name for a REGISTER with expires zero, thus a periodic un-REGISTER.
  • If a (re-)REGISTER with positive expires value fails, serreg switches to the next available UA.
  • If a UA with prio lower than the current becomes available again, serreg switches to the UA with the lower prio.

This PR is based on baresip/re#19.

@alfredh
Copy link
Collaborator

alfredh commented Sep 9, 2020

this one can be merged after 1.0.0 is released

@alfredh alfredh added this to the v1.0.1 milestone Sep 9, 2020
@cspiel1 cspiel1 force-pushed the serial_registration branch 2 times, most recently from 702d6a2 to fbc1891 Compare September 10, 2020 11:34
@cspiel1
Copy link
Collaborator Author

cspiel1 commented Sep 28, 2020

I did a lot of tests with up to 5 instances of routr SIP server running in docker.

  1. serial mode (fbregint was not set)
  • Switch to next proxy if all of current prio proxies go offline.
  • Switch from last prio proxy to prio=0 proxy.
  • Multiple proxies with same prio --> parallel registration
  • If a prio p is missing and there is prio p-1 and p+1, then if proxy with p-1 goes offline it switches to prio p+1.
  • None of the proxies registration is successful. --> prevent fast endless registration loop
  • Then switch to first available proxy.
  1. Cisco mode (fbregint was set)
  • Periodic REGISTER with expire=0 is done with configured fbregint.
  • Switch to next proxy if all of current prio proxies go offline. But this time it knows if the fallback is available.
  • If current prio is p and all prio p proxies go offline and all p+1 proxies are also offline but p+2 proxy is available, it switch to p+2 proxy. This switch is done immediately, without trying p+1 proxies.
  • If current prio is p and p-1 proxy becomes available again (this is detected by the periodic REGISTER with expire 0), it switches back to p-1 proxy.
  • Switching from maxprio to prio 0 works also.
  • Prevent fast endless loop REGISTER if none of the proxies is available. Then switch to first available proxy.

@alfredh alfredh removed this from the v1.0.1 milestone Sep 29, 2020
@alfredh
Copy link
Collaborator

alfredh commented Sep 29, 2020

should be possible to merge now ?

@cspiel1
Copy link
Collaborator Author

cspiel1 commented Sep 29, 2020

should be possible to merge now ?

Yes. I will make travis happy first. I recently found the handy tool "make ccheck". ;-)

A priority field is added to struct account. Default prio is 0.
The function reg_failed() has to use new libre function sipreg_failed() in
order to be compatible with Cisco REGISTER keep-alives. It returns true if a
REGISTER was not successful. It is not important if the REGISTER had the
expires field set positive or zero. For simplicity we use sipreg_registered()
now for reg_isok().
After a (re-)REGISTER fails the Cisco fallback REGISTER keep-alives are started
if an fbregint was configured. But the failc counter of the new sipreg instance
should be greater than zero in order to let sipreg_failed() return true. Then
when the first Cisco fallback REGISTER succeeds, failc is reset to zero and
sipreg_failed() returns false. Then the upper baresip layer knows that the SIP
proxy is available again.
This are periodic un-REGISTER requests (REGISTER with expires=0) in order to
test the availability of a SIP-proxy. When sometimes a re-REGISTER of a UA
fails, we are able to switch immediately to an available SIP proxy. The new
function ua_fallback() starts the periodic un-REGISTER requests.
When module account reads the configuration at startup of baresip only the
registrations for accounts with priority zero should be startet. For other
accounts with a positive fbregint the Cisco REGISTER keep-alives should be
started.
The user may specify a fbregint and prio parameters with command ua_new. If
both got positive values, the Cisco REGISTER keep-alives will be started for
this account.
The Cisco fallback REGISTER keep-alives are able to detect, if a SIP proxy
becomes available again. Then the upper layer may use this information to
switch to this SIP proxy if its priority is higher than the current. E.g. to
switch back from fallback SIP proxy to the main SIP proxy. This commit adds
UA_EVENT_FALLBACK_OK for this purpose and UA_EVENT_FALLBACK_FAIL for
completeness.
This is a more intelligent serial registration mode that uses also the response
information of the periodic un-REGISTER requests (Cisco REGISTER keep-alives)
to decide which UA would be a possible fallback.
Suppose SIP proxy "A" has prio = a and SIP proxy "B" has prio = b and a < b.

Further suppose that "A" is not available, so we are registered to "B". When
"A" becomes available, we want to switch to proxy "A". This means we start
the periodic (re-)REGISTER to "A" and the Cisco REGISTER keep-alives to "B".
@cspiel1 cspiel1 force-pushed the serial_registration branch from d3dea49 to 95fe482 Compare September 29, 2020 16:39
@alfredh alfredh merged commit dcbc411 into baresip:master Sep 29, 2020
@alfredh
Copy link
Collaborator

alfredh commented Sep 29, 2020

many thanks for your contributions :)

@cspiel1
Copy link
Collaborator Author

cspiel1 commented Sep 29, 2020

Many thanks for review and merge! :-)

@cspiel1 cspiel1 deleted the serial_registration branch September 30, 2020 06:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants