Пример #1
0
def populateDB_ftr(c,num,status,vpPoisoned):

	pfx = '184.164.' + str(num) + '.0/24'

	print "---------------------------------"
	print "populateDB_ftr"
	print "time: " + str(int(time.time()))
	print "prefix: " + str(pfx)
	
	tstamp = int(time.time())

	mux = MUX_NAMES[PREFIX_RANGE.index(num)]
	
	for feed in feeds:	
		locs = pfxToLoc[feed][pfx]
		for rv in reversed(list(locs)):
			update = api.get_path(feed, pfx, rv, 'last_update')
			if feed=='rv':
				continue
			
			elif feed=='ftr':
				if update.time < tstamp-(15*60):
					continue
			elif feed=='rtr':
				if update.time < tstamp-(30*60):
					continue
				
			unix_time = update.time

			if (not update.path) is False:
				path = ""
				for asn in update.path:
					path += (str(asn) + " ")
				path = path.split()
				tup = getFilteredPath(path,feed)
				if tup is None:
					update.path = []
				else:
					filpath = tup[0]

		    
			if not update.path:
				update.path = [0]
			if not update.hops:
				update.hops = [0]
            
			path_str = ""
			for n in update.path:
				path_str += (str(n) + " ")
			hops_str = ""
			for n in update.hops:
				hops_str += (str(n) + " ")


			c.execute('insert into TRGraph values (?,?,?,?,?,?,?)', \
				   (pfx, unix_time, last_poison_time, feed, path_str, hops_str, str(rv)))

	sys.stdout.flush()
Пример #2
0
def updateState(num,poison_round,update,feed,pfx,filpath,mux,rv,status):

	path = ""
	for asn in update.path:
		path += (str(asn) + " ")
		path = path.split()
	tup = getFilteredPath(path,feed)
	if tup is None:
		update.path = []
	else:
		filpath = tup[0]
		mux = tup[1]

		if num==240: #CLEMSON
			vPoint = VP_Poison1(pfx,filpath,feed,mux,str(rv),5)
		else:
			vPoint = VP_Poison1(pfx,filpath,feed,mux,str(rv),4)
		if status==SENTINEL:
			if poison_round==0:
				pfx2VP[num].append(vPoint)
				pfx2VPBeingPoisoned[num] = pfx2VP[num][0]
			else:
				if str(rv) != pfx2VPBeingPoisoned[num].rv: 
					pfx2VP[num].append(vPoint)
				else:
					pfx2VP[num].append(pfx2VPBeingPoisoned[num])
		else:
			if str(rv)==vpPoisoned:
				pfx2VPBeingPoisoned[num].prev_path = pfx2VPBeingPoisoned[num].cur_path
				pfx2VPBeingPoisoned[num].cur_path = filpath

				if pfx2VPBeingPoisoned[num].cur_path==pfx2VPBeingPoisoned[num].prev_path:
					pfx2VPBeingPoisoned[num].PoisonNoEffect = True
				else:
								#potentially some new ASes in the new path
					pfx2VPBeingPoisoned[num].addStuff2PoisonQueue()
