Пример #1
0
def main(args):
    global pcapps
    global outputseverity
    global algorithm

    prevarg = ""
    for arg in args:

        if prevarg == "-top":
            cap = int(arg)
            pcapps = list(graph.processedApps)[0:cap]
        if prevarg == "-applist":
            pcapps = set(arg.split(","))

        if prevarg == "-severity":
            outputseverity = int(arg)

        if prevarg == "-pathalgorithm":
            algorithm = arg
        prevarg = arg

    printAllFlows=False
    printStatistics=False
    printSampleFlows=False
    printAppStatistics=False
    arguments=sys.argv
    if (len(arguments[1:]) > 0):
        if "-printAllFlows" in arguments:
            print("Printing all flows.")
            printAllFlows=True
        if "-printSampleFlows" in arguments:
            print("Printing a sample of the flows (100 flows with length > 2).")
            printSampleFlows=True
        if "-printStatistics" in arguments:
            print("Printing statistics.")
            printStatistics=True
        if "-printAppStats" in arguments:
            print("Printing app statistics.")
            printAppStatistics=True
    if not printAllFlows:
        print("Printing only one flow of max. found length. Use -printAllFlows to print all.")
    if not printStatistics:
        print("Omitting graph statistics. Use -printStatistics to print them.")
        
    print "Running querier with algorithm: %s" % algorithm

    for node in graph.sources:
        global visitedEdges
        visitedEdges = set()
        if (not node in graph.nodes): #source has children
            print ("source is not key in graph.nodes list?!: " + node)
        else:
            traverse(node, GraphFlow([(None,node)], [], graph.hashToObjectMapping))
        if (flowCount > breakOffFlowCount):
            print ("more than %i flows. breaking off!" % breakOffFlowCount)
            break
        
#-------------------------------------------------------------------------------------------
    outputDirectory = args[1]
    maxLength = int(args[2])
    allApps = computeAllApps(graph,allFlows)
    appGraph = AppGraph()
    appGraph.convertGraphIntoAppGraph(graph)
    print("lenght of Apps: " + str(len(appGraph.apps)))
    print("lenght of Edges: " + str(len(appGraph.edges)))
    
    data = computeNumberOfFlowsForEachApp(allApps, allFlows, graph)
    saveData(data, str(outputDirectory) + "/NumberOfFlowsForEachApp.txt")
    data = computeNumberOfEdgesForEachApp(allApps, graph)
    saveData(data, str(outputDirectory) + "/NumberOfEdgesForEachApp.txt")
    data = computeNumberOfFlowsPerEdge(allFlows, edgeSet)
    saveData(data, str(outputDirectory) + "/NumberOfFlowsPerEdge.txt")
    data = computeNumberOfFlowsPerIntent(allFlows, graph)
    saveData(data, str(outputDirectory) + "/NumberOfFlowsPerIntent.txt")
    data = computeNumberOfFlowsPerSource(allFlows, graph)
    saveData(data, str(outputDirectory) + "/NumberOfFlowsPerSource.txt")
    data = computeNumberOfFlowsPerSink(allFlows, graph)
    saveData(data, str(outputDirectory) + "/NumberOfFlowsPerSink.txt")
    data = computeNumberOfIncomingEdgesPerIntent(graph)
    saveData(data, str(outputDirectory) + "/NumberOfIncomingEdgesPerIntent.txt")
    data = computeNumberOfOutgoingEdgesPerIntent(graph)
    saveData(data, str(outputDirectory) + "/NumberOfOutgoingEdgesPerIntent.txt")
    data = computeLengthOfFlowsDistribution(maxLength, graph, allFlows)
    saveData(data, str(outputDirectory) + "/LengthOfFlowsDistribution.txt")
    data = computeAppDegreeInAppGraph(appGraph)
    saveData(data[0], str(outputDirectory) + "/AppDegreeInAppGraphOutgoing.txt")
    saveData(data[1], str(outputDirectory) + "/AppDegreeInAppGraphIngoing.txt")
    
    
    data = computeAppDegreeInAppGraphLenOfEdges(appGraph)
    dataOutgoing = data[0]
    dataIncoming = data[1]
    dataCombined = dict()
    for app in appGraph.apps:
        combinedDegree = dataOutgoing[app] + dataIncoming[app]
        newPair = {app:combinedDegree}
        dataCombined.update(newPair)
      
    dataSorted = sorted(dataCombined.items(), key=operator.itemgetter(1))
    file = open(str(outputDirectory) + "/AppDegree.txt", "w")
    file.write("Degree,Count \n")
    for d in dataSorted:
        file.write(str(d) + "\n")
    file.close()
    
    degree = 0
    dataDegreeCount = dict()
    # 8675 ist nur eine grosse Zahl von der ich weiss das es keine Grade dieser groesse gibt
    while degree < 8675:
        newPair = {degree:0}
        dataDegreeCount.update(newPair)
        degree += 1
    for data in dataCombined:
        dataCount = dataCombined[data]
        degreeCount = dataDegreeCount[dataCount] + 1
        newPair = {dataCount:degreeCount}
        dataDegreeCount.update(newPair)
    # Datei zur Berechnung der Scalefreeness
    file = open(str(outputDirectory) + "/DegreeCount.csv", "w")
    file.write("Degree,Count \n")
    for d in dataDegreeCount:
        file.write(str(d) + "," + str(dataDegreeCount[d]) + "\n")
    file.close()
