Ejemplo n.º 1
0
# asn-filter.py:  Get info about ASNs from graphs file
#                   i.e. makes asngraphs files
#
# Copyright 2017, Nevil Brownlee,  U Auckland | RIPE NCC

import dgs_ld
import timebins
import sys, datetime, string, os.path
import codecs

import config as c

reqd_ymds = []
reqd_msms = []
pp_names = "y! m! mxd= mntr="  # indexes 0 to 3
pp_ix, pp_values = c.set_pp(pp_names)  # Set up config info
mx_depth = c.draw_mx_depth  # Default paremeters for drawing
mn_trpkts = c.draw_mn_trpkts
for n, ix in enumerate(pp_ix):
    if ix == 0:  # y  (yyyymmdd) dates
        reqd_ymds = c.check_ymds(pp_values[n])
    elif ix == 1:  # m  (50xx) msm_ids
        reqd_msms = c.check_msm_ids(pp_values[n])
    elif ix == 2:  # mxd  specify max depth
        mx_depth = pp_values[n]
    elif ix == 3:  # mntr  specify min trpkts
        mn_trpkts = pp_values[n]
    else:
        exit()
if len(reqd_ymds) == 0:
    reqd_ymds = [c.start_ymd]
# 1620, Sat 11 Jan 2020 (NZDT)
# 1520, Wed 10 Jul 2019 (NZST)
#
# make-combined-asns-file.py  # Makes single asns file for all msm_ids
#
# Copyright 2020, Nevil Brownlee,  U Auckland | RIPE NCC

import sys, datetime, string, os, glob

import config as c

pp_ix, pp_values = c.set_pp("")  # Set up config info (no + params)

enf, nntb = c.find_msm_files("asns", c.start_ymd)
print("enf = %s" % enf)
for gfn in enf:
    fna = gfn.split("-")
    msm_id = int(fna[1]);  n_bins = int(fna[-1].split(".")[0])
    print("  msm_id = %d, n_bins = %s" % (msm_id, n_bins))
    if n_bins != c.n_bins:
        print("*** Inconsistent nbr of timebins (%d != %d)" % (
            n_bins, c.n_bins))

asn_dir = {}  # Dictionary  IPprefix -> ASN

for fn in enf:
    print(fn)
    asnsf = open(fn, 'r', encoding='utf-8')
    for line in asnsf:
        la = line.strip().split()
        ip_addr = la[0];  asn = la[1]