Principy telefonn´ı signalizace SIP Teorie a praxe IP telefonie Skymia s.r.o. Petr Hruˇska
[email protected] 6.12.2012
Historie protokolu SIP
• 1996 prvn´ı pracovn´ı verze • 1999 schv´ aleno RFC 2543 • 2002 schv´ aleno RFC 3261
Standardy • z´ aklad je v RFC 3261 • dalˇ s´ı rozˇs´ıˇren´ı v RFC 3262, 3263, 3264, 3265,
3361, 3581, 3856, ... • stovky str´ anek specifikac´ı • RFC 5411:A Hitchhiker’s Guide to the Session
Initiation Protocol (SIP) (Stopaˇr˚ uv pr˚ uvodce po SIPu )
Co SIP dovede?
Vˇsechno co se t´yk´a signalizace, zejm´ena: • dohled´ an´ı IP telefonu na internetu podle ,,ˇc´ısla” • nav´ az´an´ı v´ıc hovor˚ u jedn´ım vol´an´ım, tzv. vˇetven´ı
Jak SIP vypad´ a?
INVITE sip:
[email protected] SIP/2.0 From: "Jana"<sip:
[email protected]>;tag=Hxfergs To: "Petr"<sip:
[email protected]> Via: SIP/2.0/UDP 10.0.0.1:5060; branch=z9hG4bKx Call-ID:
[email protected] ... Zpr´avy se pˇren´aˇs´ı bud’ jako UDP pakety, nebo pˇres TCP. Standardn´ı port je 5060.
Jak vypad´ a HTTP?
GET /path/file.html HTTP/1.1 Host: www.host1.com:80 • srovnejte
INVITE sip:
[email protected] SIP/2.0
Poˇ zadavky a odpovˇ edi
Poˇzadavek zaˇc´ın´a vˇzdy metodou, napˇr´ıklad INVITE pro nav´az´an´ı hovor˚ u, nebo BYE pro jejich ukonˇcen´ı. Odpovˇed’ obsahuje ˇc´ıseln´y k´od pro stroje a popis pro lidi.
SIP URI
• SIPov´ e adresy typu sip:
[email protected] • SIPov´ a adresa = SIP URI • obdoba telefonn´ıho ˇ c´ısla – d´ate-li nˇekomu svoji
SIPovou adresu, m˚ uˇze v´am zavolat
Transakce
Terminologie Koncov´e zaˇr´ızen´ı z hlediska protokolu SIP je User Agent (UA). V r´amci transakce (poˇzadavek → odpovˇed’) hraje UA bud’ roli klienta (UAC), nebo roli serveru (UAS). UA m˚ uˇze hr´at v´ıce rol´ı z´aroveˇn. Mezilehl´a zaˇr´ızen´ı jsou SIP Proxy. Slouˇz´ı k pˇrepos´ıl´an´ı a smˇerov´an´ı zpr´av. Jejich u´loha je pˇribliˇznˇe obdoba u´lohy routeru v IP komunikaci.
Pˇr´ıklady odpovˇ ed´ı
100 Trying 180 Ringing 200 OK 404 Not Found 603 Declined
provizorn´ı odpovˇed’, potvrzen´ı pˇrijet´ı volan´y telefon vyzv´an´ı kladn´e vyˇr´ızen´ı poˇzadavku volan´e ˇc´ıslo neexistuje odm´ıtnuto uˇzivatelem
Dialog
• dialog je technick´ y term´ın • o nˇ eco ˇsirˇs´ı pojem neˇz hovor • zaˇ c´ın´a s vyzv´anenˇen´ım • konˇ c´ı kdyˇz nikdo nezvedne telefon, nebo UAC
potvrd´ı konec hovoru
Metoda BYE ukonˇ cen´ı hovoru
Ukonˇ cen´ı hovoru
Co mus´ı UA vˇ edˇ et pro zavˇ eˇsen´ı? • kontakt protistrany
[email protected] • seznam mezilehl´ ych router˚ u
2.2.2.2, 3.3.3.3 • ID dialogu – tˇri n´ ahodnˇe vygenerovan´e ˇretˇezce: Call-ID, From tag, To tag • poˇradov´ e ˇc´ıslo poˇzadavku CSeq Pokud tohle (a p´ar dalˇs´ıch ned˚ uleˇzitost´ı) o sobˇe UA navz´ajem vˇed´ı, ˇr´ık´ame, ˇze nav´azaly dialog. S tˇemito informacemi jiˇz lze zkonstruovat poˇzadavek BYE.
BYE BYE sip:
[email protected] SIP/2.0 Max-Forwards: 70 From: "Jana"<sip:
[email protected]>;tag=psvz To: "Petr"<sip:
[email protected]>;tag=bflm Call-ID: 5b063520 User-Agent: YV3/1.0.3 Via: SIP/2.0/UDP 1.1.1.1:5060;rport;br... Route: <sip:2.2.2.2;lr=on> Route: <sip:3.3.3.3;lr=on> Contact: <sip:
[email protected]> Content-Length: 0 CSeq: 13309 BYE
Hlaviˇ cky Route
Loose routing Route: <sip:2.2.2.2;lr=on> Route: <sip:3.3.3.3;lr=on>
• kaˇ zd´y SIP Proxy napˇred odstran´ı prvn´ı poloˇzku • nenajde-li tam sebe, tak nˇ ekdo nedodrˇzel
RFC3261 • zpr´ ava je pˇreposl´ana na prvn´ı poloˇzku zb´yvaj´ıc´ıho seznamu • je-li seznam pr´ azdn´y, je zpr´ava pˇreposl´ana na Request URI
Request URI
BYE sip:
[email protected] SIP/2.0 • URI z prvn´ıho ˇr´ adku • v´ yznam se mˇen´ı podle metody, obecnˇe je to
adres´at poˇzadavku • zpr´ avy v dialogu maj´ı v RURI kontakt protistrany • pouˇ zije se, kdyˇz dojdou hlaviˇcky Route
From a To From: "Jana"<sip:
[email protected]>;tag=psvz To: "Petr"<sip:
[email protected]>;tag=bflm
• kdyby prvn´ı zavˇ esil Petr, byl by ve From m´ısto
Jany • From tag je zkop´ırovan´ y z INVITE • To tag je vygenerovan´ y na stranˇe volan´eho pˇri zpracov´an´ı INVITE • nic jin´ eho neˇz tagy se nepouˇz´ıv´a!
Pˇrepos´ıl´ an´ı
Pˇrepos´ıl´ an´ı
Kdy konˇ c´ı hovor? • praktick´ a ot´azka d˚ uleˇzit´a pro billing • zpr´ avy se pˇrepos´ılaj´ı ˇr´adovˇe po sekund´ach • m˚ uˇze se ztratit poˇzadavek i odpovˇed’ • neexistuje jasn´ a odpovˇed’ • lze definovat jako okamˇ zik odesl´an´ı BYE
(okamˇzik zavˇeˇsen´ı) • v praxi to urˇ cuje br´ana do PSTN
Via
Via slouˇz´ı ke smˇerov´an´ı odpovˇedi
Via
BYE sip:
[email protected] SIP/2.0 From: "Jana"<sip:
[email protected]>;tag=psvz To: "Petr"<sip:
[email protected]>;tag=bflm Via: SIP/2.0/UDP 1.1.1.1:5060;branch=z9hG4bKx Call-ID: 5b063520 ...
Via
BYE sip:
[email protected] SIP/2.0 From: "Jana"<sip:
[email protected]>;tag=psvz To: "Petr"<sip:
[email protected]>;tag=bflm Via: SIP/2.0/UDP 3.3.3.3:5060;branch=z9hG4bKz Via: SIP/2.0/UDP 2.2.2.2:5060;branch=z9hG4bKy Via: SIP/2.0/UDP 1.1.1.1:5060;branch=z9hG4bKx Call-ID: 5b063520 ...
Via
SIP/2.0 200 OK From: "Jana"<sip:
[email protected]>;tag=psvz To: "Petr"<sip:
[email protected]>;tag=bflm Via: SIP/2.0/UDP 3.3.3.3:5060;branch=z9hG4bKz Via: SIP/2.0/UDP 2.2.2.2:5060;branch=z9hG4bKy Via: SIP/2.0/UDP 1.1.1.1:5060;branch=z9hG4bKx Call-ID: 5b063520 ...
Metoda INVITE
Poˇ zadavek s metodou INVITE
Odm´ıtnut´ı hovoru
INVITE INVITE sip:
[email protected] SIP/2.0 From: "Jana"<sip:
[email protected]>;tag=psvz To: "Petr"<sip:
[email protected]> Call-ID: 5b063520 CSeq: 13308 INVITE Contact: <sip:
[email protected]> Max-Forwards: 70 Via: SIP/2.0/UDP 1.1.1.1:5060;rport;br... Allow: INFO,PRACK,INVITE,ACK,OPTIONS,BYE,CANCEL User-Agent: YV3/1.0.3 Supported: 100rel Content-Length: 400 Content-Type: application/sdp
100 Trying
INVITE sip:
[email protected] SIP/2.0 From: "Jana"<sip:
[email protected]>;tag=psvz To: "Petr"<sip:
[email protected]> Contact:
[email protected] Record-Route: <sip:2.2.2.2;lr=on> Via: SIP/2.0/UDP 2.2.2.2:5060;branch=z9hG4bKy Via: SIP/2.0/UDP 1.1.1.1:5060;branch=z9hG4bKx Call-ID: 5b063520 ...
SIP Proxy 2.2.2.2 nen´ı zodpovˇedn´y za b.cz, takˇze zjist´ı IP adresu pro b.cz a pˇrepoˇsle poˇzadavek na 3.3.3.3.
INVITE sip:
[email protected] SIP/2.0 From: "Jana"<sip:
[email protected]>;tag=psvz To: "Petr"<sip:
[email protected]> Contact:
[email protected] Record-Route: <sip:3.3.3.3;lr=on> Record-Route: <sip:2.2.2.2;lr=on> Via: SIP/2.0/UDP 3.3.3.3:5060;branch=z9hG4bKz Via: SIP/2.0/UDP 2.2.2.2:5060;branch=z9hG4bKy ...
SIP Proxy 3.3.3.3 je zodpovˇedn´y za b.cz, takˇze zn´a IP adresu UA
[email protected]. Pˇrep´ıˇse Request-URI a pˇrepoˇsle poˇzadavek na 4.4.4.4.
Record-Route SIP/2.0 200 OK From: "Jana"<sip:
[email protected]>;tag=psvz To: "Petr"<sip:
[email protected]>;tag=bflm Contact:
[email protected] Record-Route: <sip:3.3.3.3;lr=on> Record-Route: <sip:2.2.2.2;lr=on> Via: SIP/2.0/UDP 3.3.3.3:5060;branch=z9hG4bKz ...
Hlaviˇcky Record-Route se zkop´ıruj´ı do odpovˇedi u´plnˇe stejnˇe jako Via. Narozd´ıl od Via ale projdou k volan´emu nepozmˇenˇen´e.
M´ edia
SIPov´ y lichobˇ eˇ zn´ık
SDP
Content-Length: 400 Content-Type: application/sdp • d´ elka a form´at dat za hlaviˇckami zpr´avy • SDP = Session Description Protocol • RFC 2327, upˇresnˇ en´ı pro SIP v RFC 3264
INVITE sip:
[email protected] SIP/2.0 To: "291914320"<sip:
[email protected]> Accept: application/dtmf-relay,application/sdp,text/plain,application/sip User-Agent: YV3/1.0.3 Via: SIP/2.0/UDP 10.27.105.76:5060;rport;branch=z9hG4bK46d759a5 From: "phru8648"<sip:
[email protected]>;tag=4e128660 Allow: UPDATE,INFO,PRACK,MESSAGE,REFER,NOTIFY,INVITE,ACK,OPTIONS,BYE,CANCEL Allow-Events: talk,hold,refer Call-ID:
[email protected] Max-Forwards: 70 Contact: <sip:
[email protected]:5060> Session-Expires: 1800 Content-Length: 400 Content-Type: application/sdp Supported: timer,100rel,join,tdialog,replaces,norefersub,histinfo CSeq: 32437 INVITE v=0 o=ipr1B240EF4FD 13756244 13756244 IN IP4 1.1.1.1 s=c=IN IP4 1.1.1.1 t=0 0 m=audio 8010 RTP/AVP 0 8 104 2 105 18 4 101 a=rtpmap:0 PCMU/8000 a=rtpmap:8 PCMA/8000 a=rtpmap:104 G726-32/8000 a=rtpmap:2 G721/8000 a=rtpmap:105 G726-40/8000 a=rtpmap:18 G729/8000 a=rtpmap:4 G723/8000 a=rtpmap:101 telephone-event/8000 a=ptime:20 a=fmtp:101 0-16 a=fmtp:4 ptime=30;bitrate=6.3
Form´ at SDP
v=0 o=ipr1B240EF4FD 13756244 13756244 IN IP4 1.1.1.1 s=• v= verze protokolu • o= originator (kdo to zaloˇ zil) • s= jm´ eno session, doporuˇceno s=-
Form´ at SDP
c=IN IP4 1.1.1.1 t=0 0 • c= adresa (connection information) • t= ˇ cas, zaˇc´atek a konec session (pro SIP je
doporuˇceno pouˇz´ıvat t=0 0)
Form´ at SDP m=audio 8010 RTP/AVP 0 8 104 2 105 18 4 101 • m= media stream • media port transport fmt-list • zaˇ c´ın´a sekci s parametry streamu • v SDP nab´ıdce m˚ uˇze b´yt v´ıce stream˚ u, klient
m˚ uˇze libovoln´y z nich odm´ıtnout • v SDP odpovˇ edi mus´ı b´yt pˇresnˇe stejn´y poˇcet m= sekc´ı, odm´ıtnut´ı se provede nastaven´ım portu na hodnotu 0
Form´ at SDP m=audio 8010 RTP/AVP 0 8 104 2 105 18 4 101 a=rtpmap:0 PCMU/8000 a=rtpmap:8 PCMA/8000 • a=rtpmap urˇ cuje parametry rtp kodeku • poˇrad´ı kodek˚ u ve fmt-list odpov´ıd´a
preferenci, nev´ıce preferovan´y kodek je na zaˇc´atku • protistrana si m˚ uˇze vybrat libovoln´y kodek a dokonce m˚ uˇze bˇehem hovoru kodeky libovolnˇe stˇr´ıdat
SDP odpovˇ ed’
• mus´ı obsahovat alespoˇ n jeden nab´ızen´y kodek • m˚ uˇze obsahovat i kodeky, kter´e nebyly
nab´ıdnuty • opˇ et plat´ı, ˇze protistrana si jeden z kodek˚ u vybere • kaˇ zd´ym smˇerem m˚ uˇze b´yt pouˇzit´y jin´y kodek
Registrace
Proˇ c registrace?
• SIP Proxy zodpovˇ edn´y za dom´enu mus´ı m´ıt
kontakty na telefony jednotliv´ych uˇzivatel˚ u • registrace umoˇ znˇuje telefon˚ um nastavit, zmˇenit, nebo zjistit seznam kontakt˚ u pro SIP URI uˇzivatele
Poˇ zadavek na registraci
REGISTER sip:b.cz SIP/2.0 To: "Petr"<sip:
[email protected]> From: "Petr"<sip:
[email protected]>;tag=484d Call-ID: Acu1Ey1m Max-Forwards: 70 Expires: 3600 CSeq: 2855 REGISTER Contact: <sip:
[email protected]:5060> Via: SIP/2.0/UDP 4.4.4.4:5060;branch=z9hG4bKx Content-Length: 0
To
To: "Petr"<sip:
[email protected]> • terminologie: Address Of Record (AOR) • pro koho se nastavuj´ı kontakty • dom´ ena by mus´ı b´yt ,,validn´ı” vzhledem k
prvn´ımu ˇr´adku
From
From: "Petr"<sip:
[email protected]>;tag=4sxh • SIPov´ a adresa osoby odpovˇedn´e za registraci • registrace m˚ uˇze b´yt provedena tˇret´ı stranou • tag pro metodu REGISTER nem´ a vyuˇzit´ı
Contact Contact: <sip:
[email protected]:5060> • seznam oddˇ elen´y ˇc´arkami • bylo-li uˇ z SIP URI na serveru registrov´ano, je
upravena doba jeho platnosti • nebylo-li registrov´ ano, je pˇrid´ano • kontakty nemus´ı b´ yt jen SIP URI, ale tˇreba i http apod. • m˚ uˇze obsahovat libovoln´y poˇcet kontakt˚ u (i nulov´y)
´ eˇsn´ Uspˇ a registrace
Ne´ uspˇ eˇsn´ a registrace
Autorizace • server by mˇ el pˇri prvn´ım pokusu vygenerovat
n´ahodn´y ˇretˇezec, tzv. nonce • klient nonce pouˇ zije pro zahashov´an´ı hesla a tento hash vloˇz´ı do zpr´avy v druh´em pokusu • odposlechnut´ı komunikace nelze pouˇ z´ıt pro podvrˇzen´ı registrace, protoˇze u´toˇcn´ık dostane jin´y nonce
Pˇr´ıklad odpovˇ edi
SIP/2.0 401 Unauthorized Via: SIP/2.0/UDP 4.4.4.4:5060;branch=z9hG4bKx From: "Petr"<sip:
[email protected]>;tag=4sxh To: "Petr"<sip:
[email protected]>;tag=defz Call-ID: Acu1Ey1m CSeq: 2855 REGISTER WWW-Authenticate: Digest realm="b.cz", nonce="472756e67" Server: Kamailio Content-Length: 0
Autorizace
Authorization: Digest username="petr", realm="b.cz", nonce="472756e67", uri="sip:b.cz", response= "febdf1317568b7a914afb4a71d0fa703", algorithm=MD5
Odpovˇ ed’ na REGISTER
SIP/2.0 200 OK Via: SIP/2.0/UDP 4.4.4.4:5060;branch=z9hG4bKx From: "Petr"<sip:
[email protected]>;tag=484d To: "Petr"<sip:
[email protected]>;tag=4sdc Call-ID: Acu1Ey1m CSeq: 2856 REGISTER Contact: <sip:
[email protected]:5060>;expires=120 Server: Kamailio Content-Length: 0
Autorizace pˇri INVITE
Dˇekuji za pozornost
[email protected]