[Freeswitch] How to change Freeswitch ip address

Freeswtich 설치 이후, 테스트를 진행하는데 SIP 클라이언트 접속이 안되는 문제가 발생했다.

telnet/netstat 으로 확인해보니 포트가 안뚫려있었다. Freeswitch listen IP가 localhost 로만 설정되어 있는 상황.

따라서, Freeswitch Server Ip 설정을 변경해주니 잘 작동하였다.

/usr/local/freeswitch/conf/vars.xml 파일 내용에서 다음 부분을 수정해주었다.(local_ip_v4 항목을 추가)

  <X-PRE-PROCESS cmd="set" data="sound_prefix=$${sounds_dir}/en/us/callie"/>

  <!--
      This setting is what sets the default domain FreeSWITCH will use if all else fails.

      FreeSWICH will default to $${local_ip_v4} unless changed.  Changing this setting does
      affect the sip authentication.  Please review conf/directory/default.xml for more
      information on this topic.
  -->
  <X-PRE-PROCESS cmd="set" data="local_ip_v4=192.168.200.10"/>
  <X-PRE-PROCESS cmd="set" data="domain=$${local_ip_v4}"/>
  <X-PRE-PROCESS cmd="set" data="domain_name=$${domain}"/>
  <X-PRE-PROCESS cmd="set" data="hold_music=local_stream://moh"/>
  <X-PRE-PROCESS cmd="set" data="use_profile=internal"/>

보통은 위의 설정이 없이도, 자동으로 local_ip_v4 에 IP 가 설정이 된다. 그러나, 만약 두개 이상의 NIC 가 달려 있는 서버라면.. 문제가 발생한다. 이 경우 위의 설정이 필요하다.

참조: http://wiki.freeswitch.org/wiki/Getting_Started_Guide#Some_stuff_to_try_out.21

 

lsof anon_inode

사내에서 개발한 리눅스 플랫폼 프로그램을 테스팅하면서 File descriptor 를 감시해야 하는 경우가 생겼다.

Socket 을 열고 정상적으로 종료를 하는지 확인하는 내용이었는데.. 이를 위해서 lsof 유틸리티를 사용했다.

$ lsof -p [PID] | wc -l

의 명령어로 갯수를 확인하면서 open file descriptor 수를 감시했다.

그러던 중, lsof 의 결과 출력을 분석했는데 이상한 것이 있었다.

cbapid  5560 root    3u  0000                0,7        0       521 anon_inode
cbapid  5560 root    4u  0000                0,7        0       521 anon_inode
cbapid  5560 root    5r  0000               0,11        0 271110595 eventpoll
cbapid  5560 root    6u  0000                0,7        0       521 anon_inode
cbapid  5560 root    7r  0000               0,11        0 271110596 eventpoll
cbapid  5560 root    8u  0000                0,7        0       521 anon_inode
cbapid  5560 root    9u  0000                0,7        0       521 anon_inode
cbapid  5560 root   10r   CHR                1,9      0t0  97762892 /dev/urandom
cbapid  5560 root   11r  0000               0,11        0 271110599 eventpoll

anon_inode 와 같이 나타난 file descriptor 들이 많이 있는 것을 확인한 것이다.

anon_inode 가 무엇이고 왜 나타나는 것일까?

해답은 다음과 같다.

anon_inode 는 anonymouse_inode 의 약자이며, epoll 을 사용할 경우, 감시대상 file descriptor 들을 관리하기 위해서 생성하고 사용하는 file descriptor 인 것이다.
즉, 내부적으로 epoll 을 사용하는 library 가 있다면 나타나는 정상적인 현상인 것이다.

참조 :  http://stackoverflow.com/questions/8170902/why-is-the-jdk-nio-using-so-many-anon-inode-file-descriptors

 

 

mtp mount in gentoo

Gentoo 머신에 안드로이드 폰을 연결해서 사용할 일이 있었다. 그냥 될 줄 알고 케이블을 연결했는데 인식이 안되는 것이었다. 역시… 뭔가를 해주어야 했다.

