コード例 #1
0
ファイル: as_viewer.py プロジェクト: FR4NK-W/scion-viz
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
コード例 #2
0
 def __init__(self, finished, addr):
     # We need the lib sciond here already.
     connector = lib_sciond.init(get_sciond_api_addr(addr))
     cs_info = lib_sciond.get_service_info(
         [ServiceType.CS], connector=connector)[ServiceType.CS]
     cs = cs_info.host_info(0)
     cs_addr = SCIONAddr.from_values(addr.isd_as, cs.ipv4() or cs.ipv6())
     self.cert_done = False
     super().__init__("", finished, addr, cs_addr, cs.p.port)
コード例 #3
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