Пример #3
0
def populateDB(c, num, poison_round, status, vpPoisoned):

    pfx = "184.164." + str(num) + ".0/24"
    print "---------------------------------"
    print "populateDB"
    print "prefix: " + str(pfx)
    print "poison_round: " + str(poison_round)
    print "status: " + str(status)
    if status == TEST:
        print "vpPoisoned: " + vpPoisoned
    VPseen = num2VPseen[num]
    curVP = dict()
    tstamp = int(time.time())

    vpPois_seen = False

    if status == SENTINEL:
        pfx2VP[num] = []

    mux = MUX_NAMES[PREFIX_RANGE.index(num)]

    for feed in feeds:
        locs = pfxToLoc[feed][pfx]
        for rv in locs:
            update = api.get_path(feed, pfx, rv, "last_update")
            if feed == "rv":
                if update.time < START_TIME:
                    continue
                vp = str(rv).split(",")
                if len(vp) < 2:
                    continue
            elif feed == "ftr" or feed == "rtr":
                if update.time < tstamp - (30 * 60):
                    continue
                if rv in VPseen:
                    prev_upd = VPseen[rv]
                    if update.time <= prev_upd.time:
                        continue

            if str(rv) == vpPoisoned:
                vpPois_seen = True

            curVP[rv] = update
            unix_time = update.time

            if (not update.path) is False:
                path = ""
                for asn in update.path:
                    path += str(asn) + " "
                path = path.split()
                tup = getFilteredPath(path, feed)
                # or update.path[0] != tup[0][0]
                if tup is None:
                    update.path = []
                else:
                    filpath = tup[0]
                    mux = tup[1]

                    if num == 240:  # CLEMSON
                        vPoint = VP_Poison(pfx, filpath, feed, mux, str(rv), 5)
                    else:
                        vPoint = VP_Poison(pfx, filpath, feed, mux, str(rv), 0)
                    if status == SENTINEL:
                        if poison_round == 0:
                            pfx2VP[num].append(vPoint)
                            # pfx2VPOrder[num].append(vPoint)
                            pfx2VPBeingPoisoned[num] = pfx2VP[num][0]
                        else:
                            if str(rv) != pfx2VPBeingPoisoned[num].rv:
                                pfx2VP[num].append(vPoint)
                            else:
                                pfx2VP[num].append(pfx2VPBeingPoisoned[num])
                    else:
                        if str(rv) == vpPoisoned:
                            pfx2VPBeingPoisoned[num].prev_path = pfx2VPBeingPoisoned[num].cur_path
                            pfx2VPBeingPoisoned[num].cur_path = filpath

                            if pfx2VPBeingPoisoned[num].cur_path == pfx2VPBeingPoisoned[num].prev_path:
                                pfx2VPBeingPoisoned[num].numPoisonNoEffect += 1
                            else:
                                if pfx2VPBeingPoisoned[num].numPoisonNoEffect > 0:
                                    pfx2VPBeingPoisoned[num].numPoisonNoEffect = 0

            if not update.path and str(rv) == vpPoisoned:
                pfx2VPBeingPoisoned[num].prev_path = pfx2VPBeingPoisoned[num].cur_path
                pfx2VPBeingPoisoned[num].cur_path = []

            if not update.path:
                update.path = [0]
            if not update.hops:
                update.hops = [0]

            path_str = ""
            for n in update.path:
                path_str += str(n) + " "
            hops_str = ""
            for n in update.hops:
                hops_str += str(n) + " "

            if status == SENTINEL:
                c.execute(
                    "insert into ASGraph values (?,?,?,?,?,?,?,?,?,?,?)",
                    (pfx, unix_time, poison_round, status, str(mux), "", feed, path_str, hops_str, str(rv), 0),
                )
            else:
                thisVPoisoned = 0
                if str(rv) == vpPoisoned:
                    thisVPoisoned = 1
                poison_str = ""
                for p in pfx2PoisonList[num]:
                    poison_str += str(p) + " "
                c.execute(
                    "insert into ASGraph values (?,?,?,?,?,?,?,?,?,?,?)",
                    (
                        pfx,
                        unix_time,
                        poison_round,
                        status,
                        str(mux),
                        poison_str,
                        feed,
                        path_str,
                        hops_str,
                        str(rv),
                        thisVPoisoned,
                    ),
                )

    print "poisoned VP seen: " + str(vpPois_seen)
    if vpPois_seen is True:
        pfx2PoisVPNotSeenCount[num] = 0
    elif vpPois_seen is False and status == TEST:
        pfx2PoisVPNotSeenCount[num] += 1

    """
	if status==SENTINEL:
		vpOrder = []
		vpFound = [False]*len(pfx2VP[num])
		for v in pfx2VPOrder[num]:
			for w in pfx2VP[num]:
				if v==w:
					vpOrder.append(w)
					vpFound[pfx2VP[num].index(w)] = True
					break
		for i in range(0,len(vpFound)):
			if vpFound[i] is False:
				vpOrder.append(pfx2VP[num][i])
		pfx2VP[num] = vpOrder
	"""

    VPseen.clear()
    for vp in curVP:
        VPseen[vp] = curVP[vp]
    sys.stdout.flush()
