วันเสาร์ที่ 28 กรกฎาคม พ.ศ. 2555

Install OpenSBC - CentOS edition


#/bin/sh
#Install OpenSBC - CentOS edition
#Copyright (C) 2010 Star2Billing S.L.
#Author Jonathan Roper jonathan@star2billing.com

#This program is free software; you can redistribute it and/or
#modify it under the terms of the GNU General Public License
#as published by the Free Software Foundation; either version 2
#of the License, or (at your option) any later version.

#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.

#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

#==================================================================================================
#This script will install OpenSBC on an existing asterisk server, and will be available on port 5061
#It will provide upwards registration, and RTP proxy services.
#No configuration in Asterisk is required.
#Simply point your phone at <<IPADDR>>:5061
#If this is installed behind NAT, forward UDP 5061 and 10,000 > 20,000
#==================================================================================================

yum -y install expat expat-devel flex bison cvs

cd /usr/src

echo "================================================================================"
echo "When prompted for a CVS password, just press enter"
echo "================================================================================"


cvs -d:pserver:anonymous@opensipstack.cvs.sourceforge.net:/cvsroot/opensipstack login
cvs -z3 -d:pserver:anonymous@opensipstack.cvs.sourceforge.net:/cvsroot/opensipstack co -P opensipstack
cvs -z3 -d:pserver:anonymous@opensipstack.cvs.sourceforge.net:/cvsroot/opensipstack co -P opensbc

cd /usr/src/opensipstack/
chmod +x ./configure
./configure
make bothnoshared
cd ../opensbc
chmod +x ./configure
./configure
make bothnoshared
make distrib