Пример #2
0
def main(args):
    global pcapps
    global outputseverity
    global algorithm

    prevarg = ""
    for arg in args:

        if prevarg == "-top":
            cap = int(arg)
            pcapps = list(graph.processedApps)[0:cap]
        if prevarg == "-applist":
            pcapps = set(arg.split(","))

        if prevarg == "-severity":
            outputseverity = int(arg)

        if prevarg == "-pathalgorithm":
            algorithm = arg
        prevarg = arg

    printAllFlows=False
    printStatistics=False
    printSampleFlows=False
    printAppStatistics=False
    arguments=sys.argv
    if (len(arguments[1:]) > 0):
        if "-printAllFlows" in arguments:
            print("Printing all flows.")
            printAllFlows=True
        if "-printSampleFlows" in arguments:
            print("Printing a sample of the flows (100 flows with length > 2).")
            printSampleFlows=True
        if "-printStatistics" in arguments:
            print("Printing statistics.")
            printStatistics=True
        if "-printAppStats" in arguments:
            print("Printing app statistics.")
            printAppStatistics=True
    if not printAllFlows:
        print("Printing only one flow of max. found length. Use -printAllFlows to print all.")
    if not printStatistics:
        print("Omitting graph statistics. Use -printStatistics to print them.")
        
    print "Running querier with algorithm: %s" % algorithm

    for node in graph.sources:
        global visitedEdges
        visitedEdges = set()
        if (not node in graph.nodes): #source has children
            print ("source is not key in graph.nodes list?!: " + node)
        else:
            traverse(node, GraphFlow([(None,node)], [], graph.hashToObjectMapping))
        if (flowCount > breakOffFlowCount):
            print ("more than %i flows. breaking off!" % breakOffFlowCount)
            break
            
#-----------------------------------from here on my code--------------------------------------------------------

    appGraph = AppGraph()
    appGraph.convertGraphIntoAppGraph(graph)
    appGraph.drawGraph()
    print("lenght of Apps: " + str(len(appGraph.apps)))
    print("lenght of Edges: " + str(len(appGraph.edges)))
    counter = 0
    print "#######"

    degreeDictionarys = computeAppDegreeInAppGraph(appGraph)
    output = open('degreeOfAppGraphNumberOfEdges.pkl', 'w')
    pickle.dump(degreeDictionarys, output)
    output.close()
    degDict = computeAppDegreeInAppGraphLenOfEdges(appGraph)
    output = open('degreeOfAppGraphLengthOfEdges.pkl', 'w')
    pickle.dump(degDict, output)
    output.close()
    
    input = open('degreeOfAppGraphLengthOfEdges.pkl')
    data = pickle.load(input)
    input.close()
    dataOutgoing = data[0]
    dataIncoming = data[1]
    dataCombined = dict()
    for app in appGraph.apps:
        combinedDegree = dataOutgoing[app] + dataIncoming[app]
        newPair = {app:combinedDegree}
        dataCombined.update(newPair)
        
    dataSorted = sorted(dataCombined.items(), key=operator.itemgetter(1))
    file = open("AppDegree.txt", "a")
    for d in dataSorted:
        file.write(str(d) + "\n")
    file.close()
    maxDegree = dataSorted[-1][1]
    
    degree = 0
    dataDegreeCount = dict()
    while degree < maxDegree + 1:
        newPair = {degree:0}
        dataDegreeCount.update(newPair)
        degree += 1
    for data in dataCombined:
        dataCount = dataCombined[data]
        degreeCount = dataDegreeCount[dataCount] + 1
        newPair = {dataCount:degreeCount}
        dataDegreeCount.update(newPair)
    file = open("DegreeCount.csv", "a")
    file.write("Degree,Count \n")
    for d in dataDegreeCount:
        file.write(str(d) + "," + str(dataDegreeCount[d]) + "\n")
    file.close()