Пример #4
0
def populateDB_ftr(c,num,poison_round,vpPoisoned):

	pfx = '184.164.' + str(num) + '.0/24'

	print "---------------------------------"
	print "populateDB_ftr"
	print "time: " + str(int(time.time()))
	print "prefix: " + str(pfx)
	
	tstamp = int(time.time())

	mux = MUX_NAMES[PREFIX_RANGE.index(num)]
	
	for feed in feeds:	
		locs = pfxToLoc[feed][pfx]
		for rv in locs:
			update = api.get_path(feed, pfx, rv, 'last_update')
			if feed=='rv':
				continue

			'''
			elif feed=='ftr':
				if update.time < tstamp-(15*60):
					continue
			elif feed=='rtr':
				if update.time < tstamp-(30*60):
					continue
			'''
				
			unix_time = update.time

			if (not update.path) is False:
				path = ""
				for asn in update.path:
					path += (str(asn) + " ")
				path = path.split()
				tup = getFilteredPath(path,feed)
				if tup is None:
					update.path = []
				else:
					filpath = tup[0]

		    
			if not update.path:
				update.path = [0]
				filpath = []
			if not update.hops:
				update.hops = [0]
            
			path_str = ""
			for n in update.path:
				path_str += (str(n) + " ")
			hops_str = ""
			for n in update.hops:
				hops_str += (str(n) + " ")

			c.execute('insert into TRGraph values (?,?,?,?,?,?,?,?,?)', \
				   (pfx, unix_time, poison_round,last_poison_time, feed, path_str, hops_str, str(rv),num_ftr_query))

			if str(rv)==vpPoisoned and num_ftr_query >=2:
				#confident that poisoning effect has been seen
				vpPois_TR_path[num].unix_time = unix_time
				vpPois_TR_path[num].filpath = filpath
				vpPois_TR_path[num].path_str = path_str
				vpPois_TR_path[num].hops_str = hops_str
				vpPois_TR_path[num].feed = feed
				vpPois_TR_path[num].mux = mux
				vpPois_TR_path[num].update = update

				vpPois_seen_prevTR[num] = True

			elif str(rv)==vpPoisoned:
				vpPois_seen_prevTR[num] = False
				
	sys.stdout.flush()
