pygui: added wrapper for throughput events, fixed sending nodes/links for configuration
This commit is contained in:
parent
77f6577bce
commit
a9a2fb8e46
3 changed files with 49 additions and 11 deletions
|
@ -12,9 +12,9 @@ from typing import TYPE_CHECKING, Dict, Iterable, List, Optional, Set, Tuple
|
||||||
|
|
||||||
import grpc
|
import grpc
|
||||||
|
|
||||||
from core.api.grpc import client
|
from core.api.grpc import client, core_pb2
|
||||||
from core.api.grpc.configservices_pb2 import ConfigService, ConfigServiceConfig
|
from core.api.grpc.configservices_pb2 import ConfigService, ConfigServiceConfig
|
||||||
from core.api.grpc.core_pb2 import CpuUsageEvent, Event, ThroughputsEvent
|
from core.api.grpc.core_pb2 import CpuUsageEvent, Event
|
||||||
from core.api.grpc.emane_pb2 import EmaneModelConfig
|
from core.api.grpc.emane_pb2 import EmaneModelConfig
|
||||||
from core.api.grpc.mobility_pb2 import MobilityConfig
|
from core.api.grpc.mobility_pb2 import MobilityConfig
|
||||||
from core.api.grpc.services_pb2 import NodeServiceData, ServiceConfig, ServiceFileConfig
|
from core.api.grpc.services_pb2 import NodeServiceData, ServiceConfig, ServiceFileConfig
|
||||||
|
@ -46,6 +46,7 @@ from core.gui.wrappers import (
|
||||||
Position,
|
Position,
|
||||||
SessionLocation,
|
SessionLocation,
|
||||||
SessionState,
|
SessionState,
|
||||||
|
ThroughputsEvent,
|
||||||
)
|
)
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
@ -275,7 +276,8 @@ class CoreClient:
|
||||||
CPU_USAGE_DELAY, self.handle_cpu_event
|
CPU_USAGE_DELAY, self.handle_cpu_event
|
||||||
)
|
)
|
||||||
|
|
||||||
def handle_throughputs(self, event: ThroughputsEvent) -> None:
|
def handle_throughputs(self, event: core_pb2.ThroughputsEvent) -> None:
|
||||||
|
event = ThroughputsEvent.from_proto(event)
|
||||||
if event.session_id != self.session_id:
|
if event.session_id != self.session_id:
|
||||||
logging.warning(
|
logging.warning(
|
||||||
"ignoring throughput event session(%s) current(%s)",
|
"ignoring throughput event session(%s) current(%s)",
|
||||||
|
@ -776,12 +778,9 @@ class CoreClient:
|
||||||
"""
|
"""
|
||||||
create nodes and links that have not been created yet
|
create nodes and links that have not been created yet
|
||||||
"""
|
"""
|
||||||
node_protos = [x.core_node for x in self.canvas_nodes.values()]
|
node_protos = [x.core_node.to_proto() for x in self.canvas_nodes.values()]
|
||||||
link_protos = [x.link for x in self.links.values()]
|
link_protos = [x.link.to_proto() for x in self.links.values()]
|
||||||
if self.state != SessionState.DEFINITION:
|
self.client.set_session_state(self.session_id, SessionState.DEFINITION.value)
|
||||||
self.client.set_session_state(self.session_id, SessionState.DEFINITION)
|
|
||||||
|
|
||||||
self.client.set_session_state(self.session_id, SessionState.DEFINITION)
|
|
||||||
for node_proto in node_protos:
|
for node_proto in node_protos:
|
||||||
response = self.client.add_node(self.session_id, node_proto)
|
response = self.client.add_node(self.session_id, node_proto)
|
||||||
logging.debug("create node: %s", response)
|
logging.debug("create node: %s", response)
|
||||||
|
|
|
@ -7,7 +7,6 @@ from typing import TYPE_CHECKING, Dict, List, Optional, Set, Tuple
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from PIL.ImageTk import PhotoImage
|
from PIL.ImageTk import PhotoImage
|
||||||
|
|
||||||
from core.api.grpc.core_pb2 import ThroughputsEvent
|
|
||||||
from core.gui.dialogs.shapemod import ShapeDialog
|
from core.gui.dialogs.shapemod import ShapeDialog
|
||||||
from core.gui.graph import tags
|
from core.gui.graph import tags
|
||||||
from core.gui.graph.edges import (
|
from core.gui.graph.edges import (
|
||||||
|
@ -23,7 +22,7 @@ from core.gui.graph.shape import Shape
|
||||||
from core.gui.graph.shapeutils import ShapeType, is_draw_shape, is_marker
|
from core.gui.graph.shapeutils import ShapeType, is_draw_shape, is_marker
|
||||||
from core.gui.images import ImageEnum, TypeToImage
|
from core.gui.images import ImageEnum, TypeToImage
|
||||||
from core.gui.nodeutils import NodeDraw, NodeUtils
|
from core.gui.nodeutils import NodeDraw, NodeUtils
|
||||||
from core.gui.wrappers import Interface, Link, LinkType, Node
|
from core.gui.wrappers import Interface, Link, LinkType, Node, ThroughputsEvent
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from core.gui.app import Application
|
from core.gui.app import Application
|
||||||
|
|
|
@ -68,6 +68,46 @@ class MessageType(Enum):
|
||||||
TTY = 64
|
TTY = 64
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class BridgeThroughput:
|
||||||
|
node_id: int
|
||||||
|
throughput: float
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_proto(cls, proto: core_pb2.BridgeThroughput) -> "BridgeThroughput":
|
||||||
|
return BridgeThroughput(node_id=proto.node_id, throughput=proto.throughput)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class InterfaceThroughput:
|
||||||
|
node_id: int
|
||||||
|
iface_id: int
|
||||||
|
throughput: float
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_proto(cls, proto: core_pb2.InterfaceThroughput) -> "InterfaceThroughput":
|
||||||
|
return InterfaceThroughput(
|
||||||
|
node_id=proto.node_id, iface_id=proto.iface_id, throughput=proto.throughput
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class ThroughputsEvent:
|
||||||
|
session_id: int
|
||||||
|
bridge_throughputs: List[BridgeThroughput]
|
||||||
|
iface_throughputs: List[InterfaceThroughput]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_proto(cls, proto: core_pb2.ThroughputsEvent) -> "ThroughputsEvent":
|
||||||
|
bridges = [BridgeThroughput.from_proto(x) for x in proto.bridge_throughputs]
|
||||||
|
ifaces = [InterfaceThroughput.from_proto(x) for x in proto.iface_throughputs]
|
||||||
|
return ThroughputsEvent(
|
||||||
|
session_id=proto.session_id,
|
||||||
|
bridge_throughputs=bridges,
|
||||||
|
iface_throughputs=ifaces,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class SessionLocation:
|
class SessionLocation:
|
||||||
x: float
|
x: float
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue