SIP uses a peer to peer mechanism for call setup. In order for a call to be established, two peers need to be defined and be able to communicate with each other. This necessitates a SIP trunk entry for each peer of a given system.
Communication between two peers implies that the peer initiating the call knows the IP address of the recipient, and that the recipient can match the caller’s credentials in order to allow and configure the call.
The peer initiating the call can either have the recipient’s IP address configured, or may know the recipient’s IP address as the result of the recipient registering with the it (i.e. the calling peer is acting as a provider.) When acting as a provider, a peer allows registration of a remote peer by matching the incoming registration request’s username with the provider’s SIP trunk name. At this point the provider’s SIP trunk moves from having an UNKNOWN peer to being associated with the registered IP address.
An incoming call is matched by the recipient by looking at the incoming call’s IP address and FROM field, which defaults to the caller ID of the caller, or the calling peer’s from-user field if configured. The recipient first looks at the caller’s FROM field, and if this matches the username field of a peer that has “Identify by user” enabled or a configured extension, a successful match is made.
If no such match can be made, the recipient matches the first SIP trunk entry that is associated with the IP address of the caller. This implies that, if multiple SIP trunks are associated with peers with the same IP address, they have to have “Identify by username” enabled and a username specified, and the remote peers have to have their from-user fields set to the appropriate username.
If a successful match is made and the password and codecs that are configured for that matched peer are compatible with those in the call setup request, the call is established.
This mechanism is used for call setup in both directions.