SIP protocol details (taking call center incoming and outgoing calls as an example)

Posted by CheesierAngel on Sat, 25 Dec 2021 14:24:27 +0100

1, Background

Traditional call making process:

  1. A calls B and invites B to establish an invite
  2. Phone B rings and phone A can hear the ring
  3. Phone B indicates a reply, so the call is established
  4. On the phone...
  5. Either party hangs up and the call ends

The traditional telephone uses electromagnetic wave to transmit communication signals, but at this stage, the network has almost complete coverage. Therefore, the significance of SIP protocol is to realize the function of network telephone in IP network

2, Agreement content

sip protocol is an application layer protocol, which works together with other application layer protocols to control multimedia communication sessions through the network

Both parties need to have a sip account in the IP network. Different from the traditional digital number, SIP adopts the URL representation method

  sip:jack@google.com:5060

Resolution:

sip: indicates that the sip protocol is adopted

jack: the user name that initiates the request, alphanumeric

​ google.com: the domain name of the server to which the account belongs, which can also be expressed by ip

5060: connected port number

SIP communication process:

1. Softphone A sends A SIP message INVITE to B to INVITE B to talk

2. Softphone B rings and replies A with A SIP message RING, informing A that it is ringing. Please wait

3. Pick up the softphone B and send A SIP message OK to A to inform A that it is ready to call

4. Softphone A replies A response message ACK to B and officially starts the call

5. Next, the two sides talk

6. Softphone B hangs up and sends A SIP message BYE to A to notify A that the call is over

7. Softphone A replies A message OK to B, and the call ends

Conclusion: it is not difficult to find that SIP protocol completely realizes the traditional telephone communication process and runs in the network environment in the form of ip

3, In depth agreement subject

Several concepts:
The design of SIP protocol is very simple, with limited commands. It is also text-based, so anyone can read SIP messages passed between endpoints in a SIP session.

Some entities help SIP create its network. In SIP, each network element is identified by the SIP URI (Uniform Resource Identifier), which is like an address. The following are the network elements

  • user agent
  • proxy server
  • Registration server
  • redirect server
  • Location server

SIP is based on client server architecture, in which the caller's phone acts as the client for initiating the call and the called party's phone acts as the server for responding to the call

user agent

  • User agent client (UAC) - an entity that sends requests and receives responses
  • User agent server (UAS) - an entity that receives requests and sends responses

proxy server

The network element receives the request from the user agent and forwards it to another user. Basically, the role of the proxy server is like a router. It has some wisdom to understand the SIP request and send it with the help of URI. The proxy server is located between two user agents, and there can be up to 70 proxy servers between the source and destination

There are two types of proxy servers

  • Stateless proxy server - it just forwards received messages. This type of server does not store any call or transaction information
  • Stateful proxy server - this type of proxy server can track every request and response received and use it in the future if necessary. If the other party does not respond, it can resend the request
INVITE message instance:
INVITE sip:some@192.168.31.131:50027 SIP/2.0
Via: SIP/2.0/UDP 192.168.31.131:51971;rport;branch=z9hG4bKiYblddPPX
Max-Forwards: 70
To: <sip:some@192.168.31.131:50027>
From: <sip:null@null>;tag=Prf3c3Xc
Call-ID: cenXTa4i-1423587756904@appletekiAir
CSeq: 1 INVITE
Content-Length: 215
Content-Type: application/sdp
Contact: <sip:null@192.168.31.131:51971;transport=UDP>

v=0
o=user1 685988692 621323255 IN IP4 192.168.31.131
s=-
c=IN IP4 192.168.31.131
t=0 0
m=audio 49432 RTP/AVP 0 8 101
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:101 telephone-event/8000
a=sendrecv

The request message is divided into the following parts: starting line, message header, empty line (indicating the end of the message) and message body. The specific contents of the protocol will be explained one by one below

  1. Start line