Gentoo wiki 에서는 mtp mount 하는 방법을 세가지 소개하고 있다. 바로 mtpfs, go-mtpfs, kde 이다. 이중 나는 mtpfs 와 go-mtpfs 를 사용했다.

결론적으로 mtpfs 는 원활한 동작이 되지 않았다. Mount 까지는 성공한 듯 싶었으나, 실제 마운트된 디렉토리에서 파일들에 접근할 수가 없었다. go-mtpfs 의 경우 완벽하게 동작했다.

먼저 go 를 설지하자.

$ sudo emerge dev-lang/go

그리고 mtpfs 를 위한 추가 작업을 진행해주자.

pchero@localhost ~ $ mkdir go
pchero@localhost ~ $ export GOPATH=/home/pchero/go
pchero@localhost ~ $ go get github.com/hanwen/go-mtpfs

그리고 그룹을 추가해주고…

$ sudo gpasswd -a pchero plugdev

마운트할 디렉토리를 생성하고 휴대폰에 케이블을 연결한 뒤, 마운트를 해주자.

$ mkdir ~/Android$ ~/go/bin/go-mtfs ~/Android

언마운트를 할 때는 아래와 같이..

$ fusermount -u ~/Android/

출처: https://wiki.gentoo.org/wiki/MTP

Asterisk – sip.conf

/etc/asterisk/sip.conf 파일은 Asterisk 에서 sip 채널을 설정하는 파일이다. 즉, Asterisk 에서 관리하는 SIP 단말기 정보를 입력하는 설정파일이다.

/etc/asterisk/sip.conf 파일 예제

[general]
context = unauthenticated               ; default context for incoming calls
allowguest = no                 ; disable unauthenticated calls
srvlookup = no                  ; disable DNS SRV record lookup on outbound calls
                                ;   (unless you have a reliable DNS connection,
                                ;   in which case yes)
udpbindaddr = 0.0.0.0           ; listen for UDP requests on all interfaces
port = 5060
tcpenable = no                  ; disable TCP support
register => 123123123:123123123@192.168.0.1  ; External trunk register information
;tlsenable = yes
;tlsbindaddr = ::

[teset_phone_ibk87ns4gj]
type = friend
host = dynamic
secret = tb9hibvp9c
context = demo

[messagewaiting](!)             ; a template to handle the settings common
                                ; to all mailboxes
type=peer
subscribecontext = voicemailbox ; the dialplan context on the voicemail server
context = voicemailbox          ; the dialplan context on the voicemail server
host = 192.168.200.10           ; ip address of presence server

[office-phone](!)       ; create a template for our devices
type = friend           ;   the channel driver will match on username first,
                        ;   IP second
context = LocalSets     ; this is where calls from the device will enter
                        ; the dialplan
host = dynamic          ; the device will register with asterisk
nat = force_rport,comedia       ; assume device is behind NAT
                        ;   *** NAT stands for Network Address Translation,
                        ;   which allows multiple internal devices to share an
                        ;   external IP address.
dtmfmode = auto ; accept touch-tone from the devices, negotiated
                ; automatically
disallow = all  ; reset which voice codec this device will accept or offer
allow = g722    ; audio codecs to accept from, and request to, the device
allow = ulaw    ; in the order we prefer

; define a device name and use the office-phone template
[0000FFFF0001](office-phone)
secret = helloworld      ; a unique password for this device --
                        ; DON'T USE THE PASSWORD WE'VE USED IN THIS EXAMPLE!

; define another device name using the same template
[0000FFFF0002](office-phone)
secret = helloworld ; a unique password for this device --
                        ; DON'T USE THE PASSWORD WE'VE USED IN THIS EXAMPLE!

[0000FFFF0003](office-phone)
secret = helloworld   ; DON'T USE THE PASSWORD WE'VE USED IN THIS EXAMPLE!
allow = gsm

[0000FFF0004](messagewaiting)   ; this will need to match the subsriber
                                ; name on the proxy
