13.11.2/PJSIP: Identify endpoint for inbound calls


I am rather new to asterisk in general and PJSIP in particular, but after some rather extensive reading I think I got a good grasp of how things work. There is however one thing I still can’t figure out, and that is how to correctly identify inbound calls from my ITSP and assign them to the correct endpoint

My ITSP provides me with a total of 4 numbers. All four numbers are correctly registering to my ITSP’s server, each with it’s own username/password and contact address, so that inbound calls enter the dialplan with the extension that is specified for each registration. What I cannot figure out is how I could map inbound calls from my ITSP to use the correct endpoint for the corresponding number. From all I have read so far, it seems the only two methods of identifying an endpoint are IP address (which is the same for all four numbers) or the user portion of the From header (which will likely contain the sip-uri of the calling party).

In lack of a better solution, what I do right now is to assign all inbound calls from my ITSP to the first endpoint, by using an identify section with the ITSP’s IP address and have it point to the first endpoint. This setup works for now, as calls still enter the dialplan using the extension that was specified in the register, but if I wanted to specify different endpoint options for each of the four numbers then I would probably run into problems.

Is there any other method for identifying/assigning an enpoint that I’ve overlooked? Any help is appreciated.

The other option would be to use the ‘line’ option[1] on the outbound registration which may work with the ITSP.

[1] http://blogs.asterisk.org/2016/01/27/the-pjsip-outbound-registration-line-option/

Thanks for the quick response.

I was under the impresssion that the intended use of the ‘line’ option was rather the opposite scenario, i.e. ITSP with multiple server IP adresses. Also there are a number of things that I don’t really like about using the ‘line’ option:

  • It seems to rely upon the ITSP’s server to preserve the ‘line’ parameter from the registration.
  • Additional data is added to all requests, which should not be necessary as there already is a uniquely identifyable part (the contact address from the registration, that the ITSP’s server is supposed to use).

I will give it a try and see whether my ITSP’s broadworks based server preserves the ‘line’ parameter, so that it may be used for endpoint identification. I would however rather prefer a solution that matches on the contact address provided in each registration section (I guess that will appear in the ‘To:’ header of subsequent requests?).

No current mechanism exists for that but PJSIP is pluggable in that area so it could. As well - that relies on the behavior of the ITSP as well to preserve the Contact user and use it. Not all of them do, particularly when you have multiple DIDs under the same account.

In my case each of the four DID numbers serves as the username and each comes with a distinct password that is used for outbound authentication during registration and call setup. I have modified my pjsip.conf to use the ‘line’ parameter on all four outbound registrations and have removed the ‘identify’ section entirely. After testing some inbound calls, I can now confirm that my ITSP’s server preserves the ‘line’ parameter and that asterisk correctly assigns the calls to the corresponding endpoints. So it seems to get the job done, which is a good thing.

Nevertheless I would still prefer an endpoint identifier that matches upon the provided ‘To:’ header, which in all SIP messages that I’ve tracked, contained the corresponding DID number. I have however no idea how common or uncommon this scenario is, but I can imagine that there are many people on consumer DSL lines with similar needs.

It appears as if the documentation on that matter on the wiki here https://wiki.asterisk.org/wiki/display/AST/PJSIP+Configuration+Sections+and+Relationships is not quite correct. It states:

However I even went as far as to look at the source code, and the only thing it ever seems to match upon is the “From:” header, not the “To:” header.

Given the fact that the endpoint identifiers in pjsip are modular, I still think there should be a way to match on IP address first and “To:” header second to identify the correct endpoint for inbound calls in a scenario where you register multiple DIDs with the same ITSP. A similar issue has been discussed here https://community.asterisk.org/t/sip-header-did-help/66528/2, so maybe it’s not as uncommon as I thought? Personally I feel that neither the use of the ‘line’ parameter, nor reyling on some header parsing magic in the dialplan appears to be the correct approach to solving this kind of problem.

Can you comment on that wiki page about it being incorrect?

You are correct in that an endpoint identifier could be written to do so, but noone has written one as of yet. We also don’t currently accept feature requests (although this may change in the future based on discussion that happened, but still does not guarantee that it would get implemented).

I have added a comment on the wiki page.

Whether a separate endpoint identifier would be needed is questionable. I guess the term ‘endpoint_identifier_user’ covers both scenarios, so maybe a configuration property that determines the source where to pull that username from could be sufficient.