updates to python based logging to use module named loggers, updated logging config file to align with these changes
This commit is contained in:
parent
55d5bb3859
commit
69652ac577
63 changed files with 717 additions and 606 deletions
|
@ -94,6 +94,8 @@ from core.api.grpc.wlan_pb2 import (
|
|||
)
|
||||
from core.emulator.data import IpPrefixes
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class InterfaceHelper:
|
||||
"""
|
||||
|
@ -147,9 +149,9 @@ def stream_listener(stream: Any, handler: Callable[[core_pb2.Event], None]) -> N
|
|||
handler(event)
|
||||
except grpc.RpcError as e:
|
||||
if e.code() == grpc.StatusCode.CANCELLED:
|
||||
logging.debug("stream closed")
|
||||
logger.debug("stream closed")
|
||||
else:
|
||||
logging.exception("stream error")
|
||||
logger.exception("stream error")
|
||||
|
||||
|
||||
def start_streamer(stream: Any, handler: Callable[[core_pb2.Event], None]) -> None:
|
||||
|
|
|
@ -70,6 +70,8 @@ from core.api.grpc.wrappers import Hook
|
|||
from core.emulator.data import IpPrefixes
|
||||
from core.errors import CoreError
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class MoveNodesStreamer:
|
||||
def __init__(self, session_id: int = None, source: str = None) -> None:
|
||||
|
@ -184,9 +186,9 @@ def throughput_listener(
|
|||
handler(event)
|
||||
except grpc.RpcError as e:
|
||||
if e.code() == grpc.StatusCode.CANCELLED:
|
||||
logging.debug("throughput stream closed")
|
||||
logger.debug("throughput stream closed")
|
||||
else:
|
||||
logging.exception("throughput stream error")
|
||||
logger.exception("throughput stream error")
|
||||
|
||||
|
||||
def cpu_listener(
|
||||
|
@ -205,9 +207,9 @@ def cpu_listener(
|
|||
handler(event)
|
||||
except grpc.RpcError as e:
|
||||
if e.code() == grpc.StatusCode.CANCELLED:
|
||||
logging.debug("cpu stream closed")
|
||||
logger.debug("cpu stream closed")
|
||||
else:
|
||||
logging.exception("cpu stream error")
|
||||
logger.exception("cpu stream error")
|
||||
|
||||
|
||||
def event_listener(stream: Any, handler: Callable[[wrappers.Event], None]) -> None:
|
||||
|
@ -224,9 +226,9 @@ def event_listener(stream: Any, handler: Callable[[wrappers.Event], None]) -> No
|
|||
handler(event)
|
||||
except grpc.RpcError as e:
|
||||
if e.code() == grpc.StatusCode.CANCELLED:
|
||||
logging.debug("session stream closed")
|
||||
logger.debug("session stream closed")
|
||||
else:
|
||||
logging.exception("session stream error")
|
||||
logger.exception("session stream error")
|
||||
|
||||
|
||||
class CoreGrpcClient:
|
||||
|
|
|
@ -14,6 +14,8 @@ from core.emulator.data import (
|
|||
)
|
||||
from core.emulator.session import Session
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def handle_node_event(node_data: NodeData) -> core_pb2.Event:
|
||||
"""
|
||||
|
@ -199,7 +201,7 @@ class EventStreamer:
|
|||
elif isinstance(data, FileData):
|
||||
event = handle_file_event(data)
|
||||
else:
|
||||
logging.error("unknown event: %s", data)
|
||||
logger.error("unknown event: %s", data)
|
||||
except Empty:
|
||||
pass
|
||||
if event:
|
||||
|
|
|
@ -31,6 +31,7 @@ from core.nodes.lxd import LxcNode
|
|||
from core.nodes.network import WlanNode
|
||||
from core.services.coreservices import CoreService
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
WORKERS = 10
|
||||
|
||||
|
||||
|
@ -156,7 +157,7 @@ def create_nodes(
|
|||
start = time.monotonic()
|
||||
results, exceptions = utils.threadpool(funcs)
|
||||
total = time.monotonic() - start
|
||||
logging.debug("grpc created nodes time: %s", total)
|
||||
logger.debug("grpc created nodes time: %s", total)
|
||||
return results, exceptions
|
||||
|
||||
|
||||
|
@ -180,7 +181,7 @@ def create_links(
|
|||
start = time.monotonic()
|
||||
results, exceptions = utils.threadpool(funcs)
|
||||
total = time.monotonic() - start
|
||||
logging.debug("grpc created links time: %s", total)
|
||||
logger.debug("grpc created links time: %s", total)
|
||||
return results, exceptions
|
||||
|
||||
|
||||
|
@ -204,7 +205,7 @@ def edit_links(
|
|||
start = time.monotonic()
|
||||
results, exceptions = utils.threadpool(funcs)
|
||||
total = time.monotonic() - start
|
||||
logging.debug("grpc edit links time: %s", total)
|
||||
logger.debug("grpc edit links time: %s", total)
|
||||
return results, exceptions
|
||||
|
||||
|
||||
|
|
|
@ -116,6 +116,7 @@ from core.nodes.base import CoreNode, NodeBase
|
|||
from core.nodes.network import CtrlNet, PtpNet, WlanNode
|
||||
from core.services.coreservices import ServiceManager
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
_ONE_DAY_IN_SECONDS: int = 60 * 60 * 24
|
||||
_INTERFACE_REGEX: Pattern = re.compile(r"veth(?P<node>[0-9a-fA-F]+)")
|
||||
_MAX_WORKERS = 1000
|
||||
|
@ -136,7 +137,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
atexit.register(self._exit_handler)
|
||||
|
||||
def _exit_handler(self) -> None:
|
||||
logging.debug("catching exit, stop running")
|
||||
logger.debug("catching exit, stop running")
|
||||
self.running = False
|
||||
|
||||
def _is_running(self, context) -> bool:
|
||||
|
@ -146,7 +147,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
context.abort(grpc.StatusCode.CANCELLED, "server stopping")
|
||||
|
||||
def listen(self, address: str) -> None:
|
||||
logging.info("CORE gRPC API listening on: %s", address)
|
||||
logger.info("CORE gRPC API listening on: %s", address)
|
||||
self.server = grpc.server(futures.ThreadPoolExecutor(max_workers=_MAX_WORKERS))
|
||||
core_pb2_grpc.add_CoreApiServicer_to_server(self, self.server)
|
||||
self.server.add_insecure_port(address)
|
||||
|
@ -217,7 +218,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: grpc context
|
||||
:return: start session response
|
||||
"""
|
||||
logging.debug("start session: %s", request)
|
||||
logger.debug("start session: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
|
||||
# clear previous state and setup for creation
|
||||
|
@ -313,7 +314,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: grpc context
|
||||
:return: stop session response
|
||||
"""
|
||||
logging.debug("stop session: %s", request)
|
||||
logger.debug("stop session: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
session.data_collect()
|
||||
session.shutdown()
|
||||
|
@ -329,7 +330,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context:
|
||||
:return: a create-session response
|
||||
"""
|
||||
logging.debug("create session: %s", request)
|
||||
logger.debug("create session: %s", request)
|
||||
session = self.coreemu.create_session(request.session_id)
|
||||
session.set_state(EventTypes.DEFINITION_STATE)
|
||||
session.location.setrefgeo(47.57917, -122.13232, 2.0)
|
||||
|
@ -348,7 +349,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: a delete-session response
|
||||
"""
|
||||
logging.debug("delete session: %s", request)
|
||||
logger.debug("delete session: %s", request)
|
||||
result = self.coreemu.delete_session(request.session_id)
|
||||
return core_pb2.DeleteSessionResponse(result=result)
|
||||
|
||||
|
@ -362,7 +363,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: a delete-session response
|
||||
"""
|
||||
logging.debug("get sessions: %s", request)
|
||||
logger.debug("get sessions: %s", request)
|
||||
sessions = []
|
||||
for session_id in self.coreemu.sessions:
|
||||
session = self.coreemu.sessions[session_id]
|
||||
|
@ -387,7 +388,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: a get-session-location response
|
||||
"""
|
||||
logging.debug("get session location: %s", request)
|
||||
logger.debug("get session location: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
x, y, z = session.location.refxyz
|
||||
lat, lon, alt = session.location.refgeo
|
||||
|
@ -407,7 +408,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: a set-session-location-response
|
||||
"""
|
||||
logging.debug("set session location: %s", request)
|
||||
logger.debug("set session location: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
grpcutils.session_location(session, request.location)
|
||||
return core_pb2.SetSessionLocationResponse(result=True)
|
||||
|
@ -422,7 +423,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context:context object
|
||||
:return: set-session-state response
|
||||
"""
|
||||
logging.debug("set session state: %s", request)
|
||||
logger.debug("set session state: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
try:
|
||||
state = EventTypes(request.state)
|
||||
|
@ -451,7 +452,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: set session user response
|
||||
"""
|
||||
logging.debug("set session user: %s", request)
|
||||
logger.debug("set session user: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
session.user = request.user
|
||||
return core_pb2.SetSessionUserResponse(result=True)
|
||||
|
@ -467,7 +468,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: get-session-options response about all session's options
|
||||
"""
|
||||
logging.debug("get session options: %s", request)
|
||||
logger.debug("get session options: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
current_config = session.options.get_configs()
|
||||
default_config = session.options.default_values()
|
||||
|
@ -485,7 +486,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: set-session-options response
|
||||
"""
|
||||
logging.debug("set session options: %s", request)
|
||||
logger.debug("set session options: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
config = session.options.get_configs()
|
||||
config.update(request.config)
|
||||
|
@ -502,7 +503,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: get session metadata response
|
||||
"""
|
||||
logging.debug("get session metadata: %s", request)
|
||||
logger.debug("get session metadata: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
return core_pb2.GetSessionMetadataResponse(config=session.metadata)
|
||||
|
||||
|
@ -516,7 +517,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: set metadata response
|
||||
"""
|
||||
logging.debug("set session metadata: %s", request)
|
||||
logger.debug("set session metadata: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
session.metadata = dict(request.config)
|
||||
return core_pb2.SetSessionMetadataResponse(result=True)
|
||||
|
@ -544,7 +545,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: get-session response
|
||||
"""
|
||||
logging.debug("get session: %s", request)
|
||||
logger.debug("get session: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
links = []
|
||||
nodes = []
|
||||
|
@ -718,7 +719,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: add-node response
|
||||
"""
|
||||
logging.debug("add node: %s", request)
|
||||
logger.debug("add node: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
_type, _id, options = grpcutils.add_node_data(request.node)
|
||||
_class = session.get_node_class(_type)
|
||||
|
@ -737,7 +738,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: get-node response
|
||||
"""
|
||||
logging.debug("get node: %s", request)
|
||||
logger.debug("get node: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
node = self.get_node(session, request.node_id, context, NodeBase)
|
||||
ifaces = []
|
||||
|
@ -768,7 +769,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
options = NodeOptions()
|
||||
has_geo = request.HasField("geo")
|
||||
if has_geo:
|
||||
logging.info("has geo")
|
||||
logger.info("has geo")
|
||||
lat = request.geo.lat
|
||||
lon = request.geo.lon
|
||||
alt = request.geo.alt
|
||||
|
@ -776,7 +777,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
else:
|
||||
x = request.position.x
|
||||
y = request.position.y
|
||||
logging.info("has pos: %s,%s", x, y)
|
||||
logger.info("has pos: %s,%s", x, y)
|
||||
options.set_position(x, y)
|
||||
session.edit_node(node.id, options)
|
||||
source = request.source if request.source else None
|
||||
|
@ -794,7 +795,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: edit-node response
|
||||
"""
|
||||
logging.debug("edit node: %s", request)
|
||||
logger.debug("edit node: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
node = self.get_node(session, request.node_id, context, NodeBase)
|
||||
options = NodeOptions(icon=request.icon)
|
||||
|
@ -830,7 +831,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: core.api.grpc.core_pb2.DeleteNodeResponse
|
||||
"""
|
||||
logging.debug("delete node: %s", request)
|
||||
logger.debug("delete node: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
result = False
|
||||
if request.node_id in session.nodes:
|
||||
|
@ -850,7 +851,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: core.api.grpc.core_pb2.NodeCommandResponse
|
||||
"""
|
||||
logging.debug("sending node command: %s", request)
|
||||
logger.debug("sending node command: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
node = self.get_node(session, request.node_id, context, CoreNode)
|
||||
try:
|
||||
|
@ -871,7 +872,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: get-node-terminal response
|
||||
"""
|
||||
logging.debug("getting node terminal: %s", request)
|
||||
logger.debug("getting node terminal: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
node = self.get_node(session, request.node_id, context, CoreNode)
|
||||
terminal = node.termcmdstring("/bin/bash")
|
||||
|
@ -887,7 +888,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: get-node-links response
|
||||
"""
|
||||
logging.debug("get node links: %s", request)
|
||||
logger.debug("get node links: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
node = self.get_node(session, request.node_id, context, NodeBase)
|
||||
links = get_links(node)
|
||||
|
@ -903,7 +904,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: add-link response
|
||||
"""
|
||||
logging.debug("add link: %s", request)
|
||||
logger.debug("add link: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
node1_id = request.link.node1_id
|
||||
node2_id = request.link.node2_id
|
||||
|
@ -952,7 +953,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: edit-link response
|
||||
"""
|
||||
logging.debug("edit link: %s", request)
|
||||
logger.debug("edit link: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
node1_id = request.node1_id
|
||||
node2_id = request.node2_id
|
||||
|
@ -998,7 +999,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: delete-link response
|
||||
"""
|
||||
logging.debug("delete link: %s", request)
|
||||
logger.debug("delete link: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
node1_id = request.node1_id
|
||||
node2_id = request.node2_id
|
||||
|
@ -1029,7 +1030,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: get-hooks response about all the hooks in all session states
|
||||
"""
|
||||
logging.debug("get hooks: %s", request)
|
||||
logger.debug("get hooks: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
hooks = grpcutils.get_hooks(session)
|
||||
return core_pb2.GetHooksResponse(hooks=hooks)
|
||||
|
@ -1044,7 +1045,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: add-hook response
|
||||
"""
|
||||
logging.debug("add hook: %s", request)
|
||||
logger.debug("add hook: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
hook = request.hook
|
||||
state = EventTypes(hook.state)
|
||||
|
@ -1062,7 +1063,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: get-mobility-configurations response that has a list of configurations
|
||||
"""
|
||||
logging.debug("get mobility configs: %s", request)
|
||||
logger.debug("get mobility configs: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
configs = grpcutils.get_mobility_configs(session)
|
||||
return GetMobilityConfigsResponse(configs=configs)
|
||||
|
@ -1078,7 +1079,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: get-mobility-configuration response
|
||||
"""
|
||||
logging.debug("get mobility config: %s", request)
|
||||
logger.debug("get mobility config: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
current_config = session.mobility.get_model_config(
|
||||
request.node_id, Ns2ScriptedMobility.name
|
||||
|
@ -1097,7 +1098,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: set-mobility-configuration response
|
||||
"""
|
||||
logging.debug("set mobility config: %s", request)
|
||||
logger.debug("set mobility config: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
mobility_config = request.mobility_config
|
||||
session.mobility.set_model_config(
|
||||
|
@ -1116,7 +1117,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: mobility-action response
|
||||
"""
|
||||
logging.debug("mobility action: %s", request)
|
||||
logger.debug("mobility action: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
node = grpcutils.get_mobility_node(session, request.node_id, context)
|
||||
if not node.mobility:
|
||||
|
@ -1144,7 +1145,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: get-services response
|
||||
"""
|
||||
logging.debug("get services: %s", request)
|
||||
logger.debug("get services: %s", request)
|
||||
services = []
|
||||
for name in ServiceManager.services:
|
||||
service = ServiceManager.services[name]
|
||||
|
@ -1162,7 +1163,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: get-service-defaults response about all the available default services
|
||||
"""
|
||||
logging.debug("get service defaults: %s", request)
|
||||
logger.debug("get service defaults: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
defaults = grpcutils.get_default_services(session)
|
||||
return GetServiceDefaultsResponse(defaults=defaults)
|
||||
|
@ -1177,7 +1178,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: set-service-defaults response
|
||||
"""
|
||||
logging.debug("set service defaults: %s", request)
|
||||
logger.debug("set service defaults: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
session.services.default_services.clear()
|
||||
for service_defaults in request.defaults:
|
||||
|
@ -1197,7 +1198,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: all node service configs response
|
||||
"""
|
||||
logging.debug("get node service configs: %s", request)
|
||||
logger.debug("get node service configs: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
configs = grpcutils.get_node_service_configs(session)
|
||||
return GetNodeServiceConfigsResponse(configs=configs)
|
||||
|
@ -1213,7 +1214,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: get-node-service response about the requested service
|
||||
"""
|
||||
logging.debug("get node service: %s", request)
|
||||
logger.debug("get node service: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
service = session.services.get_service(
|
||||
request.node_id, request.service, default_service=True
|
||||
|
@ -1232,7 +1233,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: get-node-service response about the requested service
|
||||
"""
|
||||
logging.debug("get node service file: %s", request)
|
||||
logger.debug("get node service file: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
node = self.get_node(session, request.node_id, context, CoreNode)
|
||||
file_data = session.services.get_service_file(
|
||||
|
@ -1251,7 +1252,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: set-node-service response
|
||||
"""
|
||||
logging.debug("set node service: %s", request)
|
||||
logger.debug("set node service: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
config = request.config
|
||||
grpcutils.service_configuration(session, config)
|
||||
|
@ -1268,7 +1269,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: set-node-service-file response
|
||||
"""
|
||||
logging.debug("set node service file: %s", request)
|
||||
logger.debug("set node service file: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
config = request.config
|
||||
session.services.set_service_file(
|
||||
|
@ -1287,7 +1288,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: service-action response about status of action
|
||||
"""
|
||||
logging.debug("service action: %s", request)
|
||||
logger.debug("service action: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
node = self.get_node(session, request.node_id, context, CoreNode)
|
||||
service = None
|
||||
|
@ -1327,7 +1328,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: core.api.grpc.core_pb2.GetWlanConfigResponse
|
||||
:return: all wlan configurations
|
||||
"""
|
||||
logging.debug("get wlan configs: %s", request)
|
||||
logger.debug("get wlan configs: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
configs = grpcutils.get_wlan_configs(session)
|
||||
return GetWlanConfigsResponse(configs=configs)
|
||||
|
@ -1342,7 +1343,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: core.api.grpc.core_pb2.GetWlanConfigResponse
|
||||
:return: get-wlan-configuration response about the wlan configuration of a node
|
||||
"""
|
||||
logging.debug("get wlan config: %s", request)
|
||||
logger.debug("get wlan config: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
current_config = session.mobility.get_model_config(
|
||||
request.node_id, BasicRangeModel.name
|
||||
|
@ -1360,7 +1361,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: set-wlan-configuration response
|
||||
"""
|
||||
logging.debug("set wlan config: %s", request)
|
||||
logger.debug("set wlan config: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
node_id = request.wlan_config.node_id
|
||||
config = request.wlan_config.config
|
||||
|
@ -1380,7 +1381,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: get-EMANE-configuration response
|
||||
"""
|
||||
logging.debug("get emane config: %s", request)
|
||||
logger.debug("get emane config: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
config = grpcutils.get_emane_config(session)
|
||||
return GetEmaneConfigResponse(config=config)
|
||||
|
@ -1395,7 +1396,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: set-EMANE-configuration response
|
||||
"""
|
||||
logging.debug("set emane config: %s", request)
|
||||
logger.debug("set emane config: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
config = session.emane.get_configs()
|
||||
config.update(request.config)
|
||||
|
@ -1411,7 +1412,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: get-EMANE-models response that has all the models
|
||||
"""
|
||||
logging.debug("get emane models: %s", request)
|
||||
logger.debug("get emane models: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
models = grpcutils.get_emane_models(session)
|
||||
return GetEmaneModelsResponse(models=models)
|
||||
|
@ -1427,7 +1428,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: get-EMANE-model-configuration response
|
||||
"""
|
||||
logging.debug("get emane model config: %s", request)
|
||||
logger.debug("get emane model config: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
model = session.emane.models.get(request.model)
|
||||
if not model:
|
||||
|
@ -1448,7 +1449,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: set-EMANE-model-configuration response
|
||||
"""
|
||||
logging.debug("set emane model config: %s", request)
|
||||
logger.debug("set emane model config: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
model_config = request.emane_model_config
|
||||
_id = utils.iface_config_id(model_config.node_id, model_config.iface_id)
|
||||
|
@ -1467,7 +1468,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:return: get-EMANE-model-configurations response that has all the EMANE
|
||||
configurations
|
||||
"""
|
||||
logging.debug("get emane model configs: %s", request)
|
||||
logger.debug("get emane model configs: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
configs = grpcutils.get_emane_model_configs(session)
|
||||
return GetEmaneModelConfigsResponse(configs=configs)
|
||||
|
@ -1482,7 +1483,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: save-xml response
|
||||
"""
|
||||
logging.debug("save xml: %s", request)
|
||||
logger.debug("save xml: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
|
||||
_, temp_path = tempfile.mkstemp()
|
||||
|
@ -1503,7 +1504,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: Open-XML response or raise an exception if invalid XML file
|
||||
"""
|
||||
logging.debug("open xml: %s", request)
|
||||
logger.debug("open xml: %s", request)
|
||||
session = self.coreemu.create_session()
|
||||
temp = tempfile.NamedTemporaryFile(delete=False)
|
||||
temp.write(request.data.encode("utf-8"))
|
||||
|
@ -1516,7 +1517,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
session.file_path = file_path
|
||||
return core_pb2.OpenXmlResponse(session_id=session.id, result=True)
|
||||
except IOError:
|
||||
logging.exception("error opening session file")
|
||||
logger.exception("error opening session file")
|
||||
self.coreemu.delete_session(session.id)
|
||||
context.abort(grpc.StatusCode.INVALID_ARGUMENT, "invalid xml file")
|
||||
finally:
|
||||
|
@ -1549,7 +1550,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
:param context: context object
|
||||
:return: emane link response with success status
|
||||
"""
|
||||
logging.debug("emane link: %s", request)
|
||||
logger.debug("emane link: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
nem1 = request.nem1
|
||||
iface1 = session.emane.get_iface(nem1)
|
||||
|
|
|
@ -55,6 +55,8 @@ from core.nodes.network import WlanNode
|
|||
from core.nodes.physical import Rj45Node
|
||||
from core.services.coreservices import ServiceManager, ServiceShim
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class CoreHandler(socketserver.BaseRequestHandler):
|
||||
"""
|
||||
|
@ -104,7 +106,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
|
||||
:return: nothing
|
||||
"""
|
||||
logging.debug("new TCP connection: %s", self.client_address)
|
||||
logger.debug("new TCP connection: %s", self.client_address)
|
||||
|
||||
def finish(self):
|
||||
"""
|
||||
|
@ -113,40 +115,40 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
|
||||
:return: nothing
|
||||
"""
|
||||
logging.debug("finishing request handler")
|
||||
logging.debug("remaining message queue size: %s", self.message_queue.qsize())
|
||||
logger.debug("finishing request handler")
|
||||
logger.debug("remaining message queue size: %s", self.message_queue.qsize())
|
||||
|
||||
# give some time for message queue to deplete
|
||||
timeout = 10
|
||||
wait = 0
|
||||
while not self.message_queue.empty():
|
||||
logging.debug("waiting for message queue to empty: %s seconds", wait)
|
||||
logger.debug("waiting for message queue to empty: %s seconds", wait)
|
||||
time.sleep(1)
|
||||
wait += 1
|
||||
if wait == timeout:
|
||||
logging.warning("queue failed to be empty, finishing request handler")
|
||||
logger.warning("queue failed to be empty, finishing request handler")
|
||||
break
|
||||
|
||||
logging.info("client disconnected: notifying threads")
|
||||
logger.info("client disconnected: notifying threads")
|
||||
self.done = True
|
||||
for thread in self.handler_threads:
|
||||
logging.info("waiting for thread: %s", thread.getName())
|
||||
logger.info("waiting for thread: %s", thread.getName())
|
||||
thread.join(timeout)
|
||||
if thread.is_alive():
|
||||
logging.warning(
|
||||
logger.warning(
|
||||
"joining %s failed: still alive after %s sec",
|
||||
thread.getName(),
|
||||
timeout,
|
||||
)
|
||||
|
||||
logging.info("connection closed: %s", self.client_address)
|
||||
logger.info("connection closed: %s", self.client_address)
|
||||
if self.session:
|
||||
# remove client from session broker and shutdown if there are no clients
|
||||
self.remove_session_handlers()
|
||||
clients = self.session_clients[self.session.id]
|
||||
clients.remove(self)
|
||||
if not clients and not self.session.is_active():
|
||||
logging.info(
|
||||
logger.info(
|
||||
"no session clients left and not active, initiating shutdown"
|
||||
)
|
||||
self.coreemu.delete_session(self.session.id)
|
||||
|
@ -218,7 +220,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
:param core.emulator.data.EventData event_data: event data to handle
|
||||
:return: nothing
|
||||
"""
|
||||
logging.debug("handling broadcast event: %s", event_data)
|
||||
logger.debug("handling broadcast event: %s", event_data)
|
||||
|
||||
tlv_data = structutils.pack_values(
|
||||
coreapi.CoreEventTlv,
|
||||
|
@ -236,7 +238,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
try:
|
||||
self.sendall(message)
|
||||
except IOError:
|
||||
logging.exception("error sending event message")
|
||||
logger.exception("error sending event message")
|
||||
|
||||
def handle_broadcast_file(self, file_data):
|
||||
"""
|
||||
|
@ -245,7 +247,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
:param core.emulator.data.FileData file_data: file data to handle
|
||||
:return: nothing
|
||||
"""
|
||||
logging.debug("handling broadcast file: %s", file_data)
|
||||
logger.debug("handling broadcast file: %s", file_data)
|
||||
|
||||
tlv_data = structutils.pack_values(
|
||||
coreapi.CoreFileTlv,
|
||||
|
@ -266,7 +268,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
try:
|
||||
self.sendall(message)
|
||||
except IOError:
|
||||
logging.exception("error sending file message")
|
||||
logger.exception("error sending file message")
|
||||
|
||||
def handle_broadcast_config(self, config_data):
|
||||
"""
|
||||
|
@ -275,12 +277,12 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
:param core.emulator.data.ConfigData config_data: config data to handle
|
||||
:return: nothing
|
||||
"""
|
||||
logging.debug("handling broadcast config: %s", config_data)
|
||||
logger.debug("handling broadcast config: %s", config_data)
|
||||
message = dataconversion.convert_config(config_data)
|
||||
try:
|
||||
self.sendall(message)
|
||||
except IOError:
|
||||
logging.exception("error sending config message")
|
||||
logger.exception("error sending config message")
|
||||
|
||||
def handle_broadcast_exception(self, exception_data):
|
||||
"""
|
||||
|
@ -289,7 +291,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
:param core.emulator.data.ExceptionData exception_data: exception data to handle
|
||||
:return: nothing
|
||||
"""
|
||||
logging.debug("handling broadcast exception: %s", exception_data)
|
||||
logger.debug("handling broadcast exception: %s", exception_data)
|
||||
tlv_data = structutils.pack_values(
|
||||
coreapi.CoreExceptionTlv,
|
||||
[
|
||||
|
@ -306,7 +308,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
try:
|
||||
self.sendall(message)
|
||||
except IOError:
|
||||
logging.exception("error sending exception message")
|
||||
logger.exception("error sending exception message")
|
||||
|
||||
def handle_broadcast_node(self, node_data):
|
||||
"""
|
||||
|
@ -315,12 +317,12 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
:param core.emulator.data.NodeData node_data: node data to handle
|
||||
:return: nothing
|
||||
"""
|
||||
logging.debug("handling broadcast node: %s", node_data)
|
||||
logger.debug("handling broadcast node: %s", node_data)
|
||||
message = dataconversion.convert_node(node_data)
|
||||
try:
|
||||
self.sendall(message)
|
||||
except IOError:
|
||||
logging.exception("error sending node message")
|
||||
logger.exception("error sending node message")
|
||||
|
||||
def handle_broadcast_link(self, link_data):
|
||||
"""
|
||||
|
@ -329,7 +331,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
:param core.emulator.data.LinkData link_data: link data to handle
|
||||
:return: nothing
|
||||
"""
|
||||
logging.debug("handling broadcast link: %s", link_data)
|
||||
logger.debug("handling broadcast link: %s", link_data)
|
||||
options_data = link_data.options
|
||||
loss = ""
|
||||
if options_data.loss is not None:
|
||||
|
@ -381,7 +383,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
try:
|
||||
self.sendall(message)
|
||||
except IOError:
|
||||
logging.exception("error sending Event Message")
|
||||
logger.exception("error sending Event Message")
|
||||
|
||||
def register(self):
|
||||
"""
|
||||
|
@ -389,7 +391,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
|
||||
:return: register message data
|
||||
"""
|
||||
logging.info(
|
||||
logger.info(
|
||||
"GUI has connected to session %d at %s", self.session.id, time.ctime()
|
||||
)
|
||||
tlv_data = b""
|
||||
|
@ -461,14 +463,14 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
header
|
||||
)
|
||||
if message_len == 0:
|
||||
logging.warning("received message with no data")
|
||||
logger.warning("received message with no data")
|
||||
|
||||
data = b""
|
||||
while len(data) < message_len:
|
||||
data += self.request.recv(message_len - len(data))
|
||||
if len(data) > message_len:
|
||||
error_message = f"received message length does not match received data ({len(data)} != {message_len})"
|
||||
logging.error(error_message)
|
||||
logger.error(error_message)
|
||||
raise IOError(error_message)
|
||||
|
||||
try:
|
||||
|
@ -477,7 +479,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
except KeyError:
|
||||
message = coreapi.CoreMessage(message_flags, header, data)
|
||||
message.message_type = message_type
|
||||
logging.exception("unimplemented core message type: %s", message.type_str())
|
||||
logger.exception("unimplemented core message type: %s", message.type_str())
|
||||
|
||||
return message
|
||||
|
||||
|
@ -488,7 +490,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
:param message: message to queue
|
||||
:return: nothing
|
||||
"""
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
"queueing msg (queuedtimes = %s): type %s",
|
||||
message.queuedtimes,
|
||||
MessageTypes(message.message_type),
|
||||
|
@ -518,11 +520,11 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
:param message: message to handle
|
||||
:return: nothing
|
||||
"""
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
"%s handling message:\n%s", threading.currentThread().getName(), message
|
||||
)
|
||||
if message.message_type not in self.message_handlers:
|
||||
logging.error("no handler for message type: %s", message.type_str())
|
||||
logger.error("no handler for message type: %s", message.type_str())
|
||||
return
|
||||
|
||||
message_handler = self.message_handlers[message.message_type]
|
||||
|
@ -532,7 +534,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
self.dispatch_replies(replies, message)
|
||||
except Exception as e:
|
||||
self.send_exception(ExceptionLevels.ERROR, "corehandler", str(e))
|
||||
logging.exception(
|
||||
logger.exception(
|
||||
"%s: exception while handling message: %s",
|
||||
threading.currentThread().getName(),
|
||||
message,
|
||||
|
@ -560,12 +562,12 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
# multiple TLVs of same type cause KeyError exception
|
||||
reply_message = f"CoreMessage (type {message_type} flags {message_flags} length {message_length})"
|
||||
|
||||
logging.debug("sending reply:\n%s", reply_message)
|
||||
logger.debug("sending reply:\n%s", reply_message)
|
||||
|
||||
try:
|
||||
self.sendall(reply)
|
||||
except IOError:
|
||||
logging.exception("error dispatching reply")
|
||||
logger.exception("error dispatching reply")
|
||||
|
||||
def handle(self):
|
||||
"""
|
||||
|
@ -580,7 +582,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
|
||||
# TODO: add shutdown handler for session
|
||||
self.session = self.coreemu.create_session(port)
|
||||
logging.debug("created new session for client: %s", self.session.id)
|
||||
logger.debug("created new session for client: %s", self.session.id)
|
||||
clients = self.session_clients.setdefault(self.session.id, [])
|
||||
clients.append(self)
|
||||
|
||||
|
@ -594,10 +596,10 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
try:
|
||||
message = self.receive_message()
|
||||
except EOFError:
|
||||
logging.info("client disconnected")
|
||||
logger.info("client disconnected")
|
||||
break
|
||||
except IOError:
|
||||
logging.exception("error receiving message")
|
||||
logger.exception("error receiving message")
|
||||
break
|
||||
|
||||
message.queuedtimes = 0
|
||||
|
@ -619,7 +621,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
if client == self:
|
||||
continue
|
||||
|
||||
logging.debug("BROADCAST TO OTHER CLIENT: %s", client)
|
||||
logger.debug("BROADCAST TO OTHER CLIENT: %s", client)
|
||||
client.sendall(message.raw_message)
|
||||
|
||||
def send_exception(self, level, source, text, node=None):
|
||||
|
@ -643,7 +645,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
self.handle_broadcast_exception(exception_data)
|
||||
|
||||
def add_session_handlers(self):
|
||||
logging.debug("adding session broadcast handlers")
|
||||
logger.debug("adding session broadcast handlers")
|
||||
self.session.event_handlers.append(self.handle_broadcast_event)
|
||||
self.session.exception_handlers.append(self.handle_broadcast_exception)
|
||||
self.session.node_handlers.append(self.handle_broadcast_node)
|
||||
|
@ -652,7 +654,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
self.session.config_handlers.append(self.handle_broadcast_config)
|
||||
|
||||
def remove_session_handlers(self):
|
||||
logging.debug("removing session broadcast handlers")
|
||||
logger.debug("removing session broadcast handlers")
|
||||
self.session.event_handlers.remove(self.handle_broadcast_event)
|
||||
self.session.exception_handlers.remove(self.handle_broadcast_exception)
|
||||
self.session.node_handlers.remove(self.handle_broadcast_node)
|
||||
|
@ -672,7 +674,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
message.flags & MessageFlags.ADD.value
|
||||
and message.flags & MessageFlags.DELETE.value
|
||||
):
|
||||
logging.warning("ignoring invalid message: add and delete flag both set")
|
||||
logger.warning("ignoring invalid message: add and delete flag both set")
|
||||
return ()
|
||||
|
||||
_class = CoreNode
|
||||
|
@ -898,7 +900,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
else:
|
||||
node.cmd(command, wait=False)
|
||||
except CoreError:
|
||||
logging.exception("error getting object: %s", node_id)
|
||||
logger.exception("error getting object: %s", node_id)
|
||||
# XXX wait and queue this message to try again later
|
||||
# XXX maybe this should be done differently
|
||||
if not message.flags & MessageFlags.LOCAL.value:
|
||||
|
@ -920,7 +922,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
execute_server = message.get_tlv(RegisterTlvs.EXECUTE_SERVER.value)
|
||||
if execute_server:
|
||||
try:
|
||||
logging.info("executing: %s", execute_server)
|
||||
logger.info("executing: %s", execute_server)
|
||||
if message.flags & MessageFlags.STRING.value:
|
||||
old_session_ids = set(self.coreemu.sessions.keys())
|
||||
sys.argv = shlex.split(execute_server)
|
||||
|
@ -946,26 +948,26 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
new_sid = new_session_ids.difference(old_session_ids)
|
||||
try:
|
||||
sid = new_sid.pop()
|
||||
logging.info("executed: %s as session %d", execute_server, sid)
|
||||
logger.info("executed: %s as session %d", execute_server, sid)
|
||||
except KeyError:
|
||||
logging.info(
|
||||
logger.info(
|
||||
"executed %s with unknown session ID", execute_server
|
||||
)
|
||||
return replies
|
||||
|
||||
logging.debug("checking session %d for RUNTIME state", sid)
|
||||
logger.debug("checking session %d for RUNTIME state", sid)
|
||||
session = self.coreemu.sessions.get(sid)
|
||||
retries = 10
|
||||
# wait for session to enter RUNTIME state, to prevent GUI from
|
||||
# connecting while nodes are still being instantiated
|
||||
while session.state != EventTypes.RUNTIME_STATE:
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
"waiting for session %d to enter RUNTIME state", sid
|
||||
)
|
||||
time.sleep(1)
|
||||
retries -= 1
|
||||
if retries <= 0:
|
||||
logging.debug("session %d did not enter RUNTIME state", sid)
|
||||
logger.debug("session %d did not enter RUNTIME state", sid)
|
||||
return replies
|
||||
|
||||
tlv_data = coreapi.CoreRegisterTlv.pack(
|
||||
|
@ -977,7 +979,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
message = coreapi.CoreRegMessage.pack(0, tlv_data)
|
||||
replies.append(message)
|
||||
except Exception as e:
|
||||
logging.exception("error executing: %s", execute_server)
|
||||
logger.exception("error executing: %s", execute_server)
|
||||
tlv_data = coreapi.CoreExceptionTlv.pack(ExceptionTlvs.LEVEL.value, 2)
|
||||
tlv_data += coreapi.CoreExceptionTlv.pack(
|
||||
ExceptionTlvs.TEXT.value, str(e)
|
||||
|
@ -989,7 +991,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
|
||||
gui = message.get_tlv(RegisterTlvs.GUI.value)
|
||||
if gui is None:
|
||||
logging.debug("ignoring Register message")
|
||||
logger.debug("ignoring Register message")
|
||||
else:
|
||||
# register capabilities with the GUI
|
||||
replies.append(self.register())
|
||||
|
@ -1020,7 +1022,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
network_id=message.get_tlv(ConfigTlvs.NETWORK_ID.value),
|
||||
opaque=message.get_tlv(ConfigTlvs.OPAQUE.value),
|
||||
)
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
"configuration message for %s node %s", config_data.object, config_data.node
|
||||
)
|
||||
message_type = ConfigFlags(config_data.type)
|
||||
|
@ -1095,7 +1097,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
self.session.location.reset()
|
||||
else:
|
||||
if not config_data.data_values:
|
||||
logging.warning("location data missing")
|
||||
logger.warning("location data missing")
|
||||
else:
|
||||
values = [float(x) for x in config_data.data_values.split("|")]
|
||||
|
||||
|
@ -1108,7 +1110,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
# geographic reference point
|
||||
self.session.location.setrefgeo(lat, lon, alt)
|
||||
self.session.location.refscale = values[5]
|
||||
logging.info(
|
||||
logger.info(
|
||||
"location configured: %s = %s scale=%s",
|
||||
self.session.location.refxyz,
|
||||
self.session.location.refgeo,
|
||||
|
@ -1145,7 +1147,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
def handle_config_broker(self, message_type, config_data):
|
||||
if message_type not in [ConfigFlags.REQUEST, ConfigFlags.RESET]:
|
||||
if not config_data.data_values:
|
||||
logging.info("emulation server data missing")
|
||||
logger.info("emulation server data missing")
|
||||
else:
|
||||
values = config_data.data_values.split("|")
|
||||
|
||||
|
@ -1169,7 +1171,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
session_id = config_data.session
|
||||
opaque = config_data.opaque
|
||||
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
"configuration request: node(%s) session(%s) opaque(%s)",
|
||||
node_id,
|
||||
session_id,
|
||||
|
@ -1199,10 +1201,10 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
values = []
|
||||
group_strings = []
|
||||
start_index = 1
|
||||
logging.debug("sorted groups: %s", groups)
|
||||
logger.debug("sorted groups: %s", groups)
|
||||
for group in groups:
|
||||
services = sorted(group_map[group], key=lambda x: x.name.lower())
|
||||
logging.debug("sorted services for group(%s): %s", group, services)
|
||||
logger.debug("sorted services for group(%s): %s", group, services)
|
||||
end_index = start_index + len(services) - 1
|
||||
group_strings.append(f"{group}:{start_index}-{end_index}")
|
||||
start_index += len(services)
|
||||
|
@ -1226,7 +1228,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
|
||||
node = self.session.get_node(node_id, CoreNodeBase)
|
||||
if node is None:
|
||||
logging.warning(
|
||||
logger.warning(
|
||||
"request to configure service for unknown node %s", node_id
|
||||
)
|
||||
return replies
|
||||
|
@ -1285,7 +1287,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
|
||||
error_message = "services config message that I don't know how to handle"
|
||||
if values is None:
|
||||
logging.error(error_message)
|
||||
logger.error(error_message)
|
||||
else:
|
||||
if opaque is None:
|
||||
values = values.split("|")
|
||||
|
@ -1294,11 +1296,11 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
data_types is None
|
||||
or data_types[0] != ConfigDataTypes.STRING.value
|
||||
):
|
||||
logging.info(error_message)
|
||||
logger.info(error_message)
|
||||
return None
|
||||
key = values.pop(0)
|
||||
self.session.services.default_services[key] = values
|
||||
logging.debug("default services for type %s set to %s", key, values)
|
||||
logger.debug("default services for type %s set to %s", key, values)
|
||||
elif node_id:
|
||||
services = ServiceShim.servicesfromopaque(opaque)
|
||||
if services:
|
||||
|
@ -1337,16 +1339,16 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
values_str = config_data.data_values
|
||||
|
||||
node_id = utils.iface_config_id(node_id, iface_id)
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
"received configure message for %s nodenum: %s", object_name, node_id
|
||||
)
|
||||
if message_type == ConfigFlags.REQUEST:
|
||||
logging.info("replying to configure request for model: %s", object_name)
|
||||
logger.info("replying to configure request for model: %s", object_name)
|
||||
typeflags = ConfigFlags.NONE.value
|
||||
|
||||
model_class = self.session.mobility.models.get(object_name)
|
||||
if not model_class:
|
||||
logging.warning("model class does not exist: %s", object_name)
|
||||
logger.warning("model class does not exist: %s", object_name)
|
||||
return []
|
||||
|
||||
config = self.session.mobility.get_model_config(node_id, object_name)
|
||||
|
@ -1357,7 +1359,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
elif message_type != ConfigFlags.RESET:
|
||||
# store the configuration values for later use, when the node
|
||||
if not object_name:
|
||||
logging.warning("no configuration object for node: %s", node_id)
|
||||
logger.warning("no configuration object for node: %s", node_id)
|
||||
return []
|
||||
|
||||
parsed_config = {}
|
||||
|
@ -1371,7 +1373,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
if object_name == BasicRangeModel.name:
|
||||
node.updatemodel(parsed_config)
|
||||
except CoreError:
|
||||
logging.error(
|
||||
logger.error(
|
||||
"skipping mobility configuration for unknown node: %s", node_id
|
||||
)
|
||||
|
||||
|
@ -1385,11 +1387,11 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
values_str = config_data.data_values
|
||||
|
||||
node_id = utils.iface_config_id(node_id, iface_id)
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
"received configure message for %s nodenum: %s", object_name, node_id
|
||||
)
|
||||
if message_type == ConfigFlags.REQUEST:
|
||||
logging.info("replying to configure request for %s model", object_name)
|
||||
logger.info("replying to configure request for %s model", object_name)
|
||||
typeflags = ConfigFlags.NONE.value
|
||||
config = self.session.emane.get_configs()
|
||||
config_response = ConfigShim.config_data(
|
||||
|
@ -1398,7 +1400,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
replies.append(config_response)
|
||||
elif message_type != ConfigFlags.RESET:
|
||||
if not object_name:
|
||||
logging.info("no configuration object for node %s", node_id)
|
||||
logger.info("no configuration object for node %s", node_id)
|
||||
return []
|
||||
|
||||
if values_str:
|
||||
|
@ -1415,16 +1417,16 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
values_str = config_data.data_values
|
||||
|
||||
node_id = utils.iface_config_id(node_id, iface_id)
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
"received configure message for %s nodenum: %s", object_name, node_id
|
||||
)
|
||||
if message_type == ConfigFlags.REQUEST:
|
||||
logging.info("replying to configure request for model: %s", object_name)
|
||||
logger.info("replying to configure request for model: %s", object_name)
|
||||
typeflags = ConfigFlags.NONE.value
|
||||
|
||||
model_class = self.session.emane.models.get(object_name)
|
||||
if not model_class:
|
||||
logging.warning("model class does not exist: %s", object_name)
|
||||
logger.warning("model class does not exist: %s", object_name)
|
||||
return []
|
||||
|
||||
config = self.session.emane.get_model_config(node_id, object_name)
|
||||
|
@ -1435,7 +1437,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
elif message_type != ConfigFlags.RESET:
|
||||
# store the configuration values for later use, when the node
|
||||
if not object_name:
|
||||
logging.warning("no configuration object for node: %s", node_id)
|
||||
logger.warning("no configuration object for node: %s", node_id)
|
||||
return []
|
||||
|
||||
parsed_config = {}
|
||||
|
@ -1464,13 +1466,11 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
compressed_data = message.get_tlv(FileTlvs.COMPRESSED_DATA.value)
|
||||
|
||||
if compressed_data:
|
||||
logging.warning(
|
||||
"Compressed file data not implemented for File message."
|
||||
)
|
||||
logger.warning("Compressed file data not implemented for File message.")
|
||||
return ()
|
||||
|
||||
if src_path and data:
|
||||
logging.warning(
|
||||
logger.warning(
|
||||
"ignoring invalid File message: source and data TLVs are both present"
|
||||
)
|
||||
return ()
|
||||
|
@ -1487,7 +1487,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
elif file_type.startswith("hook:"):
|
||||
_, state = file_type.split(":")[:2]
|
||||
if not state.isdigit():
|
||||
logging.error("error setting hook having state '%s'", state)
|
||||
logger.error("error setting hook having state '%s'", state)
|
||||
return ()
|
||||
state = int(state)
|
||||
state = EventTypes(state)
|
||||
|
@ -1517,7 +1517,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
:param message: interface message to handle
|
||||
:return: reply messages
|
||||
"""
|
||||
logging.info("ignoring Interface message")
|
||||
logger.info("ignoring Interface message")
|
||||
return ()
|
||||
|
||||
def handle_event_message(self, message):
|
||||
|
@ -1543,7 +1543,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
raise NotImplementedError("Event message missing event type")
|
||||
node_id = event_data.node
|
||||
|
||||
logging.debug("handling event %s at %s", event_type.name, time.ctime())
|
||||
logger.debug("handling event %s at %s", event_type.name, time.ctime())
|
||||
if event_type.value <= EventTypes.SHUTDOWN_STATE.value:
|
||||
if node_id is not None:
|
||||
node = self.session.get_node(node_id, NodeBase)
|
||||
|
@ -1555,7 +1555,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
self.session.start_mobility(node_ids=[node.id])
|
||||
return ()
|
||||
|
||||
logging.warning(
|
||||
logger.warning(
|
||||
"dropping unhandled event message for node: %s", node.name
|
||||
)
|
||||
return ()
|
||||
|
@ -1580,12 +1580,12 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
self.send_node_emulation_id(_id)
|
||||
elif event_type == EventTypes.RUNTIME_STATE:
|
||||
self.session.set_state(event_type)
|
||||
logging.warning("Unexpected event message: RUNTIME state received")
|
||||
logger.warning("Unexpected event message: RUNTIME state received")
|
||||
elif event_type == EventTypes.DATACOLLECT_STATE:
|
||||
self.session.data_collect()
|
||||
elif event_type == EventTypes.SHUTDOWN_STATE:
|
||||
self.session.set_state(event_type)
|
||||
logging.warning("Unexpected event message: SHUTDOWN state received")
|
||||
logger.warning("Unexpected event message: SHUTDOWN state received")
|
||||
elif event_type in {
|
||||
EventTypes.START,
|
||||
EventTypes.STOP,
|
||||
|
@ -1605,7 +1605,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
self.session.mobility_event(event_data)
|
||||
handled = True
|
||||
if not handled:
|
||||
logging.warning(
|
||||
logger.warning(
|
||||
"unhandled event message: event type %s, name %s ",
|
||||
event_type.name,
|
||||
name,
|
||||
|
@ -1624,7 +1624,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
name = event_data.name
|
||||
data = event_data.data
|
||||
if etime is None:
|
||||
logging.warning("Event message scheduled event missing start time")
|
||||
logger.warning("Event message scheduled event missing start time")
|
||||
return ()
|
||||
if message.flags & MessageFlags.ADD.value:
|
||||
self.session.add_event(
|
||||
|
@ -1650,7 +1650,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
try:
|
||||
node = self.session.get_node(node_id, CoreNodeBase)
|
||||
except CoreError:
|
||||
logging.warning(
|
||||
logger.warning(
|
||||
"ignoring event for service '%s', unknown node '%s'", name, node_id
|
||||
)
|
||||
return
|
||||
|
@ -1692,7 +1692,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
if num > 1:
|
||||
unknown_data += ", "
|
||||
num -= 1
|
||||
logging.warning("Event requested for unknown service(s): %s", unknown_data)
|
||||
logger.warning("Event requested for unknown service(s): %s", unknown_data)
|
||||
unknown_data = f"Unknown:{unknown_data}"
|
||||
|
||||
event_data = EventData(
|
||||
|
@ -1720,7 +1720,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
files = coreapi.str_to_list(file_str)
|
||||
thumb = message.get_tlv(SessionTlvs.THUMB.value)
|
||||
user = message.get_tlv(SessionTlvs.USER.value)
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
"SESSION message flags=0x%x sessions=%s", message.flags, session_id_str
|
||||
)
|
||||
|
||||
|
@ -1732,7 +1732,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
else:
|
||||
session = self.coreemu.sessions.get(session_id)
|
||||
if session is None:
|
||||
logging.warning("session %s not found", session_id)
|
||||
logger.warning("session %s not found", session_id)
|
||||
continue
|
||||
if names is not None:
|
||||
session.name = names[index]
|
||||
|
@ -1756,14 +1756,14 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
session = self.coreemu.sessions.get(session_id)
|
||||
|
||||
if session is None:
|
||||
logging.info(
|
||||
logger.info(
|
||||
"session %s not found (flags=0x%x)", session_id, message.flags
|
||||
)
|
||||
continue
|
||||
|
||||
if message.flags & MessageFlags.ADD.value:
|
||||
# connect to the first session that exists
|
||||
logging.info("request to connect to session %s", session_id)
|
||||
logger.info("request to connect to session %s", session_id)
|
||||
|
||||
# remove client from session broker and shutdown if needed
|
||||
self.remove_session_handlers()
|
||||
|
@ -1780,7 +1780,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
clients.append(self)
|
||||
|
||||
# add broadcast handlers
|
||||
logging.info("adding session broadcast handlers")
|
||||
logger.info("adding session broadcast handlers")
|
||||
self.add_session_handlers()
|
||||
|
||||
if user:
|
||||
|
@ -1790,12 +1790,10 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
self.send_objects()
|
||||
elif message.flags & MessageFlags.DELETE.value:
|
||||
# shut down the specified session(s)
|
||||
logging.info("request to terminate session %s", session_id)
|
||||
logger.info("request to terminate session %s", session_id)
|
||||
self.coreemu.delete_session(session_id)
|
||||
else:
|
||||
logging.warning(
|
||||
"unhandled session flags for session %s", session_id
|
||||
)
|
||||
logger.warning("unhandled session flags for session %s", session_id)
|
||||
|
||||
return ()
|
||||
|
||||
|
@ -1817,9 +1815,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
try:
|
||||
self.sendall(reply)
|
||||
except IOError:
|
||||
logging.exception(
|
||||
"error sending node emulation id message: %s", node_id
|
||||
)
|
||||
logger.exception("error sending node emulation id message: %s", node_id)
|
||||
|
||||
del self.node_status_request[node_id]
|
||||
|
||||
|
@ -1845,7 +1841,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
for model_name in mobility_configs:
|
||||
config = mobility_configs[model_name]
|
||||
model_class = self.session.mobility.models[model_name]
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
"mobility config: node(%s) class(%s) values(%s)",
|
||||
node_id,
|
||||
model_class,
|
||||
|
@ -1858,7 +1854,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
|
||||
# send global emane config
|
||||
config = self.session.emane.get_configs()
|
||||
logging.debug("global emane config: values(%s)", config)
|
||||
logger.debug("global emane config: values(%s)", config)
|
||||
config_data = ConfigShim.config_data(
|
||||
0, None, ConfigFlags.UPDATE.value, self.session.emane.emane_config, config
|
||||
)
|
||||
|
@ -1870,7 +1866,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
for model_name in emane_configs:
|
||||
config = emane_configs[model_name]
|
||||
model_class = self.session.emane.models[model_name]
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
"emane config: node(%s) class(%s) values(%s)",
|
||||
node_id,
|
||||
model_class,
|
||||
|
@ -1951,7 +1947,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
self.session.broadcast_config(config_data)
|
||||
|
||||
node_count = self.session.get_node_count()
|
||||
logging.info(
|
||||
logger.info(
|
||||
"informed GUI about %d nodes and %d links", node_count, len(all_links)
|
||||
)
|
||||
|
||||
|
@ -1991,11 +1987,11 @@ class CoreUdpHandler(CoreHandler):
|
|||
header
|
||||
)
|
||||
if message_len == 0:
|
||||
logging.warning("received message with no data")
|
||||
logger.warning("received message with no data")
|
||||
return
|
||||
|
||||
if len(data) != coreapi.CoreMessage.header_len + message_len:
|
||||
logging.error(
|
||||
logger.error(
|
||||
"received message length does not match received data (%s != %s)",
|
||||
len(data),
|
||||
coreapi.CoreMessage.header_len + message_len,
|
||||
|
@ -2013,7 +2009,7 @@ class CoreUdpHandler(CoreHandler):
|
|||
message_flags, header, data[coreapi.CoreMessage.header_len :]
|
||||
)
|
||||
message.msgtype = message_type
|
||||
logging.exception("unimplemented core message type: %s", message.type_str())
|
||||
logger.exception("unimplemented core message type: %s", message.type_str())
|
||||
|
||||
def handle(self):
|
||||
message = self.receive_message()
|
||||
|
@ -2023,12 +2019,12 @@ class CoreUdpHandler(CoreHandler):
|
|||
for session_id in sessions:
|
||||
session = self.server.mainserver.coreemu.sessions.get(session_id)
|
||||
if session:
|
||||
logging.debug("session handling message: %s", session.id)
|
||||
logger.debug("session handling message: %s", session.id)
|
||||
self.session = session
|
||||
self.handle_message(message)
|
||||
self.broadcast(message)
|
||||
else:
|
||||
logging.error(
|
||||
logger.error(
|
||||
"session %d in %s message not found.",
|
||||
session_id,
|
||||
message.type_str(),
|
||||
|
@ -2052,7 +2048,7 @@ class CoreUdpHandler(CoreHandler):
|
|||
self.handle_message(message)
|
||||
self.broadcast(message)
|
||||
else:
|
||||
logging.error(
|
||||
logger.error(
|
||||
"no active session, dropping %s message.", message.type_str()
|
||||
)
|
||||
|
||||
|
@ -2065,7 +2061,7 @@ class CoreUdpHandler(CoreHandler):
|
|||
try:
|
||||
client.sendall(message.raw_message)
|
||||
except IOError:
|
||||
logging.error("error broadcasting")
|
||||
logger.error("error broadcasting")
|
||||
|
||||
def finish(self):
|
||||
return socketserver.BaseRequestHandler.finish(self)
|
||||
|
|
|
@ -10,6 +10,8 @@ from core.api.tlv.enumerations import ConfigTlvs, NodeTlvs
|
|||
from core.config import ConfigGroup, ConfigurableOptions
|
||||
from core.emulator.data import ConfigData, NodeData
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def convert_node(node_data: NodeData):
|
||||
"""
|
||||
|
@ -139,9 +141,9 @@ class ConfigShim:
|
|||
captions = None
|
||||
data_types = []
|
||||
possible_values = []
|
||||
logging.debug("configurable: %s", configurable_options)
|
||||
logging.debug("configuration options: %s", configurable_options.configurations)
|
||||
logging.debug("configuration data: %s", config)
|
||||
logger.debug("configurable: %s", configurable_options)
|
||||
logger.debug("configuration options: %s", configurable_options.configurations)
|
||||
logger.debug("configuration data: %s", config)
|
||||
for configuration in configurable_options.configurations():
|
||||
if not captions:
|
||||
captions = configuration.label
|
||||
|
|
|
@ -4,6 +4,8 @@ Utilities for working with python struct data.
|
|||
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def pack_values(clazz, packers):
|
||||
"""
|
||||
|
@ -15,7 +17,7 @@ def pack_values(clazz, packers):
|
|||
"""
|
||||
|
||||
# iterate through tuples of values to pack
|
||||
logging.debug("packing: %s", packers)
|
||||
logger.debug("packing: %s", packers)
|
||||
data = b""
|
||||
for packer in packers:
|
||||
# check if a transformer was provided for valid values
|
||||
|
@ -37,7 +39,7 @@ def pack_values(clazz, packers):
|
|||
value = transformer(value)
|
||||
|
||||
# pack and add to existing data
|
||||
logging.debug("packing: %s - %s type(%s)", tlv_type, value, type(value))
|
||||
logger.debug("packing: %s - %s type(%s)", tlv_type, value, type(value))
|
||||
data += clazz.pack(tlv_type.value, value)
|
||||
|
||||
return data
|
||||
|
|
|
@ -12,6 +12,8 @@ from core.emulator.enumerations import ConfigDataTypes
|
|||
from core.errors import CoreConfigError
|
||||
from core.nodes.network import WlanNode
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.location.mobility import WirelessModel
|
||||
|
||||
|
@ -178,7 +180,7 @@ class ConfigurableManager:
|
|||
:param config_type: configuration type to store configuration for
|
||||
:return: nothing
|
||||
"""
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
"setting config for node(%s) type(%s): %s", node_id, config_type, config
|
||||
)
|
||||
node_configs = self.node_configurations.setdefault(node_id, OrderedDict())
|
||||
|
@ -310,7 +312,7 @@ class ModelManager(ConfigurableManager):
|
|||
:param config: model configuration, None for default configuration
|
||||
:return: nothing
|
||||
"""
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
"setting model(%s) for node(%s): %s", model_class.name, node.id, config
|
||||
)
|
||||
self.set_model_config(node.id, model_class.name, config)
|
||||
|
@ -339,5 +341,5 @@ class ModelManager(ConfigurableManager):
|
|||
model_class = self.models[model_name]
|
||||
models.append((model_class, config))
|
||||
|
||||
logging.debug("models for node(%s): %s", node.id, models)
|
||||
logger.debug("models for node(%s): %s", node.id, models)
|
||||
return models
|
||||
|
|
|
@ -14,6 +14,7 @@ from core.config import Configuration
|
|||
from core.errors import CoreCommandError, CoreError
|
||||
from core.nodes.base import CoreNode
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
TEMPLATES_DIR: str = "templates"
|
||||
|
||||
|
||||
|
@ -133,7 +134,7 @@ class ConfigService(abc.ABC):
|
|||
:return: nothing
|
||||
:raises ConfigServiceBootError: when there is an error starting service
|
||||
"""
|
||||
logging.info("node(%s) service(%s) starting...", self.node.name, self.name)
|
||||
logger.info("node(%s) service(%s) starting...", self.node.name, self.name)
|
||||
self.create_dirs()
|
||||
self.create_files()
|
||||
wait = self.validation_mode == ConfigServiceMode.BLOCKING
|
||||
|
@ -154,7 +155,7 @@ class ConfigService(abc.ABC):
|
|||
try:
|
||||
self.node.cmd(cmd)
|
||||
except CoreCommandError:
|
||||
logging.exception(
|
||||
logger.exception(
|
||||
f"node({self.node.name}) service({self.name}) "
|
||||
f"failed shutdown: {cmd}"
|
||||
)
|
||||
|
@ -250,7 +251,7 @@ class ConfigService(abc.ABC):
|
|||
else:
|
||||
text = self.get_text_template(name)
|
||||
rendered = self.render_text(text, data)
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
"node(%s) service(%s) template(%s): \n%s",
|
||||
self.node.name,
|
||||
self.name,
|
||||
|
@ -301,7 +302,7 @@ class ConfigService(abc.ABC):
|
|||
del cmds[index]
|
||||
index += 1
|
||||
except CoreCommandError:
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
f"node({self.node.name}) service({self.name}) "
|
||||
f"validate command failed: {cmd}"
|
||||
)
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import logging
|
||||
from typing import TYPE_CHECKING, Dict, List, Set
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.configservice.base import ConfigService
|
||||
|
||||
|
@ -41,7 +43,7 @@ class ConfigServiceDependencies:
|
|||
for name in self.node_services:
|
||||
service = self.node_services[name]
|
||||
if service.name in self.started:
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
"skipping service that will already be started: %s", service.name
|
||||
)
|
||||
continue
|
||||
|
@ -75,7 +77,7 @@ class ConfigServiceDependencies:
|
|||
:param service: service to check dependencies for
|
||||
:return: list of config services to start in order
|
||||
"""
|
||||
logging.debug("starting service dependency check: %s", service.name)
|
||||
logger.debug("starting service dependency check: %s", service.name)
|
||||
self._reset()
|
||||
return self._visit(service)
|
||||
|
||||
|
@ -86,7 +88,7 @@ class ConfigServiceDependencies:
|
|||
:param current_service: service being visited
|
||||
:return: list of dependent services for a visited service
|
||||
"""
|
||||
logging.debug("visiting service(%s): %s", current_service.name, self.path)
|
||||
logger.debug("visiting service(%s): %s", current_service.name, self.path)
|
||||
self.visited.add(current_service.name)
|
||||
self.visiting.add(current_service.name)
|
||||
|
||||
|
@ -109,7 +111,7 @@ class ConfigServiceDependencies:
|
|||
self._visit(service)
|
||||
|
||||
# add service when bottom is found
|
||||
logging.debug("adding service to startup path: %s", current_service.name)
|
||||
logger.debug("adding service to startup path: %s", current_service.name)
|
||||
self.started.add(current_service.name)
|
||||
self.path.append(current_service)
|
||||
self.visiting.remove(current_service.name)
|
||||
|
|
|
@ -7,6 +7,8 @@ from core import utils
|
|||
from core.configservice.base import ConfigService
|
||||
from core.errors import CoreError
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ConfigServiceManager:
|
||||
"""
|
||||
|
@ -41,7 +43,7 @@ class ConfigServiceManager:
|
|||
:raises CoreError: when service is a duplicate or has unmet executables
|
||||
"""
|
||||
name = service.name
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
"loading service: class(%s) name(%s)", service.__class__.__name__, name
|
||||
)
|
||||
|
||||
|
@ -71,12 +73,12 @@ class ConfigServiceManager:
|
|||
subdirs.append(path)
|
||||
service_errors = []
|
||||
for subdir in subdirs:
|
||||
logging.debug("loading config services from: %s", subdir)
|
||||
logger.debug("loading config services from: %s", subdir)
|
||||
services = utils.load_classes(subdir, ConfigService)
|
||||
for service in services:
|
||||
try:
|
||||
self.add(service)
|
||||
except CoreError as e:
|
||||
service_errors.append(service.name)
|
||||
logging.debug("not loading service(%s): %s", service.name, e)
|
||||
logger.debug("not loading service(%s): %s", service.name, e)
|
||||
return service_errors
|
||||
|
|
|
@ -9,6 +9,7 @@ from core.nodes.base import CoreNodeBase
|
|||
from core.nodes.interface import DEFAULT_MTU, CoreInterface
|
||||
from core.nodes.network import WlanNode
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
GROUP: str = "Quagga"
|
||||
QUAGGA_STATE_DIR: str = "/var/run/quagga"
|
||||
|
||||
|
@ -229,7 +230,7 @@ class Ospfv3mdr(Ospfv3):
|
|||
def data(self) -> Dict[str, Any]:
|
||||
for iface in self.node.get_ifaces():
|
||||
is_wireless = isinstance(iface.net, (WlanNode, EmaneNet))
|
||||
logging.info("MDR wireless: %s", is_wireless)
|
||||
logger.info("MDR wireless: %s", is_wireless)
|
||||
return dict()
|
||||
|
||||
def quagga_iface_config(self, iface: CoreInterface) -> str:
|
||||
|
|
|
@ -14,6 +14,8 @@ from core.emulator.data import LinkOptions
|
|||
from core.nodes.interface import CoreInterface
|
||||
from core.xml import emanexml
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
try:
|
||||
from emane.events.commeffectevent import CommEffectEvent
|
||||
except ImportError:
|
||||
|
@ -21,7 +23,7 @@ except ImportError:
|
|||
from emanesh.events.commeffectevent import CommEffectEvent
|
||||
except ImportError:
|
||||
CommEffectEvent = None
|
||||
logging.debug("compatible emane python bindings not installed")
|
||||
logger.debug("compatible emane python bindings not installed")
|
||||
|
||||
|
||||
def convert_none(x: float) -> int:
|
||||
|
@ -113,11 +115,11 @@ class EmaneCommEffectModel(emanemodel.EmaneModel):
|
|||
"""
|
||||
service = self.session.emane.service
|
||||
if service is None:
|
||||
logging.warning("%s: EMANE event service unavailable", self.name)
|
||||
logger.warning("%s: EMANE event service unavailable", self.name)
|
||||
return
|
||||
|
||||
if iface is None or iface2 is None:
|
||||
logging.warning("%s: missing NEM information", self.name)
|
||||
logger.warning("%s: missing NEM information", self.name)
|
||||
return
|
||||
|
||||
# TODO: batch these into multiple events per transmission
|
||||
|
@ -125,7 +127,7 @@ class EmaneCommEffectModel(emanemodel.EmaneModel):
|
|||
event = CommEffectEvent()
|
||||
nem1 = self.session.emane.get_nem_id(iface)
|
||||
nem2 = self.session.emane.get_nem_id(iface2)
|
||||
logging.info("sending comm effect event")
|
||||
logger.info("sending comm effect event")
|
||||
event.append(
|
||||
nem1,
|
||||
latency=convert_none(options.delay),
|
||||
|
|
|
@ -34,6 +34,8 @@ from core.nodes.base import CoreNetworkBase, CoreNode, CoreNodeBase, NodeBase
|
|||
from core.nodes.interface import CoreInterface, TunTap
|
||||
from core.xml import emanexml
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.emulator.session import Session
|
||||
|
||||
|
@ -51,7 +53,7 @@ except ImportError:
|
|||
LocationEvent = None
|
||||
PathlossEvent = None
|
||||
EventServiceException = None
|
||||
logging.debug("compatible emane python bindings not installed")
|
||||
logger.debug("compatible emane python bindings not installed")
|
||||
|
||||
EMANE_MODELS = [
|
||||
EmaneRfPipeModel,
|
||||
|
@ -174,11 +176,11 @@ class EmaneManager(ModelManager):
|
|||
# check for emane
|
||||
path = utils.which("emane", required=False)
|
||||
if not path:
|
||||
logging.info("emane is not installed")
|
||||
logger.info("emane is not installed")
|
||||
return
|
||||
# get version
|
||||
emane_version = utils.cmd("emane --version")
|
||||
logging.info("using emane: %s", emane_version)
|
||||
logger.info("using emane: %s", emane_version)
|
||||
# load default emane models
|
||||
self.load_models(EMANE_MODELS)
|
||||
# load custom models
|
||||
|
@ -214,7 +216,7 @@ class EmaneManager(ModelManager):
|
|||
self.event_device = self.get_config("eventservicedevice")
|
||||
eventnetidx = self.session.get_control_net_index(self.event_device)
|
||||
if eventnetidx < 0:
|
||||
logging.error(
|
||||
logger.error(
|
||||
"invalid emane event service device provided: %s", self.event_device
|
||||
)
|
||||
return
|
||||
|
@ -230,18 +232,18 @@ class EmaneManager(ModelManager):
|
|||
|
||||
# disabled otachannel for event service
|
||||
# only needed for e.g. antennaprofile events xmit by models
|
||||
logging.info("using %s for event service traffic", self.event_device)
|
||||
logger.info("using %s for event service traffic", self.event_device)
|
||||
try:
|
||||
self.service = EventService(eventchannel=self.eventchannel, otachannel=None)
|
||||
except EventServiceException:
|
||||
logging.exception("error instantiating emane EventService")
|
||||
logger.exception("error instantiating emane EventService")
|
||||
|
||||
def load_models(self, emane_models: List[Type[EmaneModel]]) -> None:
|
||||
"""
|
||||
Load EMANE models and make them available.
|
||||
"""
|
||||
for emane_model in emane_models:
|
||||
logging.debug("loading emane model: %s", emane_model.__name__)
|
||||
logger.debug("loading emane model: %s", emane_model.__name__)
|
||||
emane_prefix = self.session.options.get_config(
|
||||
"emane_prefix", default=DEFAULT_EMANE_PREFIX
|
||||
)
|
||||
|
@ -281,17 +283,17 @@ class EmaneManager(ModelManager):
|
|||
:return: SUCCESS, NOT_NEEDED, NOT_READY in order to delay session
|
||||
instantiation
|
||||
"""
|
||||
logging.debug("emane setup")
|
||||
logger.debug("emane setup")
|
||||
with self.session.nodes_lock:
|
||||
for node_id in self.session.nodes:
|
||||
node = self.session.nodes[node_id]
|
||||
if isinstance(node, EmaneNet):
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
"adding emane node: id(%s) name(%s)", node.id, node.name
|
||||
)
|
||||
self.add_node(node)
|
||||
if not self._emane_nets:
|
||||
logging.debug("no emane nodes in session")
|
||||
logger.debug("no emane nodes in session")
|
||||
return EmaneState.NOT_NEEDED
|
||||
|
||||
# check if bindings were installed
|
||||
|
@ -302,9 +304,9 @@ class EmaneManager(ModelManager):
|
|||
# - needs to exist when eventservice binds to it (initeventservice)
|
||||
otadev = self.get_config("otamanagerdevice")
|
||||
netidx = self.session.get_control_net_index(otadev)
|
||||
logging.debug("emane ota manager device: index(%s) otadev(%s)", netidx, otadev)
|
||||
logger.debug("emane ota manager device: index(%s) otadev(%s)", netidx, otadev)
|
||||
if netidx < 0:
|
||||
logging.error(
|
||||
logger.error(
|
||||
"EMANE cannot start, check core config. invalid OTA device provided: %s",
|
||||
otadev,
|
||||
)
|
||||
|
@ -314,12 +316,12 @@ class EmaneManager(ModelManager):
|
|||
net_index=netidx, remove=False, conf_required=False
|
||||
)
|
||||
eventdev = self.get_config("eventservicedevice")
|
||||
logging.debug("emane event service device: eventdev(%s)", eventdev)
|
||||
logger.debug("emane event service device: eventdev(%s)", eventdev)
|
||||
if eventdev != otadev:
|
||||
netidx = self.session.get_control_net_index(eventdev)
|
||||
logging.debug("emane event service device index: %s", netidx)
|
||||
logger.debug("emane event service device index: %s", netidx)
|
||||
if netidx < 0:
|
||||
logging.error(
|
||||
logger.error(
|
||||
"emane cannot start due to invalid event service device: %s",
|
||||
eventdev,
|
||||
)
|
||||
|
@ -346,7 +348,7 @@ class EmaneManager(ModelManager):
|
|||
self.starteventmonitor()
|
||||
self.buildeventservicexml()
|
||||
with self._emane_node_lock:
|
||||
logging.info("emane building xmls...")
|
||||
logger.info("emane building xmls...")
|
||||
start_data = self.get_start_data()
|
||||
for data in start_data:
|
||||
self.start_node(data)
|
||||
|
@ -359,11 +361,11 @@ class EmaneManager(ModelManager):
|
|||
for node_id in sorted(self._emane_nets):
|
||||
emane_net = self._emane_nets[node_id]
|
||||
if not emane_net.model:
|
||||
logging.error("emane net(%s) has no model", emane_net.name)
|
||||
logger.error("emane net(%s) has no model", emane_net.name)
|
||||
continue
|
||||
for iface in emane_net.get_ifaces():
|
||||
if not iface.node:
|
||||
logging.error(
|
||||
logger.error(
|
||||
"emane net(%s) connected interface(%s) missing node",
|
||||
emane_net.name,
|
||||
iface.name,
|
||||
|
@ -403,7 +405,7 @@ class EmaneManager(ModelManager):
|
|||
with path.open("a") as f:
|
||||
f.write(f"{iface.node.name} {iface.name} {nem_id}\n")
|
||||
except IOError:
|
||||
logging.exception("error writing to emane nem file")
|
||||
logger.exception("error writing to emane nem file")
|
||||
|
||||
def links_enabled(self) -> bool:
|
||||
return self.get_config("link_enabled") == "1"
|
||||
|
@ -417,7 +419,7 @@ class EmaneManager(ModelManager):
|
|||
with self._emane_node_lock:
|
||||
for node_id in sorted(self._emane_nets):
|
||||
emane_net = self._emane_nets[node_id]
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
"post startup for emane node: %s - %s", emane_net.id, emane_net.name
|
||||
)
|
||||
emane_net.model.post_startup()
|
||||
|
@ -441,7 +443,7 @@ class EmaneManager(ModelManager):
|
|||
with self._emane_node_lock:
|
||||
if not self._emane_nets:
|
||||
return
|
||||
logging.info("stopping EMANE daemons")
|
||||
logger.info("stopping EMANE daemons")
|
||||
if self.links_enabled():
|
||||
self.link_monitor.stop()
|
||||
# shutdown interfaces and stop daemons
|
||||
|
@ -467,11 +469,11 @@ class EmaneManager(ModelManager):
|
|||
"""
|
||||
for node_id in self._emane_nets:
|
||||
emane_net = self._emane_nets[node_id]
|
||||
logging.debug("checking emane model for node: %s", node_id)
|
||||
logger.debug("checking emane model for node: %s", node_id)
|
||||
|
||||
# skip nodes that already have a model set
|
||||
if emane_net.model:
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
"node(%s) already has model(%s)", emane_net.id, emane_net.model.name
|
||||
)
|
||||
continue
|
||||
|
@ -480,11 +482,11 @@ class EmaneManager(ModelManager):
|
|||
# before nodes exist
|
||||
model_name = self.node_models.get(node_id)
|
||||
if not model_name:
|
||||
logging.error("emane node(%s) has no node model", node_id)
|
||||
logger.error("emane node(%s) has no node model", node_id)
|
||||
raise ValueError("emane node has no model set")
|
||||
|
||||
config = self.get_model_config(node_id=node_id, model_name=model_name)
|
||||
logging.debug("setting emane model(%s) config(%s)", model_name, config)
|
||||
logger.debug("setting emane model(%s) config(%s)", model_name, config)
|
||||
model_class = self.models[model_name]
|
||||
emane_net.setmodel(model_class, config)
|
||||
|
||||
|
@ -493,12 +495,12 @@ class EmaneManager(ModelManager):
|
|||
) -> Optional[LinkData]:
|
||||
iface1 = self.get_iface(nem1)
|
||||
if not iface1:
|
||||
logging.error("invalid nem: %s", nem1)
|
||||
logger.error("invalid nem: %s", nem1)
|
||||
return None
|
||||
node1 = iface1.node
|
||||
iface2 = self.get_iface(nem2)
|
||||
if not iface2:
|
||||
logging.error("invalid nem: %s", nem2)
|
||||
logger.error("invalid nem: %s", nem2)
|
||||
return None
|
||||
node2 = iface2.node
|
||||
if iface1.net != iface2.net:
|
||||
|
@ -535,7 +537,7 @@ class EmaneManager(ModelManager):
|
|||
try:
|
||||
group, port = self.get_config("eventservicegroup").split(":")
|
||||
except ValueError:
|
||||
logging.exception("invalid eventservicegroup in EMANE config")
|
||||
logger.exception("invalid eventservicegroup in EMANE config")
|
||||
return
|
||||
|
||||
dev = self.get_config("eventservicedevice")
|
||||
|
@ -551,12 +553,12 @@ class EmaneManager(ModelManager):
|
|||
Start one EMANE daemon per node having a radio.
|
||||
Add a control network even if the user has not configured one.
|
||||
"""
|
||||
logging.info("starting emane daemons...")
|
||||
logger.info("starting emane daemons...")
|
||||
loglevel = str(EmaneManager.DEFAULT_LOG_LEVEL)
|
||||
cfgloglevel = self.session.options.get_config_int("emane_log_level")
|
||||
realtime = self.session.options.get_config_bool("emane_realtime", default=True)
|
||||
if cfgloglevel:
|
||||
logging.info("setting user-defined emane log level: %d", cfgloglevel)
|
||||
logger.info("setting user-defined emane log level: %d", cfgloglevel)
|
||||
loglevel = str(cfgloglevel)
|
||||
emanecmd = f"emane -d -l {loglevel}"
|
||||
if realtime:
|
||||
|
@ -574,17 +576,17 @@ class EmaneManager(ModelManager):
|
|||
node, 0, remove=False, conf_required=False
|
||||
)
|
||||
if otanetidx > 0:
|
||||
logging.info("adding ota device ctrl%d", otanetidx)
|
||||
logger.info("adding ota device ctrl%d", otanetidx)
|
||||
self.session.add_remove_control_iface(
|
||||
node, otanetidx, remove=False, conf_required=False
|
||||
)
|
||||
if eventservicenetidx >= 0:
|
||||
logging.info("adding event service device ctrl%d", eventservicenetidx)
|
||||
logger.info("adding event service device ctrl%d", eventservicenetidx)
|
||||
self.session.add_remove_control_iface(
|
||||
node, eventservicenetidx, remove=False, conf_required=False
|
||||
)
|
||||
# multicast route is needed for OTA data
|
||||
logging.info("OTA GROUP(%s) OTA DEV(%s)", otagroup, otadev)
|
||||
logger.info("OTA GROUP(%s) OTA DEV(%s)", otagroup, otadev)
|
||||
node.node_net_client.create_route(otagroup, otadev)
|
||||
# multicast route is also needed for event data if on control network
|
||||
if eventservicenetidx >= 0 and eventgroup != otagroup:
|
||||
|
@ -594,13 +596,13 @@ class EmaneManager(ModelManager):
|
|||
platform_xml = node.directory / f"{node.name}-platform.xml"
|
||||
args = f"{emanecmd} -f {log_file} {platform_xml}"
|
||||
node.cmd(args)
|
||||
logging.info("node(%s) emane daemon running: %s", node.name, args)
|
||||
logger.info("node(%s) emane daemon running: %s", node.name, args)
|
||||
else:
|
||||
log_file = self.session.directory / f"{node.name}-emane.log"
|
||||
platform_xml = self.session.directory / f"{node.name}-platform.xml"
|
||||
args = f"{emanecmd} -f {log_file} {platform_xml}"
|
||||
node.host_cmd(args, cwd=self.session.directory)
|
||||
logging.info("node(%s) host emane daemon running: %s", node.name, args)
|
||||
logger.info("node(%s) host emane daemon running: %s", node.name, args)
|
||||
|
||||
def install_iface(self, iface: CoreInterface) -> None:
|
||||
emane_net = iface.net
|
||||
|
@ -641,11 +643,11 @@ class EmaneManager(ModelManager):
|
|||
"""
|
||||
Start monitoring EMANE location events if configured to do so.
|
||||
"""
|
||||
logging.info("emane start event monitor")
|
||||
logger.info("emane start event monitor")
|
||||
if not self.doeventmonitor():
|
||||
return
|
||||
if self.service is None:
|
||||
logging.error(
|
||||
logger.error(
|
||||
"Warning: EMANE events will not be generated "
|
||||
"because the emaneeventservice\n binding was "
|
||||
"unable to load "
|
||||
|
@ -678,7 +680,7 @@ class EmaneManager(ModelManager):
|
|||
"""
|
||||
if self.service is None:
|
||||
return
|
||||
logging.info(
|
||||
logger.info(
|
||||
"subscribing to EMANE location events. (%s)",
|
||||
threading.currentThread().getName(),
|
||||
)
|
||||
|
@ -694,7 +696,7 @@ class EmaneManager(ModelManager):
|
|||
if eid == LocationEvent.IDENTIFIER:
|
||||
self.handlelocationevent(nem, eid, data)
|
||||
|
||||
logging.info(
|
||||
logger.info(
|
||||
"unsubscribing from EMANE location events. (%s)",
|
||||
threading.currentThread().getName(),
|
||||
)
|
||||
|
@ -712,14 +714,14 @@ class EmaneManager(ModelManager):
|
|||
or "longitude" not in attrs
|
||||
or "altitude" not in attrs
|
||||
):
|
||||
logging.warning("dropped invalid location event")
|
||||
logger.warning("dropped invalid location event")
|
||||
continue
|
||||
|
||||
# yaw,pitch,roll,azimuth,elevation,velocity are unhandled
|
||||
lat = attrs["latitude"]
|
||||
lon = attrs["longitude"]
|
||||
alt = attrs["altitude"]
|
||||
logging.debug("emane location event: %s,%s,%s", lat, lon, alt)
|
||||
logger.debug("emane location event: %s,%s,%s", lat, lon, alt)
|
||||
self.handlelocationeventtoxyz(txnemid, lat, lon, alt)
|
||||
|
||||
def handlelocationeventtoxyz(
|
||||
|
@ -733,7 +735,7 @@ class EmaneManager(ModelManager):
|
|||
# convert nemid to node number
|
||||
iface = self.get_iface(nemid)
|
||||
if iface is None:
|
||||
logging.info("location event for unknown NEM %s", nemid)
|
||||
logger.info("location event for unknown NEM %s", nemid)
|
||||
return False
|
||||
|
||||
n = iface.node.id
|
||||
|
@ -742,7 +744,7 @@ class EmaneManager(ModelManager):
|
|||
x = int(x)
|
||||
y = int(y)
|
||||
z = int(z)
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
"location event NEM %s (%s, %s, %s) -> (%s, %s, %s)",
|
||||
nemid,
|
||||
lat,
|
||||
|
@ -756,7 +758,7 @@ class EmaneManager(ModelManager):
|
|||
ybit_check = y.bit_length() > 16 or y < 0
|
||||
zbit_check = z.bit_length() > 16 or z < 0
|
||||
if any([xbit_check, ybit_check, zbit_check]):
|
||||
logging.error(
|
||||
logger.error(
|
||||
"Unable to build node location message, received lat/long/alt "
|
||||
"exceeds coordinate space: NEM %s (%d, %d, %d)",
|
||||
nemid,
|
||||
|
@ -770,7 +772,7 @@ class EmaneManager(ModelManager):
|
|||
try:
|
||||
node = self.session.get_node(n, NodeBase)
|
||||
except CoreError:
|
||||
logging.exception(
|
||||
logger.exception(
|
||||
"location event NEM %s has no corresponding node %s", nemid, n
|
||||
)
|
||||
return False
|
||||
|
|
|
@ -5,6 +5,8 @@ from typing import Dict, List
|
|||
from core.config import Configuration
|
||||
from core.emulator.enumerations import ConfigDataTypes
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
manifest = None
|
||||
try:
|
||||
from emane.shell import manifest
|
||||
|
@ -13,7 +15,7 @@ except ImportError:
|
|||
from emanesh import manifest
|
||||
except ImportError:
|
||||
manifest = None
|
||||
logging.debug("compatible emane python bindings not installed")
|
||||
logger.debug("compatible emane python bindings not installed")
|
||||
|
||||
|
||||
def _type_value(config_type: str) -> ConfigDataTypes:
|
||||
|
|
|
@ -15,6 +15,8 @@ from core.location.mobility import WirelessModel
|
|||
from core.nodes.interface import CoreInterface
|
||||
from core.xml import emanexml
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class EmaneModel(WirelessModel):
|
||||
"""
|
||||
|
@ -115,7 +117,7 @@ class EmaneModel(WirelessModel):
|
|||
|
||||
:return: nothing
|
||||
"""
|
||||
logging.debug("emane model(%s) has no post setup tasks", self.name)
|
||||
logger.debug("emane model(%s) has no post setup tasks", self.name)
|
||||
|
||||
def update(self, moved_ifaces: List[CoreInterface]) -> None:
|
||||
"""
|
||||
|
@ -130,7 +132,7 @@ class EmaneModel(WirelessModel):
|
|||
emane_net = self.session.get_node(self.id, EmaneNet)
|
||||
emane_net.setnempositions(moved_ifaces)
|
||||
except CoreError:
|
||||
logging.exception("error during update")
|
||||
logger.exception("error during update")
|
||||
|
||||
def linkconfig(
|
||||
self, iface: CoreInterface, options: LinkOptions, iface2: CoreInterface = None
|
||||
|
@ -143,4 +145,4 @@ class EmaneModel(WirelessModel):
|
|||
:param iface2: interface two
|
||||
:return: nothing
|
||||
"""
|
||||
logging.warning("emane model(%s) does not support link config", self.name)
|
||||
logger.warning("emane model(%s) does not support link config", self.name)
|
||||
|
|
|
@ -10,6 +10,8 @@ from core.emulator.data import LinkData
|
|||
from core.emulator.enumerations import LinkTypes, MessageFlags
|
||||
from core.nodes.network import CtrlNet
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
try:
|
||||
from emane import shell
|
||||
except ImportError:
|
||||
|
@ -17,7 +19,7 @@ except ImportError:
|
|||
from emanesh import shell
|
||||
except ImportError:
|
||||
shell = None
|
||||
logging.debug("compatible emane python bindings not installed")
|
||||
logger.debug("compatible emane python bindings not installed")
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.emane.emanemanager import EmaneManager
|
||||
|
@ -91,7 +93,7 @@ class EmaneClient:
|
|||
# get mac config
|
||||
mac_id, _, emane_model = components[MAC_COMPONENT_INDEX]
|
||||
mac_config = self.client.getConfiguration(mac_id)
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
"address(%s) nem(%s) emane(%s)", self.address, nem_id, emane_model
|
||||
)
|
||||
|
||||
|
@ -101,9 +103,9 @@ class EmaneClient:
|
|||
elif emane_model == EMANE_RFPIPE:
|
||||
loss_table = self.handle_rfpipe(mac_config)
|
||||
else:
|
||||
logging.warning("unknown emane link model: %s", emane_model)
|
||||
logger.warning("unknown emane link model: %s", emane_model)
|
||||
continue
|
||||
logging.info("monitoring links nem(%s) model(%s)", nem_id, emane_model)
|
||||
logger.info("monitoring links nem(%s) model(%s)", nem_id, emane_model)
|
||||
loss_table.mac_id = mac_id
|
||||
self.nems[nem_id] = loss_table
|
||||
|
||||
|
@ -138,12 +140,12 @@ class EmaneClient:
|
|||
|
||||
def handle_tdma(self, config: Dict[str, Tuple]):
|
||||
pcr = config["pcrcurveuri"][0][0]
|
||||
logging.debug("tdma pcr: %s", pcr)
|
||||
logger.debug("tdma pcr: %s", pcr)
|
||||
|
||||
def handle_80211(self, config: Dict[str, Tuple]) -> LossTable:
|
||||
unicastrate = config["unicastrate"][0][0]
|
||||
pcr = config["pcrcurveuri"][0][0]
|
||||
logging.debug("80211 pcr: %s", pcr)
|
||||
logger.debug("80211 pcr: %s", pcr)
|
||||
tree = etree.parse(pcr)
|
||||
root = tree.getroot()
|
||||
table = root.find("table")
|
||||
|
@ -159,7 +161,7 @@ class EmaneClient:
|
|||
|
||||
def handle_rfpipe(self, config: Dict[str, Tuple]) -> LossTable:
|
||||
pcr = config["pcrcurveuri"][0][0]
|
||||
logging.debug("rfpipe pcr: %s", pcr)
|
||||
logger.debug("rfpipe pcr: %s", pcr)
|
||||
tree = etree.parse(pcr)
|
||||
root = tree.getroot()
|
||||
table = root.find("table")
|
||||
|
@ -192,7 +194,7 @@ class EmaneLinkMonitor:
|
|||
self.link_timeout = int(self.emane_manager.get_config("link_timeout"))
|
||||
self.initialize()
|
||||
if not self.clients:
|
||||
logging.info("no valid emane models to monitor links")
|
||||
logger.info("no valid emane models to monitor links")
|
||||
return
|
||||
self.scheduler = sched.scheduler()
|
||||
self.scheduler.enter(0, 0, self.check_links)
|
||||
|
@ -228,7 +230,7 @@ class EmaneLinkMonitor:
|
|||
client.check_links(self.links, self.loss_threshold)
|
||||
except shell.ControlPortException:
|
||||
if self.running:
|
||||
logging.exception("link monitor error")
|
||||
logger.exception("link monitor error")
|
||||
|
||||
# find new links
|
||||
current_links = set(self.links.keys())
|
||||
|
|
|
@ -19,6 +19,8 @@ from core.errors import CoreError
|
|||
from core.nodes.base import CoreNetworkBase, CoreNode
|
||||
from core.nodes.interface import CoreInterface
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.emane.emanemodel import EmaneModel
|
||||
from core.emulator.session import Session
|
||||
|
@ -34,7 +36,7 @@ except ImportError:
|
|||
from emanesh.events import LocationEvent
|
||||
except ImportError:
|
||||
LocationEvent = None
|
||||
logging.debug("compatible emane python bindings not installed")
|
||||
logger.debug("compatible emane python bindings not installed")
|
||||
|
||||
|
||||
class EmaneNet(CoreNetworkBase):
|
||||
|
@ -92,9 +94,7 @@ class EmaneNet(CoreNetworkBase):
|
|||
def updatemodel(self, config: Dict[str, str]) -> None:
|
||||
if not self.model:
|
||||
raise CoreError(f"no model set to update for node({self.name})")
|
||||
logging.info(
|
||||
"node(%s) updating model(%s): %s", self.id, self.model.name, config
|
||||
)
|
||||
logger.info("node(%s) updating model(%s): %s", self.id, self.model.name, config)
|
||||
self.model.update_config(config)
|
||||
|
||||
def setmodel(self, model: "WirelessModelType", config: Dict[str, str]) -> None:
|
||||
|
@ -122,7 +122,7 @@ class EmaneNet(CoreNetworkBase):
|
|||
nem_id = self.session.emane.get_nem_id(iface)
|
||||
ifname = iface.localname
|
||||
if nem_id is None:
|
||||
logging.info("nemid for %s is unknown", ifname)
|
||||
logger.info("nemid for %s is unknown", ifname)
|
||||
return
|
||||
node = iface.node
|
||||
x, y, z = node.getposition()
|
||||
|
@ -141,7 +141,7 @@ class EmaneNet(CoreNetworkBase):
|
|||
:param iface: interface to set nem position for
|
||||
"""
|
||||
if self.session.emane.service is None:
|
||||
logging.info("position service not available")
|
||||
logger.info("position service not available")
|
||||
return
|
||||
position = self._nem_position(iface)
|
||||
if position:
|
||||
|
@ -160,7 +160,7 @@ class EmaneNet(CoreNetworkBase):
|
|||
return
|
||||
|
||||
if self.session.emane.service is None:
|
||||
logging.info("position service not available")
|
||||
logger.info("position service not available")
|
||||
return
|
||||
|
||||
event = LocationEvent()
|
||||
|
|
|
@ -11,6 +11,8 @@ from core.config import Configuration
|
|||
from core.emane import emanemodel
|
||||
from core.emulator.enumerations import ConfigDataTypes
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class EmaneTdmaModel(emanemodel.EmaneModel):
|
||||
# model name
|
||||
|
@ -58,7 +60,7 @@ class EmaneTdmaModel(emanemodel.EmaneModel):
|
|||
event_device = self.session.emane.event_device
|
||||
|
||||
# initiate tdma schedule
|
||||
logging.info(
|
||||
logger.info(
|
||||
"setting up tdma schedule: schedule(%s) device(%s)", schedule, event_device
|
||||
)
|
||||
args = f"emaneevent-tdmaschedule -i {event_device} {schedule}"
|
||||
|
|
|
@ -13,6 +13,8 @@ from core.emulator.session import Session
|
|||
from core.executables import get_requirements
|
||||
from core.services.coreservices import ServiceManager
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def signal_handler(signal_number: int, _) -> None:
|
||||
"""
|
||||
|
@ -22,7 +24,7 @@ def signal_handler(signal_number: int, _) -> None:
|
|||
:param _: ignored
|
||||
:return: nothing
|
||||
"""
|
||||
logging.info("caught signal: %s", signal_number)
|
||||
logger.info("caught signal: %s", signal_number)
|
||||
sys.exit(signal_number)
|
||||
|
||||
|
||||
|
@ -95,7 +97,7 @@ class CoreEmu:
|
|||
self.service_errors = core.services.load()
|
||||
# load custom services
|
||||
service_paths = self.config.get("custom_services_dir")
|
||||
logging.debug("custom service paths: %s", service_paths)
|
||||
logger.debug("custom service paths: %s", service_paths)
|
||||
if service_paths is not None:
|
||||
for service_path in service_paths.split(","):
|
||||
service_path = Path(service_path.strip())
|
||||
|
@ -108,7 +110,7 @@ class CoreEmu:
|
|||
|
||||
:return: nothing
|
||||
"""
|
||||
logging.info("shutting down all sessions")
|
||||
logger.info("shutting down all sessions")
|
||||
sessions = self.sessions.copy()
|
||||
self.sessions.clear()
|
||||
for _id in sessions:
|
||||
|
@ -129,7 +131,7 @@ class CoreEmu:
|
|||
_id += 1
|
||||
session = _cls(_id, config=self.config)
|
||||
session.service_manager = self.service_manager
|
||||
logging.info("created session: %s", _id)
|
||||
logger.info("created session: %s", _id)
|
||||
self.sessions[_id] = session
|
||||
return session
|
||||
|
||||
|
@ -140,14 +142,14 @@ class CoreEmu:
|
|||
:param _id: session id to delete
|
||||
:return: True if deleted, False otherwise
|
||||
"""
|
||||
logging.info("deleting session: %s", _id)
|
||||
logger.info("deleting session: %s", _id)
|
||||
session = self.sessions.pop(_id, None)
|
||||
result = False
|
||||
if session:
|
||||
logging.info("shutting session down: %s", _id)
|
||||
logger.info("shutting session down: %s", _id)
|
||||
session.data_collect()
|
||||
session.shutdown()
|
||||
result = True
|
||||
else:
|
||||
logging.error("session to delete did not exist: %s", _id)
|
||||
logger.error("session to delete did not exist: %s", _id)
|
||||
return result
|
||||
|
|
|
@ -20,6 +20,8 @@ from core.executables import get_requirements
|
|||
from core.nodes.interface import GreTap
|
||||
from core.nodes.network import CoreNetwork, CtrlNet
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.emulator.session import Session
|
||||
|
||||
|
@ -62,7 +64,7 @@ class DistributedServer:
|
|||
replace_env = env is not None
|
||||
if not wait:
|
||||
cmd += " &"
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
"remote cmd server(%s) cwd(%s) wait(%s): %s", self.host, cwd, wait, cmd
|
||||
)
|
||||
try:
|
||||
|
@ -212,13 +214,11 @@ class DistributedController:
|
|||
if tunnel is not None:
|
||||
return tunnel
|
||||
# local to server
|
||||
logging.info(
|
||||
"local tunnel node(%s) to remote(%s) key(%s)", node.name, host, key
|
||||
)
|
||||
logger.info("local tunnel node(%s) to remote(%s) key(%s)", node.name, host, key)
|
||||
local_tap = GreTap(session=self.session, remoteip=host, key=key)
|
||||
local_tap.net_client.set_iface_master(node.brname, local_tap.localname)
|
||||
# server to local
|
||||
logging.info(
|
||||
logger.info(
|
||||
"remote tunnel node(%s) to local(%s) key(%s)", node.name, self.address, key
|
||||
)
|
||||
remote_tap = GreTap(
|
||||
|
@ -240,7 +240,7 @@ class DistributedController:
|
|||
:param node2_id: node two id
|
||||
:return: tunnel key for the node pair
|
||||
"""
|
||||
logging.debug("creating tunnel key for: %s, %s", node1_id, node2_id)
|
||||
logger.debug("creating tunnel key for: %s, %s", node1_id, node2_id)
|
||||
key = (
|
||||
(self.session.id << 16)
|
||||
^ utils.hashkey(node1_id)
|
||||
|
|
|
@ -62,6 +62,8 @@ from core.services.coreservices import CoreServices
|
|||
from core.xml import corexml, corexmldeployment
|
||||
from core.xml.corexml import CoreXmlReader, CoreXmlWriter
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# maps for converting from API call node type values to classes and vice versa
|
||||
NODES: Dict[NodeTypes, Type[NodeBase]] = {
|
||||
NodeTypes.DEFAULT: CoreNode,
|
||||
|
@ -197,7 +199,7 @@ class Session:
|
|||
:raises core.CoreError: when objects to link is less than 2, or no common
|
||||
networks are found
|
||||
"""
|
||||
logging.info(
|
||||
logger.info(
|
||||
"handling wireless linking node1(%s) node2(%s): %s",
|
||||
node1.name,
|
||||
node2.name,
|
||||
|
@ -208,7 +210,7 @@ class Session:
|
|||
raise CoreError("no common network found for wireless link/unlink")
|
||||
for common_network, iface1, iface2 in common_networks:
|
||||
if not isinstance(common_network, (WlanNode, EmaneNet)):
|
||||
logging.info(
|
||||
logger.info(
|
||||
"skipping common network that is not wireless/emane: %s",
|
||||
common_network,
|
||||
)
|
||||
|
@ -263,7 +265,7 @@ class Session:
|
|||
else:
|
||||
# peer to peer link
|
||||
if isinstance(node1, CoreNodeBase) and isinstance(node2, CoreNodeBase):
|
||||
logging.info("linking ptp: %s - %s", node1.name, node2.name)
|
||||
logger.info("linking ptp: %s - %s", node1.name, node2.name)
|
||||
start = self.state.should_start()
|
||||
ptp = self.create_node(PtpNet, start)
|
||||
iface1 = node1.new_iface(ptp, iface1_data)
|
||||
|
@ -286,7 +288,7 @@ class Session:
|
|||
elif isinstance(node1, CoreNetworkBase) and isinstance(
|
||||
node2, CoreNetworkBase
|
||||
):
|
||||
logging.info(
|
||||
logger.info(
|
||||
"linking network to network: %s - %s", node1.name, node2.name
|
||||
)
|
||||
iface1 = node1.linknet(node2)
|
||||
|
@ -303,10 +305,10 @@ class Session:
|
|||
# configure tunnel nodes
|
||||
key = options.key
|
||||
if isinstance(node1, TunnelNode):
|
||||
logging.info("setting tunnel key for: %s", node1.name)
|
||||
logger.info("setting tunnel key for: %s", node1.name)
|
||||
node1.setkey(key, iface1_data)
|
||||
if isinstance(node2, TunnelNode):
|
||||
logging.info("setting tunnel key for: %s", node2.name)
|
||||
logger.info("setting tunnel key for: %s", node2.name)
|
||||
node2.setkey(key, iface2_data)
|
||||
self.sdt.add_link(node1_id, node2_id)
|
||||
return iface1, iface2
|
||||
|
@ -332,7 +334,7 @@ class Session:
|
|||
"""
|
||||
node1 = self.get_node(node1_id, NodeBase)
|
||||
node2 = self.get_node(node2_id, NodeBase)
|
||||
logging.info(
|
||||
logger.info(
|
||||
"deleting link(%s) node(%s):interface(%s) node(%s):interface(%s)",
|
||||
link_type.name,
|
||||
node1.name,
|
||||
|
@ -409,7 +411,7 @@ class Session:
|
|||
options = LinkOptions()
|
||||
node1 = self.get_node(node1_id, NodeBase)
|
||||
node2 = self.get_node(node2_id, NodeBase)
|
||||
logging.info(
|
||||
logger.info(
|
||||
"update link(%s) node(%s):interface(%s) node(%s):interface(%s)",
|
||||
link_type.name,
|
||||
node1.name,
|
||||
|
@ -525,7 +527,7 @@ class Session:
|
|||
raise CoreError(f"invalid distributed server: {options.server}")
|
||||
|
||||
# create node
|
||||
logging.info(
|
||||
logger.info(
|
||||
"creating node(%s) id(%s) name(%s) start(%s)",
|
||||
_class.__name__,
|
||||
_id,
|
||||
|
@ -547,11 +549,11 @@ class Session:
|
|||
# add services to needed nodes
|
||||
if isinstance(node, (CoreNode, PhysicalNode)):
|
||||
node.type = options.model
|
||||
logging.debug("set node type: %s", node.type)
|
||||
logger.debug("set node type: %s", node.type)
|
||||
self.services.add_services(node, node.type, options.services)
|
||||
|
||||
# add config services
|
||||
logging.info("setting node config services: %s", options.config_services)
|
||||
logger.info("setting node config services: %s", options.config_services)
|
||||
for name in options.config_services:
|
||||
service_class = self.service_manager.get_service(name)
|
||||
node.add_config_service(service_class)
|
||||
|
@ -638,7 +640,7 @@ class Session:
|
|||
:return: True if active, False otherwise
|
||||
"""
|
||||
result = self.state in {EventTypes.RUNTIME_STATE, EventTypes.DATACOLLECT_STATE}
|
||||
logging.info("session(%s) checking if active: %s", self.id, result)
|
||||
logger.info("session(%s) checking if active: %s", self.id, result)
|
||||
return result
|
||||
|
||||
def open_xml(self, file_path: Path, start: bool = False) -> None:
|
||||
|
@ -649,7 +651,7 @@ class Session:
|
|||
:param start: instantiate session if true, false otherwise
|
||||
:return: nothing
|
||||
"""
|
||||
logging.info("opening xml: %s", file_path)
|
||||
logger.info("opening xml: %s", file_path)
|
||||
# clear out existing session
|
||||
self.clear()
|
||||
# set state and read xml
|
||||
|
@ -684,7 +686,7 @@ class Session:
|
|||
:param src_name: source name
|
||||
:return: nothing
|
||||
"""
|
||||
logging.info(
|
||||
logger.info(
|
||||
"setting state hook: %s - %s source(%s)", state, file_name, src_name
|
||||
)
|
||||
hook = file_name, data
|
||||
|
@ -693,7 +695,7 @@ class Session:
|
|||
|
||||
# immediately run a hook if it is in the current state
|
||||
if self.state == state:
|
||||
logging.info("immediately running new state hook")
|
||||
logger.info("immediately running new state hook")
|
||||
self.run_hook(hook)
|
||||
|
||||
def add_node_file(
|
||||
|
@ -766,9 +768,9 @@ class Session:
|
|||
Shutdown all session nodes and remove the session directory.
|
||||
"""
|
||||
if self.state == EventTypes.SHUTDOWN_STATE:
|
||||
logging.info("session(%s) state(%s) already shutdown", self.id, self.state)
|
||||
logger.info("session(%s) state(%s) already shutdown", self.id, self.state)
|
||||
else:
|
||||
logging.info("session(%s) state(%s) shutting down", self.id, self.state)
|
||||
logger.info("session(%s) state(%s) shutting down", self.id, self.state)
|
||||
self.set_state(EventTypes.SHUTDOWN_STATE, send_event=True)
|
||||
# clear out current core session
|
||||
self.clear()
|
||||
|
@ -861,7 +863,7 @@ class Session:
|
|||
return
|
||||
self.state = state
|
||||
self.state_time = time.monotonic()
|
||||
logging.info("changing session(%s) to state %s", self.id, state.name)
|
||||
logger.info("changing session(%s) to state %s", self.id, state.name)
|
||||
self.write_state(state)
|
||||
self.run_hooks(state)
|
||||
self.run_state_hooks(state)
|
||||
|
@ -881,7 +883,7 @@ class Session:
|
|||
with state_file.open("w") as f:
|
||||
f.write(f"{state.value} {state.name}\n")
|
||||
except IOError:
|
||||
logging.exception("error writing state file: %s", state.name)
|
||||
logger.exception("error writing state file: %s", state.name)
|
||||
|
||||
def run_hooks(self, state: EventTypes) -> None:
|
||||
"""
|
||||
|
@ -903,7 +905,7 @@ class Session:
|
|||
:return: nothing
|
||||
"""
|
||||
file_name, data = hook
|
||||
logging.info("running hook %s", file_name)
|
||||
logger.info("running hook %s", file_name)
|
||||
file_path = self.directory / file_name
|
||||
log_path = self.directory / f"{file_name}.log"
|
||||
try:
|
||||
|
@ -920,7 +922,7 @@ class Session:
|
|||
env=self.get_environment(),
|
||||
)
|
||||
except (IOError, subprocess.CalledProcessError):
|
||||
logging.exception("error running hook: %s", file_path)
|
||||
logger.exception("error running hook: %s", file_path)
|
||||
|
||||
def run_state_hooks(self, state: EventTypes) -> None:
|
||||
"""
|
||||
|
@ -937,7 +939,7 @@ class Session:
|
|||
hook(state)
|
||||
except Exception:
|
||||
message = f"exception occurred when running {state.name} state hook: {hook}"
|
||||
logging.exception(message)
|
||||
logger.exception(message)
|
||||
self.exception(ExceptionLevels.ERROR, "Session.run_state_hooks", message)
|
||||
|
||||
def add_state_hook(
|
||||
|
@ -1022,7 +1024,7 @@ class Session:
|
|||
try:
|
||||
utils.load_config(path, env)
|
||||
except IOError:
|
||||
logging.exception("error reading environment file: %s", path)
|
||||
logger.exception("error reading environment file: %s", path)
|
||||
return env
|
||||
|
||||
def set_thumbnail(self, thumb_file: Path) -> None:
|
||||
|
@ -1033,7 +1035,7 @@ class Session:
|
|||
:return: nothing
|
||||
"""
|
||||
if not thumb_file.is_file():
|
||||
logging.error("thumbnail file to set does not exist: %s", thumb_file)
|
||||
logger.error("thumbnail file to set does not exist: %s", thumb_file)
|
||||
self.thumbnail = None
|
||||
return
|
||||
dst_path = self.directory / thumb_file.name
|
||||
|
@ -1054,7 +1056,7 @@ class Session:
|
|||
gid = self.directory.stat().st_gid
|
||||
os.chown(self.directory, uid, gid)
|
||||
except IOError:
|
||||
logging.exception("failed to set permission on %s", self.directory)
|
||||
logger.exception("failed to set permission on %s", self.directory)
|
||||
self.user = user
|
||||
|
||||
def create_node(
|
||||
|
@ -1111,7 +1113,7 @@ class Session:
|
|||
with self.nodes_lock:
|
||||
if _id in self.nodes:
|
||||
node = self.nodes.pop(_id)
|
||||
logging.info("deleted node(%s)", node.name)
|
||||
logger.info("deleted node(%s)", node.name)
|
||||
if node:
|
||||
node.shutdown()
|
||||
self.sdt.delete_node(_id)
|
||||
|
@ -1144,7 +1146,7 @@ class Session:
|
|||
for _id, node in self.nodes.items():
|
||||
f.write(f"{_id} {node.name} {node.apitype} {type(node)}\n")
|
||||
except IOError:
|
||||
logging.exception("error writing nodes file")
|
||||
logger.exception("error writing nodes file")
|
||||
|
||||
def exception(
|
||||
self, level: ExceptionLevels, source: str, text: str, node_id: int = None
|
||||
|
@ -1235,13 +1237,13 @@ class Session:
|
|||
"""
|
||||
# this is called from instantiate() after receiving an event message
|
||||
# for the instantiation state
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
"session(%s) checking if not in runtime state, current state: %s",
|
||||
self.id,
|
||||
self.state.name,
|
||||
)
|
||||
if self.state == EventTypes.RUNTIME_STATE:
|
||||
logging.info("valid runtime state found, returning")
|
||||
logger.info("valid runtime state found, returning")
|
||||
return
|
||||
# start event loop and set to runtime
|
||||
self.event_loop.run()
|
||||
|
@ -1255,11 +1257,11 @@ class Session:
|
|||
:return: nothing
|
||||
"""
|
||||
if self.state.already_collected():
|
||||
logging.info(
|
||||
logger.info(
|
||||
"session(%s) state(%s) already data collected", self.id, self.state
|
||||
)
|
||||
return
|
||||
logging.info("session(%s) state(%s) data collection", self.id, self.state)
|
||||
logger.info("session(%s) state(%s) data collection", self.id, self.state)
|
||||
self.set_state(EventTypes.DATACOLLECT_STATE, send_event=True)
|
||||
|
||||
# stop event loop
|
||||
|
@ -1302,7 +1304,7 @@ class Session:
|
|||
:param node: node to boot
|
||||
:return: nothing
|
||||
"""
|
||||
logging.info("booting node(%s): %s", node.name, [x.name for x in node.services])
|
||||
logger.info("booting node(%s): %s", node.name, [x.name for x in node.services])
|
||||
self.services.boot_services(node)
|
||||
node.start_config_services()
|
||||
|
||||
|
@ -1323,7 +1325,7 @@ class Session:
|
|||
funcs.append((self.boot_node, (node,), {}))
|
||||
results, exceptions = utils.threadpool(funcs)
|
||||
total = time.monotonic() - start
|
||||
logging.debug("boot run time: %s", total)
|
||||
logger.debug("boot run time: %s", total)
|
||||
if not exceptions:
|
||||
self.update_control_iface_hosts()
|
||||
return exceptions
|
||||
|
@ -1351,7 +1353,7 @@ class Session:
|
|||
"""
|
||||
d0 = self.options.get_config("controlnetif0")
|
||||
if d0:
|
||||
logging.error("controlnet0 cannot be assigned with a host interface")
|
||||
logger.error("controlnet0 cannot be assigned with a host interface")
|
||||
d1 = self.options.get_config("controlnetif1")
|
||||
d2 = self.options.get_config("controlnetif2")
|
||||
d3 = self.options.get_config("controlnetif3")
|
||||
|
@ -1396,7 +1398,7 @@ class Session:
|
|||
:param conf_required: flag to check if conf is required
|
||||
:return: control net node
|
||||
"""
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
"add/remove control net: index(%s) remove(%s) conf_required(%s)",
|
||||
net_index,
|
||||
remove,
|
||||
|
@ -1410,7 +1412,7 @@ class Session:
|
|||
return None
|
||||
else:
|
||||
prefix_spec = CtrlNet.DEFAULT_PREFIX_LIST[net_index]
|
||||
logging.debug("prefix spec: %s", prefix_spec)
|
||||
logger.debug("prefix spec: %s", prefix_spec)
|
||||
server_iface = self.get_control_net_server_ifaces()[net_index]
|
||||
|
||||
# return any existing controlnet bridge
|
||||
|
@ -1433,7 +1435,7 @@ class Session:
|
|||
if net_index == 0:
|
||||
updown_script = self.options.get_config("controlnet_updown_script")
|
||||
if not updown_script:
|
||||
logging.debug("controlnet updown script not configured")
|
||||
logger.debug("controlnet updown script not configured")
|
||||
|
||||
prefixes = prefix_spec.split()
|
||||
if len(prefixes) > 1:
|
||||
|
@ -1447,7 +1449,7 @@ class Session:
|
|||
else:
|
||||
prefix = prefixes[0]
|
||||
|
||||
logging.info(
|
||||
logger.info(
|
||||
"controlnet(%s) prefix(%s) updown(%s) serverintf(%s)",
|
||||
_id,
|
||||
prefix,
|
||||
|
@ -1510,7 +1512,7 @@ class Session:
|
|||
msg = f"Control interface not added to node {node.id}. "
|
||||
msg += f"Invalid control network prefix ({control_net.prefix}). "
|
||||
msg += "A longer prefix length may be required for this many nodes."
|
||||
logging.exception(msg)
|
||||
logger.exception(msg)
|
||||
|
||||
def update_control_iface_hosts(
|
||||
self, net_index: int = 0, remove: bool = False
|
||||
|
@ -1528,12 +1530,12 @@ class Session:
|
|||
try:
|
||||
control_net = self.get_control_net(net_index)
|
||||
except CoreError:
|
||||
logging.exception("error retrieving control net node")
|
||||
logger.exception("error retrieving control net node")
|
||||
return
|
||||
|
||||
header = f"CORE session {self.id} host entries"
|
||||
if remove:
|
||||
logging.info("Removing /etc/hosts file entries.")
|
||||
logger.info("Removing /etc/hosts file entries.")
|
||||
utils.file_demunge("/etc/hosts", header)
|
||||
return
|
||||
|
||||
|
@ -1543,7 +1545,7 @@ class Session:
|
|||
for ip in iface.ips():
|
||||
entries.append(f"{ip.ip} {name}")
|
||||
|
||||
logging.info("Adding %d /etc/hosts file entries.", len(entries))
|
||||
logger.info("Adding %d /etc/hosts file entries.", len(entries))
|
||||
utils.file_munge("/etc/hosts", header, "\n".join(entries) + "\n")
|
||||
|
||||
def runtime(self) -> float:
|
||||
|
@ -1572,7 +1574,7 @@ class Session:
|
|||
current_time = self.runtime()
|
||||
if current_time > 0:
|
||||
if event_time <= current_time:
|
||||
logging.warning(
|
||||
logger.warning(
|
||||
"could not schedule past event for time %s (run time is now %s)",
|
||||
event_time,
|
||||
current_time,
|
||||
|
@ -1584,7 +1586,7 @@ class Session:
|
|||
)
|
||||
if not name:
|
||||
name = ""
|
||||
logging.info(
|
||||
logger.info(
|
||||
"scheduled event %s at time %s data=%s",
|
||||
name,
|
||||
event_time + current_time,
|
||||
|
@ -1603,12 +1605,12 @@ class Session:
|
|||
:return: nothing
|
||||
"""
|
||||
if data is None:
|
||||
logging.warning("no data for event node(%s) name(%s)", node_id, name)
|
||||
logger.warning("no data for event node(%s) name(%s)", node_id, name)
|
||||
return
|
||||
now = self.runtime()
|
||||
if not name:
|
||||
name = ""
|
||||
logging.info("running event %s at time %s cmd=%s", name, now, data)
|
||||
logger.info("running event %s at time %s cmd=%s", name, now, data)
|
||||
if not node_id:
|
||||
utils.mute_detach(data)
|
||||
else:
|
||||
|
|
|
@ -22,6 +22,7 @@ from core.gui.statusbar import StatusBar
|
|||
from core.gui.themes import PADY
|
||||
from core.gui.toolbar import Toolbar
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
WIDTH: int = 1000
|
||||
HEIGHT: int = 800
|
||||
|
||||
|
@ -171,7 +172,7 @@ class Application(ttk.Frame):
|
|||
def show_grpc_exception(
|
||||
self, message: str, e: grpc.RpcError, blocking: bool = False
|
||||
) -> None:
|
||||
logging.exception("app grpc exception", exc_info=e)
|
||||
logger.exception("app grpc exception", exc_info=e)
|
||||
dialog = ErrorDialog(self, "GRPC Exception", message, e.details())
|
||||
if blocking:
|
||||
dialog.show()
|
||||
|
@ -179,7 +180,7 @@ class Application(ttk.Frame):
|
|||
self.after(0, lambda: dialog.show())
|
||||
|
||||
def show_exception(self, message: str, e: Exception) -> None:
|
||||
logging.exception("app exception", exc_info=e)
|
||||
logger.exception("app exception", exc_info=e)
|
||||
self.after(
|
||||
0, lambda: ErrorDialog(self, "App Exception", message, str(e)).show()
|
||||
)
|
||||
|
|
|
@ -46,6 +46,8 @@ from core.gui.graph.shape import Shape
|
|||
from core.gui.interface import InterfaceManager
|
||||
from core.gui.nodeutils import NodeDraw
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.gui.app import Application
|
||||
|
||||
|
@ -150,7 +152,7 @@ class CoreClient:
|
|||
if not self.session or event.source == GUI_SOURCE:
|
||||
return
|
||||
if event.session_id != self.session.id:
|
||||
logging.warning(
|
||||
logger.warning(
|
||||
"ignoring event session(%s) current(%s)",
|
||||
event.session_id,
|
||||
self.session.id,
|
||||
|
@ -159,7 +161,7 @@ class CoreClient:
|
|||
if event.link_event:
|
||||
self.app.after(0, self.handle_link_event, event.link_event)
|
||||
elif event.session_event:
|
||||
logging.info("session event: %s", event)
|
||||
logger.info("session event: %s", event)
|
||||
session_event = event.session_event
|
||||
if session_event.event <= SessionState.SHUTDOWN.value:
|
||||
self.session.state = SessionState(session_event.event)
|
||||
|
@ -174,22 +176,22 @@ class CoreClient:
|
|||
else:
|
||||
dialog.set_pause()
|
||||
else:
|
||||
logging.warning("unknown session event: %s", session_event)
|
||||
logger.warning("unknown session event: %s", session_event)
|
||||
elif event.node_event:
|
||||
self.app.after(0, self.handle_node_event, event.node_event)
|
||||
elif event.config_event:
|
||||
logging.info("config event: %s", event)
|
||||
logger.info("config event: %s", event)
|
||||
elif event.exception_event:
|
||||
self.handle_exception_event(event.exception_event)
|
||||
else:
|
||||
logging.info("unhandled event: %s", event)
|
||||
logger.info("unhandled event: %s", event)
|
||||
|
||||
def handle_link_event(self, event: LinkEvent) -> None:
|
||||
logging.debug("Link event: %s", event)
|
||||
logger.debug("Link event: %s", event)
|
||||
node1_id = event.link.node1_id
|
||||
node2_id = event.link.node2_id
|
||||
if node1_id == node2_id:
|
||||
logging.warning("ignoring links with loops: %s", event)
|
||||
logger.warning("ignoring links with loops: %s", event)
|
||||
return
|
||||
canvas_node1 = self.canvas_nodes[node1_id]
|
||||
canvas_node2 = self.canvas_nodes[node2_id]
|
||||
|
@ -207,7 +209,7 @@ class CoreClient:
|
|||
canvas_node1, canvas_node2, event.link
|
||||
)
|
||||
else:
|
||||
logging.warning("unknown link event: %s", event)
|
||||
logger.warning("unknown link event: %s", event)
|
||||
else:
|
||||
if event.message_type == MessageType.ADD:
|
||||
self.app.manager.add_wired_edge(canvas_node1, canvas_node2, event.link)
|
||||
|
@ -216,10 +218,10 @@ class CoreClient:
|
|||
elif event.message_type == MessageType.NONE:
|
||||
self.app.manager.update_wired_edge(event.link)
|
||||
else:
|
||||
logging.warning("unknown link event: %s", event)
|
||||
logger.warning("unknown link event: %s", event)
|
||||
|
||||
def handle_node_event(self, event: NodeEvent) -> None:
|
||||
logging.debug("node event: %s", event)
|
||||
logger.debug("node event: %s", event)
|
||||
node = event.node
|
||||
if event.message_type == MessageType.NONE:
|
||||
canvas_node = self.canvas_nodes[node.id]
|
||||
|
@ -235,10 +237,10 @@ class CoreClient:
|
|||
canvas_node.canvas.delete_selected_objects()
|
||||
elif event.message_type == MessageType.ADD:
|
||||
if node.id in self.session.nodes:
|
||||
logging.error("core node already exists: %s", node)
|
||||
logger.error("core node already exists: %s", node)
|
||||
self.app.manager.add_core_node(node)
|
||||
else:
|
||||
logging.warning("unknown node event: %s", event)
|
||||
logger.warning("unknown node event: %s", event)
|
||||
|
||||
def enable_throughputs(self) -> None:
|
||||
self.handling_throughputs = self.client.throughputs(
|
||||
|
@ -272,24 +274,24 @@ class CoreClient:
|
|||
|
||||
def handle_throughputs(self, event: ThroughputsEvent) -> None:
|
||||
if event.session_id != self.session.id:
|
||||
logging.warning(
|
||||
logger.warning(
|
||||
"ignoring throughput event session(%s) current(%s)",
|
||||
event.session_id,
|
||||
self.session.id,
|
||||
)
|
||||
return
|
||||
logging.debug("handling throughputs event: %s", event)
|
||||
logger.debug("handling throughputs event: %s", event)
|
||||
self.app.after(0, self.app.manager.set_throughputs, event)
|
||||
|
||||
def handle_cpu_event(self, event: core_pb2.CpuUsageEvent) -> None:
|
||||
self.app.after(0, self.app.statusbar.set_cpu, event.usage)
|
||||
|
||||
def handle_exception_event(self, event: ExceptionEvent) -> None:
|
||||
logging.info("exception event: %s", event)
|
||||
logger.info("exception event: %s", event)
|
||||
self.app.statusbar.add_alert(event)
|
||||
|
||||
def join_session(self, session_id: int) -> None:
|
||||
logging.info("joining session(%s)", session_id)
|
||||
logger.info("joining session(%s)", session_id)
|
||||
self.reset()
|
||||
try:
|
||||
self.session = self.client.get_session(session_id)
|
||||
|
@ -314,7 +316,7 @@ class CoreClient:
|
|||
# canvas setting
|
||||
config = self.session.metadata
|
||||
canvas_config = config.get("canvas")
|
||||
logging.debug("canvas metadata: %s", canvas_config)
|
||||
logger.debug("canvas metadata: %s", canvas_config)
|
||||
if canvas_config:
|
||||
canvas_config = json.loads(canvas_config)
|
||||
self.app.manager.parse_metadata(canvas_config)
|
||||
|
@ -324,14 +326,14 @@ class CoreClient:
|
|||
if shapes_config:
|
||||
shapes_config = json.loads(shapes_config)
|
||||
for shape_config in shapes_config:
|
||||
logging.debug("loading shape: %s", shape_config)
|
||||
logger.debug("loading shape: %s", shape_config)
|
||||
Shape.from_metadata(self.app, shape_config)
|
||||
|
||||
# load edges config
|
||||
edges_config = config.get("edges")
|
||||
if edges_config:
|
||||
edges_config = json.loads(edges_config)
|
||||
logging.info("edges config: %s", edges_config)
|
||||
logger.info("edges config: %s", edges_config)
|
||||
for edge_config in edges_config:
|
||||
edge = self.links[edge_config["token"]]
|
||||
edge.width = edge_config["width"]
|
||||
|
@ -347,7 +349,7 @@ class CoreClient:
|
|||
if canvas_node:
|
||||
canvas_node.hide()
|
||||
else:
|
||||
logging.warning("invalid node to hide: %s", _id)
|
||||
logger.warning("invalid node to hide: %s", _id)
|
||||
|
||||
def create_new_session(self) -> None:
|
||||
"""
|
||||
|
@ -355,7 +357,7 @@ class CoreClient:
|
|||
"""
|
||||
try:
|
||||
session_id = self.client.create_session()
|
||||
logging.info("created session: %s", session_id)
|
||||
logger.info("created session: %s", session_id)
|
||||
self.join_session(session_id)
|
||||
location_config = self.app.guiconfig.location
|
||||
self.session.location = SessionLocation(
|
||||
|
@ -377,7 +379,7 @@ class CoreClient:
|
|||
session_id = self.session.id
|
||||
try:
|
||||
response = self.client.delete_session(session_id)
|
||||
logging.info("deleted session(%s), Result: %s", session_id, response)
|
||||
logger.info("deleted session(%s), Result: %s", session_id, response)
|
||||
except grpc.RpcError as e:
|
||||
self.app.show_grpc_exception("Delete Session Error", e)
|
||||
|
||||
|
@ -419,7 +421,7 @@ class CoreClient:
|
|||
dialog = SessionsDialog(self.app, True)
|
||||
dialog.show()
|
||||
except grpc.RpcError as e:
|
||||
logging.exception("core setup error")
|
||||
logger.exception("core setup error")
|
||||
self.app.show_grpc_exception("Setup Error", e, blocking=True)
|
||||
self.app.close()
|
||||
|
||||
|
@ -456,7 +458,7 @@ class CoreClient:
|
|||
result, exceptions = self.client.start_session(
|
||||
self.session, asymmetric_links
|
||||
)
|
||||
logging.info("start session(%s), result: %s", self.session.id, result)
|
||||
logger.info("start session(%s), result: %s", self.session.id, result)
|
||||
if result:
|
||||
self.set_metadata()
|
||||
except grpc.RpcError as e:
|
||||
|
@ -469,7 +471,7 @@ class CoreClient:
|
|||
result = False
|
||||
try:
|
||||
result = self.client.stop_session(session_id)
|
||||
logging.info("stopped session(%s), result: %s", session_id, result)
|
||||
logger.info("stopped session(%s), result: %s", session_id, result)
|
||||
except grpc.RpcError as e:
|
||||
self.app.show_grpc_exception("Stop Session Error", e)
|
||||
return result
|
||||
|
@ -513,7 +515,7 @@ class CoreClient:
|
|||
canvas=canvas_config, shapes=shapes, edges=edges_config, hidden=hidden
|
||||
)
|
||||
response = self.client.set_session_metadata(self.session.id, metadata)
|
||||
logging.debug("set session metadata %s, result: %s", metadata, response)
|
||||
logger.debug("set session metadata %s, result: %s", metadata, response)
|
||||
|
||||
def launch_terminal(self, node_id: int) -> None:
|
||||
try:
|
||||
|
@ -527,7 +529,7 @@ class CoreClient:
|
|||
return
|
||||
node_term = self.client.get_node_terminal(self.session.id, node_id)
|
||||
cmd = f"{terminal} {node_term} &"
|
||||
logging.info("launching terminal %s", cmd)
|
||||
logger.info("launching terminal %s", cmd)
|
||||
os.system(cmd)
|
||||
except grpc.RpcError as e:
|
||||
self.app.show_grpc_exception("Node Terminal Error", e)
|
||||
|
@ -540,16 +542,16 @@ class CoreClient:
|
|||
Save core session as to an xml file
|
||||
"""
|
||||
if not file_path and not self.session.file:
|
||||
logging.error("trying to save xml for session with no file")
|
||||
logger.error("trying to save xml for session with no file")
|
||||
return
|
||||
if not file_path:
|
||||
file_path = str(self.session.file)
|
||||
try:
|
||||
if not self.is_runtime():
|
||||
logging.debug("Send session data to the daemon")
|
||||
logger.debug("Send session data to the daemon")
|
||||
self.send_data()
|
||||
self.client.save_xml(self.session.id, file_path)
|
||||
logging.info("saved xml file %s", file_path)
|
||||
logger.info("saved xml file %s", file_path)
|
||||
except grpc.RpcError as e:
|
||||
self.app.show_grpc_exception("Save XML Error", e)
|
||||
|
||||
|
@ -559,7 +561,7 @@ class CoreClient:
|
|||
"""
|
||||
try:
|
||||
result, session_id = self._client.open_xml(file_path)
|
||||
logging.info(
|
||||
logger.info(
|
||||
"open xml file %s, result(%s) session(%s)",
|
||||
file_path,
|
||||
result,
|
||||
|
@ -573,14 +575,14 @@ class CoreClient:
|
|||
node_service = self.client.get_node_service(
|
||||
self.session.id, node_id, service_name
|
||||
)
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
"get node(%s) service(%s): %s", node_id, service_name, node_service
|
||||
)
|
||||
return node_service
|
||||
|
||||
def set_node_service(self, node_id: int, config: ServiceConfig) -> NodeServiceData:
|
||||
result = self.client.set_node_service(self.session.id, config)
|
||||
logging.info("set node service result(%s): %s", result, config)
|
||||
logger.info("set node service result(%s): %s", result, config)
|
||||
return self.client.get_node_service(self.session.id, node_id, config.service)
|
||||
|
||||
def get_node_service_file(
|
||||
|
@ -589,7 +591,7 @@ class CoreClient:
|
|||
data = self.client.get_node_service_file(
|
||||
self.session.id, node_id, service_name, file_name
|
||||
)
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
"get service file for node(%s), service: %s, file: %s, data: %s",
|
||||
node_id,
|
||||
service_name,
|
||||
|
@ -603,7 +605,7 @@ class CoreClient:
|
|||
) -> None:
|
||||
config = ServiceFileConfig(node_id, service_name, file_name, data)
|
||||
result = self.client.set_node_service_file(self.session.id, config)
|
||||
logging.info("set service file config %s: %s", config, result)
|
||||
logger.info("set service file config %s: %s", config, result)
|
||||
|
||||
def create_nodes_and_links(self) -> None:
|
||||
"""
|
||||
|
@ -612,7 +614,7 @@ class CoreClient:
|
|||
self.client.set_session_state(self.session.id, SessionState.DEFINITION)
|
||||
for node in self.session.nodes.values():
|
||||
node_id = self.client.add_node(self.session.id, node, source=GUI_SOURCE)
|
||||
logging.debug("created node: %s", node_id)
|
||||
logger.debug("created node: %s", node_id)
|
||||
asymmetric_links = []
|
||||
for edge in self.links.values():
|
||||
self.add_link(edge.link)
|
||||
|
@ -648,7 +650,7 @@ class CoreClient:
|
|||
"""
|
||||
Clean ups when done using grpc
|
||||
"""
|
||||
logging.debug("close grpc")
|
||||
logger.debug("close grpc")
|
||||
self.client.close()
|
||||
|
||||
def next_node_id(self) -> int:
|
||||
|
@ -704,7 +706,7 @@ class CoreClient:
|
|||
services = self.session.default_services.get(model)
|
||||
if services:
|
||||
node.services = services.copy()
|
||||
logging.info(
|
||||
logger.info(
|
||||
"add node(%s) to session(%s), coordinates(%s, %s)",
|
||||
node.name,
|
||||
self.session.id,
|
||||
|
@ -831,13 +833,13 @@ class CoreClient:
|
|||
return config_service_protos
|
||||
|
||||
def run(self, node_id: int) -> str:
|
||||
logging.info("running node(%s) cmd: %s", node_id, self.observer)
|
||||
logger.info("running node(%s) cmd: %s", node_id, self.observer)
|
||||
_, output = self.client.node_command(self.session.id, node_id, self.observer)
|
||||
return output
|
||||
|
||||
def get_wlan_config(self, node_id: int) -> Dict[str, ConfigOption]:
|
||||
config = self.client.get_wlan_config(self.session.id, node_id)
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
"get wlan configuration from node %s, result configuration: %s",
|
||||
node_id,
|
||||
config,
|
||||
|
@ -846,7 +848,7 @@ class CoreClient:
|
|||
|
||||
def get_mobility_config(self, node_id: int) -> Dict[str, ConfigOption]:
|
||||
config = self.client.get_mobility_config(self.session.id, node_id)
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
"get mobility config from node %s, result configuration: %s",
|
||||
node_id,
|
||||
config,
|
||||
|
@ -861,7 +863,7 @@ class CoreClient:
|
|||
config = self.client.get_emane_model_config(
|
||||
self.session.id, node_id, model, iface_id
|
||||
)
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
"get emane model config: node id: %s, EMANE model: %s, "
|
||||
"interface: %s, config: %s",
|
||||
node_id,
|
||||
|
@ -873,17 +875,17 @@ class CoreClient:
|
|||
|
||||
def execute_script(self, script) -> None:
|
||||
session_id = self.client.execute_script(script)
|
||||
logging.info("execute python script %s", session_id)
|
||||
logger.info("execute python script %s", session_id)
|
||||
if session_id != -1:
|
||||
self.join_session(session_id)
|
||||
|
||||
def add_link(self, link: Link) -> None:
|
||||
result, _, _ = self.client.add_link(self.session.id, link, source=GUI_SOURCE)
|
||||
logging.debug("added link: %s", result)
|
||||
logger.debug("added link: %s", result)
|
||||
if not result:
|
||||
logging.error("error adding link: %s", link)
|
||||
logger.error("error adding link: %s", link)
|
||||
|
||||
def edit_link(self, link: Link) -> None:
|
||||
result = self.client.edit_link(self.session.id, link, source=GUI_SOURCE)
|
||||
if not result:
|
||||
logging.error("error editing link: %s", link)
|
||||
logger.error("error editing link: %s", link)
|
||||
|
|
|
@ -13,6 +13,8 @@ from core.gui.graph.graph import CanvasGraph
|
|||
from core.gui.themes import PADX, PADY
|
||||
from core.gui.widgets import image_chooser
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.gui.app import Application
|
||||
|
||||
|
@ -167,5 +169,5 @@ class CanvasWallpaperDialog(Dialog):
|
|||
try:
|
||||
self.canvas.set_wallpaper(filename)
|
||||
except FileNotFoundError:
|
||||
logging.error("invalid background: %s", filename)
|
||||
logger.error("invalid background: %s", filename)
|
||||
self.destroy()
|
||||
|
|
|
@ -18,6 +18,8 @@ from core.gui.dialogs.dialog import Dialog
|
|||
from core.gui.themes import FRAME_PAD, PADX, PADY
|
||||
from core.gui.widgets import CodeText, ConfigFrame, ListboxScroll
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.gui.app import Application
|
||||
from core.gui.coreclient import CoreClient
|
||||
|
@ -97,7 +99,7 @@ class ConfigServiceConfigDialog(Dialog):
|
|||
if service_config:
|
||||
for key, value in service_config.config.items():
|
||||
self.config[key].value = value
|
||||
logging.info("default config: %s", self.default_config)
|
||||
logger.info("default config: %s", self.default_config)
|
||||
for file, data in service_config.templates.items():
|
||||
self.modified_files.add(file)
|
||||
self.temp_service_files[file] = data
|
||||
|
@ -181,7 +183,7 @@ class ConfigServiceConfigDialog(Dialog):
|
|||
self.modes_combobox.bind("<<ComboboxSelected>>", self.handle_mode_changed)
|
||||
self.modes_combobox.grid(row=0, column=1, sticky=tk.EW, pady=PADY)
|
||||
|
||||
logging.info("config service config: %s", self.config)
|
||||
logger.info("config service config: %s", self.config)
|
||||
self.config_frame = ConfigFrame(tab, self.app, self.config)
|
||||
self.config_frame.draw_config()
|
||||
self.config_frame.grid(sticky=tk.NSEW, pady=PADY)
|
||||
|
@ -328,7 +330,7 @@ class ConfigServiceConfigDialog(Dialog):
|
|||
def handle_mode_changed(self, event: tk.Event) -> None:
|
||||
mode = self.modes_combobox.get()
|
||||
config = self.mode_configs[mode]
|
||||
logging.info("mode config: %s", config)
|
||||
logger.info("mode config: %s", config)
|
||||
self.config_frame.set_values(config)
|
||||
|
||||
def update_template_file_data(self, event: tk.Event) -> None:
|
||||
|
@ -350,7 +352,7 @@ class ConfigServiceConfigDialog(Dialog):
|
|||
|
||||
def click_defaults(self) -> None:
|
||||
self.node.config_service_configs.pop(self.service_name, None)
|
||||
logging.info(
|
||||
logger.info(
|
||||
"cleared config service config: %s", self.node.config_service_configs
|
||||
)
|
||||
self.temp_service_files = dict(self.original_service_files)
|
||||
|
@ -358,7 +360,7 @@ class ConfigServiceConfigDialog(Dialog):
|
|||
self.template_text.text.delete(1.0, "end")
|
||||
self.template_text.text.insert("end", self.temp_service_files[filename])
|
||||
if self.config_frame:
|
||||
logging.info("resetting defaults: %s", self.default_config)
|
||||
logger.info("resetting defaults: %s", self.default_config)
|
||||
self.config_frame.set_values(self.default_config)
|
||||
|
||||
def click_copy(self) -> None:
|
||||
|
|
|
@ -13,6 +13,8 @@ from core.gui.nodeutils import NodeDraw
|
|||
from core.gui.themes import FRAME_PAD, PADX, PADY
|
||||
from core.gui.widgets import CheckboxList, ListboxScroll, image_chooser
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.gui.app import Application
|
||||
|
||||
|
@ -209,7 +211,7 @@ class CustomNodesDialog(Dialog):
|
|||
name, node_draw.image_file, list(node_draw.services)
|
||||
)
|
||||
self.app.guiconfig.nodes.append(custom_node)
|
||||
logging.info("saving custom nodes: %s", self.app.guiconfig.nodes)
|
||||
logger.info("saving custom nodes: %s", self.app.guiconfig.nodes)
|
||||
self.app.save_config()
|
||||
self.destroy()
|
||||
|
||||
|
@ -219,7 +221,7 @@ class CustomNodesDialog(Dialog):
|
|||
image_file = str(Path(self.image_file).absolute())
|
||||
custom_node = CustomNode(name, image_file, list(self.services))
|
||||
node_draw = NodeDraw.from_custom(custom_node)
|
||||
logging.info(
|
||||
logger.info(
|
||||
"created new custom node (%s), image file (%s), services: (%s)",
|
||||
name,
|
||||
image_file,
|
||||
|
@ -239,7 +241,7 @@ class CustomNodesDialog(Dialog):
|
|||
node_draw.image_file = str(Path(self.image_file).absolute())
|
||||
node_draw.image = self.image
|
||||
node_draw.services = set(self.services)
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
"edit custom node (%s), image: (%s), services (%s)",
|
||||
node_draw.model,
|
||||
node_draw.image_file,
|
||||
|
|
|
@ -7,6 +7,8 @@ from core.gui.appconfig import SCRIPT_PATH
|
|||
from core.gui.dialogs.dialog import Dialog
|
||||
from core.gui.themes import FRAME_PAD, PADX
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.gui.app import Application
|
||||
|
||||
|
@ -83,6 +85,6 @@ class ExecutePythonDialog(Dialog):
|
|||
def script_execute(self) -> None:
|
||||
file = self.file_entry.get()
|
||||
options = self.option_entry.get()
|
||||
logging.info("Execute %s with options %s", file, options)
|
||||
logger.info("Execute %s with options %s", file, options)
|
||||
self.app.core.execute_script(file)
|
||||
self.destroy()
|
||||
|
|
|
@ -6,6 +6,8 @@ from typing import TYPE_CHECKING, Optional
|
|||
from core.gui.dialogs.dialog import Dialog
|
||||
from core.gui.themes import FRAME_PAD, PADX, PADY
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.gui.app import Application
|
||||
|
||||
|
@ -139,8 +141,8 @@ class FindDialog(Dialog):
|
|||
_x, _y, _, _ = canvas_node.canvas.bbox(canvas_node.id)
|
||||
oid = canvas_node.canvas.find_withtag("rectangle")
|
||||
x0, y0, x1, y1 = canvas_node.canvas.bbox(oid[0])
|
||||
logging.debug("Dist to most left: %s", abs(x0 - _x))
|
||||
logging.debug("White canvas width: %s", abs(x0 - x1))
|
||||
logger.debug("Dist to most left: %s", abs(x0 - _x))
|
||||
logger.debug("White canvas width: %s", abs(x0 - x1))
|
||||
|
||||
# calculate the node's location
|
||||
# (as fractions of white canvas's width and height)
|
||||
|
|
|
@ -17,6 +17,8 @@ from core.gui.dialogs.emaneconfig import EmaneModelDialog
|
|||
from core.gui.themes import FRAME_PAD, PADX, PADY
|
||||
from core.gui.widgets import ListboxScroll, image_chooser
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.gui.app import Application
|
||||
from core.gui.graph.node import CanvasNode
|
||||
|
@ -261,7 +263,7 @@ class NodeConfigDialog(Dialog):
|
|||
|
||||
if nutils.is_rj45(self.node):
|
||||
ifaces = self.app.core.client.get_ifaces()
|
||||
logging.debug("host machine available interfaces: %s", ifaces)
|
||||
logger.debug("host machine available interfaces: %s", ifaces)
|
||||
ifaces_scroll = ListboxScroll(frame)
|
||||
ifaces_scroll.listbox.config(state=state)
|
||||
ifaces_scroll.grid(
|
||||
|
|
|
@ -12,6 +12,8 @@ from core.gui.dialogs.dialog import Dialog
|
|||
from core.gui.themes import FRAME_PAD, PADX, PADY
|
||||
from core.gui.widgets import CheckboxList, ListboxScroll
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.gui.app import Application
|
||||
|
||||
|
@ -131,7 +133,7 @@ class NodeConfigServiceDialog(Dialog):
|
|||
|
||||
def click_save(self) -> None:
|
||||
self.node.config_services = self.current_services.copy()
|
||||
logging.info("saved node config services: %s", self.node.config_services)
|
||||
logger.info("saved node config services: %s", self.node.config_services)
|
||||
self.destroy()
|
||||
|
||||
def click_cancel(self) -> None:
|
||||
|
|
|
@ -9,6 +9,8 @@ from core.gui.dialogs.dialog import Dialog
|
|||
from core.gui.themes import FRAME_PAD, PADX, PADY, scale_fonts
|
||||
from core.gui.validation import LARGEST_SCALE, SMALLEST_SCALE
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.gui.app import Application
|
||||
|
||||
|
@ -102,7 +104,7 @@ class PreferencesDialog(Dialog):
|
|||
|
||||
def theme_change(self, event: tk.Event) -> None:
|
||||
theme = self.theme.get()
|
||||
logging.info("changing theme: %s", theme)
|
||||
logger.info("changing theme: %s", theme)
|
||||
self.app.style.theme_use(theme)
|
||||
|
||||
def click_save(self) -> None:
|
||||
|
|
|
@ -20,6 +20,8 @@ from core.gui.images import ImageEnum
|
|||
from core.gui.themes import FRAME_PAD, PADX, PADY
|
||||
from core.gui.widgets import CodeText, ListboxScroll
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.gui.app import Application
|
||||
from core.gui.coreclient import CoreClient
|
||||
|
@ -393,7 +395,7 @@ class ServiceConfigDialog(Dialog):
|
|||
1.0, "end"
|
||||
)
|
||||
else:
|
||||
logging.debug("file already existed")
|
||||
logger.debug("file already existed")
|
||||
|
||||
def delete_filename(self) -> None:
|
||||
cbb = self.filename_combobox
|
||||
|
@ -601,7 +603,7 @@ class ServiceConfigDialog(Dialog):
|
|||
i = dirs.index(d)
|
||||
self.dir_list.listbox.delete(i)
|
||||
except ValueError:
|
||||
logging.debug("directory is not in the list")
|
||||
logger.debug("directory is not in the list")
|
||||
self.directory_entry.delete(0, "end")
|
||||
|
||||
def directory_select(self, event) -> None:
|
||||
|
|
|
@ -10,6 +10,8 @@ from core.gui.dialogs.dialog import Dialog
|
|||
from core.gui.themes import PADX, PADY
|
||||
from core.gui.widgets import ConfigFrame
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.gui.app import Application
|
||||
|
||||
|
@ -55,7 +57,7 @@ class SessionOptionsDialog(Dialog):
|
|||
try:
|
||||
session_id = self.app.core.session.id
|
||||
result = self.app.core.client.set_session_options(session_id, config)
|
||||
logging.info("saved session config: %s", result)
|
||||
logger.info("saved session config: %s", result)
|
||||
except grpc.RpcError as e:
|
||||
self.app.show_grpc_exception("Set Session Options Error", e)
|
||||
self.destroy()
|
||||
|
|
|
@ -12,6 +12,8 @@ from core.gui.images import ImageEnum
|
|||
from core.gui.task import ProgressTask
|
||||
from core.gui.themes import PADX, PADY
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.gui.app import Application
|
||||
|
||||
|
@ -31,7 +33,7 @@ class SessionsDialog(Dialog):
|
|||
def get_sessions(self) -> List[SessionSummary]:
|
||||
try:
|
||||
sessions = self.app.core.client.get_sessions()
|
||||
logging.info("sessions: %s", sessions)
|
||||
logger.info("sessions: %s", sessions)
|
||||
return sorted(sessions, key=lambda x: x.id)
|
||||
except grpc.RpcError as e:
|
||||
self.app.show_grpc_exception("Get Sessions Error", e)
|
||||
|
@ -175,7 +177,7 @@ class SessionsDialog(Dialog):
|
|||
self.selected_id = None
|
||||
self.delete_button.config(state=tk.DISABLED)
|
||||
self.connect_button.config(state=tk.DISABLED)
|
||||
logging.debug("selected session: %s", self.selected_session)
|
||||
logger.debug("selected session: %s", self.selected_session)
|
||||
|
||||
def click_connect(self) -> None:
|
||||
if not self.selected_session:
|
||||
|
@ -199,7 +201,7 @@ class SessionsDialog(Dialog):
|
|||
def click_delete(self) -> None:
|
||||
if not self.selected_session:
|
||||
return
|
||||
logging.info("click delete session: %s", self.selected_session)
|
||||
logger.info("click delete session: %s", self.selected_session)
|
||||
self.tree.delete(self.selected_id)
|
||||
self.app.core.delete_session(self.selected_session)
|
||||
session_id = None
|
||||
|
|
|
@ -11,6 +11,8 @@ from core.gui.frames.link import EdgeInfoFrame, WirelessEdgeInfoFrame
|
|||
from core.gui.graph import tags
|
||||
from core.gui.utils import bandwidth_text, delay_jitter_text
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.gui.app import Application
|
||||
from core.gui.graph.graph import CanvasGraph
|
||||
|
@ -393,7 +395,7 @@ class Edge:
|
|||
self.dst.canvas.coords(self.dst_label2, *dst_pos)
|
||||
|
||||
def delete(self) -> None:
|
||||
logging.debug("deleting canvas edge, id: %s", self.id)
|
||||
logger.debug("deleting canvas edge, id: %s", self.id)
|
||||
self.src.canvas.delete(self.id)
|
||||
self.src.canvas.delete(self.src_label)
|
||||
self.src.canvas.delete(self.dst_label)
|
||||
|
@ -488,7 +490,7 @@ class CanvasWirelessEdge(Edge):
|
|||
token: str,
|
||||
link: Link,
|
||||
) -> None:
|
||||
logging.debug("drawing wireless link from node %s to node %s", src, dst)
|
||||
logger.debug("drawing wireless link from node %s to node %s", src, dst)
|
||||
super().__init__(app, src, dst)
|
||||
self.src.wireless_edges.add(self)
|
||||
self.dst.wireless_edges.add(self)
|
||||
|
@ -622,7 +624,7 @@ class CanvasEdge(Edge):
|
|||
self.draw_link_options()
|
||||
|
||||
def complete(self, dst: "CanvasNode", link: Link = None) -> None:
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
"completing wired link from node(%s) to node(%s)",
|
||||
self.src.core_node.name,
|
||||
dst.core_node.name,
|
||||
|
|
|
@ -18,6 +18,8 @@ from core.gui.graph.node import CanvasNode, ShadowNode
|
|||
from core.gui.graph.shape import Shape
|
||||
from core.gui.graph.shapeutils import ShapeType, is_draw_shape, is_marker
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.gui.app import Application
|
||||
from core.gui.graph.manager import CanvasManager
|
||||
|
@ -184,7 +186,7 @@ class CanvasGraph(tk.Canvas):
|
|||
"""
|
||||
Draw a node or finish drawing an edge according to the current graph mode
|
||||
"""
|
||||
logging.debug("click release")
|
||||
logger.debug("click release")
|
||||
x, y = self.canvas_xy(event)
|
||||
if not self.inside_canvas(x, y):
|
||||
return
|
||||
|
@ -210,7 +212,7 @@ class CanvasGraph(tk.Canvas):
|
|||
else:
|
||||
self.focus_set()
|
||||
self.selected = self.get_selected(event)
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
"click release selected(%s) mode(%s)", self.selected, self.manager.mode
|
||||
)
|
||||
if self.manager.mode == GraphMode.EDGE:
|
||||
|
@ -228,7 +230,7 @@ class CanvasGraph(tk.Canvas):
|
|||
edge = self.drawing_edge
|
||||
self.drawing_edge = None
|
||||
# edge dst must be a node
|
||||
logging.debug("current selected: %s", self.selected)
|
||||
logger.debug("current selected: %s", self.selected)
|
||||
dst_node = self.nodes.get(self.selected)
|
||||
if not dst_node:
|
||||
edge.delete()
|
||||
|
@ -331,8 +333,8 @@ class CanvasGraph(tk.Canvas):
|
|||
self.offset[0] * factor + event.x * (1 - factor),
|
||||
self.offset[1] * factor + event.y * (1 - factor),
|
||||
)
|
||||
logging.debug("ratio: %s", self.ratio)
|
||||
logging.debug("offset: %s", self.offset)
|
||||
logger.debug("ratio: %s", self.ratio)
|
||||
logger.debug("offset: %s", self.offset)
|
||||
self.app.statusbar.set_zoom(self.ratio)
|
||||
if self.wallpaper:
|
||||
self.redraw_wallpaper()
|
||||
|
@ -347,10 +349,10 @@ class CanvasGraph(tk.Canvas):
|
|||
|
||||
self.cursor = x, y
|
||||
selected = self.get_selected(event)
|
||||
logging.debug("click press(%s): %s", self.cursor, selected)
|
||||
logger.debug("click press(%s): %s", self.cursor, selected)
|
||||
x_check = self.cursor[0] - self.offset[0]
|
||||
y_check = self.cursor[1] - self.offset[1]
|
||||
logging.debug("click press offset(%s, %s)", x_check, y_check)
|
||||
logger.debug("click press offset(%s, %s)", x_check, y_check)
|
||||
is_node = selected in self.nodes
|
||||
if self.manager.mode == GraphMode.EDGE and is_node:
|
||||
node = self.nodes[selected]
|
||||
|
@ -387,7 +389,7 @@ class CanvasGraph(tk.Canvas):
|
|||
node = self.nodes[selected]
|
||||
self.select_object(node.id)
|
||||
self.selected = selected
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
"selected node(%s), coords: (%s, %s)",
|
||||
node.core_node.name,
|
||||
node.core_node.position.x,
|
||||
|
@ -397,7 +399,7 @@ class CanvasGraph(tk.Canvas):
|
|||
shadow_node = self.shadow_nodes[selected]
|
||||
self.select_object(shadow_node.id)
|
||||
self.selected = selected
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
"selected shadow node(%s), coords: (%s, %s)",
|
||||
shadow_node.node.core_node.name,
|
||||
shadow_node.node.core_node.position.x,
|
||||
|
@ -418,7 +420,7 @@ class CanvasGraph(tk.Canvas):
|
|||
self.cursor = x, y
|
||||
|
||||
# handle multiple selections
|
||||
logging.debug("control left click: %s", event)
|
||||
logger.debug("control left click: %s", event)
|
||||
selected = self.get_selected(event)
|
||||
if (
|
||||
selected not in self.selection
|
||||
|
@ -489,12 +491,12 @@ class CanvasGraph(tk.Canvas):
|
|||
"""
|
||||
delete selected nodes and any data that relates to it
|
||||
"""
|
||||
logging.debug("press delete key")
|
||||
logger.debug("press delete key")
|
||||
if not self.app.core.is_runtime():
|
||||
self.delete_selected_objects()
|
||||
self.app.default_info()
|
||||
else:
|
||||
logging.debug("node deletion is disabled during runtime state")
|
||||
logger.debug("node deletion is disabled during runtime state")
|
||||
|
||||
def double_click(self, event: tk.Event) -> None:
|
||||
selected = self.get_selected(event)
|
||||
|
@ -606,10 +608,10 @@ class CanvasGraph(tk.Canvas):
|
|||
self.draw_wallpaper(image)
|
||||
|
||||
def redraw_canvas(self, dimensions: Tuple[int, int] = None) -> None:
|
||||
logging.debug("redrawing canvas to dimensions: %s", dimensions)
|
||||
logger.debug("redrawing canvas to dimensions: %s", dimensions)
|
||||
|
||||
# reset scale and move back to original position
|
||||
logging.debug("resetting scaling: %s %s", self.ratio, self.offset)
|
||||
logger.debug("resetting scaling: %s %s", self.ratio, self.offset)
|
||||
factor = 1 / self.ratio
|
||||
self.scale(tk.ALL, self.offset[0], self.offset[1], factor, factor)
|
||||
self.move(tk.ALL, -self.offset[0], -self.offset[1])
|
||||
|
@ -628,11 +630,11 @@ class CanvasGraph(tk.Canvas):
|
|||
|
||||
def redraw_wallpaper(self) -> None:
|
||||
if self.adjust_to_dim.get():
|
||||
logging.debug("drawing wallpaper to canvas dimensions")
|
||||
logger.debug("drawing wallpaper to canvas dimensions")
|
||||
self.resize_to_wallpaper()
|
||||
else:
|
||||
option = ScaleOption(self.scale_option.get())
|
||||
logging.debug("drawing canvas using scaling option: %s", option)
|
||||
logger.debug("drawing canvas using scaling option: %s", option)
|
||||
if option == ScaleOption.UPPER_LEFT:
|
||||
self.wallpaper_upper_left()
|
||||
elif option == ScaleOption.CENTERED:
|
||||
|
@ -640,7 +642,7 @@ class CanvasGraph(tk.Canvas):
|
|||
elif option == ScaleOption.SCALED:
|
||||
self.wallpaper_scaled()
|
||||
elif option == ScaleOption.TILED:
|
||||
logging.warning("tiled background not implemented yet")
|
||||
logger.warning("tiled background not implemented yet")
|
||||
self.organize()
|
||||
|
||||
def organize(self) -> None:
|
||||
|
@ -648,7 +650,7 @@ class CanvasGraph(tk.Canvas):
|
|||
self.tag_raise(tag)
|
||||
|
||||
def set_wallpaper(self, filename: Optional[str]) -> None:
|
||||
logging.info("setting canvas(%s) background: %s", self.id, filename)
|
||||
logger.info("setting canvas(%s) background: %s", self.id, filename)
|
||||
if filename:
|
||||
img = Image.open(filename)
|
||||
self.wallpaper = img
|
||||
|
@ -673,10 +675,10 @@ class CanvasGraph(tk.Canvas):
|
|||
|
||||
def copy(self) -> None:
|
||||
if self.core.is_runtime():
|
||||
logging.debug("copy is disabled during runtime state")
|
||||
logger.debug("copy is disabled during runtime state")
|
||||
return
|
||||
if self.selection:
|
||||
logging.debug("to copy nodes: %s", self.selection)
|
||||
logger.debug("to copy nodes: %s", self.selection)
|
||||
self.to_copy.clear()
|
||||
for node_id in self.selection.keys():
|
||||
canvas_node = self.nodes[node_id]
|
||||
|
@ -684,7 +686,7 @@ class CanvasGraph(tk.Canvas):
|
|||
|
||||
def paste(self) -> None:
|
||||
if self.core.is_runtime():
|
||||
logging.debug("paste is disabled during runtime state")
|
||||
logger.debug("paste is disabled during runtime state")
|
||||
return
|
||||
# maps original node canvas id to copy node canvas id
|
||||
copy_map = {}
|
||||
|
@ -825,7 +827,7 @@ class CanvasGraph(tk.Canvas):
|
|||
wallpaper = Path(wallpaper)
|
||||
if not wallpaper.is_file():
|
||||
wallpaper = appconfig.BACKGROUNDS_PATH.joinpath(wallpaper)
|
||||
logging.info("canvas(%s), wallpaper: %s", self.id, wallpaper)
|
||||
logger.info("canvas(%s), wallpaper: %s", self.id, wallpaper)
|
||||
if wallpaper.is_file():
|
||||
self.set_wallpaper(str(wallpaper))
|
||||
else:
|
||||
|
|
|
@ -19,6 +19,8 @@ from core.gui.graph.node import CanvasNode
|
|||
from core.gui.graph.shapeutils import ShapeType
|
||||
from core.gui.nodeutils import NodeDraw
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.gui.app import Application
|
||||
from core.gui.coreclient import CoreClient
|
||||
|
@ -166,7 +168,7 @@ class CanvasManager:
|
|||
canvas_id = self._next_id()
|
||||
self.notebook.add(tab, text=f"Canvas {canvas_id}")
|
||||
unique_id = self.notebook.tabs()[-1]
|
||||
logging.info("creating canvas(%s)", canvas_id)
|
||||
logger.info("creating canvas(%s)", canvas_id)
|
||||
self.canvas_ids[unique_id] = canvas_id
|
||||
self.unique_ids[canvas_id] = unique_id
|
||||
|
||||
|
@ -213,7 +215,7 @@ class CanvasManager:
|
|||
self.unique_ids.clear()
|
||||
self.edges.clear()
|
||||
self.wireless_edges.clear()
|
||||
logging.info("cleared canvases")
|
||||
logger.info("cleared canvases")
|
||||
|
||||
# reset settings
|
||||
self.show_node_labels.set(True)
|
||||
|
@ -289,7 +291,7 @@ class CanvasManager:
|
|||
for canvas_config in config.get("canvases", []):
|
||||
canvas_id = canvas_config.get("id")
|
||||
if canvas_id is None:
|
||||
logging.error("canvas config id not provided")
|
||||
logger.error("canvas config id not provided")
|
||||
continue
|
||||
canvas = self.get(canvas_id)
|
||||
canvas.parse_metadata(canvas_config)
|
||||
|
@ -297,7 +299,7 @@ class CanvasManager:
|
|||
def add_core_node(self, core_node: Node) -> None:
|
||||
# get canvas tab for node
|
||||
canvas_id = core_node.canvas if core_node.canvas > 0 else 1
|
||||
logging.info("adding core node canvas(%s): %s", core_node.name, canvas_id)
|
||||
logger.info("adding core node canvas(%s): %s", core_node.name, canvas_id)
|
||||
canvas = self.get(canvas_id)
|
||||
image = nutils.get_icon(core_node, self.app)
|
||||
x = core_node.position.x
|
||||
|
@ -354,7 +356,7 @@ class CanvasManager:
|
|||
network_id = link.network_id if link.network_id else None
|
||||
token = create_wireless_token(src.id, dst.id, network_id)
|
||||
if token in self.wireless_edges:
|
||||
logging.warning("ignoring link that already exists: %s", link)
|
||||
logger.warning("ignoring link that already exists: %s", link)
|
||||
return
|
||||
edge = CanvasWirelessEdge(self.app, src, dst, network_id, token, link)
|
||||
self.wireless_edges[token] = edge
|
||||
|
|
|
@ -24,6 +24,8 @@ from core.gui.graph.edges import CanvasEdge, CanvasWirelessEdge
|
|||
from core.gui.graph.tooltip import CanvasTooltip
|
||||
from core.gui.images import ImageEnum
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.gui.app import Application
|
||||
from core.gui.graph.graph import CanvasGraph
|
||||
|
@ -87,7 +89,7 @@ class CanvasNode:
|
|||
self.canvas.tag_bind(self.id, "<Button-1>", self.show_info)
|
||||
|
||||
def delete(self) -> None:
|
||||
logging.debug("Delete canvas node for %s", self.core_node)
|
||||
logger.debug("Delete canvas node for %s", self.core_node)
|
||||
self.canvas.delete(self.id)
|
||||
self.canvas.delete(self.text_id)
|
||||
self.delete_antennas()
|
||||
|
@ -110,7 +112,7 @@ class CanvasNode:
|
|||
"""
|
||||
delete one antenna
|
||||
"""
|
||||
logging.debug("Delete an antenna on %s", self.core_node.name)
|
||||
logger.debug("Delete an antenna on %s", self.core_node.name)
|
||||
if self.antennas:
|
||||
antenna_id = self.antennas.pop()
|
||||
self.canvas.delete(antenna_id)
|
||||
|
@ -120,7 +122,7 @@ class CanvasNode:
|
|||
"""
|
||||
delete all antennas
|
||||
"""
|
||||
logging.debug("Remove all antennas for %s", self.core_node.name)
|
||||
logger.debug("Remove all antennas for %s", self.core_node.name)
|
||||
for antenna_id in self.antennas:
|
||||
self.canvas.delete(antenna_id)
|
||||
self.antennas.clear()
|
||||
|
@ -400,7 +402,7 @@ class CanvasNode:
|
|||
|
||||
def update_icon(self, icon_path: str) -> None:
|
||||
if not Path(icon_path).exists():
|
||||
logging.error(f"node icon does not exist: {icon_path}")
|
||||
logger.error(f"node icon does not exist: {icon_path}")
|
||||
return
|
||||
self.core_node.icon = icon_path
|
||||
self.image = images.from_file(icon_path, width=images.NODE_SIZE)
|
||||
|
|
|
@ -5,6 +5,8 @@ from core.gui.dialogs.shapemod import ShapeDialog
|
|||
from core.gui.graph import tags
|
||||
from core.gui.graph.shapeutils import ShapeType
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.gui.app import Application
|
||||
from core.gui.graph.graph import CanvasGraph
|
||||
|
@ -92,7 +94,7 @@ class Shape:
|
|||
shape = Shape(app, canvas, shape_type, *coords, data=data)
|
||||
canvas.shapes[shape.id] = shape
|
||||
except ValueError:
|
||||
logging.exception("unknown shape: %s", shape_type)
|
||||
logger.exception("unknown shape: %s", shape_type)
|
||||
|
||||
def draw(self) -> None:
|
||||
if self.created:
|
||||
|
@ -139,7 +141,7 @@ class Shape:
|
|||
state=self.app.manager.show_annotations.state(),
|
||||
)
|
||||
else:
|
||||
logging.error("unknown shape type: %s", self.shape_type)
|
||||
logger.error("unknown shape type: %s", self.shape_type)
|
||||
self.created = True
|
||||
|
||||
def get_font(self) -> List[Union[int, str]]:
|
||||
|
@ -192,7 +194,7 @@ class Shape:
|
|||
self.canvas.move(self.text_id, x_offset, y_offset)
|
||||
|
||||
def delete(self) -> None:
|
||||
logging.debug("Delete shape, id(%s)", self.id)
|
||||
logger.debug("Delete shape, id(%s)", self.id)
|
||||
self.canvas.delete(self.id)
|
||||
self.canvas.delete(self.text_id)
|
||||
|
||||
|
|
|
@ -9,6 +9,8 @@ from core.gui import nodeutils as nutils
|
|||
from core.gui.graph.edges import CanvasEdge
|
||||
from core.gui.graph.node import CanvasNode
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.gui.app import Application
|
||||
|
||||
|
@ -196,12 +198,12 @@ class InterfaceManager:
|
|||
else:
|
||||
self.current_subnets = self.next_subnets()
|
||||
else:
|
||||
logging.info("ignoring subnet change for link between network nodes")
|
||||
logger.info("ignoring subnet change for link between network nodes")
|
||||
|
||||
def find_subnets(
|
||||
self, canvas_node: CanvasNode, visited: Set[int] = None
|
||||
) -> Optional[IPNetwork]:
|
||||
logging.info("finding subnet for node: %s", canvas_node.core_node.name)
|
||||
logger.info("finding subnet for node: %s", canvas_node.core_node.name)
|
||||
subnets = None
|
||||
if not visited:
|
||||
visited = set()
|
||||
|
@ -220,7 +222,7 @@ class InterfaceManager:
|
|||
else:
|
||||
subnets = self.find_subnets(check_node, visited)
|
||||
if subnets:
|
||||
logging.info("found subnets: %s", subnets)
|
||||
logger.info("found subnets: %s", subnets)
|
||||
break
|
||||
return subnets
|
||||
|
||||
|
@ -244,7 +246,7 @@ class InterfaceManager:
|
|||
iface1=src_iface,
|
||||
iface2=dst_iface,
|
||||
)
|
||||
logging.info("added link between %s and %s", src_node.name, dst_node.name)
|
||||
logger.info("added link between %s and %s", src_node.name, dst_node.name)
|
||||
return link
|
||||
|
||||
def create_iface(self, canvas_node: CanvasNode, wireless_link: bool) -> Interface:
|
||||
|
@ -266,5 +268,5 @@ class InterfaceManager:
|
|||
ip6=ip6,
|
||||
ip6_mask=ip6_mask,
|
||||
)
|
||||
logging.info("create node(%s) interface(%s)", node.name, iface)
|
||||
logger.info("create node(%s) interface(%s)", node.name, iface)
|
||||
return iface
|
||||
|
|
|
@ -27,6 +27,8 @@ from core.gui.graph.manager import CanvasManager
|
|||
from core.gui.observers import ObserversMenu
|
||||
from core.gui.task import ProgressTask
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.gui.app import Application
|
||||
|
||||
|
@ -274,10 +276,10 @@ class Menubar(tk.Menu):
|
|||
|
||||
def open_recent_files(self, file_path: Path) -> None:
|
||||
if file_path.is_file():
|
||||
logging.debug("Open recent file %s", file_path)
|
||||
logger.debug("Open recent file %s", file_path)
|
||||
self.open_xml_task(file_path)
|
||||
else:
|
||||
logging.warning("File does not exist %s", file_path)
|
||||
logger.warning("File does not exist %s", file_path)
|
||||
|
||||
def update_recent_files(self) -> None:
|
||||
self.recent_menu.delete(0, tk.END)
|
||||
|
@ -429,23 +431,23 @@ class Menubar(tk.Menu):
|
|||
canvas.show_hidden()
|
||||
|
||||
def click_session_options(self) -> None:
|
||||
logging.debug("Click options")
|
||||
logger.debug("Click options")
|
||||
dialog = SessionOptionsDialog(self.app)
|
||||
if not dialog.has_error:
|
||||
dialog.show()
|
||||
|
||||
def click_sessions(self) -> None:
|
||||
logging.debug("Click change sessions")
|
||||
logger.debug("Click change sessions")
|
||||
dialog = SessionsDialog(self.app)
|
||||
dialog.show()
|
||||
|
||||
def click_hooks(self) -> None:
|
||||
logging.debug("Click hooks")
|
||||
logger.debug("Click hooks")
|
||||
dialog = HooksDialog(self.app)
|
||||
dialog.show()
|
||||
|
||||
def click_servers(self) -> None:
|
||||
logging.debug("Click emulation servers")
|
||||
logger.debug("Click emulation servers")
|
||||
dialog = ServersDialog(self.app)
|
||||
dialog.show()
|
||||
|
||||
|
@ -458,7 +460,7 @@ class Menubar(tk.Menu):
|
|||
padding = (images.NODE_SIZE / 2) + 10
|
||||
layout_size = padding + images.NODE_SIZE
|
||||
col_count = width // layout_size
|
||||
logging.info(
|
||||
logger.info(
|
||||
"auto grid layout: dimension(%s, %s) col(%s)", width, height, col_count
|
||||
)
|
||||
canvas = self.manager.current()
|
||||
|
|
|
@ -8,6 +8,8 @@ from core.gui import images
|
|||
from core.gui.appconfig import CustomNode, GuiConfig
|
||||
from core.gui.images import ImageEnum
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.gui.app import Application
|
||||
|
||||
|
@ -118,11 +120,11 @@ def get_icon(node: Node, app: "Application") -> PhotoImage:
|
|||
try:
|
||||
image = images.from_file(node.icon, width=images.NODE_SIZE, scale=scale)
|
||||
except OSError:
|
||||
logging.error("invalid icon: %s", node.icon)
|
||||
logger.error("invalid icon: %s", node.icon)
|
||||
# custom node
|
||||
elif is_custom(node):
|
||||
image_file = _get_custom_file(app.guiconfig, node.model)
|
||||
logging.info("custom node file: %s", image_file)
|
||||
logger.info("custom node file: %s", image_file)
|
||||
if image_file:
|
||||
image = images.from_file(image_file, width=images.NODE_SIZE, scale=scale)
|
||||
# built in node
|
||||
|
|
|
@ -4,6 +4,8 @@ import time
|
|||
import tkinter as tk
|
||||
from typing import TYPE_CHECKING, Any, Callable, Optional, Tuple
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.gui.app import Application
|
||||
|
||||
|
@ -43,7 +45,7 @@ class ProgressTask:
|
|||
if self.callback:
|
||||
self.app.after(0, self.callback, *values)
|
||||
except Exception as e:
|
||||
logging.exception("progress task exception")
|
||||
logger.exception("progress task exception")
|
||||
self.app.show_exception("Task Error", e)
|
||||
finally:
|
||||
self.app.after(0, self.complete)
|
||||
|
|
|
@ -20,6 +20,8 @@ from core.gui.task import ProgressTask
|
|||
from core.gui.themes import Styles
|
||||
from core.gui.tooltip import Tooltip
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.gui.app import Application
|
||||
|
||||
|
@ -338,7 +340,7 @@ class Toolbar(ttk.Frame):
|
|||
type_enum: NodeTypeEnum,
|
||||
image: PhotoImage,
|
||||
) -> None:
|
||||
logging.debug("update button(%s): %s", button, node_draw)
|
||||
logger.debug("update button(%s): %s", button, node_draw)
|
||||
button.configure(image=image)
|
||||
button.image = image
|
||||
self.app.manager.node_draw = node_draw
|
||||
|
@ -399,7 +401,7 @@ class Toolbar(ttk.Frame):
|
|||
"""
|
||||
redraw buttons on the toolbar, send node and link messages to grpc server
|
||||
"""
|
||||
logging.info("clicked stop button")
|
||||
logger.info("clicked stop button")
|
||||
self.app.menubar.set_state(is_runtime=False)
|
||||
self.app.core.close_mobility_players()
|
||||
enable_buttons(self.runtime_frame, enabled=False)
|
||||
|
@ -415,7 +417,7 @@ class Toolbar(ttk.Frame):
|
|||
def update_annotation(
|
||||
self, shape_type: ShapeType, image_enum: ImageEnum, image: PhotoImage
|
||||
) -> None:
|
||||
logging.debug("clicked annotation")
|
||||
logger.debug("clicked annotation")
|
||||
self.annotation_button.configure(image=image)
|
||||
self.annotation_button.image = image
|
||||
self.app.manager.annotation_type = shape_type
|
||||
|
@ -433,7 +435,7 @@ class Toolbar(ttk.Frame):
|
|||
self.marker_frame.grid()
|
||||
|
||||
def click_run_button(self) -> None:
|
||||
logging.debug("Click on RUN button")
|
||||
logger.debug("Click on RUN button")
|
||||
dialog = RunToolDialog(self.app)
|
||||
dialog.show()
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@ from core.gui import appconfig, themes, validation
|
|||
from core.gui.dialogs.dialog import Dialog
|
||||
from core.gui.themes import FRAME_PAD, PADX, PADY
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.gui.app import Application
|
||||
|
||||
|
@ -161,7 +163,7 @@ class ConfigFrame(ttk.Notebook):
|
|||
)
|
||||
entry.grid(row=index, column=1, sticky=tk.EW)
|
||||
else:
|
||||
logging.error("unhandled config option type: %s", option.type)
|
||||
logger.error("unhandled config option type: %s", option.type)
|
||||
self.values[option.name] = value
|
||||
|
||||
def parse_config(self) -> Dict[str, str]:
|
||||
|
|
|
@ -10,6 +10,7 @@ from pyproj import Transformer
|
|||
|
||||
from core.emulator.enumerations import RegisterTlvs
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
SCALE_FACTOR: float = 100.0
|
||||
CRS_WGS84: int = 4326
|
||||
CRS_PROJ: int = 3857
|
||||
|
@ -92,7 +93,7 @@ class GeoLocation:
|
|||
:param alt: altitude value
|
||||
:return: x,y,z representation of provided values
|
||||
"""
|
||||
logging.debug("input lon,lat,alt(%s, %s, %s)", lon, lat, alt)
|
||||
logger.debug("input lon,lat,alt(%s, %s, %s)", lon, lat, alt)
|
||||
px, py = self.to_pixels.transform(lon, lat)
|
||||
px -= self.refproj[0]
|
||||
py -= self.refproj[1]
|
||||
|
@ -100,7 +101,7 @@ class GeoLocation:
|
|||
x = self.meters2pixels(px) + self.refxyz[0]
|
||||
y = -(self.meters2pixels(py) + self.refxyz[1])
|
||||
z = self.meters2pixels(pz) + self.refxyz[2]
|
||||
logging.debug("result x,y,z(%s, %s, %s)", x, y, z)
|
||||
logger.debug("result x,y,z(%s, %s, %s)", x, y, z)
|
||||
return x, y, z
|
||||
|
||||
def getgeo(self, x: float, y: float, z: float) -> Tuple[float, float, float]:
|
||||
|
@ -112,7 +113,7 @@ class GeoLocation:
|
|||
:param z: z value
|
||||
:return: lat,lon,alt representation of provided values
|
||||
"""
|
||||
logging.debug("input x,y(%s, %s)", x, y)
|
||||
logger.debug("input x,y(%s, %s)", x, y)
|
||||
x -= self.refxyz[0]
|
||||
y = -(y - self.refxyz[1])
|
||||
if z is None:
|
||||
|
@ -123,5 +124,5 @@ class GeoLocation:
|
|||
py = self.refproj[1] + self.pixels2meters(y)
|
||||
lon, lat = self.to_geo.transform(px, py)
|
||||
alt = self.refgeo[2] + self.pixels2meters(z)
|
||||
logging.debug("result lon,lat,alt(%s, %s, %s)", lon, lat, alt)
|
||||
logger.debug("result lon,lat,alt(%s, %s, %s)", lon, lat, alt)
|
||||
return lat, lon, alt
|
||||
|
|
|
@ -28,6 +28,8 @@ from core.nodes.base import CoreNode
|
|||
from core.nodes.interface import CoreInterface
|
||||
from core.nodes.network import WlanNode
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.emulator.session import Session
|
||||
|
||||
|
@ -81,7 +83,7 @@ class MobilityManager(ModelManager):
|
|||
if node_ids is None:
|
||||
node_ids = self.nodes()
|
||||
for node_id in node_ids:
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
"node(%s) mobility startup: %s", node_id, self.get_all_configs(node_id)
|
||||
)
|
||||
try:
|
||||
|
@ -95,8 +97,8 @@ class MobilityManager(ModelManager):
|
|||
if node.mobility:
|
||||
self.session.event_loop.add_event(0.0, node.mobility.startup)
|
||||
except CoreError:
|
||||
logging.exception("mobility startup error")
|
||||
logging.warning(
|
||||
logger.exception("mobility startup error")
|
||||
logger.warning(
|
||||
"skipping mobility configuration for unknown node: %s", node_id
|
||||
)
|
||||
|
||||
|
@ -114,7 +116,7 @@ class MobilityManager(ModelManager):
|
|||
try:
|
||||
node = get_mobility_node(self.session, node_id)
|
||||
except CoreError:
|
||||
logging.exception(
|
||||
logger.exception(
|
||||
"ignoring event for model(%s), unknown node(%s)", name, node_id
|
||||
)
|
||||
return
|
||||
|
@ -124,17 +126,17 @@ class MobilityManager(ModelManager):
|
|||
for model in models:
|
||||
cls = self.models.get(model)
|
||||
if not cls:
|
||||
logging.warning("ignoring event for unknown model '%s'", model)
|
||||
logger.warning("ignoring event for unknown model '%s'", model)
|
||||
continue
|
||||
if cls.config_type in [RegisterTlvs.WIRELESS, RegisterTlvs.MOBILITY]:
|
||||
model = node.mobility
|
||||
else:
|
||||
continue
|
||||
if model is None:
|
||||
logging.warning("ignoring event, %s has no model", node.name)
|
||||
logger.warning("ignoring event, %s has no model", node.name)
|
||||
continue
|
||||
if cls.name != model.name:
|
||||
logging.warning(
|
||||
logger.warning(
|
||||
"ignoring event for %s wrong model %s,%s",
|
||||
node.name,
|
||||
cls.name,
|
||||
|
@ -410,16 +412,16 @@ class BasicRangeModel(WirelessModel):
|
|||
linked = self.wlan.linked(a, b)
|
||||
if d > self.range:
|
||||
if linked:
|
||||
logging.debug("was linked, unlinking")
|
||||
logger.debug("was linked, unlinking")
|
||||
self.wlan.unlink(a, b)
|
||||
self.sendlinkmsg(a, b, unlink=True)
|
||||
else:
|
||||
if not linked:
|
||||
logging.debug("was not linked, linking")
|
||||
logger.debug("was not linked, linking")
|
||||
self.wlan.link(a, b)
|
||||
self.sendlinkmsg(a, b)
|
||||
except KeyError:
|
||||
logging.exception("error getting interfaces during calclink")
|
||||
logger.exception("error getting interfaces during calclink")
|
||||
|
||||
@staticmethod
|
||||
def calcdistance(
|
||||
|
@ -449,7 +451,7 @@ class BasicRangeModel(WirelessModel):
|
|||
self.range = self._get_config(self.range, config, "range")
|
||||
if self.range is None:
|
||||
self.range = 0
|
||||
logging.debug("wlan %s set range to %s", self.wlan.name, self.range)
|
||||
logger.debug("wlan %s set range to %s", self.wlan.name, self.range)
|
||||
self.bw = self._get_config(self.bw, config, "bandwidth")
|
||||
self.delay = self._get_config(self.delay, config, "delay")
|
||||
self.loss = self._get_config(self.loss, config, "error")
|
||||
|
@ -927,7 +929,7 @@ class Ns2ScriptedMobility(WayPointMobility):
|
|||
|
||||
def update_config(self, config: Dict[str, str]) -> None:
|
||||
self.file = Path(config["file"])
|
||||
logging.info(
|
||||
logger.info(
|
||||
"ns-2 scripted mobility configured for WLAN %d using file: %s",
|
||||
self.id,
|
||||
self.file,
|
||||
|
@ -955,11 +957,11 @@ class Ns2ScriptedMobility(WayPointMobility):
|
|||
try:
|
||||
f = file_path.open("r")
|
||||
except IOError:
|
||||
logging.exception(
|
||||
logger.exception(
|
||||
"ns-2 scripted mobility failed to load file: %s", self.file
|
||||
)
|
||||
return
|
||||
logging.info("reading ns-2 script file: %s", file_path)
|
||||
logger.info("reading ns-2 script file: %s", file_path)
|
||||
ln = 0
|
||||
ix = iy = iz = None
|
||||
inodenum = None
|
||||
|
@ -1002,7 +1004,7 @@ class Ns2ScriptedMobility(WayPointMobility):
|
|||
else:
|
||||
raise ValueError
|
||||
except ValueError:
|
||||
logging.exception(
|
||||
logger.exception(
|
||||
"skipping line %d of file %s '%s'", ln, self.file, line
|
||||
)
|
||||
continue
|
||||
|
@ -1052,7 +1054,7 @@ class Ns2ScriptedMobility(WayPointMobility):
|
|||
raise ValueError
|
||||
self.nodemap[int(parts[0])] = int(parts[1])
|
||||
except ValueError:
|
||||
logging.exception("ns-2 mobility node map error")
|
||||
logger.exception("ns-2 mobility node map error")
|
||||
|
||||
def map(self, nodenum: str) -> int:
|
||||
"""
|
||||
|
@ -1074,19 +1076,19 @@ class Ns2ScriptedMobility(WayPointMobility):
|
|||
:return: nothing
|
||||
"""
|
||||
if self.autostart == "":
|
||||
logging.info("not auto-starting ns-2 script for %s", self.net.name)
|
||||
logger.info("not auto-starting ns-2 script for %s", self.net.name)
|
||||
return
|
||||
try:
|
||||
t = float(self.autostart)
|
||||
except ValueError:
|
||||
logging.exception(
|
||||
logger.exception(
|
||||
"Invalid auto-start seconds specified '%s' for %s",
|
||||
self.autostart,
|
||||
self.net.name,
|
||||
)
|
||||
return
|
||||
self.movenodesinitial()
|
||||
logging.info("scheduling ns-2 script for %s autostart at %s", self.net.name, t)
|
||||
logger.info("scheduling ns-2 script for %s autostart at %s", self.net.name, t)
|
||||
self.state = self.STATE_RUNNING
|
||||
self.session.event_loop.add_event(t, self.run)
|
||||
|
||||
|
@ -1096,7 +1098,7 @@ class Ns2ScriptedMobility(WayPointMobility):
|
|||
|
||||
:return: nothing
|
||||
"""
|
||||
logging.info("starting script: %s", self.file)
|
||||
logger.info("starting script: %s", self.file)
|
||||
laststate = self.state
|
||||
super().start()
|
||||
if laststate == self.STATE_PAUSED:
|
||||
|
@ -1117,7 +1119,7 @@ class Ns2ScriptedMobility(WayPointMobility):
|
|||
|
||||
:return: nothing
|
||||
"""
|
||||
logging.info("pausing script: %s", self.file)
|
||||
logger.info("pausing script: %s", self.file)
|
||||
super().pause()
|
||||
self.statescript("pause")
|
||||
|
||||
|
@ -1129,7 +1131,7 @@ class Ns2ScriptedMobility(WayPointMobility):
|
|||
position
|
||||
:return: nothing
|
||||
"""
|
||||
logging.info("stopping script: %s", self.file)
|
||||
logger.info("stopping script: %s", self.file)
|
||||
super().stop(move_initial=move_initial)
|
||||
self.statescript("stop")
|
||||
|
||||
|
|
|
@ -21,6 +21,8 @@ from core.nodes.client import VnodeClient
|
|||
from core.nodes.interface import CoreInterface, TunTap, Veth
|
||||
from core.nodes.netclient import LinuxNetClient, get_net_client
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.emulator.distributed import DistributedServer
|
||||
from core.emulator.session import Session
|
||||
|
@ -404,7 +406,7 @@ class CoreNodeBase(NodeBase):
|
|||
if iface_id not in self.ifaces:
|
||||
raise CoreError(f"node({self.name}) interface({iface_id}) does not exist")
|
||||
iface = self.ifaces.pop(iface_id)
|
||||
logging.info("node(%s) removing interface(%s)", self.name, iface.name)
|
||||
logger.info("node(%s) removing interface(%s)", self.name, iface.name)
|
||||
iface.detachnet()
|
||||
iface.shutdown()
|
||||
|
||||
|
@ -547,17 +549,17 @@ class CoreNode(CoreNodeBase):
|
|||
|
||||
output = self.host_cmd(vnoded, env=env)
|
||||
self.pid = int(output)
|
||||
logging.debug("node(%s) pid: %s", self.name, self.pid)
|
||||
logger.debug("node(%s) pid: %s", self.name, self.pid)
|
||||
|
||||
# create vnode client
|
||||
self.client = VnodeClient(self.name, self.ctrlchnlname)
|
||||
|
||||
# bring up the loopback interface
|
||||
logging.debug("bringing up loopback interface")
|
||||
logger.debug("bringing up loopback interface")
|
||||
self.node_net_client.device_up("lo")
|
||||
|
||||
# set hostname for node
|
||||
logging.debug("setting hostname: %s", self.name)
|
||||
logger.debug("setting hostname: %s", self.name)
|
||||
self.node_net_client.set_hostname(self.name)
|
||||
|
||||
# mark node as up
|
||||
|
@ -588,18 +590,18 @@ class CoreNode(CoreNodeBase):
|
|||
try:
|
||||
self.host_cmd(f"kill -9 {self.pid}")
|
||||
except CoreCommandError:
|
||||
logging.exception("error killing process")
|
||||
logger.exception("error killing process")
|
||||
# remove node directory if present
|
||||
try:
|
||||
self.host_cmd(f"rm -rf {self.ctrlchnlname}")
|
||||
except CoreCommandError:
|
||||
logging.exception("error removing node directory")
|
||||
logger.exception("error removing node directory")
|
||||
# clear interface data, close client, and mark self and not up
|
||||
self.ifaces.clear()
|
||||
self.client.close()
|
||||
self.up = False
|
||||
except OSError:
|
||||
logging.exception("error during shutdown")
|
||||
logger.exception("error during shutdown")
|
||||
finally:
|
||||
self.rmnodedir()
|
||||
|
||||
|
@ -668,7 +670,7 @@ class CoreNode(CoreNodeBase):
|
|||
:return: nothing
|
||||
:raises CoreCommandError: when a non-zero exit status occurs
|
||||
"""
|
||||
logging.debug("node(%s) mounting: %s at %s", self.name, src_path, target_path)
|
||||
logger.debug("node(%s) mounting: %s at %s", self.name, src_path, target_path)
|
||||
self.cmd(f"mkdir -p {target_path}")
|
||||
self.cmd(f"{MOUNT} -n --bind {src_path} {target_path}")
|
||||
self._mounts.append((src_path, target_path))
|
||||
|
@ -726,9 +728,9 @@ class CoreNode(CoreNodeBase):
|
|||
if self.up:
|
||||
flow_id = self.node_net_client.get_ifindex(veth.name)
|
||||
veth.flow_id = int(flow_id)
|
||||
logging.debug("interface flow index: %s - %s", veth.name, veth.flow_id)
|
||||
logger.debug("interface flow index: %s - %s", veth.name, veth.flow_id)
|
||||
mac = self.node_net_client.get_mac(veth.name)
|
||||
logging.debug("interface mac: %s - %s", veth.name, mac)
|
||||
logger.debug("interface mac: %s - %s", veth.name, mac)
|
||||
veth.set_mac(mac)
|
||||
|
||||
try:
|
||||
|
@ -867,7 +869,7 @@ class CoreNode(CoreNodeBase):
|
|||
:return: nothing
|
||||
:raises CoreCommandError: when a non-zero exit status occurs
|
||||
"""
|
||||
logging.info("adding file from %s to %s", src_path, file_path)
|
||||
logger.info("adding file from %s to %s", src_path, file_path)
|
||||
directory = file_path.parent
|
||||
if self.server is None:
|
||||
self.client.check_cmd(f"mkdir -p {directory}")
|
||||
|
@ -898,7 +900,7 @@ class CoreNode(CoreNodeBase):
|
|||
self.host_cmd(f"mkdir -m {0o755:o} -p {directory}")
|
||||
self.server.remote_put_temp(host_path, contents)
|
||||
self.host_cmd(f"chmod {mode:o} {host_path}")
|
||||
logging.debug("node(%s) added file: %s; mode: 0%o", self.name, host_path, mode)
|
||||
logger.debug("node(%s) added file: %s; mode: 0%o", self.name, host_path, mode)
|
||||
|
||||
def nodefilecopy(self, file_path: Path, src_path: Path, mode: int = None) -> None:
|
||||
"""
|
||||
|
@ -917,7 +919,7 @@ class CoreNode(CoreNodeBase):
|
|||
self.server.remote_put(src_path, host_path)
|
||||
if mode is not None:
|
||||
self.host_cmd(f"chmod {mode:o} {host_path}")
|
||||
logging.info("node(%s) copied file: %s; mode: %s", self.name, host_path, mode)
|
||||
logger.info("node(%s) copied file: %s; mode: %s", self.name, host_path, mode)
|
||||
|
||||
|
||||
class CoreNetworkBase(NodeBase):
|
||||
|
|
|
@ -11,6 +11,8 @@ from core.errors import CoreCommandError
|
|||
from core.nodes.base import CoreNode
|
||||
from core.nodes.netclient import LinuxNetClient, get_net_client
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.emulator.session import Session
|
||||
|
||||
|
@ -50,7 +52,7 @@ class DockerClient:
|
|||
self.run(f"docker rm -f {self.name}")
|
||||
|
||||
def check_cmd(self, cmd: str, wait: bool = True, shell: bool = False) -> str:
|
||||
logging.info("docker cmd output: %s", cmd)
|
||||
logger.info("docker cmd output: %s", cmd)
|
||||
return utils.cmd(f"docker exec {self.name} {cmd}", wait=wait, shell=shell)
|
||||
|
||||
def create_ns_cmd(self, cmd: str) -> str:
|
||||
|
@ -60,7 +62,7 @@ class DockerClient:
|
|||
args = f"docker inspect -f '{{{{.State.Pid}}}}' {self.name}"
|
||||
output = self.run(args)
|
||||
self.pid = output
|
||||
logging.debug("node(%s) pid: %s", self.name, self.pid)
|
||||
logger.debug("node(%s) pid: %s", self.name, self.pid)
|
||||
return output
|
||||
|
||||
def copy_file(self, src_path: Path, dst_path: Path) -> str:
|
||||
|
@ -169,7 +171,7 @@ class DockerNode(CoreNode):
|
|||
:param dir_path: path to create
|
||||
:return: nothing
|
||||
"""
|
||||
logging.debug("creating node dir: %s", dir_path)
|
||||
logger.debug("creating node dir: %s", dir_path)
|
||||
args = f"mkdir -p {dir_path}"
|
||||
self.cmd(args)
|
||||
|
||||
|
@ -182,7 +184,7 @@ class DockerNode(CoreNode):
|
|||
:return: nothing
|
||||
:raises CoreCommandError: when a non-zero exit status occurs
|
||||
"""
|
||||
logging.debug("mounting source(%s) target(%s)", src_path, target_path)
|
||||
logger.debug("mounting source(%s) target(%s)", src_path, target_path)
|
||||
raise Exception("not supported")
|
||||
|
||||
def nodefile(self, file_path: Path, contents: str, mode: int = 0o644) -> None:
|
||||
|
@ -194,7 +196,7 @@ class DockerNode(CoreNode):
|
|||
:param mode: mode for file
|
||||
:return: nothing
|
||||
"""
|
||||
logging.debug("nodefile filename(%s) mode(%s)", file_path, mode)
|
||||
logger.debug("nodefile filename(%s) mode(%s)", file_path, mode)
|
||||
temp = NamedTemporaryFile(delete=False)
|
||||
temp.write(contents.encode("utf-8"))
|
||||
temp.close()
|
||||
|
@ -209,7 +211,7 @@ class DockerNode(CoreNode):
|
|||
if self.server is not None:
|
||||
self.host_cmd(f"rm -f {temp_path}")
|
||||
temp_path.unlink()
|
||||
logging.debug("node(%s) added file: %s; mode: 0%o", self.name, file_path, mode)
|
||||
logger.debug("node(%s) added file: %s; mode: 0%o", self.name, file_path, mode)
|
||||
|
||||
def nodefilecopy(self, file_path: Path, src_path: Path, mode: int = None) -> None:
|
||||
"""
|
||||
|
@ -221,7 +223,7 @@ class DockerNode(CoreNode):
|
|||
:param mode: mode to copy to
|
||||
:return: nothing
|
||||
"""
|
||||
logging.info(
|
||||
logger.info(
|
||||
"node file copy file(%s) source(%s) mode(%s)", file_path, src_path, mode
|
||||
)
|
||||
self.cmd(f"mkdir -p {file_path.parent}")
|
||||
|
|
|
@ -15,6 +15,8 @@ from core.emulator.enumerations import TransportType
|
|||
from core.errors import CoreCommandError, CoreError
|
||||
from core.nodes.netclient import LinuxNetClient, get_net_client
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.emulator.distributed import DistributedServer
|
||||
from core.emulator.session import Session
|
||||
|
@ -274,7 +276,7 @@ class CoreInterface:
|
|||
:return: True if parameter changed, False otherwise
|
||||
"""
|
||||
# treat None and 0 as unchanged values
|
||||
logging.debug("setting param: %s - %s", key, value)
|
||||
logger.debug("setting param: %s - %s", key, value)
|
||||
if value is None or value < 0:
|
||||
return False
|
||||
|
||||
|
@ -457,7 +459,7 @@ class TunTap(CoreInterface):
|
|||
try:
|
||||
self.node.node_net_client.device_flush(self.name)
|
||||
except CoreCommandError:
|
||||
logging.exception("error shutting down tunnel tap")
|
||||
logger.exception("error shutting down tunnel tap")
|
||||
|
||||
self.up = False
|
||||
|
||||
|
@ -482,14 +484,14 @@ class TunTap(CoreInterface):
|
|||
msg = f"attempt {i} failed with nonzero exit status {r}"
|
||||
if i < attempts + 1:
|
||||
msg += ", retrying..."
|
||||
logging.info(msg)
|
||||
logger.info(msg)
|
||||
time.sleep(delay)
|
||||
delay += delay
|
||||
if delay > maxretrydelay:
|
||||
delay = maxretrydelay
|
||||
else:
|
||||
msg += ", giving up"
|
||||
logging.info(msg)
|
||||
logger.info(msg)
|
||||
|
||||
return result
|
||||
|
||||
|
@ -500,7 +502,7 @@ class TunTap(CoreInterface):
|
|||
|
||||
:return: wait for device local response
|
||||
"""
|
||||
logging.debug("waiting for device local: %s", self.localname)
|
||||
logger.debug("waiting for device local: %s", self.localname)
|
||||
|
||||
def localdevexists():
|
||||
try:
|
||||
|
@ -517,7 +519,7 @@ class TunTap(CoreInterface):
|
|||
|
||||
:return: nothing
|
||||
"""
|
||||
logging.debug("waiting for device node: %s", self.name)
|
||||
logger.debug("waiting for device node: %s", self.name)
|
||||
|
||||
def nodedevexists():
|
||||
try:
|
||||
|
@ -634,5 +636,5 @@ class GreTap(CoreInterface):
|
|||
self.net_client.device_down(self.localname)
|
||||
self.net_client.delete_device(self.localname)
|
||||
except CoreCommandError:
|
||||
logging.exception("error during shutdown")
|
||||
logger.exception("error during shutdown")
|
||||
self.localname = None
|
||||
|
|
|
@ -12,6 +12,8 @@ from core.errors import CoreCommandError
|
|||
from core.nodes.base import CoreNode
|
||||
from core.nodes.interface import CoreInterface
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.emulator.session import Session
|
||||
|
||||
|
@ -145,7 +147,7 @@ class LxcNode(CoreNode):
|
|||
:param dir_path: path to create
|
||||
:return: nothing
|
||||
"""
|
||||
logging.info("creating node dir: %s", dir_path)
|
||||
logger.info("creating node dir: %s", dir_path)
|
||||
args = f"mkdir -p {dir_path}"
|
||||
self.cmd(args)
|
||||
|
||||
|
@ -158,7 +160,7 @@ class LxcNode(CoreNode):
|
|||
:return: nothing
|
||||
:raises CoreCommandError: when a non-zero exit status occurs
|
||||
"""
|
||||
logging.debug("mounting source(%s) target(%s)", src_path, target_path)
|
||||
logger.debug("mounting source(%s) target(%s)", src_path, target_path)
|
||||
raise Exception("not supported")
|
||||
|
||||
def nodefile(self, file_path: Path, contents: str, mode: int = 0o644) -> None:
|
||||
|
@ -170,7 +172,7 @@ class LxcNode(CoreNode):
|
|||
:param mode: mode for file
|
||||
:return: nothing
|
||||
"""
|
||||
logging.debug("nodefile filename(%s) mode(%s)", file_path, mode)
|
||||
logger.debug("nodefile filename(%s) mode(%s)", file_path, mode)
|
||||
temp = NamedTemporaryFile(delete=False)
|
||||
temp.write(contents.encode("utf-8"))
|
||||
temp.close()
|
||||
|
@ -185,7 +187,7 @@ class LxcNode(CoreNode):
|
|||
if self.server is not None:
|
||||
self.host_cmd(f"rm -f {temp_path}")
|
||||
temp_path.unlink()
|
||||
logging.debug("node(%s) added file: %s; mode: 0%o", self.name, file_path, mode)
|
||||
logger.debug("node(%s) added file: %s; mode: 0%o", self.name, file_path, mode)
|
||||
|
||||
def nodefilecopy(self, file_path: Path, src_path: Path, mode: int = None) -> None:
|
||||
"""
|
||||
|
@ -197,7 +199,7 @@ class LxcNode(CoreNode):
|
|||
:param mode: mode to copy to
|
||||
:return: nothing
|
||||
"""
|
||||
logging.info(
|
||||
logger.info(
|
||||
"node file copy file(%s) source(%s) mode(%s)", file_path, src_path, mode
|
||||
)
|
||||
self.cmd(f"mkdir -p {file_path.parent}")
|
||||
|
|
|
@ -26,6 +26,8 @@ from core.nodes.base import CoreNetworkBase
|
|||
from core.nodes.interface import CoreInterface, GreTap, Veth
|
||||
from core.nodes.netclient import get_net_client
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.emulator.distributed import DistributedServer
|
||||
from core.emulator.session import Session
|
||||
|
@ -90,7 +92,7 @@ class EbtablesQueue:
|
|||
try:
|
||||
del self.last_update_time[wlan]
|
||||
except KeyError:
|
||||
logging.exception(
|
||||
logger.exception(
|
||||
"error deleting last update time for wlan, ignored before: %s", wlan
|
||||
)
|
||||
if len(self.last_update_time) > 0:
|
||||
|
@ -186,7 +188,7 @@ class EbtablesQueue:
|
|||
try:
|
||||
wlan.host_cmd(f"rm -f {self.atomic_file}")
|
||||
except CoreCommandError:
|
||||
logging.exception("error removing atomic file: %s", self.atomic_file)
|
||||
logger.exception("error removing atomic file: %s", self.atomic_file)
|
||||
|
||||
def ebchange(self, wlan: "CoreNetwork") -> None:
|
||||
"""
|
||||
|
@ -309,7 +311,7 @@ class CoreNetwork(CoreNetworkBase):
|
|||
:return: combined stdout and stderr
|
||||
:raises CoreCommandError: when a non-zero exit status occurs
|
||||
"""
|
||||
logging.debug("network node(%s) cmd", self.name)
|
||||
logger.debug("network node(%s) cmd", self.name)
|
||||
output = utils.cmd(args, env, cwd, wait, shell)
|
||||
self.session.distributed.execute(lambda x: x.remote_cmd(args, env, cwd, wait))
|
||||
return output
|
||||
|
@ -344,7 +346,7 @@ class CoreNetwork(CoreNetworkBase):
|
|||
]
|
||||
ebtablescmds(self.host_cmd, cmds)
|
||||
except CoreCommandError:
|
||||
logging.exception("error during shutdown")
|
||||
logger.exception("error during shutdown")
|
||||
# removes veth pairs used for bridge-to-bridge connections
|
||||
for iface in self.get_ifaces():
|
||||
iface.shutdown()
|
||||
|
@ -763,7 +765,7 @@ class CtrlNet(CoreNetwork):
|
|||
raise CoreError(f"old bridges exist for node: {self.id}")
|
||||
|
||||
super().startup()
|
||||
logging.info("added control network bridge: %s %s", self.brname, self.prefix)
|
||||
logger.info("added control network bridge: %s %s", self.brname, self.prefix)
|
||||
|
||||
if self.hostid and self.assign_address:
|
||||
self.add_addresses(self.hostid)
|
||||
|
@ -771,7 +773,7 @@ class CtrlNet(CoreNetwork):
|
|||
self.add_addresses(-2)
|
||||
|
||||
if self.updown_script:
|
||||
logging.info(
|
||||
logger.info(
|
||||
"interface %s updown script (%s startup) called",
|
||||
self.brname,
|
||||
self.updown_script,
|
||||
|
@ -791,7 +793,7 @@ class CtrlNet(CoreNetwork):
|
|||
try:
|
||||
self.net_client.delete_iface(self.brname, self.serverintf)
|
||||
except CoreCommandError:
|
||||
logging.exception(
|
||||
logger.exception(
|
||||
"error deleting server interface %s from bridge %s",
|
||||
self.serverintf,
|
||||
self.brname,
|
||||
|
@ -799,14 +801,14 @@ class CtrlNet(CoreNetwork):
|
|||
|
||||
if self.updown_script is not None:
|
||||
try:
|
||||
logging.info(
|
||||
logger.info(
|
||||
"interface %s updown script (%s shutdown) called",
|
||||
self.brname,
|
||||
self.updown_script,
|
||||
)
|
||||
self.host_cmd(f"{self.updown_script} {self.brname} shutdown")
|
||||
except CoreCommandError:
|
||||
logging.exception("error issuing shutdown script shutdown")
|
||||
logger.exception("error issuing shutdown script shutdown")
|
||||
|
||||
super().shutdown()
|
||||
|
||||
|
@ -1006,7 +1008,7 @@ class WlanNode(CoreNetwork):
|
|||
:param config: configuration for model being set
|
||||
:return: nothing
|
||||
"""
|
||||
logging.debug("node(%s) setting model: %s", self.name, model.name)
|
||||
logger.debug("node(%s) setting model: %s", self.name, model.name)
|
||||
if model.config_type == RegisterTlvs.WIRELESS:
|
||||
self.model = model(session=self.session, _id=self.id)
|
||||
for iface in self.get_ifaces():
|
||||
|
@ -1025,7 +1027,7 @@ class WlanNode(CoreNetwork):
|
|||
def updatemodel(self, config: Dict[str, str]) -> None:
|
||||
if not self.model:
|
||||
raise CoreError(f"no model set to update for node({self.name})")
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
"node(%s) updating model(%s): %s", self.id, self.model.name, config
|
||||
)
|
||||
self.model.update_config(config)
|
||||
|
|
|
@ -16,6 +16,8 @@ from core.nodes.base import CoreNetworkBase, CoreNodeBase
|
|||
from core.nodes.interface import DEFAULT_MTU, CoreInterface
|
||||
from core.nodes.network import CoreNetwork, GreTap
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.emulator.session import Session
|
||||
|
||||
|
@ -163,7 +165,7 @@ class PhysicalNode(CoreNodeBase):
|
|||
def new_iface(
|
||||
self, net: CoreNetworkBase, iface_data: InterfaceData
|
||||
) -> CoreInterface:
|
||||
logging.info("creating interface")
|
||||
logger.info("creating interface")
|
||||
ips = iface_data.get_ips()
|
||||
iface_id = iface_data.id
|
||||
if iface_id is None:
|
||||
|
@ -191,17 +193,17 @@ class PhysicalNode(CoreNodeBase):
|
|||
self.mount(host_path, dir_path)
|
||||
|
||||
def mount(self, src_path: Path, target_path: Path) -> None:
|
||||
logging.debug("node(%s) mounting: %s at %s", self.name, src_path, target_path)
|
||||
logger.debug("node(%s) mounting: %s at %s", self.name, src_path, target_path)
|
||||
self.cmd(f"mkdir -p {target_path}")
|
||||
self.host_cmd(f"{MOUNT} --bind {src_path} {target_path}", cwd=self.directory)
|
||||
self._mounts.append((src_path, target_path))
|
||||
|
||||
def umount(self, target_path: Path) -> None:
|
||||
logging.info("unmounting '%s'", target_path)
|
||||
logger.info("unmounting '%s'", target_path)
|
||||
try:
|
||||
self.host_cmd(f"{UMOUNT} -l {target_path}", cwd=self.directory)
|
||||
except CoreCommandError:
|
||||
logging.exception("unmounting failed for %s", target_path)
|
||||
logger.exception("unmounting failed for %s", target_path)
|
||||
|
||||
def nodefile(self, file_path: Path, contents: str, mode: int = 0o644) -> None:
|
||||
host_path = self.host_path(file_path)
|
||||
|
@ -211,7 +213,7 @@ class PhysicalNode(CoreNodeBase):
|
|||
with host_path.open("w") as f:
|
||||
f.write(contents)
|
||||
host_path.chmod(mode)
|
||||
logging.info("created nodefile: '%s'; mode: 0%o", host_path, mode)
|
||||
logger.info("created nodefile: '%s'; mode: 0%o", host_path, mode)
|
||||
|
||||
def cmd(self, args: str, wait: bool = True, shell: bool = False) -> str:
|
||||
return self.host_cmd(args, wait=wait)
|
||||
|
@ -415,7 +417,7 @@ class Rj45Node(CoreNodeBase):
|
|||
if items[1][:4] == "fe80":
|
||||
continue
|
||||
self.old_addrs.append((items[1], None))
|
||||
logging.info("saved rj45 state: addrs(%s) up(%s)", self.old_addrs, self.old_up)
|
||||
logger.info("saved rj45 state: addrs(%s) up(%s)", self.old_addrs, self.old_up)
|
||||
|
||||
def restorestate(self) -> None:
|
||||
"""
|
||||
|
@ -425,7 +427,7 @@ class Rj45Node(CoreNodeBase):
|
|||
:raises CoreCommandError: when there is a command exception
|
||||
"""
|
||||
localname = self.iface.localname
|
||||
logging.info("restoring rj45 state: %s", localname)
|
||||
logger.info("restoring rj45 state: %s", localname)
|
||||
for addr in self.old_addrs:
|
||||
self.net_client.create_address(localname, addr[0], addr[1])
|
||||
if self.old_up:
|
||||
|
|
|
@ -15,6 +15,8 @@ from core.errors import CoreError
|
|||
from core.nodes.base import CoreNetworkBase, NodeBase
|
||||
from core.nodes.network import WlanNode
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.emulator.session import Session
|
||||
|
||||
|
@ -109,7 +111,7 @@ class Sdt:
|
|||
return False
|
||||
|
||||
self.seturl()
|
||||
logging.info("connecting to SDT at %s://%s", self.protocol, self.address)
|
||||
logger.info("connecting to SDT at %s://%s", self.protocol, self.address)
|
||||
if self.sock is None:
|
||||
try:
|
||||
if self.protocol.lower() == "udp":
|
||||
|
@ -119,7 +121,7 @@ class Sdt:
|
|||
# Default to tcp
|
||||
self.sock = socket.create_connection(self.address, 5)
|
||||
except IOError:
|
||||
logging.exception("SDT socket connect error")
|
||||
logger.exception("SDT socket connect error")
|
||||
return False
|
||||
|
||||
if not self.initialize():
|
||||
|
@ -157,7 +159,7 @@ class Sdt:
|
|||
try:
|
||||
self.sock.close()
|
||||
except IOError:
|
||||
logging.error("error closing socket")
|
||||
logger.error("error closing socket")
|
||||
finally:
|
||||
self.sock = None
|
||||
|
||||
|
@ -191,11 +193,11 @@ class Sdt:
|
|||
|
||||
try:
|
||||
cmd = f"{cmdstr}\n".encode()
|
||||
logging.debug("sdt cmd: %s", cmd)
|
||||
logger.debug("sdt cmd: %s", cmd)
|
||||
self.sock.sendall(cmd)
|
||||
return True
|
||||
except IOError:
|
||||
logging.exception("SDT connection error")
|
||||
logger.exception("SDT connection error")
|
||||
self.sock = None
|
||||
self.connected = False
|
||||
return False
|
||||
|
@ -250,7 +252,7 @@ class Sdt:
|
|||
:param node: node to add
|
||||
:return: nothing
|
||||
"""
|
||||
logging.debug("sdt add node: %s - %s", node.id, node.name)
|
||||
logger.debug("sdt add node: %s - %s", node.id, node.name)
|
||||
if not self.connect():
|
||||
return
|
||||
pos = self.get_node_position(node)
|
||||
|
@ -262,8 +264,8 @@ class Sdt:
|
|||
icon = node.icon
|
||||
if icon:
|
||||
node_type = node.name
|
||||
icon = icon.replace("$CORE_DATA_DIR", CORE_DATA_DIR)
|
||||
icon = icon.replace("$CORE_CONF_DIR", CORE_CONF_DIR)
|
||||
icon = icon.replace("$CORE_DATA_DIR", str(CORE_DATA_DIR))
|
||||
icon = icon.replace("$CORE_CONF_DIR", str(CORE_CONF_DIR))
|
||||
self.cmd(f"sprite {node_type} image {icon}")
|
||||
self.cmd(
|
||||
f'node {node.id} nodeLayer "{NODE_LAYER}" '
|
||||
|
@ -280,7 +282,7 @@ class Sdt:
|
|||
:param alt: node altitude
|
||||
:return: nothing
|
||||
"""
|
||||
logging.debug("sdt update node: %s - %s", node.id, node.name)
|
||||
logger.debug("sdt update node: %s - %s", node.id, node.name)
|
||||
if not self.connect():
|
||||
return
|
||||
|
||||
|
@ -300,7 +302,7 @@ class Sdt:
|
|||
:param node_id: node id to delete
|
||||
:return: nothing
|
||||
"""
|
||||
logging.debug("sdt delete node: %s", node_id)
|
||||
logger.debug("sdt delete node: %s", node_id)
|
||||
if not self.connect():
|
||||
return
|
||||
self.cmd(f"delete node,{node_id}")
|
||||
|
@ -315,7 +317,7 @@ class Sdt:
|
|||
if not self.connect():
|
||||
return
|
||||
node = node_data.node
|
||||
logging.debug("sdt handle node update: %s - %s", node.id, node.name)
|
||||
logger.debug("sdt handle node update: %s - %s", node.id, node.name)
|
||||
if node_data.message_type == MessageFlags.DELETE:
|
||||
self.cmd(f"delete node,{node.id}")
|
||||
else:
|
||||
|
@ -356,7 +358,7 @@ class Sdt:
|
|||
:param label: label for link
|
||||
:return: nothing
|
||||
"""
|
||||
logging.debug("sdt add link: %s, %s, %s", node1_id, node2_id, network_id)
|
||||
logger.debug("sdt add link: %s, %s, %s", node1_id, node2_id, network_id)
|
||||
if not self.connect():
|
||||
return
|
||||
if self.wireless_net_check(node1_id) or self.wireless_net_check(node2_id):
|
||||
|
@ -396,7 +398,7 @@ class Sdt:
|
|||
:param network_id: network link is associated with, None otherwise
|
||||
:return: nothing
|
||||
"""
|
||||
logging.debug("sdt delete link: %s, %s, %s", node1_id, node2_id, network_id)
|
||||
logger.debug("sdt delete link: %s, %s, %s", node1_id, node2_id, network_id)
|
||||
if not self.connect():
|
||||
return
|
||||
if self.wireless_net_check(node1_id) or self.wireless_net_check(node2_id):
|
||||
|
@ -416,7 +418,7 @@ class Sdt:
|
|||
:param label: label to update
|
||||
:return: nothing
|
||||
"""
|
||||
logging.debug("sdt edit link: %s, %s, %s", node1_id, node2_id, network_id)
|
||||
logger.debug("sdt edit link: %s, %s, %s", node1_id, node2_id, network_id)
|
||||
if not self.connect():
|
||||
return
|
||||
if self.wireless_net_check(node1_id) or self.wireless_net_check(node2_id):
|
||||
|
|
|
@ -34,6 +34,8 @@ from core.errors import (
|
|||
)
|
||||
from core.nodes.base import CoreNode
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.emulator.session import Session
|
||||
|
||||
|
@ -161,7 +163,7 @@ class ServiceShim:
|
|||
cls.setvalue(service, key, values[cls.keys.index(key)])
|
||||
except IndexError:
|
||||
# old config does not need to have new keys
|
||||
logging.exception("error indexing into key")
|
||||
logger.exception("error indexing into key")
|
||||
|
||||
@classmethod
|
||||
def setvalue(cls, service: "CoreService", key: str, value: str) -> None:
|
||||
|
@ -228,7 +230,7 @@ class ServiceManager:
|
|||
:raises ValueError: when service cannot be loaded
|
||||
"""
|
||||
name = service.name
|
||||
logging.debug("loading service: class(%s) name(%s)", service.__name__, name)
|
||||
logger.debug("loading service: class(%s) name(%s)", service.__name__, name)
|
||||
|
||||
# avoid duplicate services
|
||||
if name in cls.services:
|
||||
|
@ -245,7 +247,7 @@ class ServiceManager:
|
|||
try:
|
||||
service.on_load()
|
||||
except Exception as e:
|
||||
logging.exception("error during service(%s) on load", service.name)
|
||||
logger.exception("error during service(%s) on load", service.name)
|
||||
raise ValueError(e)
|
||||
|
||||
# make service available
|
||||
|
@ -281,7 +283,7 @@ class ServiceManager:
|
|||
cls.add(service)
|
||||
except (CoreError, ValueError) as e:
|
||||
service_errors.append(service.name)
|
||||
logging.debug("not loading service(%s): %s", service.name, e)
|
||||
logger.debug("not loading service(%s): %s", service.name, e)
|
||||
return service_errors
|
||||
|
||||
|
||||
|
@ -329,14 +331,14 @@ class CoreServices:
|
|||
:param node_type: node type to get default services for
|
||||
:return: default services
|
||||
"""
|
||||
logging.debug("getting default services for type: %s", node_type)
|
||||
logger.debug("getting default services for type: %s", node_type)
|
||||
results = []
|
||||
defaults = self.default_services.get(node_type, [])
|
||||
for name in defaults:
|
||||
logging.debug("checking for service with service manager: %s", name)
|
||||
logger.debug("checking for service with service manager: %s", name)
|
||||
service = ServiceManager.get(name)
|
||||
if not service:
|
||||
logging.warning("default service %s is unknown", name)
|
||||
logger.warning("default service %s is unknown", name)
|
||||
else:
|
||||
results.append(service)
|
||||
return results
|
||||
|
@ -369,7 +371,7 @@ class CoreServices:
|
|||
:param service_name: name of service to set
|
||||
:return: nothing
|
||||
"""
|
||||
logging.debug("setting custom service(%s) for node: %s", service_name, node_id)
|
||||
logger.debug("setting custom service(%s) for node: %s", service_name, node_id)
|
||||
service = self.get_service(node_id, service_name)
|
||||
if not service:
|
||||
service_class = ServiceManager.get(service_name)
|
||||
|
@ -391,15 +393,15 @@ class CoreServices:
|
|||
:return: nothing
|
||||
"""
|
||||
if not services:
|
||||
logging.info(
|
||||
logger.info(
|
||||
"using default services for node(%s) type(%s)", node.name, node_type
|
||||
)
|
||||
services = self.default_services.get(node_type, [])
|
||||
logging.info("setting services for node(%s): %s", node.name, services)
|
||||
logger.info("setting services for node(%s): %s", node.name, services)
|
||||
for service_name in services:
|
||||
service = self.get_service(node.id, service_name, default_service=True)
|
||||
if not service:
|
||||
logging.warning(
|
||||
logger.warning(
|
||||
"unknown service(%s) for node(%s)", service_name, node.name
|
||||
)
|
||||
continue
|
||||
|
@ -457,7 +459,7 @@ class CoreServices:
|
|||
raise CoreServiceBootError(*exceptions)
|
||||
|
||||
def _boot_service_path(self, node: CoreNode, boot_path: List["CoreServiceType"]):
|
||||
logging.info(
|
||||
logger.info(
|
||||
"booting node(%s) services: %s",
|
||||
node.name,
|
||||
" -> ".join([x.name for x in boot_path]),
|
||||
|
@ -467,7 +469,7 @@ class CoreServices:
|
|||
try:
|
||||
self.boot_service(node, service)
|
||||
except Exception as e:
|
||||
logging.exception("exception booting service: %s", service.name)
|
||||
logger.exception("exception booting service: %s", service.name)
|
||||
raise CoreServiceBootError(e)
|
||||
|
||||
def boot_service(self, node: CoreNode, service: "CoreServiceType") -> None:
|
||||
|
@ -479,7 +481,7 @@ class CoreServices:
|
|||
:param service: service to start
|
||||
:return: nothing
|
||||
"""
|
||||
logging.info(
|
||||
logger.info(
|
||||
"starting node(%s) service(%s) validation(%s)",
|
||||
node.name,
|
||||
service.name,
|
||||
|
@ -492,7 +494,7 @@ class CoreServices:
|
|||
try:
|
||||
node.privatedir(dir_path)
|
||||
except (CoreCommandError, CoreError) as e:
|
||||
logging.warning(
|
||||
logger.warning(
|
||||
"error mounting private dir '%s' for service '%s': %s",
|
||||
directory,
|
||||
service.name,
|
||||
|
@ -563,21 +565,21 @@ class CoreServices:
|
|||
:param service: service to validate
|
||||
:return: service validation status
|
||||
"""
|
||||
logging.debug("validating node(%s) service(%s)", node.name, service.name)
|
||||
logger.debug("validating node(%s) service(%s)", node.name, service.name)
|
||||
cmds = service.validate
|
||||
if not service.custom:
|
||||
cmds = service.get_validate(node)
|
||||
|
||||
status = 0
|
||||
for cmd in cmds:
|
||||
logging.debug("validating service(%s) using: %s", service.name, cmd)
|
||||
logger.debug("validating service(%s) using: %s", service.name, cmd)
|
||||
try:
|
||||
node.cmd(cmd)
|
||||
except CoreCommandError as e:
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
"node(%s) service(%s) validate failed", node.name, service.name
|
||||
)
|
||||
logging.debug("cmd(%s): %s", e.cmd, e.output)
|
||||
logger.debug("cmd(%s): %s", e.cmd, e.output)
|
||||
status = -1
|
||||
break
|
||||
|
||||
|
@ -612,7 +614,7 @@ class CoreServices:
|
|||
f"error stopping service {service.name}: {e.stderr}",
|
||||
node.id,
|
||||
)
|
||||
logging.exception("error running stop command %s", args)
|
||||
logger.exception("error running stop command %s", args)
|
||||
status = -1
|
||||
return status
|
||||
|
||||
|
@ -680,13 +682,13 @@ class CoreServices:
|
|||
# retrieve custom service
|
||||
service = self.get_service(node_id, service_name)
|
||||
if service is None:
|
||||
logging.warning("received file name for unknown service: %s", service_name)
|
||||
logger.warning("received file name for unknown service: %s", service_name)
|
||||
return
|
||||
|
||||
# validate file being set is valid
|
||||
config_files = service.configs
|
||||
if file_name not in config_files:
|
||||
logging.warning(
|
||||
logger.warning(
|
||||
"received unknown file(%s) for service(%s)", file_name, service_name
|
||||
)
|
||||
return
|
||||
|
@ -714,7 +716,7 @@ class CoreServices:
|
|||
try:
|
||||
node.cmd(cmd, wait)
|
||||
except CoreCommandError:
|
||||
logging.exception("error starting command")
|
||||
logger.exception("error starting command")
|
||||
status = -1
|
||||
return status
|
||||
|
||||
|
@ -732,7 +734,7 @@ class CoreServices:
|
|||
config_files = service.get_configs(node)
|
||||
for file_name in config_files:
|
||||
file_path = Path(file_name)
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
"generating service config custom(%s): %s", service.custom, file_name
|
||||
)
|
||||
if service.custom:
|
||||
|
@ -744,7 +746,7 @@ class CoreServices:
|
|||
if self.copy_service_file(node, file_path, cfg):
|
||||
continue
|
||||
except IOError:
|
||||
logging.exception("error copying service file: %s", file_name)
|
||||
logger.exception("error copying service file: %s", file_name)
|
||||
continue
|
||||
else:
|
||||
cfg = service.generate_config(node, file_name)
|
||||
|
|
|
@ -11,6 +11,8 @@ from core.nodes.base import CoreNode
|
|||
from core.nodes.interface import CoreInterface
|
||||
from core.services.coreservices import CoreService
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class VPNClient(CoreService):
|
||||
name: str = "VPNClient"
|
||||
|
@ -33,7 +35,7 @@ class VPNClient(CoreService):
|
|||
with open(fname, "r") as f:
|
||||
cfg += f.read()
|
||||
except IOError:
|
||||
logging.exception(
|
||||
logger.exception(
|
||||
"error opening VPN client configuration template (%s)", fname
|
||||
)
|
||||
return cfg
|
||||
|
@ -61,7 +63,7 @@ class VPNServer(CoreService):
|
|||
with open(fname, "r") as f:
|
||||
cfg += f.read()
|
||||
except IOError:
|
||||
logging.exception(
|
||||
logger.exception(
|
||||
"Error opening VPN server configuration template (%s)", fname
|
||||
)
|
||||
return cfg
|
||||
|
@ -89,7 +91,7 @@ class IPsec(CoreService):
|
|||
with open(fname, "r") as f:
|
||||
cfg += f.read()
|
||||
except IOError:
|
||||
logging.exception("Error opening IPsec configuration template (%s)", fname)
|
||||
logger.exception("Error opening IPsec configuration template (%s)", fname)
|
||||
return cfg
|
||||
|
||||
|
||||
|
@ -112,7 +114,7 @@ class Firewall(CoreService):
|
|||
with open(fname, "r") as f:
|
||||
cfg += f.read()
|
||||
except IOError:
|
||||
logging.exception(
|
||||
logger.exception(
|
||||
"Error opening Firewall configuration template (%s)", fname
|
||||
)
|
||||
return cfg
|
||||
|
|
|
@ -36,6 +36,8 @@ import netaddr
|
|||
|
||||
from core.errors import CoreCommandError, CoreError
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.emulator.session import Session
|
||||
from core.nodes.base import CoreNode
|
||||
|
@ -204,7 +206,7 @@ def cmd(
|
|||
:raises CoreCommandError: when there is a non-zero exit status or the file to
|
||||
execute is not found
|
||||
"""
|
||||
logging.debug("command cwd(%s) wait(%s): %s", cwd, wait, args)
|
||||
logger.debug("command cwd(%s) wait(%s): %s", cwd, wait, args)
|
||||
if shell is False:
|
||||
args = shlex.split(args)
|
||||
try:
|
||||
|
@ -221,7 +223,7 @@ def cmd(
|
|||
else:
|
||||
return ""
|
||||
except OSError as e:
|
||||
logging.error("cmd error: %s", e.strerror)
|
||||
logger.error("cmd error: %s", e.strerror)
|
||||
raise CoreCommandError(1, args, "", e.strerror)
|
||||
|
||||
|
||||
|
@ -323,7 +325,7 @@ def load_config(file_path: Path, d: Dict[str, str]) -> None:
|
|||
key, value = line.split("=", 1)
|
||||
d[key] = value.strip()
|
||||
except ValueError:
|
||||
logging.exception("error reading file to dict: %s", file_path)
|
||||
logger.exception("error reading file to dict: %s", file_path)
|
||||
|
||||
|
||||
def load_classes(path: Path, clazz: Generic[T]) -> T:
|
||||
|
@ -335,13 +337,13 @@ def load_classes(path: Path, clazz: Generic[T]) -> T:
|
|||
:return: list of classes loaded
|
||||
"""
|
||||
# validate path exists
|
||||
logging.debug("attempting to load modules from path: %s", path)
|
||||
logger.debug("attempting to load modules from path: %s", path)
|
||||
if not path.is_dir():
|
||||
logging.warning("invalid custom module directory specified" ": %s", path)
|
||||
logger.warning("invalid custom module directory specified" ": %s", path)
|
||||
# check if path is in sys.path
|
||||
parent = str(path.parent)
|
||||
if parent not in sys.path:
|
||||
logging.debug("adding parent path to allow imports: %s", parent)
|
||||
logger.debug("adding parent path to allow imports: %s", parent)
|
||||
sys.path.append(parent)
|
||||
# import and add all service modules in the path
|
||||
classes = []
|
||||
|
@ -349,7 +351,7 @@ def load_classes(path: Path, clazz: Generic[T]) -> T:
|
|||
if not _valid_module(p):
|
||||
continue
|
||||
import_statement = f"{path.name}.{p.stem}"
|
||||
logging.debug("importing custom module: %s", import_statement)
|
||||
logger.debug("importing custom module: %s", import_statement)
|
||||
try:
|
||||
module = importlib.import_module(import_statement)
|
||||
members = inspect.getmembers(module, lambda x: _is_class(module, x, clazz))
|
||||
|
@ -357,7 +359,7 @@ def load_classes(path: Path, clazz: Generic[T]) -> T:
|
|||
valid_class = member[1]
|
||||
classes.append(valid_class)
|
||||
except Exception:
|
||||
logging.exception(
|
||||
logger.exception(
|
||||
"unexpected error during import, skipping: %s", import_statement
|
||||
)
|
||||
return classes
|
||||
|
@ -398,7 +400,7 @@ def threadpool(
|
|||
result = future.result()
|
||||
results.append(result)
|
||||
except Exception as e:
|
||||
logging.exception("thread pool exception")
|
||||
logger.exception("thread pool exception")
|
||||
exceptions.append(e)
|
||||
return results, exceptions
|
||||
|
||||
|
|
|
@ -17,6 +17,8 @@ from core.nodes.lxd import LxcNode
|
|||
from core.nodes.network import CtrlNet, GreTapBridge, WlanNode
|
||||
from core.services.coreservices import CoreService
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.emane.emanemodel import EmaneModel
|
||||
from core.emulator.session import Session
|
||||
|
@ -384,7 +386,7 @@ class CoreXmlWriter:
|
|||
node_id, iface_id = utils.parse_iface_config_id(node_id)
|
||||
for model_name in all_configs:
|
||||
config = all_configs[model_name]
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
"writing emane config node(%s) model(%s)", node_id, model_name
|
||||
)
|
||||
model = self.session.emane.models[model_name]
|
||||
|
@ -404,7 +406,7 @@ class CoreXmlWriter:
|
|||
|
||||
for model_name in all_configs:
|
||||
config = all_configs[model_name]
|
||||
logging.debug(
|
||||
logger.debug(
|
||||
"writing mobility config node(%s) model(%s)", node_id, model_name
|
||||
)
|
||||
mobility_configuration = etree.SubElement(
|
||||
|
@ -609,7 +611,7 @@ class CoreXmlReader:
|
|||
services = []
|
||||
for service in node.iterchildren():
|
||||
services.append(service.get("name"))
|
||||
logging.info(
|
||||
logger.info(
|
||||
"reading default services for nodes(%s): %s", node_type, services
|
||||
)
|
||||
self.session.services.default_services[node_type] = services
|
||||
|
@ -624,7 +626,7 @@ class CoreXmlReader:
|
|||
name = data.get("name")
|
||||
value = data.get("value")
|
||||
configs[name] = value
|
||||
logging.info("reading session metadata: %s", configs)
|
||||
logger.info("reading session metadata: %s", configs)
|
||||
self.session.metadata = configs
|
||||
|
||||
def read_session_options(self) -> None:
|
||||
|
@ -636,7 +638,7 @@ class CoreXmlReader:
|
|||
name = configuration.get("name")
|
||||
value = configuration.get("value")
|
||||
xml_config[name] = value
|
||||
logging.info("reading session options: %s", xml_config)
|
||||
logger.info("reading session options: %s", xml_config)
|
||||
config = self.session.options.get_configs()
|
||||
config.update(xml_config)
|
||||
|
||||
|
@ -650,7 +652,7 @@ class CoreXmlReader:
|
|||
state = get_int(hook, "state")
|
||||
state = EventTypes(state)
|
||||
data = hook.text
|
||||
logging.info("reading hook: state(%s) name(%s)", state, name)
|
||||
logger.info("reading hook: state(%s) name(%s)", state, name)
|
||||
self.session.add_hook(state, name, data)
|
||||
|
||||
def read_servers(self) -> None:
|
||||
|
@ -660,7 +662,7 @@ class CoreXmlReader:
|
|||
for server in servers.iterchildren():
|
||||
name = server.get("name")
|
||||
address = server.get("address")
|
||||
logging.info("reading server: name(%s) address(%s)", name, address)
|
||||
logger.info("reading server: name(%s) address(%s)", name, address)
|
||||
self.session.distributed.add_server(name, address)
|
||||
|
||||
def read_session_origin(self) -> None:
|
||||
|
@ -672,19 +674,19 @@ class CoreXmlReader:
|
|||
lon = get_float(session_origin, "lon")
|
||||
alt = get_float(session_origin, "alt")
|
||||
if all([lat, lon, alt]):
|
||||
logging.info("reading session reference geo: %s, %s, %s", lat, lon, alt)
|
||||
logger.info("reading session reference geo: %s, %s, %s", lat, lon, alt)
|
||||
self.session.location.setrefgeo(lat, lon, alt)
|
||||
|
||||
scale = get_float(session_origin, "scale")
|
||||
if scale:
|
||||
logging.info("reading session reference scale: %s", scale)
|
||||
logger.info("reading session reference scale: %s", scale)
|
||||
self.session.location.refscale = scale
|
||||
|
||||
x = get_float(session_origin, "x")
|
||||
y = get_float(session_origin, "y")
|
||||
z = get_float(session_origin, "z")
|
||||
if all([x, y]):
|
||||
logging.info("reading session reference xyz: %s, %s, %s", x, y, z)
|
||||
logger.info("reading session reference xyz: %s, %s, %s", x, y, z)
|
||||
self.session.location.refxyz = (x, y, z)
|
||||
|
||||
def read_service_configs(self) -> None:
|
||||
|
@ -695,7 +697,7 @@ class CoreXmlReader:
|
|||
for service_configuration in service_configurations.iterchildren():
|
||||
node_id = get_int(service_configuration, "node")
|
||||
service_name = service_configuration.get("name")
|
||||
logging.info(
|
||||
logger.info(
|
||||
"reading custom service(%s) for node(%s)", service_name, node_id
|
||||
)
|
||||
self.session.services.set_service(node_id, service_name)
|
||||
|
@ -790,7 +792,7 @@ class CoreXmlReader:
|
|||
value = config.get("value")
|
||||
configs[name] = value
|
||||
|
||||
logging.info(
|
||||
logger.info(
|
||||
"reading emane configuration node(%s) model(%s)", node_id, model_name
|
||||
)
|
||||
node_id = utils.iface_config_id(node_id, iface_id)
|
||||
|
@ -811,7 +813,7 @@ class CoreXmlReader:
|
|||
value = config.get("value")
|
||||
configs[name] = value
|
||||
|
||||
logging.info(
|
||||
logger.info(
|
||||
"reading mobility configuration node(%s) model(%s)", node_id, model_name
|
||||
)
|
||||
self.session.mobility.set_model_config(node_id, model_name, configs)
|
||||
|
@ -868,7 +870,7 @@ class CoreXmlReader:
|
|||
if all([lat, lon, alt]):
|
||||
options.set_location(lat, lon, alt)
|
||||
|
||||
logging.info("reading node id(%s) model(%s) name(%s)", node_id, model, name)
|
||||
logger.info("reading node id(%s) model(%s) name(%s)", node_id, model, name)
|
||||
self.session.add_node(_class, node_id, options)
|
||||
|
||||
def read_network(self, network_element: etree.Element) -> None:
|
||||
|
@ -896,7 +898,7 @@ class CoreXmlReader:
|
|||
if all([lat, lon, alt]):
|
||||
options.set_location(lat, lon, alt)
|
||||
|
||||
logging.info(
|
||||
logger.info(
|
||||
"reading node id(%s) node_type(%s) name(%s)", node_id, node_type, name
|
||||
)
|
||||
self.session.add_node(_class, node_id, options)
|
||||
|
@ -926,7 +928,7 @@ class CoreXmlReader:
|
|||
for template_element in templates_element.iterchildren():
|
||||
name = template_element.get("name")
|
||||
template = template_element.text
|
||||
logging.info(
|
||||
logger.info(
|
||||
"loading xml template(%s): %s", type(template), template
|
||||
)
|
||||
service.set_template(name, template)
|
||||
|
@ -978,12 +980,12 @@ class CoreXmlReader:
|
|||
options.buffer = get_int(options_element, "buffer")
|
||||
|
||||
if options.unidirectional == 1 and node_set in node_sets:
|
||||
logging.info("updating link node1(%s) node2(%s)", node1_id, node2_id)
|
||||
logger.info("updating link node1(%s) node2(%s)", node1_id, node2_id)
|
||||
self.session.update_link(
|
||||
node1_id, node2_id, iface1_data.id, iface2_data.id, options
|
||||
)
|
||||
else:
|
||||
logging.info("adding link node1(%s) node2(%s)", node1_id, node2_id)
|
||||
logger.info("adding link node1(%s) node2(%s)", node1_id, node2_id)
|
||||
self.session.add_link(
|
||||
node1_id, node2_id, iface1_data, iface2_data, options
|
||||
)
|
||||
|
|
|
@ -15,6 +15,8 @@ from core.nodes.interface import CoreInterface
|
|||
from core.nodes.network import CtrlNet
|
||||
from core.xml import corexml
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.emane.emanemanager import EmaneManager, StartData
|
||||
from core.emane.emanemodel import EmaneModel
|
||||
|
@ -47,7 +49,7 @@ def _value_to_params(value: str) -> Optional[Tuple[str]]:
|
|||
return None
|
||||
return values
|
||||
except SyntaxError:
|
||||
logging.exception("error in value string to param list")
|
||||
logger.exception("error in value string to param list")
|
||||
return None
|
||||
|
||||
|
||||
|
|
|
@ -13,8 +13,11 @@
|
|||
"format": "%(asctime)s - %(levelname)s - %(module)s:%(funcName)s - %(message)s"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"level": "INFO",
|
||||
"handlers": ["console"]
|
||||
}
|
||||
"loggers": {
|
||||
"core": {
|
||||
"level": "INFO",
|
||||
"handlers": ["console"],
|
||||
"propagate": false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@ from core.api.tlv.enumerations import CORE_API_PORT
|
|||
from core.constants import CORE_CONF_DIR, COREDPY_VERSION
|
||||
from core.utils import close_onexec, load_logging_config
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def banner():
|
||||
"""
|
||||
|
@ -29,7 +31,7 @@ def banner():
|
|||
|
||||
:return: nothing
|
||||
"""
|
||||
logging.info("CORE daemon v.%s started %s", constants.COREDPY_VERSION, time.ctime())
|
||||
logger.info("CORE daemon v.%s started %s", constants.COREDPY_VERSION, time.ctime())
|
||||
|
||||
|
||||
def start_udp(mainserver, server_address):
|
||||
|
@ -62,7 +64,7 @@ def cored(cfg):
|
|||
address = (host, port)
|
||||
server = CoreServer(address, CoreHandler, cfg)
|
||||
except:
|
||||
logging.exception("error starting main server on: %s:%s", host, port)
|
||||
logger.exception("error starting main server on: %s:%s", host, port)
|
||||
sys.exit(1)
|
||||
|
||||
# initialize grpc api
|
||||
|
@ -79,7 +81,7 @@ def cored(cfg):
|
|||
# close handlers
|
||||
close_onexec(server.fileno())
|
||||
|
||||
logging.info("CORE TLV API TCP/UDP listening on: %s:%s", host, port)
|
||||
logger.info("CORE TLV API TCP/UDP listening on: %s:%s", host, port)
|
||||
server.serve_forever()
|
||||
|
||||
|
||||
|
@ -155,7 +157,7 @@ def main():
|
|||
try:
|
||||
cored(cfg)
|
||||
except KeyboardInterrupt:
|
||||
logging.info("keyboard interrupt, stopping core daemon")
|
||||
logger.info("keyboard interrupt, stopping core daemon")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Reference in a new issue