# ①     ②   ③            ④              ⑤          
INVITE sip:some@192.168.31.131:50027 SIP/2.0

① The request Method in this example is invite. There are six methods specified in the SIP protocol: invite, ACK and cancel are used to create a conversation, BYE is used to end the conversation, REGISTER is used to REGISTER, and OPTIONS is used to query the server capability

② The protocol header indicates that the sip protocol is used

③ Connection user name

④ Connection URL+port

⑤ sip version number. In this example, sip 2.0 protocol version is used

  1. Message header

    Via: SIP/2.0/UDP 192.168.31.131:51971;rport;branch=z9hG4bKiYblddPPX
    Max-Forwards: 70
    To: <sip:some@192.168.31.131:50027>
    From: <sip:null@null>;tag=Prf3c3Xc
    Call-ID: cenXTa4i-1423587756904@appletekiAir
    CSeq: 1 INVITE
    Content-Length: 215
    Content-Type: application/sdp
    Contact: <sip:null@192.168.31.131:51971;transport=UDP>
    

    ① via field

    Via: SIP/2.0/UDP 192.168.31.131:51971;rport;branch=z9hG4bKiYblddPPX Max-Forwards: 70

    via header field: indicates the host name and network address of the sip network element

    branch parameter: used to identify the transaction created by this request, and this field must exist

    The parameters must be divided into two parts: the first part conforms to the general principles (for RFC3261, z9hG4bK), and the second part (iyblddppx in this example) is used to implement loop detection to distinguish between loop and spiral. Both loop and spiral refer to that the Proxy forwards a request after receiving it, and then the forwarded request arrives at the Proxy again. The difference is that the request URI of the request in the loop and other header fields affecting the Proxy processing remain unchanged, while some of these parts of the spiral request must be changed. The typical case of spiral is that the request URI changes

    Before inserting the Via field into the Proxy, the loop of its branch parameter The detection part is coded according to the following elements: To Tag, From Tag, call ID field, request URI, Topmost Via field, The sequence number part of Cseq (i.e. independent of the request method), the Proxy require field and the proxy authorization field. Note: the request method cannot be used to calculate the branch parameters. For example, the ACK of cancel and non 2XX response belong to the same transaction as the request or corresponding INVITE cancelled, i.e. the branch parameters are the same. See RFC3261 P22 P25 P39 P95 P105

    Max forwards: indicates the limit on the number of hops that the request reaches the UAS

    ② To field

    To: <sip:some@192.168.31.131:50027>

    UAC initiates a dialog request, that is, out of dialog. Because the dialog has not been established and does not contain the to tag parameter, when UAS

    When receiving an INVITE request, set the to tag parameter in the 2XX or 101-199 response sent by it, which is a part of a Dialog ID (Dialog unique ID, including to tag, From Tag, call ID) together with the From Tag parameter and call ID set by UAC. RFC3261 specifies that only INVITE requests and 2XX or 101-199 responses can establish a Dialog

    ③ From field

    From: <sip:null@null>;tag=Prf3c3Xc

    The From field indicates the sender of the message. The field must contain the tag parameter as part of the ID

    ④ CALL-ID field

    Call-ID: cenXTa4i-1423587756904@appletekiAir

    Call ID refers to the unique identification of a group of responses generated after all requests of the same UAC user. The From Tag field and To Tag field set by call ID in the UAC request form a dialog ID

    ⑤ CSeq field

    CSeq: 1 INVITE

    CSeq is used to identify and sort transactions in the same dialog and distinguish new requests and request retransmissions. The contents include sequence numbers and methods. The methods must match the corresponding requests. For each new request (e.g. BYE, re invite, OPTION) in the dialog, the CSeq sequence number is increased by 1, except for CANCEL and ACK. Their CSeq sequence number must be the same as the corresponding requests

    ⑥ Content length field

    Content-Length: 215

    The content length field represents the length of the message body and is expressed in decimal numbers

    ⑦ Content type field

    Content-Type: application/sdp

    Content type indicates the media type of the message body sent to the receiver. If the message body is not empty, the content type header field must exist. If the content type header field exists and the message body is empty, it indicates that the

    The media stream length of type is 0

    ⑧ Contact field

    Contact: <sip:null@192.168.31.131:51971;transport=UDP>

    This field provides the URL of the SIP directly contacted by UAC or UAS. When the session is established, UAC provides the URL of its own SIP in the Contact field. When UAC receives the request, it will bypass PROXY and send the response to the URL of the directly contacted sip. For REGISTER transactions, the field represents the contact address of the address binding

  2. Message body

