1. SIP
SIP 是一個應用層的控制協議,可以用來建立,修改,和終止多媒體會話,例如Internet電話
SIP在建立和維持終止多媒體會話協議上,支持五個方面:
1) 用戶定位: 檢查終端用戶的位置,用於通訊。
2) 用戶有效性:檢查用戶參與會話的意願程度。
3) 用戶能力:檢查媒體和媒體的參數。
4) 建立會話: “ringing”,建立會話參數在呼叫方和被叫方。
5) 會話管理:包括發送和終止會話,修改會話參數,激活服務等等。
1.1 SIP基本組成要素
用戶代理:SIP用戶代理是一個SIP邏輯網絡端點,用於創建、發送、接收SIP消息並管理一個SIP會話
代理服務器:SIP代理服務器(PROXY)在網絡上位於SIP UAC和UAS之間,用於幫助UAC和UAS間的消息路由
注冊服務器:SIP注冊服務器用於接收SIP注冊請求,並保存發送注冊請求的UA的位置信息
重定向服務器:SIP 重定向服務器允許 SIP 代理服務器將 SIP 會話邀請信息定向到外部域
1.2 SIP 基本呼叫流程
1.2.1 注冊流程
1. 用戶首次試呼時,終端代理A向代理服務器發送REGISTER 注冊請求。
2. 代理服務器通過后端認證/計費中心獲知用戶信息不在數據庫中,便向終端代理回送401Unauthorized 質詢信息,其中包含安全認證所需的令牌。
3. 終端代理提示用戶輸入其標識和密碼后,根據安全認證令牌將其加密后,再次用REGISTER 消息報告給代理服務器。
4. 代理服務器將REGISTER消息中的用戶信息解密,通過認證/計費中心驗證其合法后, 將該用戶信息登記到數據庫中,並向終端代理A 返回成功響應消息200 OK。
1.2.2 注銷流程
1. 用戶摘機發起一路呼叫,終端代理A 向該區域的代理服務器發起Invite 請求。
2. 代理服務器通過認證/計費中心確認用戶認證已通過后,檢查請求消息中的Via 頭域中是否已包含其地址。若已包含,說明發生環回,返回指示錯誤的應答。如果沒有問題,代理服務器在請求消息的Via 頭域插入自身地址,並向Invite 消息的To 域所指示的被叫終端代理B 轉送Invite 請求。
3. 代理服務器向終端代理A 送呼叫處理中的應答消息,100 Trying。
4. 終端代理B 向代理服務器送呼叫處理中的應答消息,100 Trying;
5. 終端代理B 指示被叫用戶振鈴,用戶振鈴后,向代理服務器發送180 Ringing 振鈴信息。
6. 代理服務器向終端代理A 轉發被叫用戶振鈴信息。
7. 被叫用戶摘機,終端代理B 向代理服務器返回表示連接成功的應答(200 OK)。
8. 代理服務器向終端代理A 轉發該成功指示(200 OK)。
9. 終端代理A 收到消息后,向代理服務器發ACK 消息進行確認。
10. 代理服務器將ACK 確認消息轉發給終端代理B。
11. 主被叫用戶之間建立通信連接,開始通話。
1.2.4 正常呼叫釋放過程
1. 用戶通話結束后,被叫用戶掛機,終端代理B 向代理服務器發送Bye 消息。
2. 代理服務器轉發Bye 消息至終端代理A,同時向認證/計費中心送用戶通話的詳細信息,請求計費。
3. 主叫用戶掛機后,終端代理A向代理服務器發送確認掛斷響應消息200 OK。
4. 代理服務器轉發響應消息200OK。
1.2.5 被叫無應答流程一
1. 用戶A 發起一路呼叫,終端代理A 向代理服務器發Invite 請求消息。
2. 代理服務器向被叫用戶的終端代理B 轉發該Invite 請求。
3. 代理服務器向終端代理A 回送100 Trying 響應,表示呼叫已在處理中。
4. 終端代理B向代理服務器回送100 Trying,告知代理服務器呼叫正在處理。
5. 被叫用戶振鈴,終端代理B 向代理服務器送180 Ring 響應。
6. 代理服務器向終端代理A 轉發該響應消息。
7. 被叫久振鈴無應答,終端代理A判斷超時后,向代理服務器送Cancel 消息放棄該呼叫。
8. 代理服務器收到Cancel消息后,向終端代理A 回送200 OK 響應。
9. 代理服務器將Cancel 消息轉發給終端代理B。
10. 終端代理B 向代理服務器回送200 OK 響應。
11. 終端代理B 向代理服務器送487 請求已撤銷的響應消息。
12. 代理服務器收到后回送ACK確認。
13. 代理服務器向終端代理A 送487 請求已撤銷消息。
14. 終端代理A 向代理服務器回送ACK 確認。
1.2.6 被叫無應答流程二
1. 用戶A 發起一路呼叫,終端代理A 向代理服務器發Invite 請求消息。
2. 代理服務器向被叫用戶的終端代理B 轉發該Invite 請求。
3. 代理服務器向終端代理A 回送100 Trying 響應,表示呼叫已在處理中。
4. 終端代理B向代理服務器回送100 Trying,告知代理服務器呼叫正在處理。
5. 被叫用戶振鈴,終端代理B 向代理服務器送180 Ring 響應。
6. 代理服務器向終端代理A 轉發該響應消息。
7. 被叫久振鈴無應答,終端代理B判斷超時后,向代理服務器送408 Request timeout 消息放棄該呼叫。
8. 代理服務器收到408Request timeout 消息后,轉發該消息給終端代理A。
9. 代理服務器收到后回送ACK確認給終端代理B。
10. 終端代理A 向代理服務器回送ACK 確認。
1.3 代理服務器的路由
1.3.1 路由記錄的一般過程
1) proxy會檢查Request-URI。如果它指向的是本proxy所負責的區域,那么proxy會用位置服務的結果來替換這個URI。否則,proxy不改變這個URI。
2) proxy會檢查Route頭域的最上URI。如果這個URI指向這個proxy,這個proxy從Route頭域中移除(這個路由節點已經到達)。
3) proxy會轉發請求到最上的Route頭域值所標志的URI,或者Request-URI(如果沒有Route頭域)。
1.3.2 基本SIP四邊形
本例子是一個基本的SIP四邊傳送,U1->P1->P2->U2,使用proxy來傳送。下邊是過程。
U1 發送:
INVITE sip:callee@domain.com SIP/2.0
Contact: sip:caller@u1.example.com
發給P1,P1是一個外發的proxy。P1並不管轄domain.com,所以它查找DNS並且發送請求到那里。它也增加一個Record-Route頭域值:
INVITE sip:callee@domain.com SIP/2.0
Contact: sip:caller@u1.example.com
Record-Route: <sip:p1.example.com;lr>
P2收到這個請求。這是domain.com所以它查找位置服務器並且重寫Request-URI。它也增加一個Record-Route頭域值。請求中沒有Route頭域,所以它解析一個新的Request-URI來決定把請求發送到哪里。
INVITE sip:callee@u2.domain.com SIP/2.0
Contact: sip:caller@u1.example.com
Record-Route: <sip:p2.domain.com; lr>
Record-Route: <sip:p1.example.com;lr>
在u2.domain.com的被叫方接收到這個請求並且返回一個200OK應答:
SIP/2.0 200 OK
Contact: sip: callee@u2.domain.com
Record-Route: <sip:p2.domain.com;lr>
Record-Route: <sip:p1.example.com;lr>
u2的被叫方並且設置對話的狀態的remote target URI為:
sip: caller@u1.example.com並且它的路由集合是:
(<sip:p2.domain.com;lr>,<sip:p1.example.com;lr>)
這個轉發通過P2到P1到U1。現在U1設置它自己的對話狀態的remote target URI為:sip:calle@u2.domain.com並且它的路由集合是:
(<sip:p1.example.com;lr>,<sip:p2.domain.com;lr>)
由於所有的路由集合元素都包含了lr參數,那么U1構造最后的BYE請求:
BYE sip:callee@u2.domain.com SIP/2.0
Route:<sip:p1.example.com;lr>,<sip:p2.domain.com;lr>
就像其他所有的節點(包括proxy)會做的那樣,它會使用DNS來解析最上的Route頭域的URI值,這樣來決定往哪里發送這個請求。這就發到了P1。P1發現Request-URI中標記的URI不是它負責的域,於是它就不改變這個Request-URI。然后看到它是Route頭域的第一個值,於是就從Route頭域中移去,並且轉發這個請求到P2:
BYE sip:callee@u2.domain.com SIP/2.0
Route: <sip:p2.domain.com;lr>
P2也發現它自己並非負責這個Request-URI的域(P2負責的是domain.com並非u2.domain.com),於是P2並不改變它。它看到自己在Route的第一個值,於是移去這個,並且向u2.domain.com轉發(根據在Request-URI上查找DNS):
BYE sip:callee@u2.domain.com SIP/2.0
1.3.3 重寫Record-Route頭域值
在這里例子中,U1和U2是在不同的私有域空間中,並且他們通過proxy P1開始一個對話,這個P1作為不同私有namespace的一個網關存在。
U1->P1->U2
U1發送:
INVITE sip:callee@gateway.leftprivatespace.comSIP/2.0
Contact:<sip:caller@u1.leftprivatespace.com>
P1使用自己的定位服務並且發送下邊的信息到U2:
INVITE sip:callee@rightprivatespace.comSIP/2.0
Contact:<sip:caller@u1.leftprivatespace.com>
Record-Route:<sip:gateway.rightprivatespace.com;lr>
U2發送200 OK應答回給P1:
SIP/2.0 200 OK
Contact:<sip:callee@u2.rightprivatespace.com>
Record-Route:<sip:gateway.rightprivatespace.com;lr>
P1重寫它的Record-Route頭域參數,提供成為U1能夠使用的參數,並且發送給P1:
SIP/2.0 200 OK
Contact:<sip:callee@u2.rightprivatespace.com>
Record-Route: <sip:gateway.leftprivatespace.com;lr>
稍后,U1發送接下來的BYE到P1:
BYE sip:callee@u2.rightprivatespace.comSIP/2.0
Route:<sip:gateway.leftprivatespace.com;lr>
P1轉發到U2:
BYE sip:callee@u2.rightpriatespace.comSIP/2.0
2 開源SIP服務器和客戶端
2.1 開源SIP 服務器
1) Asterisk
2) Cipango
3) FreeSWITCH
4) GNU SIP Witch
5) Mobicents
6) Mysipswitch
7) OpenSER
8) OpenSIPS
9) SSailFin
10) SIP Express Router sipX
11) Yate
12) YXA
2.2 開源SIP 客戶端
1) Blink
2) Ekiga
3) Empathy
4) Jitsi
5) KPhone
6) Linphone
7) MicroSIP
8) PhoneGaim
9) QuteCom
10) SFLphone
11) Telephone
12) Twinkle
13) Yate client
2.3 開源SIP服務器比較
編程語言 |
操作系統 |
許可協議 |
功能 |
|
Asterisk |
C |
跨平台 |
GNU GPL/Proprietary |
Voice mail Conference calling Interactive voice response automatic call distribution |
Cipango |
Java |
|
Apache 2.0 |
|
Free Switch |
C |
跨平台 |
MPL |
會議,使用XML-RPC 控制呼叫,Interactive voice response (IVR), TTS/ASR (語音合成和語音識別), Public switched telephone network (PSTN) 接口,可連接模擬和數字中繼,VoIP 協議包括 SIP,SCCP, H.323, XMPP, GoogleTalk, t.38 等等 |
GNU SIP Witch |
C++ |
跨平台 |
GPL |
Call forwarding, call distribution, call hold, presence information and (text) messages, supports encrypted calls and also enables NAT traversal to establish the peer-to-peer connections. |
Mobicents |
Java |
跨平台 |
LGPL |
|
Mysipswitch |
C# |
|
BSD |
SIP account creation Setting up a customized dial plan Setting up 3rd party SIP Registrations SIP traffic forwarding SIP Accounts activity monitoring via the website SIP traffic monitoring via telnet Online switchboard: call hold/resume, call transfer/forward, call hangup Usual security features Click to Call (Beta) Possibility to run it on a local computer Multiple call forwarding RUBY Dial plans ENUM Lookup |
Opensip |
C |
Linux, FreeBSD, Solaris |
GNU GPL |
SIP registrar server SIP router / proxy (lcr, dynamic routing, dialplan features) SIP redirect server SIP presence agent SIP back-to-back User Agent SIP IM server (chat and end-2-end IM) SIP to SMS gateway (bidirectional) SIP to XMPP gateway for presence and IM (bidirectional) SIP load-balancer or dispatcher SIP front end for gateways/asterisk SIP NAT traversal unit SIP application server |
SailFin |
Java |
Cross-platform |
|
|
SIP Express Router |
C |
Linux, BSD, Solaris |
GPL |
RFC 3261 functionality, a variety of database backends (mysql, oracle, postgres, radius, text-db), management features (remote management via XML-RPC, load-balancing), NATi traversal, telephony features (LCR, speeddial), multidomain hosting, ENUM, presence, and even more |
sipX |
|
Fedora CentOS RHEL |
Affero General Public License |
traditional private branch exchange (PBX) like voice mail, interactive voice response systems, auto attendants and the like. Furthermore it integrates with Exchange 2007and Active Directory Environments. |
Yate |
C++ |
Cross-platform |
GNU General Public License with linking exception |
VoIP server SS7 switch VoIP client Jabber server Jabber client Conference server - with up to 200 voice channels in a single conference VoIP to PSTN gateway PC2Phone and Phone2PC gateway IP Telephony server and/or client H.323 gatekeeper H.323 multiple endpoint server H.323<->SIP Proxy SIP session border controller SIP router SIP registration server IAX server and/or client Jingle client or server MGCP server (Call Agent) ISDN passive and active recorder ISDN, RBS, analog passive recorder Call center server IVR engine Prepaid and/or postpaid cards system |
YXA |
Erlang |
Cross-platform |
New BSD license |
|
2.4 開源SIP客戶端比較
名稱 |
編程語言 |
操作系統 |
許可協議 |
功能 |
Blink |
Python |
Mac OS X, Windows and Linux |
GNU GPL |
OSX Integration (iCloud, iTunes, Address Book, Keychain, Voice Over) iCloud synchronization for accounts History menu for outgoing and incoming calls History browser System Address Book external plugin (can dial with Blink from Address Book) Answering machine Call transfer Call recording LDAP directory Launch external application on incoming calls Phone number translations |
Ekiga |
C C++ |
Unix-like, Windows |
GNU General Public License |
Call forwarding on busy, no answer, always (SIP and H.323) Call transfer (SIP and H.323) Call hold (SIP and H.323) DTMF support (SIP and H.323) Basic instant messaging (SIP) Text chat (SIP and H.323) Register with several registrars (SIP) and gatekeepers (H.323) simultaneously Ability to use an outbound proxy (SIP) or a gateway (H.323) Message waiting indications (SIP) Audio and video (SIP and H.323) STUN support (SIP and H.323) LDAP support Audio codec algorithms: iLBC, GSM 06.10, MS-GSM, G.711 A-law, G.711 µ-law, G.726, G.721, Speex, G.722, CELT (also G.723.1, G.728, G.729, GSM 06.10, GSM-AMR, G.722.2 [GSM‑AMR-WB] using Intel IPP) Video codec algorithms: H.261, H.263+, H.264, Theora, MPEG-4 |
Empathy |
C |
BSD, Linux, Other Unix-like |
GNU GPL |
ulti-protocol: Google Talk (Jabber/XMPP), MSN, IRC, Salut, AIM, Facebook, Yahoo!, Gadu Gadu, Groupwise, ICQ and QQ. (Supported protocols depend on installed Telepathy Connection Manager components.) Supports all protocols supported by Pidgin. File transfer for XMPP, and local networks. Voice and video call using SIP, XMPP and Google Talk. Some IRC support. For detailed list of supported protocol features see here Conversation theming (see list of supported Adium themes). Sharing and viewing location information. Private and group chat (with smileys and spell checking). Conversation logging. Automatic away and extended away presence. Automatic reconnection using Network Manager. Python bindings for libempathy and libempathy-gtk Support for collaborative applications (“tubes”). |
Jitsi |
Java |
Linux, Mac OS X, Windows (all Java supported) |
LGPL |
Attended and blind call transfer Auto away Auto re-connect Auto answer and Auto Forward Call recording Call encryption with SRTP and ZRTP Conference calls Direct media connection establishment with the ICE protocol Desktop Streaming Encrypted password storage using a master password File transfer for XMPP, AIM/ICQ, Windows Live Messenger, YIM Instant messaging encryption with OTR IPv6 support for SIP and XMPP Media relaying with the TURN protocol Message Waiting Indication (RFC 3842) Voice and video calls for SIP and XMPP using H.264 and H.263 or VP8 for video encoding Wideband audio with SILK, G.722, Speex and Opus DTMF support with SIP INFO, RTP (RFC 2833/RFC 4733), In-band Zeroconf via mDNS/DNS-SD (à la Apple's Bonjour) DNSSEC Group video support (Jitsi Videobridge) Packet loss concealment with the SILK and Opus codecs |
KPhone |
C++ |
Linux |
GPL |
Multiple parallel sessions (in the case of audio, one may be active, the others are held). Own ring tones or "ring music" NAT-traversal and STUN support Supported sound systems: ALSA and OSS SRTP encryption for voice Presence information Call Hold Call transfer Call forwarding Auto Answer |
Linphone |
C |
Cross-platform |
GNU GPL version 2 |
SIP user agent compliant with RFC 3261 SIP/UDP, SIP/TCP, SIP/TLS Supports IPv6 Digest authentication Supports multiple calls simultaneously with call management features: hold on with music, resume, transfer... Multiple SIP proxy support: registrar, proxies, outbound proxies Text instant messaging with delivery notification Presence using the SIMPLE standard in peer to peer mode DTMF (telephone tones) support using SIP INFO or RFC 2833 |
MicroSIP |
C/C++ |
Windows |
GNU General Public License |
Profile of a lightweight background application[2] Small memory footprint (<20 mb RAM usage) Strong adherence to the SIP standard Support for a number of codecs: Speex (narrow band and wideband), G.711 (u-law, a-law), GSM, iLBC, SILK (narrow band, wideband and ultra wideband), G.722 No Support for VP8 codec as of now STUN and ICE NAT traversal SIP SIMPLE presence and messaging |
QuteCom |
C/C++ |
Cross-platform |
GNU General Public License |
SIP compliance Provider agnostic Allows users to send SMS to France NAT traversal Cross-platform Audio smileys Qt-based GUI Chatting with MSN, AIM, ICQ, Yahoo and XMPP users Encryption via SRTP, but key exchange over Everbee key that is not a Standard Uses standard Session Initiation Protocol |
SFLphone |
C / C++ |
Linux |
GNU General Public License 3 |
SIP and IAX compatible Unlimited number of calls Call recording Attended call transfer Call hold Multiple audio conferencing (from 0.9.7 version) TLS and ZRTP support (from 0.9.7 version) Audio codecs supported: G711u, G711a, GSM, Speex (8, 16, 32 kHz), CELT, G.722 Multiple SIP accounts support STUN support per account (0.9.7) DTMF support (SIP INFO) Instant messaging Call history + search feature Silence detection with Speex audio codec Account assistant wizard Central server providing free SIP/IAX account SIP presence subscription Video multiparty conferencing (EXPERIMENTAL) Multichannel audio support [EXPERIMENTAL] Flac and OGG/Vorbis ringtone support Desktop notification: voicemail number, incoming call, information messages Minimize on start-up Minimize to tray not Direct IP-to-IP SIP call - P2P is not supported by IAx2 according to the documentation SIP Re-invite Address book support: Evolution Data Server integration (for the GNOME client), KABC integration for the KDE client PulseAudio support Native ALSA interface, DMix support Locale settings: French, English, Russian, German, Chinese, Spanish, Italian, Vietnamese Automatic opening of incoming URL |
Telephone |
Objective-C |
Mac OS X |
BSD License |
|
Twinkle |
C++ |
GNU/Linux |
GNU General Public License |
2 call appearances (lines) Multiple active call identities Custom ring tones Call Waiting Call Hold 3-way conference calling Mute Call redirection on demand Call redirection unconditional Call redirection when busy Call redirection no answer Reject call redirection request Blind call transfer Call transfer with consultation (attended call transfer) Reject call transfer request Call reject Repeat last call Do not disturb Auto answer Message Waiting Inidication Voice mail speed dial User defineable scripts triggered on call events E.g. to implement selective call reject or distinctive ringing RFC 2833 DTMF events Inband DTMF Out-of-band DTMF (SIP INFO) STUN support for NAT traversal Send NAT keep alive packets when using STUN NAT traversal through static provisioning Persistent TCP connections for NAT traversal Missed call indication History of call detail records for incoming, outgoing, successful and missed calls DNS SRV support Automatic failover to an alternate server if a server is unavailable Other programs can originate a SIP call via Twinkle, e.g. call from address book System tray icon System tray menu to quickly originate and answer calls while Twinkle stays hidden User defineable number conversion rules Simple address book Support for UDP and TCP as transport for SIP Presence Instant messaging Simple file transfer with instant message Instant message composition indication Command line interface (CLI) |
Yate |
C++ |
Cross-platform |
GNU General Public License with linking exception |
VoIP server SS7 switch VoIP client Jabber server Jabber client Conference server - with up to 200 voice channels in a single conference VoIP to PSTN gateway PC2Phone and Phone2PC gateway IP Telephony server and/or client H.323 gatekeeper H.323 multiple endpoint server H.323<->SIP Proxy SIP session border controller SIP router SIP registration server IAX server and/or client Jingle client or server MGCP server (Call Agent) ISDN passive and active recorder ISDN, RBS, analog passive recorder Call center server IVR engine Prepaid and/or postpaid cards system |
2.5 SIP 服務器和客戶端選擇
2.5.1 SIP服務器選擇:OpenSIPS
1) OpenSIPS源代碼下載:
用svn down下代碼 svn cohttps://opensips.svn.sourceforge.net/svnroot/opensips/branches/1.9 opensips_1_9
2) 安裝MySQL
3) OpenSIPS安裝
root@ubuntu:cd /home/amaryllis/work/project/opensips/
root@ubuntu:make menuconfig
4) OpenSIPS文件配置
a) 修改配置文件opensipsctlrc:
root@ubuntu:gedit /usr/local/opensips_proxy/etc/opensips/opensipsctlrc
b) 安裝數據庫:
root@ubuntu:cd /usr/local/opensips_proxy/sbin/
root@ubuntu:./opensipsdbctl create
c) 檢查M4是否安裝:
apt-get install m4
d) 生成opensips_residential_2013-3-10_22:52:46.cfg文件:
root@ubuntu:cd /usr/local/opensips_proxy/sbin/
root@ubuntu:./osipconfig
5) 設置啟動項:
root@ubuntu:cd /home/amaryllis/work/project/opensips/packaging/debian
root@ubuntu:cpopensips.init /etc/init.d/opensips
root@ubuntu:chmod+x /etc/init.d/opensips
root@ubuntu:gedit/etc/init.d/opensips
6) 設置默認項opensips.default:
root@ubuntu:cd /home/amaryllis/work/project/opensips/packaging/debian
root@ubuntu:cp opensips.default /etc/default/
root@ubuntu:cd /etc/default/
root@ubuntu:mv opensips.default opensips
root@ubuntu:gedit opensips
7) 啟動OpenSIPS:
root@ubuntu:/etc/init.d/opensips restart(重啟)
或者
root@ubuntu:/etc/init.d/opensips start(啟動)
詳情請參考該網頁
2.7 客服端編譯安裝
2.7.1 源代碼的編譯安裝
1) 下載源代碼:源代碼一般以file.tar.gzfile.tar.bz2或file.src.rpm ,用tar jxvf file.tar.bz2 或者tar zxvffile.tar.gz來解壓安裝包
2) 設置編譯環境:安裝gcc;perl; python; glibc; gtk; make; auto make 等開發工具或基礎包。如果您在編 譯軟件時,有時提示缺少什么東西之類的,大多少的是這些開發工具和開發庫等;從光盤中找出安 裝就是了;有時光盤沒有提供,請用 google 搜索相應的軟件包,有時可能也會用到源碼包編譯安 裝所依賴的包; 有時本來系統中已經安裝了所依賴的包,但系統提示找不到應該怎么辦?這時需 要我們設置一下PKG_CONFIG_PATH的環境變量就行了; #export PKG_CONFIG_PATH=/usr/lib/pkgconfig
3) ./cofigure –prefix=/usr/你想要安裝的目錄
4) Make
5) Make install
詳情請參考該網頁
2.7.2 直接安裝rpm安裝包
rpm -i 需要安裝的包文件名