cp /usr/src/opensbc/distrib/* /usr/local/bin/
echo "./opensbc -d -p /var/run/opensbc.pid -H 65536 -C 1024000" > /usr/local/bin/startup.sh
echo "./opensbc -k -p /var/run/opensbc.pid" > /usr/local/bin/shutdown.sh

echo "/usr/local/bin/opensbc -u root -d -p /var/run/opensbc.pid -H 65536 -C 1024000"  >> /etc/rc.d/rc.local

mkdir /root/OpenSIPStack
mkdir /root/OpenSIPStack/OpenSBC_data


echo "
[OpenSBC-General-Parameters]
SIP-Log-Level=1
PTRACE-Log-Level=1
Log-File-Prefix=b2bua
SBC-Application-Mode=B2BUpperReg Mode
Enable-Trunk-Port=True
Enable-Calea-Port=True
RTP-Min-Port=10000
RTP-Max-Port=20000
NAT-Keep-Alive-Interval=15
Send-OPTIONS-NAT-Keep-Alive=True
Send-Responses-Using-New-Socket=False
Enable-Local-Refer=False
Disable-Refer-Optimization=True
Max-Forwards=70
Encryption-Mode=XOR
Encryption-Key=GS
Alerting-Timeout=30000
Seize-Timeout=60000
SIP-Timer-B=Default
SIP-Timer-H=Default
Session-Keep-Alive=1800
Session-Max-Life-Span=10800
Max-Concurrent-Session=100
Max-Call-Rate-Per-Second=10

[SIP-Transports]
Main-Interface-Address Array Size=1
Main-Interface-Address 1=sip:*:5061
Backdoor-Interface-Address=sip:*:5062
Trunk-Interface-Address=sip:*:5064
Media-Server-Interface-Address=sip:*:5066
CALEA-Interface-Address=sip:*:5068
Auxiliary-Interface-Address=sip:*:5070
Interface-Route-List Array Size=0

[RTP-Proxy]
Proxy-On-Private-Contact=True
Proxy-On-via-received-vs-signaling-address=True
Proxy-On-Private-Via=True
Proxy-On-Different-RPORT=True
Proxy-All-Media=False

[Trusted-Domains]
Accept-All-Calls=True
Trusted-Domain-List Array Size=0
X-Remote-Info-List Array Size=0

[Host-Access-List]
Trust-All-Hosts=True
Trusted-Host-List Array Size=0
Enable-Selective-Banning=True
Banned-Host-List Array Size=0

[Upper-Registration]
All-Reg-As-Upper-Reg=True
Enable-Stateful-Reg=False
Rewrite-TO-Domain=True
Rewrite-FROM-Domain=True
Route-List Array Size=1
Route-List 1=[sip:*] sip:127.0.0.1:5060

[B2BUA-Routes]
Route-List Array Size=1
Route-List 1=[sip:*] sip:127.0.0.1:5060
Insert-Route-Header=True
Rewrite-TO-URI=True
Prepend-ISUP-OLI=False
Route-By-Request-URI=False
Route-By-To-URI=False
Drop-Routes-On-p-i-n-g-Timeout=False
Use-External-XML=False
External-XML-File=b2bua-route.xml

" > /root/OpenSIPStack/OpenSBC_data/OpenSBC.ini


echo "================================================================================"
echo "The web interface for this is on <<ipaddress>:9999"
echo "By default it has no password on it"
echo "After reboot, please go to the website and configure a username and password"
echo "================================================================================"
echo "Please reboot the Asterisk Switch"
echo "================================================================================"

Open Source SBC – Is there such a thing?


Session Border Controllers (SBCs) are utilized as a means to providing both load balancing and security structures for VoIP networks. To be completely honest, 90% of my customers utilize SBC appliances, be it Acme Packet, Juniper, NexTone or others.
According to a report by Transnesus, a combination of OpenSER and Asterisk can be utilized as a Back-To-Back-User-Agent (B2BUA) structure – however, the general configuration and setup isn’t clear and straight forward. I’ve been thinking to myself: “Why hadn’t anyone written and Open Source SBC? could it be? usually there’s an Open Source alternative to any commercial product”.
Like any other search on the net, I’ve pointed my Firefox to Google, and typed the phrase “Open Source SBC”, aparently, such a thing exists from a company called Solegy – over at the web address:http://www.opensourcesip.org. So, I downloaded the source code, and after a 30 minute compilation phase (bearing in mind working on a Virtual server running under VMWARE Server) – the compilation completed.
Compiling was one thing, running it was a completely different thing – took me a while to realize where the binary is located and how the configuration works out – once I did that was a breeze. On my system, after compilation the binary was located according to the following:
[root@opensbc obj_linux_x86_r]# pwd
/root/OpenSBC-1.1.5-RC1-Bundle/opensbc/obj_linux_x86_r
[root@opensbc obj_linux_x86_r]# ./opensbc -x

Message from syslogd@ at Thu Nov 13 23:15:35 2008 ...
tvms OpenSBC[18900]: Starting service process "OpenSBC" v1.1.5-25
Per the information provided by Solegy, the OpenSBC project supports several modes of operations, ranging according to the following:
Full Mode - By default OpenSBC runs in full mode exposing its capability both as a
relay SIP proxy, Registrar and as a B2B User Agent. When OpenSBC receives an INVITE
or a REGISTER request it would follow the following procedure to make a decision how
to route a request:

● If the Request-URI resolves to a remote domain, the request will be relayed. If a
relay route is available, the request is sent to that route. If a relay route is not
available, then the URI is resolved via DNS.
● If the Startline-URI resolves as a local address and port, the To URI is checked
if it resolves to a local domain and port. If not, the request would be proxied
using Relay Routes or via DNS resolution. The Request URI would be rewritten to point
to the resolved route.
● INVITE: If both Request URI and To URI resolves to a local listener and port, the
B2BUA Route is used to route the INVITE.
● REGISTER: If both Request URI and To URI resolves to a local listener and port, the
local Registrar will process the registration. This would include Authorization of
the user.

B2BOnly Mode - This mode removes the relay capability but exposes the Registrar and
the B2BUA functionalities. This mode does not do the checks performed by Full Mode. It
will always process REGISTER and INVITE as local.

● INVITE: This mode always use B2BUA Route to route calls. If there is not corresponding
route found, a DNS resolutions is done against the Request URI or the To URI in case the
Request-URI resolves to a local address.
● REGISTER: Registrations are always handled by the local registrar.

Proxy Only Mode - This mode removes the B2BUA functionality but exposes Registrar and the
relay SIP Proxy functionalities
● Always uses Relay Routes for all messages including REGISTER. If a relay route is not
configured, Requests will be relayed using DNS resolution. If a registrations is resolved
as local, the registrar would handle the registration including authorization

B2BUpperReg Mode - This is almost the same as the B2BOnly mode but with the additional
capability of relaying registrations to upper registrars.

● INVITE: This mode always uses B2BUA Route.
● REGISTER: For registrations, it performs the Request URI and To URI checking and relay
for a remote domain or process the registration locally for local domains.
● Upper-Registration: This mode also has the capability to hijack-registrations towards
upstream registrars.
Per the above, I didn’t completely understand what I should use for normal IP phones operations, so, I guess I’m more or less on my own on this one. My general understanding says that I need to use the B2BupperReg mode, however, I can’t say I’m totally sure about it – I’ll be experimenting with OpenSBC and the virtual Asterisk servers i’ve written before over the couple of months.

Ballistic-PBX / install-opensbc-ubuntu.sh


#!/bin/bash
#OpenSBC Debian

#/bin/sh
#Install OpenSBC - CentOS edition
#Copyright (C) 2010 Star2Billing S.L.
#Author Jonathan Roper jonathan@star2billing.com

#This program is free software; you can redistribute it and/or
#modify it under the terms of the GNU General Public License
#as published by the Free Software Foundation; either version 2
#of the License, or (at your option) any later version.

#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.

#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

#==================================================================================================
#This script will install OpenSBC on an existing asterisk server, and will be available on port 5061
#It will provide upwards registration, and RTP proxy services.
#No configuration in Asterisk is required.
#Simply point your phone at <<IPADDR>>:5061
#If this is installed behind NAT, forward UDP 5061 and 10,000 > 20,000
#==================================================================================================

apt-get update

apt-get install -y mc autoconf automake cvs flex expat libexpat1-dev libtool build-essential libxml2 libxml2-dev libtiff4 libtiff4-dev libssl-dev libncurses5-dev bison libaudiofile-dev subversion libnewt-dev libcurl3-dev libnet-ssleay-perl openssl ssl-cert libauthen-pam-perl libio-pty-perl libcrypt-passwdmd5-perl libdigest-md5-perl libpg-perl libdbd-pg-perl openssl ssl-cert flex bison build-essential libxml2 libxml2-dev expat libexpat1-dev libspeex-dev speex


cd /usr/src

echo "================================================================================"
echo "When prompted for a CVS password, just press enter"
echo "================================================================================"


cvs -d:pserver:anonymous@opensipstack.cvs.sourceforge.net:/cvsroot/opensipstack login
cvs -z3 -d:pserver:anonymous@opensipstack.cvs.sourceforge.net:/cvsroot/opensipstack co -P opensipstack
cvs -z3 -d:pserver:anonymous@opensipstack.cvs.sourceforge.net:/cvsroot/opensipstack co -P opensbc

cd /usr/src/opensipstack/
chmod +x ./configure
./configure --enable-localspeex --enable-gpllibs
make bothnoshared
cd ../opensbc
chmod +x ./configure
./configure --enable-gpllibs
make bothnoshared
make distrib


cp /usr/src/opensbc/distrib/* /usr/local/bin/
echo "/usr/local/bin/opensbc -d -p /var/run/opensbc.pid -H 65536 -C 1024000" > /usr/local/bin/startup.sh
echo "/usr/local/bin/opensbc -u root -k -p /var/run/opensbc.pid" > /usr/local/bin/shutdown.sh

echo "/usr/local/bin/startup.sh"  >> /etc/rc.local

mkdir /root/OpenSIPStack
mkdir /root/OpenSIPStack/OpenSBC_data


echo "
[OpenSBC-General-Parameters]
SIP-Log-Level=1
PTRACE-Log-Level=1
Log-File-Prefix=b2bua
SBC-Application-Mode=B2BUpperReg Mode
Enable-Trunk-Port=True
Enable-Calea-Port=True
RTP-Min-Port=10000
RTP-Max-Port=20000
NAT-Keep-Alive-Interval=15
Send-OPTIONS-NAT-Keep-Alive=True
Send-Responses-Using-New-Socket=False
Enable-Local-Refer=False
Disable-Refer-Optimization=True
Max-Forwards=70
Encryption-Mode=XOR
Encryption-Key=GS
Alerting-Timeout=30000
Seize-Timeout=60000
SIP-Timer-B=Default
SIP-Timer-H=Default
Session-Keep-Alive=1800
Session-Max-Life-Span=10800
Max-Concurrent-Session=100
Max-Call-Rate-Per-Second=10

[SIP-Transports]
Main-Interface-Address Array Size=1
Main-Interface-Address 1=sip:*:5061
Backdoor-Interface-Address=sip:*:5062
Trunk-Interface-Address=sip:*:5064
Media-Server-Interface-Address=sip:*:5066
CALEA-Interface-Address=sip:*:5068
Auxiliary-Interface-Address=sip:*:5070
Interface-Route-List Array Size=0

[RTP-Proxy]
Proxy-On-Private-Contact=True
Proxy-On-via-received-vs-signaling-address=True
Proxy-On-Private-Via=True
Proxy-On-Different-RPORT=True
Proxy-All-Media=False

[Trusted-Domains]
Accept-All-Calls=True
Trusted-Domain-List Array Size=0
X-Remote-Info-List Array Size=0

[Host-Access-List]
Trust-All-Hosts=True
Trusted-Host-List Array Size=0
Enable-Selective-Banning=True
Banned-Host-List Array Size=0

[Upper-Registration]
All-Reg-As-Upper-Reg=True
Enable-Stateful-Reg=False
Rewrite-TO-Domain=True
Rewrite-FROM-Domain=True
Route-List Array Size=1
Route-List 1=[sip:*] sip:127.0.0.1:5060

[B2BUA-Routes]
Route-List Array Size=1
Route-List 1=[sip:*] sip:127.0.0.1:5060
Insert-Route-Header=True
Rewrite-TO-URI=True
Prepend-ISUP-OLI=False
Route-By-Request-URI=False
Route-By-To-URI=False
Drop-Routes-On-Ping-Timeout=False
Use-External-XML=False
External-XML-File=b2bua-route.xml

" > /root/OpenSIPStack/OpenSBC_data/OpenSBC.ini


echo "================================================================================"
echo "The web interface for this is on <<ipaddress>:9999"
echo "By default it has no password on it"
echo "After reboot, please go to the website and configure a username and password"
echo "================================================================================"
echo "Please reboot"
echo "================================================================================"


echo "
1. http://11.22.33.44:9999/Internal-DNS-Mapping

This is where we create the DNS entries for the internal IP addresses, this not compulsory, but it does make admin easier.

So assuming you have pbx.yourdomain.com on 192.168.1.101, 

Create a DNS entry on your DNS server for pbx.yourdomain.com = 11.22.33.44
Now add the internal DNS mapping with [sip:pbx.yourdomain.com] sip:192.168.1.101:5060
Click the update button.
Repeat as necessary for all PBX systems.

2. http://11.22.33.44:9999/Upper-Registration

Next we need to deal with the registration aspect, so that when you create an extension on a PBX, OpenSBC checks to see that it is valid.

Edit Route list, and add entries for each of your PBX systems.
[sip:*@pbx.yourdomain.com:*] sip:pbx.yourdomain.com:5060

or if you have not bothered with Step one - [sip:*@pbx.yourdomain.com:*] sip:192.168.1.101:5060 

Then click the update button

So registrations that are sent to pbx.yourdomain.com will be forwarded to the internal PBX, and if the username and password is correct, OpenSBC will allow the endpoint to register. Note that the endpoint must be configured with the hostname, e.g. pbx.yourdomain.com, NOT 11.22.33.44

Repeat as necessary for all PBX systems.

3. http://11.22.33.44:9999/B2BUA-Routes

This is how the call is actually routed when someone picks up the phone and makes a call.

The syntax here is the same as in step 2 for upper registration, e.g.Edit Route list, and add entries for each of your PBX systems.

[sip:*@pbx.yourdomain.com:*] sip:pbx.yourdomain.com:5060

or if you have not bothered with Step one - [sip:*@pbx.yourdomain.com:*] sip:192.168.1.101:5060

Then click the update button.


4. Register your endpoint 

Now attempt to register a phone to your extension@pbx.yourdomain.com and make a call.

5. DID forwarding

To forward DID to your systems from your DID provider or A2Billing system, simply forward the DID to sip/DID-Number@pbx.yourdomain.com


Please test and test again, particularly in respect of MWI lights, extension to extension calls and check that it does what you need it do.
" > /root/OpenSIPStack/README

Vyatta with OpenSBC Install


Wednesday, December 31, 2008

Finally got pointed in the right direction with Vyatta and OpenSBC by Joegen (the main developer over at OpenSipStack.org). Here are my install notes for OpenSBC on Vyatta.

Install OpenSBC on Vyatta Firewall


Install Vyatta:

Boot from Vyatta LiveCD ISO. Press ENTER.

At login, username 'root', password 'vyatta'.

Enter 'install-system'

Configure as needed... I'll share mine when I get this all working...


Get items required for building OpenSBC (kitchen sink approach):

Login to Firewall as user 'vyatta'

cd /etc/apt

su

Password: (enter root password)

nano -w sources.list

Add line: "deb ftp://ftp.us.debian.org/debian/ lenny main contrib non-free"

Ctrl-X and Y to overwrite

apt-get update

apt-get install -y mc autoconf automake cvs flex expat libexpat1-dev libtool build-essential libxml2 libxml2-dev libtiff4 libtiff4-dev php5 php5-cli php5-mysql php5 php5-cli php5-mysql php5-gd mysql-server libmysqlclient15-dev php-pear php-db curl sox apache2 libssl-dev libncurses5-dev bison libaudiofile-dev subversion libnewt-dev libcurl3-dev libnet-ssleay-perl openssl ssl-cert libauthen-pam-perl libio-pty-perl libmd5-perl libpg-perl libdbd-pg-perl php5-pgsql sqlite3 libsqlite3-dev openssl ssl-cert libapache2-mod-php5 php5-cli php5-common phpMyAdmin php5-mcrypt mcrypt phppgadmin apache2 libmcrypt-dev


Get OpenSipStack and OpenSBC from CVS:

cd /usr/src

cvs -d:pserver:anonymous@opensipstack.cvs.sourceforge.net:/cvsroot/opensipstack login

cvs -z3 -d:pserver:anonymous@opensipstack.cvs.sourceforge.net:/cvsroot/opensipstack co -P opensipstack

cvs -z3 -d:pserver:anonymous@opensipstack.cvs.sourceforge.net:/cvsroot/opensipstack co -P opensbc


Compile / Make OpenSipStack and OpebSBC:

cd /usr/src/opensipstack

chmod +x ./configure

./configure

make bothnoshared

cd ../opensbc

chmod +x ./configure

./configure

make bothnoshared

make distrib

Starting OpenSBC

In the distrib folder under /usr/src/opensbc there should be a couple of scripts. Use ./startup.sh to start the services and ./shutdown.sh to stop them.

Access the OpenSBC management then at http://inside.ip.addr.offw:9999

Hope this helps others who have been struggling getting this going! I'm working on some Vyatta configuration files for making things all work together.

info:http://sipxecs.blogspot.com/2008/12/vyatta-with-opensbc-install.html

Looking for an SBC solution? Vyatta + Freeswitch...


Sunday, December 28, 2008

Started working on getting a proper SBC for the home network. I hacked on Vyatta with OpenSBC this morning with less than stellar compilation results. I may revisit that.

I did get a good start on Vyatta (beta of Ver 5... Debiab) with Freeswitch installed though. Here are my installation notes so far:

Vyatta VC5 Beta ISO download is at: http://www.vyatta.org/downloads

Vyatta (ver 5 beta) with FreeSwitch Installation

Install Vyatta

Boot from ISO. Press ENTER.

At login, username 'root', password 'vyatta'.

Enter 'install-system'

Configure as needed...


Get items required for building Freeswitch

Login to Firewall as user 'vyatta'

vyatta@FW1:~$ cd /etc/apt
vyatta@FW1:/etc/apt$ su
Password: (enter root password)
vyatta@FW1:/etc/apt$ nano -w sources.list

Add line: "deb ftp://ftp.us.debian.org/debian/ lenny main contrib non-free"

Ctrl-X and Y to overwrite

FW1:/etc/apt# apt-get update

FW1:/etc/apt# apt-get install -y mc autoconf automake libtool build-essential libxml2 libxml2-dev libtiff4 libtiff4-dev php5 php5-cli php5-mysql php5 php5-cli php5-mysql php5-gd mysql-server libmysqlclient15-dev php-pear php-db curl sox apache2 libssl-dev libncurses5-dev bison libaudiofile-dev subversion libnewt-dev libcurl3-dev libnet-ssleay-perl openssl ssl-cert libauthen-pam-perl libio-pty-perl libmd5-perl libpg-perl libdbd-pg-perl php5-pgsql sqlite3 libsqlite3-dev openssl ssl-cert libapache2-mod-php5 php5-cli php5-common phpMyAdmin php5-mcrypt mcrypt phppgadmin apache2 libmcrypt-dev


Get the Freeswitch Code

cd /usr/src/

svn checkout http://svn.freeswitch.org/svn/freeswitch/trunk freeswitch


Build Freeswitch...

cd freeswitch

./bootstrap.sh

./configure –prefix=/usr/local/freeswitch

make

make install

make sounds-install

make moh-install

make samples


Run Freeswitch...

cd /usr/local/freeswitch/bin

./freeswitch


That's as far as I've taken it at this point...

Shout out to http://madhawa.com/?p=10 for shedding light on Debian (etch)  install of Freeswitch.


info:http://sipxecs.blogspot.com/2008/12/looking-for-sbc-solution-vyatta.html

Vyatta version:6.4 Major changes

April 2012
reorganizing operational mode commands, better support of VRRP, Global stateful behavior for firewall,Connection Tracking Enhancements, Enhanced Connection Sync Functionality - Support for seamless failover of FTP, SIP and H.323 connections, NAT Enhancements, CLI Enhancements, Upgrade improvements for bare-metal installations (VSE only), Virtualization upgrade improvements (VSE only), VMware vSphere 5 support (VSE only), XenServer 6.0 support (VSE only), expanded GUI with additional tabs – Dashboard and Statistics. (VSE only)

วันพฤหัสบดีที่ 26 กรกฎาคม พ.ศ. 2555

Install vyatta VC6.4 - 64 Bit Virtualization iso - test is SBC

Install in VMware Workstation for VC6.4  - 64 Bit Virtualization iso
Download file : vyatta-livecd-virt_VC6.4-2012.05.31_amd64.iso for http://vyatta.org/downloads , VC6.4  - 64 Bit Virtualization iso Size: 216MB

Quick Start Guide : http://www.vyatta.com/downloads/documentation/VC6.4/Vyatta-QuickStart_R6.4_v01.pdf

Documentation for Vyatta Network OS version 6.4 : http://www.vyatta.com/download/docdl?whence=



OVERVIEW DOCUMENTS : Vyatta Network OS 6.3 Archive (27.1MB) , Vyatta Network OS 6.2 Archive (42.3MB)



Web GUI  in Vyatta Network OSversion 6.4 : is not support free version.

วันพุธที่ 25 กรกฎาคม พ.ศ. 2555

SIP programming for the Java developer


Deliver SIP-based services to Java applications with SIP Servlet

Session Initiation Protocol (SIP) is a control (signaling) protocol developed by the Internet Engineering Task Force (IETF) to manage interactive multimedia IP sessions including IP telephony, presence, and instant messaging. The SIP Servlet Specification (Java Specification Request 116), developed through the Java Community Process, provides a standard Java API programming model for delivering SIP-based services. Derived from the popular Java servlet architecture of Java Platform, Enterprise Edition (Java EE is Sun's new name for J2EE), SIP Servlet brings Internet application development capabilities to SIP solutions.
IT and telecom are converging. Network-IT applications, typically data oriented, are merging with communication applications. The increasing number of Call Me buttons appearing on Webpages is an example of this integration. The SIP Servlet Specification brings a familiar programming model to Java developers for building converged applications. This article gives a step-by-step introduction on how to use SIP Servlet to build a simple echo chat service.

Session Initiation Protocol

Defined in Request for Comments 3261, SIP is a protocol for establishing, modifying, and terminating multimedia IP communication sessions. Figure 1 is a simple example of using SIP to establish a VoIP (voice-over Internet Protocol) call:





Figure 1. Typical SIP message flow in VoIP calls

All the white lines in Figure 1 represent the SIP communications. Caller sends a SIP INVITE request to invite the "callee" to establish a voice session. Callee first responds with a message that has a 180 status code to indicate the phone is ringing. As soon as phone is picked up, a response with a 200 status code is sent to the caller to accept the invitation. Caller confirms with an ACK message, and session is established. Once the session is established, the actual digitized voice conversation typically transmits via Realtime Transmission Protocol (RTP) with the session, as the red line in Figure 1 indicates. When the conversation ends, a SIP BYE request is sent, followed by a response with a 200 status code to confirm the session termination.
Here is an example of a SIP INVITE request and a response with a 200 OK status code:
 SIP INVITE request:
INVITE sip:callee@callee.com SIP/2.0
Via: SIP/2.0/UDP pc.caller.com;branch=z9hG4bK776asdhds
Max-Forwards: 70
To: Callee <sip:callee@callee.com>
From: Caller <sip:caler@caller.com>;tag=1928301774
Call-ID: a84b4c76e66710
CSeq: 314159 INVITE
Contact: <sip:caller@pc.caller.com>
Content-Type: application/sdp
Content-Length: 142


(content (SDP) is not shown)


SIP 200 OK response:
 SIP/2.0 200 OK
Via: SIP/2.0/UDP pc.caller.com;branch=z9hG4bK776asdhds;received=192.0.2.1
To: Callee <sip:callee@callee.com>;tag=a6c85cf
From: Caller <sip:caller@caller.com>;tag=1928301774
Call-ID: a84b4c76e66710
CSeq: 314159 INVITE
Contact: <sip:callee@workstation.callee.com>
Content-Type: application/sdp
Content-Length: 131


(content (SDP) is not shown)


As you can see, the format of SIP resembles HTTP. However, when compared to HTTP, SIP is:

  • Responsible for session management. The actual multimedia content, such as instant messages, voice, and video, may or may not be transmitted via SIP.
  • Asynchronous and stateful. For each SIP request, there could be multiple responses. This means the application has to process each SIP message within a proper state context.
  • An application protocol that can run on both reliable and unreliable transport. Thus, the application must guarantee the message delivery with message retransmission and acknowledgement.
  • A peer-to-peer protocol where there is no clear distinction between client and server. Either side must be able to send and receive requests and responses.


SIP-based services

SIP-based services are SIP servers that offer services, such as message routing, to SIP endpoints, such as IP phones. For example, in Figure 2, the SIP registrar server and proxy server offer SIP registration and proxy services to help the SIP endpoints locate and communicate with each other.





message routing with SIP registrar and proxy server. Click on thumbnail to view full-sized image.

Figure 2 illustrates the following:
  1. Callee registers itself to the registrar server by sending a REGISTER request.
  2. The registrar server accepts the registration, which contains the callee's name address, by responding with a 200 OK status code.
  3. Caller requests to establish a communication session with callee by sending an INVITE request to the proxy server. The INVITE message's content typically contains the description of the communication session the caller wants to establish, such as media type, security, or IP address. The description is typically in Session Description Protocol (SDP) format.
  4. The proxy server looks up the registrar server to find out the callee's current address. Note that lookup is an implementation issue not part of SIP.
  5. The proxy server forwards the INVITE request from caller to callee based on its current address.
  6. Callee accepts the invitation by responding with a 200 OK status code. The 200 OK response to an INVITE request typically contains the description of the communication session that callee can establish with the caller.
  7. The proxy server forwards a 200 OK response from callee to caller.
  8. Caller confirms the session establishment by sending an ACK message to the proxy server. The ACK message may contain the final agreement on the session.
  9. In turn, the proxy server forwards the ACK to the callee. Thus, the three-way handshake is completed via the proxy server, and a session is established.
  10. Now the communication between caller and callee happens. The protocol used for communication may or may not be SIP. For example, instant messages can be transmitted over SIP. Voice conversations are typically transmitted over RTP.
  11. Now, callee finishes the conversation and wishes to terminate the session by sending a BYE request.
  12. Caller responds with a 200 OK status code to accept session termination.


In the above scenario, the SIP proxy server simply routes the messages to the callee's current address. As you can imagine, more interesting and smart routing services can happen. For example, the proxy server can "follow a user" by routing the messages to where he can be reached, such as a cell phone, even if someone is calling on his office phone.

SIP Servlet

Defined in Java Specification Request 116, the SIP Servlet Specification provides a container-servlet programming model for SIP applications. Since it is derived from the Java servlet architecture in Java EE, JSR 116 brings a familiar approach to building SIP services to Java EE developers.
The table below summarizes the similarity between HTTPServlet andSIPServlet.
Comparison between an HTTP and SIP servlet
HTTPSIP
Servlet classHttpServletSipServlet
SessionHttpSessionSipSession
Application packageWARSAR
Deployment descriptorweb.xmlsip.xml


Much like HTTP servlets, SIP servlets extend thejavax.servlet.sip.SipServlet class, which in turn extends thejavax.servlet.GenericServlet class. As you might have guessed,SipServlet overrides the service(ServletRequest request, ServletResponse response) method to handle different types of SIP messages.
Since SIP is asynchronous, only one of the request and response arguments in the service() method is valid; the other one is null. For example, if the incoming SIP message is a request, only the request is valid and the response is null, and vice versa. The default implementation of the SipServlet class dispatches requests todoXXX() methods and responses to doXXXResponse() methods with a single argument. For example, doInvite(SipServletRequest request) for a SIP invite request anddoSuccessResponse(SipServletResponse response) for SIP 2xx class responses. Typically SIP servlets override doXXX() methods and/ordoXXXResponse() methods to provide application logic.
How do you send SIP responses if there is no response object in thedoXXX() methods? In SIP servlets, you must call one of thecreateResponse() methods in thejavax.servlet.sip.SipServletRequest class to create a response object. Then, call the send() method on the response object to send the response.
How about creating a SIP request in a SIP servlet? There are two ways to create SIP requests: Call either one of the createRequest()methods on the SipSession class to create a SIP request within the session, or one of the createRequest() methods onjavax.servlet.sip.SipFactory to create a SIP request within a new SipSession. To get an instance of SipFactory, you must call getAttribute("javax.servlet.sip.SipFactory") on the ServletContext class.
The SipFactory is a factory interface in the SIP Servlet API for creating various API abstractions, such as requests, address objects, and application sessions. One interesting object created by SipFactory isjavax.servlet.sip.SipApplicationSession. The intention of JSR 116 is to create a unified servlet container that can run both an HTTP and a SIP servlet. SipApplicationSession provides a protocol-agnostic session object to store application data and correlate protocol-specific sessions, such as SipSession and HttpSession. Hopefully this concept will be adopted by future versions of the Servlet API to make it javax.servlet.ApplicationSession instead ofjavax.servlet.sip.SipApplicationSession.
The SipApplicationSession manages protocol-specific sessions like SipSession. The SipSession interface represents the point-to-point relationship between two SIP endpoints and roughly corresponds to a SIP dialog defined in Request for Comments 3261. SipSession is inherently more complicated than its HTTP counterpart due to SIP's asynchronous and unreliable nature mentioned above. For example, Figure 3 shows the SipSession state transitions defined in JSR 116:






Figure 3. State transitions in SipSession

Typically, an HttpSession is created when a user logs in and destroyed after logout. A SipSession typically represents one logical conversation, even if you have multiple conversations between the same endpoints. So SipSession is more dynamic and has a shorter lifespan.
More advanced discussions of the SipSession lifecycle and its relationship with SIP dialog reaches beyond this article's scope. Fortunately, the container handles most of the complexity, such as lifecycle and state transitions, and SipSession can simply be used as storage for session data.

A complete example: EchoServlet

The EchoServlet is a SIP servlet that can echo the instant messages you type in Windows Messenger:
 package com.micromethod.sample;


import java.io.IOException;
import java.util.HashMap;


import javax.servlet.*;
import javax.servlet.sip.*;


/**
 * EchoServlet provides a simple example of a SIP servlet.
 * EchoServlet echoes instant messages sent by Windows Messenger.
 */
