Multiple peers from same servers are getting the same context

Hello,
I’m building a scenario that sometimes I’ll use PJSIP peers to act like a inbound call, so sasically it will be Server A and Server B, with Server A receiving external calls and redirecting them to Server B via pjsip dialing.

As Server A has multiple DID’s, I’ve created one PJSIP Endpoint for each DID, each with different credentials, and as I want them to have different proposes inside Server B, they have different contexts as well.

The problem is: no matter which endpoint make the call, and wich extension it dials, the call in Server B will always falls on the latest registered endpoint’s context, and not the endpoint’s context that receive the call (sometimes it is the correct endpoint, but only when this endpoint was registered by last).

Is there a way to receive the call in the correct context when the peers are connected in the same server?

It depends on how you have configured things. Are you doing IP based matching? If so, then one endpoint would be used. Are you doing user based matching? What is the configuration?

It’s user based matching, I’ve created as many DID’s I have in Server A as PJSIP Endpoints.

In server B, the peers look like this:

[1000-endpt]
type=endpoint
context=1000-inbound
disallow=all
allow=ulaw
transport=transport-udp
aors=1000-endpt
outbound_auth=1000-endpt
identify_by=auth_username

[1000-endpt]
type=auth
auth_type=userpass
password=1000password
username=1000

[1000-endpt]
type=aor
contact=sip:172.16.15.2:5322
qualify_frequency=15
qualify_timeout=3

[1000-endpt]
type=registration
outbound_auth=1000-endpt
server_uri=sip:172.16.15.2:5322
client_uri=sip:1000@172.16.15.2:5322
retry_interval=60
contact_user=1000

If you set from_user to the username you wish to match on the remote side, does it match properly?

Sorry for the delayed response, was testing all the possibilities hehe

So, I’ve tryied to set “from_user” in the endpoints in Server A and Server B. Also used the “registration” configuration of “contact_user” to the username, and it keeps calling the last’s loaded endpoint context for every call:

This is the Endpoint 1000:

[1000-endpt]
type=endpoint
context=1000-inbound
disallow=all
allow=ulaw
transport=transport-udp
aors=1000-endpt
outbound_auth=1000-endpt
from_user=1000

[1000-endpt]
type=auth
auth_type=userpass
password=100password
username=1000

[1000-endpt]
type=aor
contact=sip:172.16.15.2:5322
qualify_frequency=15
qualify_timeout=3

[1000-endpt]
type=registration
outbound_auth=1000-endpt
server_uri=sip:172.16.15.2:5322
client_uri=sip:1000@172.16.15.2:5322
retry_interval=60
contact_user=1000

[1000-endpt]
type=identify
endpoint=1000-endpt
match=172.16.15.2

And this is the endpoint 2000:

[2000-endpt]
type=endpoint
context=2000-inbound
disallow=all
allow=ulaw
transport=transport-udp
aors=2000-endpt
outbound_auth=2000-endpt
from_user=2000

[2000-endpt]
type=auth
auth_type=userpass
password=2000password
username=2000

[2000-endpt]
type=aor
contact=sip:172.16.15.2:5322
qualify_frequency=15
qualify_timeout=3

[2000-endpt]
type=registration
outbound_auth=2000-endpt
server_uri=sip:172.16.15.2:5322
client_uri=sip:2000@172.16.15.2:5322
retry_interval=60
contact_user=2000

[2000-endpt]
type=identify
endpoint=2000-endpt
match=172.16.15.2

And when in Server A I call the extension 1000, it does go to the context “1000-inbound”:

[Jul 28 10:39:35] -- Executing [1000@1000-inbound:1] NoOp("PJSIP/1000-endpt-00000002", "Call received in context 1000") in new stack

But when I call 2000, it also falls in the context “1000-inbound”:

[Jul 28 10:41:39] NOTICE[10268]: res_pjsip_session.c:3078 new_invite: Call from '1000-endpt' (UDP:172.16.15.2:5322) to extension '2000' rejected because extension not found in context '1000-inbound'.

You’ll need to provide SIP traces (pjsip set logger on) as well as the actual console output to show what is being dialed.

Server A’s console when Dialing to Server B:

[Jul 28 10:58:40]     -- Executing [2000@from-pstn:1] NoCDR("PJSIP/EBSMOD-0000199b", "") in new stack
[Jul 28 10:58:40]     -- Executing [2000@from-pstn:2] Dial("PJSIP/EBSMOD-0000199b", "PJSIP/2000,,tTo") in new stack
[Jul 28 10:58:40]     -- Called PJSIP/2000
[Jul 28 10:58:40]   == Everyone is busy/congested at this time (1:0/0/1)
[Jul 28 10:58:40]     -- Executing [2000@from-pstn:3] Hangup("PJSIP/EBSMOD-0000199b", "") in new stack
[Jul 28 10:58:40]   == Spawn extension (from-pstn, 2000, 3) exited non-zero on 'PJSIP/EBSMOD-0000199b'

Server B with “pjsip set logger on”:

