Exemple #1
0
def print_as_topology(s_isd_as, connector):
    '''
    Print AS Topology data from lib.app.sciond.
    :param t: Array of ASInfo objects.
    :param i: Array of InterfaceInfo objects.
    :param s: Array of ServiceInfo objects.
    '''
    try:
        t = lib_sciond.get_as_info(connector=connector[s_isd_as])
        i = lib_sciond.get_if_info(connector=connector[s_isd_as])
        srvs = [ServiceType.BS, ServiceType.PS, ServiceType.CS]
        s = lib_sciond.get_service_info(srvs, connector=connector[s_isd_as])
    except (SCIONDResponseError) as err:
        logging.error("%s: %s" % (err.__class__.__name__, err))
        return
    for v in t:
        logging.info("----------------- AS TOPOLOGY: %s" % ISD_AS(v.p.isdas))
        logging.info("is_core_as: %s" % v.p.isCore)
        logging.info("mtu: %s" % v.p.mtu)
    for key in s:
        p_server_element(s[key])
    ridx = 1
    for key, v in i.items():
        p_router_element(v, ridx)
        ridx += 1
Exemple #2
0
 def _should_skip(self):
     if super()._should_skip():
         return True
     # Only run if the remote AS is a core AS.
     as_info = lib_sciond.get_as_info(self.dst.isd_as, self._connector)[0]
     if not as_info.p.isCore:
         logging.info("Skipping non-core remote AS")
         return True
     return False
Exemple #3
0
def print_as_viewer_info(addr):
    '''
    Attempt sciond connection if needed, and print requested AS data.
    :param addr: Optional IP Address for sciond socket binding when not
        localhost.
    '''
    try:
        # init connection to sciond
        conf_dir = "%s/%s/ISD%s/AS%s/endhost" % (
            SCION_ROOT, GEN_PATH, s_isd_as.isd_str(), s_isd_as.as_file_fmt())
        sock_file = get_default_sciond_path(s_isd_as)
        if not pathlib.Path(sock_file).exists():
            sock_file = get_default_sciond_path(None)
        connector[s_isd_as] = lib_sciond.init(sock_file)
        logging.info(connector[s_isd_as]._api_addr)
        try:  # test if sciond is already running for this AS
            logging.info("Starting sciond at %s" % sock_file)
            lib_sciond.get_as_info(connector=connector[s_isd_as])
        except (SCIONDResponseError) as err:
            logging.error("%s: %s" % (err.__class__.__name__, err))
            return
        except (SCIONDConnectionError, FileNotFoundError) as err:
            logging.warning("%s: %s" % (err.__class__.__name__, err))
            # need to launch sciond, wait for uptime
            launch_sciond(sock_file, conf_dir, addr, s_isd_as)
        if args.t:  # as topology
            print_as_topology(s_isd_as, connector)
        if args.p:  # announced paths
            print_paths(s_isd_as, d_isd_as, connector)
        if args.c:  # config
            print_yml(os.path.join(conf_dir, AS_CONF_FILE))
        if args.pp:  # path policy
            print_yml(os.path.join(conf_dir, PATH_POLICY_FILE))
        if args.trc:  # TRC
            print_json_files(findCerts(conf_dir, ".trc"))
        if args.crt:  # cert chain
            print_json_files(findCerts(conf_dir, ".crt"))
        if args.s:  # segments
            print_segments_summary(s_isd_as, connector)
    except (SCIONBaseError, AttributeError) as err:
        logging.error("%s: %s" % (err.__class__.__name__, err))
Exemple #4
0
 def _test_as_request_reply(self):
     try:
         entries = lib_sciond.get_as_info(connector=self._connector)
     except lib_sciond.SCIONDLibError as e:
         logging.error("An error occured: %s" % e)
         return False
     for entry in entries:
         if entry.isd_as() == self.addr.isd_as:
             logging.debug("Received correct AS reply.")
             return True
     logging.error("Wrong AS Reply received.")
     return False