public class EchoServlet extends SipServlet {


  /**
   * _address keeps the mapping between sign-in name and actual contact address.
   */
  protected HashMap _addresses = new HashMap();


  /**
   * Invoked for SIP INVITE requests, which are sent by Windows Messenger to establish a chat session.
   */
  protected void doInvite(SipServletRequest req) throws IOException, ServletException {
    // We accept invitation for a new session by returning 200 OK response.
    req.createResponse(SipServletResponse.SC_OK).send();
  }


  /**
   * Invoked for SIP REGISTER requests, which are sent by Windows Messenger for sign-in and sign-off.
   */
  protected void doRegister(SipServletRequest req) throws IOException, ServletException {
    String aor = req.getFrom().getURI().toString().toLowerCase();
    synchronized (_addresses) {
      // The non-zero value of Expires header indicates a sign-in.
      if (req.getExpires() != 0) {
        // Keep the name/address mapping.
        _addresses.put(aor, req.getAddressHeader("Contact").getURI());
      }
      // The zero value of Expires header indicates a sign-off.
      else {
        // Remove the name/address mapping.
        _addresses.remove(aor);
      }
    }
    // We accept the sign-in or sign-off by returning 200 OK response.
    req.createResponse(SipServletResponse.SC_OK).send();
  }


  /**
   * Invoked for SIP MESSAGE requests, which are sent by Windows Messenger for instant messages.
   */
  protected void doMessage(SipServletRequest req) throws IOException, ServletException {
    SipURI uri = null;
    synchronized (_addresses) {
      // Get the previous registered address for the sender.
      uri = (SipURI) _addresses.get(req.getFrom().getURI().toString().toLowerCase());
    }
    if (uri == null) {
      // Reject the message if it is not from a registered user.
      req.createResponse(SipServletResponse.SC_FORBIDDEN).send();
      return;
    }


    // We accept the instant message by returning 200 OK response.
    req.createResponse(SipServletResponse.SC_OK).send();


    // Create an echo SIP MESSAGE request with the same content.
    SipServletRequest echo = req.getSession().createRequest("MESSAGE");
    String charset = req.getCharacterEncoding();
    if (charset != null) {
      echo.setCharacterEncoding(charset);
    }
    echo.setRequestURI(uri);
    echo.setContent(req.getContent(), req.getContentType());
    // Send the echo MESSAGE request back to Windows Messenger.
    echo.send();
  }


