def print_paths(s_isd_as, d_isd_as, connector): ''' Print AS announced paths data from lib.app.sciond. :param paths: Array of PathInfo objects. ''' flags = lib_sciond.PathRequestFlags(flush=False, sibra=False) try: paths = lib_sciond.get_paths(d_isd_as, flags=flags, connector=connector[s_isd_as]) except (SCIONDResponseError) as err: logging.error("%s: %s" % (err.__class__.__name__, err)) return i = 1 # enumerate all paths for path in paths: logging.info("----------------- PATH %s" % i) logging.info("MTU: %s" % path.p.path.mtu) logging.info("IPV4: %s" % HostAddrIPv4(path.p.hostInfo.addrs.ipv4)) logging.info("Port: %s" % path.p.hostInfo.port) logging.info("Hops: %i" % (len(path.p.path.interfaces) / 2)) # enumerate path interfaces for interface in path.p.path.interfaces: isd_as = ISD_AS(interface.isdas) link = interface.ifID logging.info("%s (%s)" % (str(isd_as), link)) i += 1
def _get_path_via_api(self, isd_as, flush=False): flags = lib_sciond.PathRequestFlags(flush=flush) start = time.time() while time.time() - start < API_TOUT: try: path_entries = lib_sciond.get_paths(isd_as, flags=flags) except lib_sciond.SCIONDLibError as e: logging.error("Error during path lookup: %s" % e) continue if path_entries: return path_entries[0].path() logging.warning("Unable to get path to %s from local api.", isd_as) return None
def _try_sciond_api(self, flush=False): flags = lib_sciond.PathRequestFlags(flush=flush) start = time.time() while time.time() - start < API_TOUT: try: path_entries = lib_sciond.get_paths(self.dst.isd_as, flags=flags, connector=self._connector) except lib_sciond.SCIONDConnectionError as e: logging.error("Connection to SCIOND failed: %s " % e) break except lib_sciond.SCIONDLibError as e: logging.error("Error during path lookup: %s" % e) continue return path_entries logging.critical("Unable to get path from local api.") kill_self()
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)