예제 #1
0
파일: MatchRule.py 프로젝트: vasiqmz/PBDD
def is_matching(pktVal):

    global nextNode
    global matchHit
    global tmpRuleBDD
    global totalHitCount
    global rjktdPkt

    if str(pktVal) == "1":
        matchHit += 1
        log_data = "\tPacket has been accepted now ... and the hit count is "+str(matchHit) + "\n"
        writeLog(log_data)
        nextNode = "-1"
        matchHit = 0
        return True
    elif str(pktVal) != "0":
        nextNode = pktVal
        matchHit += 1
        return True
    else:
        matchHit += 1
        nodeName = db._get_var_name(tmpRuleBDD, matchHit)
        log_data = "\tPacket got rejected and the hit count is "+str(matchHit)+" and the node name is "+nodeName + "\n"
        writeLog(log_data)
        updateLastHitDb(nodeName)
        nextNode = "-1"

        totalHitCount = totalHitCount + matchHit # Updating the total hit count
        rjktdPkt = rjktdPkt + 1 # Updating the rejected packet count now

        matchHit = 0        
        return False
예제 #2
0
파일: MatchRule.py 프로젝트: vasiqmz/PBDD
def pktMatcher(pktBin, ruleBDD):

    global nextNode
    global matchHit
    global tmpRuleBDD
    tmpRuleBDD = ruleBDD

    tmp_h_table = {}

    for data in ruleBDD['h_table'].items():
        tmp_h_table[data[1]] = data[0]

    for pktData in pktBin.items():
        if str(nextNode) == "1":
            log_data = "\tPacket has been accepted now ... and the hit count is "+str(matchHit) + "\n"
            writeLog(log_data)
            matchHit = 0
            return

        elif str(nextNode) != "-1":
            if (db._get_var_name(ruleBDD, nextNode)) == pktData[0]:

                if str(pktData[1]) == "0":
                    indice = int(pktData[1])+1
                elif str(pktData[1]) == "1":
                    indice = 2

                if not is_matching(tmp_h_table[nextNode][indice]):
                    return
            else:
                nextNode = nextNode - 1
                while True:
                    if (db._get_var_name(ruleBDD, nextNode)) == pktData[0]:
                        break;
                    else:
                        nextNode = nextNode - 1

                if str(pktData[1]) == "0":
                    indice = int(pktData[1])+1
                elif str(pktData[1]) == "1":
                    indice = 2

                if not is_matching(tmp_h_table[nextNode][indice]):
                    return

        elif str(nextNode) == "-1":
            nextNode = len(tmp_h_table)+1
            if (db._get_var_name(ruleBDD, nextNode)) == pktData[0]:

                if str(pktData[1]) == "0":
                    indice = int(pktData[1])+1
                elif str(pktData[1]) == "1":
                    indice = 2

                if not is_matching(tmp_h_table[nextNode][indice]):
                    return
            else:
                nextNode = nextNode - 1
                while True:
                    if (db._get_var_name(ruleBDD, nextNode)) == pktData[0]:
                        break;
                    else:
                        nextNode = nextNode - 1
                if str(pktData[1]) == "0":
                    indice = int(pktData[1])+1
                elif str(pktData[1]) == "1":
                    indice = 2
                if not is_matching(tmp_h_table[nextNode][indice]):
                    return