  /**
   * Invoked for SIP 2xx class responses.
   */
  protected void doSuccessResponse(SipServletResponse resp) throws IOException, ServletException {
    // Print out when the echo message was accepted.
    if (resp.getMethod().equalsIgnoreCase("MESSAGE")) {
       System.out.println("\"" + resp.getRequest().getContent() + "\" was accepted: " + resp.getStatus());
    }
  }


  /**
   * Invoked for SIP 4xx-6xx class responses.
   */
  protected void doErrorResponse(SipServletResponse resp) throws IOException, ServletException {
    // Print out when the echo message was rejected/
    if (resp.getMethod().equalsIgnoreCase("MESSAGE")) {
       System.out.println("\"" + resp.getRequest().getContent() + "\" was rejected: " + resp.getStatus());
    }
  }


  /**
   * Invoked for SIP BYE requests, which are sent by Windows Messenger to terminate a chat session/
   */
  protected void doBye(SipServletRequest req) throws IOException, ServletException {
    // Accept session termination by returning 200 OK response.
    req.createResponse(SipServletResponse.SC_OK).send();
  }
}


Figure 4 shows how the SIP message flows between Windows Messenger and EchoServlet:





Figure 4. Message flow between Windows Messenger and EchoServlet

You can compile EchoServlet just like any Java code. Just make sure servlet.jar and sipservlet.jar (part of JSR 116 distribution) are on the classpath.
Similarly to HTTP servlet applications, each SIP servlet application has a deployment descriptor: sip.xml. Here is an example:
 <?xml version="1.0" encoding="UTF-8"?>


