Beispiel #1
0
def printTargetInstallPairs(targetList, installList, transitList):
    Globals.TARGETLOG.write('Installed:\n')
    for i, target in enumerate(targetList):
        childRules = IPRules.findChildRules(installList, target['ip'],
                                            target['wild'])
        if childRules != []:
            Globals.TARGETLOG.write(
                str(target['ip']) + "/" + str(target['wild']) + " -> " +
                str(target['replica']) + ":" + str(target['traffic']) + '\n')
            for j, rule in enumerate(childRules):
                Globals.TARGETLOG.write('\t' + str(rule['ip']) + "/" +
                                        str(rule['wild']) + " -> " +
                                        str(rule['replica']) + ":" +
                                        str(rule['traffic']) + '\n')

    Globals.TARGETLOG.write('Transition:\n')
    for i, target in enumerate(targetList):
        childRules = IPRules.findChildRules(transitList, target['ip'],
                                            target['wild'])
        if childRules != []:
            Globals.TARGETLOG.write(
                str(target['ip']) + "/" + str(target['wild']) + " -> " +
                str(target['replica']) + ":" + str(target['traffic']) + '\n')
            for j, rule in enumerate(childRules):
                Globals.TARGETLOG.write('\t' + str(rule['ip']) + "/" +
                                        str(rule['wild']) + " -> " +
                                        str(rule['replica']) + ":" +
                                        str(rule['traffic']) + '\n')
Beispiel #2
0
def handleTimeoutRule(timeoutRule):
    printTimeoutRule(timeoutRule)

    for i, targetRule in enumerate(Globals.TARGETRULES):
        childRules = IPRules.findChildRules(Globals.TRANSITRULES, targetRule['ip'], targetRule['wild'])
        allDone = True
        for j, childRule in enumerate(childRules):
            if childRule['ip'] == timeoutRule['ip'] and childRule['wild'] == timeoutRule['wild']:
                Globals.TRANSITRULES.remove(timeoutRule)
                timeoutRule['replica'] = targetRule['replica']
		Globals.TRANSITRULES.append(timeoutRule)
            elif childRule['replica'] != targetRule['replica']:
                allDone = False
        
        if allDone and childRules != []:
            Globals.ASSIGNLOG.write("Moving to Installed: " + str(targetRule['ip']) + "/" + str(targetRule['wild']) + ":" + str(targetRule['replica']) + "\n")
            childRules = IPRules.findChildRules(Globals.TRANSITRULES, targetRule['ip'], targetRule['wild'])
            for j, childRule in enumerate(childRules):
                Globals.TRANSITRULES.remove(childRule)
                actionDeleteRule(childRule)
            newChildren = IPRules.genChildrenRules(targetRule)
            newChildren[0]['replica'] = targetRule['replica']
            newChildren[1]['replica'] = targetRule['replica']
	    newChildren[0]['traffic'] = long(targetRule['traffic'] / 2)
	    newChildren[1]['traffic'] = long(targetRule['traffic'] / 2)
            Globals.INSTALLEDRULES.append(newChildren[0])
            Globals.INSTALLEDRULES.append(newChildren[1])
            actionInstallRule(newChildren[0])
            actionInstallRule(newChildren[1])
Beispiel #3
0
def determineTargets(targetList, alphas, deeperList):
    totalTraffic = long(sumTraffic(targetList) / numNonZero(targetList))
    newTargetList = []
    oldTargetList = []

    Globals.ASSIGNLOG.write('Threshold: ' + str(totalTraffic * Globals.MINTGTTHRESH) + " < x < " + str(totalTraffic * Globals.MAXTGTTHRESH) + '\n')
    for i in range(0, len(targetList)):
        if targetList[i]['traffic'] > (totalTraffic * Globals.MAXTGTTHRESH) or Alphas.sumAllAlphaAssign(alphas) < Alphas.sumAllAlphaTarget(alphas):
	    Globals.ASSIGNLOG.write('\t' + str(targetList[i]['ip']) + " Beyond Threshold " + str(targetList[i]['traffic']) + '\n')
	    # Beyond Threshold: Need more rules
            childList = IPRules.findChildRules(deeperList, targetList[i]['ip'], targetList[i]['wild'])
            for j, child in enumerate(childList):
                newTargetList.append(child)
            if childList != []:
	        oldTargetList.append(targetList[i])
	elif targetList[i]['traffic'] < (totalTraffic * Globals.MINTGTTHRESH):
	    Globals.ASSIGNLOG.write('\t' + str(targetList[i]['ip']) + " Under Threshold " + str(targetList[i]['traffic']) + '\n')
	    # Below Theshold: Reduce rules
	    (siblingIP, siblingWild) = IPRules.findSiblingRule(targetList[i])
	    siblingRule = IPRules.findMatch(targetList, siblingIP, siblingWild)
	    if siblingRule != []:
	        if siblingRule[0]['traffic'] <= (totalTraffic * Globals.MINTGTTHRESH) and \
                   targetList.index(siblingRule[0]) < i:
		    parentRule = IPRules.getParentRule(siblingRule[0])
		    Globals.ASSIGNLOG.write('\t' + str(parentRule['ip']) + '/' + str(parentRule['wild']) + ' combined\n')
	            newTargetList.append(parentRule)
		    oldTargetList.append(targetList[i])
		    oldTargetList.append(siblingRule[0])
	else:
	    Globals.ASSIGNLOG.write('\t' + str(targetList[i]['ip']) + " Fine Threshold " + str(targetList[i]['traffic']) + '\n')
	    if targetList[i]['replica'] == -1:
	        newTargetList.append(targetList[i])
		oldTargetList.append(targetList[i])

    return (oldTargetList, newTargetList)
