def runSimulation(theNetwork, startingPoint, virus): """ Description: This function calls runSimulation passing in the network, starting point for the virus to start, the virus, and a True/False value. The infected percentage is then calcualted by getting the infectedCount array and counting the number of infected and dividing by network size. Pre: theNetwork is a Network object predefined. startingPoint is an integer value specifying the starting point. virus is the type of virus and is either a Trojan or a Worm object. Post: returns the infectedPercent """ if virus == "W": virus = viruses.Worm() else: virus = viruses.Trojan() sim.runOnce(theNetwork, startingPoint, virus, False) infectedCount = 0 for node in theNetwork.infectedList[1:]: if node == n.State.infected: infectedCount += 1 infectedPercent = (infectedCount / networkSize) * 100 return infectedPercent
def runTrojan(theNetwork): startingPoint = N.random.randint(1, networkSize + 1) virus = viruses.Trojan() sim.runOnce(theNetwork, startingPoint, virus, False) infectedCount = 0 for node in theNetwork.infectedList[1:]: if node == n.State.infected: infectedCount += 1 infectedPercent = (infectedCount / networkSize) * 100 return infectedPercent
def runSimulation(theNetwork, startingPoint, virus): if virus == "LB": virus = viruses.LogicBomb() if virus == "W": virus = viruses.Worm((0, .1)) else: virus = viruses.Trojan() sim.runOnce(theNetwork, startingPoint, virus, False) infectedCount = 0 for node in theNetwork.infectedList[1:]: if node == n.State.infected: infectedCount += 1 infectedPercent = (infectedCount / networkSize) * 100 return infectedPercent
nodeStrengthRange = (.2, .4) theNetwork = n.Network(disp.graphType.TREE) theNetwork.createnetwork("tree.txt", nodeStrengthRange) infectedPercentMedStrengthTreeWorm.append(runSimulation( theNetwork, 1, "W")) nodeStrengthRange = (.4, .6) theNetwork = n.Network(disp.graphType.TREE) theNetwork.createnetwork("tree.txt", nodeStrengthRange) infectedPercentHighStrengthTreeWorm.append( runSimulation(theNetwork, 1, "W")) virus = viruses.Trojan() for x in range(n_runs): nodeStrengthRange = (0.4, .6) theNetwork = n.Network(disp.graphType.TREE) theNetwork.createnetwork("tree.txt", nodeStrengthRange) infectedPercentLowStrengthTreeTrojan.append( runSimulation(theNetwork, 1, "T")) nodeStrengthRange = (.2, .4) theNetwork = n.Network(disp.graphType.TREE) theNetwork.createnetwork("tree.txt", nodeStrengthRange) infectedPercentMedStrengthTreeTrojan.append( runSimulation(theNetwork, int(networkSize / 2), "T"))
""" title = "Rate of Infection by a " + virusName + " in a " + graphType + " Network" fileName = virusName + "_" + graphType + ".png" plt.figure() # plot time turns vs percentage of infected network/system plt.ylabel("Infection rate per step") plt.xlabel("Network Cycles") plt.title(title) plt.plot(range(time_turns), rates) plt.savefig(fileName) #fileMaker.main(50) Types = ["Worm", "Trojan", "Logic Bomb"] virus = [viruses.Worm(), viruses.Trojan(), viruses.LogicBomb()] #create 6 line graphs of the rate of infection over time. for x in range(3): theNetwork = n.Network(disp.graphType.LINE) theNetwork.createnetwork("line.txt") numberOfSteps, infectionRates, percentatages = sim.runOnce( theNetwork, 1, virus[x], False) drawGraph(numberOfSteps, infectionRates, Types[x], "Line") theNetwork = n.Network(disp.graphType.RING) theNetwork.createnetwork("ring.txt") numberOfSteps, infectionRates, percentatages = sim.runOnce( theNetwork, 1, virus[x], False) drawGraph(numberOfSteps, infectionRates, Types[x], "Ring")