<!DOCTYPE sip-app 
  PUBLIC "-//Java Community Process//DTD SIP Application 1.0//EN" 
  "http://www.jcp.org/dtd/sip-app_1_0.dtd">


<sip-app>
  <display-name>SIP Servlet Sample</display-name>


  <servlet>
    <servlet-name>echo</servlet-name>
    <servlet-class>com.micromethod.sample.EchoServlet</servlet-class>
  </servlet>


  <servlet-mapping>
    <servlet-name>echo</servlet-name>
    <pattern>
      <or>
            <equal><var>request.method</var><value>REGISTER</value></equal>
            <equal><var>request.method</var><value>INVITE</value></equal>
      </or>
    </pattern>
  </servlet-mapping>
</sip-app>



The noticeable differences from a typical web.xml are the servlet mapping rules. Instead of specifying a URL pattern, you must write a Boolean expression in XML with various values in the SIP request headers. The SIP servlet container evaluates all the expressions from different applications for each initial SIP request—the SIP request does not belong to any existingSipSession. If an expression is evaluated to be true, the corresponding SIP servlet is invoked. If there are multiple matches, the container may simply invoke the first matching servlet or have other local policies.
In the above sip.xml, we simply specify that EchoServlet accepts the initial SIP REGISTER and INVITE requests. Once the session is established, all the messages sent within the session, such as MESSAGE and BYE, are automatically delivered to the servlet associated with the session.
Now, you must create a SIP servlet application package with EchoServlet and sip.xml in order to deploy and run. Similar to an HTTP servlet application, a SIP servlet application must be assembled in a SIP application archive (SAR). A SAR is simply a Java Archive (JAR) with additional requirements for the directory structure and content. The structure of SAR resembles WAR and should look something like the following:
  .../WEB-INF
      |-- classes
      |   |-- com
      |       |-- micromethod
      |           |-- sample
      |               |-- EchoServlet.class
      |-- sip.xml