Beispiel #4
0
def printTargetInstallPairs(targetList, installList, transitList):
    Globals.TARGETLOG.write('Installed:\n')
    for i, target in enumerate(targetList):
        childRules = IPRules.findChildRules(installList, target['ip'], target['wild'])
	if childRules != []:
	    Globals.TARGETLOG.write(str(target['ip']) + "/" + str(target['wild']) + " -> " + str(target['replica']) + ":" + str(target['traffic']) + '\n')
	    for j, rule in enumerate(childRules):
	        Globals.TARGETLOG.write('\t' + str(rule['ip']) + "/" + str(rule['wild']) + " -> " + str(rule['replica']) + ":" + str(rule['traffic']) + '\n')

    Globals.TARGETLOG.write('Transition:\n')
    for i, target in enumerate(targetList):
        childRules = IPRules.findChildRules(transitList, target['ip'], target['wild'])
	if childRules != []:
            Globals.TARGETLOG.write(str(target['ip']) + "/" + str(target['wild']) + " -> " + str(target['replica']) + ":" + str(target['traffic']) + '\n')
            for j, rule in enumerate(childRules):
                Globals.TARGETLOG.write('\t' + str(rule['ip']) + "/" + str(rule['wild']) + " -> " + str(rule['replica']) + ":" + str(rule['traffic']) + '\n')
Beispiel #5
0
def handleTimeoutRule(timeoutRule):
    printTimeoutRule(timeoutRule)

    for i, targetRule in enumerate(Globals.TARGETRULES):
        childRules = IPRules.findChildRules(Globals.TRANSITRULES,
                                            targetRule['ip'],
                                            targetRule['wild'])
        allDone = True
        for j, childRule in enumerate(childRules):
            if childRule['ip'] == timeoutRule['ip'] and childRule[
                    'wild'] == timeoutRule['wild']:
                Globals.TRANSITRULES.remove(timeoutRule)
                timeoutRule['replica'] = targetRule['replica']
                Globals.TRANSITRULES.append(timeoutRule)
            elif childRule['replica'] != targetRule['replica']:
                allDone = False

        if allDone and childRules != []:
            Globals.ASSIGNLOG.write("Moving to Installed: " +
                                    str(targetRule['ip']) + "/" +
                                    str(targetRule['wild']) + ":" +
                                    str(targetRule['replica']) + "\n")
            childRules = IPRules.findChildRules(Globals.TRANSITRULES,
                                                targetRule['ip'],
                                                targetRule['wild'])
            for j, childRule in enumerate(childRules):
                Globals.TRANSITRULES.remove(childRule)
                actionDeleteRule(childRule)
            newChildren = IPRules.genChildrenRules(targetRule)
            newChildren[0]['replica'] = targetRule['replica']
            newChildren[1]['replica'] = targetRule['replica']
            newChildren[0]['traffic'] = long(targetRule['traffic'] / 2)
            newChildren[1]['traffic'] = long(targetRule['traffic'] / 2)
            Globals.INSTALLEDRULES.append(newChildren[0])
            Globals.INSTALLEDRULES.append(newChildren[1])
            actionInstallRule(newChildren[0])
            actionInstallRule(newChildren[1])
