A simple SIP call example

xiaoxiao2021-03-06  58

shows the SIP message exchange between two SIP-enabled devices. The two devices could be SIP phones, hand-helds, palmtops, or cell phones. It is assumed that both devices are connected to an IP network such as the Internet and know each other's IP Address.

Figure 2.1: a Simple Sip session Establishment Example.

The calling party, Tesla, begins the message exchange by sending a SIP INVITE message to the called party, Marconi. The INVITE contains the details of the type of session or call that is requested. It could be a simple voice (audio) session, A Multimedia Session Such as a video conference, or it could be a gaming session.

The INVITE Message Contains the Following Fields:

INVITE SIP: Marconi@radio.org Sip / 2.0

VIA: SIP / 2.0 / udp lab.high-voltage.org:5060;branch=z9hg4bkfw19b

Max-Forwards: 70

TO: G. Marconi

From: Nikola Tesla ; tag = 76341

Call-ID: 123456789@Lab.high-voltage.org

CSEQ: 1 Invite

Subject: About That Power Outage ...

Contact:

Content-Type: Application / SDP

Content-Length: 158

V = 0

O = Tesla 2890844526 2890844526 in ip4 lab.high-voltage.org

S = Phone Call

C = in IP4 100.101.102.103

T = 0 0

M = Audio 49170 RTP / AVP 0

a = rtpmap: 0 pcmu / 8000

SINCE SIP IS A TEXT-Encoded Protocol, this Is Actually What The Sip Message Would Look Like "On The Wire" AS A UDP DataGram Being Transport over, for example, Ethernet.

The fields listed in the INVITE message are called header fields They have the form Header:.. Value CRLF The first line of the request message, called the start line, lists the method, which is INVITE, the Request-URI, then the SIP version number (2.0), all separated by spaces. Each line of a SIP message is terminated by a CRLF. The Request-URI is a special form of SIP URI and indicates the resource to which the request is being sent, also known as the request target. SIP URIs are discussed in more detail in later sections.The first header field following the start line shown is a Via header field. Each SIP device that originates or forwards a SIP message stamps its own address in a Via header field, usually Written as a host name That Can Be Resolved Into An IP Address Using A DNS Query. The Via Header Field Contains The Sip Version Number (2.0), A "/", THEN UDP for UDP Transport, A Space, The Hostname OR Address , A Colon, THEN A Port Number, in this Example The "Well-KNown" SIP port number 5060. Transport of SIP using TCP, UDP, TLS, and SCTP and the use of port numbers are covered later in this chapter. The branch parameter is a transaction identifier. Responses relating to this request can be correlated because they will contain this Same Transaction Identifier.

The next header field shown is the Max-Forwards header field, which is initialized to some large integer and decremented by each SIP server, which receives and forwards the request, providing simple loop detection.

The next header fields are the To and From header fields, which show the originator and destination of the SIP request. When a name label is used, as in this example, the SIP URI is enclosed in brackets and used for routing the request. The name label could be displayed during alerting, for example, but is not used by the protocol.The Call-ID header field is an identifier used to keep track of a particular SIP session. The originator of the request creates a locally unique string, then usually adds an "@" and its host name to make it globally unique. in addition to the Call-ID, each party in the session also contributes a random identifier, unique for each call. These identifiers, called tags, are included in the To and from header fields as the session is established. The Initial Invite Shown Contains a from tag but no to tag.

The user agent that generates the initial INVITE to establish the session generates the unique Call-ID and From tag. In the response to the INVITE, the user agent answering the request will generate the To tag. The combination of the local tag (contained in the From header field), remote tag (contained in the to header field), and the Call-ID uniquely identifies the established session, known as a "dialog". This dialog identifier is used by both parties to identify this call because they could HAVE MULTIPLE CALLS SET UP BETWEEN THEM. Subsequent Requests WILL USE THIS DIALOG IDENTIFIER, AS WILL BE Shown In The Following Examples.

The next header field shown is the CSeq, or command sequence. It contains a number, followed by the method name, INVITE in this case. This number is incremented for each new request sent. In this example, the command sequence number is initialized to 1, but it could start at another integer value.The Via header fields plus the Max-Forwards, To, From, Call-ID, and CSeq header fields represent the minimum required header field set in any SIP request message. Other header fields can be included as optional additional information, or information needed for a specific request type A Contact header field is also required in this INVITE message, which contains the SIP URI of Tesla's communication device, known as a user agent (UA);. this URI can be used to route messages directly to Tesla. The optional Subject header field is present in this example. It is not used by the protocol, but could be displayed during alerting to aid the called party in deciding whether to accept the call. The same sort of useful prioritization and screening commonly performed using the Subject and From header fields in an e-mail message is also possible with a SIP INVITE request. Additional header fields are present in this INVITE message, which contain the media information necessary to set up the Call.