You can simply create the SAR using the jar command from the top directory: jar cv0f echo.sar.

Deploying SAR in SIPMethod

Now it is time to deploy your SAR into your favorite SIP servlet container. Since each container has different deployment mechanisms, as an example, I use SIPMethod Application Server, a SIP servlet container from Micromethod Technologies.
Assuming you have properly downloaded and installed SIPMethod Application Server, to deploy a SAR into SIPMethod Application Server, you simply copy the SAR into SIPMethod's sipapps directory:
  • Linux: cp echo.sar <sm_home>/sipapps
  • Windows: copy echo.sar <sm_home>\sipapps
The <sm_home> is where you install SIPMethod Application Server.

Once SIPMethod starts, it will expand echo.sar into the echo directory under sipapps. Here is an example of the directory structure:
Figure 5. Directory structure after deployment

Test the EchoServlet

Assuming you have deployed echo.sar properly, you can start SIPMethod Application Server using its startup script:
  • Linux: <sm_home>/bin/startup.sh
  • Windows: <sm_home>\bin\startup.bat
                
EchoServlet requires Windows Messenger 5.0 or above. Please configure Windows Messenger with the following steps:
1. Open the Options dialog from the Tools menu
2. Open the Accounts tab in the Options dialog
3. Enable SIP Communications Service Account by checking "My contacts include users of a SIP Communications Service"
4. Type a name, such as weichen@micromethod.com, in the Sign-In Name field

Figure 6. Configure SIP account in Windows Messenger. Click on thumbnail to view full-sized image.

5. Open SIP Communications Service Connection Configuration dialog by clicking the Advanced... button
6. Click the Configure Settings radio button
7. Type IP address or machine name of where SIPMethod is running, such as 192.168.0.4, in Server Name or IP Address field
8. Select either TCP or UDP






Figure 7. Configure SIP connection in Windows Messenger. Click on thumbnail to view full-sized image.

