Skip to content
Snippets Groups Projects
Commit 64a8b950 authored by Alexandre Savard's avatar Alexandre Savard
Browse files

[#2536] Added an event loop in sflphone python client

parent d0fe2fe3
No related branches found
No related tags found
No related merge requests found
...@@ -22,14 +22,14 @@ ...@@ -22,14 +22,14 @@
<send retrans="500"> <send retrans="500">
<![CDATA[ <![CDATA[
REGISTER sip:192.168.50.79 SIP/2.0 REGISTER sip:[remote_ip] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];rport;branch=[branch] Via: SIP/2.0/[transport] [local_ip]:[local_port];rport;branch=[branch]
Max-Forward: 70 Max-Forward: 70
From: <sip:27182@[local_ip]:[local_port]>;tag=[call_number] From: <sip:27182@[remote_ip]:[remote_port]>;tag=[call_number]
To: <sip:27182@192.168.50.79:[local_port]> To: <sip:27182@[remote_ip]:[remote_port]>
Call-ID: [call_id] Call-ID: REG///[call_id]
CSeq: 1 REGISTER CSeq: 1 REGISTER
Contact: <sip:27182@[local_ip]:[local_port]> Contact: <sip:27182@[remote_ip]:[remote_port]>
Content-Length: 0 Content-Length: 0
Expires: 300 Expires: 300
...@@ -42,14 +42,14 @@ ...@@ -42,14 +42,14 @@
<send retrans="500"> <send retrans="500">
<![CDATA[ <![CDATA[
REGISTER sip:192.168.50.79 SIP/2.0 REGISTER sip:[remote_ip] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];rport;branch=[branch] Via: SIP/2.0/[transport] [local_ip]:[local_port];rport;branch=[branch]
Max-Forwards: 70 Max-Forwards: 70
From: <sip:27182@[local_ip]:[local_port]>;tag=[call_number] From: <sip:27182@[remote_ip]:[remote_port]>;tag=[call_number]
To: <sip:27182@192.168.50.79:[local_port]> To: <sip:27182@[remote_ip]:[remote_port]>
Call-ID: [call_id] Call-ID: REG///[call_id]
CSeq: 1 REGISTER CSeq: 2 REGISTER
Contact: <sip:27182@[local_ip]:[local_port]> Contact: <sip:27182@[remote_ip]:[remote_port]>
Content-Length: 0 Content-Length: 0
Expires: 300 Expires: 300
[authentication username=27182 password=1234] [authentication username=27182 password=1234]
...@@ -60,16 +60,17 @@ ...@@ -60,16 +60,17 @@
<recv response="200"> <recv response="200">
</recv> </recv>
<pause milliseconds="200"/>
<send retrans="500"> <send retrans="500">
<![CDATA[ <![CDATA[
INVITE sip:31416@192.168.50.79 SIP/2.0 INVITE sip:2000@[remote_ip] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch] Via: SIP/2.0/[transport] [local_ip]:[local_port];rport;branch=[branch]
From: <sip:27182@[local_ip]:[local_port]>;tag=[call_number] From: <sip:27182@[remote_ip]:[remote_port]>;tag=[call_number]
To: <sip:31416@192.168.50.79:[remote_port]> To: <sip:2000@[remote_ip]:[remote_port]>
Call-ID: [call_id] Call-ID: [call_id]
CSeq: 1 INVITE CSeq: 3 INVITE
Contact: sip:27182@[local_ip]:[local_port] Contact: sip:27182@[local_ip]:[local_port]
Max-Forwards: 70 Max-Forwards: 70
Subject: Functional Test Subject: Functional Test
...@@ -87,36 +88,73 @@ ...@@ -87,36 +88,73 @@
]]> ]]>
</send> </send>
<recv response="100" optional="true"> <recv response="401" auth="true">
</recv> </recv>
<recv response="180" optional="true"> <pause milliseconds="200"/>
</recv>
<send>
<![CDATA[
ACK sip:27182@[remote_ip] SIP/2.0
Max-Forwards: 70
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
From: <sip:27182@[remote_ip]:[remote_port]>;tag=[call_number]
To: <sip:2000@[remote_ip]:[remote_port]>
Call-ID: [call_id]
CSeq: 4 ACK
Subject: Functional Test
Content-Length: 0
]]>
</send>
<send retrans="500">
<![CDATA[
INVITE sip:2000@[remote_ip] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];rport;branch=[branch]
From: <sip:27182@:[remote_ip]:[remote_port]>;tag=[call_number]
To: <sip:2000@[remote_ip]:[remote_port]>
Call-ID: [call_id]
CSeq: 5 INVITE
Contact: sip:27182@[local_ip]:[local_port]
Max-Forwards: 70
Subject: Functional Test
Content-Type: application/sdp
Content-Length: [len]
[authentication username=27182 password=1234]
v=0
o=user1 53655765 2353687637 IN IP[local_ip_type] [local_ip]
s=-
c=IN IP[media_ip_type] [media_ip]
t=0 0
m=audio [media_port] RTP/AVP 0
a=rtpmap:0 PCMU/8000
]]>
</send>
<!-- Do something different on an optional receive --> <recv response="100">
<recv response="403" optional="true" next="1">
</recv> </recv>
<recv response="180">
</recv>
<recv response="200"> <recv response="200">
<action>
<ereg regexp="ua25"
search_in="hdr"
header="From: "
assign_to="8"/>
</action>
</recv> </recv>
<!-- set variable 8 above on 25th call, send the ACK but skip the pause for it --> <send>
<send next="1" test="8">
<![CDATA[ <![CDATA[
ACK sip:31416@192.168.50.79 SIP/2.0 ACK sip:2000@192.168.50.79 SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch] Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
From: <sip:27182@[local_ip]:[local_port]>;tag=[call_number] From: <sip:27182@[local_ip]:[local_port]>;tag=[call_number]
To: <sip:31416@192.168.50.79:[remote_port]> To: <sip:2000@192.168.50.79:[remote_port]>
Call-ID: [call_id] Call-ID: [call_id]
CSeq: 1 ACK CSeq: 5 ACK
Contact: sip:27182@[local_ip]:[local_port] Contact: sip:27182@[local_ip]:[local_port]
Max-Forwards: 70 Max-Forwards: 70
Subject: Functional Test Subject: Functional Test
...@@ -125,19 +163,15 @@ ...@@ -125,19 +163,15 @@
]]> ]]>
</send> </send>
<pause milliseconds="5000"/>
<label id="1"/>
<send retrans="500"> <send retrans="500">
<![CDATA[ <![CDATA[
BYE sip:31416@192.168.50.79 SIP/2.0 BYE sip:2000@192.168.50.79 SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch] Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
From: <sip:27182@[local_ip]:[local_port]>;tag=[call_number] From: <sip:27182@[local_ip]:[local_port]>;tag=[call_number]
To: <sip:31416@192.168.50.79:[remote_port]> To: <sip:2000@192.168.50.79:[remote_port]>
Call-ID: [call_id] Call-ID: [call_id]
CSeq: 2 BYE CSeq: 6 BYE
Contact: sip:27182@[local_ip]:[local_port] Contact: sip:27182@[local_ip]:[local_port]
Max-Forwards: 70 Max-Forwards: 70
Subject: Functional Test Subject: Functional Test
...@@ -146,16 +180,7 @@ ...@@ -146,16 +180,7 @@
]]> ]]>
</send> </send>
<recv response="200" crlf="true">
</recv>
<pause milliseconds="4000"/>
<!-- definition of the response time repartition table (unit is ms) -->
<ResponseTimeRepartition value="10, 20, 30, 40, 50, 100, 150, 200"/>
<!-- definition of the call length repartition table (unit is ms) --> <pause milliseconds="1000"/>
<CallLengthRepartition value="10, 50, 100, 500, 1000, 5000, 10000"/>
</scenario> </scenario>
...@@ -11,10 +11,10 @@ function test_ip2ipcall { ...@@ -11,10 +11,10 @@ function test_ip2ipcall {
# start sflphoned # start sflphoned
/usr/lib/sflphone/sflphoned& /usr/lib/sflphone/sflphoned&
#wait some time to make sure sflphone is started # wait some time to make sure sflphoned is started
sleep 2; sleep 2;
#run python client and associated script # run python client and script to make calls
python ../tools/pysflphone/pysflphone_testdbus.py python ../tools/pysflphone/pysflphone_testdbus.py
# kill every one # kill every one
...@@ -24,8 +24,22 @@ function test_ip2ipcall { ...@@ -24,8 +24,22 @@ function test_ip2ipcall {
function test_accountcall { function test_accountcall {
sipp -sf accountcalluac.xml 192.168.50.79 -i 192.168.50.182 -p ${SERVERPORT} # start sflphoned
# /usr/lib/sflphone/sflphoned&
# wait some time to make sure sflphoned is started
#sleep 2;
# python ../tools/pysflphone/pysflphone_testdbus.py &
#sleep 2;
# start sipp client and send calls
sipp -sf accountcalluac.xml 192.168.50.79 -i 192.168.50.182 -p ${SERVERPORT} -l 1
# kill every one
killall sipp
killall sflphoned
} }
# function called if CTRL-C detected # function called if CTRL-C detected
...@@ -38,4 +52,6 @@ bashtrap() ...@@ -38,4 +52,6 @@ bashtrap()
# Here Start the Test suite # Here Start the Test suite
test_ip2ipcall # test_ip2ipcall
\ No newline at end of file
test_accountcall
\ No newline at end of file
...@@ -4,6 +4,8 @@ import sys ...@@ -4,6 +4,8 @@ import sys
import getopt import getopt
from threading import Event
from sflphonectrlsimple import SflPhoneCtrlSimple from sflphonectrlsimple import SflPhoneCtrlSimple
...@@ -82,16 +84,27 @@ class SflPhoneTests(SflPhoneCtrlSimple): ...@@ -82,16 +84,27 @@ class SflPhoneTests(SflPhoneCtrlSimple):
print "Account with ID " + accountID + " removed" print "Account with ID " + accountID + " removed"
# Open sflphone and connect to sflphoned through dbus # Open sflphone and connect to sflphoned through dbus
sflphone = SflPhoneTests() sflphone = SflPhoneTests()
sflphone.start()
# Test 1: Makke approximately one IP2IP call per second # Test 1: Makke approximately one IP2IP call per second
# to a sipp uas on local addrress # to a sipp uas on local addrress
#sflphone.test_make_iptoip_call() #sflphone.test_make_iptoip_call()
# Test 2:
accountID = sflphone.test_create_account() # Test 2: - Create an account on Asterisk
# - Wait for incoming calls
# - Once a call is received, answer
# - The call should then be hung up by caller
# accountID = sflphone.test_create_account()
# sflphone.test_make_account_call() # sflphone.test_make_account_call()
time.sleep(0.3) # time.sleep(0.3)
# sflphone.test_remove_account(accountID) # sflphone.test_remove_account(accountID)
...@@ -32,6 +32,7 @@ import time ...@@ -32,6 +32,7 @@ import time
import hashlib import hashlib
from threading import Thread from threading import Thread
from threading import Event
from Errors import * from Errors import *
...@@ -42,21 +43,23 @@ except ImportError, e: ...@@ -42,21 +43,23 @@ except ImportError, e:
raise SflPhoneError("No python-dbus module found") raise SflPhoneError("No python-dbus module found")
class SflPhoneCtrlSimple(object): class SflPhoneCtrlSimple(Thread):
"""Simple class for controlling SflPhoned through DBUS""" """Simple class for controlling SflPhoned through DBUS"""
# list of active calls (known by the client) # list of active calls (known by the client)
activeCalls = {} activeCalls = {}
def __init__(self, name=sys.argv[0]): def __init__(self, name=sys.argv[0]):
Thread.__init__(self)
# current active account # current active account
self.account = None self.account = None
# client name # client name
self.name = name self.name = name
# client registered to sflphoned ? # client registered to sflphoned ?
self.registered = False self.registered = False
self.register() self.register()
self.event = Event()
self.currentCallId = ""
def __del__(self): def __del__(self):
...@@ -139,6 +142,9 @@ class SflPhoneCtrlSimple(object): ...@@ -139,6 +142,9 @@ class SflPhoneCtrlSimple(object):
def onIncomingCall(self, account, callid, to): def onIncomingCall(self, account, callid, to):
print "Incoming call: " + account + ", " + callid + ", " + to print "Incoming call: " + account + ", " + callid + ", " + to
self.activeCalls[callid] = {'Account': account, 'To': to, 'State': '' } self.activeCalls[callid] = {'Account': account, 'To': to, 'State': '' }
self.currentCallId = callid
self.event.set()
Answer(callid)
# On call state changed event, set the values for new calls, # On call state changed event, set the values for new calls,
# or delete the call from the list of active calls # or delete the call from the list of active calls
...@@ -559,3 +565,13 @@ class SflPhoneCtrlSimple(object): ...@@ -559,3 +565,13 @@ class SflPhoneCtrlSimple(object):
m.update(str(t) + str(r)) m.update(str(t) + str(r))
callid = m.hexdigest() callid = m.hexdigest()
return callid return callid
def run(self):
while(True):
print "Waiting Event"
self.event.wait()
sflphone.Accept(sflphone.currentCallId)
self.event.clear()
print "Call Accepted"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment