SIP SUBSCRIBE NOTIFY

From 탱이의 잡동사니
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Overview

원문은 이곳<ref>http://www.nexpert.net/147</ref>에서 확인할 수 있다.

SUBSCRIBE/NOTIFY

이벤트에 대한 통지 요청을 하고, 이에 대한 응답을 받는 다는 것은 다양한 SIP 응용 서비스에서 유용하다. RFC 3265 SIP-Specific Event Notification 에 다음과 같은 SIP 응용 서비스를 예로 들고 있다.

  • Automatic Callback Service(자동 콜백 서비스)
특정 단말의 상태정보를 알 수 있도록 호가 종료되었을 때, 상태 정보가 SIP 서비스로 통지(Notification)된다면, 바로 콜백이 이루어질 것이다. 콜백 서비스는 상대방이 부재중이거나 통화중일 때 송신자가 콜백 서비스를 신청해 놓으면, 상대방의 상태 변화가 감지되자마자 자동으로 통화가 되도록 하는 것이다.
  • Buddy List(친구 목록)
버디 리스트에 등록된 친구 또는 동료의 상태정보가 실시간으로 통지되어 메신저와 같은 서비스를 편리하게 사용한다.
  • MWI (Message Waiting Indication)
음성사서함의 상태 변화 이벤트가 실시간으로 전화 또는 메신저에 통지되어 음성 사서함의 저장된 음성을 들을 수 있다.
  • PINT (PSTN and Internet Internetworking)
PINT 에서도 호 상태 정보를 통한 서비스가 가능하다.

이러한 SIP 응용 서비스는 SUBSCRIBE와 NOTIFY 메소드를 활용한다.

Dialog

Sip sub noti dialog.png

Subscribe는 메신저 서버, UA 등 다양한 형태가 될 것이며, Notifier는 Register 서버 또는 UA 이다. 여기서 SUBSCRIBE와 NOTIFY가 언제 생성되는지 알아보자. SUBSCRIBE 메소드는 Subscriber가 특정 사용자의 현재의 상태와 상태 정보 업데이트를 요청하여 향후의 이벤트 발생 시에 통지해 줄 것을 요청하는 것이다. 또한 Notify는 SUBSCRIBE에 의해 요청된 이벤트 발생시 통지하거나, Subscription (신청)된 단말의 상태 변화를 Subscriber에게 통지한다.

SUBSCRIBE 메시지 분석

이제 패킷을 분석해보자. 최초 Subscriber가 Notifier 에게 SUBSCRIBE 요청을 한다.

SUBSCRIBE sip:alice@atlanta.com SIP/2.0
Via: SIP/2.0/TCP app_IM.atlanta.com;branch=z9hG4bKnashds7
From: sip:app_IM.atlanta.com ;tag=123aa9
To: sip:alice@atlanta.com
Call-ID: 9987@app_IM.atlanta.com
CSeq: 9887 SUBSCRIBE
Contact: sip:app_IM.atlanta.com
Event: reg
Max-Forwards: 70
Expires: 21600
Accept: application/reginfo+xml

위의 SUBSCRIBE 요청에서 관심있게 보아야 할 것은 다음과 같다.

  • Event: reg
SUBSCRIBE 요청에 이벤트가 포함되어야 한다. 이벤트는 앨리스의 등록 상태 정보를 요청하는 것이다.
  • Expires: 21600
SUBSCRIBE 요청에 이 헤더가 포함되어야 하며, 이 요청의 유효 기간을 명시한다. 유효 기간 만료 전에 같은 다이얼로그(같은 Call-ID)로 SUBSCRIBE를 주기적으로 생성해야 한다. 만일 Expires:0 으로 설정한다면, Unsubscribe 를 요청하는 것이다.

위의 SUBSCRIBE 메시지가 SIP Registrar 서버에 요청이 된 후 아래와 같이 200 OK 메시지가 전송된다.