Beispiel #6
0
def handleRules(rulesList):

    for i, rule in enumerate(rulesList):

        newRules = rule['NewRules']
        oldRules = rule['OldRules']

        # 1:1 means simply replacement! Never should be N:N
        if len(newRules) == len(oldRules):
            oldRule = oldRules[0]
            newRule = newRules[0]
            oldIP = oldRule['ip']
            oldWild = oldRule['wild']
            oldTraffic = oldRule['traffic']
            newIP = newRule['ip']
            newWild = newRule['wild']
            newReplica = newRule['replica']

            Globals.TARGETRULES.remove(oldRule)
            oldInstalledChildren = IPRules.findChildRules(
                Globals.INSTALLEDRULES, oldIP, oldWild)
            for i, oldChildRule in enumerate(oldInstalledChildren):
                newChildRule = copyRule(oldChildRule)
                newChildRule['replica'] = newReplica
                actionReplaceRule([oldChildRule], [newChildRule])
            newRule['traffic'] = oldTraffic
            Globals.TARGETRULES.append(newRule)

        # 1:2 install more specific targets
        elif len(newRules) > len(oldRules):
            oldRule = oldRules[0]
            newRule1 = newRules[0]
            newRule2 = newRules[1]
            oldIP = oldRule['ip']
            oldWild = oldRule['wild']
            oldReplica = oldRule['replica']
            oldTraffic = oldRule['traffic']
            newIP1 = newRule1['ip']
            newWild1 = newRule1['wild']
            newReplica1 = newRule1['replica']
            newTraffic1 = long(oldTraffic / 2)
            newIP2 = newRule2['ip']
            newWild2 = newRule2['wild']
            newReplica2 = newRule2['replica']
            newTraffic2 = long(oldTraffic / 2)

            Globals.TARGETRULES.remove(oldRule)
            oldInstalledChildren = IPRules.findChildRules(
                Globals.INSTALLEDRULES, oldIP, oldWild)
            for i, rule in enumerate(oldInstalledChildren):
                newChildren = IPRules.genChildrenRules(rule)
                if IPRules.findMatch([IPRules.getParentRule(newChildren[0])],
                                     newIP1, newWild1) != []:
                    newChildren[0]['replica'] = newReplica1
                    newChildren[1]['replica'] = newReplica1
                else:
                    newChildren[0]['replica'] = newReplica2
                    newChildren[1]['replica'] = newReplica2
                newChildren[0]['traffic'] = long(rule['traffic'] / 2)
                newChildren[1]['traffic'] = long(rule['traffic'] / 2)
                rule['replica'] = oldReplica

                actionReplaceRule([rule], newChildren)
            Globals.TARGETRULES.append(newRule1)
            Globals.TARGETRULES.append(newRule2)

# 2:1 install more general targets
        else:
            newRule = newRules[0]
            newIP = newRule['ip']
            newWild = newRule['wild']
            newReplica = newRule['replica']
            oldRule1 = oldRules[0]
            oldRule2 = oldRules[1]
            oldIP1 = oldRule1['ip']
            oldWild1 = oldRule1['wild']
            oldTraffic1 = oldRule1['traffic']
            oldIP2 = oldRule2['ip']
            oldWild2 = oldRule2['wild']
            oldTraffic2 = oldRule2['traffic']

            Globals.TARGETRULES.remove(oldRule1)
            Globals.TARGETRULES.remove(oldRule2)
            oldInstalledChildren1 = IPRules.findChildRules(
                Globals.INSTALLEDRULES, oldIP1, oldWild1)
            oldTransitionChildren1 = IPRules.findChildRules(
                Globals.TRANSITRULES, oldIP1, oldWild1)
            oldInstalledChildren1.extend(oldTransitionChildren1)
            oldRule1['replica'] = newReplica
            actionReplaceRule(oldInstalledChildren1, [oldRule1])
            oldInstalledChildren2 = IPRules.findChildRules(
                Globals.INSTALLEDRULES, oldIP2, oldWild2)
            oldTransitionChildren2 = IPRules.findChildRules(
                Globals.TRANSITRULES, oldIP2, oldWild2)
            oldInstalledChildren2.extend(oldTransitionChildren2)
            oldRule2['replica'] = newReplica
            actionReplaceRule(oldInstalledChildren2, [oldRule2])
            newRule['traffic'] = long(oldTraffic1 + oldTraffic2)
            Globals.TARGETRULES.append(newRule)
