SIP Learning (example)

Source: Internet
Author: User

This digest from: http://blog.chinaunix.net/uid-20655530-id-1589483.html

The quickest way to learn the SIP protocol is to learn by example,

Found a complete call flow, let's go!

INVITE

The calling party Tesla First initiates the INVITE message to the called party Marconi. The INVITE message contains the session type and the parameters necessary for some calls. The session type may be simple speech, or it may be a multimedia video used by a web conferencing, or it may be a game session. Here's a sample of the message body, which we'll analyze in detail the meaning of each field.

INVITE sip:[email protected] sip/2.0
    <=   request method, request address ( Request- Uri), sip  version number (now all  sip/2.0)
        <=   The request address is usually called party address, with  msn   email 

Via:sip/2.0/udp lab.high-voltage.org:5060;branch=z9hg4bkfw19b
    < 2.0 Udp
        < is a random code, which is considered a transport identity
        <= Via 
        < tcp, tls< Span style= "font-family: the song Body;" >, SCTP

Max-forwards:70
<= Maximum number of hops, is the number of hops through the SIP server, mainly to prevent cyclic jumping
<= per proxy server, the integer minus one

To:g. Marconi <sip:[email protected]>
From:nikola Tesla <sip:[email protected]>;tag=76341
<= Indicates the sender and target party of the request message
<= If there is a user name tag in it, the address needs to be wrapped in angle brackets.
<= for INVITE messages, you can include tag in the from field , which is also a random code

Call-id: [email protected]
The <= call ID is a globally unique value generated by the local device. The value is the same for each call
<= The INVITE message is sent to the user agent, the from tag and Call-id global unique codes are generated locally, and the called party Agent generates the to tag global unique code. These three random codes are used for the entire conversation of the dialogue Identifier (dialog indentifier) on both sides of the call.

Cseq:1 INVITE
<=cseq, also called command seqence, each time a new request is sent, the number is automatically added 1
* The above fields are required for all SIP message bodies, some of the other header fields are optional, and some are required for specific requests

Subject:about that Power Outage ...
Contact: <sip:[email protected]>
<=contact is required for INVITE messages, it is routed to the called device address, also known as the user agent (UA)
Content-type:application/sdp
content-length:158
<= the last two-bit subordinate field describes the message body type and the field length

V=0    <= sdp version number , currently  0
O=tesla 2890844526 2890844526 in IP4 Lab.high-voltage.org    <= called source address, type, etc.
S=phone call    <= theme
C=in IP4 100.101.102.103    <= connection
t=0 0     <=   timestamp
M= Audio 49170 RTP/AVP 0   <= Media
a=rtpmap:0 Pcmu/8000    <= Media properties

<= from the above SDP message body We can draw the following information
<= Connection IP address:100.101.102.103
<= Media Format:audio
<= Port number:49170
<= Media Transfer type:RTP
<= Media code:PCM u law
<= Sample rate:8000 Hz

Ringing

when the called party receives After the INVITE requests the message, it will reply to the ringing. As the name implies, is sent back to the ring tone, prompting the call party phone has been connected, is waiting to be called to answer. When the called party receives the INVITE message, it will also have a ringing or other call-in prompt, which is set by the called Party (we can think of it as our own setting of the ringtone). a response that is called a "message-in- time response "is an answer that is used to test the called state. So it does not contain much information, and the specific response message is as follows:

sip/2.0 ringing
VIA:SIP/2.0/UDP lab.high-voltage.org:5060;branch=z9hg4bkfw19b
; received=100.101.102.103 <= Add one hereReceivedparameter that identifies the receiving partyIpAddress
To:g. Marconi <sip:[email Protected]>;tag=a53e42 <= mentioned above,to tagas the called Party logo
From:nikola Tesla <sip:[email protected]>;tag=76341 <= requires a very sending partyFrom tagconsistent
Call-id:[email protected]
Cseq:1 INVITE
Contact: <sip:[email protected]>
content-length:0
<= forRingingresponse, is basically theINVITEof theVia,To,From,Call-idand theCSeqthe content is copied over, for the first line markedSipversion number, response code (180) and action reason (Reason phrase)
<= Note hereFromand theToaddress, as they are used to specify the direction of the call, so theOKThe response did not swap the address and remains intact. A little different isToThe header field was added by the called PartyMarconigenerated byTagIdentification

Ok

be slogan after the bell, if the user is called Marconi pick up the phone, the response is issued with a OK . This response, in addition to being turned on, has a function to specify the called allowed connection media format, allowing the caller to confirm that the media can be received.
The message body is as follows

sip/2.0 OK
via:sip/2.0/udp lab.high-voltage.org:5060;branch=z9hg4bkfw19b
; received=100.101.102.103
To:g. Marconi <sip:[email protected]>;tag=a53e42
From:nikola Tesla <sip:[email  protected]>;tag=76341
Call-id: [email protected]
cseq:1 INVITE
Contact: <sip:[email protected]>
CONTENT-TYPE:APPLICATION/SDP
content-length:155
    <= header field section Basic ibid.

v=0
O=marconi 2890844528 2890844528 in IP4 tower.radio.org
S=phone call
c=in IP4 200.201.202.203
t=0 0
M=audio 60000 RTP/AVP 0
A= rtpmap:0 pcmu/8000

<= from the above SDP message body We can draw the following information
<= Terminal IP address:200.201.202.203
<= Media Format:audio
<= Port number:60000
<= Media Transfer type:RTP
<= Media code:PCM u law
<= Sample rate:8000 Hz

Ack

the last step before the call is the caller's confirmation of the OK response. This confirmation confirms that the connection is allowed and is about to start the media connection using another protocol. This other protocol is the RTP format negotiated above in the SDP message segment . The ACK response reads as follows:

ACK Sip:[email protected] sip/2.0
VIA:SIP/2.0/UDP lab.high-voltage.org:5060;branch=z9hg4bk321g
Max-forwards:70
To:g. Marconi <sip:[email Protected]>;tag=a53e42
From:nikola Tesla <sip:[email protected]>;tag=76341
Call-id: [email protected]
Cseq:1 ACK
content-length:0

BYE

after the call is completed, the called Party Marconi first hangs the machine and sends the BYE request command. Note that this is called by Marconi, so the Via field and the from, to and INVITE fields are different. is actually inverted.

BYE Sip:[email protected] sip/2.0
VIA:SIP/2.0/UDP TOWER.RADIO.ORG:5060;BRANCH=Z9HG4BK392KF
Max-forwards:70
To:nikola Tesla <sip:[email protected]>;tag=76341
From:g. Marconi <sip:[email Protected]>;tag=a53e42
Call-id: [email protected]
Cseq:1 BYE
content-length:0

OK

after BYE, asked to be called party issued a OK confirmation, that is, let the Lord called to know that the call already know that you hung up. (Note that this is called the main character has been reversed) For example, after the call, one side asked to hang the machine, the other party needs to know that it has been hanging.

sip/2.0 OK
VIA:SIP/2.0/UDP TOWER.RADIO.ORG:5060;BRANCH=Z9HG4BK392KF
; received=200.201.202.203
To:nikola Tesla <sip:[email protected]>;tag=76341
From:g. Marconi <sip:[email Protected]>;tag=a53e42
Call-id: [email protected]
Cseq:1 BYE
content-length:0

This is the simplest call process. The process is simply that there are no other devices between the two terminals, and a complete point-to-point connection between them is only required to know the other IP address. This is a rare form of call in real life.

SIP Learning (example)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.