SIP/2.0 200 OK
Via: SIP/2.0/TCP app_IM.atlanta.com;branch=z9hG4bKnashds7 ; received=10.1.3.2
From: sip:app_IM.atlanta.com ;tag=123aa9
To: sip:alice@atlanta.com ; tag=xyzygg
Call-ID: 9987@app_IM.atlanta.com
CSeq: 9887 SUBSCRIBE
Contact: sip:server19.atlanta.com
Expires: 3600

200 OK 에서 Expires:3600 으로 보내졌다. 기존의 요청된 유효기간보다 매우 짧은 3600초 동안만 Registration 상태 정보에 대해 통지하겠다는 의미이다. 이제 Notifier 에 의해 Accept 되었으므로 엘리스의 등록 상태 정보의 변화는 Subscriber 에게 한 시간 동안 통지될 것이다. 앨리스가 등록되어 있음을 NOTIFY 메소드를 이용하여 보낸다.

NOFITY sip:app_IM.atlanta.com SIP/2.0
Via: SIP/2.0/TCP server1.atlanta.com;branch=z9G4bKnasaii
From: sip:alice@atlanta.com ;tab=xyzygg
To: sip:app_IM.atlanta.com ;tag=123aa9
Max-Forwards: 70
Call-ID: 9987@app_IM.atlanta.com
CSeq:1288 NOTIFY
Contatct: sip:server19.atlanta.com
Event: reg
Subscription-State: active
Content-Type: application/reginfo+xml
Content-Length: 223
<?xml version="1.0"?>
  <reginfo xmlns="urn:ietf:params:xml:ns:reginfo" version="0" state="full">
    <registration aor="sip:alice@atlanta.com" id="a7" state="init" />
  </reginfo>

reginfo+xml 메시지에서 앨리스의 등록 상태가 init라고 표기하고 있다. 여기서 Subscription-State 헤더를 살펴보자. 이름에서 알 수 있듯이, Subscription 에 대한 상태 정보를 나타낸다.

  • Active
Subscription 은 Accepted 및 Authorized 되었음을 의미한다.
  • Pending
Notifier가 Subscription을 수령했지만, 불충분한 정책정보로 인해 숭인 또는 거절 여부를 아직 결정하지 못함을 의미한다.
  • Terminated
Subscription이 종료되었음을 의미. Expires 유효기간이 만료되었을 수도 있으며, 사유가 명기된다.

Registration State Machine

RFC 3680 SIP Event Package for Registrations 에 따른 등록 상태의 변화에 대해 살펴보자. 아래 그림은 등록 상태 변화를 도식화 한 것이다.

Sip registration state.png

위 과정을 이해하기 위해 다시한번 SIP Registration 을 짚어보자. SIP 에서 Registration 이란 Contact Address 와 Address-of-record를 바인딩하는 것이다. 여기서 Contact Address는 AoR에 의한 식별된 사용자에게 연결되기 위한 실제 단말의 주소라고 할 수 있다. 이러한 일련의 과정을 위해 User Agent가 SIP REGISTER 메소드를 이용한다.

다음은 등록 상태 변화를 나타낸 것이다.

  • Init
Address-of-record 에 등록된 Contact 이 없는 상태. 즉, 도메인에 등록된 사용자이나 통화하기 위한 Contact 주소가 확보되지 않았음을 의미한다.
  • Active
하나 이상의 Contact address가 바인딩 된 상태이다.
  • Terminated
더 이상의 Contact address가 존재하지 않는 상태로 바로 Init 상태로 전환된다.

User Presence & Registration State

등록 상태 정보는 사용자 상태 정보(Presence)와는 틀린 것이다. 사용자 상태 정보는 사용자가 지금 망에서 다른 사용자와 통화할 수 있는지를 의미하며, 사용자와 연결하기 위한 다양한 통신 수단을 나타내는 Contact address 의 집합을 나타낸다. 등록 상태 정보는 사용자와 연결하기 위한 Contact address가 존재하는 지를 나타내는 것이다. 즉, 사용자 상태 정보를 알기 위해서는 등록 상태 정보라는 Raw 데이터가 필요하게 되는 것이다.

Welcome Notice 서비스 예제