mailbox = 0000FFFF0004@DIR1     ; must be in the form mailbox@mailboxcontext
defaultuser = 0000FFFF0004      ; this will need to match the subscriber
                                ; name on the proxy

[general] Section

가장 기본적인 섹션이며, Default 값들을 설정하는 곳이다.
모든 채널 모듈 설정시, 기본적으로 설정의 제일 앞부분에 [general] 섹션을 포함한다고 생각하면 되며,  [general] 섹션의 이름은 바뀌어서는 안된다.
[general] 섹션에서는 기본적인 프로토콜 연결 방식과 Default Parameter 들을 설정할 수 있다.

context=unauthenticated         ; default context for incoming calls

위의 예제에서는 default context 로 unauthenticated 를 설정했다. 이것은, 별도로 context를 설정하지 않은 sip 채널들에 대해서는 unauthenticated 방식으로 처리하겠다는 뜻이다.
참고로 unauthenticated 에 관한 설정 내용은 /etc/asterisk/extension.conf 에 설정할 되어있어야 한다.

allowguest=no                   ; disable unauthenticated calls

Guest call 허용 여부. 명시적으로 계정을 가진 사람들만 통화가 가능하도록 할지 말지에 관한 옵션이다. No 로 설정시, sip.conf 에 등록된 계정만 통화가 가능하게 된다.

srvlookup=no                    ; disable DNS SRV record lookup on outbound calls
;   (unless you have a reliable DNS connection,
;   in which case yes)

DNS lookup 설정 여부

udpbindaddr=0.0.0.0             ; listen for UDP requests on all interfaces

NIC 가 여러개 있을 경우, 어느 IP 주소로 Listen 소켓을 열어둘지를 설정하는 옵션. 0.0.0.0 으로 설정할 경우, 사용가능한 모든 IP 주소로 Listen Port 를 열어놓는다.
Asterisk 의 NIC 사용방식은 all-or-one 방식이다. 즉, 하나를 사용하거나 모두를 사용하거나 이다.
예를 들어, 만약 NIC가 3개가 있을 경우 이중 2개만 사용할 수는 없다는 것이다.

tcpenable=no                    ; disable TCP support

TCP 사용 여부를 설정한다.

[office-phone](!) 섹션

 [office-phone](!)       ; create a template for our devices

템플릿 섹션 설정. [office-phone] 뒤에 붙은 (!) 표시는 이 섹션은 템플릿로 사용된다는 것을 가리킨다. 템플릿으로 만들어진 섹션은 추후 device 추가시 적용하여 사용가능 하다.

type=friend             ;   the channel driver will match on username first,
;   IP second

peer, user, friend 로 설정가능하다. 각각의 의미는 다음과 같다.
peer : Source IP 와 Port number 로 요청을 확인한다.
user : SIP Request 에서 From header 안의 username 으로 요청을 확인한다. sip.conf 에서 설정된 내용중에서 일치하는 device 정보를 찾는다.
friend : peer/user 두가지 방식 모두 사용해서 요청을 확인한다.

host=dynamic            ; the device will register with asterisk

연결되는 SIP 장비의 IP 주소를 설정한다. dynamic 또는 직접 IP 주소 입력 방식이 있는데, 만약 SIP 단말기가 고정 IP 가 아니라면 dynamic 으로 설정해야 한다.

 nat=force_rport,comedia ; assume device is behind NAT
;   *** NAT stands for Network Address Translation,
;   which allows multiple internal devices to share an
;   external IP address.

단말장치가 NAT 안쪽에 있는 경우 설정한다.

dtmfmode=auto   ; accept touch-tone from the devices, negotiated
; automatically

Asterisk 가 DTMF(touch-tone)을 보낼 때, 어떤 형식의 Dial tone을 보낼지 설정한다. info, inband, rfc2833, auto 중 한가지를 설정할 수 있다. info 설정은 SIP INFO method 를 사용하고, inband는 inband audio tone 을 전달한다. 그리고 rfc2833은 RFC-2833 에서 제정된 out-of-band method 를 전달한다.

