Ejemplo n.º 1
0
    def __init__(self, name, parent=None, enabled=True):
        super(RouterItem, self).__init__(parent)

        assert router_name.is_valid(name)
        self.name = name  # TODO: Use @property

        self._logger = logging.getLogger("RouterItem.router={0}".format(self.name))

        self.setFlag(QGraphicsItem.ItemIsMovable)
        self.setFlag(QGraphicsItem.ItemSendsGeometryChanges)
        self.setCacheMode(QGraphicsItem.DeviceCoordinateCache)
        self.setZValue(1)

        # Circle color.
        self.color = palette.palette[self.name]

        # Circle radius.
        self.radius = 5.0
        # Circle (width, height).
        self.size = QSizeF(2 * self.radius, 2 * self.radius)
        self.size_rect = QRectF(QPointF(-self.size.width() / 2.0, -self.size.height() / 2.0), self.size)

        self._last_paint_bounding_rect = QRectF(self.size_rect)

        # connected router -> link to it
        self._links = {}

        # packet -> protocol
        # self._packets_for_delivery = {}

        self._link_manager = RouterLinkManager()
        self._datagram_router = None
        self._service_manager = None
        self._rip_service_transmitter = None
        self._rip_service = None

        self.velocity = QPointF()
        self.max_mouse_move_velocity = 100

        self._drag_points = deque(maxlen=10)

        self._enabled = False
        self.hide()
        self._start_networking()

        self.enabled = enabled

        update_rate = 20  # frames per second
        self._timer_id = self.startTimer(int(1000.0 / update_rate))
Ejemplo n.º 2
0
    def __init__(self, name):
        super(Router, self).__init__()

        assert router_name.is_valid(name)
        self._name = name

        self._link_manager = RouterLinkManager()

        self._datagram_router = DatagramRouter(
            router_name=self._name,
            link_manager=self._link_manager)

        self._service_manager = RouterServiceManager(self._datagram_router)

        self._rip_service_transmitter = \
            self._service_manager.register_service(RIPService.protocol)

        self._rip_service = RIPService(self._name, self._link_manager,
            self._rip_service_transmitter)

        self._datagram_router.set_routing_table(
            self._rip_service.dynamic_routing_table())