The Content-Type and Content-Length header fields indicate that the message body is SDP [3] and contains 158 octets of data. The basis for the octet count of 158 is shown in Table 2.1, where the CR LF at the end of each line is shown as a © ® and the octet count for each line is shown on the right-hand side. A blank line separates the message body from the header field list, which ends with the Content-Length header field. In this case, there are seven lines of SDP data describing the media attributes that the caller Tesla desires for the call. This media information is needed because SIP makes no assumptions about the type of media session to be established-the caller must specify exactly what type of session ( audio, video, gaming) that he wishes to establish. The SDP field names are listed in Table 2.2, and will be discussed detail in Section 7.1, but a quick review of the lines shows the basic information necessary to establish a session.Table 2.1 : Content-Length Calculation EXAMPLE

Linetotalv = 0 © ®05o = Tesla 2890844526 2890844526 IN ip4 lab.high-voltage.org © ®14c = phone call © ® 14c = in ip4 100.101.102.103 © ®26t = 0 © ®07m = Audio 49170 RTP / AVP 0 © ® 25a = RTPMAP: 0 PCMU / 8000 © ®22 158

Table 2.2: SDP Data from Example

SDP ParameterParameter Namev = 0 Version numbero = Tesla 2890844526 2890844526 IN IP4 lab.high-voltage.org Origin containing names = Phone Call Subjectc = IN IP4 100.101.102.103 Connectiont = 0 0 Timem = audio 49170 RTP / AVP 0 Mediaa = rtpmap: 0 PCMU / 8000 Attributes

Table 2.2 Includes the:

Connection IP Address (100.101.102.103); Media Format (AUDIO); Port Number (49170); Media Transport Protocol (RTP); Media Encoding; Sampling Rate (8,000 Hz).

INVITE is an example of a SIP request message. There are five other methods or types of SIP requests currently defined in the SIP specification RFC 3261 and others in extension RFCs. The next message in Figure 2.1 is a 180 Ringing message sent in response to the INVITE. This message indicates that the called party Marconi has received the INVITE and that alerting is taking place. The alerting could be ringing a phone, flashing a message on a screen, or any other method of attracting the attention of the called party, Marconi .The 180 Ringing is an example of a SIP response message. Responses are numerical and are classified by the first digit of the number. A 180 response is an "informational class" response, identified by the first digit being a 1. Informational responses are Used to Convey Noncritical Information About The Progress of The Call. Many Sip Response Codes WERE BASED ON HTTP VERSION 1.1 Response Codes with some extensions and additions. Anyone Who Has Ever Browsed The WORL d Wide Web has likely received a "404 Not Found" response from a Web server when a requested page was not found. 404 Not Found is also a valid SIP "client error class" response in a request to an unknown user. The other classes Of Sip Responses Are Covered in Chapter 5.

The response code number in SIP alone determines the way the response is interpreted by the server or the user. The reason phrase, Ringing in this case, is suggested in the standard, but any text can be used to convey more information. For instance, 180 Hold Your Horses, I'm Trying to Wake Him Up! Is a Perfectly Valid Sip Response And Has The Same Meaning As a 180 Ringing Response.

The 180 Ringing Response Has The Following Structure:

SIP / 2.0 180 Ringingvia: SIP / 2.0 / udp lab.high-voltage.org:5060;branch=z9hg4bkfw19b

Received = 100.101.102.103

TO: G. Marconi ; tag = a53e42

From: Nikola Tesla >; tag = 76341

Call-ID: 123456789@Lab.high-voltage.org

CSEQ: 1 Invite

Contact:

Content-Length: 0

The message was created by copying many of the header fields from the INVITE message, including the Via, To, From, Call-ID, and CSeq, then adding a response start line containing the SIP version number, the response code, and the reason Phrase. this approach simplifier the message processing for responses.

The Via header field contains the original branch parameter but also has an additional received parameter. This parameter contains the literal IP address that the request was received from (100.101.102.103), which typically is the same address that the URI in the Via resolves using DNS (lab.high-voltage.org).

Note that the To and From header fields are not reversed in the response message as one might them to expect be. Even though this message is sent to Marconi from Tesla, the header fields read the opposite. This is because the To and From header fields In Sip Are Defined to Indicate The Direction of The Request, Not The Direction of The Message. Since Tesla Initiated this Request, All Responses Will Read to: Marconi from: Tesla.

. ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

The response also contains a Contact header field, which contains an address at which Marconi can be contacted directly once the session is established.When the called party Marconi decides to accept the call (ie, the phone is answered), a 200 OK response is .. sent This response also indicates that the type of media session proposed by the caller is acceptable The 200 OK is an example of a "success class" response The 200 OK message body contains Marconi's media information.:

SIP / 2.0 200 OK

VIA: SIP / 2.0 / udp lab.high-voltage.org:5060;branch=z9hg4bkfw19b

Received = 100.101.102.103

TO: G. Marconi ; tag = a53e42

From: Nikola Tesla ; tag = 76341

Call-ID: 123456789@Lab.high-voltage.org

CSEQ: 1 Invite

Contact:

Content-Type: Application / SDP

Content-Length: 155

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

This response is constructed the same way as the 180 Ringing response and contains the same To tag and Contact URI. The media capabilities, however, must be communicated in a SDP message body added to the response. From the same SDP fields as Table 2.2, The SDP Contains:

End-point IP address (200.201.202.203); Media Format (Audio); Port Number (60000); Media Transport Protocol (RTP); Media Encoding (PCM μ-Law); Sampling Rate (8,000 Hz).

The final step is to confirm the media session with an "acknowledgment" request. The confirmation means that Tesla has received successfully Marconi's response. This exchange of media information allows the media session to be established using another protocol, RTP in this example.ACK sip : marconi@tower.radio.org Sip / 2.0

VIA: SIP / 2.0 / udp lab.high-voltage.org:5060;branch=z9hg4bk321g

Max-Forwards: 70

TO: G. Marconi ; tag = a53e42

From: Nikola Tesla ; tag = 76341

Call-ID: 123456789@Lab.high-voltage.org

CSEQ: 1 ACK

Content-Length: 0

The command sequence, CSeq, has the same number as the INVITE, but the method is set to ACK. At this point, the media session begins using the media information carried in the SIP messages. The media session takes place using another protocol, typically Rtp. The Branch Parameter in The Via Header Field Contains A New Transaction Identifier Than The Invite, Since An Ack Sent To Acknowledge A 200 OK Is Considered a Separate Transaction.

This message exchange shows that SIP is an end-to-end signaling protocol. A SIP network, or SIP server is not required for the protocol to be used. Two end points running a SIP protocol stack and knowing each other's IP addresses can use SIP to set up a media session between them. Although less obvious, this example also shows the client-server nature of the SIP protocol. When Tesla originates the INVITE request, he is acting as a SIP client. When Marconi responds to the request, he is acting as a SIP server. After the media session is established, Marconi originates the BYE request and acts as the SIP client, while Tesla acts as the SIP server when he responds. This is why a SIP-enabled device must contain both SIP server and SIP client software-during a typical session, both are needed. This is quite different from other client-server Internet protocols such as HTTP or FTP. The Web browser is always an HTTP client, and the Web server is always an HTTP server, And Similarly for ftp. i N SIP, An End Will Switch Back and Forth During a session Between Being a Client and a Server.in Figure 2.1, a Bye Request Is Sent by Marconi to Terminate The Media Session:

BYE Sip: n.tesla@lab.high-voltage.org Sip / 2.0

VIA: SIP / 2.0 / udp Tower.Radio.org:5060; Branch=z9hg4bk392kf

Max-Forwards: 70

TO: Nikola Tesla ; tag = 76341

From: g. marconi ; tag = a53e42

Call-ID: 123456789@Lab.high-voltage.org

CSEQ: 1 bye

Content-Length: 0

The Via header field in this example is populated with Marconi's host address and contains a new transaction identifier since the BYE is considered a separate transaction from the INVITE or ACK transactions shown previously. The To and From header fields reflect that this request is originated by Marconi , as they are reversed from the messages in the previous transaction. Tesla, however, is able to identify the dialog using the presence of the same local and remote tags and Call-ID as the INVITE, and tear down the correct media session.Notice that all the branch IDs shown in the example so far begin with the string z9hG4bK. This is a special string that indicates that the branch ID has been calculated using strict rules defined in RFC 3261 and is as a result usable as a transaction identifier. [ 1]

The Confirmation Response To The Bye IS A 200 OK:

SIP / 2.0 200 OK

VIA: SIP / 2.0 / udp Tower.Radio.org:5060; Branch=z9hg4bk392kf

Received = 200.201.202.203

TO: Nikola Tesla ; tag = 76341

From: g. marconi ; tag = a53e42

Call-ID: 123456789@Lab.high-voltage.org

CSEQ: 1 bye

Content-Length: 0

The response echoes the cseq of the original request: 1 bye.

[1] This string is needed because branch IDs generated by user agents prior to RFC 3261 may have constructed branch IDs which are not suitable as transaction identifiers. In this case, a client must construct its own transaction identifier using the To tag, From tag , Call-ID, and CSEQ.

转载请注明原文地址:https://www.9cbs.com/read-114606.html

New Post(0)