Пример #5
0
def populateDB(c,num,poison_round,status,vpPoisoned):

	pfx = '184.164.' + str(num) + '.0/24'

	print "---------------------------------"
	print "populateDB"
	print "time: " + str(int(time.time()))
	print "prefix: " + str(pfx)
	print "poison_round: " + str(poison_round)
	print "status: " + str(status)
	if status==TEST:
		print "vpPoisoned: " + vpPoisoned

	poison_str = ""
	for p in pfx2PoisonList[num]:
		poison_str += (str(p) + " ")
	
	curVP = dict()
	tstamp = int(time.time())

	vpPois_seen = False
    
	if status==SENTINEL:
		pfx2VP[num] = []

	mux = MUX_NAMES[PREFIX_RANGE.index(num)]
	
	for feed in feeds:	
		locs = pfxToLoc[feed][pfx]
		for rv in locs:
			update = api.get_path(feed, pfx, rv, 'last_update')
			if feed=='rv':
				if update.time < START_TIME:
					continue
				vp = str(rv).split(',')
				if len(vp)<2:
					continue
			elif feed=='ftr' or feed=='rtr':
				if update.time < tstamp-(30*60):
					continue
				if str(rv) in num2VPseen[num]:
					prev_upd = num2VPseen[num][str(rv)]
					if update.time<=prev_upd.time:
						continue

			if str(rv)==vpPoisoned:
				vpPois_seen = True

			curVP[str(rv)] = update
			unix_time = update.time

			if str(rv) in num2VPseen[num]:
				prev_update = num2VPseen[num][str(rv)]
			else:
				prev_update = None

			if (not update.path) is False:
				path = ""
				for asn in update.path:
					path += (str(asn) + " ")
				path = path.split()
				tup = getFilteredPath(path,feed)
				#or update.path[0] != tup[0][0]
				if tup is None:
					update.path = []
				else:
					filpath = tup[0]
					mux = tup[1]

					if num==240 or num==241: #CLEMSON
						vPoint = VP_Poison1(pfx,filpath,feed,mux,str(rv),5)
					else:
						vPoint = VP_Poison1(pfx,filpath,feed,mux,str(rv),4)
					if status==SENTINEL:
						if poison_round==0:
							pfx2VP[num].append(vPoint)
							pfx2VPBeingPoisoned[num] = pfx2VP[num][0]
						else:
							if str(rv) != pfx2VPBeingPoisoned[num].rv: 
								pfx2VP[num].append(vPoint)
							else:
								pfx2VP[num].append(pfx2VPBeingPoisoned[num])
					else:
						if str(rv)==vpPoisoned:
							pfx2VPBeingPoisoned[num].prev_path = pfx2VPBeingPoisoned[num].cur_path
							pfx2VPBeingPoisoned[num].cur_path = filpath

							if pfx2VPBeingPoisoned[num].cur_path==pfx2VPBeingPoisoned[num].prev_path:
								pfx2VPBeingPoisoned[num].PoisonNoEffect = True
							else:
								#potentially some new ASes in the new path
								pfx2VPBeingPoisoned[num].addStuff2PoisonQueue()
								

			if not update.path and str(rv)==vpPoisoned:
				pfx2VPBeingPoisoned[num].prev_path = pfx2VPBeingPoisoned[num].cur_path
				pfx2VPBeingPoisoned[num].cur_path = []
		    
			if not update.path:
				update.path = [0]
			if not update.hops:
				update.hops = [0]

			prev_path_str = ""
			if prev_update is not None:
				if not prev_update.path:
					prev_update.path = [0]
				for n in prev_update.path:
					prev_path_str += (str(n) + " ")
                
            
			path_str = ""
			for n in update.path:
				path_str += (str(n) + " ")
			hops_str = ""
			for n in update.hops:
				hops_str += (str(n) + " ")


			if status==SENTINEL:
				c.execute('insert into ASGraph values (?,?,?,?,?,?,?,?,?,?,?,?,?)', \
					  (pfx, unix_time, last_poison_time,poison_round, status, str(mux), "", \
					   feed, path_str, hops_str, prev_path_str, str(rv),0))              
			else:
				thisVPoisoned = 0
				if str(rv)==vpPoisoned:
					thisVPoisoned = 1
				c.execute('insert into ASGraph values (?,?,?,?,?,?,?,?,?,?,?,?,?)', \
					  (pfx, unix_time,last_poison_time,poison_round,status,str(mux), \
                                           poison_str,feed,path_str,hops_str,prev_path_str,str(rv),thisVPoisoned))


	print "poisoned VP seen: " + str(vpPois_seen)
	if vpPois_seen is True:
		pfx2PoisVPNotSeenCount[num] = 0
	elif vpPois_seen is False and status==TEST:
		if vpPois_seen_prevTR[num] is True:
			print "poisoned VP not seen has a previous traceroute" 
			pfx2VPBeingPoisoned[num].prev_path = pfx2VPBeingPoisoned[num].cur_path
			pfx2VPBeingPoisoned[num].cur_path = vpPois_TR_path[num].filpath   #this path might be empty
			
			if pfx2VPBeingPoisoned[num].cur_path==pfx2VPBeingPoisoned[num].prev_path:
				pfx2VPBeingPoisoned[num].PoisonNoEffect = True
			else:
				#potentially some new ASes in the new path
				pfx2VPBeingPoisoned[num].addStuff2PoisonQueue()


			curVP[vpPoisoned] = vpPois_TR_path[num].update
			if vpPoisoned in num2VPseen[num]:
				prev_update = num2VPseen[num][vpPoisoned]
			else:
				prev_update = None
			
			prev_path_str = ""
			if prev_update is not None:
				if not prev_update.path:
					prev_update.path = [0]
				for n in prev_update.path:
					prev_path_str += (str(n) + " ")
				
                        c.execute('insert into ASGraph values (?,?,?,?,?,?,?,?,?,?,?,?,?)', \
				   (pfx, vpPois_TR_path[num].unix_time,last_poison_time,poison_round,status,str(vpPois_TR_path[num].mux), \
				    poison_str,vpPois_TR_path[num].feed,vpPois_TR_path[num].path_str,vpPois_TR_path[num].hops_str, \
				    prev_path_str,vpPoisoned,1))
		else:
			pfx2PoisVPNotSeenCount[num] += 1
	
	num2VPseen[num].clear()
	for vp in curVP:
		num2VPseen[num][vp] = curVP[vp]
	sys.stdout.flush()
