Budgetphone and E_NOCLUE problems
budgetphone.nl is a dutch sip provider that delivers good technical support, low prices, multiple lines, business contracts and a lot more.
Sip seemed to be a straightforward configuration but as budgetphone was growing, also the way SIP invites were send changed, and things started crumbling down.
This was a typical E_NOCLUE problem. And I was the one with the lacking clue.
Update new server 2009-04-19
Budgetphone has upgraded to a new server with cool new features.
The server however does not need SRV lookups anymore. Furthermore: the (authorization) domain has been changed to sip1.budgetphone.nl .
It add cool features like typing in SIP uri's for call forwarding. (Maybe even iax uri's

)
To call or to be called
The biggest question. Maybe not.
Calling and being called are seperate things in asterisk. You can register whatever you want without having a peer configuration in your sip.conf, and still have
working incoming calls.
Who's calling, and who are you calling
The HA setup of budgetphone prevents us from correlating registration-info with incoming calls from budgetphone. So we must insert hacks to know who's calling (all be it not authoritative), and who they're calling. In the end, all incoming sip providers will go into the same incoming context.
Sip calling
For sip callouts, you only need the following information per phone number: What's your account (fromuser/fromdomain), what's the password (secret), what's the proxy (host), and what's the username the proxy thinks you have (to match the context with the password):
[bpaccount1]
type=friend
secret=#yourpassword#
username=#yourphonenumber#
fromuser=#yourphonenumber#
fromdomain=sip1.budgetphone.nl
host=sip1.budgetphone.nl
fromuser and fromdomain are used to "create" your sip account: that will be
@.
host is used as the proxy. Username is to match the 407 proxy authentication with this account. Else it does not know the password.
To use this in your dialplan, you simply type:
exten => s,n,Dial(SIP/${EXTEN}@bpaccount1)
This will make asterisk call using sip1.budgetphone.nl and with the accountname @. It goes something like this:
INVITE (no auth, account ) >>
407 Proxy Authentication Required (challenge) <<
ACK (407, no auth) >>
INVITE (Proxy-Auth, account) >>
100 Giving a try <<
180 Ringing <<
200 OK (rtp info) <<
Call me!
Getting calls from budgetphone is easy. Just tell them where you are on a regular basis. So how do we do that?
Well, we let asterisk tell them. The register commands are used to let asterisk continuosly send register's to budgetphone. It goes something like this:
REGISTER (no auth, account, your extension at asterisk) >>
403 UNAUTHORIZED (challenge) <<
REGISTER (response on challenge) >>
OK <<
From that moment on budgetphone will remember your registration for a period of time. If a call arrives for you, it will sent an invite from one of it's proxies to your extension at your asterisk server. Be aware that asterisk is unable to match the ip of the proxies to this registry.
A register in asterisk looks like this:
register => <accountname>:<password>@<combined domain and proxy>/<your extension at asterisk>
in other words:
register => 31xxxxxxxxx:<password>@sip1.budgetphone.nl/bpaccount1
When a call arrives at budgetphone, it will INVITE bpaccount1 in your asterisk server. The asterisk server looks up bpaccount1 in the dialplan, which will be in the default dialplan context for sip channels.
Using the <your extension at asterisk> you can easily differentiate multiple numbers at budgetphone.