diff options
Diffstat (limited to 'Monitoring/MonitoringTool/PacketTracking/Monitoring')
22 files changed, 1572 insertions, 0 deletions
diff --git a/Monitoring/MonitoringTool/PacketTracking/Monitoring/Aggregator/Aggregator.py b/Monitoring/MonitoringTool/PacketTracking/Monitoring/Aggregator/Aggregator.py new file mode 100644 index 0000000..a3ed8c9 --- /dev/null +++ b/Monitoring/MonitoringTool/PacketTracking/Monitoring/Aggregator/Aggregator.py @@ -0,0 +1,385 @@ +""" +Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project +Copyright according to BSD License +For full text of the license see: ./novi/Software/Monitoring/MonitoringTool/PacketTracking/license.txt + +@author <a href="mailto:ramon.masek@fokus.fraunhofer.de">Ramon Masek</a>, Fraunhofer FOKUS +@author <a href="mailto:c.henke@tu-berlin.de">Christian Henke</a>, Technical University Berlin +@author <a href="mailto:carsten.schmoll@fokus.fraunhofer.de">Carsten Schmoll</a>, Fraunhofer FOKUS +@author <a href="mailto:Julian.Vetter@campus.tu-berlin.de">Julian Vetter</a>, Fraunhofer FOKUS +@author <a href="mailto:">Jens Krenzin</a>, Fraunhofer FOKUS +@author <a href="mailto:">Michael Gehring</a>, Fraunhofer FOKUS +@author <a href="mailto:">Tacio Grespan Santos</a>, Fraunhofer FOKUS +@author <a href="mailto:">Fabian Wolff</a>, Fraunhofer FOKUS +""" + +# System imports +from time import strptime, strftime, localtime, mktime +from sys import maxint + +# Project imports +from DBAccess import DBAccess +from DelayPlotter import DelayPlotter +from Task.Passive.Monitoring.SliceManager.SliceManager import SliceManager +from Task.Passive.Monitoring.DataTypes import Node, Status +from Task.Passive.Monitoring.DataTypes import PtVolumeStats +from Task.Passive.Monitoring.DataTypes import PtHopStats +from Task.Passive.Monitoring.DataTypes import PtPathStats +from Task.Passive.Monitoring.DataTypes import PtActivity + +# Constants DO NOT EDIT! +NUM = 0 +SUMBYTES = 1 +SUMDELAY = 2 +MINDELAY = 3 +MAXDELAY = 4 +PATH = 5 +TS = 5 +# Constants + +class Aggregator(object): + def __init__(self): + self.__noviDB = DBAccess("127.0.0.1", 5432, "noviDB", + "novi_user","novi123") + self.__sliceDB = SliceManager("127.0.0.1", 5432, "noviDB", + "novi_user", "novi123") + self.__delayPlotter = DelayPlotter() + + def __checkHashFuntion(self, function): + """ + Method to check if the given 'function' is a valid PT hashing function + @type Function: str + @param Function: String that contains the name of the + hashing function. + @rtype boolean + @return Returns 'true' if the function is a valid + hashing function, 'false' otherwise + """ + return function in ["BOB", "OAAT", "TWMX", "HSIEH"] + + def __checkDateTime(self, timeString): + """ + Method that checks if a given time string is valid, according to the + ISO time format ("YYYY-MM-DDThh:mm:ss"). If its valid the string is + converted to Pythons specific 9 floating values format (time_struct) + and returned to the caller. + @type timeString: str + @param timeString: The string that contains the time, which + should be verified. + @rtype: struct_time + @return: Time in Python specific 9 floating values + format. + """ + timeTuple = localtime() + try: + timeTuple= strptime(timeString, "%Y-%m-%dT%H:%M:%S") + except ValueError: + print ("Wrong date/time format, time must be provided in the" + " following format 'YYYY-MM-DDThh:mm:ss'") + print ("Time set to: " + strftime("%Y-%m-%dT%H:%M:%S", timeTuple)) + return timeTuple + + def __checkNodeList(self, nodeList): + """ + Check the validity of the given nodeList, if one of the nodes is neither + of type int nor of type Node the method raises an exception. For int + values in the list the method converts them to a Node with Oid from the + int value. The method also checks if all nodes are in the booked slice, + if not the concerning node is removed from the list. + @type nodeList: list + @param nodeList: List of nodes that should be validated. + @rtype: list + @return: New list with only valid nodes. + """ + for i in range(len(nodeList)): + nodeList[i] = self.__makeNodeFromOid(nodeList[i]) + return [node for node in nodeList if self.__sliceDB.validateNode(node)] + + def __checkNodeList2D(self, nodeList2D): + """ + Check the validity of the given nodeList2D, if one of the nodes tuples + is not of type tuple with the length of 2 the method raises an + exception. The method also checks if all nodes are in the booked slice, + if not the concerning node tuple is removed from the list. + @type nodeList2D: list + @param nodeList2D: List of nodes that should be validated. + @rtype: list + @return: New list with only valid node tuples. + """ + for i in range(len(nodeList2D)): + nodeList2D[i] = self.__makeNodeTupleFromOid(nodeList2D[i]) + return [nodeTuple for nodeTuple in nodeList2D if + (self.__sliceDB.validateNode(nodeTuple[0]) and + self.__sliceDB.validateNode(nodeTuple[1]))] + + def __checkNodeTuple(self, nodeTuple): + """ + Checks if both tuple entries are valid nodes. + @type nodeTuple: tuple + @param nodeTuple Tuple that should be checked for validity + @type tuple + @return: The old tuple if everything is all right or + an empty tuple if the tuple containes invalid + datatypes or is not in the booked slice + """ + nodeTuple = self.__makeNodeTupleFromOid(nodeTuple) + return nodeTuple if (self.__sliceDB.validateNode(nodeTuple[0]) and + self.__sliceDB.validateNode(nodeTuple[1])) else () + + def __makeNodeFromOid(self, value): + """ + This method checks whether the given 'value' is of type Node or int + (OID), if it is an int, it returns a new Node, with the given + 'value' as OID, otherwise it just returns the Node. + @type value: int/Node + @param value: The value that is checked if it is of type int + or Node. + @rtype Node + @return Newly created node if 'value' was int, or just + returning the given value if the type already + was Node. + """ + if type(value).__name__ == "int": + return Node.Node(value) + elif type(value).__name__ == "Node": + return value + else: + raise TypeError("'node' must be of type 'int' or 'Node'") + + def __makeNodeTupleFromOid(self, nodeTuple): + if type(nodeTuple).__name__ == "tuple" and len(nodeTuple) == 2: + return (self.__makeNodeFromOid(nodeTuple[0]), + self.__makeNodeFromOid(nodeTuple[1])) + else: + raise TypeError("'nodeTuple' must be of type 'tuple' and length " + "must be 2") + + def getPtVolumeStats(self, startTime, stopTime, nodeList): + # Check if all given parameters are valid + startTime = self.__checkDateTime(startTime) # struct_time + stopTime = self.__checkDateTime(stopTime) # struct_time + nodeList = self.__checkNodeList(nodeList) + stats = [] + + for node in nodeList: + maxDelay = 0 + minDelay = maxint + byteCount = 0 + avgPktSize = 0 + number = 0 + + rows = self.__noviDB.selectDelayEntrys(startTime, stopTime, + node.oid) + if len(rows) != 0: + for row in rows: + if (row[MAXDELAY] > maxDelay): + maxDelay = row[MAXDELAY] + if (row[MINDELAY] < minDelay): + minDelay = row[MINDELAY] + byteCount += row[SUMBYTES] + number += row[NUM] + + if number != 0: + avgPktSize = byteCount/number + stats.append(PtVolumeStats.PtVolumeStats(startTime, stopTime, node, + number, avgPktSize)) + return stats + + def getPtHopStats(self, startTime, stopTime, nodeList2D): + # Check if all given parameters are valid + startTime = self.__checkDateTime(startTime) # struct_time + stopTime = self.__checkDateTime(stopTime) # struct_time + nodeList2D = self.__checkNodeList2D(nodeList2D) + stats = [] + + for nodeTuple in nodeList2D: + src = nodeTuple[0] + dst = nodeTuple[1] + + maxDelay = 0 + minDelay = maxint + byteCount = 0 + avgPktSize = 0 + delayCount = 0 + avgDelay = 0 + number = 0 + + rows = self.__noviDB.selectHopDelays(startTime, stopTime, + src.oid, dst.oid) + if len(rows) != 0: + for row in rows: + if (row[MAXDELAY] > maxDelay): + maxDelay = row[MAXDELAY] + if (row[MINDELAY] < minDelay): + minDelay = row[MINDELAY] + byteCount += row[SUMBYTES] + delayCount += row[SUMDELAY] + number += row[NUM] + + if number != 0: + avgPktSize = byteCount/number + avgDelay = delayCount/number + + stats.append(PtHopStats.PtHopStats(startTime, stopTime, src, dst, + number, avgDelay, avgPktSize)) + return stats + + def getPtPathStats(self, startTime, stopTime, nodeTuple): + # Check if all given parameters are valid + startTime = self.__checkDateTime(startTime) # struct_time + stopTime = self.__checkDateTime(stopTime) # struct_time + nodeTuple = self.__checkNodeTuple(nodeTuple) + stats = [] + + if len(nodeTuple) == 0: + return stats + src = nodeTuple[0] + dst = nodeTuple[1] + path = "" + + rows = self.__noviDB.selectPathDelays(startTime, stopTime, + src.oid, dst.oid) + if len(rows) != 0: + for row in rows: + if len(path) == 0: + maxDelay = 0 + minDelay = maxint + byteCount = 0 + avgPktSize = 0 + delayCount = 0 + avgDelay = 0 + number = 0 + path = row[PATH] + if row[PATH] != path: + stats.append(PtPathStats.PtPathStats(startTime, stopTime, + src, dst, number, + avgPktSize, avgDelay, + path)) + path = "" + else: + if (row[MAXDELAY] > maxDelay): + maxDelay = row[MAXDELAY] + if (row[MINDELAY] < minDelay): + minDelay = row[MINDELAY] + byteCount += row[SUMBYTES] + delayCount += row[SUMDELAY] + number += row[NUM] + + if number != 0: + avgPktSize = byteCount/number + avgDelay = delayCount/number + + stats.append(PtPathStats.PtPathStats(startTime, stopTime, src, dst, + number, avgPktSize, avgDelay, + path)) + return stats + + def getPtActivity(self, startTime, stopTime, nodeList): + # Check if all given parameters are valid + startTime = self.__checkDateTime(startTime) # struct_time + stopTime = self.__checkDateTime(stopTime) # struct_time + nodeList = self.__checkNodeList(nodeList) + stats = [] + + for node in nodeList: + activity = 0 + packets = 0 + percentile = 0 + + rows = self.__noviDB.selectActivityEntries(startTime, stopTime, + node.oid) + if len(rows) != 0: + for row in rows: + packets += row[NUM] + + activity = packets*self.__sliceDB.selectActivityThreshold(node.oid) + + if(mktime(stopTime) - mktime(startTime) != 0): + percentile = activity*100 /((mktime(stopTime) - + mktime(startTime)) *1000*1000) + + if percentile > 100: + percentile = 100 + stats.append(PtActivity.PtActivity(startTime, stopTime, node, + percentile)) + return stats + + def restartPtCollector(self): + # Carsten/Jens + print "restartPtCollector" + return Status.Status() + + def restartPtProbes(self, nodeList): + # Carsten/Jens + print "restartPtProbes" + return Status.Status() + + def purgePtDatabase(self, startTime, stopTime): + #TODO: Fix the return type to a real Status + self.__noviDB.purgeDelayDB(startTime, stopTime) + return Status.Status() + + def setPtHashRange(self, range): + #TODO: Fix the return type to a real Status + try: + if int(range) <= 100 and int(range) > 0: + self.__sliceDB.updateHashRange(range) + return Status.Status() + else: + raise ValueError + except ValueError: + print "Invalid range, value must an integer between 1 and 100." + return Status.Status(-1) + + def setPtHashFunction(self, hashFunction): + #TODO: Fix the return type to a real Status + if self.__checkHashFuntion(hashFunction): + self.__sliceDB.updateHashFunction(hashFunction) + return Status.Status() + else: + print hashFunction + ": Unknown hashing function." + return Status.Status(-1) + + + def setPtActivityThreshold(self, timeMSec): + #TODO: Fix the return type to a real Status + self.__sliceDB.updateActivityThreshold(timeMSec) + return Status.Status() + + def viewPtPathTracks(self, startTime, stopTime, nodeList): + # Spaeter + print "viewPtPathTracks" + return Status.Status() + + def viewPtHopTracks(self, startTime, stoptime, nodeList2D): + # Spaeter + print "viewPtHopTracks" + return Status.Status() + + def plotPtPathStats(self, startTime, stopTime, nodeList): + print "plotPtPathStats" + return Status.Status() + + def plotPtHopStats(self, startTime, stopTime, nodeList2D): + # Check if all given parameters are valid + startTime = self.__checkDateTime(startTime) # struct_time + stopTime = self.__checkDateTime(stopTime) # struct_time + nodeList2D = self.__checkNodeList2D(nodeList2D) + + for nodeTuple in nodeList2D: + src = nodeTuple[0] + dst = nodeTuple[1] + delaysY = [] + timeX = [] + + rows = self.__noviDB.selectHopDelays(startTime, stopTime, + src.oid, dst.oid) + if len(rows) != 0: + for row in rows: + delaysY.append(row[SUMDELAY]/row[NUM]) + timeX.append(row[TS]) + self.__delayPlotter.plotStats(timeX, delaysY) + else: + return Status.Status(-1) + + return Status.Status() diff --git a/Monitoring/MonitoringTool/PacketTracking/Monitoring/Aggregator/DBAccess.py b/Monitoring/MonitoringTool/PacketTracking/Monitoring/Aggregator/DBAccess.py new file mode 100644 index 0000000..966fb5d --- /dev/null +++ b/Monitoring/MonitoringTool/PacketTracking/Monitoring/Aggregator/DBAccess.py @@ -0,0 +1,124 @@ +""" +Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project +Copyright according to BSD License +For full text of the license see: ./novi/Software/Monitoring/MonitoringTool/PacketTracking/license.txt + +@author <a href="mailto:ramon.masek@fokus.fraunhofer.de">Ramon Masek</a>, Fraunhofer FOKUS +@author <a href="mailto:c.henke@tu-berlin.de">Christian Henke</a>, Technical University Berlin +@author <a href="mailto:carsten.schmoll@fokus.fraunhofer.de">Carsten Schmoll</a>, Fraunhofer FOKUS +@author <a href="mailto:Julian.Vetter@campus.tu-berlin.de">Julian Vetter</a>, Fraunhofer FOKUS +@author <a href="mailto:">Jens Krenzin</a>, Fraunhofer FOKUS +@author <a href="mailto:">Michael Gehring</a>, Fraunhofer FOKUS +@author <a href="mailto:">Tacio Grespan Santos</a>, Fraunhofer FOKUS +@author <a href="mailto:">Fabian Wolff</a>, Fraunhofer FOKUS +""" + +from time import mktime + +from Task.Passive.Monitoring.Database.DBConnector import DBConnector + +class DBAccess(DBConnector): + def __init__(self, host = "127.0.0.1", port = 5432, + db = "dump", user = "user", pwd = "pwd"): + DBConnector.__init__(self, host, port, db, user, pwd) + + def selectDelayEntrys(self, startTime, stopTime, nodeOid): + """ + Function to select a set of delay information from the database. The + statement calls 'SELECT num, sumbytes, sumdelay, mindelay, maxdelay FROM + delays WHERE (ts >= startTime AND ts <= stopTime) AND (src = nodeOid OR + dst = nodeOid);'. + @type startTime: struct_time + @param startTime: A sequence of 9 integers, as returned from + gmtime(), localtime() or strptime(). + @type stopTime: struct_time + @param stopTime: A sequence of 9 integers, as returned from + gmtime(), localtime() or strptime(). + @rtype: list + @return: List of rows that match the time interval and also + the nodes OID + """ + startTimeString = str(int(mktime(startTime)*1000*1000)) # sec->musec + stopTimeString = str(int(mktime(stopTime)*1000*1000)) # sec->musec + statement = ("SELECT num, sumbytes, sumdelay, mindelay, maxdelay " + "FROM hop_delays WHERE (ts >= " + startTimeString + + " AND ts <= " + stopTimeString + ") AND (src = " + + str(nodeOid) + " OR dst = " + str(nodeOid) + ");") + connection = self.connect() + rows = self.executeSelect(connection, statement) + self.disconnect(connection) + return rows + + def selectActivityEntries(self, startTime, stopTime, nodeOid): + """ + Method to get the activity of a node (number of packets in the defined + time interval). + @type startTime: struct_time + @param startTime: A sequence of 9 integers, as returned from + gmtime(), localtime() or strptime(). + @type stopTime: struct_time + @param stopTime: A sequence of 9 integers, as returned from + gmtime(), localtime() or strptime(). + @rtype: list + @return: List of rows that match the time interval and also + the nodes OID + """ + startTimeString = str(int(mktime(startTime)*1000*1000)) # sec->musec + stopTimeString = str(int(mktime(stopTime)*1000*1000)) # sec->musec + statement = ("SELECT num FROM hop_delays WHERE (ts >= " + + startTimeString + " AND ts <= " + stopTimeString + ") " + "AND (src = " + str(nodeOid) + " OR dst = " + + str(nodeOid) + ");") + connection = self.connect() + rows = self.executeSelect(connection, statement) + self.disconnect(connection) + return rows + + def selectPathDelays(self, startTime, stopTime, srcOid, dstOid): + startTimeString = str(int(mktime(startTime)*1000*1000)) # sec->musec + stopTimeString = str(int(mktime(stopTime)*1000*1000)) # sec->musec + statement = ("SELECT num, sumbytes, sumdelay, mindelay, maxdelay, path " + "FROM path_delays WHERE (ts >= " + startTimeString + + " AND ts <= " + stopTimeString + ") AND (src = " + + str(srcOid) + " AND dst = " + str(dstOid) + ") " + "ORDER BY path ASC;") + connection = self.connect() + rows = self.executeSelect(connection, statement) + self.disconnect(connection) + return rows + + def selectHopDelays(self, startTime, stopTime, srcOid, dstOid): + startTimeString = str(int(mktime(startTime)*1000*1000)) # sec->musec + stopTimeString = str(int(mktime(stopTime)*1000*1000)) # sec->musec + statement = ("SELECT num, sumbytes, sumdelay, mindelay, maxdelay, ts " + "FROM hop_delays WHERE (ts >= " + startTimeString + + " AND ts <= " + stopTimeString + ") AND (src = " + + str(srcOid) + " AND dst = " + str(dstOid) + ");") + connection = self.connect() + rows = self.executeSelect(connection, statement) + self.disconnect(connection) + return rows + + def purgeDelayDB(self, startTime, stopTime): + """ + Function to remove a set of observed tracks from the database in the + interval between 'StartTime' and 'StopTime'. The statement calls 'DELETE + FROM delays WHERE (ts >= startTime AND ts <= stopTime);' + @type startTime: struct_time + @param startTime: A sequence of 9 integers, as returned from + gmtime(), localtime() or strptime(). + @type stopTime: struct_time + @param stopTime: A sequence of 9 integers, as returned from + gmtime(), localtime() or strptime(). + @rtype: Integer + @return: Returns the number of purged rows on success -1 + otherwise. + """ + startTimeString = str(int(mktime(startTime)*1000*1000)) # sec->musec + stopTimeString = str(int(mktime(stopTime)*1000*1000)) # sec->musec + statement = ("DELETE FROM hop_delays WHERE (ts >= " + startTimeString + + " AND ts <= " + stopTimeString + ");") + connection = self.connect() + self.executeUpdate(connection, statement) + self.disconnect(connection) + diff --git a/Monitoring/MonitoringTool/PacketTracking/Monitoring/Aggregator/DelayPlotter.py b/Monitoring/MonitoringTool/PacketTracking/Monitoring/Aggregator/DelayPlotter.py new file mode 100644 index 0000000..36e9d5a --- /dev/null +++ b/Monitoring/MonitoringTool/PacketTracking/Monitoring/Aggregator/DelayPlotter.py @@ -0,0 +1,24 @@ +""" +Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project +Copyright according to BSD License +For full text of the license see: ./novi/Software/Monitoring/MonitoringTool/PacketTracking/license.txt + +@author <a href="mailto:ramon.masek@fokus.fraunhofer.de">Ramon Masek</a>, Fraunhofer FOKUS +@author <a href="mailto:c.henke@tu-berlin.de">Christian Henke</a>, Technical University Berlin +@author <a href="mailto:carsten.schmoll@fokus.fraunhofer.de">Carsten Schmoll</a>, Fraunhofer FOKUS +@author <a href="mailto:Julian.Vetter@campus.tu-berlin.de">Julian Vetter</a>, Fraunhofer FOKUS +@author <a href="mailto:">Jens Krenzin</a>, Fraunhofer FOKUS +@author <a href="mailto:">Michael Gehring</a>, Fraunhofer FOKUS +@author <a href="mailto:">Tacio Grespan Santos</a>, Fraunhofer FOKUS +@author <a href="mailto:">Fabian Wolff</a>, Fraunhofer FOKUS +""" + +from matplotlib.pyplot import plot, show + +class DelayPlotter(object): + def __init__(self): + pass + + def plotStats(self, x, y): + plot(x,y) + show()
\ No newline at end of file diff --git a/Monitoring/MonitoringTool/PacketTracking/Monitoring/Aggregator/__init__.py b/Monitoring/MonitoringTool/PacketTracking/Monitoring/Aggregator/__init__.py new file mode 100644 index 0000000..fcc3deb --- /dev/null +++ b/Monitoring/MonitoringTool/PacketTracking/Monitoring/Aggregator/__init__.py @@ -0,0 +1,22 @@ +""" +Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project +Copyright according to BSD License +For full text of the license see: ./novi/Software/Monitoring/MonitoringTool/PacketTracking/license.txt + +@author <a href="mailto:ramon.masek@fokus.fraunhofer.de">Ramon Masek</a>, Fraunhofer FOKUS +@author <a href="mailto:c.henke@tu-berlin.de">Christian Henke</a>, Technical University Berlin +@author <a href="mailto:carsten.schmoll@fokus.fraunhofer.de">Carsten Schmoll</a>, Fraunhofer FOKUS +@author <a href="mailto:Julian.Vetter@campus.tu-berlin.de">Julian Vetter</a>, Fraunhofer FOKUS +@author <a href="mailto:">Jens Krenzin</a>, Fraunhofer FOKUS +@author <a href="mailto:">Michael Gehring</a>, Fraunhofer FOKUS +@author <a href="mailto:">Tacio Grespan Santos</a>, Fraunhofer FOKUS +@author <a href="mailto:">Fabian Wolff</a>, Fraunhofer FOKUS +""" + +from Aggregator import Aggregator + +def main(): + A = Aggregator() + +if __name__ == "__main__": + main()
\ No newline at end of file diff --git a/Monitoring/MonitoringTool/PacketTracking/Monitoring/DataTypes/Node.py b/Monitoring/MonitoringTool/PacketTracking/Monitoring/DataTypes/Node.py new file mode 100644 index 0000000..98f9017 --- /dev/null +++ b/Monitoring/MonitoringTool/PacketTracking/Monitoring/DataTypes/Node.py @@ -0,0 +1,34 @@ +""" +Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project +Copyright according to BSD License +For full text of the license see: ./novi/Software/Monitoring/MonitoringTool/PacketTracking/license.txt + +@author <a href="mailto:ramon.masek@fokus.fraunhofer.de">Ramon Masek</a>, Fraunhofer FOKUS +@author <a href="mailto:c.henke@tu-berlin.de">Christian Henke</a>, Technical University Berlin +@author <a href="mailto:carsten.schmoll@fokus.fraunhofer.de">Carsten Schmoll</a>, Fraunhofer FOKUS +@author <a href="mailto:Julian.Vetter@campus.tu-berlin.de">Julian Vetter</a>, Fraunhofer FOKUS +@author <a href="mailto:">Jens Krenzin</a>, Fraunhofer FOKUS +@author <a href="mailto:">Michael Gehring</a>, Fraunhofer FOKUS +@author <a href="mailto:">Tacio Grespan Santos</a>, Fraunhofer FOKUS +@author <a href="mailto:">Fabian Wolff</a>, Fraunhofer FOKUS +""" + +from IPy import IP + +class Node(object): + def __init__(self, oid = 0, ip = "0.0.0.0", + latitude = 0.0, longitude = 0.0): + self.oid = oid + self.ip = ip + self.latitude = latitude + self.longitude = longitude + + def set_ip(self, ip): + try: + IP(ip) + self.ip = ip + except ValueError: + self.ip = "0.0.0.0" + + def __str__(self): + return (str(self.oid) + " (" + str(self.ip) + ")") diff --git a/Monitoring/MonitoringTool/PacketTracking/Monitoring/DataTypes/PtActivity.py b/Monitoring/MonitoringTool/PacketTracking/Monitoring/DataTypes/PtActivity.py new file mode 100644 index 0000000..766761a --- /dev/null +++ b/Monitoring/MonitoringTool/PacketTracking/Monitoring/DataTypes/PtActivity.py @@ -0,0 +1,53 @@ +""" +Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project +Copyright according to BSD License +For full text of the license see: ./novi/Software/Monitoring/MonitoringTool/PacketTracking/license.txt + +@author <a href="mailto:ramon.masek@fokus.fraunhofer.de">Ramon Masek</a>, Fraunhofer FOKUS +@author <a href="mailto:c.henke@tu-berlin.de">Christian Henke</a>, Technical University Berlin +@author <a href="mailto:carsten.schmoll@fokus.fraunhofer.de">Carsten Schmoll</a>, Fraunhofer FOKUS +@author <a href="mailto:Julian.Vetter@campus.tu-berlin.de">Julian Vetter</a>, Fraunhofer FOKUS +@author <a href="mailto:">Jens Krenzin</a>, Fraunhofer FOKUS +@author <a href="mailto:">Michael Gehring</a>, Fraunhofer FOKUS +@author <a href="mailto:">Tacio Grespan Santos</a>, Fraunhofer FOKUS +@author <a href="mailto:">Fabian Wolff</a>, Fraunhofer FOKUS +""" + +from time import mktime, time, strftime, localtime + +from Task.Passive.Monitoring.DataTypes import Node + +class PtActivity(object): + def __init__(self, startTime = time(), stopTime = time(), + node = Node.Node(), activity = 0): + self.startTime = mktime(startTime) + self.stopTime = mktime(stopTime) + self.node = node + self.activity = activity + + def __str__(self): + startTime = strftime("%a, %d %b %Y %H:%M:%S", localtime(self.startTime)) + stopTime = strftime("%a, %d %b %Y %H:%M:%S", localtime(self.stopTime)) + return ("PtActivity:\n" + " Node (Oid): " + str(self.node) + "\n" + " StartTime: " + startTime + "\n" + " StopTime: " + stopTime + "\n" + " Activity: " + str(self.activity) + " %") + + def set_StartTime(self, StartTime): + """ + Overwritten setter functions to convert the time_struct into a real + timestamp. + @type StartTime: struct_time + @param StartTime Time that defines the start of the observation + """ + self.StartTime = mktime(StartTime) + + def set_StopTime(self, StopTime): + """ + Overwritten setter functions to convert the time_struct into a real + timestamp. + @type StartTime: struct_time + @param StartTime Time that defines the end of the observation + """ + self.StopTime = mktime(StopTime)
\ No newline at end of file diff --git a/Monitoring/MonitoringTool/PacketTracking/Monitoring/DataTypes/PtHopStats.py b/Monitoring/MonitoringTool/PacketTracking/Monitoring/DataTypes/PtHopStats.py new file mode 100644 index 0000000..4e887fa --- /dev/null +++ b/Monitoring/MonitoringTool/PacketTracking/Monitoring/DataTypes/PtHopStats.py @@ -0,0 +1,67 @@ +""" +Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project +Copyright according to BSD License +For full text of the license see: ./novi/Software/Monitoring/MonitoringTool/PacketTracking/license.txt + +@author <a href="mailto:ramon.masek@fokus.fraunhofer.de">Ramon Masek</a>, Fraunhofer FOKUS +@author <a href="mailto:c.henke@tu-berlin.de">Christian Henke</a>, Technical University Berlin +@author <a href="mailto:carsten.schmoll@fokus.fraunhofer.de">Carsten Schmoll</a>, Fraunhofer FOKUS +@author <a href="mailto:Julian.Vetter@campus.tu-berlin.de">Julian Vetter</a>, Fraunhofer FOKUS +@author <a href="mailto:">Jens Krenzin</a>, Fraunhofer FOKUS +@author <a href="mailto:">Michael Gehring</a>, Fraunhofer FOKUS +@author <a href="mailto:">Tacio Grespan Santos</a>, Fraunhofer FOKUS +@author <a href="mailto:">Fabian Wolff</a>, Fraunhofer FOKUS +""" + +from time import mktime, time, strftime, localtime + +from Task.Passive.Monitoring.DataTypes import Node + +class PtHopStats(object): + """ + Packet tracking Hop statistics, i.e. delay/volume statistics between two + neighbor Pt probes + """ + def __init__(self, startTime = time(), stopTime = time(), + src = Node.Node(), dst = Node.Node(), number = 0, + avgPktSize = 0, avgDelay = 0): + self.startTime = mktime(startTime) + self.stopTime = mktime(stopTime) + self.src = src + self.dst = dst + self.number = number + self.avgPktSize = avgPktSize + self.avgDelay = avgDelay + + def __str__(self): + startTime = strftime("%a, %d %b %Y %H:%M:%S", + localtime(self.startTime)) + stopTime = strftime("%a, %d %b %Y %H:%M:%S", + localtime(self.stopTime)) + return ("PtHopStats:\n" + " Src. Node: " + str(self.src) + "\n" + + " Dst. Node: " + str(self.dst) + "\n" + + " StartTime: " + startTime + "\n" + + " StopTime: " + stopTime + "\n" + + " Packets: " + str(self.number) + " Pkts\n" + " Avg. Pktsize: " + str(self.avgPktSize) + " Bytes\n" + + " Avg. Delay: " + str(self.avgDelay) + " ms") + + def set_startTime(self, startTime): + """ + Overwritten setter functions to convert the time_struct into a real + timestamp. + @type StartTime: struct_time + @param StartTime Time that defines the start of the + observation + """ + self.startTime = mktime(startTime) + + def set_stopTime(self, stopTime): + """ + Overwritten setter functions to convert the time_struct into a real + timestamp. + @type StartTime: struct_time + @param StartTime Time that defines the end of the observation + """ + self.stopTime = mktime(stopTime)
\ No newline at end of file diff --git a/Monitoring/MonitoringTool/PacketTracking/Monitoring/DataTypes/PtPathStats.py b/Monitoring/MonitoringTool/PacketTracking/Monitoring/DataTypes/PtPathStats.py new file mode 100644 index 0000000..332087c --- /dev/null +++ b/Monitoring/MonitoringTool/PacketTracking/Monitoring/DataTypes/PtPathStats.py @@ -0,0 +1,64 @@ +""" +Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project +Copyright according to BSD License +For full text of the license see: ./novi/Software/Monitoring/MonitoringTool/PacketTracking/license.txt + +@author <a href="mailto:ramon.masek@fokus.fraunhofer.de">Ramon Masek</a>, Fraunhofer FOKUS +@author <a href="mailto:c.henke@tu-berlin.de">Christian Henke</a>, Technical University Berlin +@author <a href="mailto:carsten.schmoll@fokus.fraunhofer.de">Carsten Schmoll</a>, Fraunhofer FOKUS +@author <a href="mailto:Julian.Vetter@campus.tu-berlin.de">Julian Vetter</a>, Fraunhofer FOKUS +@author <a href="mailto:">Jens Krenzin</a>, Fraunhofer FOKUS +@author <a href="mailto:">Michael Gehring</a>, Fraunhofer FOKUS +@author <a href="mailto:">Tacio Grespan Santos</a>, Fraunhofer FOKUS +@author <a href="mailto:">Fabian Wolff</a>, Fraunhofer FOKUS +""" + +from time import mktime, time, strftime, localtime + +from Task.Passive.Monitoring.DataTypes import Node + +class PtPathStats(object): + def __init__(self, startTime = time(), stopTime = time(), src = Node.Node(), + dst = Node.Node(), number = 0, avgPktSize = 0, + avgDelay = 0, path = ""): + self.startTime = mktime(startTime) + self.stopTime = mktime(stopTime) + self.src = src + self.dst = dst + self.number = number + self.avgPktSize = avgPktSize + self.avgDelay = avgDelay + self.path = path + + def __str__(self): + startTime = strftime("%a, %d %b %Y %H:%M:%S", + localtime(self.startTime)) + stopTime = strftime("%a, %d %b %Y %H:%M:%S", + localtime(self.stopTime)) + return ("PtPathStats:\n" + " Src. Node: " + str(self.src) + "\n" + + " Dst. Node: " + str(self.dst) + "\n" + + " Path: " + self.path + "\n" + + " StartTime: " + startTime + "\n" + + " StopTime: " + stopTime + "\n" + + " Packets: " + str(self.number) + " Pkts\n" + " Avg. Pktsize: " + str(self.avgPktSize) + " Bytes\n" + + " Avg. Delay: " + str(self.avgDelay) + " ms") + + def set_startTime(self, startTime): + """ + Overwritten setter functions to convert the time_struct into a real + timestamp. + @type StartTime: struct_time + @param StartTime Time that defines the start of the observation + """ + self.startTime = mktime(startTime) + + def set_stopTime(self, stopTime): + """ + Overwritten setter functions to convert the time_struct into a real + timestamp. + @type StartTime: struct_time + @param StartTime Time that defines the end of the observation + """ + self.stopTime = mktime(stopTime)
\ No newline at end of file diff --git a/Monitoring/MonitoringTool/PacketTracking/Monitoring/DataTypes/PtVolumeStats.py b/Monitoring/MonitoringTool/PacketTracking/Monitoring/DataTypes/PtVolumeStats.py new file mode 100644 index 0000000..78bce1e --- /dev/null +++ b/Monitoring/MonitoringTool/PacketTracking/Monitoring/DataTypes/PtVolumeStats.py @@ -0,0 +1,60 @@ +""" +Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project +Copyright according to BSD License +For full text of the license see: ./novi/Software/Monitoring/MonitoringTool/PacketTracking/license.txt + +@author <a href="mailto:ramon.masek@fokus.fraunhofer.de">Ramon Masek</a>, Fraunhofer FOKUS +@author <a href="mailto:c.henke@tu-berlin.de">Christian Henke</a>, Technical University Berlin +@author <a href="mailto:carsten.schmoll@fokus.fraunhofer.de">Carsten Schmoll</a>, Fraunhofer FOKUS +@author <a href="mailto:Julian.Vetter@campus.tu-berlin.de">Julian Vetter</a>, Fraunhofer FOKUS +@author <a href="mailto:">Jens Krenzin</a>, Fraunhofer FOKUS +@author <a href="mailto:">Michael Gehring</a>, Fraunhofer FOKUS +@author <a href="mailto:">Tacio Grespan Santos</a>, Fraunhofer FOKUS +@author <a href="mailto:">Fabian Wolff</a>, Fraunhofer FOKUS +""" + +from time import mktime, time, strftime, localtime + +from Task.Passive.Monitoring.DataTypes import Node + +class PtVolumeStats(object): + """ + (at least) number of packets and bytes observed by a Node + """ + def __init__(self, startTime = time(), stopTime = time(), + node = Node.Node(), number = 0, avgPktSize = 0): + self.startTime = mktime(startTime) + self.stopTime = mktime(stopTime) + self.node = node + self.number = number + self.avgPktSize = avgPktSize + + def __str__(self): + startTime = strftime("%a, %d %b %Y %H:%M:%S", localtime(self.startTime)) + stopTime = strftime("%a, %d %b %Y %H:%M:%S", localtime(self.stopTime)) + Str = ("PtVolumeStats:\n" + " Node: " + str(self.node) + "\n" + + " StartTime: " + startTime + "\n" + + " StopTime: " + stopTime + "\n" + + " Packets: " + str(self.number) + "\n" + + " Avg. Pktsize: " + str(self.avgPktSize) + " Bytes") + return Str + + + def set_StartTime(self, StartTime): + """ + Overwritten setter functions to convert the time_struct into a real + timestamp. + @type StartTime: struct_time + @param StartTime Time that defines the start of the observation + """ + self.StartTime = mktime(StartTime) + + def set_StopTime(self, StopTime): + """ + Overwritten setter functions to convert the time_struct into a real + timestamp. + @type StartTime: struct_time + @param StartTime Time that defines the end of the observation + """ + self.StopTime = mktime(StopTime)
\ No newline at end of file diff --git a/Monitoring/MonitoringTool/PacketTracking/Monitoring/DataTypes/Status.py b/Monitoring/MonitoringTool/PacketTracking/Monitoring/DataTypes/Status.py new file mode 100644 index 0000000..6206c57 --- /dev/null +++ b/Monitoring/MonitoringTool/PacketTracking/Monitoring/DataTypes/Status.py @@ -0,0 +1,25 @@ +""" +Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project +Copyright according to BSD License +For full text of the license see: ./novi/Software/Monitoring/MonitoringTool/PacketTracking/license.txt + +@author <a href="mailto:ramon.masek@fokus.fraunhofer.de">Ramon Masek</a>, Fraunhofer FOKUS +@author <a href="mailto:c.henke@tu-berlin.de">Christian Henke</a>, Technical University Berlin +@author <a href="mailto:carsten.schmoll@fokus.fraunhofer.de">Carsten Schmoll</a>, Fraunhofer FOKUS +@author <a href="mailto:Julian.Vetter@campus.tu-berlin.de">Julian Vetter</a>, Fraunhofer FOKUS +@author <a href="mailto:">Jens Krenzin</a>, Fraunhofer FOKUS +@author <a href="mailto:">Michael Gehring</a>, Fraunhofer FOKUS +@author <a href="mailto:">Tacio Grespan Santos</a>, Fraunhofer FOKUS +@author <a href="mailto:">Fabian Wolff</a>, Fraunhofer FOKUS +""" + + +class Status(object): + """ + Class to handle different errors, and also throw exceptions + """ + def __init__(self, status = 0): + self.status = status + + def __str__(self): + return ("Status:" + str(self.status))
\ No newline at end of file diff --git a/Monitoring/MonitoringTool/PacketTracking/Monitoring/DataTypes/__init__.py b/Monitoring/MonitoringTool/PacketTracking/Monitoring/DataTypes/__init__.py new file mode 100644 index 0000000..92936f3 --- /dev/null +++ b/Monitoring/MonitoringTool/PacketTracking/Monitoring/DataTypes/__init__.py @@ -0,0 +1,15 @@ +""" +Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project +Copyright according to BSD License +For full text of the license see: ./novi/Software/Monitoring/MonitoringTool/PacketTracking/license.txt + +@author <a href="mailto:ramon.masek@fokus.fraunhofer.de">Ramon Masek</a>, Fraunhofer FOKUS +@author <a href="mailto:c.henke@tu-berlin.de">Christian Henke</a>, Technical University Berlin +@author <a href="mailto:carsten.schmoll@fokus.fraunhofer.de">Carsten Schmoll</a>, Fraunhofer FOKUS +@author <a href="mailto:Julian.Vetter@campus.tu-berlin.de">Julian Vetter</a>, Fraunhofer FOKUS +@author <a href="mailto:">Jens Krenzin</a>, Fraunhofer FOKUS +@author <a href="mailto:">Michael Gehring</a>, Fraunhofer FOKUS +@author <a href="mailto:">Tacio Grespan Santos</a>, Fraunhofer FOKUS +@author <a href="mailto:">Fabian Wolff</a>, Fraunhofer FOKUS +""" + diff --git a/Monitoring/MonitoringTool/PacketTracking/Monitoring/Database/DBConnector.py b/Monitoring/MonitoringTool/PacketTracking/Monitoring/Database/DBConnector.py new file mode 100644 index 0000000..1cc6d2a --- /dev/null +++ b/Monitoring/MonitoringTool/PacketTracking/Monitoring/Database/DBConnector.py @@ -0,0 +1,135 @@ +""" +Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project +Copyright according to BSD License +For full text of the license see: ./novi/Software/Monitoring/MonitoringTool/PacketTracking/license.txt + +@author <a href="mailto:ramon.masek@fokus.fraunhofer.de">Ramon Masek</a>, Fraunhofer FOKUS +@author <a href="mailto:c.henke@tu-berlin.de">Christian Henke</a>, Technical University Berlin +@author <a href="mailto:carsten.schmoll@fokus.fraunhofer.de">Carsten Schmoll</a>, Fraunhofer FOKUS +@author <a href="mailto:Julian.Vetter@campus.tu-berlin.de">Julian Vetter</a>, Fraunhofer FOKUS +@author <a href="mailto:">Jens Krenzin</a>, Fraunhofer FOKUS +@author <a href="mailto:">Michael Gehring</a>, Fraunhofer FOKUS +@author <a href="mailto:">Tacio Grespan Santos</a>, Fraunhofer FOKUS +@author <a href="mailto:">Fabian Wolff</a>, Fraunhofer FOKUS +""" + +from IPy import IP + +import psycopg2 + +class DBConnector(object): + def __init__(self, host = "127.0.0.1", port = 5432, + db = "dump", user = "user", pwd = "pwd"): + self.host = host + self.port = port + self.db = db + self.user = user + self.pwd = pwd + + @property + def port(self): + return self.__port + + @port.setter + def port(self, port): + """ + Method to check whether the port is in the valid port range of 1-65535, + if not it raises a ValueError + @type port: int + @param port: Port on which the PostgreSQL database is + listening + """ + if port in range(1, 65535): + self.__port = port + else: + raise ValueError("Port must be in range of 1 to 65535") + + @property + def host(self): + return self.__host + + @host.setter + def host(self, host): + """ + Method to check whether the given host name is a valid IP address. If + not the IP address is set to localhost (127.0.0.1). + @type host: str + @param port: IP on which the PostgreSQL database is + reachable + """ + try: + IP(host) + self.__host = host + except ValueError: + print "Invalid IP address, setting host to 127.0.0.1" + self.__host = "127.0.0.1" + + def __str__(self): + return ("Connected to DB " + self.db + " on " + self.host + + ":" + str(self.port) + " as " + self.user) + + def connect(self): + """ + Method to connect to a PostgreSQL + @type Connection: connection + @param Connection: The connection to the PostgreSQL database + created by 'psycopg2.connect()' + @type Statement: string + @param Statement: String describing the select statement, + e.g. 'SELECT * from table;' + """ + try: + connection = psycopg2.connect("dbname='" + self.db + "' user='" + + self.user + "' host='" + self.host + + "' password='" + self.pwd + "'") + return connection + except psycopg2.Error, msg: + print "Error: ", msg + + def executeSelect(self, connection, statement): + """ + Method that executes a select statement on a PosgreSQL database. + @type connection: connection + @param connection: The connection to the PostgreSQL database + created by 'psycopg2.connect()' + @type statement: str + @param statement: String describing the select statement, + e.g. 'SELECT * from table;' + """ + st = connection.cursor() + rows = [] + try: + st.execute(statement) + rows = st.fetchall() + except Exception: + print "Statement '" + statement + "' can not be executed" + st.close() + return rows + + def executeUpdate(self, connection, statement): + """ + Method that executes an update statement on a PosgreSQL database. + @type connection: connection + @param connection: The connection to the PostgreSQL database + created by 'psycopg2.connect()' + @type statement: str + @param statement: String describing the update statement, + e.g. 'DELETE FROM table WHERE x=3;' + """ + st = connection.cursor() + try: + st.execute(statement) + connection.commit() + except Exception: + print "Statement '" + statement + "' can not be executed" + st.close() + + def disconnect(self, connection): + """ + Method to close a given connection + @type connection: connection + @param connection: A connection to a PostgreSQL that should + be closed database (created by + 'psycopg2.connect()') + """ + connection.close() diff --git a/Monitoring/MonitoringTool/PacketTracking/Monitoring/Database/__init__.py b/Monitoring/MonitoringTool/PacketTracking/Monitoring/Database/__init__.py new file mode 100644 index 0000000..1523109 --- /dev/null +++ b/Monitoring/MonitoringTool/PacketTracking/Monitoring/Database/__init__.py @@ -0,0 +1,24 @@ +""" +Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project +Copyright according to BSD License +For full text of the license see: ./novi/Software/Monitoring/MonitoringTool/PacketTracking/license.txt + +@author <a href="mailto:ramon.masek@fokus.fraunhofer.de">Ramon Masek</a>, Fraunhofer FOKUS +@author <a href="mailto:c.henke@tu-berlin.de">Christian Henke</a>, Technical University Berlin +@author <a href="mailto:carsten.schmoll@fokus.fraunhofer.de">Carsten Schmoll</a>, Fraunhofer FOKUS +@author <a href="mailto:Julian.Vetter@campus.tu-berlin.de">Julian Vetter</a>, Fraunhofer FOKUS +@author <a href="mailto:">Jens Krenzin</a>, Fraunhofer FOKUS +@author <a href="mailto:">Michael Gehring</a>, Fraunhofer FOKUS +@author <a href="mailto:">Tacio Grespan Santos</a>, Fraunhofer FOKUS +@author <a href="mailto:">Fabian Wolff</a>, Fraunhofer FOKUS +""" + +import DBConnector + +def main(): + db = DBConnector.DBConnector() + db.ConnectionInfo() + + +if __name__ == "__main__": + main()
\ No newline at end of file diff --git a/Monitoring/MonitoringTool/PacketTracking/Monitoring/PacketTracking/PacketTracking.py b/Monitoring/MonitoringTool/PacketTracking/Monitoring/PacketTracking/PacketTracking.py new file mode 100644 index 0000000..2f1073e --- /dev/null +++ b/Monitoring/MonitoringTool/PacketTracking/Monitoring/PacketTracking/PacketTracking.py @@ -0,0 +1,18 @@ +""" +Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project +Copyright according to BSD License +For full text of the license see: ./novi/Software/Monitoring/MonitoringTool/PacketTracking/license.txt + +@author <a href="mailto:ramon.masek@fokus.fraunhofer.de">Ramon Masek</a>, Fraunhofer FOKUS +@author <a href="mailto:c.henke@tu-berlin.de">Christian Henke</a>, Technical University Berlin +@author <a href="mailto:carsten.schmoll@fokus.fraunhofer.de">Carsten Schmoll</a>, Fraunhofer FOKUS +@author <a href="mailto:Julian.Vetter@campus.tu-berlin.de">Julian Vetter</a>, Fraunhofer FOKUS +@author <a href="mailto:">Jens Krenzin</a>, Fraunhofer FOKUS +@author <a href="mailto:">Michael Gehring</a>, Fraunhofer FOKUS +@author <a href="mailto:">Tacio Grespan Santos</a>, Fraunhofer FOKUS +@author <a href="mailto:">Fabian Wolff</a>, Fraunhofer FOKUS +""" + +class PacketTracking(object): + def __init__(self): + pass diff --git a/Monitoring/MonitoringTool/PacketTracking/Monitoring/PacketTracking/__init__.py b/Monitoring/MonitoringTool/PacketTracking/Monitoring/PacketTracking/__init__.py new file mode 100644 index 0000000..92936f3 --- /dev/null +++ b/Monitoring/MonitoringTool/PacketTracking/Monitoring/PacketTracking/__init__.py @@ -0,0 +1,15 @@ +""" +Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project +Copyright according to BSD License +For full text of the license see: ./novi/Software/Monitoring/MonitoringTool/PacketTracking/license.txt + +@author <a href="mailto:ramon.masek@fokus.fraunhofer.de">Ramon Masek</a>, Fraunhofer FOKUS +@author <a href="mailto:c.henke@tu-berlin.de">Christian Henke</a>, Technical University Berlin +@author <a href="mailto:carsten.schmoll@fokus.fraunhofer.de">Carsten Schmoll</a>, Fraunhofer FOKUS +@author <a href="mailto:Julian.Vetter@campus.tu-berlin.de">Julian Vetter</a>, Fraunhofer FOKUS +@author <a href="mailto:">Jens Krenzin</a>, Fraunhofer FOKUS +@author <a href="mailto:">Michael Gehring</a>, Fraunhofer FOKUS +@author <a href="mailto:">Tacio Grespan Santos</a>, Fraunhofer FOKUS +@author <a href="mailto:">Fabian Wolff</a>, Fraunhofer FOKUS +""" + diff --git a/Monitoring/MonitoringTool/PacketTracking/Monitoring/PacketTrackingGui/PacketTrackingGUI.py b/Monitoring/MonitoringTool/PacketTracking/Monitoring/PacketTrackingGui/PacketTrackingGUI.py new file mode 100644 index 0000000..b17533d --- /dev/null +++ b/Monitoring/MonitoringTool/PacketTracking/Monitoring/PacketTrackingGui/PacketTrackingGUI.py @@ -0,0 +1,18 @@ +""" +Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project +Copyright according to BSD License +For full text of the license see: ./novi/Software/Monitoring/MonitoringTool/PacketTracking/license.txt + +@author <a href="mailto:ramon.masek@fokus.fraunhofer.de">Ramon Masek</a>, Fraunhofer FOKUS +@author <a href="mailto:c.henke@tu-berlin.de">Christian Henke</a>, Technical University Berlin +@author <a href="mailto:carsten.schmoll@fokus.fraunhofer.de">Carsten Schmoll</a>, Fraunhofer FOKUS +@author <a href="mailto:Julian.Vetter@campus.tu-berlin.de">Julian Vetter</a>, Fraunhofer FOKUS +@author <a href="mailto:">Jens Krenzin</a>, Fraunhofer FOKUS +@author <a href="mailto:">Michael Gehring</a>, Fraunhofer FOKUS +@author <a href="mailto:">Tacio Grespan Santos</a>, Fraunhofer FOKUS +@author <a href="mailto:">Fabian Wolff</a>, Fraunhofer FOKUS +""" + +class PacketTrackingGUI(object): + def __init__(self): + pass diff --git a/Monitoring/MonitoringTool/PacketTracking/Monitoring/PacketTrackingGui/__init__.py b/Monitoring/MonitoringTool/PacketTracking/Monitoring/PacketTrackingGui/__init__.py new file mode 100644 index 0000000..92936f3 --- /dev/null +++ b/Monitoring/MonitoringTool/PacketTracking/Monitoring/PacketTrackingGui/__init__.py @@ -0,0 +1,15 @@ +""" +Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project +Copyright according to BSD License +For full text of the license see: ./novi/Software/Monitoring/MonitoringTool/PacketTracking/license.txt + +@author <a href="mailto:ramon.masek@fokus.fraunhofer.de">Ramon Masek</a>, Fraunhofer FOKUS +@author <a href="mailto:c.henke@tu-berlin.de">Christian Henke</a>, Technical University Berlin +@author <a href="mailto:carsten.schmoll@fokus.fraunhofer.de">Carsten Schmoll</a>, Fraunhofer FOKUS +@author <a href="mailto:Julian.Vetter@campus.tu-berlin.de">Julian Vetter</a>, Fraunhofer FOKUS +@author <a href="mailto:">Jens Krenzin</a>, Fraunhofer FOKUS +@author <a href="mailto:">Michael Gehring</a>, Fraunhofer FOKUS +@author <a href="mailto:">Tacio Grespan Santos</a>, Fraunhofer FOKUS +@author <a href="mailto:">Fabian Wolff</a>, Fraunhofer FOKUS +""" + diff --git a/Monitoring/MonitoringTool/PacketTracking/Monitoring/PassiveMonitoring.py b/Monitoring/MonitoringTool/PacketTracking/Monitoring/PassiveMonitoring.py new file mode 100644 index 0000000..0018788 --- /dev/null +++ b/Monitoring/MonitoringTool/PacketTracking/Monitoring/PassiveMonitoring.py @@ -0,0 +1,268 @@ +""" +Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project +Copyright according to BSD License +For full text of the license see: ./novi/Software/Monitoring/MonitoringTool/PacketTracking/license.txt + +@author <a href="mailto:ramon.masek@fokus.fraunhofer.de">Ramon Masek</a>, Fraunhofer FOKUS +@author <a href="mailto:c.henke@tu-berlin.de">Christian Henke</a>, Technical University Berlin +@author <a href="mailto:carsten.schmoll@fokus.fraunhofer.de">Carsten Schmoll</a>, Fraunhofer FOKUS +@author <a href="mailto:Julian.Vetter@campus.tu-berlin.de">Julian Vetter</a>, Fraunhofer FOKUS +@author <a href="mailto:">Jens Krenzin</a>, Fraunhofer FOKUS +@author <a href="mailto:">Michael Gehring</a>, Fraunhofer FOKUS +@author <a href="mailto:">Tacio Grespan Santos</a>, Fraunhofer FOKUS +@author <a href="mailto:">Fabian Wolff</a>, Fraunhofer FOKUS +""" + +from Task.Passive.Monitoring.Aggregator import Aggregator + +class PassiveMonitoring(object): + + def __init__(self): + self.__Aggregator = Aggregator() + + + # PT Actions + # 1. + def getPtVolumeStats(self, startTime, stopTime, nodeList): + """ + Function to retrieve the observed traffic in the time intervall defined + between startTime and stopTime. Traffic means, packet/byte count for + each node in the list. + @type startTime: struct_time + @param startTime: A sequence of 9 integers, as returned from + gmtime(), localtime() or strptime(). + @type stopTime: struct_time + @param stopTime: A sequence of 9 integers, as returned from + gmtime(), localtime() or strptime(). + @type nodeList: list + @param nodeList: List of nodes, whereby a node is one installed + monitoring probe. + @rtype: PtVolumeStats (list) + @return: (At least) number of packets and bytes observed by + a node. + """ + return self.__Aggregator.getPtVolumeStats(startTime, stopTime, nodeList) + + # 2. + def getPtHopStats(self, startTime, stopTime, nodeList2D): + """ + Function to retrieve the observed traffic statistics in the time + intervall defined between startTime and stopTime. Statistics mean + packet/byte count and min/max/avg delay between each adjacent node/node + pair. + @type startTime: struct_time + @param startTime: A sequence of 9 integers, as returned from + gmtime(), localtime() or strptime(). + @type StopTime: struct_time + @param StopTime: A sequence of 9 integers, as returned from + gmtime(), localtime() or strptime(). + @type nodeList2D: list + @param nodeList2D: A List of <first, second> Node pairs. + @rtype: PtHopStats (list) + @return: Packet tracking Hop statistics, i.e. delay/volume + statistics between two neighbor PT probes + """ + return self.__Aggregator.getPtHopStats(startTime, stopTime, nodeList2D) + + # 3. + def getPtPathStats(self, startTime, stopTime, nodeTuple): + """ + Function to retrieve the observed traffic statistics in the time + intervall defined between StartTime and StopTime. Statistics mean + packet/byte count and min/max/avg delay between each node/node pair. + @type startTime: struct_time + @param startTime: A sequence of 9 integers, as returned from + gmtime(), localtime() or strptime(). + @type stopTime: struct_time + @param stopTime: A sequence of 9 integers, as returned from + gmtime(), localtime() or strptime(). + @type nodeTuple: tuple + @param nodeTuple: A pair of nodes represented as a 'tuple' datatype + @rtype: PtPathStats (list) + @return: Packet tracking Hop statistics, i.e. delay/volume + statistics between any two PT probes + """ + return self.__Aggregator.getPtPathStats(startTime, stopTime, nodeTuple) + + # 4. + def getPtActivity(self, startTime, stopTime, nodeList): + """ + Returns the 'activity' for each node in the list. Activity is defined + as a percentage [0-100%] of interval startTime to stopTime . If no + packet is observed in this defined time interval the function returns + zero, otherwise the function returns a positive non-zero value. It also + depends on the configured activity threshold (timeout), which is set by + the function 'setPtActivityThreshold'. + @type startTime: struct_time + @param startTime: A sequence of 9 integers, as returned from + gmtime(), localtime() or strptime(). + @type stopTime: struct_time + @param stopTime: A sequence of 9 integers, as returned from + gmtime(), localtime() or strptime(). + @type nodeList: list + @param nodeList: List of nodes, whereby a node is one installed + monitoring probe. + @rtype: PtActivity + @return: Amount of time when there was live traffic + observed at a node. + """ + return self.__Aggregator.getPtActivity(startTime, stopTime, nodeList) + + # Pt Management (Impd4e + Collector) + # 1. + def restartPtCollector(self): + """ + Method to restart the Collector. + @rtype: Status + @return: Placeholder for return error handling, i.e. + "Success" or specific Exception. + """ + return self.__Aggregator.restartPtCollector() + + # 2. + def restartPtProbes(self, nodeList): + """ + Method to restart the probes on all the selected Nodes. + @rtype: Status + @return: Placeholder for return error handling, i.e. + "Success" or specific Exception. + """ + return self.__Aggregator.restartPtProbes(nodeList) + + # 3. + def purgePtDatabase(self, startTime, stopTime): + """ + Function to purge the observed track information from the database + (Only for administrative purposes). + @type startTime: struct_time + @param startTime: A sequence of 9 integers, as returned from + gmtime(), localtime() or strptime(). + @type stopTime: struct_time + @param stopTime: A sequence of 9 integers, as returned from + gmtime(), localtime() or strptime(). + @rtype: Status + @return: Placeholder for return error handling, i.e. + "Success" or specific Exception. + """ + return self.__Aggregator.purgePtDatabase(startTime, stopTime) + + # 4. + def setPtHashRange(self, range): + """ + Sets the hash range for the hashing algorithm, value must be between 1 + and 100. The higher, the more packets are selected by the hashing + function. 100 - Means, all packets are selected. + @type range: int + @param range: A value between 1 and 100. + @rtype: Status + @return: Placeholder for return error handling, i.e. + "Success" or specific Exception. + """ + return self.__Aggregator.setPtHashRange(range) + + # 5. + def setPtHashFunction(self, hashFunction): + """ + The PT probe provides different hashing functions to do the packet + selection. Possible parameters are: "BOB", "OAAT", "TWMX", "HSIEH + @type hashFunction: str + @param hashFunction: A short string representing the hashing function. + @rtype: Status + @return: Placeholder for return error handling, i.e. + "Success" or specific Exception. + """ + return self.__Aggregator.setPtHashFunction(hashFunction) + + # 6. + def setPtActivityThreshold(self, timeMSec): + """ + Function to adjust the activity threshold. Increasing this value in + effect reduces the probability to receive a "0 - no activity" from the + function 'getPtActivity'. + @type timeMSec: int + @param timeMSec: A time value in milliseconds. + @rtype: Status + @return: Placeholder for return error handling, i.e. + "Success" or specific Exception. + """ + return self.__Aggregator.setPtActivityThreshold(timeMSec) + + # PT Visualization (Netview) + # 1. + def viewPtPathTracks(self, startTime, stopTime, nodeList): + """ + Starts a GUI application and displays the path defined by the nodeList, + in the time interval, defined by startTime and stopTime. + @type startTime: struct_time + @param startTime: A sequence of 9 integers, as returned from + gmtime(), localtime() or strptime(). + @type stopTime: struct_time + @param stopTime: A sequence of 9 integers, as returned from + gmtime(), localtime() or strptime(). + @type nodeList: list + @param nodeList: List of nodes, whereby a node is one installed + monitoring probe. + @rtype: Status + @return: Placeholder for return error handling, i.e. + "Success" or specific Exception. + """ + return self.__Aggregator.viewPtPathTracks(startTime, stopTime, nodeList) + + # 2. + def viewPtHopTracks(self, startTime, stopTime, nodeList2D): + """ + Starts a GUI application and displays the hop defined by the node + vector, in the time interval, defined by startTime and stopTime. + @type startTime: struct_time + @param startTime: A sequence of 9 integers, as returned from + gmtime(), localtime() or strptime(). + @type stopTime: struct_time + @param StopTime: A sequence of 9 integers, as returned from + gmtime(), localtime() or strptime(). + @type nodeList2D: list + @param nodeList2D: A List of node tuples (src, dst). + @rtype: Status + @return: Placeholder for return error handling, i.e. + "Success" or specific Exception. + """ + return self.__Aggregator.viewPtHopTracks(startTime, stopTime, nodeList2D) + + # 3. + def plotPtPathStats(self, startTime, stopTime, nodeList): + """ + Plots the delay stats in a X/Y-plot for a hop between two nodes given + by the nodeList, in the time interval defined by startTime and stopTime. + @type startTime: struct_time + @param startTime: A sequence of 9 integers, as returned from + gmtime(), localtime() or strptime(). + @type stopTime: struct_time + @param stopTime: A sequence of 9 integers, as returned from + gmtime(), localtime() or strptime(). + @type nodeList: list + @param nodeList: List of nodes, whereby a node is one installed + monitoring probe. + @rtype: Status + @return: Placeholder for return error handling, i.e. + "Success" or specific Exception. + """ + return self.__Aggregator.plotPtPathStats(startTime, stopTime, nodeList) + + # 4. + def plotPtHopStats(self, startTime, stopTime, nodeList2D): + """ + Plots the delay stats in a X/Y-plot for a path between multiple nodes + given by the nodeList, in the time interval defined by startTime and + stopTime. + @type startTime: struct_time + @param startTime: A sequence of 9 integers, as returned from + gmtime(), localtime() or strptime(). + @type stopTime: struct_time + @param stopTime: A sequence of 9 integers, as returned from + gmtime(), localtime() or strptime(). + @type nodeList2D: list + @param nodeList2D: A List of <first, second> Node pairs. + @rtype: Status + @return: Placeholder for return error handling, i.e. + "Success" or specific Exception. + """ + return self.__Aggregator.plotPtHopStats(startTime, stopTime, nodeList2D)
\ No newline at end of file diff --git a/Monitoring/MonitoringTool/PacketTracking/Monitoring/SliceManager/SliceManager.py b/Monitoring/MonitoringTool/PacketTracking/Monitoring/SliceManager/SliceManager.py new file mode 100644 index 0000000..190c652 --- /dev/null +++ b/Monitoring/MonitoringTool/PacketTracking/Monitoring/SliceManager/SliceManager.py @@ -0,0 +1,70 @@ +""" +Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project +Copyright according to BSD License +For full text of the license see: ./novi/Software/Monitoring/MonitoringTool/PacketTracking/license.txt + +@author <a href="mailto:ramon.masek@fokus.fraunhofer.de">Ramon Masek</a>, Fraunhofer FOKUS +@author <a href="mailto:c.henke@tu-berlin.de">Christian Henke</a>, Technical University Berlin +@author <a href="mailto:carsten.schmoll@fokus.fraunhofer.de">Carsten Schmoll</a>, Fraunhofer FOKUS +@author <a href="mailto:Julian.Vetter@campus.tu-berlin.de">Julian Vetter</a>, Fraunhofer FOKUS +@author <a href="mailto:">Jens Krenzin</a>, Fraunhofer FOKUS +@author <a href="mailto:">Michael Gehring</a>, Fraunhofer FOKUS +@author <a href="mailto:">Tacio Grespan Santos</a>, Fraunhofer FOKUS +@author <a href="mailto:">Fabian Wolff</a>, Fraunhofer FOKUS +""" + +from Task.Passive.Monitoring.Database.DBConnector import DBConnector + +class SliceManager(DBConnector): + def __init__(self, host = "127.0.0.1", port = 5432, + db = "dump", user = "user", pwd = "pwd"): + """ + Constructor of the silce manager. + @type host: String + @param host: host where the database is running on + (default: '127.0.0.1'). Give an IP address, + because the DBConnector is validating it. + @type port: int + @param port: Port number the PostgreSQL database is listening + on (default: 5432). Must be in range of 1-65535. + @type db: String + @param db: Name of the database (default: 'dump'). + @type user: String + @param user Username (default: 'user'). + @type pwd: String + @param pwd: Password for user (default: 'pwd'). + """ + DBConnector.__init__(self, host, port, db, user, pwd) + + def validateNode(self, node): + connection = self.connect() + statement = ("SELECT oid FROM slice WHERE oid = " + str(node.oid) + ";") + rows = self.executeSelect(connection, statement) + self.disconnect(connection) + return False if len(rows) == 0 else True + + def updateHashRange(self, range): + connection = self.connect() + statement = ("UPDATE slice SET hashrange = " + str(range) + ";") + self.executeUpdate(connection, statement) + self.disconnect(connection) + + def updateHashFunction(self, function): + connection = self.connect() + statement = ("UPDATE slice SET algorithm = '" + function + "';") + self.executeUpdate(connection, statement) + self.disconnect(connection) + + def selectActivityThreshold(self, nodeOid): + connection = self.connect() + statement = ("SELECT activity FROM slice WHERE oid = " + + str(nodeOid) + ";") + rows = self.executeSelect(connection, statement) + self.disconnect(connection) + return rows[0][0] + + def updateActivityThreshold(self, timeMSec): + connection = self.connect() + statement = ("UPDATE slice SET activity = " + str(timeMSec) + ";") + self.executeUpdate(connection, statement) + self.disconnect(connection)
\ No newline at end of file diff --git a/Monitoring/MonitoringTool/PacketTracking/Monitoring/SliceManager/__init__.py b/Monitoring/MonitoringTool/PacketTracking/Monitoring/SliceManager/__init__.py new file mode 100644 index 0000000..92936f3 --- /dev/null +++ b/Monitoring/MonitoringTool/PacketTracking/Monitoring/SliceManager/__init__.py @@ -0,0 +1,15 @@ +""" +Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project +Copyright according to BSD License +For full text of the license see: ./novi/Software/Monitoring/MonitoringTool/PacketTracking/license.txt + +@author <a href="mailto:ramon.masek@fokus.fraunhofer.de">Ramon Masek</a>, Fraunhofer FOKUS +@author <a href="mailto:c.henke@tu-berlin.de">Christian Henke</a>, Technical University Berlin +@author <a href="mailto:carsten.schmoll@fokus.fraunhofer.de">Carsten Schmoll</a>, Fraunhofer FOKUS +@author <a href="mailto:Julian.Vetter@campus.tu-berlin.de">Julian Vetter</a>, Fraunhofer FOKUS +@author <a href="mailto:">Jens Krenzin</a>, Fraunhofer FOKUS +@author <a href="mailto:">Michael Gehring</a>, Fraunhofer FOKUS +@author <a href="mailto:">Tacio Grespan Santos</a>, Fraunhofer FOKUS +@author <a href="mailto:">Fabian Wolff</a>, Fraunhofer FOKUS +""" + diff --git a/Monitoring/MonitoringTool/PacketTracking/Monitoring/__init__.py b/Monitoring/MonitoringTool/PacketTracking/Monitoring/__init__.py new file mode 100644 index 0000000..a9faf1b --- /dev/null +++ b/Monitoring/MonitoringTool/PacketTracking/Monitoring/__init__.py @@ -0,0 +1,20 @@ +""" +Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project +Copyright according to BSD License +For full text of the license see: ./novi/Software/Monitoring/MonitoringTool/PacketTracking/license.txt + +@author <a href="mailto:ramon.masek@fokus.fraunhofer.de">Ramon Masek</a>, Fraunhofer FOKUS +@author <a href="mailto:c.henke@tu-berlin.de">Christian Henke</a>, Technical University Berlin +@author <a href="mailto:carsten.schmoll@fokus.fraunhofer.de">Carsten Schmoll</a>, Fraunhofer FOKUS +@author <a href="mailto:Julian.Vetter@campus.tu-berlin.de">Julian Vetter</a>, Fraunhofer FOKUS +@author <a href="mailto:">Jens Krenzin</a>, Fraunhofer FOKUS +@author <a href="mailto:">Michael Gehring</a>, Fraunhofer FOKUS +@author <a href="mailto:">Tacio Grespan Santos</a>, Fraunhofer FOKUS +@author <a href="mailto:">Fabian Wolff</a>, Fraunhofer FOKUS +""" + + + +if __name__ == "__main__": + import doctest + doctest.testmod()
\ No newline at end of file diff --git a/Monitoring/MonitoringTool/PacketTracking/Monitoring/test.py b/Monitoring/MonitoringTool/PacketTracking/Monitoring/test.py new file mode 100644 index 0000000..7c5e087 --- /dev/null +++ b/Monitoring/MonitoringTool/PacketTracking/Monitoring/test.py @@ -0,0 +1,101 @@ +""" +Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project +Copyright according to BSD License +For full text of the license see: ./novi/Software/Monitoring/MonitoringTool/PacketTracking/license.txt + +@author <a href="mailto:ramon.masek@fokus.fraunhofer.de">Ramon Masek</a>, Fraunhofer FOKUS +@author <a href="mailto:c.henke@tu-berlin.de">Christian Henke</a>, Technical University Berlin +@author <a href="mailto:carsten.schmoll@fokus.fraunhofer.de">Carsten Schmoll</a>, Fraunhofer FOKUS +@author <a href="mailto:Julian.Vetter@campus.tu-berlin.de">Julian Vetter</a>, Fraunhofer FOKUS +@author <a href="mailto:">Jens Krenzin</a>, Fraunhofer FOKUS +@author <a href="mailto:">Michael Gehring</a>, Fraunhofer FOKUS +@author <a href="mailto:">Tacio Grespan Santos</a>, Fraunhofer FOKUS +@author <a href="mailto:">Fabian Wolff</a>, Fraunhofer FOKUS +""" + +import unittest + +from PassiveMonitoring import PassiveMonitoring + +class Test(unittest.TestCase): + + def setUp(self): + self.pM = PassiveMonitoring() + self.nodeList = [1,2,3,4,5,42,46] + self.hashFunctions = ["BOB", "OAAT", "TWMX", "HSIEH"] + + def testGetPtVolumeStats(self): + ret = self.pM.getPtVolumeStats("2010-10-10T10:10:10", + "2012-10-10T10:10:10", + self.nodeList) + for r in ret: + print r + + def testGetPtHopStats(self): + ret = self.pM.getPtHopStats("2010-10-10T10:10:10", + "2012-10-10T10:10:10", + [(1,2), (3,46), (5,42)]) + for r in ret: + print r + + def testGetPtPathStats(self): + ret = self.pM.getPtPathStats("2010-10-10T10:10:10", + "2012-10-10T10:10:10", + (46,42)) + for r in ret: + print r + + def testGetPtActivity(self): + ret = self.pM.getPtActivity("2010-10-10T10:10:10", + "2012-10-10T10:10:10", + self.nodeList) + for r in ret: + print r + + def testRestartPtCollector(self): + pass + + def testRestartPtProbes(self): + pass + + def testPurgePtDatabase(self): + pass + + def testSetPtHashRange(self): + ret = 0 + for i in range(1,100): + ret += self.pM.setPtHashRange(i).status + print "setPtHashRange " + str(ret) + + def testSetPtHashFunction(self): + ret = 0 + for function in self.hashFunctions: + ret += self.pM.setPtHashFunction(function).status + print "setPtHashFunction " + str(ret) + + def testSetPtActivityThreshold(self): + ret = self.pM.setPtActivityThreshold(100).status + print "setPtActivityThreshold " + str(ret) + + def testViewPtPathTracks(self): + self.pM.viewPtPathTracks("2010-10-10T10:10:10", + "2012-10-10T10:10:10", + self.nodeList) + + def testViewPtHopTracks(self): + self.pM.viewPtHopTracks("2010-10-10T10:10:10", + "2012-10-10T10:10:10", + [(1,2), (3,46), (5,42)]) + + def testPlotPtPathStats(self): + self.pM.plotPtPathStats("2010-10-10T10:10:10", + "2012-10-10T10:10:10", + self.nodeList) + + def testPlotPtHopStats(self): + self.pM.plotPtHopStats("2010-10-10T10:10:10", + "2012-10-10T10:10:10", + [(1,2), (3,46), (5,42)]) + +if __name__ == "__main__": + unittest.main()
\ No newline at end of file |