Пример #6
0
def populateDB(c,num,poison_round,status,vpPoisoned):

	pfx = '184.164.' + str(num) + '.0/24'
	print "---------------------------------"
	print "populateDB"
	print "prefix: " + str(pfx)
	print "poison_round: " + str(poison_round)
	print "status: " + str(status)
	if status==TEST:
		print "vpPoisoned: " + vpPoisoned
	VPseen = num2VPseen[num]
	curVP = dict()
	tstamp = int(time.time())

	vpPois_seen = False
    
	if status==SENTINEL:
		pfx2VP[PREFIX_RANGE[sent_idx]] = []
	else:
		if poison_round==0:
			pfx2VP[num] = []

	if status==TEST:
		mux = MUX_NAMES[PREFIX_RANGE.index(num)]
	else:
		mux = MUX_NAMES[sent_idx]
	for feed in feeds:	
		locs = pfxToLoc[feed][pfx]
		for rv in locs:
			update = api.get_path(feed, pfx, rv, 'last_update')
			if feed=='rv':
				if update.time < START_TIME:
					continue
				vp = str(rv).split(',')
				if len(vp)<2:
					continue
			elif feed=='ftr' or feed=='rtr':
				if update.time < tstamp-(30*60):
					continue
				if rv in VPseen:
					prev_upd = VPseen[rv]
					if update.time<=prev_upd.time:
						continue

			if str(rv)==vpPoisoned:
				vpPois_seen = True

			curVP[rv] = update
			unix_time = update.time		     

			if (not update.path) is False:
				path = ""
				for asn in update.path:
					path += (str(asn) + " ")
				path = path.split()
				tup = getFilteredPath(path,feed)
				if tup is None:
					update.path = []
				else:
					filpath = tup[0]
					mux = tup[1]

					vPoint = VP_Poison(pfx,filpath,feed,mux,str(rv))
					if status==SENTINEL:
						if str(rv) != vpPoisoned: 
							pfx2VP[PREFIX_RANGE[sent_idx]].append(vPoint)
						else:
							pfx2VP[PREFIX_RANGE[sent_idx]].append(pfx2VPBeingPoisoned[PREFIX_RANGE[sent_idx]])
					else:
						if poison_round==0:
							pfx2VP[num].append(vPoint)
							pfx2VPBeingPoisoned[num] = pfx2VP[num][0]
						else:
							if str(rv)==vpPoisoned:
								pfx2VPBeingPoisoned[num].prev_path = pfx2VPBeingPoisoned[num].cur_path
								pfx2VPBeingPoisoned[num].cur_path = filpath

			if not update.path and str(rv)==vpPoisoned:
				pfx2VPBeingPoisoned[num].cur_path = []
		    
			if not update.path:
				update.path = [0]
			if not update.hops:
				update.hops = [0]
                
            
			path_str = ""
			for n in update.path:
				path_str += (str(n) + " ")
			hops_str = ""
			for n in update.hops:
				hops_str += (str(n) + " ")

			if status==SENTINEL:
				c.execute('insert into ASGraph values (?,?,?,?,?,?,?,?,?,?,?)', \
					  (pfx, unix_time, poison_round, status, str(mux), "", \
					   feed, path_str, hops_str, str(rv),0))              
			else:
				thisVPoisoned = 0
				if str(rv)==vpPoisoned:
					thisVPoisoned = 1
				poison_str = ""
				for p in pfx2PoisonSet[num]:
					poison_str += (str(p) + " ")
				c.execute('insert into ASGraph values (?,?,?,?,?,?,?,?,?,?,?)', \
					  (pfx, unix_time,poison_round,status,str(mux), \
                                           poison_str,feed,path_str,hops_str,str(rv),thisVPoisoned))

                          
	VPseen.clear()
	for vp in curVP:
		VPseen[vp] = curVP[vp]
	sys.stdout.flush()