Now make sure SIPMethod Application Server is running; sign into Windows Messenger with the sign-in account for the SIP Communications Service you entered in Options, such as weichen@micromethod.com. Now you can start a Send an Instant Message window by selecting the Actions menu, then Send an Instant Message... . Please select the Other tab and type in a name, such as anybody@yahoo.com, in the email address field. Then click OK.

Figure 8. Start a SIP chat session in Windows Messenger. Click on thumbnail to view full-sized image.

info : http://www.javaworld.com/javaworld/jw-06-2006/jw-0619-sip.html
http://opensbc.blogspot.com/2012/07/sip-programming-for-java-developer.html

SIP

บทนำ

SIP เป็นโปรโตคอลที่ใช้ Create, Modify และ Terminate Session ในการติดต่อสื่อสาร ซึ่งมีการนำไปใช้ใน Internet Telephone Call, Multimedia Distribution, และ Multimedia Conference โปรโตคอลนี้ออกแบบโดย Henning Schulzrinne จากมหาวิทยาลัยโคลัมเบียและ Mark Handley จากมหาวิทยาลัยลอนดอนในปี 1996 (พ.ศ.2539) ต่อมาในเดือนพฤศจิกายนปี 2000 (พ.ศ.2543) ก็ได้รับการยอมรับจาก 3GPP และกลายเป็นส่วนหนึ่งของสถาปัตยกรรม IMS (IP Multimedia Subsystem), Voice over IP รวมถึง H.323 และอื่น ๆ

IMS เป็นแนวคิดเกี่ยวกับสถาปัตยกรรมของการให้บริการ IP Multimedia แก่ผู้ใช้ ซึ่งเป็นส่วนหนึ่งในการพัฒนาเครือข่ายมือถือของ GSM โดยเริ่มมาจาก 3GPP R5 นำเสนอวิธีส่ง Internet Services ผ่าน GPRS ต่อมาได้มีการปรับปรุงโดย 3GPP, 3GPP2, และ TISPAN เพื่อให้ครอบคลุมถึง Wireless LAN, CDMA2000, และ Fix Line โดยนำโปรโตคอลของ IETF มาใช้ เช่น SIP

SIP จะมีลักษณะทั่วไปคือ
- ขนาดเล็ก เพราะกำหนดวิธีติดต่อไว้เพียง 6 วิธีเพื่อลดความซับซ้อน
- มีความเป็นอิสระ สามารถใช้งานกับ UDP, TCP, ATM และอื่น ๆ ได้
- เป็นข้อความที่มนุษย์สามารถอ่านได้

การออกแบบโปรโตคอล

SIP client จะใช้ TCP หรือ UDP พอร์ต 5060 เชื่อมต่อกับ SIP server และ SIP อื่น ๆ ซึ่ง SIP จะใช้สำหรับตั้งค่าและยกเลิก Voice หรือ Video call แต่ก็สามารถนำไปใช้กับงานกับระบบอื่นที่ต้องการเปิด Session รวมถึง Event Subscription และ Notification ได้ การสื่อสารโดยใช้ภาพและเสียงสามารถทำได้โดยแบ่งโปรโตคอล Session ออกจากกัน เช่น RTP (Real-time Transport Protocol)

RTP ใช้กำหนดรูปแบบ packet ในการส่งภาพและเสียงผ่านอินเตอร์เน็ต ถูกพัฒนาโดย Audio-Video Transport Working Group ของ IETF และได้ตีพิมพ์ครั้งแรกในปี 1996 (พ.ศ.2539) โดย RTP จะไม่มีพอร์ต TCP หรือ UDP มาตรฐานในการสื่อสาร แต่จะใช้พอร์ต UDP ที่เป็นเลขคู่ในการสื่อสารและพอร์ต UDP เลขคี่ถัดไปเป็น RTP Control Protocol (RTCP) เลขพอร์ตมักจะอยู่ระหว่าง 16384-32767 RTP สามารถรับส่งข้อมูลอะไรก็ได้แบบ real-time เช่น ภาพและเสียง โดยใช้โปรโตคอล SIP ในการตั้งค่าและยกเลิก

SIP จะเป็นโปรโตคอลที่ใช้ส่งสัญญาณและตั้งค่าในระบบ IP สามารถใช้งานร่วมกับระบบโทรศัพท์ PSTN (Public Switched Telephone Network) ได้ ซึ่งมาตรฐาน SIP ไม่ได้ระบุไว้ SIP ทำได้เพียงสางสัญญาณและตั้งค่า อย่างไรก็ตาม SIP สามารถใช้งานในระบบเครือข่ายได้ เช่น Proxy Server และ User Agent ซึ่งจะเหมือนกับการทำงานของโทรศัพท์ คือ หมุนเบอร์, ทำให้โทรศัพท์ปลายทางส่งเสียง, ฟังเสียงตอบรับหรือสัญญาณไม่ว่าง

SIP ทำให้ระบบโทรศัพท์มีความสามารถในขั้นตอนโทรออกมากขึ้น ดูได้จาก Signalling System 7 (SS7) โดย SS7 จะเป็นโปรโตคอลที่รวมศูนย์, ใช้กับระบบรวมศูนย์ที่ซับซ้อน, และใช้งานกับเครื่องลูกข่ายที่ไม่เก่ง (โทรศัพท์บ้าน) SIP เป็นโปรโตคอลแบบ Peer-to-Peer ซึ่งใช้กับเครือข่ายที่ไม่ซับซ้อนและเครื่องลูกค้ามีความสามารถสูง

แม้ VoIP จะมีโปรโตคอลส่งสัญญาณเยอะอยุ่แล้ว แต่ SIP ก็ช่วยสร้างเครื่องหลักในการสื่อสารแบบ IP ได้มากกว่าระบบโทรคมนาคม SIP จะเป็นมาตรฐานของ IETF ขณะที่ H.323 เป็นโปรโตคอลของ ITU ซึ่งทั้งสององค์กรก็ให้เกียรติกัน

SIP สามารถทำงานร่วมกับโปรโตคอลอื่นได้โดยจะสร้างสัญญาณให้ Session ของการติดต่อสื่อสาร SIP จะทำงานเป็นพาหะของ Session Description Protocol (SDP) ใช้อธิบายรายละเอียดของเนื้อหาที่จะส่ง เช่น หมายเลขพอร์ตที่ใช้, Codec ที่ต้องการ

SIP จะคล้ายกับ HTTP เช่น การรับส่งข้อมูลใช้ภาษาที่มนุษย์อ่านได้, รหัสบอกสถานะจะคล้าย ๆ กัน บางคนกล่าวว่า SIP เป็นโปรโตคอลแบบ stateless ซึ่งสามารถตรวจสอบความผิดพลาดและเพิ่มเติมความสามารถได้มากกว่าโปรโตคอลแบบ stateful ซึ่งโปรโตคอลแบบ stateless จะส่งคำสั่งได้อย่างอิสระ โดยไม่ต้องสนใจว่าคำสั่งก่อนหน้าคือคำสั่งอะไร ในขณะที่โปรโตคอลแบบ stateful จะต้องมีการบันทึกสถานะการแลกเปลี่ยนข้อมูลไว้ตลอดเวลา


