Esempio n. 1
0
def BloomFilter():
    global bit_map
    flowMap = filereader(2)
    plot_points = dict()

    for src in flowMap.keys():

        for desti in flowMap[src]:

            for i in range(0, nHashes):
                index = customHash(src + desti + str(i)) % BIT_MAP_WIDTH
                bitmap[index] = 1

    falsePositive = 0
    trueNegative = 0

    for i in range(0, 10000):
        randIP = str(random.randint(0, 256)) + "." + str(random.randint(
            0, 256)) + "." + (str(random.randint(0, 256)) + "." +
                              str(random.randint(0, 256)))
        mem = 1

        for j in range(0, nHashes):
            val = customHash(randIP + str(j))
            mem &= bitmap[val % BIT_MAP_WIDTH]

        if mem == 0:
            trueNegative += 1
        else:
            falsePositive += 1

    print trueNegative, falsePositive, (Decimal(falsePositive) /
                                        Decimal(falsePositive + trueNegative))
Esempio n. 2
0
def vFM():
	global physical
	flowMap = filereader(2)
	plot_points = dict()

	for src in flowMap.keys():
		destiList = flowMap[src]
		actual = len(destiList)
		c = 0
		while c < actual:
			destin = destiList[c]
			index = int((customHash(destin) & 0x7fffffff) % len(virtual))

			sIP = src.replace(".", "")
			XORed = long(sIP) ^ virtual[index]

			physicalIndex = int(customHash(str(XORed)) & 0x7fffffff) % PHYSICAL_BIT_MAP_SIZE
			physical[physicalIndex] |= 1 << gHash(destin)

			z = countZeros() % PHYSICAL_BIT_MAP_SIZE
			estimated = int(PHYSICAL_BIT_MAP_SIZE * math.pow(2, z) % phi)

			plot_points[actual] = estimated
			c += 1

	fig = plt.figure()
	gx = plot_points.keys()
	gy = plot_points.values()
	plt.scatter(gx, gy, linewidths="1")
	# plt.plot(scatter_points.keys(), scatter_points.values(), marker="o", linewidth=".5")
	plt.title("Virtual FM")
	plt.xlabel("Actual")
	plt.ylabel("Estimate")
	fig.savefig('VirtualFM.png', dpi=fig.dpi, bbox_inches='tight')
	plt.show()
Esempio n. 3
0
def physicalBitMap():
    global VIRTUAL_BIT_MAP_SIZE
    global PHYSICAL_BIT_MAP_SIZE
    global physical
    global virtual
    global flowMap

    flowMap = filereader(2)

    sortedFlowKeys = sorted(flowMap.keys())
    for sourceIP in sortedFlowKeys:
        destinationList = flowMap[sourceIP]
        count = 0
        while count < len(destinationList):
            destination = destinationList[count]
            ind = int(
                (customHash(destination) & 0x7fffffff) % VIRTUAL_BIT_MAP_SIZE)

            src = sourceIP.replace(".", "")
            xored = long(src) ^ virtual[ind]

            physicalInd = int(
                (customHash(str(xored)) & 0x7fffffff) % PHYSICAL_BIT_MAP_SIZE)
            physical[physicalInd] = 1
            count += 1
Esempio n. 4
0
def ProbabCount():
    global bit_map
    flowMap = filereader(1)
    scatter_points = dict()

    with open('pcOut.txt', 'w') as outFile:
        for flow in flowMap.keys():
            tempFlow = flowMap[flow]
            actualCardinality = len(tempFlow)

            for destn in tempFlow:
                bitMap_ind = (findHashcode(flow + destn)
                              & 0x7fffffff) % BIT_MAP_SIZE
                bit_map[bitMap_ind] = 1

            num_zeros = Decimal(countZerosInBitMap())
            Vn = num_zeros / Decimal(BIT_MAP_SIZE)

            estimatedCardinality = int((-1 * BIT_MAP_SIZE * math.log(Vn)))

            scatter_points[actualCardinality] = estimatedCardinality
            bit_map = [0] * BIT_MAP_SIZE

            outFile.write(
                str(flow) + "\t\t" + str(actualCardinality) + "\t\t" +
                str(estimatedCardinality) + "\n")
    outFile.close()

    fig = plt.figure()
    gx = scatter_points.keys()
    gy = scatter_points.values()
    plt.scatter(gx, gy, linewidths="1")
    # plt.plot(scatter_points.keys(), scatter_points.values(), marker="o", linewidth=".5")
    plt.title("Probablistic Counting")
    plt.xlabel("Actual")
    plt.ylabel("Estimate")
    fig.savefig('Probablistic.png', dpi=fig.dpi, bbox_inches='tight')
    plt.show()
Esempio n. 5
0
def cMin():
    global bit_map
    flowMap = filereader(3)
    plot_points = dict()

    for sourceDestination in flowMap.keys():
        for j in range(0, BIT_MAP_DEPTH):
            index = customHash(sourceDestination + str(j)) % BIT_MAP_WIDTH
            bitMap[j][index] += flowMap[sourceDestination]

    with open('cminOut.txt', 'w') as outFile:
        for sourceDestination in flowMap.keys():
            minVal = sys.maxint

            for k in range(0, BIT_MAP_DEPTH):
                index = customHash(sourceDestination + str(k)) % BIT_MAP_WIDTH
                minVal = min(minVal, bitMap[k][index])

            actual = flowMap[sourceDestination]
            estimated = minVal
            outFile.write(
                str(sourceDestination) + "\t\t" + str(actual) + "\t\t" +
                str(estimated) + "\n")
            plot_points[actual] = estimated

    outFile.close()

    fig = plt.figure()
    gx = plot_points.keys()
    gy = plot_points.values()
    plt.scatter(gx, gy, linewidths="1")
    # plt.plot(scatter_points.keys(), scatter_points.values(), marker="o", linewidth=".5")
    plt.title("Count Min")
    plt.xlabel("Estimate")
    plt.ylabel("Actual")
    fig.savefig('CountMin.png', dpi=fig.dpi, bbox_inches='tight')
Esempio n. 6
0
def DoubleHashM():
    flowMap = filereader(1)
    plot_points = dict()

    with open('dhmOut.txt', 'w') as outFile:
        for flow in flowMap.keys():
            estimated = len(flowMap[flow])
            actual = estimated
            plot_points[actual] = estimated
            outFile.write(
                str(flow) + "\t\t" + str(actual) + "\t\t" + str(estimated) +
                "\n")
    outFile.close()

    fig = plt.figure()
    plt.title("Double Hash Map")
    plt.xlabel("Estimate")
    plt.ylabel("Actual")
    plt.plot(plot_points.keys(),
             plot_points.values(),
             marker="o",
             linewidth=".5")
    fig.savefig('DoubleHashMap.png', dpi=fig.dpi, bbox_inches='tight')
    plt.show()