[Jul 28 10:58:40] <--- Received SIP request (877 bytes) from UDP:172.16.15.2:5322 --->
[Jul 28 10:58:40] INVITE sip:2000@172.16.19.32:5322 SIP/2.0
[Jul 28 10:58:40] Via: SIP/2.0/UDP 172.16.15.2:5322;rport;branch=z9hG4bKPj2769f01f-1011-4bbd-83b7-a0877aa10819
[Jul 28 10:58:40] From: <sip:2000@172.16.15.2>;tag=096bb1dc-d8fb-404a-96f1-75315c18836e
[Jul 28 10:58:40] To: <sip:2000@172.16.19.32>
[Jul 28 10:58:40] Contact: <sip:2000@172.16.15.2:5322>
[Jul 28 10:58:40] Call-ID: 7fe73b79-6009-4166-b003-3ccff33844ed
[Jul 28 10:58:40] CSeq: 13171 INVITE
[Jul 28 10:58:40] Allow: OPTIONS, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, REGISTER, MESSAGE, REFER
[Jul 28 10:58:40] Supported: 100rel, timer, replaces, norefersub
[Jul 28 10:58:40] Session-Expires: 1800
[Jul 28 10:58:40] Min-SE: 90
[Jul 28 10:58:40] Max-Forwards: 70
[Jul 28 10:58:40] User-Agent: Asterisk PBX 13.29.1
[Jul 28 10:58:40] Content-Type: application/sdp
[Jul 28 10:58:40] Content-Length:   233
[Jul 28 10:58:40]
[Jul 28 10:58:40] v=0
[Jul 28 10:58:40] o=- 804051818 804051818 IN IP4 172.16.15.2
[Jul 28 10:58:40] s=Asterisk
[Jul 28 10:58:40] c=IN IP4 172.16.15.2
[Jul 28 10:58:40] t=0 0
[Jul 28 10:58:40] m=audio 18776 RTP/AVP 0 101
[Jul 28 10:58:40] a=rtpmap:0 PCMU/8000
[Jul 28 10:58:40] a=rtpmap:101 telephone-event/8000
[Jul 28 10:58:40] a=fmtp:101 0-16
[Jul 28 10:58:40] a=ptime:20
[Jul 28 10:58:40] a=maxptime:150
[Jul 28 10:58:40] a=sendrecv
[Jul 28 10:58:40]
[Jul 28 10:58:40] NOTICE[10268]: res_pjsip_session.c:3078 new_invite: Call from '1000-endpt' (UDP:172.16.15.2:5322) to extension '2000' rejected because extesion not found in context '1000-inbound'.
[Jul 28 10:58:40] <--- Transmitting SIP response (402 bytes) to UDP:172.16.15.2:5322 --->
[Jul 28 10:58:40] SIP/2.0 404 Not Found
[Jul 28 10:58:40] Via: SIP/2.0/UDP 172.16.15.2:5322;rport=5322;received=172.16.15.2;branch=z9hG4bKPj2769f01f-1011-4bbd-83b7-a0877aa10819
[Jul 28 10:58:40] Call-ID: 7fe73b79-6009-4166-b003-3ccff33844ed
[Jul 28 10:58:40] From: <sip:2000@172.16.15.2>;tag=096bb1dc-d8fb-404a-96f1-75315c18836e
[Jul 28 10:58:40] To: <sip:2000@172.16.19.32>;tag=38aa62cc-a720-4214-94be-3f77f6530f34
[Jul 28 10:58:40] CSeq: 13171 INVITE
[Jul 28 10:58:40] Server: Asterisk PBX 16.7.0
[Jul 28 10:58:40] Content-Length:  0
[Jul 28 10:58:40]
[Jul 28 10:58:40]
[Jul 28 10:58:40] <--- Received SIP request (413 bytes) from UDP:172.16.15.2:5322 --->
[Jul 28 10:58:40] ACK sip:2000@172.16.19.32:5322 SIP/2.0
[Jul 28 10:58:40] Via: SIP/2.0/UDP 172.16.15.2:5322;rport;branch=z9hG4bKPj2769f01f-1011-4bbd-83b7-a0877aa10819
[Jul 28 10:58:40] From: <sip:2000@172.16.15.2>;tag=096bb1dc-d8fb-404a-96f1-75315c18836e
[Jul 28 10:58:40] To: <sip:2000@172.16.19.32>;tag=38aa62cc-a720-4214-94be-3f77f6530f34
[Jul 28 10:58:40] Call-ID: 7fe73b79-6009-4166-b003-3ccff33844ed
[Jul 28 10:58:40] CSeq: 13171 ACK
[Jul 28 10:58:40] Max-Forwards: 70
[Jul 28 10:58:40] User-Agent: Asterisk PBX 13.29.1
[Jul 28 10:58:40] Content-Length:  0

I will try to change the “identify” value in every endpoint and see what happens, it looks like the asterisk is choosing the Endpoint based in the IP address, and not by the endpoint that is receiving the call.

If you’re doing username based matching, you can’t have identify sections matching on IP address.

How do I change that? I tryed to remove the “type=identify” from the endpoints, but then I get this NOTICE in console:

[Jul 28 11:59:00] NOTICE[8653]: res_pjsip/pjsip_distributor.c:676 log_failed_request: Request 'OPTIONS' from '<sip:1000@172.16.15.2>' failed for '172.16.15.2:5322' (callid: 60bf164e-076e-4845-aade-b234c7f90f3c) - No matching endpoint found

It will try to match an endpoint named “1000”. If you rename “1000-endpt” to “1000” it should then work.

Thanks jcolp, changing every endpoint to match identically the “username” and removing the identify section resolved the issue, now each call gets redirected to it’s context.

Is there any way to achieve this without having the same name? Because thinking in the long term in my application we could have some trouble with duplicated endpoints.

The from_user and the name of the endpoint in pjsip.conf have to match, that’s it. You can name them as you wish.

1 Like