ส่วนประกอบของเครือข่าย SIP

Hardware ที่ใช้จะเหมือนกับโทรศัพท์บ้าน แต่ใช้ SIP และ RTP ในการสื่อสาร บางระบบจะใช้ Electronic Numbering (ENUM) หรือ DUDi ในการแปลงหมายเลขโทรศัพท์ให้เป็น SIP Address แล้วเรียก SIP อื่นในระบบเครือข่าย

ตัวอย่างโปรแกรมในปัจจุบันที่ใช้ SIP สื่อสาร เช่น Microsoft Windows Messenger, iChat AV, AIM ของ Apple ซึ่ง SIP จะอาศัย Proxy และอุปกรณ์เครือข่ายเพื่อทำงานแบบ peer-to-peer เหมือนระบบทั่วไป

SIP Request

RFC 3261 (SIP) มี 6 แบบ ได้แก่
- INVITE ใช้เมื่อ client ต้องการสร้าง session เพื่อติดต่อ
- ACK ใช้เมื่อ client ได้รับการตอบกลับจาก INVITE ภายในเวลาที่กำหนด
- BYE ใช้เมื่อต้องการสิ้นสุดการเชื่อมต่อ ซึ่งผู้ส่งและผู้รับสามารถส่งได้เหมือนกัน
- CANCEL ใช้เพื่อยุติการค้นหา แต่ไม่สามารถใช้ยกเลิกสายที่รับแล้วได้
- OPTIONS ใช้ตรวจสอบคุณสมบัติของ Server
- REGISTER ใช้ระบุ Address ของข้อมูล To ใน SIP Server

RFC 3262 เพิ่มความน่าเชื่อถือในการตอบกลับของ SIP
- PRACK

RFC 3265 เพิ่มเติม
- SUBSCRIBE แจ้ง Event ของ Notification จากผู้แจ้ง
- NOTIFY แจ้งเหตุการณ์ใหม่

SIP Response

1xx ข้อมูลการตอบกลับ
- 100 กำลังพยายาม
- 180 กำลังเรียก (ring)
- 181 กำลัง forward
- 182 กำลังเข้าคิว
- 183 ความคืบหน้าของ session

2xx ได้รับการตอบกลับ
- 200 OK
- 202 ตกลง

3xx Redirect
- 300 มีหลายตัวเลือก
- 301 ย้ายเป็นการถาวร
- 302 ย้ายเป็นการชั่วคราว
- 305 ใช้ Proxy
- 380 บริการเสริม

4xx การตอบกลับล้มเหลว
- 400 คำสั่ง Request ไม่ถูกต้อง
- 401 ไม่ได้รับสิทธิ ใช้กับ registrar เท่านั้น ส่วน Proxy ใช้ 407
- 402 ต้องจ่ายเงิน (สงวนไว้ใช้ในอนาคต)
- 403 ซ่อน
- 404 ไม่พบ ไม่มีผู้ใช้ชื่อนี้
- 405 ไม่อนุญาตให้ใช้วิธีนี้
- 406 ไม่สามารถรับได้
- 407 ไม่ได้รับสิทธิจาก Proxy
- 408 หมดเวลา ไม่สามารถค้นหาผู้ใช้ได้ในเวลาที่กำหนด
- 410 ไม่สามารถติดต่อผู้ใช้ได้ ณ เวลานี้
- 413 คำสั่ง Request ยาวเกินไป
- 414 Request-URI ยาวเกินไป
- 416 ไม่สนับสนุน URI แบบนี้
- 420 Server ไม่เข้าใจโปรโคตอ SIP ที่ส่งมา
- 421 ต้องการข้อมูลเพิ่มเติม
- 423 ช่วงเวลาน้อยเกินไป
- 479 ไม่สามารถใช้ URI นี้ได้
- 480 ปิดบริการชั่วคราว
- 481 ติดต่อไม่ได้
- 482 เกิดการวน loop
- 483 เชื่อมต่อมากเกินไป
- 484 Address ไม่ถูกต้อง
- 485 สับสน
- 486 สายไม่ว่าง
- 487 ยุติการร้องขอ
- 488 ไม่ได้รับ
- 489 เหตุการณ์ไม่ถูกต้อง
- 491 ยุติการร้องขอ
- 493 ไม่ถูกกฎ ไม่สามารถถอดรหัส S/MIME ได้
- 494 ต้องการความปลอดภัย

5xx server มีปัญหา
- 500 server มีปัญหาภายใน
- 501 ยังไม่เปิดใช้วิธีนี้
- 502 Gateway ไม่ถูกต้อง
- 503 ไม่สามารถให้บริการได้
- 504 หมดเวลาติดต่อ Server
- 505 Server ไม่สนับสนุนโปรโคตอล SIP รุ่นนี้
- 513 ข้อความยาวเกินไป

6xx ความล้มเหลว
- 600 ยุ่งตลอดเวลา
- 603 ไม่รับ
- 604 ไม่อยู่ตลอดเวลา
- 606 ไม่ยอมรับ

อื่น ๆ เช่น
- INFO ส่งข้อมูลโดยไม่แก้ไข Session State
- REFER ใช้กับ call transfer
- MESSAGE ข้อความที่ต้องการส่ง
- UPDATE ส่งข้อมูลเพื่อแก้ไข Session State แต่ไม่เปลี่ยนสถานะการทำงาน

ตัวอย่าง SIP Request

REGISTER sip:seberino@switch-2.nufone.net SIP/2.0
Via: SIP/2.0/UDP 66.159.194.51:5060
CSeq: 3363 REGISTER
To: sip:seberio@switch-2.nufone.net
Expires: 900
Call-ID: 401507385@66.159.194.51
User-Agent: Shtoom/0.3alpha0
Contact: <sip:seberino@66.159.194.51:5060>
Contact-Length: 0


ตัวอย่างภาษา Perl
use Net::SIP;

  # create new agent
  my $ua = Net::SIP::Simple->new(
                outgoing_proxy => '192.168.0.10',
                registrar => '192.168.0.10',
                domain => 'example.com',
                from => 'me',
                auth => [ 'me','secret' ],
  );

  # Register agent
  $ua->register;

  # Invite other party, send anncouncement once connected
  $ua->invite( 'you',
                init_media => $ua->rtp( 'send_recv', 'announcement.pcmu-8000' ),
                asymetric_rtp => 1,
  );

  # Mainloop
  $ua->loop;




ตัวอย่างการใช้งานใน ภาษา Java



http://www.javaworld.com/javaworld/jw-06-2006/jw-0619-sip.html



-------------------------------------------------------