Exemple #5
0
def index(request):
    '''
    Main index handler for index.html for main visualization page.
    Validates parameters, request scion data, returns formatted response.
    :param request: HTML request object containing url parameters.
    '''
    p = {}  # return param dictionary
    p['tab'] = set_param(request, 'tab', 'tab-pathtopo')
    p['data'] = set_param(request, 'data', 'sdapi')
    p['addr'] = set_param(request, 'addr', '')
    p['src'] = set_param(request, 'src', '')
    p['dst'] = set_param(request, 'dst', '')
    p['mp'] = set_param(request, 'mp', '5')
    p['err'] = ''
    if (p['src'] == '' and p['dst'] == ''):
        # use endhost gen/ia if no host specified
        if (p['src'] == ''):
            ia_file = "%s/%s/ia" % (SCION_ROOT, GEN_PATH)
            try:
                with open(ia_file, 'r') as fin:
                    # load and reformat
                    p['src'] = str(ISD_AS(fin.read().strip()))
            except (FileNotFoundError) as err:
                logging.warning("%s: %s" % (err.__class__.__name__, err))
        return fmt_err(request, p)
    s_isd_as = ISD_AS(p['src'])
    d_isd_as = ISD_AS(p['dst'])
    p['src'], p['dst'] = str(s_isd_as), str(d_isd_as)  # reformat
    csegs = dsegs = usegs = []
    paths = ''
    logging.info("Requesting sciond data from %s to %s" % (s_isd_as, d_isd_as))
    conf_dir = "%s/%s/ISD%s/AS%s/endhost" % (
        SCION_ROOT, GEN_PATH, s_isd_as.isd_str(), s_isd_as.as_file_fmt())
    sock_file = get_default_sciond_path(s_isd_as)
    if not pathlib.Path(sock_file).exists():
        sock_file = get_default_sciond_path(None)
    try:
        if (p['data'] == 'sdapi'):
            connector[s_isd_as] = lib_sciond.init(sock_file)
            logging.info(connector[s_isd_as]._api_addr)
            try:  # test if sciond is already running for this AS
                logging.info("Testing sciond at %s" % sock_file)
                lib_sciond.get_as_info(connector=connector[s_isd_as])
            except (SCIONDResponseError) as err:
                p['err'] = "%s: %s" % (err.__class__.__name__, err)
                return fmt_err(request, p)
            except (SCIONDConnectionError, FileNotFoundError) as err:
                logging.warning("%s: %s" % (err.__class__.__name__, err))
                # need to launch sciond, wait for uptime
                launch_sciond(sock_file, conf_dir, p['addr'], s_isd_as)

            if (p['dst'] != ''):  # PATHS
                try:
                    # get paths and keep segments
                    flags = lib_sciond.PathRequestFlags(flush=False,
                                                        sibra=False)
                    paths = lib_sciond.get_paths(d_isd_as,
                                                 max_paths=int(p['mp']),
                                                 flags=flags,
                                                 connector=connector[s_isd_as])
                    csegs = lib_sciond.get_segtype_hops(
                        PST.CORE, connector=connector[s_isd_as])
                    dsegs = lib_sciond.get_segtype_hops(
                        PST.DOWN, connector=connector[s_isd_as])
                    usegs = lib_sciond.get_segtype_hops(
                        PST.UP, connector=connector[s_isd_as])
                    # refresh old segments for next call
                    flags = lib_sciond.PathRequestFlags(flush=True,
                                                        sibra=False)
                    lib_sciond.get_paths(d_isd_as,
                                         max_paths=int(p['mp']),
                                         flags=flags,
                                         connector=connector[s_isd_as])
                except (SCIONDResponseError, SCIONDConnectionError,
                        AttributeError) as err:
                    # AttributeError handles backward-compatability
                    logging.error("%s: %s" % (err.__class__.__name__, err))
                    p['err'] = str(err)
            p['json_as_topo'] = json.dumps(
                get_json_as_topology_sciond(connector[s_isd_as], paths))
            p['json_trc'] = ("TRC information for sciond not yet implemented.")
            p['json_crt'] = (
                "Certificate information for sciond not yet implemented.")
        elif (p['data'] == 'file'):
            t = Topology.from_file(os.path.join(conf_dir, TOPO_FILE))
            topo = organize_topo(t)
            p['json_as_topo'] = json.dumps(get_json_as_topology(t, topo))
            p['json_trc'] = html_jsonfile(findCerts(conf_dir, ".trc"))
            p['json_crt'] = html_jsonfile(findCerts(conf_dir, ".crt"))
        p['path_info'] = get_as_view_html(paths, csegs, usegs, dsegs)
        p['json_path_topo'] = json.dumps(
            get_json_path_segs(paths, csegs, usegs, dsegs))
        p['json_seg_topo'] = json.dumps(
            get_json_all_segments(csegs, usegs, dsegs))
        p['json_paths'] = json.dumps(get_json_paths(paths))
    except (SCIONBaseError) as err:
        p['err'] = "%s: %s" % (err.__class__.__name__, err)
        return fmt_err(request, p)
    return render(request, 'asviz/index.html', p)
