summaryrefslogtreecommitdiffstats
path: root/For Weekly Test
diff options
context:
space:
mode:
authortt412011-07-23 02:58:02 +0200
committertt412011-07-23 02:58:02 +0200
commit7dad14ada675d92ac7bb94f7ea809d96374c1741 (patch)
tree9576b52798cace1dccbd7b999633e4a9b7fa94e2 /For Weekly Test
parentadd new file. (diff)
downloadgsm-selftest-7dad14ada675d92ac7bb94f7ea809d96374c1741.tar.gz
gsm-selftest-7dad14ada675d92ac7bb94f7ea809d96374c1741.tar.xz
gsm-selftest-7dad14ada675d92ac7bb94f7ea809d96374c1741.zip
managing files.
Diffstat (limited to 'For Weekly Test')
-rw-r--r--For Weekly Test/30-07-2011/ClientClass.py123
-rw-r--r--For Weekly Test/30-07-2011/ControllerClass.py141
-rw-r--r--For Weekly Test/30-07-2011/LogFileClass.py21
-rw-r--r--For Weekly Test/30-07-2011/ServerClass.py152
-rw-r--r--For Weekly Test/30-07-2011/classCheck.py28
-rw-r--r--For Weekly Test/30-07-2011/classPing.py28
-rw-r--r--For Weekly Test/30-07-2011/dbClass.py332
-rw-r--r--For Weekly Test/30-07-2011/sipHandler.py182
8 files changed, 1007 insertions, 0 deletions
diff --git a/For Weekly Test/30-07-2011/ClientClass.py b/For Weekly Test/30-07-2011/ClientClass.py
new file mode 100644
index 0000000..46c3b00
--- /dev/null
+++ b/For Weekly Test/30-07-2011/ClientClass.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/30-07-2011/ControllerClass.py b/For Weekly Test/30-07-2011/ControllerClass.py
new file mode 100644
index 0000000..c722df3
--- /dev/null
+++ b/For Weekly Test/30-07-2011/ControllerClass.py
@@ -0,0 +1,141 @@
+import sys
+import os
+import subprocess
+
+import classClient
+import classDb
+import classPing
+
+import LogFileClass
+logger = LogFileClass.Logging('2classController.log')
+
+from time import sleep
+
+
+class test:
+
+ def __init__(self, orig, dest, destNo):
+ self.orig = orig
+ self.dest = dest
+ self.destNo = destNo
+ self.repeatTest = None
+ self.portOrig = None
+ self.portDest = None
+ self.resultOrig = None
+ self.resultDest = None
+ self.testResult = None
+ self.add = None
+
+ def FuncTest(self):
+
+ logger.logEvent('')
+
+ try:
+
+ if self.orig =="RZ1":
+ self.portOrig = 50095
+ self.add = ''
+
+ elif self.orig =="RZ2":
+ self.portOrig = 50096
+ self.add = ''
+
+ elif self.orig =="RZ3":
+ self.portOrig = 50097
+ self.add = ''
+
+ else:
+ self.portOrig = 50099
+ self.add = 'localhost'
+ #command='--command=python 2sipHandler.py '+self.orig+ ' ' +str(self.portOrig)
+ subprocess.Popen(args=["gnome-terminal", '--command=python 2sipHandler.py '+self.orig+ ' ' +str(self.portOrig)])
+
+ sleep(3)
+
+ caller = classClient.Connection(self.add,self.portOrig)
+
+ caller.connect()
+ caller.sendData('CALLER|'+self.destNo)
+
+ origHandler = caller.receiveData(60)
+
+ if origHandler == "ready":
+ logger.logEvent('Caller handler : Ready')
+ try:
+
+ if self.dest =="gsmBox1":
+ self.portDest = 50102
+ self.add = ''
+
+ if self.dest =="gsmBox2":
+ self.portDest = 50103
+ self.add = ''
+
+ if self.dest =="gsmBox3":
+ self.portDest = 50103
+ self.add = ''
+
+ else:
+ self.portDest = 50100
+ #command='--command=python 2sipHandler.py '+self.dest+ ' ' +str(self.portDest)
+ subprocess.Popen(args=['gnome-terminal', '--command=python 2sipHandler.py '+self.dest+ ' ' +str(self.portDest)])
+ sleep(3)
+
+ receiver = classClient.Connection('localhost', self.portDest)
+
+ receiver.connect()
+ receiver.sendData('RECEIVER')
+
+ destHandler = receiver.receiveData(0)
+
+ if destHandler == 'ready':
+
+ caller.sendData('start')
+
+ self.resultOrig = caller.receiveData(60)
+ self.resultDest = receiver.receiveData(60)
+
+ if self.resultOrig <> 200 or self.resultDest <> 200:
+
+ caller.sendData('start')
+
+ self.resultOrig = caller.receiveData(60)
+ self.resultDest = receiver.receiveData(60)
+
+ if self.resultOrig <> 200 or self.resultDest <> 200:
+ self.testResult = 486
+ self.repeatTest = True
+ else:
+ self.testResult = 200
+
+ caller.sendData('487')
+ receiver.sendData('487')
+
+ else:
+
+ self.testResult = 200
+ caller.sendData('487')
+ receiver.sendData('487')
+
+ else:
+ self.testResult = 604
+ logger.logEvent('604 General Handler Error: Destination handler no respond timeout')
+ caller.sendData('487')
+
+ receiver.closeConnection()
+
+ except ValueError:
+ logger.logEvent('601 General Handler Error: Could not open Destination handler')
+ self.testResult = 601
+ caller.sendData('487')
+ caller.closeConnection()
+ else:
+ self.testResult = 605
+ logger.logEvent('605 General Handler Error: Origin handler no respond timeout')
+
+ caller.closeConnection()
+
+ except ValueError:
+ self.testResult = 602
+ logger.logEvent('602 General Handler Error: Could not open Origin handler')
+
diff --git a/For Weekly Test/30-07-2011/LogFileClass.py b/For Weekly Test/30-07-2011/LogFileClass.py
new file mode 100644
index 0000000..cb152f4
--- /dev/null
+++ b/For Weekly Test/30-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/30-07-2011/ServerClass.py b/For Weekly Test/30-07-2011/ServerClass.py
new file mode 100644
index 0000000..93c2f8e
--- /dev/null
+++ b/For Weekly Test/30-07-2011/ServerClass.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/30-07-2011/classCheck.py b/For Weekly Test/30-07-2011/classCheck.py
new file mode 100644
index 0000000..4009669
--- /dev/null
+++ b/For Weekly Test/30-07-2011/classCheck.py
@@ -0,0 +1,28 @@
+
+import classPing
+
+class checking:
+
+ def __init__(self, handler):
+
+ self.handler = handler
+ self.destNumber = None
+ self.serverStatus = None
+
+ if self.handler == 'landline':
+ server = classPing.Ping('sipgate.de')
+ self.serverStatus = server.ping(3)
+ self.destNumber = '076145875681'
+
+ if self.handler == 'sip':
+ server = classPing.Ping('132.230.4.8')
+ self.serverStatus = server.ping(3)
+ self.destNumber = '4661928'
+
+ if self.handler == 'unisip':
+ server = classPing.Ping('132.230.252.228')
+ self.serverStatus = server.ping(3)
+ self.destNumber = '076120397897'
+
+ if self.handler == 'RZ1':
+ self.destNumber = '000'
diff --git a/For Weekly Test/30-07-2011/classPing.py b/For Weekly Test/30-07-2011/classPing.py
new file mode 100644
index 0000000..e13b32b
--- /dev/null
+++ b/For Weekly Test/30-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/30-07-2011/dbClass.py b/For Weekly Test/30-07-2011/dbClass.py
new file mode 100644
index 0000000..f2a9afb
--- /dev/null
+++ b/For Weekly Test/30-07-2011/dbClass.py
@@ -0,0 +1,332 @@
+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
+user = 'root'
+passw = 'randompasswordSQL'
+host = 'localhost'
+dbname = 'gsmselftesting'
+
+x = DBMySQLConnection(user, passw, host, dbname)
+print "connected to the DB ", x.connectDB()
+print "do i have anything to do", x.anyTasksToDo()
+for item in x.tasksList:
+ taskID = item[0]
+ taskNo = item[1]
+ callFrom = item[2]
+ callTo = item[3]
+ print "call from to ", taskID , callFrom , callTo, taskNo
+
+print "found", x.searchTaskList('S1IP2','GSM1')
+#if variable == 0:
+# print x.insertTaskIn2('gsm4','sip8',2)
+
+print "remove a task ",x.removeTaskFromList('2')
+
+#print x.cleanTasksList()
+
+for item in x.tasksList:
+ device = item[1]
+ print "device name", device
+ print "device's IP", x.deviceAddress(device)
+
+print "update task result ", x.updateTaskResult(1,3)
+
+print "update ping Table", x.updatePingResult(1,5,4,3,2,1)
+print "delete a task from temp table", x.deleteTempTask(2)
+print "add a result to the table", x.addResult(4,34)
+
+#new task to do
+#$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
+#just made for Tri :)---------------------------------------------------------------
+#print x.cleanTasksList()
+#print "do i have any task from SIP1 to GSM1 to do", x.anyTasksFromTo('SIP2', 'GSMu1', 2)
+#for item in x.tasksList:
+# taskID = item[0]
+# callFrom = item[1]
+# callTo = item[2]
+# print "call from to ", taskID , callFrom , callTo
+
+print 'i am inserting into the table something', x.insertTaskIn2('gsm4','sip8',2)
+print 'i am inserting into the table something', x.insertTaskIn2('gsm4','sip8',2)
+print 'i am inserting into the table something', x.insertTaskIn2('gsm4','sip8',2)
+print 'i am inserting into the table something', x.insertTaskIn2('gsm4','sip8',2)
+#-----------------------------------------------------------------------------------
+#$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
+for item in x.tasksList:
+ taskID = item[0]
+ taskNo = item[1]
+ callFrom = item[2]
+ callTo = item[3]
+ print "call from to ", taskID , callFrom , callTo, taskNo
+
+print "close connection to the DB", x.closeDBConn()
+
+del x #delete
diff --git a/For Weekly Test/30-07-2011/sipHandler.py b/For Weekly Test/30-07-2011/sipHandler.py
new file mode 100644
index 0000000..91e3f62
--- /dev/null
+++ b/For Weekly Test/30-07-2011/sipHandler.py
@@ -0,0 +1,182 @@
+import sys
+import string
+import pjsua as pj
+import classServer
+import LogFileClass
+
+from time import sleep
+
+def log_cb(level, str, len):
+ print "--------starting Handler--------"
+
+# Receive events from incoming Call
+class Account(pj.AccountCallback):
+
+ def on_incoming_call(self, call):
+ global current_call
+
+ current_call = call
+ call_cb = Calling(current_call)
+ current_call.set_callback(call_cb)
+
+ 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()
+
+ logger.logEvent('200')
+
+class Calling(pj.CallCallback):
+
+ def __init__(self, call=None):
+ pj.CallCallback.__init__(self, call)
+
+ 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")
+ logger.logEvent('200')
+ server.sendData('200')
+
+ 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=Calling()
+ return acc.make_call(uri, cb)
+
+ except pj.Error, e:
+ print "408 " + str(e)
+ logger.logEvent('408')
+ return None
+
+global acc_cfg
+global handler
+global state
+
+handler = sys.argv[1]
+port = sys.argv[2]
+
+lib = pj.Lib()
+stop = False
+
+logger = LogFileClass.Logging('sipHandler.log')
+logger.logEvent('')
+
+while stop <> True:
+
+ acc_cfg = None
+
+ 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(port)
+ logger.logEvent('Connect to Controller')
+ conn = server.openSocket()
+
+ message = server.receiveData(30)
+ num = message[7:]
+
+ if handler == 'sip':
+ logger.logEvent('Beeing SIP')
+ acc_cfg = pj.AccountConfig("132.230.4.8","mpselftest1","1mpselftest")
+
+ elif handler == 'landline':
+ logger.logEvent('Beeing Landline')
+ acc_cfg = pj.AccountConfig("sipgate.de","1289459","MMW9AX")
+
+ elif handler == 'unisip':
+ logger.logEvent('Beeing University SIP')
+ acc_cfg = pj.AccountConfig("132.230.252.228", "4976120397897", "hB8M3WyFt61C")
+
+ else:
+ logger.logEvent('Unknown Message')
+ server.sendData('Unknown Message')
+ server.closeConnection()
+ sys.exit(1)
+
+ try:
+
+ logger.logEvent('Register Account to SIP server')
+ acc = lib.create_account(acc_cfg, cb=Account())
+
+
+ if acc.info().reg_status < 700:
+
+ if message.find('RECEIVER') <> -1:
+ logger.logEvent(acc.info().reg_status)
+ server.sendData('ready')
+ logger.logEvent('Receiver Handler Ready')
+
+ while 1:
+
+ data = server.receiveData(3)
+
+ if data == "487":
+ logger.logEvent('Terminate')
+ stop = True
+ break
+
+ elif message.find('CALLER') <> -1:
+ logger.logEvent(acc.info().reg_status)
+ server.sendData('ready')
+ logger.logEvent('Caller Handler Ready')
+
+ while 1:
+
+ data = server.receiveData(3)
+
+ if event == "start" and num <> "":
+
+ logger.logEvent(event)
+ logger.logEvent('Make a call to: ' + num)
+ number = "sip:"+num+"@132.230.4.8"
+ make_call(number)
+
+ if data == "487":
+ stop = True
+ logger.logEvent('Terminate')
+ break
+
+ else:
+ logger.logEvent('Unknow Message')
+ server.sendData('Unknow Message')
+ server.closeConnection()
+ sys.exit(1)
+
+ else:
+ logger.logEvent("488 Not Acceptable Here")
+ lib.destroy()
+
+ except ValueError:
+ print "401 Unauthorized " + str(e)
+ logger.logEvent("401 Unauthorized ")
+
+logger.logEvent("Goodbye")
+acc.delete()
+lib.destroy()
+server.closeConnection()
+lib = None
+acc = None
+