0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

VoIP動作検証

Posted at

概要

VoIPの勉強のため「基礎からわかるTCP/IP SIPによるVoIPプログラミング」のサンプルコードを動作させる。

※注意)サンプルプログラムの詳細は「基礎からわかるTCP/IP SIPによるVoIPプログラミング」を参照。

なお、オーディオデバイスの設定はできていない。alsaをインストールすれば/dev/dspファイルは作成するがopenに失敗していた。

環境

  • osx上でmultipassで仮想マシン(Ubuntu20.04)を複数起動し構築する。
  • SIPバーサはsiproxdを用いる

端末間の直接通信

作成環境

名称未設定ファイル.drawio.png

SIPクライアントの設定

  • ソースコードをビルドする。
gcc -o ./sipua -D_POSIX_PTHREAD_SEMANTICS -pthread rtp_ctrl.c stack_if.c stk_main.c sip_ctrl.c sdp.c sound.c codec.c sip_message.c
  • sip.confの設定

クライアントA

rtp_port = 10000
user_name = user1
reg_svr = 192.168.2.100
use_svr = off

クライアントB

rtp_port = 10000
user_name = user2
reg_svr = 192.168.2.100
use_svr = off
  • /etc/hostname
    クライアントA:ua1.voip.org
    クライアントB:ua2.voip.org

  • /etc/nssswitch.conf
    hostsにdnsを書いておくと、files(/etc/hosts)で解決できても DNSパケット送信することがあるのでdnsは無効化。

hosts:          files
# dns
  • /etc/hosts
    以下を追加する。なぜかサンプルプログラムがua1でドメイン名解決する処理があったのでua1も記載しておく。
192.168.64.19 ua1.voip.org ua1
192.168.64.20 ua2.voip.org ua2
  • 動作結果
    以下はクライアントA(user1)からクライアントB(user2)へ着信した場合の例。SIPプロトコルによるシーケンスが動作することを確認。なお、オーディオデバイスの設定はできていないが、RTPパケットは送信されていた(以下の記載からは割愛)。
No.     Time           Source                Destination           Protocol Length sport  Info
      7 55.672520      192.168.64.19         192.168.64.20         SIP/SDP  540    46488  Request: INVITE sip:user2@ua2.voip.org | 
      8 55.673621      192.168.64.20         192.168.64.19         SIP      321    38564  Status: 100 Trying | 
      9 55.673779      192.168.64.20         192.168.64.19         SIP      322    47324  Status: 180 Ringing | 
     10 60.442988      192.168.64.20         192.168.64.19         SIP/SDP  528    36473  Status: 200 OK | 
     11 60.444425      192.168.64.19         192.168.64.20         SIP      334    57753  Request: ACK sip:user2@ua2.voip.org | 
 294753 74.204702      192.168.64.19         192.168.64.20         SIP      369    41012  Request: BYE sip:user2@ua2.voip.org | 
 294755 74.206524      192.168.64.20         192.168.64.19         SIP      314    35579  Status: 200 OK | 

SIPサーバを経由させた通信

作成環境

voipsrv.drawio.png

SIPサーバインストール

  • SIPサーバをインストールする。
sudo apt-get update
sudo apt-get install libosip2-dev
sudo apt-get install siproxd
  • siproxd.conf を修正する
    inbound,outboundのインタフェースを環境に合わせて修正する。
    以下修正前後のconfのdiffコマンド。
20,21c20,21
< if_inbound  = enp0s2
< if_outbound = enp0s2
---
> if_inbound  = eth0
> if_outbound = ppp0
49,50c49,50
< hosts_allow_reg = 192.168.64.0/24
< hosts_allow_sip = 192.168.64.0/24
---
> #hosts_allow_reg = 192.168.1.8/24
> #hosts_allow_sip = 123.45.0.0/16,123.46.0.0/16
  • sip.confの設定

クライアントA

rtp_port = 10000
user_name = user1
reg_svr = 192.168.64.21
use_svr = on

クライアントB

rtp_port = 10000
user_name = user2
reg_svr = 192.168.64.21
use_svr = on
  • クライアントの/etc/hosts
    SIPサーバのドメインを記載する。
    直接通信できないように対向クライアントの定義は無効化する。
192.168.64.19 ua1.voip.org ua1
#192.168.64.20 ua2.voip.org ua2
192.168.64.21 svr.voip.org
#192.168.64.19 ua1.voip.org ua1
192.168.64.20 ua2.voip.org ua2
192.168.64.21 svr.voip.org
  • SIPサーバの/etc/hosts
192.168.64.19 ua1.voip.org ua1
192.168.64.20 ua2.voip.org ua2
192.168.64.21 svr.voip.org svr
  • SIPサーバの起動
siproxd -c /etc/siproxd.conf 
  • 動作結果
    以下はクライアントA(user1)でパケットキャプチャした場合の例。SIPサーバ経由でクライアントB(user2)と通信している。
No.     Time           Source                Destination           Protocol Length sport 
      1 0.000000       192.168.64.19         192.168.64.21         SIP      378    54963  Request: REGISTER sip:svr.voip.org  (1 binding) | 
      2 0.000976       192.168.64.21         192.168.64.19         SIP      341    5060   Status: 200 OK  (1 binding) | 
      9 54.653315      192.168.64.19         192.168.64.21         SIP/SDP  539    44627  Request: INVITE sip:user2@ua2.voip.org | 
     10 54.656013      192.168.64.21         192.168.64.19         SIP      320    5060   Status: 100 Trying | 
     11 54.656095      192.168.64.21         192.168.64.19         SIP      321    5060   Status: 180 Ringing | 
     12 59.075057      192.168.64.21         192.168.64.19         SIP/SDP  528    5060   Status: 200 OK | 
     13 59.075662      192.168.64.19         192.168.64.21         SIP      333    43864  Request: ACK sip:user2@ua2.voip.org | 
 271442 86.282511      192.168.64.21         192.168.64.19         SIP      452    5060   Request: BYE sip:user1@ua1.voip.org | 
 271443 86.283572      192.168.64.19         192.168.64.21         SIP      397    53241  Status: 200 OK | 
 271448 92.064110      192.168.64.19         192.168.64.21         SIP      374    47229  Request: REGISTER sip:svr.voip.org  (remove 1 binding) | 
 271449 92.065197      192.168.64.21         192.168.64.19         SIP      337    5060   Status: 200 OK  (removed 1 binding) | 

参考

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?