Exemple #6
0
def get_json_as_topology_sciond(connector, paths):
    '''
    Format all sciond AS topology data as a graph.
    Data comes from lib.app.sciond.
    '''
    nodes = []
    links = []
    try:
        logging.info("\n-------- SCIOND: AS Info")
        t = lib_sciond.get_as_info(connector=connector)
        for v in t:
            logging.debug(v.__dict__)
            isd_as = str(ISD_AS(v.p.isdas))
            nodes.append(get_root_as_node(isd_as, v.p.isCore, v.p.mtu))

        logging.info("\n-------- SCIOND: Interface Info")
        if_idx = 0
        i = lib_sciond.get_if_info(connector=connector)
        for key, v in i.items():
            logging.debug('%s: %s' % (key, v.__dict__))
            addr = v.p.hostInfo.addrs.ipv4
            port = v.p.hostInfo.port
            label = '%s-%s' % (ServiceType.BR, if_idx + 1)
            type = ServiceType.BR
            ifID = v.p.ifID
            nodes, links = json_append_router(nodes, links, isd_as, label,
                                              type, addr, port, ifID)

            # find any matching interfaces from paths
            if_id = v.p.ifID
            if_isd_as = "(%s)" % if_id
            for path in paths:
                match = False
                for interface in path.p.path.interfaces:
                    if match:
                        if_isd_as = "%s (%s)" % (ISD_AS(
                            interface.isdas), if_id)
                        break
                    if interface.ifID == v.p.ifID:
                        match = True

            link_type = "PARENT"
            nodes.append(get_json_interface_node_sciond(if_isd_as))
            links.append(get_json_interface_link(label, if_isd_as, link_type))
            if_idx += 1

        logging.info("\n-------- SCIOND: Service Info")
        srvs = [ServiceType.BS, ServiceType.PS, ServiceType.CS]
        v = lib_sciond.get_service_info(srvs, connector=connector)
        for key in v:
            logging.debug(v[key].__dict__)
            sidx = 0
            for hi in v[key].p.hostInfos:
                addr = hi.addrs.ipv4
                port = hi.port
                label = '%s-%s' % (v[key].p.serviceType, sidx + 1)
                type = str(v[key].p.serviceType)
                nodes, links = json_append_server(nodes, links, isd_as, label,
                                                  type, addr, port)
                sidx += 1

    except (SCIONDResponseError) as err:
        logging.error("%s: %s" % (err.__class__.__name__, err))

    graph = {}
    graph["nodes"] = nodes
    graph["links"] = links
    logging.debug(graph)
    return graph