RFC 3680 SIP Event Package for Registration에는 등록 상태 정보를 이용한 몇 가지 시나리오가 있다. 이 중에서 RFC 3680의 Welcome Notice 서비스 예제를 살펴보자. Welcome Notice는 현재 일반적으로 사용되는 것으로 사용자가 로밍폰으로 외국에서 전화기를 켜면, 사용자의 단말이 Welcome to the country 메시지를 받게된다. 이의 호 절차는 다음과 같다.

Sip welcome to country.png

Application은 특정 사용자 (Joe)의 등록 상태 정보를 요청하기 위해 Notifier로 동작하는 Registrar 서버에 SUBSCRIBE를 아래와 같이 전달한다.

SUBSCRIBE sip:joe@example.com SIP/2.0
Via: SIP/2.0/UDP app.example.com;branch=z9hG4bKnashds7
From: sip:app.example.com;tag=123aa9
To: sip:joe@example.com
Call-ID: 9987@app.example.com
CSeq: 9887 SUBSCRIBE
Contact: sip:app.excample.com
Event: reg
Max-Forwards: 70
Accept: application/reginfo+xml

Registrar는 아래와 같이 200 OK를 통해 3600초 동안 Joe의 등록 상태 정보를 보내겠다고 한다.

SIP/2.0 200 OK
Via: SIP/2.0/UDP app.example.com;branch=z9hG4bKnashds7;received=192.0.2.1
From: sip:app.example.com;tag=123aa9
To: sip:joe@example.com;tag=xyzygg
Call-ID: 9987@app.example.com
CSeq: 9987 SUBSCRIBE
Contact: sip:server19.example.com
Expires: 3600

Registrar는 200 OK를 전송한 후, Joe의 현재 등록 상태를 Application 에 NOTIFY 메소드를 통해 아래와 같이 전달한다. reginfo+xml 포멧으로 된 Joe의 등록상태는 Init이다. 즉, 사용자의 등록정보는 있되, Contact Address가 아직 업데이트 되어 있지는 않다는 것이다.

NOTIFY sip:app.example.com SIP/2.0
Via: SIP/2.0/UDP server19.example.com;branch=z9hG4bKnasaii
From: sip:joe@example
To: sip:app.example.com;tag=123aa9
Call-ID: 9987@app.example.com
CSeq: 1288 NOTIFY
Contact: sip:server19.example.com
Event: reg
Max-Forwards: 70
Content-Type: application/reginfo+xml
Content-Length: ...
<?xml version="1.0"?>
  <reginfo xmlns="um:ietf:params:xml:ns:reginfo" version="0" state="full">
    <registration aor="sip:joe@example.com" id="a7" state="init" />
  </reginfo>

Joe는 로밍지역에서 전화기의 전원을 켜게되면, 아래와 같은 등록 메시지가 전달된다.

REGISTER sip:example.com SIP/2.0
Via: SIP/2.0/UDP server19.example.com;branch=z9hG4bKnasaii
From: sip:joe@example.com;tag=xyzygg
To: sip:app.example.com;tag=123aa9
Call-ID: 9987@app.example.com
CSeq: 1289 NOTIFY
Contact: sip:server19.example.com
Event: reg
Max-Forwards: 70
Content-Type: application/reginfo+xml
Content=Length: ...
<?xml version="1.0"?>
  <reginfo xmlns="um:ietf:params:xml:ns:reginfo" version="1" state="partial">
    <registration aor="sip:joe@example.com" id="a7" state="active">
      <contact id="76" state="active" event="registered" duration-registered="0">
        <uri>sip:joe@pc34.example.com</uri>
      </contact>
    </registration>
  </reginfo>

아래와 같이 Welcome to the example.com service! 라는 메시지가 전송된다.

MESSAGE sip:joe@pc34.example.com SIP/2.0
Via: SIP/2.0/UDP app.example.com;branch=z9hG4bKnashds8
From: sip:app.example.com;tag=123aa10
To: sip:joe@example.com
Call-ID: 9988@app.example.com
CSeq: 82779 MESSAGE
Max-Forwards: 70
Content-Type: text/plain
Content-Length: ...

Welcome to the example.com service!

References

<references />