示例#1
0
if __name__=='__main__':
	routers = loadRouters() # load from the file
	stats = NetStatistics(methods=('stdev','median','made'), advanced=1) # init Statistics with multiple outlier detection methods
	nrouters = len(routers)
	pool = Pool(processes = nrouters)
	for i in range(num_samples):
		nexttime = time.time()+pollinterval
		sample = pool.map(poll, range(nrouters)) # running polling in multiple threads
		try:
			stats.addSample(sample) # put the polling results into the Network Statistics object
		except Exception:
			printerrmsg("Router(s) didn't respond")
			continue
		netstate, stdevthreshold, alarm = stats.getNetState() # get the current network state from the Statistics object
		packetsize, medianthreshold, madethreshold = stats.getAdvParams() # get the additional network state parameters
		if stats.netstate != "start":
			if stdevthreshold:
				msg = "%7d\t\t%4d\t\t| %7d  %7d  %7d |  %s" % (netstate, packetsize, stdevthreshold, medianthreshold, madethreshold, alarm)
				if alarm=='ALARM':
					msg+="\t%3d\t%s" % stats.getAlarmParams() # if there is an alarm -> get the probability and the attack type
				printmsg(msg)
			else:
				printerrmsg("%7d\t\t%4d\t\t|" % (netstate, packetsize))
		else:
			printerrmsg("start polling\n-----------------------------\ntime\t\tnetwork load, packetsize\t|\tthresholds")
		try:
			time.sleep(nexttime-time.time())
		except Exception:
			pass
示例#2
0
	try:
		return routers[routerid].pollLinksLoad()
	except Exception:
		return None

if __name__=='__main__':
	routers = loadRouters() # load from the file
	stats = NetStatistics()
	nrouters = len(routers)
	pool = Pool(processes = nrouters)
	for i in range(num_samples):
		nexttime = time.time()+pollinterval
		sample = pool.map(poll, range(nrouters)) # running polling in multiple threads
		try:
			stats.addSample(sample) # putting the polling results to the Network Statistics object
		except Exception:
			printerrmsg("Router(s) didn't respond")
			continue
		netstate, threshold, alarm = stats.getNetState() # get the current network state from the Statistics object
		if stats.netstate != "start":
			if threshold:
				printmsg("%7d\t\t|  %7d  |  %s" % (netstate, threshold, alarm))
			else:
				printerrmsg("%7d\t\t|" % netstate)
		else:
			printerrmsg("start polling\n-----------------------------\ntime\t\tnetwork load\t| threshold")
		try:
			time.sleep(nexttime-time.time())
		except Exception:
			pass