Beispiel #7
0
def handleRules(rulesList):

    for i, rule in enumerate(rulesList):

    	newRules = rule['NewRules']
    	oldRules = rule['OldRules']
    	
    	# 1:1 means simply replacement! Never should be N:N
    	if len(newRules) == len(oldRules):
    	    oldRule = oldRules[0]
    	    newRule = newRules[0]
    	    oldIP = oldRule['ip']
    	    oldWild = oldRule['wild']
	    oldTraffic = oldRule['traffic']
    	    newIP = newRule['ip']
    	    newWild = newRule['wild']
    	    newReplica = newRule['replica']
    	    
    	    Globals.TARGETRULES.remove(oldRule)
    	    oldInstalledChildren = IPRules.findChildRules(Globals.INSTALLEDRULES, oldIP, oldWild)
    	    for i, oldChildRule in enumerate(oldInstalledChildren):
		newChildRule = copyRule(oldChildRule)
		newChildRule['replica'] = newReplica
    	        actionReplaceRule([oldChildRule], [newChildRule])
	    newRule['traffic'] = oldTraffic
    	    Globals.TARGETRULES.append(newRule)
    	    
    	# 1:2 install more specific targets
    	elif len(newRules) > len(oldRules):
    	    oldRule = oldRules[0]
    	    newRule1 = newRules[0]
    	    newRule2 = newRules[1]
    	    oldIP = oldRule['ip']
    	    oldWild = oldRule['wild']
            oldReplica = oldRule['replica']
            oldTraffic = oldRule['traffic']
    	    newIP1 = newRule1['ip']
    	    newWild1 = newRule1['wild']
    	    newReplica1 = newRule1['replica']
	    newTraffic1 = long(oldTraffic / 2)
    	    newIP2 = newRule2['ip']
    	    newWild2 = newRule2['wild']
    	    newReplica2 = newRule2['replica']
	    newTraffic2 = long(oldTraffic / 2)
    	   
    	    Globals.TARGETRULES.remove(oldRule)
    	    oldInstalledChildren = IPRules.findChildRules(Globals.INSTALLEDRULES, oldIP, oldWild)
    	    for i, rule in enumerate(oldInstalledChildren):
    	        newChildren = IPRules.genChildrenRules(rule)
	        if IPRules.findMatch([IPRules.getParentRule(newChildren[0])], newIP1, newWild1) != []:
                    newChildren[0]['replica'] = newReplica1
                    newChildren[1]['replica'] = newReplica1
		else:	
    	            newChildren[0]['replica'] = newReplica2
    	            newChildren[1]['replica'] = newReplica2
		newChildren[0]['traffic'] = long(rule['traffic'] / 2)
		newChildren[1]['traffic'] = long(rule['traffic'] / 2)
                rule['replica'] = oldReplica

    	        actionReplaceRule([rule], newChildren)
    	    Globals.TARGETRULES.append(newRule1)
    	    Globals.TARGETRULES.append(newRule2)

	# 2:1 install more general targets
        else:
            newRule = newRules[0]
            newIP = newRule['ip']
            newWild = newRule['wild']
            newReplica = newRule['replica']
            oldRule1 = oldRules[0]
            oldRule2 = oldRules[1]
            oldIP1 = oldRule1['ip']
            oldWild1 = oldRule1['wild']
	    oldTraffic1 = oldRule1['traffic']
            oldIP2 = oldRule2['ip']
            oldWild2 = oldRule2['wild']
	    oldTraffic2 = oldRule2['traffic']
            
            Globals.TARGETRULES.remove(oldRule1)
            Globals.TARGETRULES.remove(oldRule2)
            oldInstalledChildren1 = IPRules.findChildRules(Globals.INSTALLEDRULES, oldIP1, oldWild1)
	    oldTransitionChildren1 = IPRules.findChildRules(Globals.TRANSITRULES, oldIP1, oldWild1)
	    oldInstalledChildren1.extend(oldTransitionChildren1)
            oldRule1['replica'] = newReplica
            actionReplaceRule(oldInstalledChildren1, [oldRule1])
            oldInstalledChildren2 = IPRules.findChildRules(Globals.INSTALLEDRULES, oldIP2, oldWild2)
	    oldTransitionChildren2 = IPRules.findChildRules(Globals.TRANSITRULES, oldIP2, oldWild2)
	    oldInstalledChildren2.extend(oldTransitionChildren2)
            oldRule2['replica'] = newReplica
            actionReplaceRule(oldInstalledChildren2, [oldRule2])
	    newRule['traffic'] = long(oldTraffic1 + oldTraffic2)
            Globals.TARGETRULES.append(newRule)