[Asterisk-doc] [Fwd: Re: [Asterisk-Users Canreinvite=[yes|no] explained (new subject)]

Olle E. Johansson asterisk-doc@lists.digium.com
Fri, 11 Jun 2004 20:59:14 +0200


Addition to my SIP Nat writings...
/O :-)

-------- Original Message --------
Subject: Re: [Asterisk-Users Canreinvite=[yes|no] explained (new subject)
Date: Fri, 11 Jun 2004 20:58:19 +0200
From: Olle E. Johansson <oej@edvina.net>
Organization: Edvina AB
To: asterisk-users@lists.digium.com
References: <001501c44fc0$7ee5efd0$6501a8c0@senadspc>

Senad Jordanovic wrote:
> brian wrote:
>>That's the only way to make it work.
> Devices behind nat, on same network, can call each other ONLY if
> "canreinvite" is set to no? Is that what you are saying?
> 
Canreinvite=yes *only* works if all devices are on the same side of the NAT, the
outside or the inside.

If one device is on a different side of a NAT device than another phone
or Asterisk, you can't allow re-invites for that device.

Let me explain:

Phone A -------------> Asterisk -----------------> phone B

Phone A calls phone B. The first thing you have to remember is that Asterisk
is *not* a SIP proxy, it's a SIP PBX. So phone A sends an invite to Asterisk.
Asterisk starts a *new* SIP dialog and sends an invite to Phone B.
If Phone B accepts the call ("answers"), it sends an "200 OK" sip message
to Asterisk. Asterisk sends a "200 OK" SIP message to phone A. We now have
*two* SIP calls, or dialogs, that are bridged through Asterisk.

The natural behaviour for the Asterisk SIP channel in this case is
to get a feeling of "Hey, these two phones are using me just for transport
of bits between themselves. Why not get out of the loop and let them
exchange these bits directly with each other? I can use the spare CPU
cycles for something more meaningful than shipping these bits..."

So, in order to get out of this meaningless position, Asterisk checks if
the phones are compatible. If they support the same codec, if they
can talk to each other. If *one* of them have canreinvite=no
or something else that stops a direct audio relationship from phone A to B,
Asterisk stays in the middle of things, shipping bits between the phones
(the audio stream).

If they are compatible, Asterisk sends a new SIP INVITE to both of the
phones, redirecting the media streams for the current calls to each
other. This is called a Re-INVITE, an INVITE where we change media
for an existing SIP dialog, not trying to start a new call.

This works perfectly well if all phones are compatible and we have
the network configured so that they can talk full duplex to each other.
If one is behind a NAT, they can't. If that's the case, we'll only
get one audio stream, from the phone on the inside to the one on the
outside. That's why we want to set canreinvite=no to make sure
Asterisk doesn't even try to re-INVITE.

------------------
Executive Summary:

canreinvite=no in a [peer] configuration makes Asterisk stay
in the middle of the media stream. This is the "safe" setting,
but remember it makes your CPU always handle the media stream.

Regards,
/Olle


PS. Yes, the Asteriskdocs.org project is allowed to use this text if they
find it meaningful :-)



-- 
Olle E. Johansson, Edvina.net AB, oej@edvina.net
----- Phone +46 8 594 788 10, Cell phone: +46 70 593 68 51
----- IP phone: sip:oej@edvina.net
----- Address: Runbovägen 10, SE-192 48 Sollentuna, Sweden
----- Web: http://edvina.net