def handle_node_event(node_data: NodeData) -> core_pb2.Event: """ Handle node event when there is a node event :param node_data: node data :return: node event that contains node id, name, model, position, and services """ node = node_data.node x, y, _ = node.position.get() position = core_pb2.Position(x=x, y=y) lon, lat, alt = node.position.get_geo() geo = core_pb2.Geo(lon=lon, lat=lat, alt=alt) services = [x.name for x in node.services] node_proto = core_pb2.Node( id=node.id, name=node.name, model=node.type, icon=node.icon, position=position, geo=geo, services=services, ) message_type = node_data.message_type.value node_event = core_pb2.NodeEvent(message_type=message_type, node=node_proto) return core_pb2.Event(node_event=node_event, source=node_data.source)
def get_node_proto(session: Session, node: NodeBase) -> core_pb2.Node: """ Convert CORE node to protobuf representation. :param session: session containing node :param node: node to convert :return: node proto """ node_type = session.get_node_type(node.__class__) position = core_pb2.Position(x=node.position.x, y=node.position.y, z=node.position.z) geo = core_pb2.Geo(lat=node.position.lat, lon=node.position.lon, alt=node.position.alt) services = [x.name for x in node.services] model = node.type node_dir = None config_services = [] if isinstance(node, CoreNodeBase): node_dir = node.nodedir config_services = [x for x in node.config_services] channel = None if isinstance(node, CoreNode): channel = node.ctrlchnlname emane_model = None if isinstance(node, EmaneNet): emane_model = node.model.name image = None if isinstance(node, (DockerNode, LxcNode)): image = node.image return core_pb2.Node( id=node.id, name=node.name, emane=emane_model, model=model, type=node_type.value, position=position, geo=geo, services=services, icon=node.icon, image=image, config_services=config_services, dir=node_dir, channel=channel, canvas=node.canvas, )
def get_node_proto(session: Session, node: NodeBase) -> core_pb2.Node: """ Convert CORE node to protobuf representation. :param session: session containing node :param node: node to convert :return: node proto """ node_type = session.get_node_type(node.__class__) position = core_pb2.Position(x=node.position.x, y=node.position.y, z=node.position.z) geo = core_pb2.Geo(lat=node.position.lat, lon=node.position.lon, alt=node.position.alt) services = getattr(node, "services", []) if services is None: services = [] services = [x.name for x in services] config_services = getattr(node, "config_services", {}) config_services = [x for x in config_services] emane_model = None if isinstance(node, EmaneNet): emane_model = node.model.name model = getattr(node, "type", None) node_dir = getattr(node, "nodedir", None) channel = getattr(node, "ctrlchnlname", None) image = getattr(node, "image", None) return core_pb2.Node( id=node.id, name=node.name, emane=emane_model, model=model, type=node_type.value, position=position, geo=geo, services=services, icon=node.icon, image=image, config_services=config_services, dir=node_dir, channel=channel, )
def handle_node_event(event: NodeData) -> core_pb2.NodeEvent: """ Handle node event when there is a node event :param event: node data :return: node event that contains node id, name, model, position, and services """ position = core_pb2.Position(x=event.x_position, y=event.y_position) geo = core_pb2.Geo(lat=event.latitude, lon=event.longitude, alt=event.altitude) node_proto = core_pb2.Node( id=event.id, name=event.name, model=event.model, position=position, geo=geo, services=event.services, ) return core_pb2.NodeEvent(node=node_proto, source=event.source)
def to_proto(self) -> core_pb2.Geo: return core_pb2.Geo(lat=self.lat, lon=self.lon, alt=self.alt)
def move_iter(): yield core_pb2.MoveNodesRequest( session_id=session.id, node_id=node.id, geo=core_pb2.Geo(lon=lon, lat=lat, alt=alt), )
def get_node_proto(session: Session, node: NodeBase, emane_configs: List[NodeEmaneConfig]) -> core_pb2.Node: """ Convert CORE node to protobuf representation. :param session: session containing node :param node: node to convert :param emane_configs: emane configs related to node :return: node proto """ node_type = session.get_node_type(node.__class__) position = core_pb2.Position(x=node.position.x, y=node.position.y, z=node.position.z) geo = core_pb2.Geo(lat=node.position.lat, lon=node.position.lon, alt=node.position.alt) services = [x.name for x in node.services] model = node.type node_dir = None config_services = [] if isinstance(node, CoreNodeBase): node_dir = str(node.directory) config_services = [x for x in node.config_services] channel = None if isinstance(node, CoreNode): channel = str(node.ctrlchnlname) emane_model = None if isinstance(node, EmaneNet): emane_model = node.model.name image = None if isinstance(node, (DockerNode, LxcNode)): image = node.image # check for wlan config wlan_config = session.mobility.get_configs( node.id, config_type=BasicRangeModel.name) if wlan_config: wlan_config = get_config_options(wlan_config, BasicRangeModel) # check for mobility config mobility_config = session.mobility.get_configs( node.id, config_type=Ns2ScriptedMobility.name) if mobility_config: mobility_config = get_config_options(mobility_config, Ns2ScriptedMobility) # check for service configs custom_services = session.services.custom_services.get(node.id) service_configs = {} if custom_services: for service in custom_services.values(): service_proto = get_service_configuration(service) service_configs[service.name] = NodeServiceConfig( node_id=node.id, service=service.name, data=service_proto, files=service.config_data, ) # check for config service configs config_service_configs = {} if isinstance(node, CoreNode): for service in node.config_services.values(): if not service.custom_templates and not service.custom_config: continue config_service_configs[service.name] = ConfigServiceConfig( node_id=node.id, name=service.name, templates=service.custom_templates, config=service.custom_config, ) return core_pb2.Node( id=node.id, name=node.name, emane=emane_model, model=model, type=node_type.value, position=position, geo=geo, services=services, icon=node.icon, image=image, config_services=config_services, dir=node_dir, channel=channel, canvas=node.canvas, wlan_config=wlan_config, mobility_config=mobility_config, service_configs=service_configs, config_service_configs=config_service_configs, emane_configs=emane_configs, )