#!/usr/bin/env python3 # Get topologies import sys from birdvisu.providers import BirdSocketTopologyProvider, OspfFileTopologyProvider ref_topo_file = 'reference.ospf' if len(sys.argv) > 1: ref_topo_file = sys.argv[1] ref_topo = OspfFileTopologyProvider(ref_topo_file).get_topology() try: cur_topo = BirdSocketTopologyProvider(instance='ospfv2', area=1).get_topology() except OSError as e: raise NotImplementedError('Cannot create a mock topology atm') from e # Create combined topology from birdvisu.topo_v3 import TopologyV3 combined_topology = TopologyV3.combine_topologies(reference=ref_topo, current=cur_topo) combined_topology.freeze() # Annotate it from birdvisu.topo_v3 import VertexID from birdvisu.annotations import AnnotatedTopology, AnnotatorID from birdvisu.annotations.analysis import TopologyDifference, ShortestPathTree from ipaddress import IPv4Address annot_topo = AnnotatedTopology(combined_topology) annotators = [ AnnotatorID(TopologyDifference), AnnotatorID(ShortestPathTree, (VertexID( family=None, is_router=True, address=None, router_id=int(IPv4Address('172.23.100.10')), dr_id=None, discriminator=None ), 'current')), ] for ann_id in annotators: annot_topo.run_annotator(ann_id) # --- # Show it from birdvisu.visualisation import annotators from birdvisu import maps_new # annotators.create_qgritems does not like being run without Qt initialization. from PySide6 import QtCore, QtGui, QtWidgets app = QtWidgets.QApplication([]) annotated_topology = maps_new.annotate_topology(combined_topology, # A semi-canonical set of annotators: [ annotators.extract_positions, annotators.random_position, annotators.assign_brushes, annotators.create_qgritems, ] ) # Render the widget scene = QtWidgets.QGraphicsScene() for tagsrc in [ annotated_topology.router_annotations.values(), annotated_topology.network_annotations.values(), annotated_topology.link_annotations.values(), ]: for taglist in tagsrc: assert len(taglist) > 0 assert isinstance(taglist[-1], QtWidgets.QGraphicsItem) scene.addItem(taglist[-1]) view = QtWidgets.QGraphicsView(scene) #view.show() main_window = QtWidgets.QMainWindow() main_window.setCentralWidget(view) menu = main_window.menuBar().addMenu('Hello') act = QtGui.QAction('Hi') #act.setToolTip('Howdy') menu.addAction(act) main_window.show() app.exec()