def parse_args_for_create(args): parser = create_parser() parser.add_argument('--services-data', help='Services CSV datafile', default='data/services.csv') parser.add_argument('--path-prefix', help='Prefix for generated URL paths', default=path_prefix) parser.add_argument('--asset-prefix', help='Prefix for generated asset URLs', default=asset_prefix) parser.add_argument('--static-prefix', help='Prefix for generated GOV.UK static URLs', default=static_prefix) parser.add_argument('--static-digests', help='Path to manifest file containing assets digests', type=argparse.FileType()) return parser.parse_args(args)
def main(): global opts parser = create_parser() opts, _args = parser.parse_args() if opts.database is None or opts.blacklist is None: parser.parse_args(["-h"]) opts.output = opts.output + str(datetime.now()) 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) # get the livedb object: 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) sys.stdout = open(opts.output, "w") sys.stderr = sys.stdout global conn c = create_db() global feeds feeds = ["ftr", "rv", "rtr"] num2pfx = dict() global pfxToLoc pfxToLoc = dict() for feed in feeds: pfxToLoc[feed] = api.get_prefix_to_locations(feed) global num2VPseen num2VPseen = dict() for num in PREFIX_RANGE: num2VPseen[num] = dict() global pfx2PoisonList pfx2PoisonList = dict() for num in PREFIX_RANGE: pfx2PoisonList[num] = list() pfx2PoisonList[num].append(RIOT_ASN) global pfx2VPBeingPoisoned pfx2VPBeingPoisoned = dict() global pfx2VP pfx2VP = defaultdict(list) """ global pfx2VPOrder pfx2VPOrder = defaultdict(list) """ global pfx2VPAlreadyPoisoned pfx2VPAlreadyPoisoned = dict() for num in PREFIX_RANGE: pfx2VPAlreadyPoisoned[num] = set() global pfx2PoisVPNotSeenCount pfx2PoisVPNotSeenCount = dict() for num in PREFIX_RANGE: pfx2PoisVPNotSeenCount[num] = 0 for num in PREFIX_RANGE: num2pfx[num] = Prefix(num, RIOT_ASN, "announced") num2pfx[num].up() announce_null(num2pfx[num]) soft_reset(num2pfx) wait_cmd(POISON_INTERVAL_2) # initial poisoning so that the path shows up in the data feeds pfx_idx = 0 for mux in MUX_NAMES: pfx = num2pfx[PREFIX_RANGE[pfx_idx]] pfx.poisonList([RIOT_ASN]) announce_sentinel(pfx, mux) pfx_idx += 1 soft_reset(num2pfx) wait_cmd(POISON_INTERVAL) poisonRound = 0 sent_used = True while True: for num in PREFIX_RANGE: if poisonRound % SENT_ROUND == 0 and sent_used is True: vpJustPoisoned = "" populateDB(c, num, poisonRound, SENTINEL, "") else: vpJustPoisoned = pfx2VPBeingPoisoned[num].rv populateDB(c, num, poisonRound, TEST, vpJustPoisoned) conn.commit() print "vantage points:" for v in pfx2VP[num]: print v print "vp's already poisoned: " + str(pfx2VPAlreadyPoisoned[num]) pfx2PoisonList[num] = getNextPoisoning(num, poisonRound, sent_used) print "poison_list: " + str(pfx2PoisonList[num]) print "sentinel used: " + str(sent_used) pfx = num2pfx[num] pfx.poisonList(list(pfx2PoisonList[num])) for mux in MUX_NAMES: if PREFIX_RANGE.index(num) == MUX_NAMES.index(mux): pfx.update_route_map1(mux, True) else: pfx.update_route_map1(mux, False) pfx.up() if poisonRound % SENT_ROUND != 0: poisonRound += 1 else: if sent_used is False: # we just sent sentinels out sent_used = True else: sent_used = False poisonRound += 1 sys.stdout.flush() soft_reset(num2pfx) wait_cmd(POISON_INTERVAL)
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) # get the livedb object: 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) sys.stdout = open(opts.output, 'w') sys.stderr = sys.stdout db_file = opts.database + str(datetime.now()) #db_file = "../data/mike_data/mike.db2012-04-25 00:08:59.710008" conn = sqlite3.connect(db_file) c = conn.cursor() c.execute("create table if not exists ASGraph (prefix text, unix_time int, dtime text, \ poison_round int, poisonedAS int, feed text, observedPath text, filteredASPath, vpoint text, thisVPoisoned int)") c.execute("create index idx_pfx on ASGraph(prefix)") c.execute("create index idx_asn on ASGraph(poisonedAS)") c.execute("create index idx_pfx_path on ASGraph(prefix,observedPath)") c.execute("create index idx_pfx_filpath on ASGraph(prefix,filteredASPath)") c.execute("create index idx_prepend on ASGraph(poison_round)") c.execute("create index idx_vpoint on ASGraph(vpoint)") num2pfx = dict() for num in PREFIX_RANGE: num2pfx[num] = Prefix(num, 47065, "announced") global feeds #feeds = ['rv', 'ftr'] feeds = ['rv'] global num2PoisonSet num2PoisonSet = dict() for num in PREFIX_RANGE: num2PoisonSet[num] = set() num2PoisonSet[num].add(47065) global num2VPoint num2VPoint = dict() for num in PREFIX_RANGE: num2VPoint[num] = "0" global ASPoisoned ASPoisoned = dict() for num in PREFIX_RANGE: pfx = num2pfx[num] pfx.poisonList([47065]) pfx.up() soft_reset(num2pfx) wait_cmd(1800) global poisonRound poisonRound = 0 global pfxToLoc pfxToLoc = dict() for feed in feeds: pfxToLoc[feed] = api.get_prefix_to_locations(feed) while True: for num in PREFIX_RANGE: populateDB(c,num) conn.commit() #wait_cmd(1800) for num in PREFIX_RANGE: pfx = num2pfx[num] f = False while f is False: f = getPoisonings(c,num) pfx.poisonList(list(num2PoisonSet[num])) pfx.up() soft_reset(num2pfx) poisonRound += 1 wait_cmd(3600)
def main(): global opts parser = create_parser() opts, _args = parser.parse_args() if opts.database is None: parser.parse_args(['-h']) opts.output = opts.output + str(datetime.now()) 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', 51555) # get the livedb object: 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) sys.stdout = open(opts.output, 'w') sys.stderr = sys.stdout global conn c = create_db() global feeds feeds = ['ftr', 'rv', 'rtr'] num2pfx = dict() global pfxToLoc pfxToLoc = dict() for feed in feeds: pfxToLoc[feed] = api.get_prefix_to_locations(feed) global num2VPseen num2VPseen = dict() for num in PREFIX_RANGE: num2VPseen[num] = dict() global pfx2PoisonList pfx2PoisonList = dict() for num in PREFIX_RANGE: pfx2PoisonList[num] = list() pfx2PoisonList[num].append(RIOT_ASN) global pfx2VPBeingPoisoned pfx2VPBeingPoisoned = dict() global pfx2VP pfx2VP = defaultdict(list) global pfx2VPAlreadyPoisoned pfx2VPAlreadyPoisoned = dict() for num in PREFIX_RANGE: pfx2VPAlreadyPoisoned[num] = set() global pfx2VPASNAlreadyDone pfx2VPASNAlreadyDone = dict() for num in PREFIX_RANGE: pfx2VPASNAlreadyDone[num] = set() global pfx2PoisVPNotSeenCount pfx2PoisVPNotSeenCount = dict() for num in PREFIX_RANGE: pfx2PoisVPNotSeenCount[num] = 0 global vpPois_TR_path vpPois_TR_path = dict() for num in PREFIX_RANGE: vpPois_TR_path[num] = TR_path_object('','','','','','','') global vpPois_seen_prevTR vpPois_seen_prevTR = dict() for num in PREFIX_RANGE: vpPois_seen_prevTR[num] = False #signal.signal(signal.SIGUSR1, lambda sig, stack: traceback.print_stack(stack)) signal.signal(signal.SIGUSR1, printStack) for num in PREFIX_RANGE: num2pfx[num] = Prefix(num, RIOT_ASN, "announced") num2pfx[num].up() announce_null(num2pfx[num]) soft_reset(num2pfx) wait_cmd(POISON_INTERVAL_2) #initial poisoning so that the path shows up in the data feeds pfx_idx = 0 for mux in MUX_NAMES: pfx = num2pfx[PREFIX_RANGE[pfx_idx]] pfx.poisonList([RIOT_ASN]) announce_sentinel(pfx,mux) pfx_idx += 1 soft_reset(num2pfx) global last_poison_time last_poison_time = int(time.time()) wait_cmd(POISON_INTERVAL) poisonRound = 0 sent_used = True global num_ftr_query num_ftr_query = NUM_FTR while True: if num_ftr_query>=NUM_FTR: for num in PREFIX_RANGE: if poisonRound%SENT_ROUND==0 and sent_used is True: populateDB(c,num,poisonRound,SENTINEL,"") else: populateDB(c,num,poisonRound,TEST,pfx2VPBeingPoisoned[num].rv) conn.commit() print "VPNotSeenCount: " + str(pfx2PoisVPNotSeenCount[num]) ''' print "vantage points:" for v in pfx2VP[num]: print v ''' print "vp's already poisoned: " + str(pfx2VPAlreadyPoisoned[num]) print "vp ASes already done: " + str(pfx2VPASNAlreadyDone[num]) pfx2PoisonList[num] = getNextPoisoning(num,poisonRound,sent_used) print "poison_list: " + str(pfx2PoisonList[num]) print "sentinel used: " + str(sent_used) pfx = num2pfx[num] pfx.poisonList(list(pfx2PoisonList[num])) for mux in MUX_NAMES: if PREFIX_RANGE.index(num)==MUX_NAMES.index(mux): pfx.update_route_map1(mux, True) else: pfx.update_route_map1(mux,False) pfx.up() if poisonRound%SENT_ROUND != 0: poisonRound += 1 else: if sent_used is False: #we just sent sentinels out sent_used = True else: sent_used = False poisonRound += 1 sys.stdout.flush() soft_reset(num2pfx) last_poison_time = int(time.time()) num_ftr_query = 1 wait_cmd(FTR_INTERVAL) else: for num in PREFIX_RANGE: if poisonRound%SENT_ROUND==0 and sent_used is True: populateDB_ftr(c,num,poisonRound,"") else: populateDB_ftr(c,num,poisonRound,pfx2VPBeingPoisoned[num].rv) conn.commit() num_ftr_query += 1 wait_cmd(FTR_INTERVAL)
def main(): global opts parser = create_parser() opts, _args = parser.parse_args() if opts.database is None or opts.refasn is None: parser.parse_args(['-h']) 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) # get the livedb object: 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) sys.stdout = open(opts.output, 'w') sys.stderr = sys.stdout conn = sqlite3.connect(opts.database + str(datetime.now())) c = conn.cursor() #observedPath is the raw path that you see both feeds: lists if ASs from ftr and list of ASes from rv (W in case of withdrawn rv path) #filteredASPath is the filtered AS path #asn: the ASN that we're trying to measure c.execute("create table if not exists ASGraph (prefix text, unix_time int, dtime text, asn int, \ prepend_round int, mux text, feed text, observedPath text, ipPath text, vpoint text)") c.execute("create index idx_pfx on ASGraph(prefix)") c.execute("create index idx_asn on ASGraph(asn)") c.execute("create index idx_pfx_path on ASGraph(prefix,observedPath)") c.execute("create index idx_prepend on ASGraph(prepend_round)") global feeds feeds = ['rv', 'ftr'] num2pfx = dict() #announce 250-255 from all muxes for num in PREFIX_RANGE: num2pfx[num] = Prefix(num, 47065, "announced") #initial poisoning so that the path shows up in the data feeds for num in PREFIX_RANGE: pfx = num2pfx[num] for mux in MUX_NAMES: pfx.update_route_map1(mux, True) pfx.up() soft_reset(num2pfx) wait_cmd(1800) global pfxToLoc pfxToLoc = dict() for feed in feeds: pfxToLoc[feed] = api.get_prefix_to_locations(feed) global num2VPseen num2VPseen = dict() for num in PREFIX_RANGE: num2VPseen[num] = dict() global num2pfxMux num2pfxMux = dict() global numPrepend numPrepend = 0 #for refasn store the initial path for each prefix for num in PREFIX_RANGE: populateDB(c,num,opts.refasn) conn.commit() numPrepend = 1 while True: for num in PREFIX_RANGE: mux = num2pfxMux[num] print "mux for prefix " + str(num) + ": " + mux pfx = num2pfx[num] assert mux in MUX_NAMES pfx.set_num_prepend1(numPrepend,mux) pfx.up() soft_reset(num2pfx) wait_cmd(1800) for num in PREFIX_RANGE: populateDB(c,num,opts.refasn) conn.commit() numPrepend += 1
def main(): global opts parser = create_parser() opts, _args = parser.parse_args() if opts.database is None or opts.blacklist is None: parser.parse_args(['-h']) 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) # get the livedb object: 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) sys.stdout = open(opts.output, 'w') sys.stderr = sys.stdout global conn c = create_db() global feeds feeds = ['rv', 'ftr', 'rtr'] num2pfx = dict() global pfxToLoc pfxToLoc = dict() for feed in feeds: pfxToLoc[feed] = api.get_prefix_to_locations(feed) global num2VPseen num2VPseen = dict() for num in PREFIX_RANGE: num2VPseen[num] = dict() global pfx2PoisonSet pfx2PoisonSet = dict() for num in PREFIX_RANGE: pfx2PoisonSet[num] = set() pfx2PoisonSet[num].add(RIOT_ASN) global pfx2VPBeingPoisoned pfx2VPBeingPoisoned = dict() global pfx2VP pfx2VP = defaultdict(list) global sent_idx sent_idx = 0 for num in PREFIX_RANGE: num2pfx[num] = Prefix(num, RIOT_ASN, "announced") num2pfx[num].up() announce_null(num2pfx[num]) soft_reset(num2pfx) wait_cmd(POISON_INTERVAL_2) #initial poisoning so that the path shows up in the data feeds pfx_idx = 0 for mux in MUX_NAMES: pfx = num2pfx[PREFIX_RANGE[pfx_idx]] pfx.poisonList([RIOT_ASN]) announce_sentinel(pfx,mux) pfx_idx += 1 #last pfx is the sentinel: for now starting with the first mux announce_sentinel(num2pfx[PREFIX_RANGE[-1]],MUX_NAMES[sent_idx]) soft_reset(num2pfx) wait_cmd(POISON_INTERVAL) poisonRound = 0 while True: if poisonRound==0: vpJustPoisoned = "" else: vpJustPoisoned = pfx2VPBeingPoisoned[PREFIX_RANGE[sent_idx]].rv populateDB(c,PREFIX_RANGE[-1],poisonRound,SENTINEL,vpJustPoisoned) conn.commit() for num in PREFIX_RANGE[0:len(PREFIX_RANGE)-1]: if poisonRound==0: vpJustPoisoned = "" else: vpJustPoisoned = pfx2VPBeingPoisoned[num].rv populateDB(c,num,poisonRound,TEST,vpJustPoisoned) conn.commit() print "vantage points:" for v in pfx2VP[num]: print v pfx2PoisonSet[num] = getNextPoisoning(num) print "pset: " + str(pfx2PoisonSet[num]) pfx = num2pfx[num] pfx.poisonList(list(pfx2PoisonSet[num])) for mux in MUX_NAMES: if PREFIX_RANGE.index(num)==MUX_NAMES.index(mux): pfx.update_route_map1(mux, True) else: pfx.update_route_map1(mux,False) pfx.up() sent_idx = (sent_idx+1)%len(MUX_NAMES) announce_sentinel(num2pfx[PREFIX_RANGE[-1]],MUX_NAMES[sent_idx]) poisonRound += 1 sys.stdout.flush() soft_reset(num2pfx) wait_cmd(POISON_INTERVAL)
def main(): global opts parser = create_parser() opts, _args = parser.parse_args() opts.output = opts.output + str(datetime.now()) 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) # get the livedb object: 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 = ['ftr', 'rv', 'rtr'] num2pfx = dict() global pfxToLoc pfxToLoc = dict() for feed in feeds: pfxToLoc[feed] = api.get_prefix_to_locations(feed) for num in PREFIX_RANGE: num2pfx[num] = Prefix(num, RIOT_ASN, "announced") num2pfx[num].up() announce_null(num2pfx[num]) soft_reset(num2pfx) wait_cmd(POISON_INTERVAL_2) #initial poisoning so that the path shows up in the data feeds pfx_idx = 0 for mux in MUX_NAMES: pfx = num2pfx[PREFIX_RANGE[pfx_idx]] pfx.poisonList([RIOT_ASN]) announce_sentinel(pfx,mux) pfx_idx += 1 soft_reset(num2pfx) wait_cmd(POISON_INTERVAL) numPaths = 0 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 elif feed=='ftr' or feed=='rtr': if update.time < tstamp-(30*60): continue numPaths += 1 print numPaths
def main(): global opts parser = create_parser() opts, _args = parser.parse_args() if opts.database is None: parser.parse_args(['-h']) 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) sys.stdout = open(opts.output, 'w') sys.stderr = sys.stdout global conn c = create_db() global feeds feeds = ['rv', 'ftr'] num2pfx = dict() global pfxToLoc pfxToLoc = dict() for feed in feeds: pfxToLoc[feed] = api.get_prefix_to_locations(feed) global num2VPseen num2VPseen = dict() for num in PREFIX_RANGE: num2VPseen[num] = dict() for num in PREFIX_RANGE_SENT: num2VPseen[num] = dict() global num2PoisonAS num2PoisonAS = dict() for num in PREFIX_RANGE: num2PoisonAS[num] = RIOT_ASN 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] = -1 for num in PREFIX_RANGE: num2pfx[num] = Prefix(num, RIOT_ASN, "announced") pfx = num2pfx[num] pfx.poisonList([RIOT_ASN]) pfx.up() for num in PREFIX_RANGE: pfx = num2pfx[num] for mux in MUX_NAMES: if PREFIX_RANGE.index(num)==MUX_NAMES.index(mux): pfx.update_route_map1(mux, True) else: pfx.update_route_map1(mux,False) pfx.up() for num in PREFIX_RANGE_SENT: num2pfx[num] = Prefix(num, RIOT_ASN, "announced") pfx = num2pfx[num] pfx.poisonList([RIOT_ASN]) pfx.up() for num in PREFIX_RANGE_SENT: pfx = num2pfx[num] for mux in MUX_NAMES: if PREFIX_RANGE_SENT.index(num)==MUX_NAMES.index(mux): pfx.update_route_map1(mux, True) else: pfx.update_route_map1(mux,False) pfx.up() soft_reset(num2pfx) wait_cmd(POISON_INTERVAL) poisonRound = 0 while True: for num in PREFIX_RANGE_SENT: populateDB(c,num,poisonRound,SENTINEL,"") conn.commit() for num in PREFIX_RANGE: if poisonRound==0: vpJustPoisoned = "" else: vpJustPoisoned = pfx2VP[num][pfx2VPtoPoison[num]].rv populateDB(c,num,poisonRound,TEST,vpJustPoisoned) conn.commit() if poisonRound==0: for num in PREFIX_RANGE: pfx2VPtoPoison[num] = 0 pfx = num2pfx[num] print num2ASPoisonedThisRound[num] vp2poison = pfx2VP[num][pfx2VPtoPoison[num]] print "vp to poison: " + str(pfx2VPtoPoison[num]) + " " + str(vp2poison) num2PoisonAS[num] = getNextPoisoning(vp2poison, num2ASPoisonedThisRound[num]) if num2PoisonAS[num] > 0 and num2PoisonAS[num] not in opts.blacklist: num2ASPoisonedThisRound[num].append(num2PoisonAS[num]) print "as to poison: " + str(num2PoisonAS[num]) print "new poisonidx: " + str(vp2poison.poisonIdx) if vp2poison.poisonIdx==vp2poison.startingPoisonIdx: if (pfx2VPtoPoison[num]+1)==len(pfx2VP[num]): num2ASPoisonedThisRound[num] = [] pfx2VPtoPoison[num] = (pfx2VPtoPoison[num]+1)%len(pfx2VP[num]) print "new vp to poison: " + str(pfx2VPtoPoison[num]) if num2PoisonAS[num] > 0 and num2PoisonAS[num] not in opts.blacklist: pfx.poisonList([num2PoisonAS[num]]) else: pfx.poisonList([RIOT_ASN]) for mux in MUX_NAMES: if PREFIX_RANGE.index(num)==MUX_NAMES.index(mux): pfx.update_route_map1(mux, True) else: pfx.update_route_map1(mux,False) pfx.up() sys.stdout.flush() soft_reset(num2pfx) poisonRound += 1 wait_cmd(POISON_INTERVAL)
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) """
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) # get the livedb object: 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) sys.stdout = open(opts.output, 'w') sys.stderr = sys.stdout global num2PoisonCandidates num2PoisonCandidates = dict() for num in PREFIX_RANGE: num2PoisonCandidates[num] = list() global num2commonAS num2commonAS = dict() num2commonAS[241] = [101,73] num2commonAS[243] = [6939,2381] num2commonAS[245] = [174,2637] num2commonAS[247] = [7922,88] num2commonAS[249] = [209,2722,12148] global num2startPoisIdx num2startPoisIdx = dict() num2startPoisIdx[241] = 3 num2startPoisIdx[243] = 2 num2startPoisIdx[245] = 2 num2startPoisIdx[247] = 2 num2startPoisIdx[249] = 3 conn = sqlite3.connect('data/imc4.db') c = conn.cursor() #c.execute("drop table ASGraph ") c.execute("create table ASGraph (prefix text, unix_time int, dtime text, asn int, edge int, \ bfs_level int, poison_round int, startTime text, poisoning text, feed text, observedPath text, vpoint text)") c.execute("create index idx_pfx on ASGraph(prefix)") c.execute("create index idx_asn on ASGraph(asn)") c.execute("create index idx_pfx_path on ASGraph(prefix,observedPath)") c.execute("create index idx_edge on ASGraph(asn,edge)") global feeds feeds = ['rv', 'ftr'] num2pfx = dict() for num in PREFIX_RANGE: num2pfx[num] = Prefix(num, 47065, "announced") global num2PoisonSet num2PoisonSet = dict() for num in PREFIX_RANGE: num2PoisonSet[num] = set() num2PoisonSet[num].add(47065) global startTime startTime = str(datetime.now()) #initial poisoning so that the path shows up in the data feeds for num in PREFIX_RANGE: pfx = num2pfx[num] pfx.poisonList([47065]) pfx.up() soft_reset(num2pfx) wait_cmd(1800) global num2BFSLevel num2BFSLevel = dict() for num in PREFIX_RANGE: num2BFSLevel[num] = 1 global num2PoisonRound num2PoisonRound = dict() for num in PREFIX_RANGE: num2PoisonRound[num] = 1 global pfxToLoc pfxToLoc = dict() for feed in feeds: pfxToLoc[feed] = api.get_prefix_to_locations(feed) while True: for num in PREFIX_RANGE: populateDB(c,num) conn.commit() #wait_cmd(1800) for num in PREFIX_RANGE: pfx = num2pfx[num] getPoisonings(c,num) pfx.poisonList(list(num2PoisonSet[num])) pfx.up() soft_reset(num2pfx) for num in PREFIX_RANGE: num2PoisonRound[num] += 1 #for num in PREFIX_RANGE: # logging.info('prefix_getPoisonings 184.164.%d.0/24 %s %s', num, num2PoisonSet[num]) wait_cmd(1800) '''
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) # get the livedb object: 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) #sys.stdout = open(opts.output, 'w') #sys.stderr = sys.stdout global num2PoisonCandidates num2PoisonCandidates = dict() for num in PREFIX_RANGE: num2PoisonCandidates[num] = list() global num2commonAS num2commonAS = dict() num2commonAS[241] = [101,73] num2commonAS[243] = [6939,2381] num2commonAS[245] = [174,2637] num2commonAS[247] = [7922,88] num2commonAS[249] = [209,2722,12148] global num2startPoisIdx num2startPoisIdx = dict() num2startPoisIdx[241] = 3 num2startPoisIdx[243] = 2 num2startPoisIdx[245] = 2 num2startPoisIdx[247] = 2 num2startPoisIdx[249] = 3 conn = sqlite3.connect('data/imc3.db') c = conn.cursor() global feeds feeds = ['rv', 'ftr'] global num2PoisonSet num2PoisonSet = dict() for num in PREFIX_RANGE: num2PoisonSet[num] = set() num2PoisonSet[num].add(47065) global num2BFSLevel num2BFSLevel = dict() for num in PREFIX_RANGE: num2BFSLevel[num] = 1 global num2PoisonRound num2PoisonRound = dict() for num in PREFIX_RANGE: num2PoisonRound[num] = 1 global pfxToLoc pfxToLoc = dict() for feed in feeds: pfxToLoc[feed] = api.get_prefix_to_locations(feed) i = 1 while (i < 5): for num in PREFIX_RANGE: getPoisonings(c,num) for num in PREFIX_RANGE: num2PoisonRound[num] += 1 i += 1 ''' while True: for num in PREFIX_RANGE: populateDB(c,num) conn.commit() #wait_cmd(1800) for num in PREFIX_RANGE: pfx = num2pfx[num] getPoisonings(c,num) pfx.poisonList(list(num2PoisonSet[num])) pfx.up() soft_reset(num2pfx) for num in PREFIX_RANGE: num2PoisonRound[num] += 1 #for num in PREFIX_RANGE: # logging.info('prefix_getPoisonings 184.164.%d.0/24 %s %s', num, num2PoisonSet[num]) wait_cmd(1800) ''' '''
optimizer=keras.optimizers.SGD(lr=args.lr, momentum=args.momentum), metrics=['accuracy']) model.fit(x_train, y_train, batch_size=batch_size, epochs=epochs, verbose=0, validation_data=(x_test, y_test), callbacks=[TuneCallback(reporter)]) if __name__ == '__main__': from helper import create_parser parser = create_parser() args = parser.parse_args() mnist.load_data() # we do this because it's not threadsafe import ray from ray import tune from ray.tune.async_hyperband import AsyncHyperBandScheduler ray.init() #ray.init(redis_address="localhost:6379") sched = AsyncHyperBandScheduler(time_attr="timesteps_total", reward_attr="mean_accuracy", max_t=400, grace_period=20) tune.register_trainable("train_mnist", lambda cfg, rprtr: train_mnist(args, cfg, rprtr))