Пример #7
0
def populateDB(c, num, poison_round, status, vpPoisoned):

    #vpPoisoned is a string
    pfx = '184.164.' + str(num) + '.0/24'
    print "---------------------------------"
    print "prefix: " + str(pfx)
    print "poison_round: " + str(poison_round)
    print "status: " + str(status)
    if status==TEST:
        print "vpPoisoned: " + str(vpPoisoned) + " " + str(pfx2VPtoPoison[num])
    VPseen = num2VPseen[num]
    curVP = dict()
    tstamp = int(time.time())

    for feed in feeds:
        locs = pfxToLoc[feed][pfx]
        for rv in locs:
            update = api.get_path(feed, pfx, rv, 'last_update')
            if feed=='rv':
                if update.time < START_TIME:
                    continue
                vp = str(rv).split(',')
                if len(vp)<2:
                    continue
            if feed=='ftr':
                if update.time < tstamp-(30*60):
                    continue
                if rv in VPseen:
                    prev_upd = VPseen[rv]
                    if update.time<=prev_upd.time:
                        continue

            curVP[rv] = update
            unix_time = update.time
            
            if poison_round==0 and ((not update.path) is False) and status==TEST:
                path = ""
                for asn in update.path:
                    path += (str(asn) + " ")
                path = path.split()
                tup = getFilteredPath(path,feed)
                if tup is None:
                    continue
                filpath = tup[0]
                mux = tup[1]
                
                vPoint = VP(pfx,filpath,feed,mux,str(rv))
                pfx2VP[num].append(vPoint)
                print vPoint
                
                
            if not update.path:
                update.path = [0]
            if not update.hops:
                update.hops = [0]
                
            mux = ''
            for m in muxASToName:
                if int(m) in update.path:
                    mux = muxASToName[m]
                    break

            if len(mux)==0:
                continue
            
            path_str = ""
            for n in update.path:
                path_str += (str(n) + " ")
            hops_str = ""
            for n in update.hops:
                hops_str += (str(n) + " ")

            if status==SENTINEL:
                c.execute('insert into ASGraph values (?,?,?,?,?,?,?,?,?,?,?)', \
                              (pfx, unix_time, poison_round, status, str(mux), -1, \
                                   feed, path_str, hops_str, str(rv),0))              
            else:
                thisVPoisoned = 0
                if str(rv)==vpPoisoned:
                              thisVPoisoned = 1
                c.execute('insert into ASGraph values (?,?,?,?,?,?,?,?,?,?,?)', \
                              (pfx, unix_time,poison_round,status, str(mux), \
                                   num2PoisonAS[num],feed,path_str,hops_str,str(rv),thisVPoisoned))

                          
    VPseen.clear()
    for vp in curVP:
               VPseen[vp] = curVP[vp]
    sys.stdout.flush()
Пример #8
0
def main():

    global opts
    parser = create_parser()
    opts, _args = parser.parse_args()

    resource.setrlimit(resource.RLIMIT_AS, (2147483648L, 2147483648L))

    Pyro4.config.HMAC_KEY = "choffnes-cunha-javed-owning"
    sys.excepthook = Pyro4.util.excepthook
    ns = Pyro4.naming.locateNS("128.208.4.106", 51556)
    uri = ns.lookup("livedb.main")
    global api
    api = Pyro4.Proxy(uri)

    mkdir_p(opts.logdir)
    logger = logging.getLogger()
    logger.setLevel(logging.DEBUG)
    formatter = logging.Formatter("%(message)s")
    loghandler = logging.handlers.RotatingFileHandler(opts.logfile, maxBytes=128 * 1024 * 1024, backupCount=5)
    loghandler.setFormatter(formatter)
    logger.addHandler(loghandler)

    global feeds
    feeds = ["rv", "ftr"]

    global pfxToLoc
    pfxToLoc = dict()
    for feed in feeds:
        pfxToLoc[feed] = api.get_prefix_to_locations(feed)

    global num2PoisonAS
    num2PoisonAS = dict()
    for num in PREFIX_RANGE:
        num2PoisonAS[num] = 47065

    num2ASPoisonedThisRound = defaultdict(list)

    global pfx2VP
    pfx2VP = defaultdict(list)
    global pfx2VPtoPoison
    pfx2VPtoPoison = dict()  # the VP index to be poisoned
    for num in PREFIX_RANGE:
        pfx2VPtoPoison[num] = 0

    tstamp = int(time.time())
    for num in PREFIX_RANGE:
        pfx = "184.164." + str(num) + ".0/24"
        for feed in feeds:
            locs = pfxToLoc[feed][pfx]
            for rv in locs:
                update = api.get_path(feed, pfx, rv, "last_update")
                if not update.path:
                    continue
                if feed == "rv":
                    print update
                    if update.time < (START_TIME - 10 * 3600):
                        continue
                    vp = str(rv).split(",")
                    if len(vp) < 2:
                        continue
                if feed == "ftr":
                    if update.time < tstamp - (30 * 60):
                        continue

                path = ""
                for asn in update.path:
                    path += str(asn) + " "
                path = path.split()
                tup = getFilteredPath(path, feed)
                if tup is None:
                    continue
                filpath = tup[0]
                mux = tup[1]

                vPoint = VP(pfx, filpath, feed, mux, str(rv))
                pfx2VP[num].append(vPoint)

    """
Пример #9
0
        time = row[7]
        vpoint = row[8]
        prepend_mux = row[1]
        prepend_length = row[2]

        if len(s) < 3:
            continue
        z = list(s)
        z.reverse()
        mux = row[3]
        for asn in z:
            if asn in muxASToName:
                mux = muxASToName[asn]
                break

        filpath = getFilteredPath(s,mux,feed)
        if filpath is None:
            continue

        if status==SENTINEL:
            prev_asn = '0'
            for asn in filpath:
                if asn==prev_asn or asn==RIOT:
                    continue
                if asn in MUX_ASN:
                    
                    if prev_asn=='3267' and asn=='20388':
                            print P
                    
                    as2neigh[prev_asn].add(asn)
                    as2mux2neigh[prev_asn][mux].add(asn)
Пример #10
0
        
        mux = row[0]
        if len(mux)==0:
            if '7922' in s:
                mux='PRINCE'
            elif '174' in s:
                mux='GATECH'
            else:
                continue
        unfiltered_path = row[1][1:len(row[1])-1]
        s = unfiltered_path.split(", ")
        if len(s) < 2:
            continue
        if len(s) < 3 and s[-1] not in MUX_ASN:
             continue
        filpath = getFilteredPath(s,mux)
        if filpath is None:
            continue

        prev_asn = '0'
        for asn in filpath:
            if asn in MUX_ASN or asn==prev_asn:
                prev_asn = asn
                continue
            idx = filpath.index(asn)
            P = Path(pfx, prev_asn, mux, 0,'',filpath[idx:],MUX_NAMES,[0,0,0,0,0],[])
            as2mux2datapaths[asn][mux].append(filpath[idx:])
            if asn in as2mux2Path:
                if mux in as2mux2Path[asn]:
                    as2mux2Path[asn][mux].path_data = filpath[idx:]
                else:
Пример #11
0
def populateDB(c,num,poison_round,status,vpPoisoned):

	pfx = '184.164.' + str(num) + '.0/24'

	print "---------------------------------"
	print "populateDB"
	print "time: " + str(int(time.time()))
	print "prefix: " + str(pfx)
	print "poison_round: " + str(poison_round)
	print "status: " + str(status)
	if status==TEST:
		print "vpPoisoned: " + vpPoisoned
		
	VPseen = num2VPseen[num]
	
	curVP = dict()
	tstamp = int(time.time())

	vpPois_seen = False
    
	if status==SENTINEL:
		pfx2VP[num] = []

	mux = MUX_NAMES[PREFIX_RANGE.index(num)]
	
	for feed in feeds:	
		locs = pfxToLoc[feed][pfx]
		for rv in reversed(list(locs)):
			update = api.get_path(feed, pfx, rv, 'last_update')
			if feed=='rv':
				if update.time < START_TIME:
					continue
				vp = str(rv).split(',')
				if len(vp)<2:
					continue
			elif feed=='ftr' or feed=='rtr':
				if update.time < tstamp-(35*60):
					continue
				if rv in VPseen:
					prev_upd = VPseen[rv]
					if update.time<=prev_upd.time:
						continue

			if str(rv)==vpPoisoned:
				vpPois_seen = True

			curVP[rv] = update
			unix_time = update.time

			if rv in VPseen:
				prev_update = VPseen[rv]
			else:
				prev_update = None

			if (not update.path) is False:
				path = ""
				for asn in update.path:
					path += (str(asn) + " ")
				path = path.split()
				tup = getFilteredPath(path,feed)
				#or update.path[0] != tup[0][0]
				if tup is None:
					update.path = []
				else:
					filpath = tup[0]
					mux = tup[1]

					if num==240: #CLEMSON
						vPoint = VP_Poison1(pfx,filpath,feed,mux,str(rv),5)
					else:
						vPoint = VP_Poison1(pfx,filpath,feed,mux,str(rv),4)
					if status==SENTINEL:
						if poison_round==0:
							pfx2VP[num].append(vPoint)
							pfx2VPBeingPoisoned[num] = pfx2VP[num][0]
						else:
							if str(rv) != pfx2VPBeingPoisoned[num].rv: 
								pfx2VP[num].append(vPoint)
							else:
								pfx2VP[num].append(pfx2VPBeingPoisoned[num])
					else:
						if str(rv)==vpPoisoned:
							pfx2VPBeingPoisoned[num].prev_path = pfx2VPBeingPoisoned[num].cur_path
							pfx2VPBeingPoisoned[num].cur_path = filpath

							if pfx2VPBeingPoisoned[num].cur_path==pfx2VPBeingPoisoned[num].prev_path:
								pfx2VPBeingPoisoned[num].PoisonNoEffect = True
							else:
								#potentially some new ASes in the new path
								pfx2VPBeingPoisoned[num].addStuff2PoisonQueue()
								

			if not update.path and str(rv)==vpPoisoned:
				pfx2VPBeingPoisoned[num].prev_path = pfx2VPBeingPoisoned[num].cur_path
				pfx2VPBeingPoisoned[num].cur_path = []
		    
			if not update.path:
				update.path = [0]
			if not update.hops:
				update.hops = [0]

			prev_path_str = ""
			if prev_update is not None:
				if not prev_update.path:
					prev_update.path = [0]
				for n in prev_update.path:
					prev_path_str += (str(n) + " ")
                
            
			path_str = ""
			for n in update.path:
				path_str += (str(n) + " ")
			hops_str = ""
			for n in update.hops:
				hops_str += (str(n) + " ")


			if status==SENTINEL:
				c.execute('insert into ASGraph values (?,?,?,?,?,?,?,?,?,?,?,?,?)', \
					  (pfx, unix_time, last_poison_time,poison_round, status, str(mux), "", \
					   feed, path_str, hops_str, prev_path_str, str(rv),0))              
			else:
				thisVPoisoned = 0
				if str(rv)==vpPoisoned:
					thisVPoisoned = 1
				poison_str = ""
				for p in pfx2PoisonList[num]:
					poison_str += (str(p) + " ")
				c.execute('insert into ASGraph values (?,?,?,?,?,?,?,?,?,?,?,?,?)', \
					  (pfx, unix_time,last_poison_time,poison_round,status,str(mux), \
                                           poison_str,feed,path_str,hops_str,prev_path_str,str(rv),thisVPoisoned))


	print "poisoned VP seen: " + str(vpPois_seen)
	if vpPois_seen is True:
		pfx2PoisVPNotSeenCount[num] = 0
	elif vpPois_seen is False and status==TEST:
		pfx2PoisVPNotSeenCount[num] += 1
		

	'''
	if status==SENTINEL:
		vpOrder = []
		vpFound = [False]*len(pfx2VP[num])
		for v in pfx2VPOrder[num]:
			for w in pfx2VP[num]:
				if v==w:
					vpOrder.append(w)
					vpFound[pfx2VP[num].index(w)] = True
					break
		for i in range(0,len(vpFound)):
			if vpFound[i] is False:
				vpOrder.append(pfx2VP[num][i])
		pfx2VP[num] = vpOrder
	'''
	
	VPseen.clear()
	for vp in curVP:
		VPseen[vp] = curVP[vp]
	sys.stdout.flush()