summaryrefslogtreecommitdiffstats
path: root/For Weekly Test/Old/20-07-2011
diff options
context:
space:
mode:
Diffstat (limited to 'For Weekly Test/Old/20-07-2011')
-rw-r--r--For Weekly Test/Old/20-07-2011/Controller.py183
-rw-r--r--For Weekly Test/Old/20-07-2011/LogFileClass.py21
-rw-r--r--For Weekly Test/Old/20-07-2011/LogFileClass.pycbin0 -> 1534 bytes
-rw-r--r--For Weekly Test/Old/20-07-2011/Testing.py44
-rw-r--r--For Weekly Test/Old/20-07-2011/UniSIPRecHandler.log15
-rw-r--r--For Weekly Test/Old/20-07-2011/classClient.py123
-rw-r--r--For Weekly Test/Old/20-07-2011/classClient.pycbin0 -> 3673 bytes
-rw-r--r--For Weekly Test/Old/20-07-2011/classController.py239
-rw-r--r--For Weekly Test/Old/20-07-2011/classController.pycbin0 -> 4893 bytes
-rw-r--r--For Weekly Test/Old/20-07-2011/classDB.py271
-rw-r--r--For Weekly Test/Old/20-07-2011/classDb.pycbin0 -> 5978 bytes
-rw-r--r--For Weekly Test/Old/20-07-2011/classPing.py28
-rw-r--r--For Weekly Test/Old/20-07-2011/classPing.pycbin0 -> 1283 bytes
-rw-r--r--For Weekly Test/Old/20-07-2011/classServer.py152
-rw-r--r--For Weekly Test/Old/20-07-2011/classServer.pycbin0 -> 4651 bytes
-rw-r--r--For Weekly Test/Old/20-07-2011/gsmcall_.py105
-rw-r--r--For Weekly Test/Old/20-07-2011/gsmincom_.py148
-rw-r--r--For Weekly Test/Old/20-07-2011/landlineCall.py135
-rw-r--r--For Weekly Test/Old/20-07-2011/landlineReceiver.py111
-rw-r--r--For Weekly Test/Old/20-07-2011/localsipReceiver.py112
-rw-r--r--For Weekly Test/Old/20-07-2011/sipCall.py135
-rw-r--r--For Weekly Test/Old/20-07-2011/sipCallHandler.log112
-rw-r--r--For Weekly Test/Old/20-07-2011/sipReceiver.py111
23 files changed, 2045 insertions, 0 deletions
diff --git a/For Weekly Test/Old/20-07-2011/Controller.py b/For Weekly Test/Old/20-07-2011/Controller.py
new file mode 100644
index 0000000..c1d63a4
--- /dev/null
+++ b/For Weekly Test/Old/20-07-2011/Controller.py
@@ -0,0 +1,183 @@
+import sys
+import os
+import time
+import MySQLdb
+import subprocess
+
+
+import classClient #import class socket
+import classDb #import class db
+import classPing
+import classController
+from time import sleep
+
+
+
+sipNum = "4661929"
+landlnNum = "076145875681"
+unisipNum = "076120397897"
+
+
+sipCall = "sipCall.py"
+sipRec = "sipReceiver.py"
+landlnCall = "landlineCall.py"
+landlnRec = "landlineReceiver.py"
+localSipRec = "localsipReceiver.py"
+
+
+# Main software
+
+# Check DB connection
+db = classDb.DBMySQLConnection('root', 'randompasswordSQL', 'localhost', 'gsmselftesting')
+db.connectDB()
+print ""
+dbStatus = db.connectDB()
+
+
+if dbStatus == 1:
+
+ # Check Ping to the Every Handler
+ sipServer = classPing.Ping('132.230.4.8')
+ sipServerStatus = sipServer.ping(3)
+
+ sipGateServer = classPing.Ping('sipgate.de')
+ sipGateServerStatus = sipGateServer.ping(3)
+
+ sipLocalServer = classPing.Ping('132.230.252.228')
+ sipLocalServerStatus = sipLocalServer.ping(3)
+
+# Fetch The task information from DB
+ db.anyTasksToDo()
+ #x = ()
+
+ for item in db.tasksList:
+
+ taskID = item[0]
+ taskNo = item[1]
+ callFrom = item[2]
+ callTo = item[3]
+
+ print "Test ID : " , taskID
+ print "Caller : " , callFrom
+ print "Receiver : " , callTo
+
+ if callFrom == "sip":
+ if sipServerStatus == 0:
+ print "[failed] 500 Server Internal Error"
+
+ else:
+
+ if callTo == "gsmrz1":
+
+ x = classController.test(sipCall, "localhost", "gsmincom_.py", "localhost","4661455")
+ x.FuncTest()
+
+ db.addResult(taskID, x.testResult)
+
+ if x.repeatTest == True:
+ db.insertTaskIn2(callTo,callFrom,taskNo)
+
+ if callTo == "gsmrz2":
+
+ if gsmBox1Status == 0:
+ print "[failed] 500 Server Internal Error"
+
+ else:
+ x = classController.test(sipCall, "localhost", "Box1", "132.0.0.2","404")
+ x.FuncTest()
+
+ db.addResult(taskID, x.testResult)
+
+ if x.repeatTest == True:
+ db.insertTaskIn2(callTo,callFrom,taskNo)
+
+ if callTo == "gsmrz3":
+
+ if gsmBox2Status == 0:
+ print "[failed] 500 Server Internal Error"
+
+ else:
+ x = classController.test(sipCall, "localhost", "Box2", "132.0.0.3","405")
+ x.FuncTest()
+
+ db.addResult(taskID, x.testResult)
+
+ if x.repeatTest == True:
+ db.insertTaskIn2(callTo,callFrom,taskNo)
+
+ if callTo == "landline":
+
+ if sipGateServerStatus == 0:
+ print "[failed] 500 Server Internal Error"
+
+ else:
+ x = classController.test(sipCall, "localhost", landlnRec, "localhost",landlnNum)
+ x.FuncTest()
+
+ db.addResult(taskID, x.testResult)
+
+ if x.repeatTest == True:
+ db.insertTaskIn2(callTo,callFrom,taskNo)
+ sleep(5)
+
+ if callTo == "localsip":
+ if sipLocalServerStatus == 0:
+ print "[failed] 500 Server Internal Error"
+
+ else:
+ x = classController.test(sipCall, "localhost", localSipRec, "localhost",unisipNum)
+ x.FuncTest()
+
+ db.addResult(taskID, x.testResult)
+ sleep(5)
+
+ if callTo == "externalgsm":
+ x.FuncTest(sipCall, "localhost", o2Rec, "localhost","405")
+ db.addResult(taskID, testResult)
+
+ x.FuncTest(sipCall, "localhost", tmobileRec, "localhost","405")
+ db.addResult(taskID, testResult)
+
+ x.FuncTest(sipCall, "localhost", vodafoneRec, "localhost","405")
+ db.addResult(taskID, testResult)
+
+ x.FuncTest(sipCall, "localhost", "xx", "localhost","405")
+ db.addResult(taskID, testResult)
+
+
+
+ if callFrom =="gsmrz1":
+
+ if callTo =="sip":
+ if sipServerStatus == 0:
+ print "[failed] 500 Server Internal Error"
+
+ else:
+ x.FuncTest("gsmcall_.py", "localhost", sipRec, "localhost",sipNum)
+ db.addResult(taskID, testResult)
+ sleep(10)
+
+
+ if callTo =="gsmrz2":
+ if gsmBox1Status == 0:
+ print "[failed] 500 Server Internal Error"
+
+ else:
+ x.FuncTest("Box1", "132.0.0.2", sipRec, "localhost",sipNum)
+ db.addResult(taskID, testResult)
+
+ if callTo =="gsmrz3":
+ if gsmBox2Status == 0:
+ print "[failed] 500 Server Internal Error"
+
+ else:
+ x.FuncTest("Box2", "132.0.0.3", sipRec, "localhost",sipNum)
+ db.addResult(taskID, testResult)
+
+
+
+
+# will exit if DB connection failed
+else:
+ sys.exit(5)
+
diff --git a/For Weekly Test/Old/20-07-2011/LogFileClass.py b/For Weekly Test/Old/20-07-2011/LogFileClass.py
new file mode 100644
index 0000000..cb152f4
--- /dev/null
+++ b/For Weekly Test/Old/20-07-2011/LogFileClass.py
@@ -0,0 +1,21 @@
+import string
+import datetime
+
+class Logging:
+
+ def __init__(self, logFileName):
+ self.writeToFile = open(logFileName, 'a')
+ self.justStarted = 1
+
+ def logEvent(self, event):
+ now = str(datetime.datetime.now())
+ if self.justStarted == 1:
+ self.writeToFile.write('\n\n------------------STARTED THE LOGGING '+ now + ' ------------------\n')
+ self.justStarted = 0
+ else:
+ self.writeToFile.write('On: '+ now + '\t' + 'Event: ' +str(event) + '\n')
+
+ def closeLogging(self):
+ now = str(datetime.datetime.now())
+ self.writeToFile.write('------------------FINISHED THE LOGGING '+ now + ' ------------------')
+ self.writeToFile.close()
diff --git a/For Weekly Test/Old/20-07-2011/LogFileClass.pyc b/For Weekly Test/Old/20-07-2011/LogFileClass.pyc
new file mode 100644
index 0000000..511a60e
--- /dev/null
+++ b/For Weekly Test/Old/20-07-2011/LogFileClass.pyc
Binary files differ
diff --git a/For Weekly Test/Old/20-07-2011/Testing.py b/For Weekly Test/Old/20-07-2011/Testing.py
new file mode 100644
index 0000000..34316ee
--- /dev/null
+++ b/For Weekly Test/Old/20-07-2011/Testing.py
@@ -0,0 +1,44 @@
+import sys
+import os
+import time
+import MySQLdb
+import subprocess
+import signal
+
+import classClient
+import classDb
+import classPing
+
+from time import sleep
+
+command="--command=python sipCall.py"
+subprocess.Popen(args=["gnome-terminal", command])
+sleep(5)
+x = classClient.Connection("localhost", "50097")
+x.connect()
+origHandler = x.receiveData(0)
+print origHandler
+
+#command="--command=python localsipReceiver.py"
+#subprocess.Popen(args=["gnome-terminal", command])
+sleep(5)
+y = classClient.Connection("localhost", "50107")
+y.connect()
+
+while 1:
+ destHandler = y.receiveData(0)
+ if destHandler <> "":
+ break
+
+print destHandler
+
+if destHandler == "ready":
+ y.closeConnection()
+ y.connect()
+
+ #x.sendData("start|076120397897")
+while 1:
+ destHandlers = y.receiveData(0)
+ #origHandlers = x.receiveData(0)
+
+ print destHandlers#, origHandlers
diff --git a/For Weekly Test/Old/20-07-2011/UniSIPRecHandler.log b/For Weekly Test/Old/20-07-2011/UniSIPRecHandler.log
new file mode 100644
index 0000000..a203845
--- /dev/null
+++ b/For Weekly Test/Old/20-07-2011/UniSIPRecHandler.log
@@ -0,0 +1,15 @@
+
+
+------------------STARTED THE LOGGING 2011-07-19 13:40:01.724672 ------------------
+On: 2011-07-19 13:40:01.724716 Event: Connect to Controller via port 50107
+On: 2011-07-19 13:40:03.587386 Event: Register Account to University SIP server
+On: 2011-07-19 13:40:03.587623 Event: 100
+On: 2011-07-19 13:40:08.589638 Event: Handler Ready
+On: 2011-07-19 13:40:08.621158 Event: {Call "mpselftest1" <sip:4661928@132.230.252.228>}
+On: 2011-07-19 13:40:09.122499 Event: Answer call
+On: 2011-07-19 13:40:09.623197 Event: Hangup call
+On: 2011-07-19 13:40:09.623657 Event: 200
+On: 2011-07-19 13:40:10.144886 Event: Terminate
+On: 2011-07-19 13:40:10.145237 Event: Un-Rigester SIP Account
+On: 2011-07-19 13:40:11.577828 Event: Close Connection to the Controller
+On: 2011-07-19 13:40:11.577983 Event: Close Connection to the Controller
diff --git a/For Weekly Test/Old/20-07-2011/classClient.py b/For Weekly Test/Old/20-07-2011/classClient.py
new file mode 100644
index 0000000..46c3b00
--- /dev/null
+++ b/For Weekly Test/Old/20-07-2011/classClient.py
@@ -0,0 +1,123 @@
+import socket
+import sys
+import os
+import string
+import signal
+
+class TimeoutException(Exception):
+ pass
+
+class Connection:
+ def __init__(self, h, p):
+ self.host = h
+ self.port = p
+ self.s = None
+ self.connected = 0
+
+ self.debugMode = 0
+
+ def connect(self):
+ self.s = None
+
+ for res in socket.getaddrinfo(self.host, self.port, socket.AF_UNSPEC, socket.SOCK_STREAM):
+ af, socktype, proto, canonname, sa = res
+ try:
+ self.s = socket.socket(af, socktype, proto)
+ self.s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) #this resolves the bug with live packets
+ except socket.error, msg:
+ self.s = None
+ self.connected = 0
+ continue
+ try:
+ self.s.connect(sa)
+ except socket.error, msg:
+ self.s.close()
+ self.connected = 0
+ self.s = None
+ continue
+ break
+ if self.s is None:
+ self.connected = 0
+ return 0 #couldn't connect to the server
+ else:
+ self.connected = 1
+ return 1 #successfully connected to the server
+
+ def sendData(self, data):
+ if self.connected == 1:
+ try:
+ self.s.send(data)
+ return 1
+ except Exception, e:
+ if self.debugMode == 1:
+ import traceback
+ print traceback.format_exc()
+ print e
+ self.connected = 0
+ return 2
+
+ else:
+ return 0
+
+ def receiveData(self, timeout):
+ if self.connected == 1:
+
+ def timeout_handler(signum, frame):
+ raise TimeoutException()
+
+ old_handler = signal.signal(signal.SIGALRM, timeout_handler)
+ signal.alarm(timeout) #start the timeout alarm, for timeout seconds
+ try:
+ data = self.s.recv(1024)
+
+ #stop the timeout function
+ signal.signal(signal.SIGALRM, old_handler)
+ signal.alarm(0)
+
+ return data
+
+
+ except TimeoutException:
+ #timeout happened
+ signal.signal(signal.SIGALRM, old_handler)
+ signal.alarm(0)
+ return 'TIMEOUT'
+
+ except Exception, e:
+
+ signal.signal(signal.SIGALRM, old_handler)
+ signal.alarm(0)
+
+ error = str(e)
+ if self.debugMode == 1:
+ import traceback
+ print traceback.format_exc()
+ print e
+ self.connected = 0
+ if error[0:11] == '[Errno 104]':
+ return 3 #the other side reset the connection,[Errno 104] Connection reset by peer
+
+ return 2
+ else:
+ return 0
+
+ def closeConnection(self):
+ if self.connected == 1:
+ try:
+ self.connected = 0
+ SHUT_RDWR = 2
+ self.s.shutdown(SHUT_RDWR)
+ self.s.close()
+ return 1
+ except Exception, e:
+ self.connected = 0
+ error = str(e)
+ if self.debugMode == 1:
+ import traceback
+ print traceback.format_exc()
+ print e
+ if error[0:11] == '[Errno 107]':
+ return 3 #the other side closed the connection before us, [Errno 107] Transport endpoint is not connected
+ return 2
+ else:
+ return 0
diff --git a/For Weekly Test/Old/20-07-2011/classClient.pyc b/For Weekly Test/Old/20-07-2011/classClient.pyc
new file mode 100644
index 0000000..fbfa63d
--- /dev/null
+++ b/For Weekly Test/Old/20-07-2011/classClient.pyc
Binary files differ
diff --git a/For Weekly Test/Old/20-07-2011/classController.py b/For Weekly Test/Old/20-07-2011/classController.py
new file mode 100644
index 0000000..b7e3bff
--- /dev/null
+++ b/For Weekly Test/Old/20-07-2011/classController.py
@@ -0,0 +1,239 @@
+import sys
+import os
+import time
+import MySQLdb
+import subprocess
+import signal
+
+import classClient
+import classDb
+import classPing
+
+from time import sleep
+
+class TimeoutException(Exception):
+ pass
+
+class test:
+
+ def __init__(self, orig, origAdd, dest, destAdd, destNo):
+ self.orig = orig
+ self.origAdd = origAdd
+ self.dest = dest
+ self.destAdd = destAdd
+ self.destNo = destNo
+ self.repeatTest = None
+ self.portOrig = None
+ self.resultOrig = None
+ self.resultDest = None
+ self.testResult = None
+ self.x = None
+ self.y = None
+
+ def FuncTest(self):
+
+ def timeout_handler(signum, frame):
+ raise TimeoutException()
+ print ""
+ print "====================== Preparing Test ======================"
+
+ try:
+
+ if self.dest =="gsmBox1" or self.dest =="gsmBox2":
+
+ if self.dest =="gsmBox1":
+ portOrig = 50095
+
+ if self.dest =="gsmBox2":
+ portOrig = 50096
+
+ print ""
+ print "Connecting to Caller handler"
+ x.connect()
+ x.sendData('be caller')
+
+ else:
+ # open SIP caller handler
+
+ command="--command=python " +self.orig
+ subprocess.Popen(args=["gnome-terminal", command])
+
+ sleep(5)
+
+ if self.orig=="sipCall.py":
+ self.portOrig = 50097
+
+ if self.orig == "landlineCall.py":
+ self.portOrig = 50099
+
+ if self.orig == "LocalSIPCall.py":
+ self.portOrig = 50100
+
+
+ x = classClient.Connection(self.origAdd,self.portOrig)
+ print ""
+ print "Connecting to Caller handler"
+ x.connect()
+
+ # wait respond from origin handler
+ signal.signal(signal.SIGALRM, timeout_handler)
+ signal.alarm(60)
+
+ while 1:
+ try:
+ origHandler = x.receiveData(0)
+ if origHandler <> "":
+ break
+
+ except TimeoutException:
+ origHandler = "failed"
+ break
+
+
+ if origHandler == "ready":
+ print "Caller handler : Ready"
+ print ""
+ try:
+ if self.dest =="gsmBox1" or self.dest =="gsmBox2":
+
+ if self.dest =="gsmBox1":
+ self.portDest = 50102
+
+ if self.dest =="gsmBox2":
+ self.portDest = 50103
+
+ y = classClient.Connection(self.destAdd, self.portDest)
+ print "Connecting to Receiver handler"
+ y.connect()
+ y.sendData('receiver')
+
+ else:
+ command="--command=python " +self.dest
+ subprocess.Popen(args=["gnome-terminal", command])
+
+ sleep(2)
+
+ if self.dest=="SIPReceiver.py":
+ self.portDest = 50104
+
+ if self.dest == "landlineReceiver.py":
+ self.portDest = 50106
+
+ if self.dest == "localsipReceiver.py":
+ self.portDest = 50107
+
+ y = classClient.Connection(self.destAdd, self.portDest)
+ print "Connecting to Receiver handler"
+ y.connect()
+
+
+ signal.signal(signal.SIGALRM, timeout_handler)
+ signal.alarm(60)
+
+ while 1:
+ try:
+ destHandler = y.receiveData(0)
+ if destHandler <> "":
+ break
+
+ except TimeoutException:
+ destHandler = "failed"
+ break
+
+ if destHandler == "ready":
+
+ print "Receiver handler : Ready"
+
+ x.sendData("start|"+self.destNo)#send message to handler to start the call
+
+
+ signal.signal(signal.SIGALRM, timeout_handler)
+ signal.alarm(120)
+
+ print ""
+ print "------------ Test Result ------------"
+ print ""
+
+ while 1:
+ try:
+ sleep(0.5)
+ self.resultOrig = x.receiveData(0)
+ self.resultDest = y.receiveData(0)
+
+ if self.resultOrig <> "" and self.resultDest <> "":
+ break
+
+ except TimeoutException:
+ self.resultOrig = 486
+ self.resultDest = 486
+ break
+
+ #if failed, tell everybody to try one more time
+ if self.resultOrig == 486 or self.resultDest == 486:
+
+ x.sendData("start|"+self.destNo)
+
+ signal.signal(signal.SIGALRM, timeout_handler)
+ signal.alarm(120)
+
+ while 1:
+ try:
+ sleep(0.5)
+ self.resultOrig = x.receiveData(0)
+ self.resultDest = y.receiveData(0)
+
+ if self.resultOrig <> "" and self.resultDest <> "":
+ print "here"
+ break
+
+ except TimeoutException:
+ self.resultOrig = 486
+ self.resultDest = 486
+ break
+
+ #if still failed, we make automatic test vice versa
+
+ if self.resultOrig == 486 or self.resultDest == 486:
+ self.testResult = 486
+ self.repeatTest = True
+
+ print "Second test result origin: ", self.resultOrig
+ print "Second test result Destination: ", self.resultDest
+ else:
+ self.testResult = 200
+
+ print "Second test result origin: ", self.resultOrig
+ print "Second test result Destination: ", self.resultDest
+ x.sendData('487')
+ y.sendData('487')
+
+ else:
+
+ self.testResult = 200
+
+ print "Test Result origin: ", self.resultOrig
+ print "Test Result Destination: ", self.resultDest
+ x.sendData('487')
+ y.sendData('487')
+
+ else:
+ self.testResult = 604
+ print "604 General Handler Error: Destination handler no respond"
+ #tell Caller handler to terminate because receiver doesnt work
+ x.sendData('487')
+
+ y.closeConnection()
+
+ except ValueError:
+ print "601 General Handler Error: Could not open Destination handler"
+ self.testResult = 601
+ else:
+ self.testResult = 605
+ print "605 General Handler Error: Origin handler no respond"
+
+ x.closeConnection()
+
+ except ValueError:
+ testResult = 602
+ print "602 General Handler Error: Could not open Origin handler"
+
diff --git a/For Weekly Test/Old/20-07-2011/classController.pyc b/For Weekly Test/Old/20-07-2011/classController.pyc
new file mode 100644
index 0000000..c649bdb
--- /dev/null
+++ b/For Weekly Test/Old/20-07-2011/classController.pyc
Binary files differ
diff --git a/For Weekly Test/Old/20-07-2011/classDB.py b/For Weekly Test/Old/20-07-2011/classDB.py
new file mode 100644
index 0000000..11a109f
--- /dev/null
+++ b/For Weekly Test/Old/20-07-2011/classDB.py
@@ -0,0 +1,271 @@
+import MySQLdb
+import string
+
+class DBMySQLConnection:
+ def __init__(self, username, password, host, dbname):
+ #initialize at the start all the user parameters
+ self.usern = username
+ self.passw = password
+ self.host = host
+ self.db = dbname
+ self.connectionCreated = 0
+ self.tasksList = list()
+ global debugMode
+ debugMode = 0
+
+ def connectDB(self):
+ try:
+ #try the connection
+ self.datBaseConn=MySQLdb.connect(self.host,self.usern, self.passw,self.db)
+ self.datBaseConn.paramstyle = 'format'
+ self.cur = self.datBaseConn.cursor() #make the cursor, used for sending queries
+ self.connectionCreated = 1 #use it as an indicator that the connection was created
+ return 1
+
+ except MySQLdb.Error, e:
+ #if we have an error then try to catch it
+ error=str(e)
+ if error[1:5] == '1045':
+ #wrong username or password
+ return 0
+ elif error[1:5] == '2002':
+ #can't connect to mysql, mysql shutdown or wrong host
+ return 2
+ else:
+ if debugMode == 1:
+ print error
+ return 3
+
+ def closeDBConn(self):
+ #close the connection to the database here
+ if self.connectionCreated == 1:
+ try:
+ #close the cursor and then the connection to the DB
+ self.cur.close()
+ self.datBaseConn.close()
+ return 1
+ except MySQLdb.Error, e:
+ #in case of an error
+ if debugMode == 1:
+ error = str(e)
+ print error
+ return 3
+ else:
+ #I never really had a connection
+ return 0
+
+ def anyTasksToDo(self):
+ #see are there any jobs to be executed and make a list out of it
+ if self.connectionCreated == 1:
+ try:
+ self.cur.execute("SELECT * FROM TempTaskTable")
+ output = self.cur.fetchall() #get the mysql response
+ #parse the output from the mysql by creating a list
+ #with lists where each attribue(column) gets independent
+ #element of the list
+ for record in output:
+ columns = list()
+ for entry in record:
+ columns.append(str(entry))
+ self.tasksList.append(columns)
+ return 1
+ except MySQLdb.Error, e:
+ error = str(e)
+ if error[1:5] == '1146':
+ return 2 #the table doesn't exist
+ if debugMode == 1:
+ print str(e)
+ return 3
+ else:
+ return 0
+
+ def cleanTasksList(self):
+ if self.connectionCreated == 1:
+ del self.tasksList[:]
+ return 1
+ else:
+ return 0
+
+ def removeTaskFromList(self, taskID):
+ #remove only one task from the task list
+ if self.connectionCreated == 1:
+ for index in range(len(self.tasksList)):
+ item = self.tasksList[index]
+ if item[0] == str(taskID):
+ #self.tasksList.remove(index)
+ #print 'found it'
+ del self.tasksList[index]
+ return 1 #deleted taskID
+
+ return 2 #didn't find that taskID
+ else:
+ return 0
+
+ def deviceAddress(self,deviceName):
+ if self.connectionCreated == 1:
+ try:
+ successful = self.cur.execute("SELECT `deviceIP` FROM DeviceAddress where `deviceName`=%s", deviceName)
+ #self.cur.execute()
+ output = self.cur.fetchall() #get the mysql response
+ #parse the output from the mysql by creating a list
+ #with lists where each attribue(column) gets independent
+ #element of the list
+ deviceAddr = ''
+ for record in output:
+ columns = list()
+ for entry in record:
+ deviceAddr = str(entry)
+ return deviceAddr
+ except MySQLdb.Error, e:
+ error = str(e)
+ if error[1:5] == '1146':
+ return 2 #the table doesn't exist
+ if debugMode == 1:
+ print str(e)
+ return 3 #some error happened
+ else:
+ return 0 #I am not connected
+
+ def updateTaskResult(self, taskID, status):
+ if self.connectionCreated == 1:
+ try:
+ successful = self.cur.execute("UPDATE TaskTable SET status=%i WHERE taskID=%i"%(int(status), int(taskID)))
+ output = self.cur.fetchone()
+
+ if debugMode == 1:
+ print output
+ if successful == 0:
+ return 1 #update successful
+ else:
+ return 4 #taskID doesn't exist
+
+ except MySQLdb.Error, e:
+ if debugMode == 1:
+ print str(e)
+ return 3
+ else:
+ return 0
+
+ def updatePingResult(self, taskNo, sipServer, sipGate, sipLoc, gsmBox1, gsmBox2):
+ if self.connectionCreated == 1:
+ try:
+ successful = self.cur.execute("UPDATE PingResultTable SET sipServer=%i, sipGate=%i, sipLoc=%i, gsmBox1=%i, gsmBox2=%i WHERE taskNo=%i"%(int(sipServer), int(sipGate), int(sipLoc), int(gsmBox1), int(gsmBox2), int(taskNo)))
+ output = self.cur.fetchone()
+
+ if debugMode == 1:
+ print output
+ if successful == 0:
+ return 1 #ping table updated
+ else:
+ return 4 #the taskNo didn't exist
+
+
+ except MySQLdb.Error, e:
+ if debugMode == 1:
+ print str(e)
+ return 3
+ else:
+ return 0
+
+ def deleteTempTask(self, taskID):
+ if self.connectionCreated == 1:
+ try:
+ successful = self.cur.execute("DELETE FROM TempTaskTable WHERE taskID=%i"%(int(taskID)))
+ output = self.cur.fetchone()
+
+ if debugMode == 1:
+ print output
+
+ if successful == 1:
+ return 1 #deleted it
+ else:
+ return 4 #that taskID didn't exist or something else
+ except MySQLdb.Error, e:
+ if debugMode == 1:
+ print str(e)
+ return 3
+
+ else:
+ return 0
+
+ def addResult(self, taskID, result):
+ if self.connectionCreated == 1:
+ try:
+ successful = self.cur.execute("INSERT INTO ResultTable(taskID, result) VALUES ('%i', '%i')"%(int(taskID), int(result)))
+ output = self.cur.fetchone()
+
+ if debugMode == 1:
+ print output
+ if successful == 1:
+ return 1 #successfully added the result
+ else:
+ return 4 #hmmm
+ except MySQLdb.Error, e:
+ error = str(e)
+ if error[1:5] == '1062':
+ return 2 #duplicate entry for the key
+ if debugMode == 1:
+ print str(e)
+ return 3
+ else:
+ return 0
+
+
+ def insertTaskIn2(self, fromDevice, toDevice, taskNo):
+ if self.connectionCreated == 1:
+ try:
+ #I used here a transaction since I want the mysql to execute a few commands and tell me was it successful rather than to execute some and there happens a mistake and one part is updated and the other isn't
+ newQuery = "START TRANSACTION; INSERT INTO `TaskTable` (`taskNo`, `from`, `to`, `status`) VALUES ('" + str(taskNo) + "', '" + str(fromDevice) + "', '" + str(toDevice) +"', '0'); SELECT @taskID := LAST_INSERT_ID(); INSERT INTO `TempTaskTable` (`taskID`, `taskNo`, `from`, `to`) VALUES (@taskID, '" + str(taskNo) + "', '" + str(fromDevice) + "', '"+ str(toDevice) + "'); COMMIT;"
+
+
+ successful = self.cur.execute(newQuery)
+ output = self.cur.fetchone()
+
+
+ #without closing the cursos we get a MySQL error, the mistake is an internal mistak of the MySQLdb python library
+ # self.cur.close()
+ # self.cur = self.datBaseConn.cursor()
+
+ while self.cur.nextset() is not None: pass
+
+ newQuery1 = 'SELECT taskID FROM `TempTaskTable` ORDER BY taskID DESC LIMIT 1';
+ successful1 = self.cur.execute(newQuery1)
+ record = self.cur.fetchone()
+
+ columns = list()
+ for entry in record:
+ columns.append(str(entry))
+
+ columns.append(str(taskNo))
+ columns.append(str(fromDevice))
+ columns.append(str(toDevice))
+ self.tasksList.append(columns)
+
+ return 1
+
+ if debugMode == 1:
+ print output
+
+ except MySQLdb.Error, e:
+ error = str(e)
+ if debugMode == 1:
+ print str(e)
+ if error[1:5] == '1062':
+ return 2 #duplicate entry for the key
+ return 3
+ else:
+ return 0
+
+
+ def searchTaskList(self, fromDevice, toDevice):
+ if self.connectionCreated == 1:
+ for item in self.tasksList:
+ taskID = item[0]
+ taskNo = item[1]
+ callFrom = item[2]
+ callTo = item [3]
+ if callFrom == fromDevice and callTo == toDevice:
+ return 1 #that task was found
+ return 2 #that task wasn't found
+ else:
+ return 0
diff --git a/For Weekly Test/Old/20-07-2011/classDb.pyc b/For Weekly Test/Old/20-07-2011/classDb.pyc
new file mode 100644
index 0000000..8bf4d7c
--- /dev/null
+++ b/For Weekly Test/Old/20-07-2011/classDb.pyc
Binary files differ
diff --git a/For Weekly Test/Old/20-07-2011/classPing.py b/For Weekly Test/Old/20-07-2011/classPing.py
new file mode 100644
index 0000000..e13b32b
--- /dev/null
+++ b/For Weekly Test/Old/20-07-2011/classPing.py
@@ -0,0 +1,28 @@
+import subprocess
+import string
+
+class Ping:
+
+ def __init__(self, pingAddress):
+ self.pingAddress = pingAddress
+
+ def ping(self,numberTries):
+ tried = 1
+ while numberTries >= tried:
+ tried += 1
+ #the parameter c 1 means only one ping to be sent, parameter W 3 means how many seconds the time out should be, 3 seconds
+ ping_cmd = subprocess.Popen(['ping', self.pingAddress, '-c', '1', '-W', '2'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT).communicate()[0]
+
+ pingAlive = int(string.find(ping_cmd, '1 received'))
+ unknownHost = int(string.find(ping_cmd, 'unknown host'))
+
+
+ if pingAlive != -1:
+ break
+
+ if unknownHost != -1:
+ return 2 #unknown host
+ if pingAlive != -1:
+ return 1 #ping works fine
+ else:
+ return 0 #no ping response
diff --git a/For Weekly Test/Old/20-07-2011/classPing.pyc b/For Weekly Test/Old/20-07-2011/classPing.pyc
new file mode 100644
index 0000000..b664a9c
--- /dev/null
+++ b/For Weekly Test/Old/20-07-2011/classPing.pyc
Binary files differ
diff --git a/For Weekly Test/Old/20-07-2011/classServer.py b/For Weekly Test/Old/20-07-2011/classServer.py
new file mode 100644
index 0000000..93c2f8e
--- /dev/null
+++ b/For Weekly Test/Old/20-07-2011/classServer.py
@@ -0,0 +1,152 @@
+import socket
+import sys
+import os
+import string
+import signal
+
+class TimeoutException(Exception):
+ pass
+
+class ServerHandler:
+
+ def __init__(self,p):
+ self.port = p
+ self.host = None #symbolic name meaning all available interfaces
+ self.s = None
+ self.connected = 0
+ self.address = "127.0.0.1" #address of the main controller
+ self.onceConnected = 0
+ self.error = 'No error'
+
+ self.debugMode = 0
+
+ def openSocket(self):
+ self.error = 'No error'
+ for res in socket.getaddrinfo(self.host, self.port, socket.AF_UNSPEC,
+ socket.SOCK_STREAM, 0, socket.AI_PASSIVE):
+ af, socktype, proto, canonname, sa = res
+
+ try:
+ self.s = socket.socket(af, socktype, proto)
+ self.s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) #this resolves the bug with live packets
+ except socket.error, msg:
+ self.s = None
+ self.connected = 0
+ self.error = str(msg)
+ continue
+
+ try:
+ self.s.bind(sa)
+ self.s.listen(1)
+ except socket.error, msg:
+ self.s.close()
+ self.s = None
+ self.connected = 0
+ self.error = str(msg)
+ continue
+ break
+
+ if self.s is None:
+ self.connected = 0
+ return 0
+ else: #accept the connection
+ self.connection, self.address = self.s.accept()
+ self.connected = 1
+ self.onceConnected = 1
+ return 1
+
+ def connectedTo(self):
+ return self.address
+
+ def receiveData(self, timeout):
+ if self.connected == 1:
+
+ def timeout_handler(signum, frame):
+ raise TimeoutException()
+
+ try:
+
+ old_handler = signal.signal(signal.SIGALRM, timeout_handler)
+ signal.alarm(timeout) #start the timeout alarm, for timeout seconds
+
+ data = self.connection.recv(1024)
+
+ #stop the timeout function
+ signal.signal(signal.SIGALRM, old_handler)
+ signal.alarm(0)
+
+ if not data:
+ self.connected = 0
+ return 'NO DATA'
+ else:
+ return data
+
+ except TimeoutException:
+ #timeout happened
+ signal.signal(signal.SIGALRM, old_handler)
+ signal.alarm(0)
+ return 'TIMEOUT'
+
+ except Exception, e:
+ #stop the timeout timer
+ signal.signal(signal.SIGALRM, old_handler)
+ signal.alarm(0)
+
+ if self.debugMode == 1:
+ import traceback
+ print traceback.format_exc()
+ print e
+ self.connected = 0
+ if error[0:11] == '[Errno 104]':
+ return 3 #the other side reset the connection,[Errno 104] Connection reset by peer
+
+ return 2
+ else:
+ return 0
+
+ def sendData(self, data):
+ if self.connected == 1:
+ try:
+ self.connection.send(data)
+ return 1
+
+ except Exception, e:
+ if self.debugMode == 1:
+ import traceback
+ print traceback.format_exc()
+ print e
+ self.connecected = 0
+ return 2
+ else:
+ return 0
+
+ def closeConnection(self):
+ if self.onceConnected == 1:
+ try:
+ self.connected = 0
+ SHUT_RDWR = 2
+ self.connection.shutdown(SHUT_RDWR)
+ self.connection.close()
+ return 1
+ except Exception, e:
+ self.connected = 0
+ error = str(e)
+ if self.debugMode == 1:
+ import traceback
+ print traceback.format_exc()
+ print e
+ if error[0:11] == '[Errno 107]':
+ return 3 #the other side closed the connection before us [Errno 107] Transport endpoint is not connected
+ return 2
+ else:
+ return 0
+
+ def killPort(self):
+ killResult = os.popen('lsof -i tcp:' + str(self.port) + ' | grep "python " | awk -F" " ' + "'{print $2}'").read()
+ killResult = killResult.replace('\n','')
+ print killResult
+ if killResult!='':
+ print killResult
+ killPort = os.popen("kill -9 " + killResult).read()
+ return 1
+ return 0
diff --git a/For Weekly Test/Old/20-07-2011/classServer.pyc b/For Weekly Test/Old/20-07-2011/classServer.pyc
new file mode 100644
index 0000000..a96a41f
--- /dev/null
+++ b/For Weekly Test/Old/20-07-2011/classServer.pyc
Binary files differ
diff --git a/For Weekly Test/Old/20-07-2011/gsmcall_.py b/For Weekly Test/Old/20-07-2011/gsmcall_.py
new file mode 100644
index 0000000..70e9c72
--- /dev/null
+++ b/For Weekly Test/Old/20-07-2011/gsmcall_.py
@@ -0,0 +1,105 @@
+import sys
+import socket
+import time
+
+import subprocess
+import os
+from serial import *
+
+import classServer
+
+from time import sleep
+import string
+
+
+stop ="false"
+success = "failed"
+
+global server
+
+global ser
+portAddress = '/dev/ttyUSB0'
+portName = portAddress[-4:]
+portExist = os.popen('dmesg | grep ' + portName).read()
+
+if portExist == '':
+ print 'The serial port does not exist'
+ sys.exit()
+
+
+
+while stop <> "true":#???
+
+
+ try:
+
+ server = classServer.ServerHandler(50098)
+ tried = server.openSocket()
+
+ if server.error != 'No error':
+ print server.error
+ if server.error == '[Errno 98] Address already in use':
+ print 'one should try to kill the port'
+ print server.killPort()
+ server.closeConection()
+
+
+ server.sendData('ready')#send message to controller
+ print "Controller status: ", server.connected
+
+
+ while stop <> "true":
+ try:
+ data = server.receiveData() # waiting mode, until receiver start message or terminate message
+
+ if data == "start": # if receiver start message, handler start to call destination
+
+ while 1:
+
+ num = server.receiveData()
+
+ #num = "929"
+ if num <> "NO DATA":
+ server.closeConnection()
+
+ ser = Serial(
+ port=portAddress,
+ baudrate=19200,
+ bytesize=EIGHTBITS,
+ parity=PARITY_NONE,
+ stopbits=STOPBITS_ONE)
+
+ ser.close()
+ ser.open()
+
+ ser.write('ATD4661' + num + ';\r')
+ sleep(3)
+ ser.write('AT+CHUP\r')
+
+ ser.close()
+ tried = server.openSocket()
+ sleep(2)
+ success = "success"
+ server.sendData(success)
+
+ if data == "terminated": # will terminate the handler if controller send terminate message
+ stop = "true"
+ break
+
+ except ValueError:
+ print "error when sending message"
+ server.closeConnection()
+ del server
+
+
+ server.closeConnection()
+ del server
+ print "Goodbye"
+ sleep(3)
+ sys.exit(1)
+
+ except ValueError:
+ print "Exception: " + str(e)
+
+print "Goodbye"
+sleep(3)
diff --git a/For Weekly Test/Old/20-07-2011/gsmincom_.py b/For Weekly Test/Old/20-07-2011/gsmincom_.py
new file mode 100644
index 0000000..0b2c48e
--- /dev/null
+++ b/For Weekly Test/Old/20-07-2011/gsmincom_.py
@@ -0,0 +1,148 @@
+
+import atexit
+import signal
+
+import sys
+import socket
+import time
+import os
+import string
+import classServer
+from time import sleep
+from serial import *
+
+
+success = None
+stop = False
+
+try:
+
+ global ser
+ global server
+ portAddress = '/dev/ttyUSB0'
+ portName = portAddress[-4:]
+ portExist = os.popen('dmesg | grep ' + portName).read()
+
+ if portExist == '':
+ print 'The serial port does not exist'
+ sys.exit()
+
+
+
+ server = classServer.ServerHandler(50105)
+ tried = server.openSocket()
+
+
+ print "here:", server.connected
+ if server.connected == 1:
+
+ server.sendData('ready')
+ server.closeConnection()
+
+ ser = Serial(
+ port=portAddress,
+ baudrate=19200,
+ bytesize=EIGHTBITS,
+ parity=PARITY_NONE,
+ stopbits=STOPBITS_ONE)
+
+ ser.close()
+ ser.open()
+
+ signalQuality = ser.write('AT+CSQ\r')
+ print "signal Quality ", signalQuality
+ print ""
+
+
+
+ while stop <> True:
+
+ global pickUp
+ pickUp = None
+ buffer = ""
+
+
+ buffer = buffer + ser.read(ser.inWaiting()) #read the serial port and add it to the buffer variable
+ if '\n' in buffer: #if a new line character is found in the buffer then the cellphone has sent something
+ lines = buffer.split('\n') #parse the buffer variable with the new line character
+ last_received = lines.pop(0) #put into last_received variable the first content from lines (FIFO)
+
+ buffer = '\n'.join(lines) #add a new line to the buffer variable
+
+ last_received=last_received.split('\n') #parse the last received value with new lines
+ line = last_received[0].replace(chr(13), '')
+
+ print "buffer:", buffer
+ print "line:", line
+
+ if len(line) > 0:
+
+
+ if line=="RING":
+
+ print "Somebody calling"
+ print ""
+ sleep(1)
+ ser.write('ATA\r')
+ sleep(1)
+ ser.write('AT+CSQ\r')
+
+ sleep(2)
+ ser.write('AT+CLCC\r')
+
+
+ if line[0:5] == '+CSQ:':
+
+ space = int(string.find(line,' '))+1
+ coma = int(string.find(line,','))
+ signalStr = (int(line[space:coma])*2)-113
+
+ line=''
+
+ if line[0:6]=='+CLCC:':
+
+ pickUp = 1
+
+ print "I will hangup the call"
+ print ""
+ sleep(5)
+
+ ser.write('AT+CHUP\r')
+ pickUp = 0
+ ser.close()
+
+ quotation1 = int(string.find(line,'"'))+1
+ lineTemp = line[quotation1:]
+
+ quotation2 = int(string.find(lineTemp,'"'))
+ numberOfCaller = line[quotation1:quotation1+quotation2]
+
+ print "Signal Strength: ", signalStr
+ print ""
+
+ tried = server.openSocket()
+ server.sendData('I got call from :' +numberOfCaller)
+ print "with caller number", numberOfCaller
+ sleep(1)
+ server.sendData('success')
+ stop = True
+ sleep (3)
+
+
+
+ server.closeConnection()
+ del server
+ else:
+
+ print "not connected"
+
+ del server
+
+ ser.close()
+except ValueError:
+ print "Exception: "
+ server.closeConnection()
+ del server
+
+print "GOODBYE"
+sleep(5)
diff --git a/For Weekly Test/Old/20-07-2011/landlineCall.py b/For Weekly Test/Old/20-07-2011/landlineCall.py
new file mode 100644
index 0000000..fcdf4fe
--- /dev/null
+++ b/For Weekly Test/Old/20-07-2011/landlineCall.py
@@ -0,0 +1,135 @@
+import sys
+import pjsua as pj
+import classServer
+import LogFileClass
+logger = LogFileClass.Logging('landlineCallHandler.log')
+from time import sleep
+
+
+def log_cb(level, str, len):
+ print str, "landline log"
+
+# Receive events from Call
+class MyCallCallback(pj.CallCallback):
+
+ def on_state(self):
+ global current_call
+
+ if self.call.info().state <> pj.CallState.DISCONNECTED:
+ if self.call.info().state_text == "CONNECTING":
+ logger.logEvent("Call Connecting")
+ sleep(1)
+ if self.call.info().state <> pj.CallState.DISCONNECTED:
+ logger.logEvent("will Hangup call")
+ current_call.hangup()
+
+ logger.logEvent('200')
+ server.sendData('200')
+ else:
+ sleep(0.5)
+
+ if self.call.info().last_reason == "Busy Here":
+ logger.logEvent('Number busy or Offline')
+ server.sendData('486')
+ logger.logEvent('486')
+
+ if self.call.info().state == pj.CallState.DISCONNECTED:
+ logger.logEvent('Call Disconnected')
+ current_call = None
+
+
+def make_call(uri):
+
+ try:
+
+ cb=MyCallCallback()
+ return acc.make_call(uri, cb)
+
+ except pj.Error, e:
+ print "408 " + str(e)
+ logger.logEvent('408')
+ return None
+
+
+lib = pj.Lib()
+stop =False
+current_call = None
+logger.logEvent('')
+
+while stop <> True:
+
+
+ lib.init(log_cfg = pj.LogConfig(level=1, callback=log_cb))
+ transport = lib.create_transport(pj.TransportType.UDP, pj.TransportConfig(0))
+
+ lib.start()
+ lib.set_null_snd_dev()
+
+
+ server = classServer.ServerHandler(50099)
+ logger.logEvent('Connect to Controller via port 50099')
+ conn = server.openSocket()
+
+ try:
+ logger.logEvent('Register Account to sipgate.de server')
+ acc_cfg = pj.AccountConfig("sipgate.de","1289459","MMW9AX")
+ acc = lib.create_account(acc_cfg, cb=pj.AccountCallback())
+
+
+ if acc.info().reg_status < 700:
+
+ server.sendData('ready')
+ logger.logEvent('Handler Ready')
+
+ while 1:
+ try:
+ data = server.receiveData(0)
+ event = data[0:5]
+ num = data[6:]
+
+ if event == "start" and num <> "":
+
+ logger.logEvent(event)
+ logger.logEvent('Make a call to: ' + num)
+ number = "sip:"+num+"@sipgate.de"
+ current_call = make_call(number)
+
+ if data == "487":
+ stop = True
+ logger.logEvent('Terminate')
+ break
+
+ except ValueError:
+ logger.logEvent("error: Failed retrive message from Controller")
+ logger.logEvent('999')
+ server.closeConnection()
+ logger.logEvent('Close Connection to the Controller')
+
+
+ server.closeConnection()
+ logger.logEvent('Close Connection to the Controller')
+
+ else:
+ logger.logEvent("488 Not Acceptable Here")
+
+ lib.destroy()
+ lib = None
+ acc = None
+
+
+ server.closeConnection()
+ logger.logEvent('Close Connection to the Controller')
+ except ValueError:
+ print "401 Unauthorized " + str(e)
+ logger.logEvent("401 Unauthorized ")
+
+logger.logEvent("Goodbye")
+sleep(3)
+acc.delete()
+logger.logEvent('Un-Rigester SIP Account')
+lib.destroy()
+server.closeConnection()
+logger.logEvent('Close Connection to the Controller')
+lib = None
+acc = None
+
diff --git a/For Weekly Test/Old/20-07-2011/landlineReceiver.py b/For Weekly Test/Old/20-07-2011/landlineReceiver.py
new file mode 100644
index 0000000..ba02562
--- /dev/null
+++ b/For Weekly Test/Old/20-07-2011/landlineReceiver.py
@@ -0,0 +1,111 @@
+import sys
+import pjsua as pj
+import classServer
+import LogFileClass
+
+from time import sleep
+
+logger = LogFileClass.Logging('LandlineRecHandler.log')
+
+def log_cb(level, str, len):
+ print str, "landline Handler Receiver Log"
+
+
+class MyAccountCallback(pj.AccountCallback):
+
+ def on_incoming_call(self, call):
+
+ current_call = call
+ logger.logEvent(current_call)
+ sleep(0.5)
+
+ call.answer(200)
+ logger.logEvent("Answer call")
+ sleep(0.5)
+
+ if current_call <> None:
+ logger.logEvent("Hangup call")
+ call.hangup()
+
+ server.sendData('200')
+ logger.logEvent('200')
+lib = pj.Lib()
+stop = False
+logger.logEvent('')
+
+try:
+
+ server = classServer.ServerHandler(50106)
+ logger.logEvent('Connect to Controller via port 50106')
+ conn = server.openSocket()
+
+ lib.init(log_cfg = pj.LogConfig(level=1, callback=log_cb))
+ transport = lib.create_transport(pj.TransportType.UDP, pj.TransportConfig(0))
+
+ lib.start()
+ lib.set_null_snd_dev()
+
+ try:
+ logger.logEvent('Register Account to sipgate.de server')
+ acc_cfg = pj.AccountConfig("sipgate.de","1289459","MMW9AX")
+ acc = lib.create_account(acc_cfg, cb=MyAccountCallback())
+
+ if acc.info().reg_status < 700:
+
+ logger.logEvent(acc.info().reg_status)
+ server.sendData('ready')
+ logger.logEvent('Handler Ready')
+
+ while stop <> True:
+
+ data = server.receiveData(0)
+
+ if data == "487":
+ logger.logEvent('Terminate')
+ stop = True
+ break
+
+ transport = None
+ acc.delete()
+ logger.logEvent('Un-Rigester SIP Account')
+ acc = None
+ lib.destroy()
+ lib = None
+ server.closeConnection()
+ logger.logEvent('Close Connection to the Controller')
+
+ else:
+ logger.logEvent("488 Not Acceptable Here")
+ lib.destroy()
+
+ lib = None
+ acc = None
+
+ server.closeConnection()
+ logger.logEvent('Close Connection to the Controller')
+
+
+ except pj.Error, e:
+ print "401 Unauthorized " +str(e)
+ logger.logEvent("401 Unauthorized ")
+
+ lib.destroy()
+ lib = None
+
+ server.closeConnection()
+ logger.logEvent('Close Connection to the Controller')
+
+except pj.Error, e:
+ print "Exception: " + str(e)
+ logger.logEvent(str(e))
+
+ lib.destroy()
+
+ lib = None
+ server.closeConnection()
+ logger.logEvent('Close Connection to the Controller')
+
+
+
+
+
diff --git a/For Weekly Test/Old/20-07-2011/localsipReceiver.py b/For Weekly Test/Old/20-07-2011/localsipReceiver.py
new file mode 100644
index 0000000..eb95ce0
--- /dev/null
+++ b/For Weekly Test/Old/20-07-2011/localsipReceiver.py
@@ -0,0 +1,112 @@
+import sys
+import pjsua as pj
+import classServer
+import LogFileClass
+
+from time import sleep
+
+logger = LogFileClass.Logging('UniSIPRecHandler.log')
+
+def log_cb(level, str, len):
+ print str, "SIP University account Handler Receiver Log"
+
+
+class MyAccountCallback(pj.AccountCallback):
+
+ def on_incoming_call(self, call):
+
+ current_call = call
+ logger.logEvent(current_call)
+ sleep(0.5)
+
+ call.answer(200)
+ logger.logEvent("Answer call")
+ sleep(0.5)
+
+ if current_call <> None:
+ logger.logEvent("Hangup call")
+ call.hangup()
+
+ server.sendData('200')
+ logger.logEvent('200')
+lib = pj.Lib()
+stop = False
+logger.logEvent('')
+
+try:
+
+ server = classServer.ServerHandler(50107)
+ logger.logEvent('Connect to Controller via port 50107')
+ conn = server.openSocket()
+
+ lib.init(log_cfg = pj.LogConfig(level=1, callback=log_cb))
+ transport = lib.create_transport(pj.TransportType.UDP, pj.TransportConfig(0))
+
+ lib.start()
+ lib.set_null_snd_dev()
+
+ try:
+ logger.logEvent('Register Account to University SIP server')
+ acc_cfg = pj.AccountConfig("132.230.252.228", "4976120397897", "hB8M3WyFt61C")
+ acc = lib.create_account(acc_cfg, cb=MyAccountCallback())
+
+ if acc.info().reg_status < 700:
+
+ logger.logEvent(acc.info().reg_status)
+ sleep(5)
+ server.sendData('ready')
+ logger.logEvent('Handler Ready')
+
+ while stop <> True:
+
+ data = server.receiveData(0)
+
+ if data == "487":
+ logger.logEvent('Terminate')
+ stop = True
+ break
+
+ transport = None
+ acc.delete()
+ logger.logEvent('Un-Rigester SIP Account')
+ acc = None
+ lib.destroy()
+ lib = None
+ server.closeConnection()
+ logger.logEvent('Close Connection to the Controller')
+
+ else:
+ logger.logEvent("488 Not Acceptable Here")
+ lib.destroy()
+
+ lib = None
+ acc = None
+
+ server.closeConnection()
+ logger.logEvent('Close Connection to the Controller')
+
+
+ except pj.Error, e:
+ print "401 Unauthorized " +str(e)
+ logger.logEvent("401 Unauthorized ")
+
+ lib.destroy()
+ lib = None
+
+ server.closeConnection()
+ logger.logEvent('Close Connection to the Controller')
+
+except pj.Error, e:
+ print "Exception: " + str(e)
+ logger.logEvent(str(e))
+
+ lib.destroy()
+
+ lib = None
+ server.closeConnection()
+ logger.logEvent('Close Connection to the Controller')
+
+
+
+
+
diff --git a/For Weekly Test/Old/20-07-2011/sipCall.py b/For Weekly Test/Old/20-07-2011/sipCall.py
new file mode 100644
index 0000000..51ae240
--- /dev/null
+++ b/For Weekly Test/Old/20-07-2011/sipCall.py
@@ -0,0 +1,135 @@
+import sys
+import pjsua as pj
+import classServer
+import LogFileClass
+logger = LogFileClass.Logging('sipCallHandler.log')
+from time import sleep
+
+
+def log_cb(level, str, len):
+ print str, "SIP log"
+
+# Receive events from Call
+class MyCallCallback(pj.CallCallback):
+
+ def on_state(self):
+ global current_call
+
+ if self.call.info().state <> pj.CallState.DISCONNECTED:
+ if self.call.info().state_text == "CONNECTING":
+ logger.logEvent("Call Connecting")
+ sleep(1)
+ if self.call.info().state <> pj.CallState.DISCONNECTED:
+ logger.logEvent("will Hangup call")
+ current_call.hangup()
+
+ logger.logEvent('200')
+ server.sendData('200')
+ else:
+ sleep(0.5)
+
+ if self.call.info().last_reason == "Busy Here":
+ logger.logEvent('Number busy or Offline')
+ server.sendData('486')
+ logger.logEvent('486')
+
+ if self.call.info().state == pj.CallState.DISCONNECTED:
+ logger.logEvent('Call Disconnected')
+ current_call = None
+
+
+def make_call(uri):
+
+ try:
+
+ cb=MyCallCallback()
+ return acc.make_call(uri, cb)
+
+ except pj.Error, e:
+ print "408 " + str(e)
+ logger.logEvent('408')
+ return None
+
+
+lib = pj.Lib()
+stop =False
+current_call = None
+logger.logEvent('')
+
+while stop <> True:
+
+
+ lib.init(log_cfg = pj.LogConfig(level=1, callback=log_cb))
+ transport = lib.create_transport(pj.TransportType.UDP, pj.TransportConfig(0))
+
+ lib.start()
+ lib.set_null_snd_dev()
+
+
+ server = classServer.ServerHandler(50097)
+ logger.logEvent('Connect to Controller via port 50097')
+ conn = server.openSocket()
+
+ try:
+ logger.logEvent('Register Account to SIP server')
+ acc_cfg = pj.AccountConfig("132.230.4.8","mpselftest1","1mpselftest")
+ acc = lib.create_account(acc_cfg, cb=pj.AccountCallback())
+
+
+ if acc.info().reg_status < 700:
+
+ server.sendData('ready')
+ logger.logEvent('Handler Ready')
+
+ while 1:
+ try:
+ data = server.receiveData(0)
+ event = data[0:5]
+ num = data[6:]
+
+ if event == "start" and num <> "":
+
+ logger.logEvent(event)
+ logger.logEvent('Make a call to: ' + num)
+ number = "sip:"+num+"@132.230.4.8"
+ current_call = make_call(number)
+
+ if data == "487":
+ stop = True
+ logger.logEvent('Terminate')
+ break
+
+ except ValueError:
+ logger.logEvent("error: Failed retrive message from Controller")
+ logger.logEvent('999')
+ server.closeConnection()
+ logger.logEvent('Close Connection to the Controller')
+
+
+ server.closeConnection()
+ logger.logEvent('Close Connection to the Controller')
+
+ else:
+ logger.logEvent("488 Not Acceptable Here")
+
+ lib.destroy()
+ lib = None
+ acc = None
+
+
+ server.closeConnection()
+ logger.logEvent('Close Connection to the Controller')
+ except ValueError:
+ print "401 Unauthorized " + str(e)
+ logger.logEvent("401 Unauthorized ")
+
+logger.logEvent("Goodbye")
+sleep(3)
+acc.delete()
+logger.logEvent('Un-Rigester SIP Account')
+lib.destroy()
+server.closeConnection()
+logger.logEvent('Close Connection to the Controller')
+lib = None
+acc = None
+
diff --git a/For Weekly Test/Old/20-07-2011/sipCallHandler.log b/For Weekly Test/Old/20-07-2011/sipCallHandler.log
new file mode 100644
index 0000000..88005da
--- /dev/null
+++ b/For Weekly Test/Old/20-07-2011/sipCallHandler.log
@@ -0,0 +1,112 @@
+
+
+------------------STARTED THE LOGGING 2011-07-19 13:15:05.342369 ------------------
+On: 2011-07-19 13:15:05.351935 Event: Connect to Controller via port 50097
+
+
+------------------STARTED THE LOGGING 2011-07-19 13:15:19.499982 ------------------
+On: 2011-07-19 13:15:19.509715 Event: Connect to Controller via port 50097
+
+
+------------------STARTED THE LOGGING 2011-07-19 13:15:26.475769 ------------------
+On: 2011-07-19 13:15:26.485197 Event: Connect to Controller via port 50097
+
+
+------------------STARTED THE LOGGING 2011-07-19 13:15:36.151728 ------------------
+On: 2011-07-19 13:15:36.162183 Event: Connect to Controller via port 50097
+On: 2011-07-19 13:15:41.003034 Event: Register Account to SIP server
+On: 2011-07-19 13:15:41.003725 Event: Handler Ready
+
+
+------------------STARTED THE LOGGING 2011-07-19 13:17:12.303046 ------------------
+On: 2011-07-19 13:17:12.315193 Event: Connect to Controller via port 50097
+On: 2011-07-19 13:17:17.153546 Event: Register Account to SIP server
+On: 2011-07-19 13:17:17.154274 Event: Handler Ready
+
+
+------------------STARTED THE LOGGING 2011-07-19 13:17:35.665110 ------------------
+On: 2011-07-19 13:17:35.675358 Event: Connect to Controller via port 50097
+On: 2011-07-19 13:17:40.499101 Event: Register Account to SIP server
+On: 2011-07-19 13:17:40.499773 Event: Handler Ready
+On: 2011-07-19 13:17:40.499834 Event: status Server
+
+
+------------------STARTED THE LOGGING 2011-07-19 13:17:52.086222 ------------------
+On: 2011-07-19 13:17:52.096731 Event: Connect to Controller via port 50097
+On: 2011-07-19 13:17:56.885712 Event: Register Account to SIP server
+On: 2011-07-19 13:17:56.886499 Event: Handler Ready
+On: 2011-07-19 13:17:56.886560 Event: status Server
+On: 2011-07-19 13:18:03.923972 Event: start
+On: 2011-07-19 13:18:03.924059 Event: Make a call to: 076120397897
+On: 2011-07-19 13:18:04.476832 Event: Call Connecting
+On: 2011-07-19 13:18:05.477602 Event: will Hangup call
+On: 2011-07-19 13:18:05.477915 Event: 200
+On: 2011-07-19 13:18:05.478784 Event: 487
+On: 2011-07-19 13:18:05.478854 Event: Terminate
+On: 2011-07-19 13:18:05.479006 Event: Close Connection to the Controller
+On: 2011-07-19 13:18:05.479098 Event: Close Connection to the Controller
+On: 2011-07-19 13:18:05.479125 Event: Goodbye
+On: 2011-07-19 13:18:05.980151 Event: Call Disconnected
+On: 2011-07-19 13:18:08.482562 Event: Un-Rigester SIP Account
+On: 2011-07-19 13:18:10.007436 Event: Close PJSUA Library
+On: 2011-07-19 13:18:10.007616 Event: Close Connection to the Controller
+
+
+------------------STARTED THE LOGGING 2011-07-19 13:39:56.727710 ------------------
+On: 2011-07-19 13:39:56.741089 Event: Connect to Controller via port 50097
+On: 2011-07-19 13:40:01.558882 Event: Register Account to SIP server
+On: 2011-07-19 13:40:01.559560 Event: Handler Ready
+On: 2011-07-19 13:40:08.589980 Event: start
+On: 2011-07-19 13:40:08.590047 Event: Make a call to: 076120397897
+On: 2011-07-19 13:40:09.142686 Event: Call Connecting
+On: 2011-07-19 13:40:10.144021 Event: will Hangup call
+On: 2011-07-19 13:40:10.144344 Event: 200
+On: 2011-07-19 13:40:10.145325 Event: Terminate
+On: 2011-07-19 13:40:10.145583 Event: Close Connection to the Controller
+On: 2011-07-19 13:40:10.145717 Event: Close Connection to the Controller
+On: 2011-07-19 13:40:10.145766 Event: Goodbye
+On: 2011-07-19 13:40:10.646310 Event: Call Disconnected
+On: 2011-07-19 13:40:13.149215 Event: Un-Rigester SIP Account
+On: 2011-07-19 13:40:14.675876 Event: Close Connection to the Controller
+
+
+------------------STARTED THE LOGGING 2011-07-19 14:08:43.478088 ------------------
+On: 2011-07-19 14:08:43.488948 Event: Connect to Controller via port 50097
+On: 2011-07-19 14:08:48.312081 Event: Register Account to SIP server
+On: 2011-07-19 14:08:48.312787 Event: Handler Ready
+On: 2011-07-19 14:08:50.341066 Event: start
+On: 2011-07-19 14:08:50.341103 Event: Make a call to: 076145875681
+On: 2011-07-19 14:08:55.437133 Event: Call Connecting
+On: 2011-07-19 14:08:56.438035 Event: will Hangup call
+On: 2011-07-19 14:08:56.438314 Event: 200
+On: 2011-07-19 14:08:56.439496 Event: Terminate
+On: 2011-07-19 14:08:56.439679 Event: Close Connection to the Controller
+On: 2011-07-19 14:08:56.439788 Event: Close Connection to the Controller
+On: 2011-07-19 14:08:56.439832 Event: Goodbye
+On: 2011-07-19 14:08:56.940779 Event: Call Disconnected
+On: 2011-07-19 14:08:59.441807 Event: Un-Rigester SIP Account
+On: 2011-07-19 14:09:00.553758 Event: Close Connection to the Controller
+
+
+------------------STARTED THE LOGGING 2011-07-19 14:11:06.310465 ------------------
+On: 2011-07-19 14:11:06.324540 Event: Connect to Controller via port 50097
+On: 2011-07-19 14:11:06.325868 Event: Register Account to SIP server
+On: 2011-07-19 14:11:06.326082 Event: Handler Ready
+
+
+------------------STARTED THE LOGGING 2011-07-19 14:10:53.811684 ------------------
+On: 2011-07-19 14:10:53.825926 Event: Connect to Controller via port 50097
+On: 2011-07-19 14:10:58.642116 Event: Register Account to SIP server
+On: 2011-07-19 14:10:58.642823 Event: Handler Ready
+On: 2011-07-19 14:11:00.667479 Event: start
+On: 2011-07-19 14:11:00.667554 Event: Make a call to: 076145875681
+On: 2011-07-19 14:11:05.148098 Event: Call Connecting
+On: 2011-07-19 14:11:06.149414 Event: will Hangup call
+On: 2011-07-19 14:11:06.149749 Event: 200
+On: 2011-07-19 14:11:06.151074 Event: Terminate
+On: 2011-07-19 14:11:06.151273 Event: Close Connection to the Controller
+On: 2011-07-19 14:11:06.151408 Event: Close Connection to the Controller
+On: 2011-07-19 14:11:06.151457 Event: Goodbye
+On: 2011-07-19 14:11:06.652364 Event: Call Disconnected
+On: 2011-07-19 14:11:09.153186 Event: Un-Rigester SIP Account
+On: 2011-07-19 14:11:10.309656 Event: Close Connection to the Controller
diff --git a/For Weekly Test/Old/20-07-2011/sipReceiver.py b/For Weekly Test/Old/20-07-2011/sipReceiver.py
new file mode 100644
index 0000000..62f9a49
--- /dev/null
+++ b/For Weekly Test/Old/20-07-2011/sipReceiver.py
@@ -0,0 +1,111 @@
+import sys
+import pjsua as pj
+import classServer
+import LogFileClass
+
+from time import sleep
+
+logger = LogFileClass.Logging('sipRecHandler.log')
+
+def log_cb(level, str, len):
+ print str, "sip Handler Receiver Log"
+
+
+class MyAccountCallback(pj.AccountCallback):
+
+ def on_incoming_call(self, call):
+
+ current_call = call
+ logger.logEvent(current_call)
+ sleep(0.5)
+
+ call.answer(200)
+ logger.logEvent("Answer call")
+ sleep(0.5)
+
+ if current_call <> None:
+ logger.logEvent("Hangup call")
+ call.hangup()
+
+ server.sendData('200')
+ logger.logEvent('200')
+lib = pj.Lib()
+stop = False
+logger.logEvent('')
+
+try:
+
+ server = classServer.ServerHandler(50104)
+ logger.logEvent('Connect to Controller via port 50104')
+ conn = server.openSocket()
+
+ lib.init(log_cfg = pj.LogConfig(level=1, callback=log_cb))
+ transport = lib.create_transport(pj.TransportType.UDP, pj.TransportConfig(0))
+
+ lib.start()
+ lib.set_null_snd_dev()
+
+ try:
+ logger.logEvent('Register Account to SIP Asterik server')
+ acc_cfg = pj.AccountConfig("132.230.4.8", "mpselftest2", "2mpselftest")
+ acc = lib.create_account(acc_cfg, cb=MyAccountCallback())
+
+ if acc.info().reg_status < 700:
+
+ logger.logEvent(acc.info().reg_status)
+ server.sendData('ready')
+ logger.logEvent('Handler Ready')
+
+ while stop <> True:
+
+ data = server.receiveData(0)
+
+ if data == "487":
+ logger.logEvent('Terminate')
+ stop = True
+ break
+
+ transport = None
+ acc.delete()
+ logger.logEvent('Un-Rigester SIP Account')
+ acc = None
+ lib.destroy()
+ lib = None
+ server.closeConnection()
+ logger.logEvent('Close Connection to the Controller')
+
+ else:
+ logger.logEvent("488 Not Acceptable Here")
+ lib.destroy()
+
+ lib = None
+ acc = None
+
+ server.closeConnection()
+ logger.logEvent('Close Connection to the Controller')
+
+
+ except pj.Error, e:
+ print "401 Unauthorized " +str(e)
+ logger.logEvent("401 Unauthorized ")
+
+ lib.destroy()
+ lib = None
+
+ server.closeConnection()
+ logger.logEvent('Close Connection to the Controller')
+
+except pj.Error, e:
+ print "Exception: " + str(e)
+ logger.logEvent(str(e))
+
+ lib.destroy()
+
+ lib = None
+ server.closeConnection()
+ logger.logEvent('Close Connection to the Controller')
+
+
+
+
+