disallow=all    ; reset which voice codec this device will accept or offer
allow=g722      ; audio codecs to accept from, and request to, the device
allow=ulaw      ; in the order we prefer
allow=alaw

사용/불가능 audio codec 을 지정한다. 제일 첫라인 disallow=all  은 general 에서 이미 설정된 코덱 내용들을 모두 버린다른 뜻이며, 바로 아랫 줄 부터 어떤 코덱들을 사용할 것인지 하나씩 설정한다.
ulaw의 경우, Canada 와 US를 제외한 거의 대부분의 국가에서 사용하며, alaw 는 주로 Canada 와 US 에서 사용한다.

[0000FFFF0003](office-phone) 섹션

[0000FFFF0003](office-phone)

장비 이름(username) 0000FFFF0003 과 office-phone 템플릿을 사용한다고 선언한 부분이다.

secret=helloworld     ; DON’T USE THE PASSWORD WE’VE USED IN THIS EXAMPLE!

password 를 설정한다.

ISO 8601

ISO 8601 은 날짜와 시간의 표기에 관한 국제 표준이다.

날짜와 시간을 나타낼 때, 누가 보아도 정확한 시간을 알 수 있도록 만들어 놓은 표준이다.

예를 들어, 여러개의 Time Zone 을 가진 나라가 있다면 (ex. USA) 하나의 로그파일을 분석 할 때, 각각의 Time zone에 맞춰서 로그를 분석하려고 하기때문에 여러가지 문제가 발생할 것이다.이런 경우 ISO 8601 표기에 맞춰 로그 시간을 표시한다면 해결책이 될 수 있다.

날짜의 경우, 우리가 평소에 쓰던 방식과 크게 다르지 않는데, 시간의 경우 조금 다르게 표시한다.
어떻게 시간을 표시할까? 생각보다 ISO 8601의 표기법은 간단하다.

다음은 Wikipedia 에서 가져온 ISO 8601 의 내용중 시간 표시에 관한 부분이다.

시간

시간의 표기에는 쌍점을 쓴 hh:mm:ss(확장 형식) 또는 hhmmss(기본 형식)를 사용한다. hh는 시(時)로서 00부터 24까지의 값을 갖는다.
mm은 분(分)으로서 00부터 59까지의 값을 갖는다. ss는 초(秒)로서 00부터 59까지의 값을 갖는다. 
반점이나 온점을 써서 앞 단위를 나눈 시간을 나타낼 수도 있는데, 이때 십진수를 사용하며 자릿수는 정보 교환 주체 사이에 미리 합의해야 한다. 
다음은 분절 시간 표현 자릿수로 한 자리를 정한 예이다.

    10:20:30,4 또는 102030,4 : 10시 20분 30.4초
    10:30,5 또는 1030,5 : 10:30:30과 같다.
    10.5 : 10:30와 같다.

날짜와 함께 표기할 때

날짜와 시간 사이에 T를 넣어 표기한다.

    1981-02-22T09:00:00 : 1981년 2월 22일 09:00

시간대 표기

UTC 시간대에서는 시각 뒤에 Z를 붙인다.

    1981-02-22T09:00Z 또는 19810222T1200Z : UTC 시간대에서의 1981년 2월 22일 오전 9시

UTC외의 시간대에서는 시각 뒤에 ±hh:mm, ±hhmm, ±hh를 덧붙여 쓴다.

    1981-02-22T09:00:00+09:00 : UTC+9 시간대에서의 1981년 2월 22일 오전 9시

우리 나라에서만 서비스하는 시스템이라면 굳이 ISO 8601 표기를 따르지 않아도 상관없다.
하지만 만약 다른 나라에서도 사용하는 시스템을 개발하고 그 시스템을 유지보수해야 하는 과정에서 Time zone 과 관련된 문제가 나타난다면 ISO 8601은 그 해답이 될 수 있겠다.

참조 : http://ko.wikipedia.org/wiki/ISO_8601