The encoding protocol of the message is specified by the header, and SDP protocol is generally used

#Version number is 0
v=0
#Creator user name + session ID + version + network type + address type + address 
o=user1 685988692 621323255 IN IP4 192.168.31.131
#Session name                
s=-
#Connection information: network type + address type + address
c=IN IP4 192.168.31.131
#Session activity time start time + end time
t=0 0
#Media description: media + port + delivery + format list
#Audio + port 49432 + Transmission Protocol RTP + format AVP, payload 0 (u rate PCM coding)
m=audio 49432 RTP/AVP 0 8 101
#0 or more session attributes: attribute + payload + code name + sampling frequency.         
a=rtpmap:0 PCMU/8000
#rtpmap + type 0 + PCMU + 8KHz 
a=rtpmap:8 PCMA/8000
#a there can be multiple. See SDP protocol
a=rtpmap:101 telephone-event/8000
a=sendrecv
Ring message
SIP/2.0 180 Ringing
From: <sip:null@null>;tag=Prf3c3Xc
Call-ID: cenXTa4i-1423587756904@appletekiAir
CSeq: 1 INVITE
Via: SIP/2.0/UDP 192.168.31.131:51971;rport=51971;branch=z9hG4bKiYblddPPX
To: <sip:some@192.168.31.131:50027>;tag=AM1g60xRvq
Contact: <sip:192.168.31.131:50027;transport=UDP>
OK message
SIP/2.0 200 OK
From: <sip:null@null>;tag=Prf3c3Xc
Call-ID: cenXTa4i-1423587756904@appletekiAir
CSeq: 1 INVITE
Via: SIP/2.0/UDP 192.168.31.131:51971;rport=51971;branch=z9hG4bKiYblddPPX
To: <sip:some@192.168.31.131:50027>;tag=AM1g60xRvq
Content-Length: 214
Content-Type: application/sdp
Contact: <sip:192.168.31.131:50027;transport=UDP>

v=0
o=user1 77115499 915054303 IN IP4 192.168.31.131
s=-
c=IN IP4 192.168.31.131
t=0 0
m=audio 49434 RTP/AVP 0 8 101
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:101 telephone-event/8000
a=sendrecv
ACK message
ACK sip:192.168.31.131:50027;transport=UDP SIP/2.0
Via: SIP/2.0/UDP 192.168.31.131:51971;rport;branch=z9hG4bKEfwYu4LbB
To: <sip:some@192.168.31.131:50027>;tag=AM1g60xRvq
From: <sip:null@null>;tag=Prf3c3Xc
Call-ID: cenXTa4i-1423587756904@appletekiAir
CSeq: 3 ACK
Max-Forwards: 70
BYE message
BYE sip:null@192.168.31.131:51971;transport=UDP SIP/2.0
Via: SIP/2.0/UDP 192.168.31.131:50027;rport;branch=z9hG4bKvtPAT0lfO
To: <sip:null@null>;tag=Prf3c3Xc
From: <sip:some@192.168.31.131:50027>;tag=AM1g60xRvq
Call-ID: cenXTa4i-1423587756904@appletekiAir
CSeq: 711793880 BYE
Max-Forwards: 70

Topics: network server Network Protocol