diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml new file mode 100644 index 00000000..abbadab3 --- /dev/null +++ b/.github/workflows/documentation.yml @@ -0,0 +1,21 @@ +name: documentation +on: + push: + branches: + - master +permissions: + contents: write +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: 3.x + - uses: actions/cache@v2 + with: + key: ${{ github.ref }} + path: .cache + - run: pip install mkdocs-material + - run: mkdocs gh-deploy --force diff --git a/.gitignore b/.gitignore index beb83c13..ca4c07dd 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,9 @@ configure~ debian stamp-h1 +# python virtual environments +venv + # generated protobuf files *_pb2.py *_pb2_grpc.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 836571e8..425f2ae0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,26 @@ +## 2023-08-01 CORE 9.0.3 + +* Installation + * updated various dependencies +* Documentation + * improved GUI docs to include node interaction and note xhost usage + * \#780 - fixed gRPC examples + * \#787 - complete documentation revamp to leverage mkdocs material + * \#790 - fixed custom emane model example +* core-daemon + * update type hinting to avoid deprecated imports + * updated commands ran within docker based nodes to have proper environment variables + * fixed issue improperly setting session options over gRPC + * \#668 - add fedora sbin path to frr service + * \#774 - fixed pcap configservice + * \#805 - fixed radvd configservice template error +* core-gui + * update type hinting to avoid deprecated imports + * fixed issue allowing duplicate named hook scripts + * fixed issue joining sessions with RJ45 nodes +* utility scripts + * fixed issue in core-cleanup for removing devices + ## 2023-03-02 CORE 9.0.2 * Installation @@ -12,11 +35,10 @@ * fixed issue for LXC nodes to properly use a configured image name and write it to XML * \#742 - fixed issue with bad wlan node id being used * \#744 - fixed issue not properly setting broadcast address - -## core-gui -* fixed sample1.xml to remove SSH service -* fixed emane demo examples -* fixed issue displaying emane configs generally configured for a node +* core-gui + * fixed sample1.xml to remove SSH service + * fixed emane demo examples + * fixed issue displaying emane configs generally configured for a node ## 2022-11-28 CORE 9.0.1 diff --git a/configure.ac b/configure.ac index c8108f27..4e56507a 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. # this defines the CORE version number, must be static for AC_INIT -AC_INIT(core, 9.0.2) +AC_INIT(core, 9.0.3) # autoconf and automake initialization AC_CONFIG_SRCDIR([netns/version.h.in]) diff --git a/daemon/core/api/grpc/client.py b/daemon/core/api/grpc/client.py index a1559d64..2a5a1d44 100644 --- a/daemon/core/api/grpc/client.py +++ b/daemon/core/api/grpc/client.py @@ -4,10 +4,11 @@ gRpc client for interfacing with CORE. import logging import threading +from collections.abc import Callable, Generator, Iterable from contextlib import contextmanager from pathlib import Path from queue import Queue -from typing import Any, Callable, Dict, Generator, Iterable, List, Optional, Tuple +from typing import Any, Optional import grpc @@ -235,7 +236,7 @@ class CoreGrpcClient: def start_session( self, session: wrappers.Session, definition: bool = False - ) -> Tuple[bool, List[str]]: + ) -> tuple[bool, list[str]]: """ Start a session. @@ -285,7 +286,7 @@ class CoreGrpcClient: response = self.stub.DeleteSession(request) return response.result - def get_sessions(self) -> List[wrappers.SessionSummary]: + def get_sessions(self) -> list[wrappers.SessionSummary]: """ Retrieves all currently known sessions. @@ -354,7 +355,7 @@ class CoreGrpcClient: self, session_id: int, handler: Callable[[wrappers.Event], None], - events: List[wrappers.EventType] = None, + events: list[wrappers.EventType] = None, ) -> grpc.Future: """ Listen for session events. @@ -428,7 +429,7 @@ class CoreGrpcClient: def get_node( self, session_id: int, node_id: int - ) -> Tuple[wrappers.Node, List[wrappers.Interface], List[wrappers.Link]]: + ) -> tuple[wrappers.Node, list[wrappers.Interface], list[wrappers.Link]]: """ Get node details. @@ -536,7 +537,7 @@ class CoreGrpcClient: command: str, wait: bool = True, shell: bool = False, - ) -> Tuple[int, str]: + ) -> tuple[int, str]: """ Send command to a node and get the output. @@ -575,7 +576,7 @@ class CoreGrpcClient: def add_link( self, session_id: int, link: wrappers.Link, source: str = None - ) -> Tuple[bool, wrappers.Interface, wrappers.Interface]: + ) -> tuple[bool, wrappers.Interface, wrappers.Interface]: """ Add a link between nodes. @@ -646,7 +647,7 @@ class CoreGrpcClient: def get_mobility_config( self, session_id: int, node_id: int - ) -> Dict[str, wrappers.ConfigOption]: + ) -> dict[str, wrappers.ConfigOption]: """ Get mobility configuration for a node. @@ -660,7 +661,7 @@ class CoreGrpcClient: return wrappers.ConfigOption.from_dict(response.config) def set_mobility_config( - self, session_id: int, node_id: int, config: Dict[str, str] + self, session_id: int, node_id: int, config: dict[str, str] ) -> bool: """ Set mobility configuration for a node. @@ -706,7 +707,7 @@ class CoreGrpcClient: response = self.stub.GetConfig(request) return wrappers.CoreConfig.from_proto(response) - def get_service_defaults(self, session_id: int) -> List[wrappers.ServiceDefault]: + def get_service_defaults(self, session_id: int) -> list[wrappers.ServiceDefault]: """ Get default services for different default node models. @@ -723,7 +724,7 @@ class CoreGrpcClient: return defaults def set_service_defaults( - self, session_id: int, service_defaults: Dict[str, List[str]] + self, session_id: int, service_defaults: dict[str, list[str]] ) -> bool: """ Set default services for node models. @@ -829,7 +830,7 @@ class CoreGrpcClient: def get_wlan_config( self, session_id: int, node_id: int - ) -> Dict[str, wrappers.ConfigOption]: + ) -> dict[str, wrappers.ConfigOption]: """ Get wlan configuration for a node. @@ -843,7 +844,7 @@ class CoreGrpcClient: return wrappers.ConfigOption.from_dict(response.config) def set_wlan_config( - self, session_id: int, node_id: int, config: Dict[str, str] + self, session_id: int, node_id: int, config: dict[str, str] ) -> bool: """ Set wlan configuration for a node. @@ -861,7 +862,7 @@ class CoreGrpcClient: def get_emane_model_config( self, session_id: int, node_id: int, model: str, iface_id: int = -1 - ) -> Dict[str, wrappers.ConfigOption]: + ) -> dict[str, wrappers.ConfigOption]: """ Get emane model configuration for a node or a node's interface. @@ -909,7 +910,7 @@ class CoreGrpcClient: with open(file_path, "w") as xml_file: xml_file.write(response.data) - def open_xml(self, file_path: Path, start: bool = False) -> Tuple[bool, int]: + def open_xml(self, file_path: Path, start: bool = False) -> tuple[bool, int]: """ Load a local scenario XML file to open as a new session. @@ -940,7 +941,7 @@ class CoreGrpcClient: response = self.stub.EmaneLink(request) return response.result - def get_ifaces(self) -> List[str]: + def get_ifaces(self) -> list[str]: """ Retrieves a list of interfaces available on the host machine that are not a part of a CORE session. @@ -951,20 +952,26 @@ class CoreGrpcClient: response = self.stub.GetInterfaces(request) return list(response.ifaces) - def get_config_service_defaults(self, name: str) -> wrappers.ConfigServiceDefaults: + def get_config_service_defaults( + self, session_id: int, node_id: int, name: str + ) -> wrappers.ConfigServiceDefaults: """ Retrieves config service default values. + :param session_id: session id to get node from + :param node_id: node id to get service data from :param name: name of service to get defaults for :return: config service defaults """ - request = GetConfigServiceDefaultsRequest(name=name) + request = GetConfigServiceDefaultsRequest( + name=name, session_id=session_id, node_id=node_id + ) response = self.stub.GetConfigServiceDefaults(request) return wrappers.ConfigServiceDefaults.from_proto(response) def get_node_config_service( self, session_id: int, node_id: int, name: str - ) -> Dict[str, str]: + ) -> dict[str, str]: """ Retrieves information for a specific config service on a node. @@ -982,7 +989,7 @@ class CoreGrpcClient: def get_config_service_rendered( self, session_id: int, node_id: int, name: str - ) -> Dict[str, str]: + ) -> dict[str, str]: """ Retrieve the rendered config service files for a node. @@ -1129,7 +1136,7 @@ class CoreGrpcClient: def get_wireless_config( self, session_id: int, node_id: int - ) -> Dict[str, wrappers.ConfigOption]: + ) -> dict[str, wrappers.ConfigOption]: request = GetWirelessConfigRequest(session_id=session_id, node_id=node_id) response = self.stub.GetWirelessConfig(request) return wrappers.ConfigOption.from_dict(response.config) @@ -1156,7 +1163,7 @@ class CoreGrpcClient: self.channel = None @contextmanager - def context_connect(self) -> Generator: + def context_connect(self) -> Generator[None, None, None]: """ Makes a context manager based connection to the server, will close after context ends. diff --git a/daemon/core/api/grpc/events.py b/daemon/core/api/grpc/events.py index 82f03c20..65a20296 100644 --- a/daemon/core/api/grpc/events.py +++ b/daemon/core/api/grpc/events.py @@ -1,6 +1,7 @@ import logging +from collections.abc import Iterable from queue import Empty, Queue -from typing import Iterable, Optional +from typing import Optional from core.api.grpc import core_pb2, grpcutils from core.api.grpc.grpcutils import convert_link_data diff --git a/daemon/core/api/grpc/grpcutils.py b/daemon/core/api/grpc/grpcutils.py index 434314a4..f89144e4 100644 --- a/daemon/core/api/grpc/grpcutils.py +++ b/daemon/core/api/grpc/grpcutils.py @@ -1,7 +1,7 @@ import logging import time from pathlib import Path -from typing import Any, Dict, List, Optional, Tuple, Type, Union +from typing import Any, Optional, Union import grpc from grpc import ServicerContext @@ -36,6 +36,7 @@ from core.nodes.docker import DockerNode, DockerOptions from core.nodes.interface import CoreInterface from core.nodes.lxd import LxcNode, LxcOptions from core.nodes.network import CoreNetwork, CtrlNet, PtpNet, WlanNode +from core.nodes.podman import PodmanNode, PodmanOptions from core.nodes.wireless import WirelessNode from core.services.coreservices import CoreService @@ -63,8 +64,8 @@ class CpuUsage: def add_node_data( - _class: Type[NodeBase], node_proto: core_pb2.Node -) -> Tuple[Position, NodeOptions]: + _class: type[NodeBase], node_proto: core_pb2.Node +) -> tuple[Position, NodeOptions]: """ Convert node protobuf message to data for creating a node. @@ -81,7 +82,7 @@ def add_node_data( options.config_services = node_proto.config_services if isinstance(options, EmaneOptions): options.emane_model = node_proto.emane - if isinstance(options, (DockerOptions, LxcOptions)): + if isinstance(options, (DockerOptions, LxcOptions, PodmanOptions)): options.image = node_proto.image position = Position() position.set(node_proto.position.x, node_proto.position.y) @@ -118,7 +119,7 @@ def link_iface(iface_proto: core_pb2.Interface) -> InterfaceData: def add_link_data( link_proto: core_pb2.Link, -) -> Tuple[InterfaceData, InterfaceData, LinkOptions]: +) -> tuple[InterfaceData, InterfaceData, LinkOptions]: """ Convert link proto to link interfaces and options data. @@ -145,8 +146,8 @@ def add_link_data( def create_nodes( - session: Session, node_protos: List[core_pb2.Node] -) -> Tuple[List[NodeBase], List[Exception]]: + session: Session, node_protos: list[core_pb2.Node] +) -> tuple[list[NodeBase], list[Exception]]: """ Create nodes using a thread pool and wait for completion. @@ -176,8 +177,8 @@ def create_nodes( def create_links( - session: Session, link_protos: List[core_pb2.Link] -) -> Tuple[List[NodeBase], List[Exception]]: + session: Session, link_protos: list[core_pb2.Link] +) -> tuple[list[NodeBase], list[Exception]]: """ Create links using a thread pool and wait for completion. @@ -200,8 +201,8 @@ def create_links( def edit_links( - session: Session, link_protos: List[core_pb2.Link] -) -> Tuple[List[None], List[Exception]]: + session: Session, link_protos: list[core_pb2.Link] +) -> tuple[list[None], list[Exception]]: """ Edit links using a thread pool and wait for completion. @@ -235,7 +236,7 @@ def convert_value(value: Any) -> str: return value -def convert_session_options(session: Session) -> Dict[str, common_pb2.ConfigOption]: +def convert_session_options(session: Session) -> dict[str, common_pb2.ConfigOption]: config_options = {} for option in session.options.options: value = session.options.get(option.id) @@ -252,9 +253,9 @@ def convert_session_options(session: Session) -> Dict[str, common_pb2.ConfigOpti def get_config_options( - config: Dict[str, str], - configurable_options: Union[ConfigurableOptions, Type[ConfigurableOptions]], -) -> Dict[str, common_pb2.ConfigOption]: + config: dict[str, str], + configurable_options: Union[ConfigurableOptions, type[ConfigurableOptions]], +) -> dict[str, common_pb2.ConfigOption]: """ Retrieve configuration options in a form that is used by the grpc server. @@ -283,7 +284,7 @@ def get_config_options( def get_node_proto( - session: Session, node: NodeBase, emane_configs: List[NodeEmaneConfig] + session: Session, node: NodeBase, emane_configs: list[NodeEmaneConfig] ) -> core_pb2.Node: """ Convert CORE node to protobuf representation. @@ -313,7 +314,7 @@ def get_node_proto( if isinstance(node, EmaneNet): emane_model = node.wireless_model.name image = None - if isinstance(node, (DockerNode, LxcNode)): + if isinstance(node, (DockerNode, LxcNode, PodmanNode)): image = node.image # check for wlan config wlan_config = session.mobility.get_configs( @@ -390,7 +391,7 @@ def get_node_proto( ) -def get_links(session: Session, node: NodeBase) -> List[core_pb2.Link]: +def get_links(session: Session, node: NodeBase) -> list[core_pb2.Link]: """ Retrieve a list of links for grpc to use. @@ -435,7 +436,7 @@ def convert_iface(iface: CoreInterface) -> core_pb2.Interface: ) -def convert_core_link(core_link: CoreLink) -> List[core_pb2.Link]: +def convert_core_link(core_link: CoreLink) -> list[core_pb2.Link]: """ Convert core link to protobuf data. @@ -581,7 +582,7 @@ def convert_link( ) -def parse_proc_net_dev(lines: List[str]) -> Dict[str, Any]: +def parse_proc_net_dev(lines: list[str]) -> dict[str, dict[str, float]]: """ Parse lines of output from /proc/net/dev. @@ -599,7 +600,7 @@ def parse_proc_net_dev(lines: List[str]) -> Dict[str, Any]: return stats -def get_net_stats() -> Dict[str, Dict]: +def get_net_stats() -> dict[str, dict[str, float]]: """ Retrieve status about the current interfaces in the system @@ -728,7 +729,7 @@ def get_nem_id( return nem_id -def get_emane_model_configs_dict(session: Session) -> Dict[int, List[NodeEmaneConfig]]: +def get_emane_model_configs_dict(session: Session) -> dict[int, list[NodeEmaneConfig]]: """ Get emane model configuration protobuf data. @@ -751,7 +752,7 @@ def get_emane_model_configs_dict(session: Session) -> Dict[int, List[NodeEmaneCo return configs -def get_hooks(session: Session) -> List[core_pb2.Hook]: +def get_hooks(session: Session) -> list[core_pb2.Hook]: """ Retrieve hook protobuf data for a session. @@ -767,7 +768,7 @@ def get_hooks(session: Session) -> List[core_pb2.Hook]: return hooks -def get_default_services(session: Session) -> List[ServiceDefaults]: +def get_default_services(session: Session) -> list[ServiceDefaults]: """ Retrieve the default service sets for a given session. diff --git a/daemon/core/api/grpc/server.py b/daemon/core/api/grpc/server.py index 47615b29..6a86ab0a 100644 --- a/daemon/core/api/grpc/server.py +++ b/daemon/core/api/grpc/server.py @@ -5,9 +5,11 @@ import signal import sys import tempfile import time +from collections.abc import Iterable from concurrent import futures from pathlib import Path -from typing import Iterable, Optional, Pattern, Type +from re import Pattern +from typing import Optional import grpc from grpc import ServicerContext @@ -105,7 +107,7 @@ from core.services.coreservices import ServiceManager logger = logging.getLogger(__name__) _ONE_DAY_IN_SECONDS: int = 60 * 60 * 24 -_INTERFACE_REGEX: Pattern = re.compile(r"beth(?P[0-9a-fA-F]+)") +_INTERFACE_REGEX: Pattern[str] = re.compile(r"beth(?P[0-9a-fA-F]+)") _MAX_WORKERS = 1000 @@ -171,7 +173,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer): return session def get_node( - self, session: Session, node_id: int, context: ServicerContext, _class: Type[NT] + self, session: Session, node_id: int, context: ServicerContext, _class: type[NT] ) -> NT: """ Retrieve node given session and node id @@ -210,7 +212,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer): def validate_service( self, name: str, context: ServicerContext - ) -> Type[ConfigService]: + ) -> type[ConfigService]: """ Validates a configuration service is a valid known service. @@ -282,7 +284,8 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer): # session options for option in request.session.options.values(): - session.options.set(option.name, option.value) + if option.value: + session.options.set(option.name, option.value) session.metadata = dict(request.session.metadata) # add servers @@ -1103,7 +1106,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer): node_id = request.wlan_config.node_id config = request.wlan_config.config session.mobility.set_model_config(node_id, BasicRangeModel.name, config) - if session.state == EventTypes.RUNTIME_STATE: + if session.is_running(): node = self.get_node(session, node_id, context, WlanNode) node.updatemodel(config) return SetWlanConfigResponse(result=True) @@ -1176,7 +1179,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer): logger.debug("open xml: %s", request) session = self.coreemu.create_session() temp = tempfile.NamedTemporaryFile(delete=False) - temp.write(request.data.encode("utf-8")) + temp.write(request.data.encode()) temp.close() temp_path = Path(temp.name) file_path = Path(request.file) @@ -1282,8 +1285,10 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer): :param context: grpc context :return: get config service defaults response """ + session = self.get_session(request.session_id, context) + node = self.get_node(session, request.node_id, context, CoreNode) service_class = self.validate_service(request.name, context) - service = service_class(None) + service = service_class(node) templates = service.get_templates() config = {} for configuration in service.default_configs: diff --git a/daemon/core/api/grpc/wrappers.py b/daemon/core/api/grpc/wrappers.py index d3167a98..f84e6a08 100644 --- a/daemon/core/api/grpc/wrappers.py +++ b/daemon/core/api/grpc/wrappers.py @@ -1,7 +1,7 @@ from dataclasses import dataclass, field from enum import Enum from pathlib import Path -from typing import Any, Dict, List, Optional, Set, Tuple +from typing import Any, Optional from core.api.grpc import ( common_pb2, @@ -68,6 +68,7 @@ class NodeType(Enum): DOCKER = 15 LXC = 16 WIRELESS = 17 + PODMAN = 18 class LinkType(Enum): @@ -114,13 +115,13 @@ class EventType: class ConfigService: group: str name: str - executables: List[str] - dependencies: List[str] - directories: List[str] - files: List[str] - startup: List[str] - validate: List[str] - shutdown: List[str] + executables: list[str] + dependencies: list[str] + directories: list[str] + files: list[str] + startup: list[str] + validate: list[str] + shutdown: list[str] validation_mode: ConfigServiceValidationMode validation_timer: int validation_period: float @@ -147,8 +148,8 @@ class ConfigService: class ConfigServiceConfig: node_id: int name: str - templates: Dict[str, str] - config: Dict[str, str] + templates: dict[str, str] + config: dict[str, str] @classmethod def from_proto( @@ -164,15 +165,15 @@ class ConfigServiceConfig: @dataclass class ConfigServiceData: - templates: Dict[str, str] = field(default_factory=dict) - config: Dict[str, str] = field(default_factory=dict) + templates: dict[str, str] = field(default_factory=dict) + config: dict[str, str] = field(default_factory=dict) @dataclass class ConfigServiceDefaults: - templates: Dict[str, str] - config: Dict[str, "ConfigOption"] - modes: Dict[str, Dict[str, str]] + templates: dict[str, str] + config: dict[str, "ConfigOption"] + modes: dict[str, dict[str, str]] @classmethod def from_proto( @@ -211,7 +212,7 @@ class Service: @dataclass class ServiceDefault: model: str - services: List[str] + services: list[str] @classmethod def from_proto(cls, proto: services_pb2.ServiceDefaults) -> "ServiceDefault": @@ -220,15 +221,15 @@ class ServiceDefault: @dataclass class NodeServiceData: - executables: List[str] = field(default_factory=list) - dependencies: List[str] = field(default_factory=list) - dirs: List[str] = field(default_factory=list) - configs: List[str] = field(default_factory=list) - startup: List[str] = field(default_factory=list) - validate: List[str] = field(default_factory=list) + executables: list[str] = field(default_factory=list) + dependencies: list[str] = field(default_factory=list) + dirs: list[str] = field(default_factory=list) + configs: list[str] = field(default_factory=list) + startup: list[str] = field(default_factory=list) + validate: list[str] = field(default_factory=list) validation_mode: ServiceValidationMode = ServiceValidationMode.NON_BLOCKING validation_timer: int = 5 - shutdown: List[str] = field(default_factory=list) + shutdown: list[str] = field(default_factory=list) meta: str = None @classmethod @@ -266,7 +267,7 @@ class NodeServiceConfig: node_id: int service: str data: NodeServiceData - files: Dict[str, str] = field(default_factory=dict) + files: dict[str, str] = field(default_factory=dict) @classmethod def from_proto(cls, proto: services_pb2.NodeServiceConfig) -> "NodeServiceConfig": @@ -282,11 +283,11 @@ class NodeServiceConfig: class ServiceConfig: node_id: int service: str - files: List[str] = None - directories: List[str] = None - startup: List[str] = None - validate: List[str] = None - shutdown: List[str] = None + files: list[str] = None + directories: list[str] = None + startup: list[str] = None + validate: list[str] = None + shutdown: list[str] = None def to_proto(self) -> services_pb2.ServiceConfig: return services_pb2.ServiceConfig( @@ -339,8 +340,8 @@ class InterfaceThroughput: @dataclass class ThroughputsEvent: session_id: int - bridge_throughputs: List[BridgeThroughput] - iface_throughputs: List[InterfaceThroughput] + bridge_throughputs: list[BridgeThroughput] + iface_throughputs: list[InterfaceThroughput] @classmethod def from_proto(cls, proto: core_pb2.ThroughputsEvent) -> "ThroughputsEvent": @@ -428,19 +429,19 @@ class ConfigOption: label: str = None type: ConfigOptionType = None group: str = None - select: List[str] = None + select: list[str] = None @classmethod def from_dict( - cls, config: Dict[str, common_pb2.ConfigOption] - ) -> Dict[str, "ConfigOption"]: + cls, config: dict[str, common_pb2.ConfigOption] + ) -> dict[str, "ConfigOption"]: d = {} for key, value in config.items(): d[key] = ConfigOption.from_proto(value) return d @classmethod - def to_dict(cls, config: Dict[str, "ConfigOption"]) -> Dict[str, str]: + def to_dict(cls, config: dict[str, "ConfigOption"]) -> dict[str, str]: return {k: v.value for k, v in config.items()} @classmethod @@ -671,7 +672,7 @@ class EmaneModelConfig: node_id: int model: str iface_id: int = -1 - config: Dict[str, ConfigOption] = None + config: dict[str, ConfigOption] = None @classmethod def from_proto(cls, proto: emane_pb2.GetEmaneModelConfig) -> "EmaneModelConfig": @@ -725,8 +726,8 @@ class Node: type: NodeType = NodeType.DEFAULT model: str = None position: Position = Position(x=0, y=0) - services: Set[str] = field(default_factory=set) - config_services: Set[str] = field(default_factory=set) + services: set[str] = field(default_factory=set) + config_services: set[str] = field(default_factory=set) emane: str = None icon: str = None image: str = None @@ -737,19 +738,19 @@ class Node: canvas: int = None # configurations - emane_model_configs: Dict[ - Tuple[str, Optional[int]], Dict[str, ConfigOption] + emane_model_configs: dict[ + tuple[str, Optional[int]], dict[str, ConfigOption] ] = field(default_factory=dict, repr=False) - wlan_config: Dict[str, ConfigOption] = field(default_factory=dict, repr=False) - wireless_config: Dict[str, ConfigOption] = field(default_factory=dict, repr=False) - mobility_config: Dict[str, ConfigOption] = field(default_factory=dict, repr=False) - service_configs: Dict[str, NodeServiceData] = field( + wlan_config: dict[str, ConfigOption] = field(default_factory=dict, repr=False) + wireless_config: dict[str, ConfigOption] = field(default_factory=dict, repr=False) + mobility_config: dict[str, ConfigOption] = field(default_factory=dict, repr=False) + service_configs: dict[str, NodeServiceData] = field( default_factory=dict, repr=False ) - service_file_configs: Dict[str, Dict[str, str]] = field( + service_file_configs: dict[str, dict[str, str]] = field( default_factory=dict, repr=False ) - config_service_configs: Dict[str, ConfigServiceData] = field( + config_service_configs: dict[str, ConfigServiceData] = field( default_factory=dict, repr=False ) @@ -849,18 +850,18 @@ class Node: wireless_config={k: v.to_proto() for k, v in self.wireless_config.items()}, ) - def set_wlan(self, config: Dict[str, str]) -> None: + def set_wlan(self, config: dict[str, str]) -> None: for key, value in config.items(): option = ConfigOption(name=key, value=value) self.wlan_config[key] = option - def set_mobility(self, config: Dict[str, str]) -> None: + def set_mobility(self, config: dict[str, str]) -> None: for key, value in config.items(): option = ConfigOption(name=key, value=value) self.mobility_config[key] = option def set_emane_model( - self, model: str, config: Dict[str, str], iface_id: int = None + self, model: str, config: dict[str, str], iface_id: int = None ) -> None: key = (model, iface_id) config_options = self.emane_model_configs.setdefault(key, {}) @@ -873,23 +874,23 @@ class Node: class Session: id: int = None state: SessionState = SessionState.DEFINITION - nodes: Dict[int, Node] = field(default_factory=dict) - links: List[Link] = field(default_factory=list) + nodes: dict[int, Node] = field(default_factory=dict) + links: list[Link] = field(default_factory=list) dir: str = None user: str = None - default_services: Dict[str, Set[str]] = field(default_factory=dict) + default_services: dict[str, set[str]] = field(default_factory=dict) location: SessionLocation = SessionLocation( x=0.0, y=0.0, z=0.0, lat=47.57917, lon=-122.13232, alt=2.0, scale=150.0 ) - hooks: Dict[str, Hook] = field(default_factory=dict) - metadata: Dict[str, str] = field(default_factory=dict) + hooks: dict[str, Hook] = field(default_factory=dict) + metadata: dict[str, str] = field(default_factory=dict) file: Path = None - options: Dict[str, ConfigOption] = field(default_factory=dict) - servers: List[Server] = field(default_factory=list) + options: dict[str, ConfigOption] = field(default_factory=dict) + servers: list[Server] = field(default_factory=list) @classmethod def from_proto(cls, proto: core_pb2.Session) -> "Session": - nodes: Dict[int, Node] = {x.id: Node.from_proto(x) for x in proto.nodes} + nodes: dict[int, Node] = {x.id: Node.from_proto(x) for x in proto.nodes} links = [Link.from_proto(x) for x in proto.links] default_services = {x.model: set(x.services) for x in proto.default_services} hooks = {x.file: Hook.from_proto(x) for x in proto.hooks} @@ -987,7 +988,7 @@ class Session: self.links.append(link) return link - def set_options(self, config: Dict[str, str]) -> None: + def set_options(self, config: dict[str, str]) -> None: for key, value in config.items(): option = ConfigOption(name=key, value=value) self.options[key] = option @@ -995,9 +996,9 @@ class Session: @dataclass class CoreConfig: - services: List[Service] = field(default_factory=list) - config_services: List[ConfigService] = field(default_factory=list) - emane_models: List[str] = field(default_factory=list) + services: list[Service] = field(default_factory=list) + config_services: list[ConfigService] = field(default_factory=list) + emane_models: list[str] = field(default_factory=list) @classmethod def from_proto(cls, proto: core_pb2.GetConfigResponse) -> "CoreConfig": @@ -1088,7 +1089,7 @@ class ConfigEvent: node_id: int object: str type: int - data_types: List[int] + data_types: list[int] data_values: str captions: str bitmap: str diff --git a/daemon/core/config.py b/daemon/core/config.py index ae40627e..7a6ffa49 100644 --- a/daemon/core/config.py +++ b/daemon/core/config.py @@ -5,7 +5,7 @@ Common support for configurable CORE objects. import logging from collections import OrderedDict from dataclasses import dataclass, field -from typing import TYPE_CHECKING, Any, Dict, List, Optional, Set, Tuple, Type, Union +from typing import TYPE_CHECKING, Any, Optional, Union from core.emane.nodes import EmaneNet from core.emulator.enumerations import ConfigDataTypes @@ -17,9 +17,9 @@ logger = logging.getLogger(__name__) if TYPE_CHECKING: from core.location.mobility import WirelessModel - WirelessModelType = Type[WirelessModel] + WirelessModelType = type[WirelessModel] -_BOOL_OPTIONS: Set[str] = {"0", "1"} +_BOOL_OPTIONS: set[str] = {"0", "1"} @dataclass @@ -43,7 +43,7 @@ class Configuration: type: ConfigDataTypes label: str = None default: str = "" - options: List[str] = field(default_factory=list) + options: list[str] = field(default_factory=list) group: str = "Configuration" def __post_init__(self) -> None: @@ -118,10 +118,10 @@ class ConfigurableOptions: """ name: Optional[str] = None - options: List[Configuration] = [] + options: list[Configuration] = [] @classmethod - def configurations(cls) -> List[Configuration]: + def configurations(cls) -> list[Configuration]: """ Provides the configurations for this class. @@ -130,7 +130,7 @@ class ConfigurableOptions: return cls.options @classmethod - def config_groups(cls) -> List[ConfigGroup]: + def config_groups(cls) -> list[ConfigGroup]: """ Defines how configurations are grouped. @@ -139,7 +139,7 @@ class ConfigurableOptions: return [ConfigGroup("Options", 1, len(cls.configurations()))] @classmethod - def default_values(cls) -> Dict[str, str]: + def default_values(cls) -> dict[str, str]: """ Provides an ordered mapping of configuration keys to default values. @@ -165,7 +165,7 @@ class ConfigurableManager: """ self.node_configurations = {} - def nodes(self) -> List[int]: + def nodes(self) -> list[int]: """ Retrieves the ids of all node configurations known by this manager. @@ -208,7 +208,7 @@ class ConfigurableManager: def set_configs( self, - config: Dict[str, str], + config: dict[str, str], node_id: int = _default_node, config_type: str = _default_type, ) -> None: @@ -250,7 +250,7 @@ class ConfigurableManager: def get_configs( self, node_id: int = _default_node, config_type: str = _default_type - ) -> Optional[Dict[str, str]]: + ) -> Optional[dict[str, str]]: """ Retrieve configurations for a node and configuration type. @@ -264,7 +264,7 @@ class ConfigurableManager: result = node_configs.get(config_type) return result - def get_all_configs(self, node_id: int = _default_node) -> Dict[str, Any]: + def get_all_configs(self, node_id: int = _default_node) -> dict[str, Any]: """ Retrieve all current configuration types for a node. @@ -284,11 +284,11 @@ class ModelManager(ConfigurableManager): Creates a ModelManager object. """ super().__init__() - self.models: Dict[str, Any] = {} - self.node_models: Dict[int, str] = {} + self.models: dict[str, Any] = {} + self.node_models: dict[int, str] = {} def set_model_config( - self, node_id: int, model_name: str, config: Dict[str, str] = None + self, node_id: int, model_name: str, config: dict[str, str] = None ) -> None: """ Set configuration data for a model. @@ -317,7 +317,7 @@ class ModelManager(ConfigurableManager): # set configuration self.set_configs(model_config, node_id=node_id, config_type=model_name) - def get_model_config(self, node_id: int, model_name: str) -> Dict[str, str]: + def get_model_config(self, node_id: int, model_name: str) -> dict[str, str]: """ Retrieve configuration data for a model. @@ -342,7 +342,7 @@ class ModelManager(ConfigurableManager): self, node: Union[WlanNode, EmaneNet], model_class: "WirelessModelType", - config: Dict[str, str] = None, + config: dict[str, str] = None, ) -> None: """ Set model and model configuration for node. @@ -361,7 +361,7 @@ class ModelManager(ConfigurableManager): def get_models( self, node: Union[WlanNode, EmaneNet] - ) -> List[Tuple[Type, Dict[str, str]]]: + ) -> list[tuple[type, dict[str, str]]]: """ Return a list of model classes and values for a net if one has been configured. This is invoked when exporting a session to XML. diff --git a/daemon/core/configservice/base.py b/daemon/core/configservice/base.py index 3d61edcc..e15260eb 100644 --- a/daemon/core/configservice/base.py +++ b/daemon/core/configservice/base.py @@ -5,7 +5,7 @@ import logging import time from dataclasses import dataclass from pathlib import Path -from typing import Any, Dict, List, Optional +from typing import Any, Optional from mako import exceptions from mako.lookup import TemplateLookup @@ -67,7 +67,7 @@ class ConfigService(abc.ABC): validation_timer: int = 5 # directories to shadow and copy files from - shadow_directories: List[ShadowDir] = [] + shadow_directories: list[ShadowDir] = [] def __init__(self, node: CoreNode) -> None: """ @@ -79,9 +79,9 @@ class ConfigService(abc.ABC): class_file = inspect.getfile(self.__class__) templates_path = Path(class_file).parent.joinpath(TEMPLATES_DIR) self.templates: TemplateLookup = TemplateLookup(directories=templates_path) - self.config: Dict[str, Configuration] = {} - self.custom_templates: Dict[str, str] = {} - self.custom_config: Dict[str, str] = {} + self.config: dict[str, Configuration] = {} + self.custom_templates: dict[str, str] = {} + self.custom_config: dict[str, str] = {} configs = self.default_configs[:] self._define_config(configs) @@ -108,47 +108,47 @@ class ConfigService(abc.ABC): @property @abc.abstractmethod - def directories(self) -> List[str]: + def directories(self) -> list[str]: raise NotImplementedError @property @abc.abstractmethod - def files(self) -> List[str]: + def files(self) -> list[str]: raise NotImplementedError @property @abc.abstractmethod - def default_configs(self) -> List[Configuration]: + def default_configs(self) -> list[Configuration]: raise NotImplementedError @property @abc.abstractmethod - def modes(self) -> Dict[str, Dict[str, str]]: + def modes(self) -> dict[str, dict[str, str]]: raise NotImplementedError @property @abc.abstractmethod - def executables(self) -> List[str]: + def executables(self) -> list[str]: raise NotImplementedError @property @abc.abstractmethod - def dependencies(self) -> List[str]: + def dependencies(self) -> list[str]: raise NotImplementedError @property @abc.abstractmethod - def startup(self) -> List[str]: + def startup(self) -> list[str]: raise NotImplementedError @property @abc.abstractmethod - def validate(self) -> List[str]: + def validate(self) -> list[str]: raise NotImplementedError @property @abc.abstractmethod - def shutdown(self) -> List[str]: + def shutdown(self) -> list[str]: raise NotImplementedError @property @@ -276,7 +276,7 @@ class ConfigService(abc.ABC): f"failure to create service directory: {directory}" ) - def data(self) -> Dict[str, Any]: + def data(self) -> dict[str, Any]: """ Returns key/value data, used when rendering file templates. @@ -303,7 +303,7 @@ class ConfigService(abc.ABC): """ raise CoreError(f"service({self.name}) unknown template({name})") - def get_templates(self) -> Dict[str, str]: + def get_templates(self) -> dict[str, str]: """ Retrieves mapping of file names to templates for all cases, which includes custom templates, file templates, and text templates. @@ -331,7 +331,7 @@ class ConfigService(abc.ABC): templates[file] = template return templates - def get_rendered_templates(self) -> Dict[str, str]: + def get_rendered_templates(self) -> dict[str, str]: templates = {} data = self.data() for file in sorted(self.files): @@ -339,7 +339,7 @@ class ConfigService(abc.ABC): templates[file] = rendered return templates - def _get_rendered_template(self, file: str, data: Dict[str, Any]) -> str: + def _get_rendered_template(self, file: str, data: dict[str, Any]) -> str: file_path = Path(file) template_path = get_template_path(file_path) if file in self.custom_templates: @@ -426,7 +426,7 @@ class ConfigService(abc.ABC): f"node({self.node.name}) service({self.name}) failed to validate" ) - def _render(self, template: Template, data: Dict[str, Any] = None) -> str: + def _render(self, template: Template, data: dict[str, Any] = None) -> str: """ Renders template providing all associated data to template. @@ -440,7 +440,7 @@ class ConfigService(abc.ABC): node=self.node, config=self.render_config(), **data ) - def render_text(self, text: str, data: Dict[str, Any] = None) -> str: + def render_text(self, text: str, data: dict[str, Any] = None) -> str: """ Renders text based template providing all associated data to template. @@ -458,7 +458,7 @@ class ConfigService(abc.ABC): f"{exceptions.text_error_template().render_unicode()}" ) - def render_template(self, template_path: str, data: Dict[str, Any] = None) -> str: + def render_template(self, template_path: str, data: dict[str, Any] = None) -> str: """ Renders file based template providing all associated data to template. @@ -475,7 +475,7 @@ class ConfigService(abc.ABC): f"{exceptions.text_error_template().render_unicode()}" ) - def _define_config(self, configs: List[Configuration]) -> None: + def _define_config(self, configs: list[Configuration]) -> None: """ Initializes default configuration data. @@ -485,7 +485,7 @@ class ConfigService(abc.ABC): for config in configs: self.config[config.id] = config - def render_config(self) -> Dict[str, str]: + def render_config(self) -> dict[str, str]: """ Returns configuration data key/value pairs for rendering a template. @@ -496,7 +496,7 @@ class ConfigService(abc.ABC): else: return {k: v.default for k, v in self.config.items()} - def set_config(self, data: Dict[str, str]) -> None: + def set_config(self, data: dict[str, str]) -> None: """ Set configuration data from key/value pairs. diff --git a/daemon/core/configservice/dependencies.py b/daemon/core/configservice/dependencies.py index b24c83c6..1fbc4e48 100644 --- a/daemon/core/configservice/dependencies.py +++ b/daemon/core/configservice/dependencies.py @@ -1,5 +1,5 @@ import logging -from typing import TYPE_CHECKING, Dict, List, Set +from typing import TYPE_CHECKING logger = logging.getLogger(__name__) @@ -12,16 +12,16 @@ class ConfigServiceDependencies: Generates sets of services to start in order of their dependencies. """ - def __init__(self, services: Dict[str, "ConfigService"]) -> None: + def __init__(self, services: dict[str, "ConfigService"]) -> None: """ Create a ConfigServiceDependencies instance. :param services: services for determining dependency sets """ # helpers to check validity - self.dependents: Dict[str, Set[str]] = {} - self.started: Set[str] = set() - self.node_services: Dict[str, "ConfigService"] = {} + self.dependents: dict[str, set[str]] = {} + self.started: set[str] = set() + self.node_services: dict[str, "ConfigService"] = {} for service in services.values(): self.node_services[service.name] = service for dependency in service.dependencies: @@ -29,11 +29,11 @@ class ConfigServiceDependencies: dependents.add(service.name) # used to find paths - self.path: List["ConfigService"] = [] - self.visited: Set[str] = set() - self.visiting: Set[str] = set() + self.path: list["ConfigService"] = [] + self.visited: set[str] = set() + self.visiting: set[str] = set() - def startup_paths(self) -> List[List["ConfigService"]]: + def startup_paths(self) -> list[list["ConfigService"]]: """ Find startup path sets based on service dependencies. @@ -54,8 +54,8 @@ class ConfigServiceDependencies: if self.started != set(self.node_services): raise ValueError( - "failure to start all services: %s != %s" - % (self.started, self.node_services.keys()) + f"failure to start all services: {self.started} != " + f"{self.node_services.keys()}" ) return paths @@ -70,7 +70,7 @@ class ConfigServiceDependencies: self.visited.clear() self.visiting.clear() - def _start(self, service: "ConfigService") -> List["ConfigService"]: + def _start(self, service: "ConfigService") -> list["ConfigService"]: """ Starts a oath for checking dependencies for a given service. @@ -81,7 +81,7 @@ class ConfigServiceDependencies: self._reset() return self._visit(service) - def _visit(self, current_service: "ConfigService") -> List["ConfigService"]: + def _visit(self, current_service: "ConfigService") -> list["ConfigService"]: """ Visits a service when discovering dependency chains for service. @@ -96,14 +96,14 @@ class ConfigServiceDependencies: for service_name in current_service.dependencies: if service_name not in self.node_services: raise ValueError( - "required dependency was not included in node services: %s" - % service_name + "required dependency was not included in node " + f"services: {service_name}" ) if service_name in self.visiting: raise ValueError( - "cyclic dependency at service(%s): %s" - % (current_service.name, service_name) + f"cyclic dependency at service({current_service.name}): " + f"{service_name}" ) if service_name not in self.visited: diff --git a/daemon/core/configservice/manager.py b/daemon/core/configservice/manager.py index 1fd26e43..542f3cc5 100644 --- a/daemon/core/configservice/manager.py +++ b/daemon/core/configservice/manager.py @@ -2,7 +2,6 @@ import logging import pathlib import pkgutil from pathlib import Path -from typing import Dict, List, Type from core import configservices, utils from core.configservice.base import ConfigService @@ -20,9 +19,9 @@ class ConfigServiceManager: """ Create a ConfigServiceManager instance. """ - self.services: Dict[str, Type[ConfigService]] = {} + self.services: dict[str, type[ConfigService]] = {} - def get_service(self, name: str) -> Type[ConfigService]: + def get_service(self, name: str) -> type[ConfigService]: """ Retrieve a service by name. @@ -35,7 +34,7 @@ class ConfigServiceManager: raise CoreError(f"service does not exist {name}") return service_class - def add(self, service: Type[ConfigService]) -> None: + def add(self, service: type[ConfigService]) -> None: """ Add service to manager, checking service requirements have been met. @@ -62,7 +61,7 @@ class ConfigServiceManager: # make service available self.services[name] = service - def load_locals(self) -> List[str]: + def load_locals(self) -> list[str]: """ Search and add config service from local core module. @@ -81,7 +80,7 @@ class ConfigServiceManager: logger.debug("not loading config service(%s): %s", service.name, e) return errors - def load(self, path: Path) -> List[str]: + def load(self, path: Path) -> list[str]: """ Search path provided for config services and add them for being managed. diff --git a/daemon/core/configservices/frrservices/services.py b/daemon/core/configservices/frrservices/services.py index 7ed965be..378d42f8 100644 --- a/daemon/core/configservices/frrservices/services.py +++ b/daemon/core/configservices/frrservices/services.py @@ -1,5 +1,5 @@ import abc -from typing import Any, Dict, List +from typing import Any from core.config import Configuration from core.configservice.base import ConfigService, ConfigServiceMode @@ -82,29 +82,30 @@ def rj45_check(iface: CoreInterface) -> bool: class FRRZebra(ConfigService): name: str = "FRRzebra" group: str = GROUP - directories: List[str] = ["/usr/local/etc/frr", "/var/run/frr", "/var/log/frr"] - files: List[str] = [ + directories: list[str] = ["/usr/local/etc/frr", "/var/run/frr", "/var/log/frr"] + files: list[str] = [ "/usr/local/etc/frr/frr.conf", "frrboot.sh", "/usr/local/etc/frr/vtysh.conf", "/usr/local/etc/frr/daemons", ] - executables: List[str] = ["zebra"] - dependencies: List[str] = [] - startup: List[str] = ["bash frrboot.sh zebra"] - validate: List[str] = ["pidof zebra"] - shutdown: List[str] = ["killall zebra"] + executables: list[str] = ["zebra"] + dependencies: list[str] = [] + startup: list[str] = ["bash frrboot.sh zebra"] + validate: list[str] = ["pidof zebra"] + shutdown: list[str] = ["killall zebra"] validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING - default_configs: List[Configuration] = [] - modes: Dict[str, Dict[str, str]] = {} + default_configs: list[Configuration] = [] + modes: dict[str, dict[str, str]] = {} - def data(self) -> Dict[str, Any]: + def data(self) -> dict[str, Any]: frr_conf = self.files[0] frr_bin_search = self.node.session.options.get( "frr_bin_search", default="/usr/local/bin /usr/bin /usr/lib/frr" ).strip('"') frr_sbin_search = self.node.session.options.get( - "frr_sbin_search", default="/usr/local/sbin /usr/sbin /usr/lib/frr" + "frr_sbin_search", + default="/usr/local/sbin /usr/sbin /usr/lib/frr /usr/libexec/frr", ).strip('"') services = [] @@ -145,16 +146,16 @@ class FRRZebra(ConfigService): class FrrService(abc.ABC): group: str = GROUP - directories: List[str] = [] - files: List[str] = [] - executables: List[str] = [] - dependencies: List[str] = ["FRRzebra"] - startup: List[str] = [] - validate: List[str] = [] - shutdown: List[str] = [] + directories: list[str] = [] + files: list[str] = [] + executables: list[str] = [] + dependencies: list[str] = ["FRRzebra"] + startup: list[str] = [] + validate: list[str] = [] + shutdown: list[str] = [] validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING - default_configs: List[Configuration] = [] - modes: Dict[str, Dict[str, str]] = {} + default_configs: list[Configuration] = [] + modes: dict[str, dict[str, str]] = {} ipv4_routing: bool = False ipv6_routing: bool = False @@ -175,8 +176,8 @@ class FRROspfv2(FrrService, ConfigService): """ name: str = "FRROSPFv2" - shutdown: List[str] = ["killall ospfd"] - validate: List[str] = ["pidof ospfd"] + shutdown: list[str] = ["killall ospfd"] + validate: list[str] = ["pidof ospfd"] ipv4_routing: bool = True def frr_config(self) -> str: @@ -227,8 +228,8 @@ class FRROspfv3(FrrService, ConfigService): """ name: str = "FRROSPFv3" - shutdown: List[str] = ["killall ospf6d"] - validate: List[str] = ["pidof ospf6d"] + shutdown: list[str] = ["killall ospf6d"] + validate: list[str] = ["pidof ospf6d"] ipv4_routing: bool = True ipv6_routing: bool = True @@ -264,8 +265,8 @@ class FRRBgp(FrrService, ConfigService): """ name: str = "FRRBGP" - shutdown: List[str] = ["killall bgpd"] - validate: List[str] = ["pidof bgpd"] + shutdown: list[str] = ["killall bgpd"] + validate: list[str] = ["pidof bgpd"] custom_needed: bool = True ipv4_routing: bool = True ipv6_routing: bool = True @@ -294,8 +295,8 @@ class FRRRip(FrrService, ConfigService): """ name: str = "FRRRIP" - shutdown: List[str] = ["killall ripd"] - validate: List[str] = ["pidof ripd"] + shutdown: list[str] = ["killall ripd"] + validate: list[str] = ["pidof ripd"] ipv4_routing: bool = True def frr_config(self) -> str: @@ -319,8 +320,8 @@ class FRRRipng(FrrService, ConfigService): """ name: str = "FRRRIPNG" - shutdown: List[str] = ["killall ripngd"] - validate: List[str] = ["pidof ripngd"] + shutdown: list[str] = ["killall ripngd"] + validate: list[str] = ["pidof ripngd"] ipv6_routing: bool = True def frr_config(self) -> str: @@ -345,8 +346,8 @@ class FRRBabel(FrrService, ConfigService): """ name: str = "FRRBabel" - shutdown: List[str] = ["killall babeld"] - validate: List[str] = ["pidof babeld"] + shutdown: list[str] = ["killall babeld"] + validate: list[str] = ["pidof babeld"] ipv6_routing: bool = True def frr_config(self) -> str: @@ -385,8 +386,8 @@ class FRRpimd(FrrService, ConfigService): """ name: str = "FRRpimd" - shutdown: List[str] = ["killall pimd"] - validate: List[str] = ["pidof pimd"] + shutdown: list[str] = ["killall pimd"] + validate: list[str] = ["pidof pimd"] ipv4_routing: bool = True def frr_config(self) -> str: diff --git a/daemon/core/configservices/nrlservices/services.py b/daemon/core/configservices/nrlservices/services.py index ba9ef29c..3002cd94 100644 --- a/daemon/core/configservices/nrlservices/services.py +++ b/daemon/core/configservices/nrlservices/services.py @@ -1,4 +1,4 @@ -from typing import Any, Dict, List +from typing import Any from core import utils from core.config import Configuration @@ -10,18 +10,18 @@ GROUP: str = "ProtoSvc" class MgenSinkService(ConfigService): name: str = "MGEN_Sink" group: str = GROUP - directories: List[str] = [] - files: List[str] = ["mgensink.sh", "sink.mgen"] - executables: List[str] = ["mgen"] - dependencies: List[str] = [] - startup: List[str] = ["bash mgensink.sh"] - validate: List[str] = ["pidof mgen"] - shutdown: List[str] = ["killall mgen"] + directories: list[str] = [] + files: list[str] = ["mgensink.sh", "sink.mgen"] + executables: list[str] = ["mgen"] + dependencies: list[str] = [] + startup: list[str] = ["bash mgensink.sh"] + validate: list[str] = ["pidof mgen"] + shutdown: list[str] = ["killall mgen"] validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING - default_configs: List[Configuration] = [] - modes: Dict[str, Dict[str, str]] = {} + default_configs: list[Configuration] = [] + modes: dict[str, dict[str, str]] = {} - def data(self) -> Dict[str, Any]: + def data(self) -> dict[str, Any]: ifnames = [] for iface in self.node.get_ifaces(): name = utils.sysctl_devname(iface.name) @@ -32,18 +32,18 @@ class MgenSinkService(ConfigService): class NrlNhdp(ConfigService): name: str = "NHDP" group: str = GROUP - directories: List[str] = [] - files: List[str] = ["nrlnhdp.sh"] - executables: List[str] = ["nrlnhdp"] - dependencies: List[str] = [] - startup: List[str] = ["bash nrlnhdp.sh"] - validate: List[str] = ["pidof nrlnhdp"] - shutdown: List[str] = ["killall nrlnhdp"] + directories: list[str] = [] + files: list[str] = ["nrlnhdp.sh"] + executables: list[str] = ["nrlnhdp"] + dependencies: list[str] = [] + startup: list[str] = ["bash nrlnhdp.sh"] + validate: list[str] = ["pidof nrlnhdp"] + shutdown: list[str] = ["killall nrlnhdp"] validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING - default_configs: List[Configuration] = [] - modes: Dict[str, Dict[str, str]] = {} + default_configs: list[Configuration] = [] + modes: dict[str, dict[str, str]] = {} - def data(self) -> Dict[str, Any]: + def data(self) -> dict[str, Any]: has_smf = "SMF" in self.node.config_services ifnames = [] for iface in self.node.get_ifaces(control=False): @@ -54,18 +54,18 @@ class NrlNhdp(ConfigService): class NrlSmf(ConfigService): name: str = "SMF" group: str = GROUP - directories: List[str] = [] - files: List[str] = ["startsmf.sh"] - executables: List[str] = ["nrlsmf", "killall"] - dependencies: List[str] = [] - startup: List[str] = ["bash startsmf.sh"] - validate: List[str] = ["pidof nrlsmf"] - shutdown: List[str] = ["killall nrlsmf"] + directories: list[str] = [] + files: list[str] = ["startsmf.sh"] + executables: list[str] = ["nrlsmf", "killall"] + dependencies: list[str] = [] + startup: list[str] = ["bash startsmf.sh"] + validate: list[str] = ["pidof nrlsmf"] + shutdown: list[str] = ["killall nrlsmf"] validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING - default_configs: List[Configuration] = [] - modes: Dict[str, Dict[str, str]] = {} + default_configs: list[Configuration] = [] + modes: dict[str, dict[str, str]] = {} - def data(self) -> Dict[str, Any]: + def data(self) -> dict[str, Any]: has_nhdp = "NHDP" in self.node.config_services has_olsr = "OLSR" in self.node.config_services ifnames = [] @@ -84,18 +84,18 @@ class NrlSmf(ConfigService): class NrlOlsr(ConfigService): name: str = "OLSR" group: str = GROUP - directories: List[str] = [] - files: List[str] = ["nrlolsrd.sh"] - executables: List[str] = ["nrlolsrd"] - dependencies: List[str] = [] - startup: List[str] = ["bash nrlolsrd.sh"] - validate: List[str] = ["pidof nrlolsrd"] - shutdown: List[str] = ["killall nrlolsrd"] + directories: list[str] = [] + files: list[str] = ["nrlolsrd.sh"] + executables: list[str] = ["nrlolsrd"] + dependencies: list[str] = [] + startup: list[str] = ["bash nrlolsrd.sh"] + validate: list[str] = ["pidof nrlolsrd"] + shutdown: list[str] = ["killall nrlolsrd"] validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING - default_configs: List[Configuration] = [] - modes: Dict[str, Dict[str, str]] = {} + default_configs: list[Configuration] = [] + modes: dict[str, dict[str, str]] = {} - def data(self) -> Dict[str, Any]: + def data(self) -> dict[str, Any]: has_smf = "SMF" in self.node.config_services has_zebra = "zebra" in self.node.config_services ifname = None @@ -108,18 +108,18 @@ class NrlOlsr(ConfigService): class NrlOlsrv2(ConfigService): name: str = "OLSRv2" group: str = GROUP - directories: List[str] = [] - files: List[str] = ["nrlolsrv2.sh"] - executables: List[str] = ["nrlolsrv2"] - dependencies: List[str] = [] - startup: List[str] = ["bash nrlolsrv2.sh"] - validate: List[str] = ["pidof nrlolsrv2"] - shutdown: List[str] = ["killall nrlolsrv2"] + directories: list[str] = [] + files: list[str] = ["nrlolsrv2.sh"] + executables: list[str] = ["nrlolsrv2"] + dependencies: list[str] = [] + startup: list[str] = ["bash nrlolsrv2.sh"] + validate: list[str] = ["pidof nrlolsrv2"] + shutdown: list[str] = ["killall nrlolsrv2"] validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING - default_configs: List[Configuration] = [] - modes: Dict[str, Dict[str, str]] = {} + default_configs: list[Configuration] = [] + modes: dict[str, dict[str, str]] = {} - def data(self) -> Dict[str, Any]: + def data(self) -> dict[str, Any]: has_smf = "SMF" in self.node.config_services ifnames = [] for iface in self.node.get_ifaces(control=False): @@ -130,18 +130,18 @@ class NrlOlsrv2(ConfigService): class OlsrOrg(ConfigService): name: str = "OLSRORG" group: str = GROUP - directories: List[str] = ["/etc/olsrd"] - files: List[str] = ["olsrd.sh", "/etc/olsrd/olsrd.conf"] - executables: List[str] = ["olsrd"] - dependencies: List[str] = [] - startup: List[str] = ["bash olsrd.sh"] - validate: List[str] = ["pidof olsrd"] - shutdown: List[str] = ["killall olsrd"] + directories: list[str] = ["/etc/olsrd"] + files: list[str] = ["olsrd.sh", "/etc/olsrd/olsrd.conf"] + executables: list[str] = ["olsrd"] + dependencies: list[str] = [] + startup: list[str] = ["bash olsrd.sh"] + validate: list[str] = ["pidof olsrd"] + shutdown: list[str] = ["killall olsrd"] validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING - default_configs: List[Configuration] = [] - modes: Dict[str, Dict[str, str]] = {} + default_configs: list[Configuration] = [] + modes: dict[str, dict[str, str]] = {} - def data(self) -> Dict[str, Any]: + def data(self) -> dict[str, Any]: has_smf = "SMF" in self.node.config_services ifnames = [] for iface in self.node.get_ifaces(control=False): @@ -152,13 +152,13 @@ class OlsrOrg(ConfigService): class MgenActor(ConfigService): name: str = "MgenActor" group: str = GROUP - directories: List[str] = [] - files: List[str] = ["start_mgen_actor.sh"] - executables: List[str] = ["mgen"] - dependencies: List[str] = [] - startup: List[str] = ["bash start_mgen_actor.sh"] - validate: List[str] = ["pidof mgen"] - shutdown: List[str] = ["killall mgen"] + directories: list[str] = [] + files: list[str] = ["start_mgen_actor.sh"] + executables: list[str] = ["mgen"] + dependencies: list[str] = [] + startup: list[str] = ["bash start_mgen_actor.sh"] + validate: list[str] = ["pidof mgen"] + shutdown: list[str] = ["killall mgen"] validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING - default_configs: List[Configuration] = [] - modes: Dict[str, Dict[str, str]] = {} + default_configs: list[Configuration] = [] + modes: dict[str, dict[str, str]] = {} diff --git a/daemon/core/configservices/quaggaservices/services.py b/daemon/core/configservices/quaggaservices/services.py index 8aa85807..8b4d4909 100644 --- a/daemon/core/configservices/quaggaservices/services.py +++ b/daemon/core/configservices/quaggaservices/services.py @@ -1,6 +1,6 @@ import abc import logging -from typing import Any, Dict, List +from typing import Any from core.config import Configuration from core.configservice.base import ConfigService, ConfigServiceMode @@ -84,22 +84,22 @@ def rj45_check(iface: CoreInterface) -> bool: class Zebra(ConfigService): name: str = "zebra" group: str = GROUP - directories: List[str] = ["/usr/local/etc/quagga", "/var/run/quagga"] - files: List[str] = [ + directories: list[str] = ["/usr/local/etc/quagga", "/var/run/quagga"] + files: list[str] = [ "/usr/local/etc/quagga/Quagga.conf", "quaggaboot.sh", "/usr/local/etc/quagga/vtysh.conf", ] - executables: List[str] = ["zebra"] - dependencies: List[str] = [] - startup: List[str] = ["bash quaggaboot.sh zebra"] - validate: List[str] = ["pidof zebra"] - shutdown: List[str] = ["killall zebra"] + executables: list[str] = ["zebra"] + dependencies: list[str] = [] + startup: list[str] = ["bash quaggaboot.sh zebra"] + validate: list[str] = ["pidof zebra"] + shutdown: list[str] = ["killall zebra"] validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING - default_configs: List[Configuration] = [] - modes: Dict[str, Dict[str, str]] = {} + default_configs: list[Configuration] = [] + modes: dict[str, dict[str, str]] = {} - def data(self) -> Dict[str, Any]: + def data(self) -> dict[str, Any]: quagga_bin_search = self.node.session.options.get( "quagga_bin_search", default="/usr/local/bin /usr/bin /usr/lib/quagga" ).strip('"') @@ -153,16 +153,16 @@ class Zebra(ConfigService): class QuaggaService(abc.ABC): group: str = GROUP - directories: List[str] = [] - files: List[str] = [] - executables: List[str] = [] - dependencies: List[str] = ["zebra"] - startup: List[str] = [] - validate: List[str] = [] - shutdown: List[str] = [] + directories: list[str] = [] + files: list[str] = [] + executables: list[str] = [] + dependencies: list[str] = ["zebra"] + startup: list[str] = [] + validate: list[str] = [] + shutdown: list[str] = [] validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING - default_configs: List[Configuration] = [] - modes: Dict[str, Dict[str, str]] = {} + default_configs: list[Configuration] = [] + modes: dict[str, dict[str, str]] = {} ipv4_routing: bool = False ipv6_routing: bool = False @@ -183,8 +183,8 @@ class Ospfv2(QuaggaService, ConfigService): """ name: str = "OSPFv2" - validate: List[str] = ["pidof ospfd"] - shutdown: List[str] = ["killall ospfd"] + validate: list[str] = ["pidof ospfd"] + shutdown: list[str] = ["killall ospfd"] ipv4_routing: bool = True def quagga_iface_config(self, iface: CoreInterface) -> str: @@ -234,8 +234,8 @@ class Ospfv3(QuaggaService, ConfigService): """ name: str = "OSPFv3" - shutdown: List[str] = ["killall ospf6d"] - validate: List[str] = ["pidof ospf6d"] + shutdown: list[str] = ["killall ospf6d"] + validate: list[str] = ["pidof ospf6d"] ipv4_routing: bool = True ipv6_routing: bool = True @@ -300,8 +300,8 @@ class Bgp(QuaggaService, ConfigService): """ name: str = "BGP" - shutdown: List[str] = ["killall bgpd"] - validate: List[str] = ["pidof bgpd"] + shutdown: list[str] = ["killall bgpd"] + validate: list[str] = ["pidof bgpd"] ipv4_routing: bool = True ipv6_routing: bool = True @@ -329,8 +329,8 @@ class Rip(QuaggaService, ConfigService): """ name: str = "RIP" - shutdown: List[str] = ["killall ripd"] - validate: List[str] = ["pidof ripd"] + shutdown: list[str] = ["killall ripd"] + validate: list[str] = ["pidof ripd"] ipv4_routing: bool = True def quagga_config(self) -> str: @@ -354,8 +354,8 @@ class Ripng(QuaggaService, ConfigService): """ name: str = "RIPNG" - shutdown: List[str] = ["killall ripngd"] - validate: List[str] = ["pidof ripngd"] + shutdown: list[str] = ["killall ripngd"] + validate: list[str] = ["pidof ripngd"] ipv6_routing: bool = True def quagga_config(self) -> str: @@ -380,8 +380,8 @@ class Babel(QuaggaService, ConfigService): """ name: str = "Babel" - shutdown: List[str] = ["killall babeld"] - validate: List[str] = ["pidof babeld"] + shutdown: list[str] = ["killall babeld"] + validate: list[str] = ["pidof babeld"] ipv6_routing: bool = True def quagga_config(self) -> str: @@ -420,8 +420,8 @@ class Xpimd(QuaggaService, ConfigService): """ name: str = "Xpimd" - shutdown: List[str] = ["killall xpimd"] - validate: List[str] = ["pidof xpimd"] + shutdown: list[str] = ["killall xpimd"] + validate: list[str] = ["pidof xpimd"] ipv4_routing: bool = True def quagga_config(self) -> str: diff --git a/daemon/core/configservices/securityservices/services.py b/daemon/core/configservices/securityservices/services.py index e866617c..e6243b2c 100644 --- a/daemon/core/configservices/securityservices/services.py +++ b/daemon/core/configservices/securityservices/services.py @@ -1,4 +1,4 @@ -from typing import Any, Dict, List +from typing import Any from core.config import ConfigString, Configuration from core.configservice.base import ConfigService, ConfigServiceMode @@ -9,41 +9,41 @@ GROUP_NAME: str = "Security" class VpnClient(ConfigService): name: str = "VPNClient" group: str = GROUP_NAME - directories: List[str] = [] - files: List[str] = ["vpnclient.sh"] - executables: List[str] = ["openvpn", "ip", "killall"] - dependencies: List[str] = [] - startup: List[str] = ["bash vpnclient.sh"] - validate: List[str] = ["pidof openvpn"] - shutdown: List[str] = ["killall openvpn"] + directories: list[str] = [] + files: list[str] = ["vpnclient.sh"] + executables: list[str] = ["openvpn", "ip", "killall"] + dependencies: list[str] = [] + startup: list[str] = ["bash vpnclient.sh"] + validate: list[str] = ["pidof openvpn"] + shutdown: list[str] = ["killall openvpn"] validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING - default_configs: List[Configuration] = [ + default_configs: list[Configuration] = [ ConfigString(id="keydir", label="Key Dir", default="/etc/core/keys"), ConfigString(id="keyname", label="Key Name", default="client1"), ConfigString(id="server", label="Server", default="10.0.2.10"), ] - modes: Dict[str, Dict[str, str]] = {} + modes: dict[str, dict[str, str]] = {} class VpnServer(ConfigService): name: str = "VPNServer" group: str = GROUP_NAME - directories: List[str] = [] - files: List[str] = ["vpnserver.sh"] - executables: List[str] = ["openvpn", "ip", "killall"] - dependencies: List[str] = [] - startup: List[str] = ["bash vpnserver.sh"] - validate: List[str] = ["pidof openvpn"] - shutdown: List[str] = ["killall openvpn"] + directories: list[str] = [] + files: list[str] = ["vpnserver.sh"] + executables: list[str] = ["openvpn", "ip", "killall"] + dependencies: list[str] = [] + startup: list[str] = ["bash vpnserver.sh"] + validate: list[str] = ["pidof openvpn"] + shutdown: list[str] = ["killall openvpn"] validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING - default_configs: List[Configuration] = [ + default_configs: list[Configuration] = [ ConfigString(id="keydir", label="Key Dir", default="/etc/core/keys"), ConfigString(id="keyname", label="Key Name", default="server"), ConfigString(id="subnet", label="Subnet", default="10.0.200.0"), ] - modes: Dict[str, Dict[str, str]] = {} + modes: dict[str, dict[str, str]] = {} - def data(self) -> Dict[str, Any]: + def data(self) -> dict[str, Any]: address = None for iface in self.node.get_ifaces(control=False): ip4 = iface.get_ip4() @@ -56,48 +56,48 @@ class VpnServer(ConfigService): class IPsec(ConfigService): name: str = "IPsec" group: str = GROUP_NAME - directories: List[str] = [] - files: List[str] = ["ipsec.sh"] - executables: List[str] = ["racoon", "ip", "setkey", "killall"] - dependencies: List[str] = [] - startup: List[str] = ["bash ipsec.sh"] - validate: List[str] = ["pidof racoon"] - shutdown: List[str] = ["killall racoon"] + directories: list[str] = [] + files: list[str] = ["ipsec.sh"] + executables: list[str] = ["racoon", "ip", "setkey", "killall"] + dependencies: list[str] = [] + startup: list[str] = ["bash ipsec.sh"] + validate: list[str] = ["pidof racoon"] + shutdown: list[str] = ["killall racoon"] validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING - default_configs: List[Configuration] = [] - modes: Dict[str, Dict[str, str]] = {} + default_configs: list[Configuration] = [] + modes: dict[str, dict[str, str]] = {} class Firewall(ConfigService): name: str = "Firewall" group: str = GROUP_NAME - directories: List[str] = [] - files: List[str] = ["firewall.sh"] - executables: List[str] = ["iptables"] - dependencies: List[str] = [] - startup: List[str] = ["bash firewall.sh"] - validate: List[str] = [] - shutdown: List[str] = [] + directories: list[str] = [] + files: list[str] = ["firewall.sh"] + executables: list[str] = ["iptables"] + dependencies: list[str] = [] + startup: list[str] = ["bash firewall.sh"] + validate: list[str] = [] + shutdown: list[str] = [] validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING - default_configs: List[Configuration] = [] - modes: Dict[str, Dict[str, str]] = {} + default_configs: list[Configuration] = [] + modes: dict[str, dict[str, str]] = {} class Nat(ConfigService): name: str = "NAT" group: str = GROUP_NAME - directories: List[str] = [] - files: List[str] = ["nat.sh"] - executables: List[str] = ["iptables"] - dependencies: List[str] = [] - startup: List[str] = ["bash nat.sh"] - validate: List[str] = [] - shutdown: List[str] = [] + directories: list[str] = [] + files: list[str] = ["nat.sh"] + executables: list[str] = ["iptables"] + dependencies: list[str] = [] + startup: list[str] = ["bash nat.sh"] + validate: list[str] = [] + shutdown: list[str] = [] validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING - default_configs: List[Configuration] = [] - modes: Dict[str, Dict[str, str]] = {} + default_configs: list[Configuration] = [] + modes: dict[str, dict[str, str]] = {} - def data(self) -> Dict[str, Any]: + def data(self) -> dict[str, Any]: ifnames = [] for iface in self.node.get_ifaces(control=False): ifnames.append(iface.name) diff --git a/daemon/core/configservices/utilservices/services.py b/daemon/core/configservices/utilservices/services.py index 3a4addfe..73d72060 100644 --- a/daemon/core/configservices/utilservices/services.py +++ b/daemon/core/configservices/utilservices/services.py @@ -1,4 +1,4 @@ -from typing import Any, Dict, List +from typing import Any import netaddr @@ -12,18 +12,18 @@ GROUP_NAME = "Utility" class DefaultRouteService(ConfigService): name: str = "DefaultRoute" group: str = GROUP_NAME - directories: List[str] = [] - files: List[str] = ["defaultroute.sh"] - executables: List[str] = ["ip"] - dependencies: List[str] = [] - startup: List[str] = ["bash defaultroute.sh"] - validate: List[str] = [] - shutdown: List[str] = [] + directories: list[str] = [] + files: list[str] = ["defaultroute.sh"] + executables: list[str] = ["ip"] + dependencies: list[str] = [] + startup: list[str] = ["bash defaultroute.sh"] + validate: list[str] = [] + shutdown: list[str] = [] validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING - default_configs: List[Configuration] = [] - modes: Dict[str, Dict[str, str]] = {} + default_configs: list[Configuration] = [] + modes: dict[str, dict[str, str]] = {} - def data(self) -> Dict[str, Any]: + def data(self) -> dict[str, Any]: # only add default routes for linked routing nodes routes = [] ifaces = self.node.get_ifaces() @@ -40,18 +40,18 @@ class DefaultRouteService(ConfigService): class DefaultMulticastRouteService(ConfigService): name: str = "DefaultMulticastRoute" group: str = GROUP_NAME - directories: List[str] = [] - files: List[str] = ["defaultmroute.sh"] - executables: List[str] = [] - dependencies: List[str] = [] - startup: List[str] = ["bash defaultmroute.sh"] - validate: List[str] = [] - shutdown: List[str] = [] + directories: list[str] = [] + files: list[str] = ["defaultmroute.sh"] + executables: list[str] = [] + dependencies: list[str] = [] + startup: list[str] = ["bash defaultmroute.sh"] + validate: list[str] = [] + shutdown: list[str] = [] validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING - default_configs: List[Configuration] = [] - modes: Dict[str, Dict[str, str]] = {} + default_configs: list[Configuration] = [] + modes: dict[str, dict[str, str]] = {} - def data(self) -> Dict[str, Any]: + def data(self) -> dict[str, Any]: ifname = None for iface in self.node.get_ifaces(control=False): ifname = iface.name @@ -62,18 +62,18 @@ class DefaultMulticastRouteService(ConfigService): class StaticRouteService(ConfigService): name: str = "StaticRoute" group: str = GROUP_NAME - directories: List[str] = [] - files: List[str] = ["staticroute.sh"] - executables: List[str] = [] - dependencies: List[str] = [] - startup: List[str] = ["bash staticroute.sh"] - validate: List[str] = [] - shutdown: List[str] = [] + directories: list[str] = [] + files: list[str] = ["staticroute.sh"] + executables: list[str] = [] + dependencies: list[str] = [] + startup: list[str] = ["bash staticroute.sh"] + validate: list[str] = [] + shutdown: list[str] = [] validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING - default_configs: List[Configuration] = [] - modes: Dict[str, Dict[str, str]] = {} + default_configs: list[Configuration] = [] + modes: dict[str, dict[str, str]] = {} - def data(self) -> Dict[str, Any]: + def data(self) -> dict[str, Any]: routes = [] for iface in self.node.get_ifaces(control=False): for ip in iface.ips(): @@ -90,18 +90,18 @@ class StaticRouteService(ConfigService): class IpForwardService(ConfigService): name: str = "IPForward" group: str = GROUP_NAME - directories: List[str] = [] - files: List[str] = ["ipforward.sh"] - executables: List[str] = ["sysctl"] - dependencies: List[str] = [] - startup: List[str] = ["bash ipforward.sh"] - validate: List[str] = [] - shutdown: List[str] = [] + directories: list[str] = [] + files: list[str] = ["ipforward.sh"] + executables: list[str] = ["sysctl"] + dependencies: list[str] = [] + startup: list[str] = ["bash ipforward.sh"] + validate: list[str] = [] + shutdown: list[str] = [] validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING - default_configs: List[Configuration] = [] - modes: Dict[str, Dict[str, str]] = {} + default_configs: list[Configuration] = [] + modes: dict[str, dict[str, str]] = {} - def data(self) -> Dict[str, Any]: + def data(self) -> dict[str, Any]: devnames = [] for iface in self.node.get_ifaces(): devname = utils.sysctl_devname(iface.name) @@ -112,18 +112,18 @@ class IpForwardService(ConfigService): class SshService(ConfigService): name: str = "SSH" group: str = GROUP_NAME - directories: List[str] = ["/etc/ssh", "/var/run/sshd"] - files: List[str] = ["startsshd.sh", "/etc/ssh/sshd_config"] - executables: List[str] = ["sshd"] - dependencies: List[str] = [] - startup: List[str] = ["bash startsshd.sh"] - validate: List[str] = [] - shutdown: List[str] = ["killall sshd"] + directories: list[str] = ["/etc/ssh", "/var/run/sshd"] + files: list[str] = ["startsshd.sh", "/etc/ssh/sshd_config"] + executables: list[str] = ["sshd"] + dependencies: list[str] = [] + startup: list[str] = ["bash startsshd.sh"] + validate: list[str] = [] + shutdown: list[str] = ["killall sshd"] validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING - default_configs: List[Configuration] = [] - modes: Dict[str, Dict[str, str]] = {} + default_configs: list[Configuration] = [] + modes: dict[str, dict[str, str]] = {} - def data(self) -> Dict[str, Any]: + def data(self) -> dict[str, Any]: return dict( sshcfgdir=self.directories[0], sshstatedir=self.directories[1], @@ -134,18 +134,18 @@ class SshService(ConfigService): class DhcpService(ConfigService): name: str = "DHCP" group: str = GROUP_NAME - directories: List[str] = ["/etc/dhcp", "/var/lib/dhcp"] - files: List[str] = ["/etc/dhcp/dhcpd.conf"] - executables: List[str] = ["dhcpd"] - dependencies: List[str] = [] - startup: List[str] = ["touch /var/lib/dhcp/dhcpd.leases", "dhcpd"] - validate: List[str] = ["pidof dhcpd"] - shutdown: List[str] = ["killall dhcpd"] + directories: list[str] = ["/etc/dhcp", "/var/lib/dhcp"] + files: list[str] = ["/etc/dhcp/dhcpd.conf"] + executables: list[str] = ["dhcpd"] + dependencies: list[str] = [] + startup: list[str] = ["touch /var/lib/dhcp/dhcpd.leases", "dhcpd"] + validate: list[str] = ["pidof dhcpd"] + shutdown: list[str] = ["killall dhcpd"] validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING - default_configs: List[Configuration] = [] - modes: Dict[str, Dict[str, str]] = {} + default_configs: list[Configuration] = [] + modes: dict[str, dict[str, str]] = {} - def data(self) -> Dict[str, Any]: + def data(self) -> dict[str, Any]: subnets = [] for iface in self.node.get_ifaces(control=False): for ip4 in iface.ip4s: @@ -162,18 +162,18 @@ class DhcpService(ConfigService): class DhcpClientService(ConfigService): name: str = "DHCPClient" group: str = GROUP_NAME - directories: List[str] = [] - files: List[str] = ["startdhcpclient.sh"] - executables: List[str] = ["dhclient"] - dependencies: List[str] = [] - startup: List[str] = ["bash startdhcpclient.sh"] - validate: List[str] = ["pidof dhclient"] - shutdown: List[str] = ["killall dhclient"] + directories: list[str] = [] + files: list[str] = ["startdhcpclient.sh"] + executables: list[str] = ["dhclient"] + dependencies: list[str] = [] + startup: list[str] = ["bash startdhcpclient.sh"] + validate: list[str] = ["pidof dhclient"] + shutdown: list[str] = ["killall dhclient"] validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING - default_configs: List[Configuration] = [] - modes: Dict[str, Dict[str, str]] = {} + default_configs: list[Configuration] = [] + modes: dict[str, dict[str, str]] = {} - def data(self) -> Dict[str, Any]: + def data(self) -> dict[str, Any]: ifnames = [] for iface in self.node.get_ifaces(control=False): ifnames.append(iface.name) @@ -183,56 +183,56 @@ class DhcpClientService(ConfigService): class FtpService(ConfigService): name: str = "FTP" group: str = GROUP_NAME - directories: List[str] = ["/var/run/vsftpd/empty", "/var/ftp"] - files: List[str] = ["vsftpd.conf"] - executables: List[str] = ["vsftpd"] - dependencies: List[str] = [] - startup: List[str] = ["vsftpd ./vsftpd.conf"] - validate: List[str] = ["pidof vsftpd"] - shutdown: List[str] = ["killall vsftpd"] + directories: list[str] = ["/var/run/vsftpd/empty", "/var/ftp"] + files: list[str] = ["vsftpd.conf"] + executables: list[str] = ["vsftpd"] + dependencies: list[str] = [] + startup: list[str] = ["vsftpd ./vsftpd.conf"] + validate: list[str] = ["pidof vsftpd"] + shutdown: list[str] = ["killall vsftpd"] validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING - default_configs: List[Configuration] = [] - modes: Dict[str, Dict[str, str]] = {} + default_configs: list[Configuration] = [] + modes: dict[str, dict[str, str]] = {} class PcapService(ConfigService): name: str = "pcap" group: str = GROUP_NAME - directories: List[str] = [] - files: List[str] = ["pcap.sh"] - executables: List[str] = ["tcpdump"] - dependencies: List[str] = [] - startup: List[str] = ["bash pcap.sh start"] - validate: List[str] = ["pidof tcpdump"] - shutdown: List[str] = ["bash pcap.sh stop"] + directories: list[str] = [] + files: list[str] = ["pcap.sh"] + executables: list[str] = ["tcpdump"] + dependencies: list[str] = [] + startup: list[str] = ["bash pcap.sh start"] + validate: list[str] = ["pidof tcpdump"] + shutdown: list[str] = ["bash pcap.sh stop"] validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING - default_configs: List[Configuration] = [] - modes: Dict[str, Dict[str, str]] = {} + default_configs: list[Configuration] = [] + modes: dict[str, dict[str, str]] = {} - def data(self) -> Dict[str, Any]: + def data(self) -> dict[str, Any]: ifnames = [] for iface in self.node.get_ifaces(control=False): ifnames.append(iface.name) - return dict() + return dict(ifnames=ifnames) class RadvdService(ConfigService): name: str = "radvd" group: str = GROUP_NAME - directories: List[str] = ["/etc/radvd", "/var/run/radvd"] - files: List[str] = ["/etc/radvd/radvd.conf"] - executables: List[str] = ["radvd"] - dependencies: List[str] = [] - startup: List[str] = [ + directories: list[str] = ["/etc/radvd", "/var/run/radvd"] + files: list[str] = ["/etc/radvd/radvd.conf"] + executables: list[str] = ["radvd"] + dependencies: list[str] = [] + startup: list[str] = [ "radvd -C /etc/radvd/radvd.conf -m logfile -l /var/log/radvd.log" ] - validate: List[str] = ["pidof radvd"] - shutdown: List[str] = ["pkill radvd"] + validate: list[str] = ["pidof radvd"] + shutdown: list[str] = ["pkill radvd"] validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING - default_configs: List[Configuration] = [] - modes: Dict[str, Dict[str, str]] = {} + default_configs: list[Configuration] = [] + modes: dict[str, dict[str, str]] = {} - def data(self) -> Dict[str, Any]: + def data(self) -> dict[str, Any]: ifaces = [] for iface in self.node.get_ifaces(control=False): prefixes = [] @@ -247,22 +247,22 @@ class RadvdService(ConfigService): class AtdService(ConfigService): name: str = "atd" group: str = GROUP_NAME - directories: List[str] = ["/var/spool/cron/atjobs", "/var/spool/cron/atspool"] - files: List[str] = ["startatd.sh"] - executables: List[str] = ["atd"] - dependencies: List[str] = [] - startup: List[str] = ["bash startatd.sh"] - validate: List[str] = ["pidof atd"] - shutdown: List[str] = ["pkill atd"] + directories: list[str] = ["/var/spool/cron/atjobs", "/var/spool/cron/atspool"] + files: list[str] = ["startatd.sh"] + executables: list[str] = ["atd"] + dependencies: list[str] = [] + startup: list[str] = ["bash startatd.sh"] + validate: list[str] = ["pidof atd"] + shutdown: list[str] = ["pkill atd"] validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING - default_configs: List[Configuration] = [] - modes: Dict[str, Dict[str, str]] = {} + default_configs: list[Configuration] = [] + modes: dict[str, dict[str, str]] = {} class HttpService(ConfigService): name: str = "HTTP" group: str = GROUP_NAME - directories: List[str] = [ + directories: list[str] = [ "/etc/apache2", "/var/run/apache2", "/var/log/apache2", @@ -270,21 +270,21 @@ class HttpService(ConfigService): "/var/lock/apache2", "/var/www", ] - files: List[str] = [ + files: list[str] = [ "/etc/apache2/apache2.conf", "/etc/apache2/envvars", "/var/www/index.html", ] - executables: List[str] = ["apache2ctl"] - dependencies: List[str] = [] - startup: List[str] = ["chown www-data /var/lock/apache2", "apache2ctl start"] - validate: List[str] = ["pidof apache2"] - shutdown: List[str] = ["apache2ctl stop"] + executables: list[str] = ["apache2ctl"] + dependencies: list[str] = [] + startup: list[str] = ["chown www-data /var/lock/apache2", "apache2ctl start"] + validate: list[str] = ["pidof apache2"] + shutdown: list[str] = ["apache2ctl stop"] validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING - default_configs: List[Configuration] = [] - modes: Dict[str, Dict[str, str]] = {} + default_configs: list[Configuration] = [] + modes: dict[str, dict[str, str]] = {} - def data(self) -> Dict[str, Any]: + def data(self) -> dict[str, Any]: ifaces = [] for iface in self.node.get_ifaces(control=False): ifaces.append(iface) diff --git a/daemon/core/configservices/utilservices/templates/etc/radvd/radvd.conf b/daemon/core/configservices/utilservices/templates/etc/radvd/radvd.conf index 1436f068..d003b4b1 100644 --- a/daemon/core/configservices/utilservices/templates/etc/radvd/radvd.conf +++ b/daemon/core/configservices/utilservices/templates/etc/radvd/radvd.conf @@ -1,5 +1,5 @@ # auto-generated by RADVD service (utility.py) -% for ifname, prefixes in values: +% for ifname, prefixes in ifaces: interface ${ifname} { AdvSendAdvert on; diff --git a/daemon/core/configservices/utilservices/templates/ipforward.sh b/daemon/core/configservices/utilservices/templates/ipforward.sh index a8d3abed..75717ecf 100644 --- a/daemon/core/configservices/utilservices/templates/ipforward.sh +++ b/daemon/core/configservices/utilservices/templates/ipforward.sh @@ -13,4 +13,5 @@ sysctl -w net.ipv4.conf.default.rp_filter=0 sysctl -w net.ipv4.conf.${devname}.forwarding=1 sysctl -w net.ipv4.conf.${devname}.send_redirects=0 sysctl -w net.ipv4.conf.${devname}.rp_filter=0 +sysctl -w net.ipv6.conf.${devname}.forwarding=1 % endfor diff --git a/daemon/core/configservices/utilservices/templates/pcap.sh b/daemon/core/configservices/utilservices/templates/pcap.sh index 6a099f8c..d4a0ea9f 100644 --- a/daemon/core/configservices/utilservices/templates/pcap.sh +++ b/daemon/core/configservices/utilservices/templates/pcap.sh @@ -3,7 +3,7 @@ # (-s snap length, -C limit pcap file length, -n disable name resolution) if [ "x$1" = "xstart" ]; then % for ifname in ifnames: - tcpdump -s 12288 -C 10 -n -w ${node.name}.${ifname}.pcap -i ${ifname} < /dev/null & + tcpdump -s 12288 -C 10 -n -w ${node.name}.${ifname}.pcap -i ${ifname} > /dev/null 2>&1 & % endfor elif [ "x$1" = "xstop" ]; then mkdir -p $SESSION_DIR/pcap diff --git a/daemon/core/emane/emanemanager.py b/daemon/core/emane/emanemanager.py index 294ae528..c02570c9 100644 --- a/daemon/core/emane/emanemanager.py +++ b/daemon/core/emane/emanemanager.py @@ -6,7 +6,7 @@ import logging import os import threading from enum import Enum -from typing import TYPE_CHECKING, Dict, List, Optional, Set, Tuple, Type, Union +from typing import TYPE_CHECKING, Optional, Union from core import utils from core.emane.emanemodel import EmaneModel @@ -126,9 +126,9 @@ class EmaneManager: """ super().__init__() self.session: "Session" = session - self.nems_to_ifaces: Dict[int, CoreInterface] = {} - self.ifaces_to_nems: Dict[CoreInterface, int] = {} - self._emane_nets: Dict[int, EmaneNet] = {} + self.nems_to_ifaces: dict[int, CoreInterface] = {} + self.ifaces_to_nems: dict[CoreInterface, int] = {} + self._emane_nets: dict[int, EmaneNet] = {} self._emane_node_lock: threading.Lock = threading.Lock() # port numbers are allocated from these counters self.platformport: int = self.session.options.get_int( @@ -141,14 +141,14 @@ class EmaneManager: self.eventmonthread: Optional[threading.Thread] = None # model for global EMANE configuration options - self.node_configs: Dict[int, Dict[str, Dict[str, str]]] = {} - self.node_models: Dict[int, str] = {} + self.node_configs: dict[int, dict[str, dict[str, str]]] = {} + self.node_models: dict[int, str] = {} # link monitor self.link_monitor: EmaneLinkMonitor = EmaneLinkMonitor(self) # emane event monitoring - self.services: Dict[str, EmaneEventService] = {} - self.nem_service: Dict[int, EmaneEventService] = {} + self.services: dict[str, EmaneEventService] = {} + self.nem_service: dict[int, EmaneEventService] = {} def next_nem_id(self, iface: CoreInterface) -> int: nem_id = self.session.options.get_int("nem_id_start") @@ -161,7 +161,7 @@ class EmaneManager: def get_config( self, key: int, model: str, default: bool = True - ) -> Optional[Dict[str, str]]: + ) -> Optional[dict[str, str]]: """ Get the current or default configuration for an emane model. @@ -181,7 +181,7 @@ class EmaneManager: config = model_class.default_values() return config - def set_config(self, key: int, model: str, config: Dict[str, str] = None) -> None: + def set_config(self, key: int, model: str, config: dict[str, str] = None) -> None: """ Sets and update the provided configuration against the default model or currently set emane model configuration. @@ -199,7 +199,7 @@ class EmaneManager: model_configs = self.node_configs.setdefault(key, {}) model_configs[model] = model_config - def get_model(self, model_name: str) -> Type[EmaneModel]: + def get_model(self, model_name: str) -> type[EmaneModel]: """ Convenience method for getting globally loaded emane models. @@ -211,7 +211,7 @@ class EmaneManager: def get_iface_config( self, emane_net: EmaneNet, iface: CoreInterface - ) -> Dict[str, str]: + ) -> dict[str, str]: """ Retrieve configuration for a given interface, first checking for interface specific config, node specific config, network specific config, and finally @@ -260,7 +260,7 @@ class EmaneManager: ) self._emane_nets[emane_net.id] = emane_net - def getnodes(self) -> Set[CoreNode]: + def getnodes(self) -> set[CoreNode]: """ Return a set of CoreNodes that are linked to an EMANE network, e.g. containers having one or more radio interfaces. @@ -335,7 +335,7 @@ class EmaneManager: self.start_daemon(iface) self.install_iface(iface, config) - def get_ifaces(self) -> List[Tuple[EmaneNet, TunTap]]: + def get_ifaces(self) -> list[tuple[EmaneNet, TunTap]]: ifaces = [] for emane_net in self._emane_nets.values(): if not emane_net.wireless_model: @@ -354,7 +354,7 @@ class EmaneManager: return sorted(ifaces, key=lambda x: (x[1].node.id, x[1].id)) def setup_control_channels( - self, nem_id: int, iface: CoreInterface, config: Dict[str, str] + self, nem_id: int, iface: CoreInterface, config: dict[str, str] ) -> None: node = iface.node # setup ota device @@ -419,7 +419,7 @@ class EmaneManager: def get_nem_position( self, iface: CoreInterface - ) -> Optional[Tuple[int, float, float, int]]: + ) -> Optional[tuple[int, float, float, int]]: """ Retrieves nem position for a given interface. @@ -453,7 +453,7 @@ class EmaneManager: event.append(nemid, latitude=lat, longitude=lon, altitude=alt) self.publish_event(nemid, event, send_all=True) - def set_nem_positions(self, moved_ifaces: List[CoreInterface]) -> None: + def set_nem_positions(self, moved_ifaces: list[CoreInterface]) -> None: """ Several NEMs have moved, from e.g. a WaypointMobilityModel calculation. Generate an EMANE Location Event having several @@ -480,7 +480,7 @@ class EmaneManager: try: with path.open("a") as f: f.write(f"{iface.node.name} {iface.name} {nem_id}\n") - except IOError: + except OSError: logger.exception("error writing to emane nem file") def links_enabled(self) -> bool: @@ -624,7 +624,7 @@ class EmaneManager: args = f"{emanecmd} -f {log_file} {platform_xml}" node.host_cmd(args, cwd=self.session.directory) - def install_iface(self, iface: TunTap, config: Dict[str, str]) -> None: + def install_iface(self, iface: TunTap, config: dict[str, str]) -> None: external = config.get("external", "0") if external == "0": iface.set_ips() diff --git a/daemon/core/emane/emanemanifest.py b/daemon/core/emane/emanemanifest.py index 0fb5bc17..ea2b05fd 100644 --- a/daemon/core/emane/emanemanifest.py +++ b/daemon/core/emane/emanemanifest.py @@ -1,6 +1,5 @@ import logging from pathlib import Path -from typing import Dict, List from core.config import Configuration from core.emulator.enumerations import ConfigDataTypes @@ -33,7 +32,7 @@ def _type_value(config_type: str) -> ConfigDataTypes: return ConfigDataTypes[config_type] -def _get_possible(config_type: str, config_regex: str) -> List[str]: +def _get_possible(config_type: str, config_regex: str) -> list[str]: """ Retrieve possible config value options based on emane regexes. @@ -51,7 +50,7 @@ def _get_possible(config_type: str, config_regex: str) -> List[str]: return [] -def _get_default(config_type_name: str, config_value: List[str]) -> str: +def _get_default(config_type_name: str, config_value: list[str]) -> str: """ Convert default configuration values to one used by core. @@ -74,7 +73,7 @@ def _get_default(config_type_name: str, config_value: List[str]) -> str: return config_default -def parse(manifest_path: Path, defaults: Dict[str, str]) -> List[Configuration]: +def parse(manifest_path: Path, defaults: dict[str, str]) -> list[Configuration]: """ Parses a valid emane manifest file and converts the provided configuration values into ones used by core. diff --git a/daemon/core/emane/emanemodel.py b/daemon/core/emane/emanemodel.py index cc5b0f4d..4e31d632 100644 --- a/daemon/core/emane/emanemodel.py +++ b/daemon/core/emane/emanemodel.py @@ -3,7 +3,7 @@ Defines Emane Models used within CORE. """ import logging from pathlib import Path -from typing import Dict, List, Optional, Set +from typing import Optional from core.config import ConfigBool, ConfigGroup, ConfigString, Configuration from core.emane import emanemanifest @@ -28,38 +28,38 @@ class EmaneModel(WirelessModel): # default platform configuration settings platform_controlport: str = "controlportendpoint" platform_xml: str = "nemmanager.xml" - platform_defaults: Dict[str, str] = { + platform_defaults: dict[str, str] = { "eventservicedevice": DEFAULT_DEV, "eventservicegroup": "224.1.2.8:45703", "otamanagerdevice": DEFAULT_DEV, "otamanagergroup": "224.1.2.8:45702", } - platform_config: List[Configuration] = [] + platform_config: list[Configuration] = [] # default mac configuration settings mac_library: Optional[str] = None mac_xml: Optional[str] = None - mac_defaults: Dict[str, str] = {} - mac_config: List[Configuration] = [] + mac_defaults: dict[str, str] = {} + mac_config: list[Configuration] = [] # default phy configuration settings, using the universal model phy_library: Optional[str] = None phy_xml: str = "emanephy.xml" - phy_defaults: Dict[str, str] = { + phy_defaults: dict[str, str] = { "subid": "1", "propagationmodel": "2ray", "noisemode": "none", } - phy_config: List[Configuration] = [] + phy_config: list[Configuration] = [] # support for external configurations - external_config: List[Configuration] = [ + external_config: list[Configuration] = [ ConfigBool(id="external", default="0"), ConfigString(id="platformendpoint", default="127.0.0.1:40001"), ConfigString(id="transportendpoint", default="127.0.0.1:50002"), ] - config_ignore: Set[str] = set() + config_ignore: set[str] = set() @classmethod def load(cls, emane_prefix: Path) -> None: @@ -94,7 +94,7 @@ class EmaneModel(WirelessModel): cls.platform_config.pop(controlport_index) @classmethod - def configurations(cls) -> List[Configuration]: + def configurations(cls) -> list[Configuration]: """ Returns the combination all all configurations (mac, phy, and external). @@ -105,7 +105,7 @@ class EmaneModel(WirelessModel): ) @classmethod - def config_groups(cls) -> List[ConfigGroup]: + def config_groups(cls) -> list[ConfigGroup]: """ Returns the defined configuration groups. @@ -122,7 +122,7 @@ class EmaneModel(WirelessModel): ConfigGroup("External Parameters", phy_len + 1, config_len), ] - def build_xml_files(self, config: Dict[str, str], iface: CoreInterface) -> None: + def build_xml_files(self, config: dict[str, str], iface: CoreInterface) -> None: """ Builds xml files for this emane model. Creates a nem.xml file that points to both mac.xml and phy.xml definitions. @@ -146,7 +146,7 @@ class EmaneModel(WirelessModel): """ logger.debug("emane model(%s) has no post setup tasks", self.name) - def update(self, moved_ifaces: List[CoreInterface]) -> None: + def update(self, moved_ifaces: list[CoreInterface]) -> None: """ Invoked from MobilityModel when nodes are moved; this causes emane location events to be generated for the nodes in the moved diff --git a/daemon/core/emane/linkmonitor.py b/daemon/core/emane/linkmonitor.py index 5ed6d49d..1997e9f8 100644 --- a/daemon/core/emane/linkmonitor.py +++ b/daemon/core/emane/linkmonitor.py @@ -2,7 +2,7 @@ import logging import sched import threading import time -from typing import TYPE_CHECKING, Dict, List, Optional, Set, Tuple +from typing import TYPE_CHECKING, Optional from lxml import etree @@ -34,10 +34,10 @@ NEM_SELF: int = 65535 class LossTable: - def __init__(self, losses: Dict[float, float]) -> None: - self.losses: Dict[float, float] = losses - self.sinrs: List[float] = sorted(self.losses.keys()) - self.loss_lookup: Dict[int, float] = {} + def __init__(self, losses: dict[float, float]) -> None: + self.losses: dict[float, float] = losses + self.sinrs: list[float] = sorted(self.losses.keys()) + self.loss_lookup: dict[int, float] = {} for index, value in enumerate(self.sinrs): self.loss_lookup[index] = self.losses[value] self.mac_id: Optional[str] = None @@ -84,7 +84,7 @@ class EmaneClient: self.client: shell.ControlPortClient = shell.ControlPortClient( self.address, port ) - self.nems: Dict[int, LossTable] = {} + self.nems: dict[int, LossTable] = {} self.setup() def setup(self) -> None: @@ -110,7 +110,7 @@ class EmaneClient: self.nems[nem_id] = loss_table def check_links( - self, links: Dict[Tuple[int, int], EmaneLink], loss_threshold: int + self, links: dict[tuple[int, int], EmaneLink], loss_threshold: int ) -> None: for from_nem, loss_table in self.nems.items(): tables = self.client.getStatisticTable(loss_table.mac_id, (SINR_TABLE,)) @@ -138,11 +138,11 @@ class EmaneClient: link = EmaneLink(from_nem, to_nem, sinr) links[link_key] = link - def handle_tdma(self, config: Dict[str, Tuple]): + def handle_tdma(self, config: dict[str, tuple]): pcr = config["pcrcurveuri"][0][0] logger.debug("tdma pcr: %s", pcr) - def handle_80211(self, config: Dict[str, Tuple]) -> LossTable: + def handle_80211(self, config: dict[str, tuple]) -> LossTable: unicastrate = config["unicastrate"][0][0] pcr = config["pcrcurveuri"][0][0] logger.debug("80211 pcr: %s", pcr) @@ -159,7 +159,7 @@ class EmaneClient: losses[sinr] = por return LossTable(losses) - def handle_rfpipe(self, config: Dict[str, Tuple]) -> LossTable: + def handle_rfpipe(self, config: dict[str, tuple]) -> LossTable: pcr = config["pcrcurveuri"][0][0] logger.debug("rfpipe pcr: %s", pcr) tree = etree.parse(pcr) @@ -179,9 +179,9 @@ class EmaneClient: class EmaneLinkMonitor: def __init__(self, emane_manager: "EmaneManager") -> None: self.emane_manager: "EmaneManager" = emane_manager - self.clients: List[EmaneClient] = [] - self.links: Dict[Tuple[int, int], EmaneLink] = {} - self.complete_links: Set[Tuple[int, int]] = set() + self.clients: list[EmaneClient] = [] + self.links: dict[tuple[int, int], EmaneLink] = {} + self.complete_links: set[tuple[int, int]] = set() self.loss_threshold: Optional[int] = None self.link_interval: Optional[int] = None self.link_timeout: Optional[int] = None @@ -210,7 +210,7 @@ class EmaneLinkMonitor: if client.nems: self.clients.append(client) - def get_addresses(self) -> List[Tuple[str, int]]: + def get_addresses(self) -> list[tuple[str, int]]: addresses = [] nodes = self.emane_manager.getnodes() for node in nodes: @@ -273,25 +273,25 @@ class EmaneLinkMonitor: if self.running: self.scheduler.enter(self.link_interval, 0, self.check_links) - def get_complete_id(self, link_id: Tuple[int, int]) -> Tuple[int, int]: + def get_complete_id(self, link_id: tuple[int, int]) -> tuple[int, int]: value1, value2 = link_id if value1 < value2: return value1, value2 else: return value2, value1 - def is_complete_link(self, link_id: Tuple[int, int]) -> bool: + def is_complete_link(self, link_id: tuple[int, int]) -> bool: reverse_id = link_id[1], link_id[0] return link_id in self.links and reverse_id in self.links - def get_link_label(self, link_id: Tuple[int, int]) -> str: + def get_link_label(self, link_id: tuple[int, int]) -> str: source_id = tuple(sorted(link_id)) source_link = self.links[source_id] dest_id = link_id[::-1] dest_link = self.links[dest_id] return f"{source_link.sinr:.1f} / {dest_link.sinr:.1f}" - def send_link(self, message_type: MessageFlags, link_id: Tuple[int, int]) -> None: + def send_link(self, message_type: MessageFlags, link_id: tuple[int, int]) -> None: nem1, nem2 = link_id link = self.emane_manager.get_nem_link(nem1, nem2, message_type) if link: diff --git a/daemon/core/emane/modelmanager.py b/daemon/core/emane/modelmanager.py index 989802c4..92dd5b8e 100644 --- a/daemon/core/emane/modelmanager.py +++ b/daemon/core/emane/modelmanager.py @@ -1,7 +1,6 @@ import logging import pkgutil from pathlib import Path -from typing import Dict, List, Type from core import utils from core.emane import models as emane_models @@ -12,10 +11,10 @@ logger = logging.getLogger(__name__) class EmaneModelManager: - models: Dict[str, Type[EmaneModel]] = {} + models: dict[str, type[EmaneModel]] = {} @classmethod - def load_locals(cls, emane_prefix: Path) -> List[str]: + def load_locals(cls, emane_prefix: Path) -> list[str]: """ Load local core emane models and make them available. @@ -38,7 +37,7 @@ class EmaneModelManager: return errors @classmethod - def load(cls, path: Path, emane_prefix: Path) -> List[str]: + def load(cls, path: Path, emane_prefix: Path) -> list[str]: """ Search and load custom emane models and make them available. @@ -63,7 +62,7 @@ class EmaneModelManager: return errors @classmethod - def get(cls, name: str) -> Type[EmaneModel]: + def get(cls, name: str) -> type[EmaneModel]: model = cls.models.get(name) if model is None: raise CoreError(f"emame model does not exist {name}") diff --git a/daemon/core/emane/models/bypass.py b/daemon/core/emane/models/bypass.py index 25841114..e8f2ed39 100644 --- a/daemon/core/emane/models/bypass.py +++ b/daemon/core/emane/models/bypass.py @@ -2,7 +2,6 @@ EMANE Bypass model for CORE """ from pathlib import Path -from typing import List, Set from core.config import ConfigBool, Configuration from core.emane import emanemodel @@ -12,11 +11,11 @@ class EmaneBypassModel(emanemodel.EmaneModel): name: str = "emane_bypass" # values to ignore, when writing xml files - config_ignore: Set[str] = {"none"} + config_ignore: set[str] = {"none"} # mac definitions mac_library: str = "bypassmaclayer" - mac_config: List[Configuration] = [ + mac_config: list[Configuration] = [ ConfigBool( id="none", default="0", @@ -26,7 +25,7 @@ class EmaneBypassModel(emanemodel.EmaneModel): # phy definitions phy_library: str = "bypassphylayer" - phy_config: List[Configuration] = [] + phy_config: list[Configuration] = [] @classmethod def load(cls, emane_prefix: Path) -> None: diff --git a/daemon/core/emane/models/commeffect.py b/daemon/core/emane/models/commeffect.py index c3f0b07b..aa093a93 100644 --- a/daemon/core/emane/models/commeffect.py +++ b/daemon/core/emane/models/commeffect.py @@ -4,7 +4,6 @@ commeffect.py: EMANE CommEffect model for CORE import logging from pathlib import Path -from typing import Dict, List from lxml import etree @@ -42,12 +41,12 @@ class EmaneCommEffectModel(emanemodel.EmaneModel): name: str = "emane_commeffect" shim_library: str = "commeffectshim" shim_xml: str = "commeffectshim.xml" - shim_defaults: Dict[str, str] = {} - config_shim: List[Configuration] = [] + shim_defaults: dict[str, str] = {} + config_shim: list[Configuration] = [] # comm effect does not need the default phy and external configurations - phy_config: List[Configuration] = [] - external_config: List[Configuration] = [] + phy_config: list[Configuration] = [] + external_config: list[Configuration] = [] @classmethod def load(cls, emane_prefix: Path) -> None: @@ -56,11 +55,11 @@ class EmaneCommEffectModel(emanemodel.EmaneModel): cls.config_shim = emanemanifest.parse(shim_xml_path, cls.shim_defaults) @classmethod - def configurations(cls) -> List[Configuration]: + def configurations(cls) -> list[Configuration]: return cls.platform_config + cls.config_shim @classmethod - def config_groups(cls) -> List[ConfigGroup]: + def config_groups(cls) -> list[ConfigGroup]: platform_len = len(cls.platform_config) return [ ConfigGroup("Platform Parameters", 1, platform_len), @@ -71,7 +70,7 @@ class EmaneCommEffectModel(emanemodel.EmaneModel): ), ] - def build_xml_files(self, config: Dict[str, str], iface: CoreInterface) -> None: + def build_xml_files(self, config: dict[str, str], iface: CoreInterface) -> None: """ Build the necessary nem and commeffect XMLs in the given path. If an individual NEM has a nonstandard config, we need to build diff --git a/daemon/core/emane/models/tdma.py b/daemon/core/emane/models/tdma.py index c6ac631b..100e960d 100644 --- a/daemon/core/emane/models/tdma.py +++ b/daemon/core/emane/models/tdma.py @@ -4,7 +4,6 @@ tdma.py: EMANE TDMA model bindings for CORE import logging from pathlib import Path -from typing import Set from core import constants, utils from core.config import ConfigString @@ -28,7 +27,7 @@ class EmaneTdmaModel(emanemodel.EmaneModel): default_schedule: Path = ( constants.CORE_DATA_DIR / "examples" / "tdma" / "schedule.xml" ) - config_ignore: Set[str] = {schedule_name} + config_ignore: set[str] = {schedule_name} @classmethod def load(cls, emane_prefix: Path) -> None: diff --git a/daemon/core/emane/nodes.py b/daemon/core/emane/nodes.py index 1a0b6e75..ecf684d7 100644 --- a/daemon/core/emane/nodes.py +++ b/daemon/core/emane/nodes.py @@ -6,11 +6,11 @@ share the same MAC+PHY model. import logging import time from dataclasses import dataclass -from typing import TYPE_CHECKING, Callable, Dict, List, Optional, Type, Union +from typing import TYPE_CHECKING, Callable, Optional, Union from core.emulator.data import InterfaceData, LinkData, LinkOptions from core.emulator.distributed import DistributedServer -from core.emulator.enumerations import EventTypes, MessageFlags, RegisterTlvs +from core.emulator.enumerations import MessageFlags, RegisterTlvs from core.errors import CoreCommandError, CoreError from core.nodes.base import CoreNetworkBase, CoreNode, NodeOptions from core.nodes.interface import CoreInterface @@ -167,7 +167,7 @@ class EmaneNet(CoreNetworkBase): self.mobility: Optional[WayPointMobility] = None model_class = self.session.emane.get_model(options.emane_model) self.wireless_model: Optional["EmaneModel"] = model_class(self.session, self.id) - if self.session.state == EventTypes.RUNTIME_STATE: + if self.session.is_running(): self.session.emane.add_node(self) @classmethod @@ -196,7 +196,7 @@ class EmaneNet(CoreNetworkBase): def unlink(self, iface1: CoreInterface, iface2: CoreInterface) -> None: pass - def updatemodel(self, config: Dict[str, str]) -> None: + def updatemodel(self, config: dict[str, str]) -> None: """ Update configuration for the current model. @@ -212,8 +212,8 @@ class EmaneNet(CoreNetworkBase): def setmodel( self, - model: Union[Type["EmaneModel"], Type["WayPointMobility"]], - config: Dict[str, str], + model: Union[type["EmaneModel"], type["WayPointMobility"]], + config: dict[str, str], ) -> None: """ set the EmaneModel associated with this node @@ -225,7 +225,7 @@ class EmaneNet(CoreNetworkBase): self.mobility = model(session=self.session, _id=self.id) self.mobility.update_config(config) - def links(self, flags: MessageFlags = MessageFlags.NONE) -> List[LinkData]: + def links(self, flags: MessageFlags = MessageFlags.NONE) -> list[LinkData]: links = [] emane_manager = self.session.emane # gather current emane links @@ -280,7 +280,7 @@ class EmaneNet(CoreNetworkBase): self.attach(iface) if self.up: iface.startup() - if self.session.state == EventTypes.RUNTIME_STATE: + if self.session.is_running(): self.session.emane.start_iface(self, iface) return iface diff --git a/daemon/core/emulator/broadcast.py b/daemon/core/emulator/broadcast.py new file mode 100644 index 00000000..bf56f99d --- /dev/null +++ b/daemon/core/emulator/broadcast.py @@ -0,0 +1,67 @@ +from collections.abc import Callable +from typing import TypeVar, Union + +from core.emulator.data import ( + ConfigData, + EventData, + ExceptionData, + FileData, + LinkData, + NodeData, +) +from core.errors import CoreError + +T = TypeVar( + "T", bound=Union[EventData, ExceptionData, NodeData, LinkData, FileData, ConfigData] +) + + +class BroadcastManager: + def __init__(self) -> None: + """ + Creates a BroadcastManager instance. + """ + self.handlers: dict[type[T], set[Callable[[T], None]]] = {} + + def send(self, data: T) -> None: + """ + Retrieve handlers for data, and run all current handlers. + + :param data: data to provide to handlers + :return: nothing + """ + handlers = self.handlers.get(type(data), set()) + for handler in handlers: + handler(data) + + def add_handler(self, data_type: type[T], handler: Callable[[T], None]) -> None: + """ + Add a handler for a given data type. + + :param data_type: type of data to add handler for + :param handler: handler to add + :return: nothing + """ + handlers = self.handlers.setdefault(data_type, set()) + if handler in handlers: + raise CoreError( + f"cannot add data({data_type}) handler({repr(handler)}), " + f"already exists" + ) + handlers.add(handler) + + def remove_handler(self, data_type: type[T], handler: Callable[[T], None]) -> None: + """ + Remove a handler for a given data type. + + :param data_type: type of data to remove handler for + :param handler: handler to remove + :return: nothing + """ + handlers = self.handlers.get(data_type, set()) + if handler not in handlers: + raise CoreError( + f"cannot remove data({data_type}) handler({repr(handler)}), " + f"does not exist" + ) + handlers.remove(handler) diff --git a/daemon/core/emulator/controlnets.py b/daemon/core/emulator/controlnets.py new file mode 100644 index 00000000..27b00367 --- /dev/null +++ b/daemon/core/emulator/controlnets.py @@ -0,0 +1,239 @@ +import logging +from typing import TYPE_CHECKING, Optional + +from core import utils +from core.emulator.data import InterfaceData +from core.errors import CoreError +from core.nodes.base import CoreNode +from core.nodes.interface import DEFAULT_MTU +from core.nodes.network import CtrlNet + +logger = logging.getLogger(__name__) + +if TYPE_CHECKING: + from core.emulator.session import Session + +CTRL_NET_ID: int = 9001 +ETC_HOSTS_PATH: str = "/etc/hosts" + + +class ControlNetManager: + def __init__(self, session: "Session") -> None: + self.session: "Session" = session + self.etc_hosts_header: str = f"CORE session {self.session.id} host entries" + + def _etc_hosts_enabled(self) -> bool: + """ + Determines if /etc/hosts should be configured. + + :return: True if /etc/hosts should be configured, False otherwise + """ + return self.session.options.get_bool("update_etc_hosts", False) + + def _get_server_ifaces( + self, + ) -> tuple[None, Optional[str], Optional[str], Optional[str]]: + """ + Retrieve control net server interfaces. + + :return: control net server interfaces + """ + d0 = self.session.options.get("controlnetif0") + if d0: + logger.error("controlnet0 cannot be assigned with a host interface") + d1 = self.session.options.get("controlnetif1") + d2 = self.session.options.get("controlnetif2") + d3 = self.session.options.get("controlnetif3") + return None, d1, d2, d3 + + def _get_prefixes( + self, + ) -> tuple[Optional[str], Optional[str], Optional[str], Optional[str]]: + """ + Retrieve control net prefixes. + + :return: control net prefixes + """ + p = self.session.options.get("controlnet") + p0 = self.session.options.get("controlnet0") + p1 = self.session.options.get("controlnet1") + p2 = self.session.options.get("controlnet2") + p3 = self.session.options.get("controlnet3") + if not p0 and p: + p0 = p + return p0, p1, p2, p3 + + def update_etc_hosts(self) -> None: + """ + Add the IP addresses of control interfaces to the /etc/hosts file. + + :return: nothing + """ + if not self._etc_hosts_enabled(): + return + control_net = self.get_control_net(0) + entries = "" + for iface in control_net.get_ifaces(): + name = iface.node.name + for ip in iface.ips(): + entries += f"{ip.ip} {name}\n" + logger.info("adding entries to /etc/hosts") + utils.file_munge(ETC_HOSTS_PATH, self.etc_hosts_header, entries) + + def clear_etc_hosts(self) -> None: + """ + Clear IP addresses of control interfaces from the /etc/hosts file. + + :return: nothing + """ + if not self._etc_hosts_enabled(): + return + logger.info("removing /etc/hosts file entries") + utils.file_demunge(ETC_HOSTS_PATH, self.etc_hosts_header) + + def get_control_net_index(self, dev: str) -> int: + """ + Retrieve control net index. + + :param dev: device to get control net index for + :return: control net index, -1 otherwise + """ + if dev[0:4] == "ctrl" and int(dev[4]) in (0, 1, 2, 3): + index = int(dev[4]) + if index == 0: + return index + if index < 4 and self._get_prefixes()[index] is not None: + return index + return -1 + + def get_control_net(self, index: int) -> Optional[CtrlNet]: + """ + Retrieve a control net based on index. + + :param index: control net index + :return: control net when available, None otherwise + """ + try: + return self.session.get_node(CTRL_NET_ID + index, CtrlNet) + except CoreError: + return None + + def add_control_net( + self, index: int, conf_required: bool = True + ) -> Optional[CtrlNet]: + """ + Create a control network bridge as necessary. The conf_reqd flag, + when False, causes a control network bridge to be added even if + one has not been configured. + + :param index: network index to add + :param conf_required: flag to check if conf is required + :return: control net node + """ + logger.info( + "checking to add control net index(%s) conf_required(%s)", + index, + conf_required, + ) + # check for valid index + if not (0 <= index <= 3): + raise CoreError(f"invalid control net index({index})") + # return any existing control net bridge + control_net = self.get_control_net(index) + if control_net: + logger.info("control net index(%s) already exists", index) + return control_net + # retrieve prefix for current index + index_prefix = self._get_prefixes()[index] + if not index_prefix: + if conf_required: + return None + else: + index_prefix = CtrlNet.DEFAULT_PREFIX_LIST[index] + # retrieve valid prefix from old style values + prefixes = index_prefix.split() + if len(prefixes) > 1: + # a list of per-host prefixes is provided + try: + prefix = prefixes[0].split(":", 1)[1] + except IndexError: + prefix = prefixes[0] + else: + prefix = prefixes[0] + # use the updown script for control net 0 only + updown_script = None + if index == 0: + updown_script = self.session.options.get("controlnet_updown_script") + # build a new controlnet bridge + _id = CTRL_NET_ID + index + server_iface = self._get_server_ifaces()[index] + logger.info( + "adding controlnet(%s) prefix(%s) updown(%s) server interface(%s)", + _id, + prefix, + updown_script, + server_iface, + ) + options = CtrlNet.create_options() + options.prefix = prefix + options.updown_script = updown_script + options.serverintf = server_iface + control_net = self.session.create_node(CtrlNet, False, _id, options=options) + control_net.brname = f"ctrl{index}.{self.session.short_session_id()}" + control_net.startup() + return control_net + + def remove_control_net(self, index: int) -> None: + """ + Removes control net. + + :param index: index of control net to remove + :return: nothing + """ + control_net = self.get_control_net(index) + if control_net: + logger.info("removing control net index(%s)", index) + self.session.delete_node(control_net.id) + + def add_control_iface(self, node: CoreNode, index: int) -> None: + """ + Adds a control net interface to a node. + + :param node: node to add control net interface to + :param index: index of control net to add interface to + :return: nothing + :raises CoreError: if control net doesn't exist, interface already exists, + or there is an error creating the interface + """ + control_net = self.get_control_net(index) + if not control_net: + raise CoreError(f"control net index({index}) does not exist") + iface_id = control_net.CTRLIF_IDX_BASE + index + if node.ifaces.get(iface_id): + raise CoreError(f"control iface({iface_id}) already exists") + try: + logger.info( + "node(%s) adding control net index(%s) interface(%s)", + node.name, + index, + iface_id, + ) + ip4 = control_net.prefix[node.id] + ip4_mask = control_net.prefix.prefixlen + iface_data = InterfaceData( + id=iface_id, + name=f"ctrl{index}", + mac=utils.random_mac(), + ip4=ip4, + ip4_mask=ip4_mask, + mtu=DEFAULT_MTU, + ) + iface = node.create_iface(iface_data) + control_net.attach(iface) + iface.control = True + except ValueError: + raise CoreError( + f"error adding control net interface to node({node.id}), " + f"invalid control net prefix({control_net.prefix}), " + "a longer prefix length may be required" + ) diff --git a/daemon/core/emulator/coreemu.py b/daemon/core/emulator/coreemu.py index a4b0be6a..574002e6 100644 --- a/daemon/core/emulator/coreemu.py +++ b/daemon/core/emulator/coreemu.py @@ -1,7 +1,6 @@ import logging import os from pathlib import Path -from typing import Dict, List, Type from core import utils from core.configservice.manager import ConfigServiceManager @@ -20,7 +19,7 @@ class CoreEmu: Provides logic for creating and configuring CORE sessions and the nodes within them. """ - def __init__(self, config: Dict[str, str] = None) -> None: + def __init__(self, config: dict[str, str] = None) -> None: """ Create a CoreEmu object. @@ -31,13 +30,13 @@ class CoreEmu: # configuration config = config if config else {} - self.config: Dict[str, str] = config + self.config: dict[str, str] = config # session management - self.sessions: Dict[int, Session] = {} + self.sessions: dict[int, Session] = {} # load services - self.service_errors: List[str] = [] + self.service_errors: list[str] = [] self.service_manager: ConfigServiceManager = ConfigServiceManager() self._load_services() @@ -119,7 +118,7 @@ class CoreEmu: _, session = self.sessions.popitem() session.shutdown() - def create_session(self, _id: int = None, _cls: Type[Session] = Session) -> Session: + def create_session(self, _id: int = None, _cls: type[Session] = Session) -> Session: """ Create a new CORE session. diff --git a/daemon/core/emulator/data.py b/daemon/core/emulator/data.py index de5b3559..7d3dc8dc 100644 --- a/daemon/core/emulator/data.py +++ b/daemon/core/emulator/data.py @@ -2,7 +2,7 @@ CORE data objects. """ from dataclasses import dataclass, field -from typing import TYPE_CHECKING, Any, List, Optional, Tuple +from typing import TYPE_CHECKING, Any, Optional import netaddr @@ -24,7 +24,7 @@ class ConfigData: node: int = None object: str = None type: int = None - data_types: Tuple[int] = None + data_types: tuple[int] = None data_values: str = None captions: str = None bitmap: str = None @@ -81,8 +81,8 @@ class NodeOptions: model: Optional[str] = "PC" canvas: int = None icon: str = None - services: List[str] = field(default_factory=list) - config_services: List[str] = field(default_factory=list) + services: list[str] = field(default_factory=list) + config_services: list[str] = field(default_factory=list) x: float = None y: float = None lat: float = None @@ -93,9 +93,9 @@ class NodeOptions: emane: str = None legacy: bool = False # src, dst - binds: List[Tuple[str, str]] = field(default_factory=list) + binds: list[tuple[str, str]] = field(default_factory=list) # src, dst, unique, delete - volumes: List[Tuple[str, str, bool, bool]] = field(default_factory=list) + volumes: list[tuple[str, str, bool, bool]] = field(default_factory=list) def set_position(self, x: float, y: float) -> None: """ @@ -148,7 +148,7 @@ class InterfaceData: ip6_mask: int = None mtu: int = None - def get_ips(self) -> List[str]: + def get_ips(self) -> list[str]: """ Returns a list of ip4 and ip6 addresses when present. diff --git a/daemon/core/emulator/distributed.py b/daemon/core/emulator/distributed.py index 1d09ce1e..1c0d3c92 100644 --- a/daemon/core/emulator/distributed.py +++ b/daemon/core/emulator/distributed.py @@ -8,7 +8,7 @@ import threading from collections import OrderedDict from pathlib import Path from tempfile import NamedTemporaryFile -from typing import TYPE_CHECKING, Callable, Dict, Tuple +from typing import TYPE_CHECKING, Callable import netaddr from fabric import Connection @@ -48,7 +48,7 @@ class DistributedServer: self.lock: threading.Lock = threading.Lock() def remote_cmd( - self, cmd: str, env: Dict[str, str] = None, cwd: str = None, wait: bool = True + self, cmd: str, env: dict[str, str] = None, cwd: str = None, wait: bool = True ) -> str: """ Run command remotely using server connection. @@ -105,7 +105,7 @@ class DistributedServer: """ with self.lock: temp = NamedTemporaryFile(delete=False) - temp.write(data.encode("utf-8")) + temp.write(data.encode()) temp.close() self.conn.put(temp.name, str(dst_path)) os.unlink(temp.name) @@ -123,8 +123,8 @@ class DistributedController: :param session: session """ self.session: "Session" = session - self.servers: Dict[str, DistributedServer] = OrderedDict() - self.tunnels: Dict[int, Tuple[GreTap, GreTap]] = {} + self.servers: dict[str, DistributedServer] = OrderedDict() + self.tunnels: dict[int, tuple[GreTap, GreTap]] = {} self.address: str = self.session.options.get("distributed_address") def add_server(self, name: str, host: str) -> None: @@ -187,8 +187,7 @@ class DistributedController: :return: nothing """ mtu = self.session.options.get_int("mtu") - for node_id in self.session.nodes: - node = self.session.nodes[node_id] + for node in self.session.nodes.values(): if not isinstance(node, CtrlNet) or node.serverintf is not None: continue for name in self.servers: @@ -214,7 +213,7 @@ class DistributedController: def create_gre_tunnel( self, node: CoreNetwork, server: DistributedServer, mtu: int, start: bool - ) -> Tuple[GreTap, GreTap]: + ) -> tuple[GreTap, GreTap]: """ Create gre tunnel using a pair of gre taps between the local and remote server. diff --git a/daemon/core/emulator/enumerations.py b/daemon/core/emulator/enumerations.py index e04d382b..96fb919b 100644 --- a/daemon/core/emulator/enumerations.py +++ b/daemon/core/emulator/enumerations.py @@ -50,6 +50,7 @@ class NodeTypes(Enum): DOCKER = 15 LXC = 16 WIRELESS = 17 + PODMAN = 18 class LinkTypes(Enum): diff --git a/daemon/core/emulator/hooks.py b/daemon/core/emulator/hooks.py new file mode 100644 index 00000000..ffeeafeb --- /dev/null +++ b/daemon/core/emulator/hooks.py @@ -0,0 +1,145 @@ +import logging +import subprocess +from collections.abc import Callable +from pathlib import Path + +from core.emulator.enumerations import EventTypes +from core.errors import CoreError + +logger = logging.getLogger(__name__) + + +class HookManager: + """ + Provides functionality for managing and running script/callback hooks. + """ + + def __init__(self) -> None: + """ + Create a HookManager instance. + """ + self.script_hooks: dict[EventTypes, dict[str, str]] = {} + self.callback_hooks: dict[EventTypes, list[Callable[[], None]]] = {} + + def reset(self) -> None: + """ + Clear all current hooks. + + :return: nothing + """ + self.script_hooks.clear() + self.callback_hooks.clear() + + def add_script_hook(self, state: EventTypes, file_name: str, data: str) -> None: + """ + Add a hook script to run for a given state. + + :param state: state to run hook on + :param file_name: hook file name + :param data: file data + :return: nothing + """ + logger.info("setting state hook: %s - %s", state, file_name) + state_hooks = self.script_hooks.setdefault(state, {}) + if file_name in state_hooks: + raise CoreError( + f"adding duplicate state({state.name}) hook script({file_name})" + ) + state_hooks[file_name] = data + + def delete_script_hook(self, state: EventTypes, file_name: str) -> None: + """ + Delete a script hook from a given state. + + :param state: state to delete script hook from + :param file_name: name of script to delete + :return: nothing + """ + state_hooks = self.script_hooks.get(state, {}) + if file_name not in state_hooks: + raise CoreError( + f"deleting state({state.name}) hook script({file_name}) " + "that does not exist" + ) + del state_hooks[file_name] + + def add_callback_hook( + self, state: EventTypes, hook: Callable[[EventTypes], None] + ) -> None: + """ + Add a hook callback to run for a state. + + :param state: state to add hook for + :param hook: callback to run + :return: nothing + """ + hooks = self.callback_hooks.setdefault(state, []) + if hook in hooks: + name = getattr(callable, "__name__", repr(hook)) + raise CoreError( + f"adding duplicate state({state.name}) hook callback({name})" + ) + hooks.append(hook) + + def delete_callback_hook( + self, state: EventTypes, hook: Callable[[EventTypes], None] + ) -> None: + """ + Delete a state hook. + + :param state: state to delete hook for + :param hook: hook to delete + :return: nothing + """ + hooks = self.callback_hooks.get(state, []) + if hook not in hooks: + name = getattr(callable, "__name__", repr(hook)) + raise CoreError( + f"deleting state({state.name}) hook callback({name}) " + "that does not exist" + ) + hooks.remove(hook) + + def run_hooks( + self, state: EventTypes, directory: Path, env: dict[str, str] + ) -> None: + """ + Run all hooks for the current state. + + :param state: state to run hooks for + :param directory: directory to run script hooks within + :param env: environment to run script hooks with + :return: nothing + """ + for state_hooks in self.script_hooks.get(state, {}): + for file_name, data in state_hooks.items(): + logger.info("running hook %s", file_name) + file_path = directory / file_name + log_path = directory / f"{file_name}.log" + try: + with file_path.open("w") as f: + f.write(data) + with log_path.open("w") as f: + args = ["/bin/sh", file_name] + subprocess.check_call( + args, + stdout=f, + stderr=subprocess.STDOUT, + close_fds=True, + cwd=directory, + env=env, + ) + except (OSError, subprocess.CalledProcessError) as e: + raise CoreError( + f"failure running state({state.name}) " + f"hook script({file_name}): {e}" + ) + for hook in self.callback_hooks.get(state, []): + try: + hook() + except Exception as e: + name = getattr(callable, "__name__", repr(hook)) + raise CoreError( + f"failure running state({state.name}) " + f"hook callback({name}): {e}" + ) diff --git a/daemon/core/emulator/links.py b/daemon/core/emulator/links.py index 22f75b98..5df29d90 100644 --- a/daemon/core/emulator/links.py +++ b/daemon/core/emulator/links.py @@ -4,8 +4,9 @@ for a session. """ import logging +from collections.abc import ValuesView from dataclasses import dataclass -from typing import Dict, Optional, Tuple, ValuesView +from typing import Optional from core.emulator.data import LinkData, LinkOptions from core.emulator.enumerations import LinkTypes, MessageFlags @@ -15,7 +16,7 @@ from core.nodes.interface import CoreInterface from core.nodes.network import PtpNet logger = logging.getLogger(__name__) -LinkKeyType = Tuple[int, Optional[int], int, Optional[int]] +LinkKeyType = tuple[int, Optional[int], int, Optional[int]] def create_key( @@ -145,8 +146,8 @@ class LinkManager: """ Create a LinkManager instance. """ - self._links: Dict[LinkKeyType, CoreLink] = {} - self._node_links: Dict[int, Dict[LinkKeyType, CoreLink]] = {} + self._links: dict[LinkKeyType, CoreLink] = {} + self._node_links: dict[int, dict[LinkKeyType, CoreLink]] = {} def add(self, core_link: CoreLink) -> None: """ diff --git a/daemon/core/emulator/session.py b/daemon/core/emulator/session.py index b8b1b35e..5a6557ee 100644 --- a/daemon/core/emulator/session.py +++ b/daemon/core/emulator/session.py @@ -14,7 +14,7 @@ import tempfile import threading import time from pathlib import Path -from typing import Callable, Dict, List, Optional, Set, Tuple, Type, TypeVar, Union +from typing import Callable, Optional, TypeVar, Union from core import constants, utils from core.configservice.manager import ConfigServiceManager @@ -57,6 +57,7 @@ from core.nodes.network import ( WlanNode, ) from core.nodes.physical import PhysicalNode, Rj45Node +from core.nodes.podman import PodmanNode from core.nodes.wireless import WirelessNode from core.plugins.sdt import Sdt from core.services.coreservices import CoreServices @@ -66,7 +67,7 @@ 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]] = { +NODES: dict[NodeTypes, type[NodeBase]] = { NodeTypes.DEFAULT: CoreNode, NodeTypes.PHYSICAL: PhysicalNode, NodeTypes.SWITCH: SwitchNode, @@ -81,13 +82,13 @@ NODES: Dict[NodeTypes, Type[NodeBase]] = { NodeTypes.DOCKER: DockerNode, NodeTypes.LXC: LxcNode, NodeTypes.WIRELESS: WirelessNode, + NodeTypes.PODMAN: PodmanNode, } -NODES_TYPE: Dict[Type[NodeBase], NodeTypes] = {NODES[x]: x for x in NODES} -CONTAINER_NODES: Set[Type[NodeBase]] = {DockerNode, LxcNode} +NODES_TYPE: dict[type[NodeBase], NodeTypes] = {NODES[x]: x for x in NODES} CTRL_NET_ID: int = 9001 -LINK_COLORS: List[str] = ["green", "blue", "orange", "purple", "turquoise"] +LINK_COLORS: list[str] = ["green", "blue", "orange", "purple", "turquoise"] NT: TypeVar = TypeVar("NT", bound=NodeBase) -WIRELESS_TYPE: Tuple[Type[WlanNode], Type[EmaneNet], Type[WirelessNode]] = ( +WIRELESS_TYPE: tuple[type[WlanNode], type[EmaneNet], type[WirelessNode]] = ( WlanNode, EmaneNet, WirelessNode, @@ -100,7 +101,7 @@ class Session: """ def __init__( - self, _id: int, config: Dict[str, str] = None, mkdir: bool = True + self, _id: int, config: dict[str, str] = None, mkdir: bool = True ) -> None: """ Create a Session instance. @@ -121,33 +122,33 @@ class Session: self.thumbnail: Optional[Path] = None self.user: Optional[str] = None self.event_loop: EventLoop = EventLoop() - self.link_colors: Dict[int, str] = {} + self.link_colors: dict[int, str] = {} # dict of nodes: all nodes and nets - self.nodes: Dict[int, NodeBase] = {} + self.nodes: dict[int, NodeBase] = {} self.nodes_lock: threading.Lock = threading.Lock() self.link_manager: LinkManager = LinkManager() # states and hooks handlers self.state: EventTypes = EventTypes.DEFINITION_STATE self.state_time: float = time.monotonic() - self.hooks: Dict[EventTypes, List[Tuple[str, str]]] = {} - self.state_hooks: Dict[EventTypes, List[Callable[[EventTypes], None]]] = {} + self.hooks: dict[EventTypes, list[tuple[str, str]]] = {} + self.state_hooks: dict[EventTypes, list[Callable[[EventTypes], None]]] = {} self.add_state_hook( state=EventTypes.RUNTIME_STATE, hook=self.runtime_state_hook ) # handlers for broadcasting information - self.event_handlers: List[Callable[[EventData], None]] = [] - self.exception_handlers: List[Callable[[ExceptionData], None]] = [] - self.node_handlers: List[Callable[[NodeData], None]] = [] - self.link_handlers: List[Callable[[LinkData], None]] = [] - self.file_handlers: List[Callable[[FileData], None]] = [] - self.config_handlers: List[Callable[[ConfigData], None]] = [] + self.event_handlers: list[Callable[[EventData], None]] = [] + self.exception_handlers: list[Callable[[ExceptionData], None]] = [] + self.node_handlers: list[Callable[[NodeData], None]] = [] + self.link_handlers: list[Callable[[LinkData], None]] = [] + self.file_handlers: list[Callable[[FileData], None]] = [] + self.config_handlers: list[Callable[[ConfigData], None]] = [] # session options/metadata self.options: SessionConfig = SessionConfig(config) - self.metadata: Dict[str, str] = {} + self.metadata: dict[str, str] = {} # distributed support and logic self.distributed: DistributedController = DistributedController(self) @@ -163,7 +164,7 @@ class Session: self.service_manager: Optional[ConfigServiceManager] = None @classmethod - def get_node_class(cls, _type: NodeTypes) -> Type[NodeBase]: + def get_node_class(cls, _type: NodeTypes) -> type[NodeBase]: """ Retrieve the class for a given node type. @@ -176,7 +177,7 @@ class Session: return node_class @classmethod - def get_node_type(cls, _class: Type[NodeBase]) -> NodeTypes: + def get_node_type(cls, _class: type[NodeBase]) -> NodeTypes: """ Retrieve node type for a given node class. @@ -238,7 +239,7 @@ class Session: iface1_data: InterfaceData = None, iface2_data: InterfaceData = None, options: LinkOptions = None, - ) -> Tuple[Optional[CoreInterface], Optional[CoreInterface]]: + ) -> tuple[Optional[CoreInterface], Optional[CoreInterface]]: """ Add a link between nodes. @@ -345,7 +346,7 @@ class Session: iface1_data: InterfaceData = None, iface2_data: InterfaceData = None, options: LinkOptions = None, - ) -> Tuple[CoreInterface, CoreInterface]: + ) -> tuple[CoreInterface, CoreInterface]: """ Create a wired link between two nodes. @@ -476,7 +477,7 @@ class Session: def add_node( self, - _class: Type[NT], + _class: type[NT], _id: int = None, name: str = None, server: str = None, @@ -520,8 +521,7 @@ class Session: if isinstance(node, WlanNode): self.mobility.set_model_config(node.id, BasicRangeModel.name) # boot core nodes after runtime - is_runtime = self.state == EventTypes.RUNTIME_STATE - if is_runtime and isinstance(node, CoreNode): + if self.is_running() and isinstance(node, CoreNode): self.add_remove_control_iface(node, remove=False) self.boot_node(node) self.sdt.add_node(node) @@ -746,7 +746,7 @@ class Session: for hook in hooks: self.run_hook(hook) - def run_hook(self, hook: Tuple[str, str]) -> None: + def run_hook(self, hook: tuple[str, str]) -> None: """ Run a hook. @@ -770,7 +770,7 @@ class Session: cwd=self.directory, env=self.get_environment(), ) - except (IOError, subprocess.CalledProcessError): + except (OSError, subprocess.CalledProcessError): logger.exception("error running hook: %s", file_path) def run_state_hooks(self, state: EventTypes) -> None: @@ -836,7 +836,7 @@ class Session: xml_file_path = self.directory / "session-deployed.xml" xml_writer.write(xml_file_path) - def get_environment(self, state: bool = True) -> Dict[str, str]: + def get_environment(self, state: bool = True) -> dict[str, str]: """ Get an environment suitable for a subprocess.Popen call. This is the current process environment with some session-specific @@ -871,7 +871,7 @@ class Session: if path.is_file(): try: utils.load_config(path, env) - except IOError: + except OSError: logger.exception("error reading environment file: %s", path) return env @@ -888,12 +888,12 @@ class Session: uid = pwd.getpwnam(user).pw_uid gid = self.directory.stat().st_gid os.chown(self.directory, uid, gid) - except IOError: + except OSError: logger.exception("failed to set permission on %s", self.directory) def create_node( self, - _class: Type[NT], + _class: type[NT], start: bool, _id: int = None, name: str = None, @@ -929,7 +929,7 @@ class Session: node.startup() return node - def get_node(self, _id: int, _class: Type[NT]) -> NT: + def get_node(self, _id: int, _class: type[NT]) -> NT: """ Get a session node. @@ -1003,7 +1003,7 @@ class Session: ) self.broadcast_exception(exception_data) - def instantiate(self) -> List[Exception]: + def instantiate(self) -> list[Exception]: """ We have entered the instantiation state, invoke startup methods of various managers and boot the nodes. Validate nodes and check @@ -1011,7 +1011,7 @@ class Session: :return: list of service boot errors during startup """ - if self.state == EventTypes.RUNTIME_STATE: + if self.is_running(): logger.warning("ignoring instantiate, already in runtime state") return [] # create control net interfaces and network tunnels @@ -1083,6 +1083,7 @@ class Session: if isinstance(node, CoreNodeBase) and node.up: args = (node,) funcs.append((self.services.stop_services, args, {})) + funcs.append((node.stop_config_services, (), {})) utils.threadpool(funcs) # shutdown emane @@ -1122,7 +1123,7 @@ class Session: self.services.boot_services(node) node.start_config_services() - def boot_nodes(self) -> List[Exception]: + def boot_nodes(self) -> list[Exception]: """ Invoke the boot() procedure for all nodes and send back node messages to the GUI for node messages that had the status @@ -1144,7 +1145,7 @@ class Session: self.update_control_iface_hosts() return exceptions - def get_control_net_prefixes(self) -> List[str]: + def get_control_net_prefixes(self) -> list[str]: """ Retrieve control net prefixes. @@ -1159,7 +1160,7 @@ class Session: p0 = p return [p0, p1, p2, p3] - def get_control_net_server_ifaces(self) -> List[str]: + def get_control_net_server_ifaces(self) -> list[str]: """ Retrieve control net server interfaces. @@ -1365,7 +1366,7 @@ class Session: Return the current time we have been in the runtime state, or zero if not in runtime. """ - if self.state == EventTypes.RUNTIME_STATE: + if self.is_running(): return time.monotonic() - self.state_time else: return 0.0 @@ -1442,3 +1443,11 @@ class Session: color = LINK_COLORS[index] self.link_colors[network_id] = color return color + + def is_running(self) -> bool: + """ + Convenience for checking if this session is in the runtime state. + + :return: True if in the runtime state, False otherwise + """ + return self.state == EventTypes.RUNTIME_STATE diff --git a/daemon/core/emulator/sessionconfig.py b/daemon/core/emulator/sessionconfig.py index ead9e9e5..b6d5bcd3 100644 --- a/daemon/core/emulator/sessionconfig.py +++ b/daemon/core/emulator/sessionconfig.py @@ -1,4 +1,4 @@ -from typing import Dict, List, Optional +from typing import Optional from core.config import ConfigBool, ConfigInt, ConfigString, Configuration from core.errors import CoreError @@ -10,7 +10,7 @@ class SessionConfig: Provides session configuration. """ - options: List[Configuration] = [ + options: list[Configuration] = [ ConfigString(id="controlnet", label="Control Network"), ConfigString(id="controlnet0", label="Control Network 0"), ConfigString(id="controlnet1", label="Control Network 1"), @@ -35,16 +35,16 @@ class SessionConfig: ConfigInt(id="mtu", default="0", label="MTU for All Devices"), ] - def __init__(self, config: Dict[str, str] = None) -> None: + def __init__(self, config: dict[str, str] = None) -> None: """ Create a SessionConfig instance. :param config: configuration to initialize with """ - self._config: Dict[str, str] = {x.id: x.default for x in self.options} + self._config: dict[str, str] = {x.id: x.default for x in self.options} self._config.update(config or {}) - def update(self, config: Dict[str, str]) -> None: + def update(self, config: dict[str, str]) -> None: """ Update current configuration with provided values. @@ -73,7 +73,7 @@ class SessionConfig: """ return self._config.get(name, default) - def all(self) -> Dict[str, str]: + def all(self) -> dict[str, str]: """ Retrieve all configuration options. diff --git a/daemon/core/executables.py b/daemon/core/executables.py index 95c97378..f04d88de 100644 --- a/daemon/core/executables.py +++ b/daemon/core/executables.py @@ -1,5 +1,3 @@ -from typing import List - BASH: str = "bash" ETHTOOL: str = "ethtool" IP: str = "ip" @@ -13,7 +11,7 @@ UMOUNT: str = "umount" VCMD: str = "vcmd" VNODED: str = "vnoded" -COMMON_REQUIREMENTS: List[str] = [ +COMMON_REQUIREMENTS: list[str] = [ BASH, ETHTOOL, IP, @@ -26,10 +24,10 @@ COMMON_REQUIREMENTS: List[str] = [ VCMD, VNODED, ] -OVS_REQUIREMENTS: List[str] = [OVS_VSCTL] +OVS_REQUIREMENTS: list[str] = [OVS_VSCTL] -def get_requirements(use_ovs: bool) -> List[str]: +def get_requirements(use_ovs: bool) -> list[str]: """ Retrieve executable requirements needed to run CORE. diff --git a/daemon/core/gui/app.py b/daemon/core/gui/app.py index d905bff3..4fd1dce5 100644 --- a/daemon/core/gui/app.py +++ b/daemon/core/gui/app.py @@ -3,7 +3,7 @@ import math import tkinter as tk from tkinter import PhotoImage, font, messagebox, ttk from tkinter.ttk import Progressbar -from typing import Any, Dict, Optional, Type +from typing import Any, Optional import grpc @@ -45,7 +45,7 @@ class Application(ttk.Frame): self.show_infobar: tk.BooleanVar = tk.BooleanVar(value=False) # fonts - self.fonts_size: Dict[str, int] = {} + self.fonts_size: dict[str, int] = {} self.icon_text_font: Optional[font.Font] = None self.edge_font: Optional[font.Font] = None @@ -145,7 +145,7 @@ class Application(ttk.Frame): self.statusbar = StatusBar(self.right_frame, self) self.statusbar.grid(sticky=tk.EW, columnspan=2) - def display_info(self, frame_class: Type[InfoFrameBase], **kwargs: Any) -> None: + def display_info(self, frame_class: type[InfoFrameBase], **kwargs: Any) -> None: if not self.show_infobar.get(): return self.clear_info() diff --git a/daemon/core/gui/appconfig.py b/daemon/core/gui/appconfig.py index 04f2fdcb..0a5ae76b 100644 --- a/daemon/core/gui/appconfig.py +++ b/daemon/core/gui/appconfig.py @@ -1,7 +1,7 @@ import os import shutil from pathlib import Path -from typing import Dict, List, Optional, Type +from typing import Optional import yaml @@ -26,7 +26,7 @@ LOCAL_XMLS_PATH: Path = DATA_PATH.joinpath("xmls").absolute() LOCAL_MOBILITY_PATH: Path = DATA_PATH.joinpath("mobility").absolute() # configuration data -TERMINALS: Dict[str, str] = { +TERMINALS: dict[str, str] = { "xterm": "xterm -e", "aterm": "aterm -e", "eterm": "eterm -e", @@ -36,7 +36,7 @@ TERMINALS: Dict[str, str] = { "xfce4-terminal": "xfce4-terminal -x", "gnome-terminal": "gnome-terminal --window --", } -EDITORS: List[str] = ["$EDITOR", "vim", "emacs", "gedit", "nano", "vi"] +EDITORS: list[str] = ["$EDITOR", "vim", "emacs", "gedit", "nano", "vi"] class IndentDumper(yaml.Dumper): @@ -46,17 +46,17 @@ class IndentDumper(yaml.Dumper): class CustomNode(yaml.YAMLObject): yaml_tag: str = "!CustomNode" - yaml_loader: Type[yaml.SafeLoader] = yaml.SafeLoader + yaml_loader: type[yaml.SafeLoader] = yaml.SafeLoader - def __init__(self, name: str, image: str, services: List[str]) -> None: + def __init__(self, name: str, image: str, services: list[str]) -> None: self.name: str = name self.image: str = image - self.services: List[str] = services + self.services: list[str] = services class CoreServer(yaml.YAMLObject): yaml_tag: str = "!CoreServer" - yaml_loader: Type[yaml.SafeLoader] = yaml.SafeLoader + yaml_loader: type[yaml.SafeLoader] = yaml.SafeLoader def __init__(self, name: str, address: str) -> None: self.name: str = name @@ -65,7 +65,7 @@ class CoreServer(yaml.YAMLObject): class Observer(yaml.YAMLObject): yaml_tag: str = "!Observer" - yaml_loader: Type[yaml.SafeLoader] = yaml.SafeLoader + yaml_loader: type[yaml.SafeLoader] = yaml.SafeLoader def __init__(self, name: str, cmd: str) -> None: self.name: str = name @@ -74,7 +74,7 @@ class Observer(yaml.YAMLObject): class PreferencesConfig(yaml.YAMLObject): yaml_tag: str = "!PreferencesConfig" - yaml_loader: Type[yaml.SafeLoader] = yaml.SafeLoader + yaml_loader: type[yaml.SafeLoader] = yaml.SafeLoader def __init__( self, @@ -95,7 +95,7 @@ class PreferencesConfig(yaml.YAMLObject): class LocationConfig(yaml.YAMLObject): yaml_tag: str = "!LocationConfig" - yaml_loader: Type[yaml.SafeLoader] = yaml.SafeLoader + yaml_loader: type[yaml.SafeLoader] = yaml.SafeLoader def __init__( self, @@ -118,17 +118,17 @@ class LocationConfig(yaml.YAMLObject): class IpConfigs(yaml.YAMLObject): yaml_tag: str = "!IpConfigs" - yaml_loader: Type[yaml.SafeLoader] = yaml.SafeLoader + yaml_loader: type[yaml.SafeLoader] = yaml.SafeLoader def __init__(self, **kwargs) -> None: self.__setstate__(kwargs) def __setstate__(self, kwargs): - self.ip4s: List[str] = kwargs.get( + self.ip4s: list[str] = kwargs.get( "ip4s", ["10.0.0.0", "192.168.0.0", "172.16.0.0"] ) self.ip4: str = kwargs.get("ip4", self.ip4s[0]) - self.ip6s: List[str] = kwargs.get("ip6s", ["2001::", "2002::", "a::"]) + self.ip6s: list[str] = kwargs.get("ip6s", ["2001::", "2002::", "a::"]) self.ip6: str = kwargs.get("ip6", self.ip6s[0]) self.enable_ip4: bool = kwargs.get("enable_ip4", True) self.enable_ip6: bool = kwargs.get("enable_ip6", True) @@ -136,16 +136,16 @@ class IpConfigs(yaml.YAMLObject): class GuiConfig(yaml.YAMLObject): yaml_tag: str = "!GuiConfig" - yaml_loader: Type[yaml.SafeLoader] = yaml.SafeLoader + yaml_loader: type[yaml.SafeLoader] = yaml.SafeLoader def __init__( self, preferences: PreferencesConfig = None, location: LocationConfig = None, - servers: List[CoreServer] = None, - nodes: List[CustomNode] = None, - recentfiles: List[str] = None, - observers: List[Observer] = None, + servers: list[CoreServer] = None, + nodes: list[CustomNode] = None, + recentfiles: list[str] = None, + observers: list[Observer] = None, scale: float = 1.0, ips: IpConfigs = None, mac: str = "00:00:00:aa:00:00", @@ -158,16 +158,16 @@ class GuiConfig(yaml.YAMLObject): self.location: LocationConfig = location if servers is None: servers = [] - self.servers: List[CoreServer] = servers + self.servers: list[CoreServer] = servers if nodes is None: nodes = [] - self.nodes: List[CustomNode] = nodes + self.nodes: list[CustomNode] = nodes if recentfiles is None: recentfiles = [] - self.recentfiles: List[str] = recentfiles + self.recentfiles: list[str] = recentfiles if observers is None: observers = [] - self.observers: List[Observer] = observers + self.observers: list[Observer] = observers self.scale: float = scale if ips is None: ips = IpConfigs() diff --git a/daemon/core/gui/coreclient.py b/daemon/core/gui/coreclient.py index cd33aeca..da2ca6d6 100644 --- a/daemon/core/gui/coreclient.py +++ b/daemon/core/gui/coreclient.py @@ -6,9 +6,10 @@ import json import logging import os import tkinter as tk +from collections.abc import Iterable from pathlib import Path from tkinter import messagebox -from typing import TYPE_CHECKING, Dict, Iterable, List, Optional, Set, Tuple +from typing import TYPE_CHECKING, Optional import grpc @@ -16,6 +17,7 @@ from core.api.grpc import client, configservices_pb2, core_pb2 from core.api.grpc.wrappers import ( ConfigOption, ConfigService, + ConfigServiceDefaults, EmaneModelConfig, Event, ExceptionEvent, @@ -55,7 +57,7 @@ GUI_SOURCE = "gui" CPU_USAGE_DELAY = 3 -def to_dict(config: Dict[str, ConfigOption]) -> Dict[str, str]: +def to_dict(config: dict[str, ConfigOption]) -> dict[str, str]: return {x: y.value for x, y in config.items()} @@ -74,26 +76,26 @@ class CoreClient: self.show_throughputs: tk.BooleanVar = tk.BooleanVar(value=False) # global service settings - self.services: Dict[str, Set[str]] = {} - self.config_services_groups: Dict[str, Set[str]] = {} - self.config_services: Dict[str, ConfigService] = {} + self.services: dict[str, set[str]] = {} + self.config_services_groups: dict[str, set[str]] = {} + self.config_services: dict[str, ConfigService] = {} # loaded configuration data - self.emane_models: List[str] = [] - self.servers: Dict[str, CoreServer] = {} - self.custom_nodes: Dict[str, NodeDraw] = {} - self.custom_observers: Dict[str, Observer] = {} + self.emane_models: list[str] = [] + self.servers: dict[str, CoreServer] = {} + self.custom_nodes: dict[str, NodeDraw] = {} + self.custom_observers: dict[str, Observer] = {} self.read_config() # helpers - self.iface_to_edge: Dict[Tuple[int, ...], CanvasEdge] = {} + self.iface_to_edge: dict[tuple[int, ...], CanvasEdge] = {} self.ifaces_manager: InterfaceManager = InterfaceManager(self.app) self.observer: Optional[str] = None # session data - self.mobility_players: Dict[int, MobilityPlayer] = {} - self.canvas_nodes: Dict[int, CanvasNode] = {} - self.links: Dict[str, CanvasEdge] = {} + self.mobility_players: dict[int, MobilityPlayer] = {} + self.canvas_nodes: dict[int, CanvasNode] = {} + self.links: dict[str, CanvasEdge] = {} self.handling_throughputs: Optional[grpc.Future] = None self.handling_cpu_usage: Optional[grpc.Future] = None self.handling_events: Optional[grpc.Future] = None @@ -372,7 +374,7 @@ class CoreClient: # existing session sessions = self.client.get_sessions() if session_id: - session_ids = set(x.id for x in sessions) + session_ids = {x.id for x in sessions} if session_id not in session_ids: self.app.show_error( "Join Session Error", @@ -401,7 +403,7 @@ class CoreClient: except grpc.RpcError as e: self.app.show_grpc_exception("Edit Node Error", e) - def get_links(self, definition: bool = False) -> List[Link]: + def get_links(self, definition: bool = False) -> list[Link]: if not definition: self.ifaces_manager.set_macs([x.link for x in self.links.values()]) links = [] @@ -419,7 +421,7 @@ class CoreClient: links.append(edge.asymmetric_link) return links - def start_session(self, definition: bool = False) -> Tuple[bool, List[str]]: + def start_session(self, definition: bool = False) -> tuple[bool, list[str]]: self.session.links = self.get_links(definition) self.session.metadata = self.get_metadata() self.session.servers.clear() @@ -461,7 +463,7 @@ class CoreClient: self.mobility_players[node.id] = mobility_player mobility_player.show() - def get_metadata(self) -> Dict[str, str]: + def get_metadata(self) -> dict[str, str]: # create canvas data canvas_config = self.app.manager.get_metadata() canvas_config = json.dumps(canvas_config) @@ -652,7 +654,7 @@ class CoreClient: self.session.nodes[node.id] = node return node - def deleted_canvas_nodes(self, canvas_nodes: List[CanvasNode]) -> None: + def deleted_canvas_nodes(self, canvas_nodes: list[CanvasNode]) -> None: """ remove the nodes selected by the user and anything related to that node such as link, configurations, interfaces @@ -680,7 +682,7 @@ class CoreClient: dst_iface_id = edge.link.iface2.id self.iface_to_edge[(dst_node.id, dst_iface_id)] = edge - def get_wlan_configs(self) -> List[Tuple[int, Dict[str, str]]]: + def get_wlan_configs(self) -> list[tuple[int, dict[str, str]]]: configs = [] for node in self.session.nodes.values(): if node.type != NodeType.WIRELESS_LAN: @@ -691,7 +693,7 @@ class CoreClient: configs.append((node.id, config)) return configs - def get_mobility_configs(self) -> List[Tuple[int, Dict[str, str]]]: + def get_mobility_configs(self) -> list[tuple[int, dict[str, str]]]: configs = [] for node in self.session.nodes.values(): if not nutils.is_mobility(node): @@ -702,7 +704,7 @@ class CoreClient: configs.append((node.id, config)) return configs - def get_emane_model_configs(self) -> List[EmaneModelConfig]: + def get_emane_model_configs(self) -> list[EmaneModelConfig]: configs = [] for node in self.session.nodes.values(): for key, config in node.emane_model_configs.items(): @@ -716,7 +718,7 @@ class CoreClient: configs.append(config) return configs - def get_service_configs(self) -> List[ServiceConfig]: + def get_service_configs(self) -> list[ServiceConfig]: configs = [] for node in self.session.nodes.values(): if not nutils.is_container(node): @@ -736,7 +738,7 @@ class CoreClient: configs.append(config) return configs - def get_service_file_configs(self) -> List[ServiceFileConfig]: + def get_service_file_configs(self) -> list[ServiceFileConfig]: configs = [] for node in self.session.nodes.values(): if not nutils.is_container(node): @@ -749,12 +751,17 @@ class CoreClient: configs.append(config) return configs - def get_config_service_rendered(self, node_id: int, name: str) -> Dict[str, str]: + def get_config_service_rendered(self, node_id: int, name: str) -> dict[str, str]: return self.client.get_config_service_rendered(self.session.id, node_id, name) + def get_config_service_defaults( + self, node_id: int, name: str + ) -> ConfigServiceDefaults: + return self.client.get_config_service_defaults(self.session.id, node_id, name) + def get_config_service_configs_proto( self, - ) -> List[configservices_pb2.ConfigServiceConfig]: + ) -> list[configservices_pb2.ConfigServiceConfig]: config_service_protos = [] for node in self.session.nodes.values(): if not nutils.is_container(node): @@ -776,7 +783,7 @@ class CoreClient: _, 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]: + def get_wlan_config(self, node_id: int) -> dict[str, ConfigOption]: config = self.client.get_wlan_config(self.session.id, node_id) logger.debug( "get wlan configuration from node %s, result configuration: %s", @@ -785,10 +792,10 @@ class CoreClient: ) return config - def get_wireless_config(self, node_id: int) -> Dict[str, ConfigOption]: + def get_wireless_config(self, node_id: int) -> dict[str, ConfigOption]: return self.client.get_wireless_config(self.session.id, node_id) - def get_mobility_config(self, node_id: int) -> Dict[str, ConfigOption]: + def get_mobility_config(self, node_id: int) -> dict[str, ConfigOption]: config = self.client.get_mobility_config(self.session.id, node_id) logger.debug( "get mobility config from node %s, result configuration: %s", @@ -799,7 +806,7 @@ class CoreClient: def get_emane_model_config( self, node_id: int, model: str, iface_id: int = None - ) -> Dict[str, ConfigOption]: + ) -> dict[str, ConfigOption]: if iface_id is None: iface_id = -1 config = self.client.get_emane_model_config( diff --git a/daemon/core/gui/data/icons/podman.png b/daemon/core/gui/data/icons/podman.png new file mode 100644 index 00000000..771e04a0 Binary files /dev/null and b/daemon/core/gui/data/icons/podman.png differ diff --git a/daemon/core/gui/dialogs/alerts.py b/daemon/core/gui/dialogs/alerts.py index 9e430214..b13f0797 100644 --- a/daemon/core/gui/dialogs/alerts.py +++ b/daemon/core/gui/dialogs/alerts.py @@ -3,7 +3,7 @@ check engine light """ import tkinter as tk from tkinter import ttk -from typing import TYPE_CHECKING, Dict, Optional +from typing import TYPE_CHECKING, Optional from core.api.grpc.wrappers import ExceptionEvent, ExceptionLevel from core.gui.dialogs.dialog import Dialog @@ -19,7 +19,7 @@ class AlertsDialog(Dialog): super().__init__(app, "Alerts") self.tree: Optional[ttk.Treeview] = None self.codetext: Optional[CodeText] = None - self.alarm_map: Dict[int, ExceptionEvent] = {} + self.alarm_map: dict[int, ExceptionEvent] = {} self.draw() def draw(self) -> None: diff --git a/daemon/core/gui/dialogs/canvaswallpaper.py b/daemon/core/gui/dialogs/canvaswallpaper.py index 0ef294c7..5b0f27b3 100644 --- a/daemon/core/gui/dialogs/canvaswallpaper.py +++ b/daemon/core/gui/dialogs/canvaswallpaper.py @@ -4,7 +4,7 @@ set wallpaper import logging import tkinter as tk from tkinter import ttk -from typing import TYPE_CHECKING, List, Optional +from typing import TYPE_CHECKING, Optional from core.gui import images from core.gui.appconfig import BACKGROUNDS_PATH @@ -32,7 +32,7 @@ class CanvasWallpaperDialog(Dialog): ) self.filename: tk.StringVar = tk.StringVar(value=self.canvas.wallpaper_file) self.image_label: Optional[ttk.Label] = None - self.options: List[ttk.Radiobutton] = [] + self.options: list[ttk.Radiobutton] = [] self.draw() def draw(self) -> None: diff --git a/daemon/core/gui/dialogs/colorpicker.py b/daemon/core/gui/dialogs/colorpicker.py index a2f131d4..a27b1698 100644 --- a/daemon/core/gui/dialogs/colorpicker.py +++ b/daemon/core/gui/dialogs/colorpicker.py @@ -3,7 +3,7 @@ custom color picker """ import tkinter as tk from tkinter import ttk -from typing import TYPE_CHECKING, Optional, Tuple +from typing import TYPE_CHECKING, Optional from core.gui import validation from core.gui.dialogs.dialog import Dialog @@ -13,6 +13,36 @@ if TYPE_CHECKING: from core.gui.app import Application +def get_rgb(red: int, green: int, blue: int) -> str: + """ + Convert rgb integers to an rgb hex code (#). + + :param red: red value + :param green: green value + :param blue: blue value + :return: rgb hex code + """ + return f"#{red:02x}{green:02x}{blue:02x}" + + +def get_rgb_values(hex_code: str) -> tuple[int, int, int]: + """ + Convert a valid rgb hex code (#) to rgb integers. + + :param hex_code: valid rgb hex code + :return: a tuple of red, blue, and green values + """ + if len(hex_code) == 4: + red = hex_code[1] + green = hex_code[2] + blue = hex_code[3] + else: + red = hex_code[1:3] + green = hex_code[3:5] + blue = hex_code[5:] + return int(red, 16), int(green, 16), int(blue, 16) + + class ColorPickerDialog(Dialog): def __init__( self, master: tk.BaseWidget, app: "Application", initcolor: str = "#000000" @@ -27,7 +57,7 @@ class ColorPickerDialog(Dialog): self.blue_label: Optional[ttk.Label] = None self.display: Optional[tk.Frame] = None self.color: str = initcolor - red, green, blue = self.get_rgb(initcolor) + red, green, blue = get_rgb_values(initcolor) self.red: tk.IntVar = tk.IntVar(value=red) self.blue: tk.IntVar = tk.IntVar(value=blue) self.green: tk.IntVar = tk.IntVar(value=green) @@ -66,7 +96,7 @@ class ColorPickerDialog(Dialog): ) scale.grid(row=0, column=2, sticky=tk.EW, padx=PADX) self.red_label = ttk.Label( - frame, background="#%02x%02x%02x" % (self.red.get(), 0, 0), width=5 + frame, background=get_rgb(self.red.get(), 0, 0), width=5 ) self.red_label.grid(row=0, column=3, sticky=tk.EW) @@ -89,7 +119,7 @@ class ColorPickerDialog(Dialog): ) scale.grid(row=0, column=2, sticky=tk.EW, padx=PADX) self.green_label = ttk.Label( - frame, background="#%02x%02x%02x" % (0, self.green.get(), 0), width=5 + frame, background=get_rgb(0, self.green.get(), 0), width=5 ) self.green_label.grid(row=0, column=3, sticky=tk.EW) @@ -112,7 +142,7 @@ class ColorPickerDialog(Dialog): ) scale.grid(row=0, column=2, sticky=tk.EW, padx=PADX) self.blue_label = ttk.Label( - frame, background="#%02x%02x%02x" % (0, 0, self.blue.get()), width=5 + frame, background=get_rgb(0, 0, self.blue.get()), width=5 ) self.blue_label.grid(row=0, column=3, sticky=tk.EW) @@ -150,39 +180,27 @@ class ColorPickerDialog(Dialog): self.color = self.hex.get() self.destroy() - def get_hex(self) -> str: - """ - convert current RGB values into hex color - """ - red = self.red_entry.get() - blue = self.blue_entry.get() - green = self.green_entry.get() - return "#%02x%02x%02x" % (int(red), int(green), int(blue)) - def current_focus(self, focus: str) -> None: self.focus = focus def update_color(self, arg1=None, arg2=None, arg3=None) -> None: if self.focus == "rgb": - red = self.red_entry.get() - blue = self.blue_entry.get() - green = self.green_entry.get() + red = int(self.red_entry.get() or 0) + blue = int(self.blue_entry.get() or 0) + green = int(self.green_entry.get() or 0) self.set_scale(red, green, blue) - if red and blue and green: - hex_code = "#%02x%02x%02x" % (int(red), int(green), int(blue)) - self.hex.set(hex_code) - self.display.config(background=hex_code) - self.set_label(red, green, blue) + hex_code = get_rgb(red, green, blue) + self.hex.set(hex_code) + self.display.config(background=hex_code) + self.set_label(red, green, blue) elif self.focus == "hex": hex_code = self.hex.get() if len(hex_code) == 4 or len(hex_code) == 7: - red, green, blue = self.get_rgb(hex_code) - else: - return - self.set_entry(red, green, blue) - self.set_scale(red, green, blue) - self.display.config(background=hex_code) - self.set_label(str(red), str(green), str(blue)) + red, green, blue = get_rgb_values(hex_code) + self.set_entry(red, green, blue) + self.set_scale(red, green, blue) + self.display.config(background=hex_code) + self.set_label(red, green, blue) def scale_callback(self, var: tk.IntVar, color_var: tk.IntVar) -> None: color_var.set(var.get()) @@ -199,21 +217,7 @@ class ColorPickerDialog(Dialog): self.green.set(green) self.blue.set(blue) - def set_label(self, red: str, green: str, blue: str) -> None: - self.red_label.configure(background="#%02x%02x%02x" % (int(red), 0, 0)) - self.green_label.configure(background="#%02x%02x%02x" % (0, int(green), 0)) - self.blue_label.configure(background="#%02x%02x%02x" % (0, 0, int(blue))) - - def get_rgb(self, hex_code: str) -> Tuple[int, int, int]: - """ - convert a valid hex code to RGB values - """ - if len(hex_code) == 4: - red = hex_code[1] - green = hex_code[2] - blue = hex_code[3] - else: - red = hex_code[1:3] - green = hex_code[3:5] - blue = hex_code[5:] - return int(red, 16), int(green, 16), int(blue, 16) + def set_label(self, red: int, green: int, blue: int) -> None: + self.red_label.configure(background=get_rgb(red, 0, 0)) + self.green_label.configure(background=get_rgb(0, green, 0)) + self.blue_label.configure(background=get_rgb(0, 0, blue)) diff --git a/daemon/core/gui/dialogs/configserviceconfig.py b/daemon/core/gui/dialogs/configserviceconfig.py index 62c0bfc5..0e873a79 100644 --- a/daemon/core/gui/dialogs/configserviceconfig.py +++ b/daemon/core/gui/dialogs/configserviceconfig.py @@ -4,7 +4,7 @@ Service configuration dialog import logging import tkinter as tk from tkinter import ttk -from typing import TYPE_CHECKING, Dict, List, Optional, Set +from typing import TYPE_CHECKING, Optional import grpc @@ -35,22 +35,22 @@ class ConfigServiceConfigDialog(Dialog): self.node: Node = node self.service_name: str = service_name self.radiovar: tk.IntVar = tk.IntVar(value=2) - self.directories: List[str] = [] - self.templates: List[str] = [] - self.rendered: Dict[str, str] = {} - self.dependencies: List[str] = [] - self.executables: List[str] = [] - self.startup_commands: List[str] = [] - self.validation_commands: List[str] = [] - self.shutdown_commands: List[str] = [] - self.default_startup: List[str] = [] - self.default_validate: List[str] = [] - self.default_shutdown: List[str] = [] + self.directories: list[str] = [] + self.templates: list[str] = [] + self.rendered: dict[str, str] = {} + self.dependencies: list[str] = [] + self.executables: list[str] = [] + self.startup_commands: list[str] = [] + self.validation_commands: list[str] = [] + self.shutdown_commands: list[str] = [] + self.default_startup: list[str] = [] + self.default_validate: list[str] = [] + self.default_shutdown: list[str] = [] self.validation_mode: Optional[ServiceValidationMode] = None self.validation_time: Optional[int] = None self.validation_period: tk.DoubleVar = tk.DoubleVar() - self.modes: List[str] = [] - self.mode_configs: Dict[str, Dict[str, str]] = {} + self.modes: list[str] = [] + self.mode_configs: dict[str, dict[str, str]] = {} self.notebook: Optional[ttk.Notebook] = None self.templates_combobox: Optional[ttk.Combobox] = None self.modes_combobox: Optional[ttk.Combobox] = None @@ -62,12 +62,12 @@ class ConfigServiceConfigDialog(Dialog): self.template_text: Optional[CodeText] = None self.rendered_text: Optional[CodeText] = None self.validation_period_entry: Optional[ttk.Entry] = None - self.original_service_files: Dict[str, str] = {} - self.temp_service_files: Dict[str, str] = {} - self.modified_files: Set[str] = set() + self.original_service_files: dict[str, str] = {} + self.temp_service_files: dict[str, str] = {} + self.modified_files: set[str] = set() self.config_frame: Optional[ConfigFrame] = None - self.default_config: Dict[str, str] = {} - self.config: Dict[str, ConfigOption] = {} + self.default_config: dict[str, str] = {} + self.config: dict[str, ConfigOption] = {} self.has_error: bool = False self.load() if not self.has_error: @@ -87,7 +87,9 @@ class ConfigServiceConfigDialog(Dialog): self.validation_mode = service.validation_mode self.validation_time = service.validation_timer self.validation_period.set(service.validation_period) - defaults = self.core.client.get_config_service_defaults(self.service_name) + defaults = self.core.get_config_service_defaults( + self.node.id, self.service_name + ) self.original_service_files = defaults.templates self.temp_service_files = dict(self.original_service_files) self.modes = sorted(defaults.modes) @@ -405,7 +407,7 @@ class ConfigServiceConfigDialog(Dialog): pass def append_commands( - self, commands: List[str], listbox: tk.Listbox, to_add: List[str] + self, commands: list[str], listbox: tk.Listbox, to_add: list[str] ) -> None: for cmd in to_add: commands.append(cmd) diff --git a/daemon/core/gui/dialogs/copyserviceconfig.py b/daemon/core/gui/dialogs/copyserviceconfig.py index b205e175..6b2f4927 100644 --- a/daemon/core/gui/dialogs/copyserviceconfig.py +++ b/daemon/core/gui/dialogs/copyserviceconfig.py @@ -4,7 +4,7 @@ copy service config dialog import tkinter as tk from tkinter import ttk -from typing import TYPE_CHECKING, Dict, Optional +from typing import TYPE_CHECKING, Optional from core.gui.dialogs.dialog import Dialog from core.gui.themes import PADX, PADY @@ -29,7 +29,7 @@ class CopyServiceConfigDialog(Dialog): self.service: str = service self.file_name: str = file_name self.listbox: Optional[tk.Listbox] = None - self.nodes: Dict[str, int] = {} + self.nodes: dict[str, int] = {} self.draw() def draw(self) -> None: diff --git a/daemon/core/gui/dialogs/customnodes.py b/daemon/core/gui/dialogs/customnodes.py index d6dac44a..ea4421e8 100644 --- a/daemon/core/gui/dialogs/customnodes.py +++ b/daemon/core/gui/dialogs/customnodes.py @@ -2,7 +2,7 @@ import logging import tkinter as tk from pathlib import Path from tkinter import ttk -from typing import TYPE_CHECKING, Optional, Set +from typing import TYPE_CHECKING, Optional from PIL.ImageTk import PhotoImage @@ -21,13 +21,13 @@ if TYPE_CHECKING: class ServicesSelectDialog(Dialog): def __init__( - self, master: tk.BaseWidget, app: "Application", current_services: Set[str] + self, master: tk.BaseWidget, app: "Application", current_services: set[str] ) -> None: super().__init__(app, "Node Config Services", master=master) self.groups: Optional[ListboxScroll] = None self.services: Optional[CheckboxList] = None self.current: Optional[ListboxScroll] = None - self.current_services: Set[str] = current_services + self.current_services: set[str] = current_services self.draw() def draw(self) -> None: @@ -114,7 +114,7 @@ class CustomNodesDialog(Dialog): self.image_button: Optional[ttk.Button] = None self.image: Optional[PhotoImage] = None self.image_file: Optional[str] = None - self.services: Set[str] = set() + self.services: set[str] = set() self.selected: Optional[str] = None self.selected_index: Optional[int] = None self.draw() diff --git a/daemon/core/gui/dialogs/emaneconfig.py b/daemon/core/gui/dialogs/emaneconfig.py index a39720d8..00eda694 100644 --- a/daemon/core/gui/dialogs/emaneconfig.py +++ b/daemon/core/gui/dialogs/emaneconfig.py @@ -4,7 +4,7 @@ emane configuration import tkinter as tk import webbrowser from tkinter import ttk -from typing import TYPE_CHECKING, Dict, List, Optional +from typing import TYPE_CHECKING, Optional import grpc @@ -43,7 +43,7 @@ class EmaneModelDialog(Dialog): config = self.app.core.get_emane_model_config( self.node.id, self.model, self.iface_id ) - self.config: Dict[str, ConfigOption] = config + self.config: dict[str, ConfigOption] = config self.draw() except grpc.RpcError as e: self.app.show_grpc_exception("Get EMANE Config Error", e) @@ -82,7 +82,7 @@ class EmaneConfigDialog(Dialog): self.node: Node = node self.radiovar: tk.IntVar = tk.IntVar() self.radiovar.set(1) - self.emane_models: List[str] = [ + self.emane_models: list[str] = [ x.split("_")[1] for x in self.app.core.emane_models ] model = self.node.emane.split("_")[1] diff --git a/daemon/core/gui/dialogs/hooks.py b/daemon/core/gui/dialogs/hooks.py index 474dc2d0..391df18f 100644 --- a/daemon/core/gui/dialogs/hooks.py +++ b/daemon/core/gui/dialogs/hooks.py @@ -1,5 +1,5 @@ import tkinter as tk -from tkinter import ttk +from tkinter import messagebox, ttk from typing import TYPE_CHECKING, Optional from core.api.grpc.wrappers import Hook, SessionState @@ -91,6 +91,13 @@ class HookDialog(Dialog): self.hook.file = file_name self.hook.data = data else: + if file_name in self.app.core.session.hooks: + messagebox.showerror( + "Hook Error", + f"Hook {file_name} already exists!", + parent=self.master, + ) + return self.hook = Hook(state=state, file=file_name, data=data) self.destroy() diff --git a/daemon/core/gui/dialogs/ipdialog.py b/daemon/core/gui/dialogs/ipdialog.py index 68b5ab36..99388548 100644 --- a/daemon/core/gui/dialogs/ipdialog.py +++ b/daemon/core/gui/dialogs/ipdialog.py @@ -1,6 +1,6 @@ import tkinter as tk from tkinter import messagebox, ttk -from typing import TYPE_CHECKING, List, Optional +from typing import TYPE_CHECKING, Optional import netaddr @@ -17,8 +17,8 @@ class IpConfigDialog(Dialog): super().__init__(app, "IP Configuration") self.ip4: str = self.app.guiconfig.ips.ip4 self.ip6: str = self.app.guiconfig.ips.ip6 - self.ip4s: List[str] = self.app.guiconfig.ips.ip4s - self.ip6s: List[str] = self.app.guiconfig.ips.ip6s + self.ip4s: list[str] = self.app.guiconfig.ips.ip4s + self.ip6s: list[str] = self.app.guiconfig.ips.ip6s self.ip4_entry: Optional[ttk.Entry] = None self.ip4_listbox: Optional[ListboxScroll] = None self.ip6_entry: Optional[ttk.Entry] = None diff --git a/daemon/core/gui/dialogs/mobilityconfig.py b/daemon/core/gui/dialogs/mobilityconfig.py index b22c5fef..6a2991aa 100644 --- a/daemon/core/gui/dialogs/mobilityconfig.py +++ b/daemon/core/gui/dialogs/mobilityconfig.py @@ -3,7 +3,7 @@ mobility configuration """ import tkinter as tk from tkinter import ttk -from typing import TYPE_CHECKING, Dict, Optional +from typing import TYPE_CHECKING, Optional import grpc @@ -26,7 +26,7 @@ class MobilityConfigDialog(Dialog): config = self.node.mobility_config if not config: config = self.app.core.get_mobility_config(self.node.id) - self.config: Dict[str, ConfigOption] = config + self.config: dict[str, ConfigOption] = config self.draw() except grpc.RpcError as e: self.app.show_grpc_exception("Get Mobility Config Error", e) diff --git a/daemon/core/gui/dialogs/nodeconfig.py b/daemon/core/gui/dialogs/nodeconfig.py index c9ca67f5..162696d4 100644 --- a/daemon/core/gui/dialogs/nodeconfig.py +++ b/daemon/core/gui/dialogs/nodeconfig.py @@ -2,7 +2,7 @@ import logging import tkinter as tk from functools import partial from tkinter import messagebox, ttk -from typing import TYPE_CHECKING, Dict, Optional +from typing import TYPE_CHECKING, Optional import netaddr from PIL.ImageTk import PhotoImage @@ -190,7 +190,7 @@ class NodeConfigDialog(Dialog): if self.node.server: server = self.node.server self.server: tk.StringVar = tk.StringVar(value=server) - self.ifaces: Dict[int, InterfaceData] = {} + self.ifaces: dict[int, InterfaceData] = {} self.draw() def draw(self) -> None: diff --git a/daemon/core/gui/dialogs/nodeconfigservice.py b/daemon/core/gui/dialogs/nodeconfigservice.py index cddbdb03..ce718080 100644 --- a/daemon/core/gui/dialogs/nodeconfigservice.py +++ b/daemon/core/gui/dialogs/nodeconfigservice.py @@ -4,7 +4,7 @@ core node services import logging import tkinter as tk from tkinter import messagebox, ttk -from typing import TYPE_CHECKING, Optional, Set +from typing import TYPE_CHECKING, Optional from core.api.grpc.wrappers import Node from core.gui.dialogs.configserviceconfig import ConfigServiceConfigDialog @@ -20,7 +20,7 @@ if TYPE_CHECKING: class NodeConfigServiceDialog(Dialog): def __init__( - self, app: "Application", node: Node, services: Set[str] = None + self, app: "Application", node: Node, services: set[str] = None ) -> None: title = f"{node.name} Config Services" super().__init__(app, title) @@ -30,7 +30,7 @@ class NodeConfigServiceDialog(Dialog): self.current: Optional[ListboxScroll] = None if services is None: services = set(node.config_services) - self.current_services: Set[str] = services + self.current_services: set[str] = services self.protocol("WM_DELETE_WINDOW", self.click_cancel) self.draw() diff --git a/daemon/core/gui/dialogs/nodeservice.py b/daemon/core/gui/dialogs/nodeservice.py index 431d5c3d..66e83fa4 100644 --- a/daemon/core/gui/dialogs/nodeservice.py +++ b/daemon/core/gui/dialogs/nodeservice.py @@ -3,7 +3,7 @@ core node services """ import tkinter as tk from tkinter import messagebox, ttk -from typing import TYPE_CHECKING, Optional, Set +from typing import TYPE_CHECKING, Optional from core.api.grpc.wrappers import Node from core.gui.dialogs.dialog import Dialog @@ -24,7 +24,7 @@ class NodeServiceDialog(Dialog): self.services: Optional[CheckboxList] = None self.current: Optional[ListboxScroll] = None services = set(node.services) - self.current_services: Set[str] = services + self.current_services: set[str] = services self.protocol("WM_DELETE_WINDOW", self.click_cancel) self.draw() diff --git a/daemon/core/gui/dialogs/runtool.py b/daemon/core/gui/dialogs/runtool.py index 494020e3..75789893 100644 --- a/daemon/core/gui/dialogs/runtool.py +++ b/daemon/core/gui/dialogs/runtool.py @@ -1,6 +1,6 @@ import tkinter as tk from tkinter import ttk -from typing import TYPE_CHECKING, Dict, Optional +from typing import TYPE_CHECKING, Optional from core.gui import nodeutils as nutils from core.gui.dialogs.dialog import Dialog @@ -17,7 +17,7 @@ class RunToolDialog(Dialog): self.cmd: tk.StringVar = tk.StringVar(value="ps ax") self.result: Optional[CodeText] = None self.node_list: Optional[ListboxScroll] = None - self.executable_nodes: Dict[str, int] = {} + self.executable_nodes: dict[str, int] = {} self.store_nodes() self.draw() diff --git a/daemon/core/gui/dialogs/serviceconfig.py b/daemon/core/gui/dialogs/serviceconfig.py index 6f6b0d24..5eec7faf 100644 --- a/daemon/core/gui/dialogs/serviceconfig.py +++ b/daemon/core/gui/dialogs/serviceconfig.py @@ -2,7 +2,7 @@ import logging import tkinter as tk from pathlib import Path from tkinter import filedialog, messagebox, ttk -from typing import TYPE_CHECKING, Dict, List, Optional, Set, Tuple +from typing import TYPE_CHECKING, Optional import grpc from PIL.ImageTk import PhotoImage @@ -35,21 +35,21 @@ class ServiceConfigDialog(Dialog): self.service_name: str = service_name self.radiovar: tk.IntVar = tk.IntVar(value=2) self.metadata: str = "" - self.filenames: List[str] = [] - self.dependencies: List[str] = [] - self.executables: List[str] = [] - self.startup_commands: List[str] = [] - self.validation_commands: List[str] = [] - self.shutdown_commands: List[str] = [] - self.default_startup: List[str] = [] - self.default_validate: List[str] = [] - self.default_shutdown: List[str] = [] + self.filenames: list[str] = [] + self.dependencies: list[str] = [] + self.executables: list[str] = [] + self.startup_commands: list[str] = [] + self.validation_commands: list[str] = [] + self.shutdown_commands: list[str] = [] + self.default_startup: list[str] = [] + self.default_validate: list[str] = [] + self.default_shutdown: list[str] = [] self.validation_mode: Optional[ServiceValidationMode] = None self.validation_time: Optional[int] = None self.validation_period: Optional[float] = None self.directory_entry: Optional[ttk.Entry] = None - self.default_directories: List[str] = [] - self.temp_directories: List[str] = [] + self.default_directories: list[str] = [] + self.temp_directories: list[str] = [] self.documentnew_img: PhotoImage = self.app.get_enum_icon( ImageEnum.DOCUMENTNEW, width=ICON_SIZE ) @@ -67,10 +67,10 @@ class ServiceConfigDialog(Dialog): self.validation_mode_entry: Optional[ttk.Entry] = None self.service_file_data: Optional[CodeText] = None self.validation_period_entry: Optional[ttk.Entry] = None - self.original_service_files: Dict[str, str] = {} + self.original_service_files: dict[str, str] = {} self.default_config: Optional[NodeServiceData] = None - self.temp_service_files: Dict[str, str] = {} - self.modified_files: Set[str] = set() + self.temp_service_files: dict[str, str] = {} + self.modified_files: set[str] = set() self.has_error: bool = False self.load() if not self.has_error: @@ -558,13 +558,13 @@ class ServiceConfigDialog(Dialog): @classmethod def append_commands( - cls, commands: List[str], listbox: tk.Listbox, to_add: List[str] + cls, commands: list[str], listbox: tk.Listbox, to_add: list[str] ) -> None: for cmd in to_add: commands.append(cmd) listbox.insert(tk.END, cmd) - def get_commands(self) -> Tuple[List[str], List[str], List[str]]: + def get_commands(self) -> tuple[list[str], list[str], list[str]]: startup = self.startup_commands_listbox.get(0, "end") shutdown = self.shutdown_commands_listbox.get(0, "end") validate = self.validate_commands_listbox.get(0, "end") diff --git a/daemon/core/gui/dialogs/sessions.py b/daemon/core/gui/dialogs/sessions.py index deca7404..3ca4fa63 100644 --- a/daemon/core/gui/dialogs/sessions.py +++ b/daemon/core/gui/dialogs/sessions.py @@ -1,7 +1,7 @@ import logging import tkinter as tk from tkinter import messagebox, ttk -from typing import TYPE_CHECKING, List, Optional +from typing import TYPE_CHECKING, Optional import grpc @@ -30,7 +30,7 @@ class SessionsDialog(Dialog): self.protocol("WM_DELETE_WINDOW", self.on_closing) self.draw() - def get_sessions(self) -> List[SessionSummary]: + def get_sessions(self) -> list[SessionSummary]: try: sessions = self.app.core.client.get_sessions() logger.info("sessions: %s", sessions) diff --git a/daemon/core/gui/dialogs/shapemod.py b/daemon/core/gui/dialogs/shapemod.py index d0e200ee..db19ff1a 100644 --- a/daemon/core/gui/dialogs/shapemod.py +++ b/daemon/core/gui/dialogs/shapemod.py @@ -3,7 +3,7 @@ shape input dialog """ import tkinter as tk from tkinter import font, ttk -from typing import TYPE_CHECKING, List, Optional, Union +from typing import TYPE_CHECKING, Optional, Union from core.gui.dialogs.colorpicker import ColorPickerDialog from core.gui.dialogs.dialog import Dialog @@ -16,8 +16,8 @@ if TYPE_CHECKING: from core.gui.graph.graph import CanvasGraph from core.gui.graph.shape import Shape -FONT_SIZES: List[int] = [8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72] -BORDER_WIDTH: List[int] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] +FONT_SIZES: list[int] = [8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72] +BORDER_WIDTH: list[int] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] class ShapeDialog(Dialog): @@ -168,7 +168,7 @@ class ShapeDialog(Dialog): self.add_text() self.destroy() - def make_font(self) -> List[Union[int, str]]: + def make_font(self) -> list[Union[int, str]]: """ create font for text or shape label """ diff --git a/daemon/core/gui/dialogs/wirelessconfig.py b/daemon/core/gui/dialogs/wirelessconfig.py index 97e37b5f..b04fbd2c 100644 --- a/daemon/core/gui/dialogs/wirelessconfig.py +++ b/daemon/core/gui/dialogs/wirelessconfig.py @@ -1,6 +1,6 @@ import tkinter as tk from tkinter import ttk -from typing import TYPE_CHECKING, Dict, Optional +from typing import TYPE_CHECKING, Optional import grpc @@ -19,12 +19,12 @@ class WirelessConfigDialog(Dialog): super().__init__(app, f"Wireless Configuration - {canvas_node.core_node.name}") self.node: Node = canvas_node.core_node self.config_frame: Optional[ConfigFrame] = None - self.config: Dict[str, ConfigOption] = {} + self.config: dict[str, ConfigOption] = {} try: config = self.node.wireless_config if not config: config = self.app.core.get_wireless_config(self.node.id) - self.config: Dict[str, ConfigOption] = config + self.config: dict[str, ConfigOption] = config self.draw() except grpc.RpcError as e: self.app.show_grpc_exception("Wireless Config Error", e) diff --git a/daemon/core/gui/dialogs/wlanconfig.py b/daemon/core/gui/dialogs/wlanconfig.py index 237ca8a5..c382d3c8 100644 --- a/daemon/core/gui/dialogs/wlanconfig.py +++ b/daemon/core/gui/dialogs/wlanconfig.py @@ -1,6 +1,6 @@ import tkinter as tk from tkinter import ttk -from typing import TYPE_CHECKING, Dict, Optional +from typing import TYPE_CHECKING, Optional import grpc @@ -27,13 +27,13 @@ class WlanConfigDialog(Dialog): self.config_frame: Optional[ConfigFrame] = None self.range_entry: Optional[ttk.Entry] = None self.has_error: bool = False - self.ranges: Dict[int, int] = {} + self.ranges: dict[int, int] = {} self.positive_int: int = self.app.master.register(self.validate_and_update) try: config = self.node.wlan_config if not config: config = self.app.core.get_wlan_config(self.node.id) - self.config: Dict[str, ConfigOption] = config + self.config: dict[str, ConfigOption] = config self.init_draw_range() self.draw() except grpc.RpcError as e: diff --git a/daemon/core/gui/graph/edges.py b/daemon/core/gui/graph/edges.py index 8bb97962..e5a4c97b 100644 --- a/daemon/core/gui/graph/edges.py +++ b/daemon/core/gui/graph/edges.py @@ -2,10 +2,10 @@ import functools import logging import math import tkinter as tk -from typing import TYPE_CHECKING, Optional, Tuple, Union +from typing import TYPE_CHECKING, Optional, Union from core.api.grpc.wrappers import Interface, Link -from core.gui import themes +from core.gui import nodeutils, themes from core.gui.dialogs.linkconfig import LinkConfigurationDialog from core.gui.frames.link import EdgeInfoFrame, WirelessEdgeInfoFrame from core.gui.graph import tags @@ -54,7 +54,7 @@ def create_edge_token(link: Link) -> str: def node_label_positions( src_x: int, src_y: int, dst_x: int, dst_y: int -) -> Tuple[Tuple[float, float], Tuple[float, float]]: +) -> tuple[tuple[float, float], tuple[float, float]]: v_x, v_y = dst_x - src_x, dst_y - src_y v_len = math.sqrt(v_x**2 + v_y**2) if v_len == 0: @@ -128,8 +128,8 @@ class Edge: return self.width * self.app.app_scale def _get_arcpoint( - self, src_pos: Tuple[float, float], dst_pos: Tuple[float, float] - ) -> Tuple[float, float]: + self, src_pos: tuple[float, float], dst_pos: tuple[float, float] + ) -> tuple[float, float]: src_x, src_y = src_pos dst_x, dst_y = dst_pos mp_x = (src_x + dst_x) / 2 @@ -317,7 +317,7 @@ class Edge: if self.dst_label2: self.dst.canvas.itemconfig(self.dst_label2, text=text) - def drawing(self, pos: Tuple[float, float]) -> None: + def drawing(self, pos: tuple[float, float]) -> None: src_x, src_y, _, _, _, _ = self.src.canvas.coords(self.id) src_pos = src_x, src_y self.moved(src_pos, pos) @@ -368,7 +368,7 @@ class Edge: dst_pos = dst_x, dst_y self.moved(self.src.position(), dst_pos) - def moved(self, src_pos: Tuple[float, float], dst_pos: Tuple[float, float]) -> None: + def moved(self, src_pos: tuple[float, float], dst_pos: tuple[float, float]) -> None: arc_pos = self._get_arcpoint(src_pos, dst_pos) self.src.canvas.coords(self.id, *src_pos, *arc_pos, *dst_pos) if self.middle_label: @@ -381,7 +381,7 @@ class Edge: self.src.canvas.coords(self.dst_label, *dst_pos) def moved2( - self, src_pos: Tuple[float, float], dst_pos: Tuple[float, float] + self, src_pos: tuple[float, float], dst_pos: tuple[float, float] ) -> None: arc_pos = self._get_arcpoint(src_pos, dst_pos) self.dst.canvas.coords(self.id2, *src_pos, *arc_pos, *dst_pos) @@ -568,7 +568,7 @@ class CanvasEdge(Edge): label += f"{iface.ip6}/{iface.ip6_mask}" return label - def create_node_labels(self) -> Tuple[str, str]: + def create_node_labels(self) -> tuple[str, str]: label1 = None if self.link.iface1: label1 = self.iface_label(self.link.iface1) @@ -638,10 +638,10 @@ class CanvasEdge(Edge): self.check_wireless() if link is None: link = self.app.core.ifaces_manager.create_link(self) - if link.iface1: + if link.iface1 and not nodeutils.is_rj45(self.src.core_node): iface1 = link.iface1 self.src.ifaces[iface1.id] = iface1 - if link.iface2: + if link.iface2 and not nodeutils.is_rj45(self.dst.core_node): iface2 = link.iface2 self.dst.ifaces[iface2.id] = iface2 self.token = create_edge_token(link) @@ -751,9 +751,9 @@ class CanvasEdge(Edge): self.src.edges.discard(self) if self.dst: self.dst.edges.discard(self) - if self.link.iface1: + if self.link.iface1 and not nodeutils.is_rj45(self.src.core_node): del self.src.ifaces[self.link.iface1.id] - if self.link.iface2: + if self.link.iface2 and not nodeutils.is_rj45(self.dst.core_node): del self.dst.ifaces[self.link.iface2.id] if self.src.is_wireless(): self.dst.delete_antenna() diff --git a/daemon/core/gui/graph/graph.py b/daemon/core/gui/graph/graph.py index e3225a4d..1a701239 100644 --- a/daemon/core/gui/graph/graph.py +++ b/daemon/core/gui/graph/graph.py @@ -2,7 +2,7 @@ import logging import tkinter as tk from copy import deepcopy from pathlib import Path -from typing import TYPE_CHECKING, Any, Dict, List, Optional, Set, Tuple +from typing import TYPE_CHECKING, Any, Optional from PIL import Image from PIL.ImageTk import PhotoImage @@ -27,8 +27,8 @@ if TYPE_CHECKING: ZOOM_IN: float = 1.1 ZOOM_OUT: float = 0.9 -MOVE_NODE_MODES: Set[GraphMode] = {GraphMode.NODE, GraphMode.SELECT} -MOVE_SHAPE_MODES: Set[GraphMode] = {GraphMode.ANNOTATION, GraphMode.SELECT} +MOVE_NODE_MODES: set[GraphMode] = {GraphMode.NODE, GraphMode.SELECT} +MOVE_SHAPE_MODES: set[GraphMode] = {GraphMode.ANNOTATION, GraphMode.SELECT} BACKGROUND_COLOR: str = "#cccccc" @@ -40,32 +40,32 @@ class CanvasGraph(tk.Canvas): manager: "CanvasManager", core: "CoreClient", _id: int, - dimensions: Tuple[int, int], + dimensions: tuple[int, int], ) -> None: super().__init__(master, highlightthickness=0, background=BACKGROUND_COLOR) self.id: int = _id self.app: "Application" = app self.manager: "CanvasManager" = manager self.core: "CoreClient" = core - self.selection: Dict[int, int] = {} + self.selection: dict[int, int] = {} self.select_box: Optional[Shape] = None self.selected: Optional[int] = None - self.nodes: Dict[int, CanvasNode] = {} - self.shadow_nodes: Dict[int, ShadowNode] = {} - self.shapes: Dict[int, Shape] = {} - self.shadow_core_nodes: Dict[int, ShadowNode] = {} + self.nodes: dict[int, CanvasNode] = {} + self.shadow_nodes: dict[int, ShadowNode] = {} + self.shapes: dict[int, Shape] = {} + self.shadow_core_nodes: dict[int, ShadowNode] = {} # map wireless/EMANE node to the set of MDRs connected to that node - self.wireless_network: Dict[int, Set[int]] = {} + self.wireless_network: dict[int, set[int]] = {} self.drawing_edge: Optional[CanvasEdge] = None self.rect: Optional[int] = None self.shape_drawing: bool = False - self.current_dimensions: Tuple[int, int] = dimensions + self.current_dimensions: tuple[int, int] = dimensions self.ratio: float = 1.0 - self.offset: Tuple[int, int] = (0, 0) - self.cursor: Tuple[int, int] = (0, 0) - self.to_copy: List[CanvasNode] = [] + self.offset: tuple[int, int] = (0, 0) + self.cursor: tuple[int, int] = (0, 0) + self.to_copy: list[CanvasNode] = [] # background related self.wallpaper_id: Optional[int] = None @@ -82,7 +82,7 @@ class CanvasGraph(tk.Canvas): self.draw_canvas() self.draw_grid() - def draw_canvas(self, dimensions: Tuple[int, int] = None) -> None: + def draw_canvas(self, dimensions: tuple[int, int] = None) -> None: if self.rect is not None: self.delete(self.rect) if not dimensions: @@ -126,23 +126,23 @@ class CanvasGraph(tk.Canvas): shadow_node = ShadowNode(self.app, self, node) return shadow_node - def get_actual_coords(self, x: float, y: float) -> Tuple[float, float]: + def get_actual_coords(self, x: float, y: float) -> tuple[float, float]: actual_x = (x - self.offset[0]) / self.ratio actual_y = (y - self.offset[1]) / self.ratio return actual_x, actual_y - def get_scaled_coords(self, x: float, y: float) -> Tuple[float, float]: + def get_scaled_coords(self, x: float, y: float) -> tuple[float, float]: scaled_x = (x * self.ratio) + self.offset[0] scaled_y = (y * self.ratio) + self.offset[1] return scaled_x, scaled_y - def inside_canvas(self, x: float, y: float) -> Tuple[bool, bool]: + def inside_canvas(self, x: float, y: float) -> tuple[bool, bool]: x1, y1, x2, y2 = self.bbox(self.rect) valid_x = x1 <= x <= x2 valid_y = y1 <= y <= y2 return valid_x and valid_y - def valid_position(self, x1: int, y1: int, x2: int, y2: int) -> Tuple[bool, bool]: + def valid_position(self, x1: int, y1: int, x2: int, y2: int) -> tuple[bool, bool]: valid_topleft = self.inside_canvas(x1, y1) valid_bottomright = self.inside_canvas(x2, y2) return valid_topleft and valid_bottomright @@ -161,7 +161,7 @@ class CanvasGraph(tk.Canvas): self.tag_lower(tags.GRIDLINE) self.tag_lower(self.rect) - def canvas_xy(self, event: tk.Event) -> Tuple[float, float]: + def canvas_xy(self, event: tk.Event) -> tuple[float, float]: """ Convert window coordinate to canvas coordinate """ @@ -516,7 +516,7 @@ class CanvasGraph(tk.Canvas): self.nodes[node.id] = node self.core.set_canvas_node(core_node, node) - def width_and_height(self) -> Tuple[int, int]: + def width_and_height(self) -> tuple[int, int]: """ retrieve canvas width and height in pixels """ @@ -601,7 +601,7 @@ class CanvasGraph(tk.Canvas): self.redraw_canvas((image.width(), image.height())) self.draw_wallpaper(image) - def redraw_canvas(self, dimensions: Tuple[int, int] = None) -> None: + def redraw_canvas(self, dimensions: tuple[int, int] = None) -> None: logger.debug("redrawing canvas to dimensions: %s", dimensions) # reset scale and move back to original position @@ -814,7 +814,7 @@ class CanvasGraph(tk.Canvas): for edge_id in self.find_withtag(tags.EDGE): self.itemconfig(edge_id, width=int(EDGE_WIDTH * self.app.app_scale)) - def get_metadata(self) -> Dict[str, Any]: + def get_metadata(self) -> dict[str, Any]: wallpaper_path = None if self.wallpaper_file: wallpaper = Path(self.wallpaper_file) @@ -830,7 +830,7 @@ class CanvasGraph(tk.Canvas): dimensions=self.current_dimensions, ) - def parse_metadata(self, config: Dict[str, Any]) -> None: + def parse_metadata(self, config: dict[str, Any]) -> None: fit_image = config.get("fit_image", False) self.adjust_to_dim.set(fit_image) wallpaper_style = config.get("wallpaper_style", 1) diff --git a/daemon/core/gui/graph/manager.py b/daemon/core/gui/graph/manager.py index dc0adca9..b2745f5c 100644 --- a/daemon/core/gui/graph/manager.py +++ b/daemon/core/gui/graph/manager.py @@ -1,9 +1,10 @@ import json import logging import tkinter as tk +from collections.abc import ValuesView from copy import deepcopy from tkinter import BooleanVar, messagebox, ttk -from typing import TYPE_CHECKING, Any, Dict, Optional, Tuple, ValuesView +from typing import TYPE_CHECKING, Any, Literal, Optional from core.api.grpc.wrappers import Link, LinkType, Node, Session, ThroughputsEvent from core.gui import nodeutils as nutils @@ -34,7 +35,7 @@ class ShowVar(BooleanVar): self.manager: "CanvasManager" = manager self.tag: str = tag - def state(self) -> str: + def state(self) -> Literal["normal", "hidden"]: return tk.NORMAL if self.get() else tk.HIDDEN def click_handler(self) -> None: @@ -78,14 +79,14 @@ class CanvasManager: self.mode: GraphMode = GraphMode.SELECT self.annotation_type: Optional[ShapeType] = None self.node_draw: Optional[NodeDraw] = None - self.canvases: Dict[int, CanvasGraph] = {} + self.canvases: dict[int, CanvasGraph] = {} # global edge management - self.edges: Dict[str, CanvasEdge] = {} - self.wireless_edges: Dict[str, CanvasWirelessEdge] = {} + self.edges: dict[str, CanvasEdge] = {} + self.wireless_edges: dict[str, CanvasWirelessEdge] = {} # global canvas settings - self.default_dimensions: Tuple[int, int] = ( + self.default_dimensions: tuple[int, int] = ( self.app.guiconfig.preferences.width, self.app.guiconfig.preferences.height, ) @@ -111,8 +112,8 @@ class CanvasManager: # widget self.notebook: Optional[ttk.Notebook] = None - self.canvas_ids: Dict[str, int] = {} - self.unique_ids: Dict[int, str] = {} + self.canvas_ids: dict[str, int] = {} + self.unique_ids: dict[int, str] = {} self.draw() self.setup_bindings() @@ -273,17 +274,17 @@ class CanvasManager: if not self.canvases: self.add_canvas() - def redraw_canvas(self, dimensions: Tuple[int, int]) -> None: + def redraw_canvas(self, dimensions: tuple[int, int]) -> None: canvas = self.current() canvas.redraw_canvas(dimensions) if canvas.wallpaper: canvas.redraw_wallpaper() - def get_metadata(self) -> Dict[str, Any]: + def get_metadata(self) -> dict[str, Any]: canvases = [x.get_metadata() for x in self.all()] return dict(gridlines=self.show_grid.get(), canvases=canvases) - def parse_metadata_canvas(self, metadata: Dict[str, Any]) -> None: + def parse_metadata_canvas(self, metadata: dict[str, Any]) -> None: # canvas setting canvas_config = metadata.get("canvas") logger.debug("canvas metadata: %s", canvas_config) @@ -303,7 +304,7 @@ class CanvasManager: canvas = self.get(canvas_id) canvas.parse_metadata(canvas_config) - def parse_metadata_shapes(self, metadata: Dict[str, Any]) -> None: + def parse_metadata_shapes(self, metadata: dict[str, Any]) -> None: # load saved shapes shapes_config = metadata.get("shapes") if not shapes_config: @@ -313,7 +314,7 @@ class CanvasManager: logger.debug("loading shape: %s", shape_config) Shape.from_metadata(self.app, shape_config) - def parse_metadata_edges(self, metadata: Dict[str, Any]) -> None: + def parse_metadata_edges(self, metadata: dict[str, Any]) -> None: # load edges config edges_config = metadata.get("edges") if not edges_config: @@ -330,7 +331,7 @@ class CanvasManager: else: logger.warning("invalid edge token to configure: %s", edge_token) - def parse_metadata_hidden(self, metadata: Dict[str, Any]) -> None: + def parse_metadata_hidden(self, metadata: dict[str, Any]) -> None: # read hidden nodes hidden_config = metadata.get("hidden") if not hidden_config: diff --git a/daemon/core/gui/graph/node.py b/daemon/core/gui/graph/node.py index b3d0aae9..0cfbf2e9 100644 --- a/daemon/core/gui/graph/node.py +++ b/daemon/core/gui/graph/node.py @@ -2,7 +2,7 @@ import functools import logging import tkinter as tk from pathlib import Path -from typing import TYPE_CHECKING, Dict, List, Optional, Set, Tuple +from typing import TYPE_CHECKING, Optional import grpc from PIL.ImageTk import PhotoImage @@ -62,17 +62,17 @@ class CanvasNode: state=self.app.manager.show_node_labels.state(), ) self.tooltip: CanvasTooltip = CanvasTooltip(self.canvas) - self.edges: Set[CanvasEdge] = set() - self.ifaces: Dict[int, Interface] = {} - self.wireless_edges: Set[CanvasWirelessEdge] = set() - self.antennas: List[int] = [] - self.antenna_images: Dict[int, PhotoImage] = {} + self.edges: set[CanvasEdge] = set() + self.ifaces: dict[int, Interface] = {} + self.wireless_edges: set[CanvasWirelessEdge] = set() + self.antennas: list[int] = [] + self.antenna_images: dict[int, PhotoImage] = {} self.hidden: bool = False self.setup_bindings() self.context: tk.Menu = tk.Menu(self.canvas) themes.style_menu(self.context) - def position(self) -> Tuple[int, int]: + def position(self) -> tuple[int, int]: return self.canvas.coords(self.id) def next_iface_id(self) -> int: @@ -543,7 +543,7 @@ class ShadowNode: self.canvas.shadow_nodes[self.id] = self self.canvas.shadow_core_nodes[self.node.core_node.id] = self - def position(self) -> Tuple[int, int]: + def position(self) -> tuple[int, int]: return self.canvas.coords(self.id) def should_delete(self) -> bool: diff --git a/daemon/core/gui/graph/shape.py b/daemon/core/gui/graph/shape.py index 7db18b5b..5f243fdf 100644 --- a/daemon/core/gui/graph/shape.py +++ b/daemon/core/gui/graph/shape.py @@ -1,5 +1,5 @@ import logging -from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union +from typing import TYPE_CHECKING, Any, Optional, Union from core.gui.dialogs.shapemod import ShapeDialog from core.gui.graph import tags @@ -72,7 +72,7 @@ class Shape: self.draw() @classmethod - def from_metadata(cls, app: "Application", config: Dict[str, Any]) -> None: + def from_metadata(cls, app: "Application", config: dict[str, Any]) -> None: shape_type = config["type"] try: shape_type = ShapeType(shape_type) @@ -144,7 +144,7 @@ class Shape: logger.error("unknown shape type: %s", self.shape_type) self.created = True - def get_font(self) -> List[Union[int, str]]: + def get_font(self) -> list[Union[int, str]]: font = [self.shape_data.font, self.shape_data.font_size] if self.shape_data.bold: font.append("bold") @@ -198,7 +198,7 @@ class Shape: self.canvas.delete(self.id) self.canvas.delete(self.text_id) - def metadata(self) -> Dict[str, Union[str, int, bool]]: + def metadata(self) -> dict[str, Union[str, int, bool]]: coords = self.canvas.coords(self.id) # update coords to actual positions if len(coords) == 4: diff --git a/daemon/core/gui/graph/shapeutils.py b/daemon/core/gui/graph/shapeutils.py index 2b62a46c..ab82ef76 100644 --- a/daemon/core/gui/graph/shapeutils.py +++ b/daemon/core/gui/graph/shapeutils.py @@ -1,5 +1,4 @@ import enum -from typing import Set class ShapeType(enum.Enum): @@ -9,7 +8,7 @@ class ShapeType(enum.Enum): TEXT = "text" -SHAPES: Set[ShapeType] = {ShapeType.OVAL, ShapeType.RECTANGLE} +SHAPES: set[ShapeType] = {ShapeType.OVAL, ShapeType.RECTANGLE} def is_draw_shape(shape_type: ShapeType) -> bool: diff --git a/daemon/core/gui/graph/tags.py b/daemon/core/gui/graph/tags.py index 803b969e..cb1ffc15 100644 --- a/daemon/core/gui/graph/tags.py +++ b/daemon/core/gui/graph/tags.py @@ -1,5 +1,3 @@ -from typing import List - ANNOTATION: str = "annotation" GRIDLINE: str = "gridline" SHAPE: str = "shape" @@ -15,7 +13,7 @@ WALLPAPER: str = "wallpaper" SELECTION: str = "selectednodes" MARKER: str = "marker" HIDDEN: str = "hidden" -ORGANIZE_TAGS: List[str] = [ +ORGANIZE_TAGS: list[str] = [ WALLPAPER, GRIDLINE, SHAPE, @@ -29,7 +27,7 @@ ORGANIZE_TAGS: List[str] = [ SELECTION, MARKER, ] -RESET_TAGS: List[str] = [ +RESET_TAGS: list[str] = [ EDGE, NODE, NODE_LABEL, diff --git a/daemon/core/gui/graph/tooltip.py b/daemon/core/gui/graph/tooltip.py index 6e4aa62f..b820abec 100644 --- a/daemon/core/gui/graph/tooltip.py +++ b/daemon/core/gui/graph/tooltip.py @@ -1,6 +1,6 @@ import tkinter as tk from tkinter import ttk -from typing import TYPE_CHECKING, Optional, Tuple +from typing import TYPE_CHECKING, Optional from core.gui.themes import Styles @@ -27,9 +27,9 @@ class CanvasTooltip: self, canvas: "CanvasGraph", *, - pad: Tuple[int, int, int, int] = (5, 3, 5, 3), + pad: tuple[int, int, int, int] = (5, 3, 5, 3), waittime: int = 400, - wraplength: int = 600 + wraplength: int = 600, ) -> None: # in miliseconds, originally 500 self.waittime: int = waittime @@ -37,7 +37,7 @@ class CanvasTooltip: self.wraplength: int = wraplength self.canvas: "CanvasGraph" = canvas self.text: tk.StringVar = tk.StringVar() - self.pad: Tuple[int, int, int, int] = pad + self.pad: tuple[int, int, int, int] = pad self.id: Optional[str] = None self.tw: Optional[tk.Toplevel] = None @@ -63,8 +63,8 @@ class CanvasTooltip: canvas: "CanvasGraph", label: ttk.Label, *, - tip_delta: Tuple[int, int] = (10, 5), - pad: Tuple[int, int, int, int] = (5, 3, 5, 3) + tip_delta: tuple[int, int] = (10, 5), + pad: tuple[int, int, int, int] = (5, 3, 5, 3), ): c = canvas s_width, s_height = c.winfo_screenwidth(), c.winfo_screenheight() @@ -112,7 +112,7 @@ class CanvasTooltip: ) label.grid(padx=(pad[0], pad[2]), pady=(pad[1], pad[3]), sticky=tk.NSEW) x, y = tip_pos_calculator(canvas, label, pad=pad) - self.tw.wm_geometry("+%d+%d" % (x, y)) + self.tw.wm_geometry(f"+{x:d}+{y:d}") def hide(self) -> None: if self.tw: diff --git a/daemon/core/gui/images.py b/daemon/core/gui/images.py index aed4cfcc..070137fb 100644 --- a/daemon/core/gui/images.py +++ b/daemon/core/gui/images.py @@ -1,5 +1,5 @@ from enum import Enum -from typing import Dict, Optional, Tuple +from typing import Optional from PIL import Image from PIL.ImageTk import PhotoImage @@ -12,7 +12,7 @@ ANTENNA_SIZE: int = 32 BUTTON_SIZE: int = 16 ERROR_SIZE: int = 24 DIALOG_SIZE: int = 16 -IMAGES: Dict[str, str] = {} +IMAGES: dict[str, str] = {} def load_all() -> None: @@ -78,6 +78,7 @@ class ImageEnum(Enum): EDITDELETE = "edit-delete" ANTENNA = "antenna" DOCKER = "docker" + PODMAN = "podman" LXC = "lxc" ALERT = "alert" DELETE = "delete" @@ -87,7 +88,7 @@ class ImageEnum(Enum): SHADOW = "shadow" -TYPE_MAP: Dict[Tuple[NodeType, str], ImageEnum] = { +TYPE_MAP: dict[tuple[NodeType, str], ImageEnum] = { (NodeType.DEFAULT, "router"): ImageEnum.ROUTER, (NodeType.DEFAULT, "PC"): ImageEnum.PC, (NodeType.DEFAULT, "host"): ImageEnum.HOST, @@ -101,6 +102,7 @@ TYPE_MAP: Dict[Tuple[NodeType, str], ImageEnum] = { (NodeType.RJ45, None): ImageEnum.RJ45, (NodeType.TUNNEL, None): ImageEnum.TUNNEL, (NodeType.DOCKER, None): ImageEnum.DOCKER, + (NodeType.PODMAN, None): ImageEnum.PODMAN, (NodeType.LXC, None): ImageEnum.LXC, } diff --git a/daemon/core/gui/interface.py b/daemon/core/gui/interface.py index 83fba104..9ebea3c1 100644 --- a/daemon/core/gui/interface.py +++ b/daemon/core/gui/interface.py @@ -1,5 +1,5 @@ import logging -from typing import TYPE_CHECKING, Any, Dict, List, Optional, Set, Tuple +from typing import TYPE_CHECKING, Any, Optional import netaddr from netaddr import EUI, IPNetwork @@ -43,7 +43,7 @@ class Subnets: def __hash__(self) -> int: return hash(self.key()) - def key(self) -> Tuple[IPNetwork, IPNetwork]: + def key(self) -> tuple[IPNetwork, IPNetwork]: return self.ip4, self.ip6 def next(self) -> "Subnets": @@ -61,8 +61,8 @@ class InterfaceManager: self.mac: EUI = EUI(mac, dialect=netaddr.mac_unix_expanded) self.current_mac: Optional[EUI] = None self.current_subnets: Optional[Subnets] = None - self.used_subnets: Dict[Tuple[IPNetwork, IPNetwork], Subnets] = {} - self.used_macs: Set[str] = set() + self.used_subnets: dict[tuple[IPNetwork, IPNetwork], Subnets] = {} + self.used_macs: set[str] = set() def update_ips(self, ip4: str, ip6: str) -> None: self.reset() @@ -91,7 +91,7 @@ class InterfaceManager: self.current_subnets = None self.used_subnets.clear() - def removed(self, links: List[Link]) -> None: + def removed(self, links: list[Link]) -> None: # get remaining subnets remaining_subnets = set() for edge in self.app.core.links.values(): @@ -121,7 +121,7 @@ class InterfaceManager: subnets.used_indexes.discard(index) self.current_subnets = None - def set_macs(self, links: List[Link]) -> None: + def set_macs(self, links: list[Link]) -> None: self.current_mac = self.mac self.used_macs.clear() for link in links: @@ -130,7 +130,7 @@ class InterfaceManager: if link.iface2: self.used_macs.add(link.iface2.mac) - def joined(self, links: List[Link]) -> None: + def joined(self, links: list[Link]) -> None: ifaces = [] for link in links: if link.iface1: @@ -208,7 +208,7 @@ class InterfaceManager: logger.info("ignoring subnet change for link between network nodes") def find_subnets( - self, canvas_node: CanvasNode, visited: Set[int] = None + self, canvas_node: CanvasNode, visited: set[int] = None ) -> Optional[IPNetwork]: logger.info("finding subnet for node: %s", canvas_node.core_node.name) subnets = None diff --git a/daemon/core/gui/nodeutils.py b/daemon/core/gui/nodeutils.py index 0357f23d..0b3e3d9a 100644 --- a/daemon/core/gui/nodeutils.py +++ b/daemon/core/gui/nodeutils.py @@ -1,5 +1,5 @@ import logging -from typing import TYPE_CHECKING, List, Optional, Set +from typing import TYPE_CHECKING, Optional from PIL.ImageTk import PhotoImage @@ -13,22 +13,27 @@ logger = logging.getLogger(__name__) if TYPE_CHECKING: from core.gui.app import Application -NODES: List["NodeDraw"] = [] -NETWORK_NODES: List["NodeDraw"] = [] +NODES: list["NodeDraw"] = [] +NETWORK_NODES: list["NodeDraw"] = [] NODE_ICONS = {} -CONTAINER_NODES: Set[NodeType] = {NodeType.DEFAULT, NodeType.DOCKER, NodeType.LXC} -IMAGE_NODES: Set[NodeType] = {NodeType.DOCKER, NodeType.LXC} -WIRELESS_NODES: Set[NodeType] = { +CONTAINER_NODES: set[NodeType] = { + NodeType.DEFAULT, + NodeType.DOCKER, + NodeType.LXC, + NodeType.PODMAN, +} +IMAGE_NODES: set[NodeType] = {NodeType.DOCKER, NodeType.LXC, NodeType.PODMAN} +WIRELESS_NODES: set[NodeType] = { NodeType.WIRELESS_LAN, NodeType.EMANE, NodeType.WIRELESS, } -RJ45_NODES: Set[NodeType] = {NodeType.RJ45} -BRIDGE_NODES: Set[NodeType] = {NodeType.HUB, NodeType.SWITCH} -IGNORE_NODES: Set[NodeType] = {NodeType.CONTROL_NET} -MOBILITY_NODES: Set[NodeType] = {NodeType.WIRELESS_LAN, NodeType.EMANE} -NODE_MODELS: Set[str] = {"router", "PC", "mdr", "prouter"} -ROUTER_NODES: Set[str] = {"router", "mdr"} +RJ45_NODES: set[NodeType] = {NodeType.RJ45} +BRIDGE_NODES: set[NodeType] = {NodeType.HUB, NodeType.SWITCH} +IGNORE_NODES: set[NodeType] = {NodeType.CONTROL_NET} +MOBILITY_NODES: set[NodeType] = {NodeType.WIRELESS_LAN, NodeType.EMANE} +NODE_MODELS: set[str] = {"router", "PC", "mdr", "prouter"} +ROUTER_NODES: set[str] = {"router", "mdr"} ANTENNA_ICON: Optional[PhotoImage] = None @@ -41,6 +46,7 @@ def setup() -> None: (ImageEnum.PROUTER, NodeType.DEFAULT, "PRouter", "prouter"), (ImageEnum.DOCKER, NodeType.DOCKER, "Docker", None), (ImageEnum.LXC, NodeType.LXC, "LXC", None), + (ImageEnum.PODMAN, NodeType.PODMAN, "Podman", None), ] for image_enum, node_type, label, model in nodes: node_draw = NodeDraw.from_setup(image_enum, node_type, label, model) @@ -106,7 +112,7 @@ def is_iface_node(node: Node) -> bool: return is_container(node) or is_bridge(node) -def get_custom_services(gui_config: GuiConfig, name: str) -> List[str]: +def get_custom_services(gui_config: GuiConfig, name: str) -> list[str]: for custom_node in gui_config.nodes: if custom_node.name == name: return custom_node.services @@ -154,7 +160,7 @@ class NodeDraw: self.image_file: Optional[str] = None self.node_type: Optional[NodeType] = None self.model: Optional[str] = None - self.services: Set[str] = set() + self.services: set[str] = set() self.label: Optional[str] = None @classmethod diff --git a/daemon/core/gui/observers.py b/daemon/core/gui/observers.py index 7879494b..8cf026bd 100644 --- a/daemon/core/gui/observers.py +++ b/daemon/core/gui/observers.py @@ -1,13 +1,13 @@ import tkinter as tk from functools import partial -from typing import TYPE_CHECKING, Dict +from typing import TYPE_CHECKING from core.gui.dialogs.observers import ObserverDialog if TYPE_CHECKING: from core.gui.app import Application -OBSERVERS: Dict[str, str] = { +OBSERVERS: dict[str, str] = { "List Processes": "ps", "Show Interfaces": "ip address", "IPV4 Routes": "ip -4 route", diff --git a/daemon/core/gui/statusbar.py b/daemon/core/gui/statusbar.py index 441213f2..a4967cd6 100644 --- a/daemon/core/gui/statusbar.py +++ b/daemon/core/gui/statusbar.py @@ -3,7 +3,7 @@ status bar """ import tkinter as tk from tkinter import ttk -from typing import TYPE_CHECKING, List, Optional +from typing import TYPE_CHECKING, Optional from core.api.grpc.wrappers import ExceptionEvent, ExceptionLevel from core.gui.dialogs.alerts import AlertsDialog @@ -24,7 +24,7 @@ class StatusBar(ttk.Frame): self.alerts_button: Optional[ttk.Button] = None self.alert_style = Styles.no_alert self.running: bool = False - self.core_alarms: List[ExceptionEvent] = [] + self.core_alarms: list[ExceptionEvent] = [] self.draw() def draw(self) -> None: diff --git a/daemon/core/gui/task.py b/daemon/core/gui/task.py index 2623136d..6bbeb70f 100644 --- a/daemon/core/gui/task.py +++ b/daemon/core/gui/task.py @@ -2,7 +2,7 @@ import logging import threading import time import tkinter as tk -from typing import TYPE_CHECKING, Any, Callable, Optional, Tuple +from typing import TYPE_CHECKING, Any, Callable, Optional logger = logging.getLogger(__name__) @@ -17,7 +17,7 @@ class ProgressTask: title: str, task: Callable, callback: Callable = None, - args: Tuple[Any] = None, + args: tuple[Any] = None, ): self.app: "Application" = app self.title: str = title @@ -25,7 +25,7 @@ class ProgressTask: self.callback: Callable = callback if args is None: args = () - self.args: Tuple[Any] = args + self.args: tuple[Any] = args self.time: Optional[float] = None def start(self) -> None: diff --git a/daemon/core/gui/themes.py b/daemon/core/gui/themes.py index 45b109f0..cb6280e5 100644 --- a/daemon/core/gui/themes.py +++ b/daemon/core/gui/themes.py @@ -1,10 +1,9 @@ import tkinter as tk from tkinter import font, ttk -from typing import Dict, Tuple THEME_DARK: str = "black" -PADX: Tuple[int, int] = (0, 5) -PADY: Tuple[int, int] = (0, 5) +PADX: tuple[int, int] = (0, 5) +PADY: tuple[int, int] = (0, 5) FRAME_PAD: int = 5 DIALOG_PAD: int = 5 @@ -201,7 +200,7 @@ def theme_change(event: tk.Event) -> None: _alert_style(style, Styles.red_alert, "red") -def scale_fonts(fonts_size: Dict[str, int], scale: float) -> None: +def scale_fonts(fonts_size: dict[str, int], scale: float) -> None: for name in font.names(): f = font.nametofont(name) if name in fonts_size: diff --git a/daemon/core/gui/toolbar.py b/daemon/core/gui/toolbar.py index 7392071d..7c32c0af 100644 --- a/daemon/core/gui/toolbar.py +++ b/daemon/core/gui/toolbar.py @@ -3,7 +3,7 @@ import tkinter as tk from enum import Enum from functools import partial from tkinter import ttk -from typing import TYPE_CHECKING, Callable, List, Optional +from typing import TYPE_CHECKING, Callable, Optional from PIL.ImageTk import PhotoImage @@ -90,7 +90,7 @@ class ButtonBar(ttk.Frame): def __init__(self, master: tk.Widget, app: "Application") -> None: super().__init__(master) self.app: "Application" = app - self.radio_buttons: List[ttk.Button] = [] + self.radio_buttons: list[ttk.Button] = [] def create_button( self, image_enum: ImageEnum, func: Callable, tooltip: str, radio: bool = False @@ -303,7 +303,7 @@ class Toolbar(ttk.Frame): ) task.start() - def start_callback(self, result: bool, exceptions: List[str]) -> None: + def start_callback(self, result: bool, exceptions: list[str]) -> None: self.set_runtime() self.app.core.show_mobility_players() if not result and exceptions: diff --git a/daemon/core/gui/tooltip.py b/daemon/core/gui/tooltip.py index 84a3178f..6d84ac75 100644 --- a/daemon/core/gui/tooltip.py +++ b/daemon/core/gui/tooltip.py @@ -5,7 +5,7 @@ from typing import Optional from core.gui.themes import Styles -class Tooltip(object): +class Tooltip: """ Create tool tip for a given widget """ @@ -42,7 +42,7 @@ class Tooltip(object): y += self.widget.winfo_rooty() + 32 self.tw = tk.Toplevel(self.widget) self.tw.wm_overrideredirect(True) - self.tw.wm_geometry("+%d+%d" % (x, y)) + self.tw.wm_geometry(f"+{x:d}+{y:d}") self.tw.rowconfigure(0, weight=1) self.tw.columnconfigure(0, weight=1) frame = ttk.Frame(self.tw, style=Styles.tooltip_frame, padding=3) diff --git a/daemon/core/gui/validation.py b/daemon/core/gui/validation.py index 2360ab0b..61500e84 100644 --- a/daemon/core/gui/validation.py +++ b/daemon/core/gui/validation.py @@ -3,8 +3,9 @@ input validation """ import re import tkinter as tk +from re import Pattern from tkinter import ttk -from typing import Any, Optional, Pattern +from typing import Any, Optional SMALLEST_SCALE: float = 0.5 LARGEST_SCALE: float = 5.0 diff --git a/daemon/core/gui/widgets.py b/daemon/core/gui/widgets.py index 7dfd2666..902f1132 100644 --- a/daemon/core/gui/widgets.py +++ b/daemon/core/gui/widgets.py @@ -3,7 +3,7 @@ import tkinter as tk from functools import partial from pathlib import Path from tkinter import filedialog, font, ttk -from typing import TYPE_CHECKING, Any, Callable, Dict, Set, Type +from typing import TYPE_CHECKING, Any, Callable from core.api.grpc.wrappers import ConfigOption, ConfigOptionType from core.gui import appconfig, themes, validation @@ -15,7 +15,7 @@ logger = logging.getLogger(__name__) if TYPE_CHECKING: from core.gui.app import Application -INT_TYPES: Set[ConfigOptionType] = { +INT_TYPES: set[ConfigOptionType] = { ConfigOptionType.UINT8, ConfigOptionType.UINT16, ConfigOptionType.UINT32, @@ -40,7 +40,7 @@ class FrameScroll(ttk.Frame): self, master: tk.Widget, app: "Application", - _cls: Type[ttk.Frame] = ttk.Frame, + _cls: type[ttk.Frame] = ttk.Frame, **kw: Any ) -> None: super().__init__(master, **kw) @@ -86,14 +86,14 @@ class ConfigFrame(ttk.Notebook): self, master: tk.Widget, app: "Application", - config: Dict[str, ConfigOption], + config: dict[str, ConfigOption], enabled: bool = True, **kw: Any ) -> None: super().__init__(master, **kw) self.app: "Application" = app - self.config: Dict[str, ConfigOption] = config - self.values: Dict[str, tk.StringVar] = {} + self.config: dict[str, ConfigOption] = config + self.values: dict[str, tk.StringVar] = {} self.enabled: bool = enabled def draw_config(self) -> None: @@ -166,7 +166,7 @@ class ConfigFrame(ttk.Notebook): logger.error("unhandled config option type: %s", option.type) self.values[option.name] = value - def parse_config(self) -> Dict[str, str]: + def parse_config(self) -> dict[str, str]: for key in self.config: option = self.config[key] value = self.values[key] @@ -180,7 +180,7 @@ class ConfigFrame(ttk.Notebook): option.value = config_value return {x: self.config[x].value for x in self.config} - def set_values(self, config: Dict[str, str]) -> None: + def set_values(self, config: dict[str, str]) -> None: for name, data in config.items(): option = self.config[name] value = self.values[name] diff --git a/daemon/core/location/event.py b/daemon/core/location/event.py index 7f8a33a1..9b300241 100644 --- a/daemon/core/location/event.py +++ b/daemon/core/location/event.py @@ -6,7 +6,7 @@ import heapq import threading import time from functools import total_ordering -from typing import Any, Callable, Dict, List, Optional, Tuple +from typing import Any, Callable, Optional class Timer(threading.Thread): @@ -19,8 +19,8 @@ class Timer(threading.Thread): self, interval: float, func: Callable[..., None], - args: Tuple[Any] = None, - kwargs: Dict[Any, Any] = None, + args: tuple[Any] = None, + kwargs: dict[Any, Any] = None, ) -> None: """ Create a Timer instance. @@ -38,11 +38,11 @@ class Timer(threading.Thread): # validate arguments were provided if args is None: args = () - self.args: Tuple[Any] = args + self.args: tuple[Any] = args # validate keyword arguments were provided if kwargs is None: kwargs = {} - self.kwargs: Dict[Any, Any] = kwargs + self.kwargs: dict[Any, Any] = kwargs def cancel(self) -> bool: """ @@ -96,8 +96,8 @@ class Event: self.eventnum: int = eventnum self.time: float = event_time self.func: Callable[..., None] = func - self.args: Tuple[Any] = args - self.kwds: Dict[Any, Any] = kwds + self.args: tuple[Any] = args + self.kwds: dict[Any, Any] = kwds self.canceled: bool = False def __lt__(self, other: "Event") -> bool: @@ -135,7 +135,7 @@ class EventLoop: Creates a EventLoop instance. """ self.lock: threading.RLock = threading.RLock() - self.queue: List[Event] = [] + self.queue: list[Event] = [] self.eventnum: int = 0 self.timer: Optional[Timer] = None self.running: bool = False diff --git a/daemon/core/location/geo.py b/daemon/core/location/geo.py index 5896e074..78308728 100644 --- a/daemon/core/location/geo.py +++ b/daemon/core/location/geo.py @@ -3,7 +3,6 @@ Provides conversions from x,y,z to lon,lat,alt. """ import logging -from typing import Tuple import pyproj from pyproj import Transformer @@ -35,9 +34,9 @@ class GeoLocation: self.to_geo: Transformer = pyproj.Transformer.from_crs( CRS_PROJ, CRS_WGS84, always_xy=True ) - self.refproj: Tuple[float, float, float] = (0.0, 0.0, 0.0) - self.refgeo: Tuple[float, float, float] = (0.0, 0.0, 0.0) - self.refxyz: Tuple[float, float, float] = (0.0, 0.0, 0.0) + self.refproj: tuple[float, float, float] = (0.0, 0.0, 0.0) + self.refgeo: tuple[float, float, float] = (0.0, 0.0, 0.0) + self.refxyz: tuple[float, float, float] = (0.0, 0.0, 0.0) self.refscale: float = 1.0 def setrefgeo(self, lat: float, lon: float, alt: float) -> None: @@ -84,7 +83,7 @@ class GeoLocation: return 0.0 return SCALE_FACTOR * (value / self.refscale) - def getxyz(self, lat: float, lon: float, alt: float) -> Tuple[float, float, float]: + def getxyz(self, lat: float, lon: float, alt: float) -> tuple[float, float, float]: """ Convert provided lon,lat,alt to x,y,z. @@ -104,7 +103,7 @@ class GeoLocation: 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]: + def getgeo(self, x: float, y: float, z: float) -> tuple[float, float, float]: """ Convert provided x,y,z to lon,lat,alt. diff --git a/daemon/core/location/mobility.py b/daemon/core/location/mobility.py index 28040650..ebac9bc5 100644 --- a/daemon/core/location/mobility.py +++ b/daemon/core/location/mobility.py @@ -9,7 +9,7 @@ import threading import time from functools import total_ordering from pathlib import Path -from typing import TYPE_CHECKING, Callable, Dict, List, Optional, Tuple, Union +from typing import TYPE_CHECKING, Callable, Optional, Union from core import utils from core.config import ( @@ -47,7 +47,7 @@ def get_mobility_node(session: "Session", node_id: int) -> Union[WlanNode, Emane return session.get_node(node_id, EmaneNet) -def get_config_int(current: int, config: Dict[str, str], name: str) -> Optional[int]: +def get_config_int(current: int, config: dict[str, str], name: str) -> Optional[int]: """ Convenience function to get config values as int. @@ -63,7 +63,7 @@ def get_config_int(current: int, config: Dict[str, str], name: str) -> Optional[ def get_config_float( - current: Union[int, float], config: Dict[str, str], name: str + current: Union[int, float], config: dict[str, str], name: str ) -> Optional[float]: """ Convenience function to get config values as float. @@ -112,7 +112,7 @@ class MobilityManager(ModelManager): """ self.config_reset() - def startup(self, node_ids: List[int] = None) -> None: + def startup(self, node_ids: list[int] = None) -> None: """ Session is transitioning from instantiation to runtime state. Instantiate any mobility models that have been configured for a WLAN. @@ -237,7 +237,7 @@ class WirelessModel(ConfigurableOptions): self.session: "Session" = session self.id: int = _id - def links(self, flags: MessageFlags = MessageFlags.NONE) -> List[LinkData]: + def links(self, flags: MessageFlags = MessageFlags.NONE) -> list[LinkData]: """ May be used if the model can populate the GUI with wireless (green) link lines. @@ -247,7 +247,7 @@ class WirelessModel(ConfigurableOptions): """ return [] - def update(self, moved_ifaces: List[CoreInterface]) -> None: + def update(self, moved_ifaces: list[CoreInterface]) -> None: """ Update this wireless model. @@ -256,7 +256,7 @@ class WirelessModel(ConfigurableOptions): """ raise NotImplementedError - def update_config(self, config: Dict[str, str]) -> None: + def update_config(self, config: dict[str, str]) -> None: """ For run-time updates of model config. Returns True when position callback and set link parameters should be invoked. @@ -275,7 +275,7 @@ class BasicRangeModel(WirelessModel): """ name: str = "basic_range" - options: List[Configuration] = [ + options: list[Configuration] = [ ConfigInt(id="range", default="275", label="wireless range (pixels)"), ConfigInt(id="bandwidth", default="54000000", label="bandwidth (bps)"), ConfigInt(id="jitter", default="0", label="transmission jitter (usec)"), @@ -298,7 +298,7 @@ class BasicRangeModel(WirelessModel): super().__init__(session, _id) self.session: "Session" = session self.wlan: WlanNode = session.get_node(_id, WlanNode) - self.iface_to_pos: Dict[CoreInterface, Tuple[float, float, float]] = {} + self.iface_to_pos: dict[CoreInterface, tuple[float, float, float]] = {} self.iface_lock: threading.Lock = threading.Lock() self.range: int = 0 self.bw: Optional[int] = None @@ -323,7 +323,7 @@ class BasicRangeModel(WirelessModel): iface.options.update(options) iface.set_config() - def get_position(self, iface: CoreInterface) -> Tuple[float, float, float]: + def get_position(self, iface: CoreInterface) -> tuple[float, float, float]: """ Retrieve network interface position. @@ -352,7 +352,7 @@ class BasicRangeModel(WirelessModel): position_callback = set_position - def update(self, moved_ifaces: List[CoreInterface]) -> None: + def update(self, moved_ifaces: list[CoreInterface]) -> None: """ Node positions have changed without recalc. Update positions from node.position, then re-calculate links for those that have moved. @@ -412,7 +412,7 @@ class BasicRangeModel(WirelessModel): @staticmethod def calcdistance( - p1: Tuple[float, float, float], p2: Tuple[float, float, float] + p1: tuple[float, float, float], p2: tuple[float, float, float] ) -> float: """ Calculate the distance between two three-dimensional points. @@ -428,7 +428,7 @@ class BasicRangeModel(WirelessModel): c = p1[2] - p2[2] return math.hypot(math.hypot(a, b), c) - def update_config(self, config: Dict[str, str]) -> None: + def update_config(self, config: dict[str, str]) -> None: """ Configuration has changed during runtime. @@ -487,7 +487,7 @@ class BasicRangeModel(WirelessModel): link_data = self.create_link_data(iface, iface2, message_type) self.session.broadcast_link(link_data) - def links(self, flags: MessageFlags = MessageFlags.NONE) -> List[LinkData]: + def links(self, flags: MessageFlags = MessageFlags.NONE) -> list[LinkData]: """ Return a list of wireless link messages for when the GUI reconnects. @@ -513,7 +513,7 @@ class WayPoint: self, _time: float, node_id: int, - coords: Tuple[float, float, Optional[float]], + coords: tuple[float, float, Optional[float]], speed: float, ) -> None: """ @@ -526,7 +526,7 @@ class WayPoint: """ self.time: float = _time self.node_id: int = node_id - self.coords: Tuple[float, float, Optional[float]] = coords + self.coords: tuple[float, float, Optional[float]] = coords self.speed: float = speed def __eq__(self, other: "WayPoint") -> bool: @@ -563,10 +563,10 @@ class WayPointMobility(WirelessModel): """ super().__init__(session=session, _id=_id) self.state: int = self.STATE_STOPPED - self.queue: List[WayPoint] = [] - self.queue_copy: List[WayPoint] = [] - self.points: Dict[int, WayPoint] = {} - self.initial: Dict[int, WayPoint] = {} + self.queue: list[WayPoint] = [] + self.queue_copy: list[WayPoint] = [] + self.points: dict[int, WayPoint] = {} + self.initial: dict[int, WayPoint] = {} self.lasttime: Optional[float] = None self.endtime: Optional[int] = None self.timezero: float = 0.0 @@ -855,7 +855,7 @@ class Ns2ScriptedMobility(WayPointMobility): """ name: str = "ns2script" - options: List[Configuration] = [ + options: list[Configuration] = [ ConfigString(id="file", label="mobility script file"), ConfigInt(id="refresh_ms", default="50", label="refresh time (ms)"), ConfigBool(id="loop", default="1", label="loop"), @@ -867,7 +867,7 @@ class Ns2ScriptedMobility(WayPointMobility): ] @classmethod - def config_groups(cls) -> List[ConfigGroup]: + def config_groups(cls) -> list[ConfigGroup]: return [ ConfigGroup("ns-2 Mobility Script Parameters", 1, len(cls.configurations())) ] @@ -882,12 +882,12 @@ class Ns2ScriptedMobility(WayPointMobility): super().__init__(session, _id) self.file: Optional[Path] = None self.autostart: Optional[str] = None - self.nodemap: Dict[int, int] = {} + self.nodemap: dict[int, int] = {} self.script_start: Optional[str] = None self.script_pause: Optional[str] = None self.script_stop: Optional[str] = None - def update_config(self, config: Dict[str, str]) -> None: + def update_config(self, config: dict[str, str]) -> None: self.file = Path(config["file"]) logger.info( "ns-2 scripted mobility configured for WLAN %d using file: %s", @@ -916,7 +916,7 @@ class Ns2ScriptedMobility(WayPointMobility): file_path = self.findfile(self.file) try: f = file_path.open("r") - except IOError: + except OSError: logger.exception( "ns-2 scripted mobility failed to load file: %s", self.file ) diff --git a/daemon/core/nodes/base.py b/daemon/core/nodes/base.py index 92717ead..e59a89e4 100644 --- a/daemon/core/nodes/base.py +++ b/daemon/core/nodes/base.py @@ -9,7 +9,7 @@ import threading from dataclasses import dataclass, field from pathlib import Path from threading import RLock -from typing import TYPE_CHECKING, Dict, List, Optional, Tuple, Type, Union +from typing import TYPE_CHECKING, Optional, Union import netaddr @@ -29,10 +29,10 @@ if TYPE_CHECKING: from core.configservice.base import ConfigService from core.services.coreservices import CoreService - CoreServices = List[Union[CoreService, Type[CoreService]]] - ConfigServiceType = Type[ConfigService] + CoreServices = list[Union[CoreService, type[CoreService]]] + ConfigServiceType = type[ConfigService] -PRIVATE_DIRS: List[Path] = [Path("/var/run"), Path("/var/log")] +PRIVATE_DIRS: list[Path] = [Path("/var/run"), Path("/var/log")] @dataclass @@ -64,7 +64,7 @@ class Position: self.z = z return True - def get(self) -> Tuple[float, float, float]: + def get(self) -> tuple[float, float, float]: """ Retrieve x,y,z position. @@ -88,7 +88,7 @@ class Position: self.lat = lat self.alt = alt - def get_geo(self) -> Tuple[float, float, float]: + def get_geo(self) -> tuple[float, float, float]: """ Retrieve current geo position lon, lat, alt. @@ -113,9 +113,9 @@ class NodeOptions: class CoreNodeOptions(NodeOptions): model: str = "PC" """model is used for providing a default set of services""" - services: List[str] = field(default_factory=list) + services: list[str] = field(default_factory=list) """services to start within node""" - config_services: List[str] = field(default_factory=list) + config_services: list[str] = field(default_factory=list) """config services to start within node""" directory: Path = None """directory to define node, defaults to path under the session directory""" @@ -152,7 +152,7 @@ class NodeBase(abc.ABC): self.server: "DistributedServer" = server self.model: Optional[str] = None self.services: CoreServices = [] - self.ifaces: Dict[int, CoreInterface] = {} + self.ifaces: dict[int, CoreInterface] = {} self.iface_id: int = 0 self.position: Position = Position() self.up: bool = False @@ -201,7 +201,7 @@ class NodeBase(abc.ABC): def host_cmd( self, args: str, - env: Dict[str, str] = None, + env: dict[str, str] = None, cwd: Path = None, wait: bool = True, shell: bool = False, @@ -246,7 +246,7 @@ class NodeBase(abc.ABC): """ return self.position.set(x=x, y=y, z=z) - def getposition(self) -> Tuple[float, float, float]: + def getposition(self) -> tuple[float, float, float]: """ Return an (x,y,z) tuple representing this object's position. @@ -331,7 +331,7 @@ class NodeBase(abc.ABC): raise CoreError(f"node({self.name}) does not have interface({iface_id})") return self.ifaces[iface_id] - def get_ifaces(self, control: bool = True) -> List[CoreInterface]: + def get_ifaces(self, control: bool = True) -> list[CoreInterface]: """ Retrieve sorted list of interfaces, optionally do not include control interfaces. @@ -395,7 +395,7 @@ class CoreNodeBase(NodeBase): will run on, default is None for localhost """ super().__init__(session, _id, name, server, options) - self.config_services: Dict[str, "ConfigService"] = {} + self.config_services: dict[str, "ConfigService"] = {} self.directory: Optional[Path] = None self.tmpnodedir: bool = False @@ -481,7 +481,7 @@ class CoreNodeBase(NodeBase): raise CoreError(f"node({self.name}) already has service({name})") self.config_services[name] = service_class(self) - def set_service_config(self, name: str, data: Dict[str, str]) -> None: + def set_service_config(self, name: str, data: dict[str, str]) -> None: """ Sets configuration service custom config data. @@ -506,6 +506,15 @@ class CoreNodeBase(NodeBase): for service in startup_path: service.start() + def stop_config_services(self) -> None: + """ + Stop all configuration services. + + :return: nothing + """ + for service in self.config_services.values(): + service.stop() + def makenodedir(self) -> None: """ Create the node directory. @@ -574,7 +583,7 @@ class CoreNode(CoreNodeBase): self.directory: Optional[Path] = options.directory self.ctrlchnlname: Path = self.session.directory / self.name self.pid: Optional[int] = None - self._mounts: List[Tuple[Path, Path]] = [] + self._mounts: list[tuple[Path, Path]] = [] self.node_net_client: LinuxNetClient = self.create_node_net_client( self.session.use_ovs() ) @@ -928,7 +937,7 @@ class CoreNetworkBase(NodeBase): mtu = self.session.options.get_int("mtu") self.mtu: int = mtu if mtu > 0 else DEFAULT_MTU self.brname: Optional[str] = None - self.linked: Dict[CoreInterface, Dict[CoreInterface, bool]] = {} + self.linked: dict[CoreInterface, dict[CoreInterface, bool]] = {} self.linked_lock: threading.Lock = threading.Lock() def attach(self, iface: CoreInterface) -> None: diff --git a/daemon/core/nodes/docker.py b/daemon/core/nodes/docker.py index 45d2b892..ad05c407 100644 --- a/daemon/core/nodes/docker.py +++ b/daemon/core/nodes/docker.py @@ -4,8 +4,9 @@ import shlex from dataclasses import dataclass, field from pathlib import Path from tempfile import NamedTemporaryFile -from typing import TYPE_CHECKING, Dict, List, Tuple +from typing import TYPE_CHECKING +from core import utils from core.emulator.distributed import DistributedServer from core.errors import CoreCommandError, CoreError from core.executables import BASH @@ -23,9 +24,9 @@ DOCKER: str = "docker" class DockerOptions(CoreNodeOptions): image: str = "ubuntu" """image used when creating container""" - binds: List[Tuple[str, str]] = field(default_factory=list) + binds: list[tuple[str, str]] = field(default_factory=list) """bind mount source and destinations to setup within container""" - volumes: List[Tuple[str, str, bool, bool]] = field(default_factory=list) + volumes: list[tuple[str, str, bool, bool]] = field(default_factory=list) """ volume mount source, destination, unique, delete to setup within container @@ -74,8 +75,9 @@ class DockerNode(CoreNode): options = options or DockerOptions() super().__init__(session, _id, name, server, options) self.image: str = options.image - self.binds: List[Tuple[str, str]] = options.binds - self.volumes: Dict[str, DockerVolume] = {} + self.binds: list[tuple[str, str]] = options.binds + self.volumes: dict[str, DockerVolume] = {} + self.env: dict[str, str] = {} for src, dst, unique, delete in options.volumes: src_name = self._unique_name(src) if unique else src self.volumes[src] = DockerVolume(src_name, dst, unique, delete) @@ -99,7 +101,24 @@ class DockerNode(CoreNode): """ if shell: args = f"{BASH} -c {shlex.quote(args)}" - return f"nsenter -t {self.pid} -m -u -i -p -n {args}" + return f"nsenter -t {self.pid} -m -u -i -p -n -- {args}" + + def cmd(self, args: str, wait: bool = True, shell: bool = False) -> str: + """ + Runs a command that is used to configure and setup the network within a + node. + + :param args: command to run + :param wait: True to wait for status, False otherwise + :param shell: True to use shell, False otherwise + :return: combined stdout and stderr + :raises CoreCommandError: when a non-zero exit status occurs + """ + args = self.create_cmd(args, shell) + if self.server is None: + return utils.cmd(args, wait=wait, shell=shell, env=self.env) + else: + return self.server.remote_cmd(args, wait=wait, env=self.env) def _unique_name(self, name: str) -> str: """ @@ -133,7 +152,9 @@ class DockerNode(CoreNode): with self.lock: if self.up: raise CoreError(f"starting node({self.name}) that is already up") + # create node directory self.makenodedir() + # setup commands for creating bind/volume mounts binds = "" for src, dst in self.binds: binds += f"--mount type=bind,source={src},target={dst} " @@ -142,16 +163,26 @@ class DockerNode(CoreNode): volumes += ( f"--mount type=volume," f"source={volume.src},target={volume.dst} " ) + # normalize hostname hostname = self.name.replace("_", "-") + # create container and retrieve the created containers PID self.host_cmd( f"{DOCKER} run -td --init --net=none --hostname {hostname} " f"--name {self.name} --sysctl net.ipv6.conf.all.disable_ipv6=0 " f"{binds} {volumes} " f"--privileged {self.image} tail -f /dev/null" ) + # retrieve pid and process environment for use in nsenter commands self.pid = self.host_cmd( f"{DOCKER} inspect -f '{{{{.State.Pid}}}}' {self.name}" ) + output = self.host_cmd(f"cat /proc/{self.pid}/environ") + for line in output.split("\x00"): + if not line: + continue + key, value = line.split("=") + self.env[key] = value + # setup symlinks for bind and volume mounts within for src, dst in self.binds: link_path = self.host_path(Path(dst), True) self.host_cmd(f"ln -s {src} {link_path}") @@ -227,7 +258,7 @@ class DockerNode(CoreNode): """ logger.debug("node(%s) create file(%s) mode(%o)", self.name, file_path, mode) temp = NamedTemporaryFile(delete=False) - temp.write(contents.encode("utf-8")) + temp.write(contents.encode()) temp.close() temp_path = Path(temp.name) directory = file_path.parent diff --git a/daemon/core/nodes/interface.py b/daemon/core/nodes/interface.py index bb90653f..294e85f9 100644 --- a/daemon/core/nodes/interface.py +++ b/daemon/core/nodes/interface.py @@ -5,7 +5,7 @@ virtual ethernet classes that implement the interfaces available under Linux. import logging import math from pathlib import Path -from typing import TYPE_CHECKING, Callable, Dict, List, Optional +from typing import TYPE_CHECKING, Callable, Optional import netaddr @@ -114,8 +114,8 @@ class CoreInterface: self.up: bool = False self.mtu: int = mtu self.net: Optional[CoreNetworkBase] = None - self.ip4s: List[netaddr.IPNetwork] = [] - self.ip6s: List[netaddr.IPNetwork] = [] + self.ip4s: list[netaddr.IPNetwork] = [] + self.ip6s: list[netaddr.IPNetwork] = [] self.mac: Optional[netaddr.EUI] = None # placeholder position hook self.poshook: Callable[[CoreInterface], None] = lambda x: None @@ -133,7 +133,7 @@ class CoreInterface: def host_cmd( self, args: str, - env: Dict[str, str] = None, + env: dict[str, str] = None, cwd: Path = None, wait: bool = True, shell: bool = False, @@ -235,7 +235,7 @@ class CoreInterface: """ return next(iter(self.ip6s), None) - def ips(self) -> List[netaddr.IPNetwork]: + def ips(self) -> list[netaddr.IPNetwork]: """ Retrieve a list of all ip4 and ip6 addresses combined. diff --git a/daemon/core/nodes/lxd.py b/daemon/core/nodes/lxd.py index 01bd2db7..e4cba002 100644 --- a/daemon/core/nodes/lxd.py +++ b/daemon/core/nodes/lxd.py @@ -5,7 +5,7 @@ import time from dataclasses import dataclass, field from pathlib import Path from tempfile import NamedTemporaryFile -from typing import TYPE_CHECKING, Dict, List, Tuple +from typing import TYPE_CHECKING from core.emulator.data import InterfaceData, LinkOptions from core.emulator.distributed import DistributedServer @@ -24,9 +24,9 @@ if TYPE_CHECKING: class LxcOptions(CoreNodeOptions): image: str = "ubuntu" """image used when creating container""" - binds: List[Tuple[str, str]] = field(default_factory=list) + binds: list[tuple[str, str]] = field(default_factory=list) """bind mount source and destinations to setup within container""" - volumes: List[Tuple[str, str, bool, bool]] = field(default_factory=list) + volumes: list[tuple[str, str, bool, bool]] = field(default_factory=list) """ volume mount source, destination, unique, delete to setup within container @@ -74,7 +74,7 @@ class LxcNode(CoreNode): args = f"{BASH} -c {shlex.quote(args)}" return f"nsenter -t {self.pid} -m -u -i -p -n {args}" - def _get_info(self) -> Dict: + def _get_info(self) -> dict: args = f"lxc list {self.name} --format json" output = self.host_cmd(args) data = json.loads(output) @@ -170,7 +170,7 @@ class LxcNode(CoreNode): """ logger.debug("node(%s) create file(%s) mode(%o)", self.name, file_path, mode) temp = NamedTemporaryFile(delete=False) - temp.write(contents.encode("utf-8")) + temp.write(contents.encode()) temp.close() temp_path = Path(temp.name) directory = file_path.parent diff --git a/daemon/core/nodes/network.py b/daemon/core/nodes/network.py index e201e807..1ea9c31e 100644 --- a/daemon/core/nodes/network.py +++ b/daemon/core/nodes/network.py @@ -6,7 +6,7 @@ import logging import threading from dataclasses import dataclass from pathlib import Path -from typing import TYPE_CHECKING, Dict, List, Optional, Type +from typing import TYPE_CHECKING, Optional import netaddr @@ -51,7 +51,7 @@ class NftablesQueue: # this lock protects cmds and updates lists self.lock: threading.Lock = threading.Lock() # list of pending nftables commands - self.cmds: List[str] = [] + self.cmds: list[str] = [] # list of WLANs requiring update self.updates: utils.SetQueue = utils.SetQueue() @@ -226,7 +226,7 @@ class CoreNetwork(CoreNetworkBase): def host_cmd( self, args: str, - env: Dict[str, str] = None, + env: dict[str, str] = None, cwd: Path = None, wait: bool = True, shell: bool = False, @@ -448,7 +448,7 @@ class GreTapBridge(CoreNetwork): self.gretap = None super().shutdown() - def add_ips(self, ips: List[str]) -> None: + def add_ips(self, ips: list[str]) -> None: """ Set the remote tunnel endpoint. This is a one-time method for creating the GreTap device, which requires the remoteip at startup. @@ -512,7 +512,7 @@ class CtrlNet(CoreNetwork): policy: NetworkPolicy = NetworkPolicy.ACCEPT # base control interface index CTRLIF_IDX_BASE: int = 99 - DEFAULT_PREFIX_LIST: List[str] = [ + DEFAULT_PREFIX_LIST: list[str] = [ "172.16.0.0/24 172.16.1.0/24 172.16.2.0/24 172.16.3.0/24 172.16.4.0/24", "172.17.0.0/24 172.17.1.0/24 172.17.2.0/24 172.17.3.0/24 172.17.4.0/24", "172.18.0.0/24 172.18.1.0/24 172.18.2.0/24 172.18.3.0/24 172.18.4.0/24", @@ -734,7 +734,7 @@ class WlanNode(CoreNetwork): iface.poshook = self.wireless_model.position_callback iface.setposition() - def setmodel(self, wireless_model: Type["WirelessModel"], config: Dict[str, str]): + def setmodel(self, wireless_model: type["WirelessModel"], config: dict[str, str]): """ Sets the mobility and wireless model. @@ -753,12 +753,12 @@ class WlanNode(CoreNetwork): self.mobility = wireless_model(session=self.session, _id=self.id) self.mobility.update_config(config) - def update_mobility(self, config: Dict[str, str]) -> None: + def update_mobility(self, config: dict[str, str]) -> None: if not self.mobility: raise CoreError(f"no mobility set to update for node({self.name})") self.mobility.update_config(config) - def updatemodel(self, config: Dict[str, str]) -> None: + def updatemodel(self, config: dict[str, str]) -> None: if not self.wireless_model: raise CoreError(f"no model set to update for node({self.name})") logger.debug( @@ -768,7 +768,7 @@ class WlanNode(CoreNetwork): for iface in self.get_ifaces(): iface.setposition() - def links(self, flags: MessageFlags = MessageFlags.NONE) -> List[LinkData]: + def links(self, flags: MessageFlags = MessageFlags.NONE) -> list[LinkData]: """ Retrieve all link data. diff --git a/daemon/core/nodes/physical.py b/daemon/core/nodes/physical.py index 8ab13f20..30640fd8 100644 --- a/daemon/core/nodes/physical.py +++ b/daemon/core/nodes/physical.py @@ -4,7 +4,7 @@ PhysicalNode class for including real systems in the emulated network. import logging from pathlib import Path -from typing import TYPE_CHECKING, List, Optional, Tuple +from typing import TYPE_CHECKING, Optional import netaddr @@ -52,7 +52,7 @@ class Rj45Node(CoreNodeBase): ) self.iface.transport_type = TransportType.RAW self.old_up: bool = False - self.old_addrs: List[Tuple[str, Optional[str]]] = [] + self.old_addrs: list[tuple[str, Optional[str]]] = [] def startup(self) -> None: """ @@ -159,7 +159,7 @@ class Rj45Node(CoreNodeBase): """ # TODO: save/restore the PROMISC flag self.old_up = False - self.old_addrs: List[Tuple[str, Optional[str]]] = [] + self.old_addrs: list[tuple[str, Optional[str]]] = [] localname = self.iface.localname output = self.net_client.address_show(localname) for line in output.split("\n"): @@ -171,7 +171,10 @@ class Rj45Node(CoreNodeBase): if "UP" in flags: self.old_up = True elif items[0] == "inet": - self.old_addrs.append((items[1], items[3])) + broadcast = None + if items[2] == "brd": + broadcast = items[3] + self.old_addrs.append((items[1], broadcast)) elif items[0] == "inet6": if items[1][:4] == "fe80": continue diff --git a/daemon/core/nodes/podman.py b/daemon/core/nodes/podman.py new file mode 100644 index 00000000..00ef24fc --- /dev/null +++ b/daemon/core/nodes/podman.py @@ -0,0 +1,271 @@ +import json +import logging +import shlex +from dataclasses import dataclass, field +from pathlib import Path +from tempfile import NamedTemporaryFile +from typing import TYPE_CHECKING + +from core.emulator.distributed import DistributedServer +from core.errors import CoreCommandError, CoreError +from core.executables import BASH +from core.nodes.base import CoreNode, CoreNodeOptions + +logger = logging.getLogger(__name__) + +if TYPE_CHECKING: + from core.emulator.session import Session + +PODMAN: str = "podman" + + +@dataclass +class PodmanOptions(CoreNodeOptions): + image: str = "ubuntu" + """image used when creating container""" + binds: list[tuple[str, str]] = field(default_factory=list) + """bind mount source and destinations to setup within container""" + volumes: list[tuple[str, str, bool, bool]] = field(default_factory=list) + """ + volume mount source, destination, unique, delete to setup within container + + unique is True for node unique volume naming + delete is True for deleting volume mount during shutdown + """ + + +@dataclass +class VolumeMount: + src: str + """volume mount name""" + dst: str + """volume mount destination directory""" + unique: bool = True + """True to create a node unique prefixed name for this volume""" + delete: bool = True + """True to delete the volume during shutdown""" + path: str = None + """path to the volume on the host""" + + +class PodmanNode(CoreNode): + """ + Provides logic for creating a Podman based node. + """ + + def __init__( + self, + session: "Session", + _id: int = None, + name: str = None, + server: DistributedServer = None, + options: PodmanOptions = None, + ) -> None: + """ + Create a PodmanNode instance. + + :param session: core session instance + :param _id: node id + :param name: node name + :param server: remote server node + will run on, default is None for localhost + :param options: options for creating node + """ + options = options or PodmanOptions() + super().__init__(session, _id, name, server, options) + self.image: str = options.image + self.binds: list[tuple[str, str]] = options.binds + self.volumes: dict[str, VolumeMount] = {} + for src, dst, unique, delete in options.volumes: + src_name = self._unique_name(src) if unique else src + self.volumes[src] = VolumeMount(src_name, dst, unique, delete) + + @classmethod + def create_options(cls) -> PodmanOptions: + """ + Return default creation options, which can be used during node creation. + + :return: podman options + """ + return PodmanOptions() + + def create_cmd(self, args: str, shell: bool = False) -> str: + """ + Create command used to run commands within the context of a node. + + :param args: command arguments + :param shell: True to run shell like, False otherwise + :return: node command + """ + if shell: + args = f"{BASH} -c {shlex.quote(args)}" + return f"{PODMAN} exec {self.name} {args}" + + def _unique_name(self, name: str) -> str: + """ + Creates a session/node unique prefixed name for the provided input. + + :param name: name to make unique + :return: unique session/node prefixed name + """ + return f"{self.session.id}.{self.id}.{name}" + + def alive(self) -> bool: + """ + Check if the node is alive. + + :return: True if node is alive, False otherwise + """ + try: + running = self.host_cmd( + f"{PODMAN} inspect -f '{{{{.State.Running}}}}' {self.name}" + ) + return json.loads(running) + except CoreCommandError: + return False + + def startup(self) -> None: + """ + Create a podman container instance for the specified image. + + :return: nothing + """ + with self.lock: + if self.up: + raise CoreError(f"starting node({self.name}) that is already up") + # create node directory + self.makenodedir() + # setup commands for creating bind/volume mounts + binds = "" + for src, dst in self.binds: + binds += f"--mount type=bind,source={src},target={dst} " + volumes = "" + for volume in self.volumes.values(): + volumes += ( + f"--mount type=volume," f"source={volume.src},target={volume.dst} " + ) + # normalize hostname + hostname = self.name.replace("_", "-") + # create container and retrieve the created containers PID + self.host_cmd( + f"{PODMAN} run -td --init --net=none --hostname {hostname} " + f"--name {self.name} --sysctl net.ipv6.conf.all.disable_ipv6=0 " + f"{binds} {volumes} " + f"--privileged {self.image} tail -f /dev/null" + ) + # retrieve pid and process environment for use in nsenter commands + self.pid = self.host_cmd( + f"{PODMAN} inspect -f '{{{{.State.Pid}}}}' {self.name}" + ) + # setup symlinks for bind and volume mounts within + for src, dst in self.binds: + link_path = self.host_path(Path(dst), True) + self.host_cmd(f"ln -s {src} {link_path}") + for volume in self.volumes.values(): + volume.path = self.host_cmd( + f"{PODMAN} volume inspect -f '{{{{.Mountpoint}}}}' {volume.src}" + ) + link_path = self.host_path(Path(volume.dst), True) + self.host_cmd(f"ln -s {volume.path} {link_path}") + logger.debug("node(%s) pid: %s", self.name, self.pid) + self.up = True + + def shutdown(self) -> None: + """ + Shutdown logic. + + :return: nothing + """ + # nothing to do if node is not up + if not self.up: + return + with self.lock: + self.ifaces.clear() + self.host_cmd(f"{PODMAN} rm -f {self.name}") + for volume in self.volumes.values(): + if volume.delete: + self.host_cmd(f"{PODMAN} volume rm {volume.src}") + self.up = False + + def termcmdstring(self, sh: str = "/bin/sh") -> str: + """ + Create a terminal command string. + + :param sh: shell to execute command in + :return: str + """ + terminal = f"{PODMAN} exec -it {self.name} {sh}" + if self.server is None: + return terminal + else: + return f"ssh -X -f {self.server.host} xterm -e {terminal}" + + def create_dir(self, dir_path: Path) -> None: + """ + Create a private directory. + + :param dir_path: path to create + :return: nothing + """ + logger.debug("creating node dir: %s", dir_path) + self.cmd(f"mkdir -p {dir_path}") + + def mount(self, src_path: str, target_path: str) -> None: + """ + Create and mount a directory. + + :param src_path: source directory to mount + :param target_path: target directory to create + :return: nothing + :raises CoreCommandError: when a non-zero exit status occurs + """ + logger.debug("mounting source(%s) target(%s)", src_path, target_path) + raise Exception("not supported") + + def create_file(self, file_path: Path, contents: str, mode: int = 0o644) -> None: + """ + Create a node file with a given mode. + + :param file_path: name of file to create + :param contents: contents of file + :param mode: mode for file + :return: nothing + """ + logger.debug("node(%s) create file(%s) mode(%o)", self.name, file_path, mode) + temp = NamedTemporaryFile(delete=False) + temp.write(contents.encode()) + temp.close() + temp_path = Path(temp.name) + directory = file_path.parent + if str(directory) != ".": + self.cmd(f"mkdir -m {0o755:o} -p {directory}") + if self.server is not None: + self.server.remote_put(temp_path, temp_path) + self.host_cmd(f"{PODMAN} cp {temp_path} {self.name}:{file_path}") + self.cmd(f"chmod {mode:o} {file_path}") + if self.server is not None: + self.host_cmd(f"rm -f {temp_path}") + temp_path.unlink() + + def copy_file(self, src_path: Path, dst_path: Path, mode: int = None) -> None: + """ + Copy a file to a node, following symlinks and preserving metadata. + Change file mode if specified. + + :param dst_path: file name to copy file to + :param src_path: file to copy + :param mode: mode to copy to + :return: nothing + """ + logger.info( + "node file copy file(%s) source(%s) mode(%o)", dst_path, src_path, mode or 0 + ) + self.cmd(f"mkdir -p {dst_path.parent}") + if self.server: + temp = NamedTemporaryFile(delete=False) + temp_path = Path(temp.name) + src_path = temp_path + self.server.remote_put(src_path, temp_path) + self.host_cmd(f"{PODMAN} cp {src_path} {self.name}:{dst_path}") + if mode is not None: + self.cmd(f"chmod {mode:o} {dst_path}") diff --git a/daemon/core/nodes/wireless.py b/daemon/core/nodes/wireless.py index ef37db35..51a98917 100644 --- a/daemon/core/nodes/wireless.py +++ b/daemon/core/nodes/wireless.py @@ -7,7 +7,7 @@ import logging import math import secrets from dataclasses import dataclass -from typing import TYPE_CHECKING, Dict, List, Set, Tuple +from typing import TYPE_CHECKING from core.config import ConfigBool, ConfigFloat, ConfigInt, Configuration from core.emulator.data import LinkData, LinkOptions @@ -41,7 +41,7 @@ KEY_LOSS: str = "loss" def calc_distance( - point1: Tuple[float, float, float], point2: Tuple[float, float, float] + point1: tuple[float, float, float], point2: tuple[float, float, float] ) -> float: a = point1[0] - point2[0] b = point1[1] - point2[1] @@ -51,7 +51,7 @@ def calc_distance( return math.hypot(math.hypot(a, b), c) -def get_key(node1_id: int, node2_id: int) -> Tuple[int, int]: +def get_key(node1_id: int, node2_id: int) -> tuple[int, int]: return (node1_id, node2_id) if node1_id < node2_id else (node2_id, node1_id) @@ -65,7 +65,7 @@ class WirelessLink: class WirelessNode(CoreNetworkBase): - options: List[Configuration] = [ + options: list[Configuration] = [ ConfigBool( id=KEY_ENABLED, default="1" if CONFIG_ENABLED else "0", label="Enabled?" ), @@ -87,7 +87,7 @@ class WirelessNode(CoreNetworkBase): ), ConfigFloat(id=KEY_LOSS, default=str(CONFIG_LOSS), label="Loss Initial"), ] - devices: Set[str] = set() + devices: set[str] = set() @classmethod def add_device(cls) -> str: @@ -111,8 +111,8 @@ class WirelessNode(CoreNetworkBase): options: NodeOptions = None, ): super().__init__(session, _id, name, server, options) - self.bridges: Dict[int, Tuple[CoreInterface, str]] = {} - self.links: Dict[Tuple[int, int], WirelessLink] = {} + self.bridges: dict[int, tuple[CoreInterface, str]] = {} + self.links: dict[tuple[int, int], WirelessLink] = {} self.position_enabled: bool = CONFIG_ENABLED self.bandwidth: int = CONFIG_BANDWIDTH self.delay: int = CONFIG_DELAY @@ -321,7 +321,7 @@ class WirelessNode(CoreNetworkBase): def adopt_iface(self, iface: CoreInterface, name: str) -> None: raise CoreError(f"{type(self)} does not support adopt interface") - def get_config(self) -> Dict[str, Configuration]: + def get_config(self) -> dict[str, Configuration]: config = {x.id: x for x in copy.copy(self.options)} config[KEY_ENABLED].default = "1" if self.position_enabled else "0" config[KEY_RANGE].default = str(self.max_range) @@ -333,7 +333,7 @@ class WirelessNode(CoreNetworkBase): config[KEY_JITTER].default = str(self.jitter) return config - def set_config(self, config: Dict[str, str]) -> None: + def set_config(self, config: dict[str, str]) -> None: logger.info("wireless config: %s", config) self.position_enabled = config[KEY_ENABLED] == "1" self.max_range = float(config[KEY_RANGE]) diff --git a/daemon/core/player.py b/daemon/core/player.py index 6ba0d602..d06e7b97 100644 --- a/daemon/core/player.py +++ b/daemon/core/player.py @@ -5,7 +5,7 @@ import logging import sched from pathlib import Path from threading import Thread -from typing import IO, Callable, Dict, Optional +from typing import IO, Callable, Optional import grpc @@ -230,7 +230,7 @@ class CorePlayer: self.node_streamer: Optional[MoveNodesStreamer] = None self.node_streamer_thread: Optional[Thread] = None self.scheduler: sched.scheduler = sched.scheduler() - self.handlers: Dict[PlayerEvents, Callable] = { + self.handlers: dict[PlayerEvents, Callable] = { PlayerEvents.XY: self.handle_xy, PlayerEvents.GEO: self.handle_geo, PlayerEvents.CMD: self.handle_cmd, diff --git a/daemon/core/plugins/sdt.py b/daemon/core/plugins/sdt.py index 48a6cdf0..f963c817 100644 --- a/daemon/core/plugins/sdt.py +++ b/daemon/core/plugins/sdt.py @@ -5,7 +5,7 @@ sdt.py: Scripted Display Tool (SDT3D) helper import logging import socket from pathlib import Path -from typing import TYPE_CHECKING, Dict, List, Optional, Set, Tuple, Type +from typing import TYPE_CHECKING, Optional from urllib.parse import urlparse from core.constants import CORE_CONF_DIR @@ -28,9 +28,9 @@ CORE_LAYER: str = "CORE" NODE_LAYER: str = "CORE::Nodes" LINK_LAYER: str = "CORE::Links" WIRED_LINK_LAYER: str = f"{LINK_LAYER}::wired" -CORE_LAYERS: List[str] = [CORE_LAYER, LINK_LAYER, NODE_LAYER, WIRED_LINK_LAYER] +CORE_LAYERS: list[str] = [CORE_LAYER, LINK_LAYER, NODE_LAYER, WIRED_LINK_LAYER] DEFAULT_LINK_COLOR: str = "red" -NODE_TYPES: Dict[Type[NodeBase], str] = { +NODE_TYPES: dict[type[NodeBase], str] = { HubNode: "hub", SwitchNode: "lanswitch", TunnelNode: "tunnel", @@ -63,7 +63,7 @@ class Sdt: # default altitude (in meters) for flyto view DEFAULT_ALT: int = 2500 # TODO: read in user"s nodes.conf here; below are default node types from the GUI - DEFAULT_SPRITES: Dict[str, str] = [ + DEFAULT_SPRITES: dict[str, str] = [ ("router", "router.png"), ("host", "host.png"), ("PC", "pc.png"), @@ -88,9 +88,9 @@ class Sdt: self.sock: Optional[socket.socket] = None self.connected: bool = False self.url: str = self.DEFAULT_SDT_URL - self.address: Optional[Tuple[Optional[str], Optional[int]]] = None + self.address: Optional[tuple[Optional[str], Optional[int]]] = None self.protocol: Optional[str] = None - self.network_layers: Set[str] = set() + self.network_layers: set[str] = set() self.session.node_handlers.append(self.handle_node_update) self.session.link_handlers.append(self.handle_link_update) @@ -138,7 +138,7 @@ class Sdt: else: # Default to tcp self.sock = socket.create_connection(self.address, 5) - except IOError: + except OSError: logger.exception("SDT socket connect error") return False @@ -176,7 +176,7 @@ class Sdt: if self.sock: try: self.sock.close() - except IOError: + except OSError: logger.error("error closing socket") finally: self.sock = None @@ -212,7 +212,7 @@ class Sdt: logger.debug("sdt cmd: %s", cmd) self.sock.sendall(cmd) return True - except IOError: + except OSError: logger.exception("SDT connection error") self.sock = None self.connected = False diff --git a/daemon/core/scripts/cleanup.py b/daemon/core/scripts/cleanup.py index 3606fc13..1ab4647e 100755 --- a/daemon/core/scripts/cleanup.py +++ b/daemon/core/scripts/cleanup.py @@ -61,7 +61,7 @@ def cleanup_sessions() -> None: def cleanup_interfaces() -> None: print("cleaning up devices") - output = subprocess.check_output("ip -o -br link show", shell=True) + output = subprocess.check_output("ip -br link show", shell=True) lines = output.decode().strip().split("\n") for line in lines: values = line.split() @@ -73,6 +73,7 @@ def cleanup_interfaces() -> None: or name.startswith("b.") or name.startswith("ctrl") ): + name = name.split("@")[0] result = subprocess.call(f"ip link delete {name}", shell=True) if result: print(f"failed to remove {name}") diff --git a/daemon/core/scripts/cli.py b/daemon/core/scripts/cli.py index 31ad086e..760dbad7 100755 --- a/daemon/core/scripts/cli.py +++ b/daemon/core/scripts/cli.py @@ -8,7 +8,7 @@ from argparse import ( ) from functools import wraps from pathlib import Path -from typing import Any, Dict, Optional, Tuple +from typing import Any, Optional import grpc import netaddr @@ -30,7 +30,7 @@ from core.api.grpc.wrappers import ( NODE_TYPES = [x.name for x in NodeType if x != NodeType.PEER_TO_PEER] -def protobuf_to_json(message: Any) -> Dict[str, Any]: +def protobuf_to_json(message: Any) -> dict[str, Any]: return MessageToDict( message, including_default_value_fields=True, preserving_proto_field_name=True ) @@ -82,7 +82,7 @@ def ip6_type(value: str) -> IPNetwork: raise ArgumentTypeError(f"invalid ip6 address: {value}") -def position_type(value: str) -> Tuple[float, float]: +def position_type(value: str) -> tuple[float, float]: error = "invalid position, must be in the format: float,float" try: values = [float(x) for x in value.split(",")] @@ -94,7 +94,7 @@ def position_type(value: str) -> Tuple[float, float]: return x, y -def geo_type(value: str) -> Tuple[float, float, float]: +def geo_type(value: str) -> tuple[float, float, float]: error = "invalid geo, must be in the format: float,float,float" try: values = [float(x) for x in value.split(",")] diff --git a/daemon/core/scripts/routemonitor.py b/daemon/core/scripts/routemonitor.py index 2ebfdfad..42fbf3a9 100755 --- a/daemon/core/scripts/routemonitor.py +++ b/daemon/core/scripts/routemonitor.py @@ -9,7 +9,6 @@ from argparse import ArgumentDefaultsHelpFormatter from functools import cmp_to_key from queue import Queue from threading import Thread -from typing import Dict, Tuple import grpc @@ -31,7 +30,7 @@ class RouteEnum(enum.Enum): class SdtClient: - def __init__(self, address: Tuple[str, int]) -> None: + def __init__(self, address: tuple[str, int]) -> None: self.sock = socket.create_connection(address) self.links = [] self.send(f'layer "{ROUTE_LAYER}"') @@ -85,7 +84,7 @@ class RouterMonitor: self.sdt = SdtClient((sdt_host, sdt_port)) self.nodes = self.get_nodes() - def get_nodes(self) -> Dict[int, str]: + def get_nodes(self) -> dict[int, str]: with self.core.context_connect(): if self.session is None: self.session = self.get_session() @@ -146,7 +145,7 @@ class RouterMonitor: self.manage_routes() self.route_time = time.monotonic() - def route_sort(self, x: Tuple[str, int], y: Tuple[str, int]) -> int: + def route_sort(self, x: tuple[str, int], y: tuple[str, int]) -> int: x_node = x[0] y_node = y[0] if x_node == self.src_id: diff --git a/daemon/core/services/bird.py b/daemon/core/services/bird.py index ffb177f3..c2ecc4dc 100644 --- a/daemon/core/services/bird.py +++ b/daemon/core/services/bird.py @@ -1,7 +1,7 @@ """ bird.py: defines routing services provided by the BIRD Internet Routing Daemon. """ -from typing import Optional, Tuple +from typing import Optional from core.nodes.base import CoreNode from core.services.coreservices import CoreService @@ -14,12 +14,12 @@ class Bird(CoreService): name: str = "bird" group: str = "BIRD" - executables: Tuple[str, ...] = ("bird",) - dirs: Tuple[str, ...] = ("/etc/bird",) - configs: Tuple[str, ...] = ("/etc/bird/bird.conf",) - startup: Tuple[str, ...] = ("bird -c %s" % (configs[0]),) - shutdown: Tuple[str, ...] = ("killall bird",) - validate: Tuple[str, ...] = ("pidof bird",) + executables: tuple[str, ...] = ("bird",) + dirs: tuple[str, ...] = ("/etc/bird",) + configs: tuple[str, ...] = ("/etc/bird/bird.conf",) + startup: tuple[str, ...] = (f"bird -c {configs[0]}",) + shutdown: tuple[str, ...] = ("killall bird",) + validate: tuple[str, ...] = ("pidof bird",) @classmethod def generate_config(cls, node: CoreNode, filename: str) -> str: @@ -48,33 +48,30 @@ class Bird(CoreService): Returns configuration file text. Other services that depend on bird will have hooks that are invoked here. """ - cfg = """\ + cfg = f"""\ /* Main configuration file for BIRD. This is ony a template, * you will *need* to customize it according to your needs * Beware that only double quotes \'"\' are valid. No singles. */ -log "/var/log/%s.log" all; +log "/var/log/{cls.name}.log" all; #debug protocols all; #debug commands 2; -router id %s; # Mandatory for IPv6, may be automatic for IPv4 +router id {cls.router_id(node)}; # Mandatory for IPv6, may be automatic for IPv4 -protocol kernel { +protocol kernel {{ persist; # Don\'t remove routes on BIRD shutdown scan time 200; # Scan kernel routing table every 200 seconds export all; import all; -} +}} -protocol device { +protocol device {{ scan time 10; # Scan interfaces every 10 seconds -} +}} -""" % ( - cls.name, - cls.router_id(node), - ) +""" # generate protocol specific configurations for s in node.services: @@ -94,8 +91,8 @@ class BirdService(CoreService): name: Optional[str] = None group: str = "BIRD" - executables: Tuple[str, ...] = ("bird",) - dependencies: Tuple[str, ...] = ("bird",) + executables: tuple[str, ...] = ("bird",) + dependencies: tuple[str, ...] = ("bird",) meta: str = "The config file for this service can be found in the bird service." @classmethod @@ -111,7 +108,7 @@ class BirdService(CoreService): """ cfg = "" for iface in node.get_ifaces(control=False): - cfg += ' interface "%s";\n' % iface.name + cfg += f' interface "{iface.name}";\n' return cfg diff --git a/daemon/core/services/coreservices.py b/daemon/core/services/coreservices.py index 6e52b5d6..0eee980e 100644 --- a/daemon/core/services/coreservices.py +++ b/daemon/core/services/coreservices.py @@ -11,18 +11,9 @@ import enum import logging import pkgutil import time +from collections.abc import Iterable from pathlib import Path -from typing import ( - TYPE_CHECKING, - Dict, - Iterable, - List, - Optional, - Set, - Tuple, - Type, - Union, -) +from typing import TYPE_CHECKING, Optional, Union from core import services as core_services from core import utils @@ -41,7 +32,7 @@ logger = logging.getLogger(__name__) if TYPE_CHECKING: from core.emulator.session import Session - CoreServiceType = Union["CoreService", Type["CoreService"]] + CoreServiceType = Union["CoreService", type["CoreService"]] class ServiceMode(enum.Enum): @@ -57,25 +48,25 @@ class ServiceDependencies: provided. """ - def __init__(self, services: List["CoreServiceType"]) -> None: - self.visited: Set[str] = set() - self.services: Dict[str, "CoreServiceType"] = {} - self.paths: Dict[str, List["CoreServiceType"]] = {} - self.boot_paths: List[List["CoreServiceType"]] = [] - roots = set([x.name for x in services]) + def __init__(self, services: list["CoreServiceType"]) -> None: + self.visited: set[str] = set() + self.services: dict[str, "CoreServiceType"] = {} + self.paths: dict[str, list["CoreServiceType"]] = {} + self.boot_paths: list[list["CoreServiceType"]] = [] + roots = {x.name for x in services} for service in services: self.services[service.name] = service roots -= set(service.dependencies) - self.roots: List["CoreServiceType"] = [x for x in services if x.name in roots] + self.roots: list["CoreServiceType"] = [x for x in services if x.name in roots] if services and not self.roots: raise ValueError("circular dependency is present") def _search( self, service: "CoreServiceType", - visiting: Set[str] = None, - path: List[str] = None, - ) -> List["CoreServiceType"]: + visiting: set[str] = None, + path: list[str] = None, + ) -> list["CoreServiceType"]: if service.name in self.visited: return self.paths[service.name] self.visited.add(service.name) @@ -103,7 +94,7 @@ class ServiceDependencies: self.paths[service.name] = path return path - def boot_order(self) -> List[List["CoreServiceType"]]: + def boot_order(self) -> list[list["CoreServiceType"]]: for service in self.roots: self._search(service) return self.boot_paths @@ -114,10 +105,10 @@ class ServiceManager: Manages services available for CORE nodes to use. """ - services: Dict[str, Type["CoreService"]] = {} + services: dict[str, type["CoreService"]] = {} @classmethod - def add(cls, service: Type["CoreService"]) -> None: + def add(cls, service: type["CoreService"]) -> None: """ Add a service to manager. @@ -150,7 +141,7 @@ class ServiceManager: cls.services[name] = service @classmethod - def get(cls, name: str) -> Type["CoreService"]: + def get(cls, name: str) -> type["CoreService"]: """ Retrieve a service from the manager. @@ -163,7 +154,7 @@ class ServiceManager: return service @classmethod - def add_services(cls, path: Path) -> List[str]: + def add_services(cls, path: Path) -> list[str]: """ Method for retrieving all CoreServices from a given path. @@ -183,7 +174,7 @@ class ServiceManager: return service_errors @classmethod - def load_locals(cls) -> List[str]: + def load_locals(cls) -> list[str]: errors = [] for module_info in pkgutil.walk_packages( core_services.__path__, f"{core_services.__name__}." @@ -218,7 +209,7 @@ class CoreServices: """ self.session: "Session" = session # dict of default services tuples, key is node type - self.default_services: Dict[str, List[str]] = { + self.default_services: dict[str, list[str]] = { "mdr": ["zebra", "OSPFv3MDR", "IPForward"], "PC": ["DefaultRoute"], "prouter": [], @@ -226,7 +217,7 @@ class CoreServices: "host": ["DefaultRoute", "SSH"], } # dict of node ids to dict of custom services by name - self.custom_services: Dict[int, Dict[str, "CoreService"]] = {} + self.custom_services: dict[int, dict[str, "CoreService"]] = {} def reset(self) -> None: """ @@ -273,7 +264,7 @@ class CoreServices: node_services[service.name] = service def add_services( - self, node: CoreNode, model: str, services: List[str] = None + self, node: CoreNode, model: str, services: list[str] = None ) -> None: """ Add services to a node. @@ -298,7 +289,7 @@ class CoreServices: continue node.services.append(service) - def all_configs(self) -> List[Tuple[int, "CoreService"]]: + def all_configs(self) -> list[tuple[int, "CoreService"]]: """ Return (node_id, service) tuples for all stored configs. Used when reconnecting to a session or opening XML. @@ -313,7 +304,7 @@ class CoreServices: configs.append((node_id, service)) return configs - def all_files(self, service: "CoreService") -> List[Tuple[str, str]]: + def all_files(self, service: "CoreService") -> list[tuple[str, str]]: """ Return all customized files stored with a service. Used when reconnecting to a session or opening XML. @@ -349,7 +340,7 @@ class CoreServices: if exceptions: raise CoreServiceBootError(*exceptions) - def _boot_service_path(self, node: CoreNode, boot_path: List["CoreServiceType"]): + def _boot_service_path(self, node: CoreNode, boot_path: list["CoreServiceType"]): logger.info( "booting node(%s) services: %s", node.name, @@ -400,7 +391,7 @@ class CoreServices: status = self.startup_service(node, service, wait) if status: raise CoreServiceBootError( - "node(%s) service(%s) error during startup" % (node.name, service.name) + f"node({node.name}) service({service.name}) error during startup" ) # blocking mode is finished @@ -425,7 +416,7 @@ class CoreServices: if status: raise CoreServiceBootError( - "node(%s) service(%s) failed validation" % (node.name, service.name) + f"node({node.name}) service({service.name}) failed validation" ) def copy_service_file(self, node: CoreNode, file_path: Path, cfg: str) -> bool: @@ -540,11 +531,11 @@ class CoreServices: # get the file data data = service.config_data.get(filename) if data is None: - data = "%s" % service.generate_config(node, filename) + data = service.generate_config(node, filename) else: - data = "%s" % data + data = data - filetypestr = "service:%s" % service.name + filetypestr = f"service:{service.name}" return FileData( message_type=MessageFlags.ADD, node=node.id, @@ -636,7 +627,7 @@ class CoreServices: try: if self.copy_service_file(node, file_path, cfg): continue - except IOError: + except OSError: logger.exception("error copying service file: %s", file_name) continue else: @@ -674,31 +665,31 @@ class CoreService: name: Optional[str] = None # executables that must exist for service to run - executables: Tuple[str, ...] = () + executables: tuple[str, ...] = () # sets service requirements that must be started prior to this service starting - dependencies: Tuple[str, ...] = () + dependencies: tuple[str, ...] = () # group string allows grouping services together group: Optional[str] = None # private, per-node directories required by this service - dirs: Tuple[str, ...] = () + dirs: tuple[str, ...] = () # config files written by this service - configs: Tuple[str, ...] = () + configs: tuple[str, ...] = () # config file data - config_data: Dict[str, str] = {} + config_data: dict[str, str] = {} # list of startup commands - startup: Tuple[str, ...] = () + startup: tuple[str, ...] = () # list of shutdown commands - shutdown: Tuple[str, ...] = () + shutdown: tuple[str, ...] = () # list of validate commands - validate: Tuple[str, ...] = () + validate: tuple[str, ...] = () # validation mode, used to determine startup success validation_mode: ServiceMode = ServiceMode.NON_BLOCKING @@ -723,7 +714,7 @@ class CoreService: configuration is used to override their default parameters. """ self.custom: bool = True - self.config_data: Dict[str, str] = self.__class__.config_data.copy() + self.config_data: dict[str, str] = self.__class__.config_data.copy() @classmethod def on_load(cls) -> None: @@ -742,7 +733,7 @@ class CoreService: return cls.configs @classmethod - def generate_config(cls, node: CoreNode, filename: str) -> None: + def generate_config(cls, node: CoreNode, filename: str) -> str: """ Generate configuration file given a node object. The filename is provided to allow for multiple config files. @@ -751,7 +742,7 @@ class CoreService: :param node: node to generate config for :param filename: file name to generate config for - :return: nothing + :return: generated config """ raise NotImplementedError diff --git a/daemon/core/services/emaneservices.py b/daemon/core/services/emaneservices.py index 4fd78ec1..43cd9af4 100644 --- a/daemon/core/services/emaneservices.py +++ b/daemon/core/services/emaneservices.py @@ -1,5 +1,3 @@ -from typing import Tuple - from core.emane.nodes import EmaneNet from core.nodes.base import CoreNode from core.services.coreservices import CoreService @@ -9,14 +7,14 @@ from core.xml import emanexml class EmaneTransportService(CoreService): name: str = "transportd" group: str = "EMANE" - executables: Tuple[str, ...] = ("emanetransportd", "emanegentransportxml") - dependencies: Tuple[str, ...] = () - dirs: Tuple[str, ...] = () - configs: Tuple[str, ...] = ("emanetransport.sh",) - startup: Tuple[str, ...] = (f"bash {configs[0]}",) - validate: Tuple[str, ...] = (f"pidof {executables[0]}",) + executables: tuple[str, ...] = ("emanetransportd", "emanegentransportxml") + dependencies: tuple[str, ...] = () + dirs: tuple[str, ...] = () + configs: tuple[str, ...] = ("emanetransport.sh",) + startup: tuple[str, ...] = (f"bash {configs[0]}",) + validate: tuple[str, ...] = (f"pidof {executables[0]}",) validation_timer: float = 0.5 - shutdown: Tuple[str, ...] = (f"killall {executables[0]}",) + shutdown: tuple[str, ...] = (f"killall {executables[0]}",) @classmethod def generate_config(cls, node: CoreNode, filename: str) -> str: diff --git a/daemon/core/services/frr.py b/daemon/core/services/frr.py index 5fbacf42..28756c19 100644 --- a/daemon/core/services/frr.py +++ b/daemon/core/services/frr.py @@ -2,7 +2,7 @@ frr.py: defines routing services provided by FRRouting. Assumes installation of FRR via https://deb.frrouting.org/ """ -from typing import Optional, Tuple +from typing import Optional import netaddr @@ -30,16 +30,16 @@ def is_wireless(node: NodeBase) -> bool: class FRRZebra(CoreService): name: str = "FRRzebra" group: str = "FRR" - dirs: Tuple[str, ...] = ("/usr/local/etc/frr", "/var/run/frr", "/var/log/frr") - configs: Tuple[str, ...] = ( + dirs: tuple[str, ...] = ("/usr/local/etc/frr", "/var/run/frr", "/var/log/frr") + configs: tuple[str, ...] = ( "/usr/local/etc/frr/frr.conf", "frrboot.sh", "/usr/local/etc/frr/vtysh.conf", "/usr/local/etc/frr/daemons", ) - startup: Tuple[str, ...] = ("bash frrboot.sh zebra",) - shutdown: Tuple[str, ...] = ("killall zebra",) - validate: Tuple[str, ...] = ("pidof zebra",) + startup: tuple[str, ...] = ("bash frrboot.sh zebra",) + shutdown: tuple[str, ...] = ("killall zebra",) + validate: tuple[str, ...] = ("pidof zebra",) @classmethod def generate_config(cls, node: CoreNode, filename: str) -> str: @@ -75,7 +75,7 @@ class FRRZebra(CoreService): # we could verify here that filename == frr.conf cfg = "" for iface in node.get_ifaces(): - cfg += "interface %s\n" % iface.name + cfg += f"interface {iface.name}\n" # include control interfaces in addressing but not routing daemons if iface.control: cfg += " " @@ -127,11 +127,11 @@ class FRRZebra(CoreService): """ address = str(ip.ip) if netaddr.valid_ipv4(address): - return "ip address %s" % ip + return f"ip address {ip}" elif netaddr.valid_ipv6(address): - return "ipv6 address %s" % ip + return f"ipv6 address {ip}" else: - raise ValueError("invalid address: %s", ip) + raise ValueError(f"invalid address: {ip}") @classmethod def generate_frr_boot(cls, node: CoreNode) -> str: @@ -142,18 +142,19 @@ class FRRZebra(CoreService): "frr_bin_search", '"/usr/local/bin /usr/bin /usr/lib/frr"' ) frr_sbin_search = node.session.options.get( - "frr_sbin_search", '"/usr/local/sbin /usr/sbin /usr/lib/frr"' + "frr_sbin_search", + '"/usr/local/sbin /usr/sbin /usr/lib/frr /usr/libexec/frr"', ) - cfg = """\ + cfg = f"""\ #!/bin/sh # auto-generated by zebra service (frr.py) -FRR_CONF=%s -FRR_SBIN_SEARCH=%s -FRR_BIN_SEARCH=%s -FRR_STATE_DIR=%s +FRR_CONF={cls.configs[0]} +FRR_SBIN_SEARCH={frr_sbin_search} +FRR_BIN_SEARCH={frr_bin_search} +FRR_STATE_DIR={FRR_STATE_DIR} searchforprog() -{ +{{ prog=$1 searchpath=$@ ret= @@ -164,10 +165,10 @@ searchforprog() fi done echo $ret -} +}} confcheck() -{ +{{ CONF_DIR=`dirname $FRR_CONF` # if /etc/frr exists, point /etc/frr/frr.conf -> CONF_DIR if [ "$CONF_DIR" != "/etc/frr" ] && [ -d /etc/frr ] && [ ! -e /etc/frr/frr.conf ]; then @@ -177,10 +178,10 @@ confcheck() if [ "$CONF_DIR" != "/etc/frr" ] && [ -d /etc/frr ] && [ ! -e /etc/frr/vtysh.conf ]; then ln -s $CONF_DIR/vtysh.conf /etc/frr/vtysh.conf fi -} +}} bootdaemon() -{ +{{ FRR_SBIN_DIR=$(searchforprog $1 $FRR_SBIN_SEARCH) if [ "z$FRR_SBIN_DIR" = "z" ]; then echo "ERROR: FRR's '$1' daemon not found in search path:" @@ -207,10 +208,10 @@ bootdaemon() echo "ERROR: FRR's '$1' daemon failed to start!:" return 1 fi -} +}} bootfrr() -{ +{{ FRR_BIN_DIR=$(searchforprog 'vtysh' $FRR_BIN_SEARCH) if [ "z$FRR_BIN_DIR" = "z" ]; then echo "ERROR: FRR's 'vtysh' program not found in search path:" @@ -229,8 +230,8 @@ bootfrr() bootdaemon "staticd" fi for r in rip ripng ospf6 ospf bgp babel isis; do - if grep -q "^router \\<${r}\\>" $FRR_CONF; then - bootdaemon "${r}d" + if grep -q "^router \\<${{r}}\\>" $FRR_CONF; then + bootdaemon "${{r}}d" fi done @@ -239,7 +240,7 @@ bootfrr() fi $FRR_BIN_DIR/vtysh -b -} +}} if [ "$1" != "zebra" ]; then echo "WARNING: '$1': all FRR daemons are launched by the 'zebra' service!" @@ -248,12 +249,7 @@ fi confcheck bootfrr -""" % ( - cls.configs[0], - frr_sbin_search, - frr_bin_search, - FRR_STATE_DIR, - ) +""" for iface in node.get_ifaces(): cfg += f"ip link set dev {iface.name} down\n" cfg += "sleep 1\n" @@ -337,7 +333,7 @@ class FrrService(CoreService): name: Optional[str] = None group: str = "FRR" - dependencies: Tuple[str, ...] = ("FRRzebra",) + dependencies: tuple[str, ...] = ("FRRzebra",) meta: str = "The config file for this service can be found in the Zebra service." ipv4_routing: bool = False ipv6_routing: bool = False @@ -388,8 +384,8 @@ class FRROspfv2(FrrService): """ name: str = "FRROSPFv2" - shutdown: Tuple[str, ...] = ("killall ospfd",) - validate: Tuple[str, ...] = ("pidof ospfd",) + shutdown: tuple[str, ...] = ("killall ospfd",) + validate: tuple[str, ...] = ("pidof ospfd",) ipv4_routing: bool = True @staticmethod @@ -424,7 +420,7 @@ class FRROspfv2(FrrService): def generate_frr_config(cls, node: CoreNode) -> str: cfg = "router ospf\n" rtrid = cls.router_id(node) - cfg += " router-id %s\n" % rtrid + cfg += f" router-id {rtrid}\n" # network 10.0.0.0/24 area 0 for iface in node.get_ifaces(control=False): for ip4 in iface.ip4s: @@ -458,8 +454,8 @@ class FRROspfv3(FrrService): """ name: str = "FRROSPFv3" - shutdown: Tuple[str, ...] = ("killall ospf6d",) - validate: Tuple[str, ...] = ("pidof ospf6d",) + shutdown: tuple[str, ...] = ("killall ospf6d",) + validate: tuple[str, ...] = ("pidof ospf6d",) ipv4_routing: bool = True ipv6_routing: bool = True @@ -486,7 +482,7 @@ class FRROspfv3(FrrService): """ minmtu = cls.min_mtu(iface) if minmtu < iface.mtu: - return " ipv6 ospf6 ifmtu %d\n" % minmtu + return f" ipv6 ospf6 ifmtu {minmtu:d}\n" else: return "" @@ -504,9 +500,9 @@ class FRROspfv3(FrrService): def generate_frr_config(cls, node: CoreNode) -> str: cfg = "router ospf6\n" rtrid = cls.router_id(node) - cfg += " router-id %s\n" % rtrid + cfg += f" router-id {rtrid}\n" for iface in node.get_ifaces(control=False): - cfg += " interface %s area 0.0.0.0\n" % iface.name + cfg += f" interface {iface.name} area 0.0.0.0\n" cfg += "!\n" return cfg @@ -523,8 +519,8 @@ class FRRBgp(FrrService): """ name: str = "FRRBGP" - shutdown: Tuple[str, ...] = ("killall bgpd",) - validate: Tuple[str, ...] = ("pidof bgpd",) + shutdown: tuple[str, ...] = ("killall bgpd",) + validate: tuple[str, ...] = ("pidof bgpd",) custom_needed: bool = True ipv4_routing: bool = True ipv6_routing: bool = True @@ -534,9 +530,9 @@ class FRRBgp(FrrService): cfg = "!\n! BGP configuration\n!\n" cfg += "! You should configure the AS number below,\n" cfg += "! along with this router's peers.\n!\n" - cfg += "router bgp %s\n" % node.id + cfg += f"router bgp {node.id}\n" rtrid = cls.router_id(node) - cfg += " bgp router-id %s\n" % rtrid + cfg += f" bgp router-id {rtrid}\n" cfg += " redistribute connected\n" cfg += "! neighbor 1.2.3.4 remote-as 555\n!\n" return cfg @@ -548,8 +544,8 @@ class FRRRip(FrrService): """ name: str = "FRRRIP" - shutdown: Tuple[str, ...] = ("killall ripd",) - validate: Tuple[str, ...] = ("pidof ripd",) + shutdown: tuple[str, ...] = ("killall ripd",) + validate: tuple[str, ...] = ("pidof ripd",) ipv4_routing: bool = True @classmethod @@ -571,8 +567,8 @@ class FRRRipng(FrrService): """ name: str = "FRRRIPNG" - shutdown: Tuple[str, ...] = ("killall ripngd",) - validate: Tuple[str, ...] = ("pidof ripngd",) + shutdown: tuple[str, ...] = ("killall ripngd",) + validate: tuple[str, ...] = ("pidof ripngd",) ipv6_routing: bool = True @classmethod @@ -595,15 +591,15 @@ class FRRBabel(FrrService): """ name: str = "FRRBabel" - shutdown: Tuple[str, ...] = ("killall babeld",) - validate: Tuple[str, ...] = ("pidof babeld",) + shutdown: tuple[str, ...] = ("killall babeld",) + validate: tuple[str, ...] = ("pidof babeld",) ipv6_routing: bool = True @classmethod def generate_frr_config(cls, node: CoreNode) -> str: cfg = "router babel\n" for iface in node.get_ifaces(control=False): - cfg += " network %s\n" % iface.name + cfg += f" network {iface.name}\n" cfg += " redistribute static\n redistribute ipv4 connected\n" return cfg @@ -621,8 +617,8 @@ class FRRpimd(FrrService): """ name: str = "FRRpimd" - shutdown: Tuple[str, ...] = ("killall pimd",) - validate: Tuple[str, ...] = ("pidof pimd",) + shutdown: tuple[str, ...] = ("killall pimd",) + validate: tuple[str, ...] = ("pidof pimd",) ipv4_routing: bool = True @classmethod @@ -636,8 +632,8 @@ class FRRpimd(FrrService): cfg += "router igmp\n!\n" cfg += "router pim\n" cfg += " !ip pim rp-address 10.0.0.1\n" - cfg += " ip pim bsr-candidate %s\n" % ifname - cfg += " ip pim rp-candidate %s\n" % ifname + cfg += f" ip pim bsr-candidate {ifname}\n" + cfg += f" ip pim rp-candidate {ifname}\n" cfg += " !ip pim spt-threshold interval 10 bytes 80000\n" return cfg @@ -654,8 +650,8 @@ class FRRIsis(FrrService): """ name: str = "FRRISIS" - shutdown: Tuple[str, ...] = ("killall isisd",) - validate: Tuple[str, ...] = ("pidof isisd",) + shutdown: tuple[str, ...] = ("killall isisd",) + validate: tuple[str, ...] = ("pidof isisd",) ipv4_routing: bool = True ipv6_routing: bool = True @@ -672,7 +668,7 @@ class FRRIsis(FrrService): @classmethod def generate_frr_config(cls, node: CoreNode) -> str: cfg = "router isis DEFAULT\n" - cfg += " net 47.0001.0000.1900.%04x.00\n" % node.id + cfg += f" net 47.0001.0000.1900.{node.id:04x}.00\n" cfg += " metric-style wide\n" cfg += " is-type level-2-only\n" cfg += "!\n" diff --git a/daemon/core/services/nrl.py b/daemon/core/services/nrl.py index 9ef4e1d8..32e19f60 100644 --- a/daemon/core/services/nrl.py +++ b/daemon/core/services/nrl.py @@ -2,7 +2,7 @@ nrl.py: defines services provided by NRL protolib tools hosted here: http://www.nrl.navy.mil/itd/ncs/products """ -from typing import Optional, Tuple +from typing import Optional from core import utils from core.nodes.base import CoreNode @@ -33,29 +33,29 @@ class NrlService(CoreService): ip4 = iface.get_ip4() if ip4: return f"{ip4.ip}/{prefixlen}" - return "0.0.0.0/%s" % prefixlen + return f"0.0.0.0/{prefixlen}" class MgenSinkService(NrlService): name: str = "MGEN_Sink" - executables: Tuple[str, ...] = ("mgen",) - configs: Tuple[str, ...] = ("sink.mgen",) - startup: Tuple[str, ...] = ("mgen input sink.mgen",) - validate: Tuple[str, ...] = ("pidof mgen",) - shutdown: Tuple[str, ...] = ("killall mgen",) + executables: tuple[str, ...] = ("mgen",) + configs: tuple[str, ...] = ("sink.mgen",) + startup: tuple[str, ...] = ("mgen input sink.mgen",) + validate: tuple[str, ...] = ("pidof mgen",) + shutdown: tuple[str, ...] = ("killall mgen",) @classmethod def generate_config(cls, node: CoreNode, filename: str) -> str: cfg = "0.0 LISTEN UDP 5000\n" for iface in node.get_ifaces(): name = utils.sysctl_devname(iface.name) - cfg += "0.0 Join 224.225.1.2 INTERFACE %s\n" % name + cfg += f"0.0 Join 224.225.1.2 INTERFACE {name}\n" return cfg @classmethod - def get_startup(cls, node: CoreNode) -> Tuple[str, ...]: + def get_startup(cls, node: CoreNode) -> tuple[str, ...]: cmd = cls.startup[0] - cmd += " output /tmp/mgen_%s.log" % node.name + cmd += f" output /tmp/mgen_{node.name}.log" return (cmd,) @@ -65,23 +65,23 @@ class NrlNhdp(NrlService): """ name: str = "NHDP" - executables: Tuple[str, ...] = ("nrlnhdp",) - startup: Tuple[str, ...] = ("nrlnhdp",) - shutdown: Tuple[str, ...] = ("killall nrlnhdp",) - validate: Tuple[str, ...] = ("pidof nrlnhdp",) + executables: tuple[str, ...] = ("nrlnhdp",) + startup: tuple[str, ...] = ("nrlnhdp",) + shutdown: tuple[str, ...] = ("killall nrlnhdp",) + validate: tuple[str, ...] = ("pidof nrlnhdp",) @classmethod - def get_startup(cls, node: CoreNode) -> Tuple[str, ...]: + def get_startup(cls, node: CoreNode) -> tuple[str, ...]: """ Generate the appropriate command-line based on node interfaces. """ cmd = cls.startup[0] cmd += " -l /var/log/nrlnhdp.log" - cmd += " -rpipe %s_nhdp" % node.name + cmd += f" -rpipe {node.name}_nhdp" servicenames = map(lambda x: x.name, node.services) if "SMF" in servicenames: cmd += " -flooding ecds" - cmd += " -smfClient %s_smf" % node.name + cmd += f" -smfClient {node.name}_smf" ifaces = node.get_ifaces(control=False) if len(ifaces) > 0: iface_names = map(lambda x: x.name, ifaces) @@ -96,11 +96,11 @@ class NrlSmf(NrlService): """ name: str = "SMF" - executables: Tuple[str, ...] = ("nrlsmf",) - startup: Tuple[str, ...] = ("bash startsmf.sh",) - shutdown: Tuple[str, ...] = ("killall nrlsmf",) - validate: Tuple[str, ...] = ("pidof nrlsmf",) - configs: Tuple[str, ...] = ("startsmf.sh",) + executables: tuple[str, ...] = ("nrlsmf",) + startup: tuple[str, ...] = ("bash startsmf.sh",) + shutdown: tuple[str, ...] = ("killall nrlsmf",) + validate: tuple[str, ...] = ("pidof nrlsmf",) + configs: tuple[str, ...] = ("startsmf.sh",) @classmethod def generate_config(cls, node: CoreNode, filename: str) -> str: @@ -112,7 +112,7 @@ class NrlSmf(NrlService): cfg = "#!/bin/sh\n" cfg += "# auto-generated by nrl.py:NrlSmf.generateconfig()\n" comments = "" - cmd = "nrlsmf instance %s_smf" % node.name + cmd = f"nrlsmf instance {node.name}_smf" servicenames = map(lambda x: x.name, node.services) ifaces = node.get_ifaces(control=False) @@ -142,13 +142,13 @@ class NrlOlsr(NrlService): """ name: str = "OLSR" - executables: Tuple[str, ...] = ("nrlolsrd",) - startup: Tuple[str, ...] = ("nrlolsrd",) - shutdown: Tuple[str, ...] = ("killall nrlolsrd",) - validate: Tuple[str, ...] = ("pidof nrlolsrd",) + executables: tuple[str, ...] = ("nrlolsrd",) + startup: tuple[str, ...] = ("nrlolsrd",) + shutdown: tuple[str, ...] = ("killall nrlolsrd",) + validate: tuple[str, ...] = ("pidof nrlolsrd",) @classmethod - def get_startup(cls, node: CoreNode) -> Tuple[str, ...]: + def get_startup(cls, node: CoreNode) -> tuple[str, ...]: """ Generate the appropriate command-line based on node interfaces. """ @@ -157,13 +157,13 @@ class NrlOlsr(NrlService): ifaces = node.get_ifaces() if len(ifaces) > 0: iface = ifaces[0] - cmd += " -i %s" % iface.name + cmd += f" -i {iface.name}" cmd += " -l /var/log/nrlolsrd.log" - cmd += " -rpipe %s_olsr" % node.name + cmd += f" -rpipe {node.name}_olsr" servicenames = map(lambda x: x.name, node.services) if "SMF" in servicenames and "NHDP" not in servicenames: cmd += " -flooding s-mpr" - cmd += " -smfClient %s_smf" % node.name + cmd += f" -smfClient {node.name}_smf" if "zebra" in servicenames: cmd += " -z" return (cmd,) @@ -175,23 +175,23 @@ class NrlOlsrv2(NrlService): """ name: str = "OLSRv2" - executables: Tuple[str, ...] = ("nrlolsrv2",) - startup: Tuple[str, ...] = ("nrlolsrv2",) - shutdown: Tuple[str, ...] = ("killall nrlolsrv2",) - validate: Tuple[str, ...] = ("pidof nrlolsrv2",) + executables: tuple[str, ...] = ("nrlolsrv2",) + startup: tuple[str, ...] = ("nrlolsrv2",) + shutdown: tuple[str, ...] = ("killall nrlolsrv2",) + validate: tuple[str, ...] = ("pidof nrlolsrv2",) @classmethod - def get_startup(cls, node: CoreNode) -> Tuple[str, ...]: + def get_startup(cls, node: CoreNode) -> tuple[str, ...]: """ Generate the appropriate command-line based on node interfaces. """ cmd = cls.startup[0] cmd += " -l /var/log/nrlolsrv2.log" - cmd += " -rpipe %s_olsrv2" % node.name + cmd += f" -rpipe {node.name}_olsrv2" servicenames = map(lambda x: x.name, node.services) if "SMF" in servicenames: cmd += " -flooding ecds" - cmd += " -smfClient %s_smf" % node.name + cmd += f" -smfClient {node.name}_smf" cmd += " -p olsr" ifaces = node.get_ifaces(control=False) if len(ifaces) > 0: @@ -207,15 +207,15 @@ class OlsrOrg(NrlService): """ name: str = "OLSRORG" - executables: Tuple[str, ...] = ("olsrd",) - configs: Tuple[str, ...] = ("/etc/olsrd/olsrd.conf",) - dirs: Tuple[str, ...] = ("/etc/olsrd",) - startup: Tuple[str, ...] = ("olsrd",) - shutdown: Tuple[str, ...] = ("killall olsrd",) - validate: Tuple[str, ...] = ("pidof olsrd",) + executables: tuple[str, ...] = ("olsrd",) + configs: tuple[str, ...] = ("/etc/olsrd/olsrd.conf",) + dirs: tuple[str, ...] = ("/etc/olsrd",) + startup: tuple[str, ...] = ("olsrd",) + shutdown: tuple[str, ...] = ("killall olsrd",) + validate: tuple[str, ...] = ("pidof olsrd",) @classmethod - def get_startup(cls, node: CoreNode) -> Tuple[str, ...]: + def get_startup(cls, node: CoreNode) -> tuple[str, ...]: """ Generate the appropriate command-line based on node interfaces. """ @@ -558,11 +558,11 @@ class MgenActor(NrlService): # a unique name is required, without spaces name: str = "MgenActor" group: str = "ProtoSvc" - executables: Tuple[str, ...] = ("mgen",) - configs: Tuple[str, ...] = ("start_mgen_actor.sh",) - startup: Tuple[str, ...] = ("bash start_mgen_actor.sh",) - validate: Tuple[str, ...] = ("pidof mgen",) - shutdown: Tuple[str, ...] = ("killall mgen",) + executables: tuple[str, ...] = ("mgen",) + configs: tuple[str, ...] = ("start_mgen_actor.sh",) + startup: tuple[str, ...] = ("bash start_mgen_actor.sh",) + validate: tuple[str, ...] = ("pidof mgen",) + shutdown: tuple[str, ...] = ("killall mgen",) @classmethod def generate_config(cls, node: CoreNode, filename: str) -> str: @@ -574,7 +574,7 @@ class MgenActor(NrlService): cfg = "#!/bin/sh\n" cfg += "# auto-generated by nrl.py:MgenActor.generateconfig()\n" comments = "" - cmd = "mgenBasicActor.py -n %s -a 0.0.0.0" % node.name + cmd = f"mgenBasicActor.py -n {node.name} -a 0.0.0.0" ifaces = node.get_ifaces(control=False) if len(ifaces) == 0: return "" diff --git a/daemon/core/services/quagga.py b/daemon/core/services/quagga.py index a2f06bec..b96a8eae 100644 --- a/daemon/core/services/quagga.py +++ b/daemon/core/services/quagga.py @@ -1,7 +1,7 @@ """ quagga.py: defines routing services provided by Quagga. """ -from typing import Optional, Tuple +from typing import Optional import netaddr @@ -29,15 +29,15 @@ def is_wireless(node: NodeBase) -> bool: class Zebra(CoreService): name: str = "zebra" group: str = "Quagga" - dirs: Tuple[str, ...] = ("/usr/local/etc/quagga", "/var/run/quagga") - configs: Tuple[str, ...] = ( + dirs: tuple[str, ...] = ("/usr/local/etc/quagga", "/var/run/quagga") + configs: tuple[str, ...] = ( "/usr/local/etc/quagga/Quagga.conf", "quaggaboot.sh", "/usr/local/etc/quagga/vtysh.conf", ) - startup: Tuple[str, ...] = ("bash quaggaboot.sh zebra",) - shutdown: Tuple[str, ...] = ("killall zebra",) - validate: Tuple[str, ...] = ("pidof zebra",) + startup: tuple[str, ...] = ("bash quaggaboot.sh zebra",) + shutdown: tuple[str, ...] = ("killall zebra",) + validate: tuple[str, ...] = ("pidof zebra",) @classmethod def generate_config(cls, node: CoreNode, filename: str) -> str: @@ -71,7 +71,7 @@ class Zebra(CoreService): # we could verify here that filename == Quagga.conf cfg = "" for iface in node.get_ifaces(): - cfg += "interface %s\n" % iface.name + cfg += f"interface {iface.name}\n" # include control interfaces in addressing but not routing daemons if iface.control: cfg += " " @@ -123,11 +123,11 @@ class Zebra(CoreService): """ address = str(ip.ip) if netaddr.valid_ipv4(address): - return "ip address %s" % ip + return f"ip address {ip}" elif netaddr.valid_ipv6(address): - return "ipv6 address %s" % ip + return f"ipv6 address {ip}" else: - raise ValueError("invalid address: %s", ip) + raise ValueError(f"invalid address: {ip}") @classmethod def generate_quagga_boot(cls, node: CoreNode) -> str: @@ -140,16 +140,16 @@ class Zebra(CoreService): quagga_sbin_search = node.session.options.get( "quagga_sbin_search", '"/usr/local/sbin /usr/sbin /usr/lib/quagga"' ) - return """\ + return f"""\ #!/bin/sh # auto-generated by zebra service (quagga.py) -QUAGGA_CONF=%s -QUAGGA_SBIN_SEARCH=%s -QUAGGA_BIN_SEARCH=%s -QUAGGA_STATE_DIR=%s +QUAGGA_CONF={cls.configs[0]} +QUAGGA_SBIN_SEARCH={quagga_sbin_search} +QUAGGA_BIN_SEARCH={quagga_bin_search} +QUAGGA_STATE_DIR={QUAGGA_STATE_DIR} searchforprog() -{ +{{ prog=$1 searchpath=$@ ret= @@ -160,10 +160,10 @@ searchforprog() fi done echo $ret -} +}} confcheck() -{ +{{ CONF_DIR=`dirname $QUAGGA_CONF` # if /etc/quagga exists, point /etc/quagga/Quagga.conf -> CONF_DIR if [ "$CONF_DIR" != "/etc/quagga" ] && [ -d /etc/quagga ] && [ ! -e /etc/quagga/Quagga.conf ]; then @@ -173,10 +173,10 @@ confcheck() if [ "$CONF_DIR" != "/etc/quagga" ] && [ -d /etc/quagga ] && [ ! -e /etc/quagga/vtysh.conf ]; then ln -s $CONF_DIR/vtysh.conf /etc/quagga/vtysh.conf fi -} +}} bootdaemon() -{ +{{ QUAGGA_SBIN_DIR=$(searchforprog $1 $QUAGGA_SBIN_SEARCH) if [ "z$QUAGGA_SBIN_DIR" = "z" ]; then echo "ERROR: Quagga's '$1' daemon not found in search path:" @@ -196,10 +196,10 @@ bootdaemon() echo "ERROR: Quagga's '$1' daemon failed to start!:" return 1 fi -} +}} bootquagga() -{ +{{ QUAGGA_BIN_DIR=$(searchforprog 'vtysh' $QUAGGA_BIN_SEARCH) if [ "z$QUAGGA_BIN_DIR" = "z" ]; then echo "ERROR: Quagga's 'vtysh' program not found in search path:" @@ -215,8 +215,8 @@ bootquagga() bootdaemon "zebra" for r in rip ripng ospf6 ospf bgp babel; do - if grep -q "^router \\<${r}\\>" $QUAGGA_CONF; then - bootdaemon "${r}d" + if grep -q "^router \\<${{r}}\\>" $QUAGGA_CONF; then + bootdaemon "${{r}}d" fi done @@ -225,7 +225,7 @@ bootquagga() fi $QUAGGA_BIN_DIR/vtysh -b -} +}} if [ "$1" != "zebra" ]; then echo "WARNING: '$1': all Quagga daemons are launched by the 'zebra' service!" @@ -233,12 +233,7 @@ if [ "$1" != "zebra" ]; then fi confcheck bootquagga -""" % ( - cls.configs[0], - quagga_sbin_search, - quagga_bin_search, - QUAGGA_STATE_DIR, - ) +""" class QuaggaService(CoreService): @@ -249,7 +244,7 @@ class QuaggaService(CoreService): name: Optional[str] = None group: str = "Quagga" - dependencies: Tuple[str, ...] = (Zebra.name,) + dependencies: tuple[str, ...] = (Zebra.name,) meta: str = "The config file for this service can be found in the Zebra service." ipv4_routing: bool = False ipv6_routing: bool = False @@ -300,8 +295,8 @@ class Ospfv2(QuaggaService): """ name: str = "OSPFv2" - shutdown: Tuple[str, ...] = ("killall ospfd",) - validate: Tuple[str, ...] = ("pidof ospfd",) + shutdown: tuple[str, ...] = ("killall ospfd",) + validate: tuple[str, ...] = ("pidof ospfd",) ipv4_routing: bool = True @staticmethod @@ -336,7 +331,7 @@ class Ospfv2(QuaggaService): def generate_quagga_config(cls, node: CoreNode) -> str: cfg = "router ospf\n" rtrid = cls.router_id(node) - cfg += " router-id %s\n" % rtrid + cfg += f" router-id {rtrid}\n" # network 10.0.0.0/24 area 0 for iface in node.get_ifaces(control=False): for ip4 in iface.ip4s: @@ -369,8 +364,8 @@ class Ospfv3(QuaggaService): """ name: str = "OSPFv3" - shutdown: Tuple[str, ...] = ("killall ospf6d",) - validate: Tuple[str, ...] = ("pidof ospf6d",) + shutdown: tuple[str, ...] = ("killall ospf6d",) + validate: tuple[str, ...] = ("pidof ospf6d",) ipv4_routing: bool = True ipv6_routing: bool = True @@ -397,7 +392,7 @@ class Ospfv3(QuaggaService): """ minmtu = cls.min_mtu(iface) if minmtu < iface.mtu: - return " ipv6 ospf6 ifmtu %d\n" % minmtu + return f" ipv6 ospf6 ifmtu {minmtu:d}\n" else: return "" @@ -416,9 +411,9 @@ class Ospfv3(QuaggaService): cfg = "router ospf6\n" rtrid = cls.router_id(node) cfg += " instance-id 65\n" - cfg += " router-id %s\n" % rtrid + cfg += f" router-id {rtrid}\n" for iface in node.get_ifaces(control=False): - cfg += " interface %s area 0.0.0.0\n" % iface.name + cfg += f" interface {iface.name} area 0.0.0.0\n" cfg += "!\n" return cfg @@ -466,8 +461,8 @@ class Bgp(QuaggaService): """ name: str = "BGP" - shutdown: Tuple[str, ...] = ("killall bgpd",) - validate: Tuple[str, ...] = ("pidof bgpd",) + shutdown: tuple[str, ...] = ("killall bgpd",) + validate: tuple[str, ...] = ("pidof bgpd",) custom_needed: bool = True ipv4_routing: bool = True ipv6_routing: bool = True @@ -477,9 +472,9 @@ class Bgp(QuaggaService): cfg = "!\n! BGP configuration\n!\n" cfg += "! You should configure the AS number below,\n" cfg += "! along with this router's peers.\n!\n" - cfg += "router bgp %s\n" % node.id + cfg += f"router bgp {node.id}\n" rtrid = cls.router_id(node) - cfg += " bgp router-id %s\n" % rtrid + cfg += f" bgp router-id {rtrid}\n" cfg += " redistribute connected\n" cfg += "! neighbor 1.2.3.4 remote-as 555\n!\n" return cfg @@ -491,8 +486,8 @@ class Rip(QuaggaService): """ name: str = "RIP" - shutdown: Tuple[str, ...] = ("killall ripd",) - validate: Tuple[str, ...] = ("pidof ripd",) + shutdown: tuple[str, ...] = ("killall ripd",) + validate: tuple[str, ...] = ("pidof ripd",) ipv4_routing: bool = True @classmethod @@ -514,8 +509,8 @@ class Ripng(QuaggaService): """ name: str = "RIPNG" - shutdown: Tuple[str, ...] = ("killall ripngd",) - validate: Tuple[str, ...] = ("pidof ripngd",) + shutdown: tuple[str, ...] = ("killall ripngd",) + validate: tuple[str, ...] = ("pidof ripngd",) ipv6_routing: bool = True @classmethod @@ -538,15 +533,15 @@ class Babel(QuaggaService): """ name: str = "Babel" - shutdown: Tuple[str, ...] = ("killall babeld",) - validate: Tuple[str, ...] = ("pidof babeld",) + shutdown: tuple[str, ...] = ("killall babeld",) + validate: tuple[str, ...] = ("pidof babeld",) ipv6_routing: bool = True @classmethod def generate_quagga_config(cls, node: CoreNode) -> str: cfg = "router babel\n" for iface in node.get_ifaces(control=False): - cfg += " network %s\n" % iface.name + cfg += f" network {iface.name}\n" cfg += " redistribute static\n redistribute connected\n" return cfg @@ -564,8 +559,8 @@ class Xpimd(QuaggaService): """ name: str = "Xpimd" - shutdown: Tuple[str, ...] = ("killall xpimd",) - validate: Tuple[str, ...] = ("pidof xpimd",) + shutdown: tuple[str, ...] = ("killall xpimd",) + validate: tuple[str, ...] = ("pidof xpimd",) ipv4_routing: bool = True @classmethod @@ -579,8 +574,8 @@ class Xpimd(QuaggaService): cfg += "router igmp\n!\n" cfg += "router pim\n" cfg += " !ip pim rp-address 10.0.0.1\n" - cfg += " ip pim bsr-candidate %s\n" % ifname - cfg += " ip pim rp-candidate %s\n" % ifname + cfg += f" ip pim bsr-candidate {ifname}\n" + cfg += f" ip pim rp-candidate {ifname}\n" cfg += " !ip pim spt-threshold interval 10 bytes 80000\n" return cfg diff --git a/daemon/core/services/sdn.py b/daemon/core/services/sdn.py index e72b5138..a31cf87d 100644 --- a/daemon/core/services/sdn.py +++ b/daemon/core/services/sdn.py @@ -3,7 +3,6 @@ sdn.py defines services to start Open vSwitch and the Ryu SDN Controller. """ import re -from typing import Tuple from core.nodes.base import CoreNode from core.services.coreservices import CoreService @@ -24,15 +23,15 @@ class SdnService(CoreService): class OvsService(SdnService): name: str = "OvsService" group: str = "SDN" - executables: Tuple[str, ...] = ("ovs-ofctl", "ovs-vsctl") - dirs: Tuple[str, ...] = ( + executables: tuple[str, ...] = ("ovs-ofctl", "ovs-vsctl") + dirs: tuple[str, ...] = ( "/etc/openvswitch", "/var/run/openvswitch", "/var/log/openvswitch", ) - configs: Tuple[str, ...] = ("OvsService.sh",) - startup: Tuple[str, ...] = ("bash OvsService.sh",) - shutdown: Tuple[str, ...] = ("killall ovs-vswitchd", "killall ovsdb-server") + configs: tuple[str, ...] = ("OvsService.sh",) + startup: tuple[str, ...] = ("bash OvsService.sh",) + shutdown: tuple[str, ...] = ("killall ovs-vswitchd", "killall ovsdb-server") @classmethod def generate_config(cls, node: CoreNode, filename: str) -> str: @@ -59,39 +58,41 @@ class OvsService(SdnService): # create virtual interfaces cfg += "## Create a veth pair to send the data to\n" - cfg += "ip link add rtr%s type veth peer name sw%s\n" % (ifnum, ifnum) + cfg += f"ip link add rtr{ifnum} type veth peer name sw{ifnum}\n" # remove ip address of eths because quagga/zebra will assign same IPs to rtr interfaces # or assign them manually to rtr interfaces if zebra is not running for ip4 in iface.ip4s: - cfg += "ip addr del %s dev %s\n" % (ip4.ip, iface.name) + cfg += f"ip addr del {ip4.ip} dev {iface.name}\n" if has_zebra == 0: - cfg += "ip addr add %s dev rtr%s\n" % (ip4.ip, ifnum) + cfg += f"ip addr add {ip4.ip} dev rtr{ifnum}\n" for ip6 in iface.ip6s: - cfg += "ip -6 addr del %s dev %s\n" % (ip6.ip, iface.name) + cfg += f"ip -6 addr del {ip6.ip} dev {iface.name}\n" if has_zebra == 0: - cfg += "ip -6 addr add %s dev rtr%s\n" % (ip6.ip, ifnum) + cfg += f"ip -6 addr add {ip6.ip} dev rtr{ifnum}\n" # add interfaces to bridge - # Make port numbers explicit so they're easier to follow in reading the script + # Make port numbers explicit so they're easier to follow in + # reading the script cfg += "## Add the CORE interface to the switch\n" cfg += ( - "ovs-vsctl add-port ovsbr0 eth%s -- set Interface eth%s ofport_request=%d\n" - % (ifnum, ifnum, portnum) + f"ovs-vsctl add-port ovsbr0 eth{ifnum} -- " + f"set Interface eth{ifnum} ofport_request={portnum:d}\n" ) cfg += "## And then add its sibling veth interface\n" cfg += ( - "ovs-vsctl add-port ovsbr0 sw%s -- set Interface sw%s ofport_request=%d\n" - % (ifnum, ifnum, portnum + 1) + f"ovs-vsctl add-port ovsbr0 sw{ifnum} -- " + f"set Interface sw{ifnum} ofport_request={portnum + 1:d}\n" ) cfg += "## start them up so we can send/receive data\n" - cfg += "ovs-ofctl mod-port ovsbr0 eth%s up\n" % ifnum - cfg += "ovs-ofctl mod-port ovsbr0 sw%s up\n" % ifnum + cfg += f"ovs-ofctl mod-port ovsbr0 eth{ifnum} up\n" + cfg += f"ovs-ofctl mod-port ovsbr0 sw{ifnum} up\n" cfg += "## Bring up the lower part of the veth pair\n" - cfg += "ip link set dev rtr%s up\n" % ifnum + cfg += f"ip link set dev rtr{ifnum} up\n" portnum += 2 - # Add rule for default controller if there is one local (even if the controller is not local, it finds it) + # Add rule for default controller if there is one local + # (even if the controller is not local, it finds it) cfg += "\n## We assume there will be an SDN controller on the other end of this, \n" cfg += "## but it will still function if there's not\n" cfg += "ovs-vsctl set-controller ovsbr0 tcp:127.0.0.1:6633\n" @@ -102,14 +103,8 @@ class OvsService(SdnService): portnum = 1 for iface in node.get_ifaces(control=False): cfg += "## Take the data from the CORE interface and put it on the veth and vice versa\n" - cfg += ( - "ovs-ofctl add-flow ovsbr0 priority=1000,in_port=%d,action=output:%d\n" - % (portnum, portnum + 1) - ) - cfg += ( - "ovs-ofctl add-flow ovsbr0 priority=1000,in_port=%d,action=output:%d\n" - % (portnum + 1, portnum) - ) + cfg += f"ovs-ofctl add-flow ovsbr0 priority=1000,in_port={portnum:d},action=output:{portnum + 1:d}\n" + cfg += f"ovs-ofctl add-flow ovsbr0 priority=1000,in_port={portnum + 1:d},action=output:{portnum:d}\n" portnum += 2 return cfg @@ -117,10 +112,10 @@ class OvsService(SdnService): class RyuService(SdnService): name: str = "ryuService" group: str = "SDN" - executables: Tuple[str, ...] = ("ryu-manager",) - configs: Tuple[str, ...] = ("ryuService.sh",) - startup: Tuple[str, ...] = ("bash ryuService.sh",) - shutdown: Tuple[str, ...] = ("killall ryu-manager",) + executables: tuple[str, ...] = ("ryu-manager",) + configs: tuple[str, ...] = ("ryuService.sh",) + startup: tuple[str, ...] = ("bash ryuService.sh",) + shutdown: tuple[str, ...] = ("killall ryu-manager",) @classmethod def generate_config(cls, node: CoreNode, filename: str) -> str: diff --git a/daemon/core/services/security.py b/daemon/core/services/security.py index f53e8533..afd71a14 100644 --- a/daemon/core/services/security.py +++ b/daemon/core/services/security.py @@ -4,7 +4,6 @@ firewall) """ import logging -from typing import Tuple from core import constants from core.nodes.base import CoreNode @@ -17,10 +16,10 @@ logger = logging.getLogger(__name__) class VPNClient(CoreService): name: str = "VPNClient" group: str = "Security" - configs: Tuple[str, ...] = ("vpnclient.sh",) - startup: Tuple[str, ...] = ("bash vpnclient.sh",) - shutdown: Tuple[str, ...] = ("killall openvpn",) - validate: Tuple[str, ...] = ("pidof openvpn",) + configs: tuple[str, ...] = ("vpnclient.sh",) + startup: tuple[str, ...] = ("bash vpnclient.sh",) + shutdown: tuple[str, ...] = ("killall openvpn",) + validate: tuple[str, ...] = ("pidof openvpn",) custom_needed: bool = True @classmethod @@ -32,9 +31,9 @@ class VPNClient(CoreService): cfg += "# custom VPN Client configuration for service (security.py)\n" fname = f"{constants.CORE_DATA_DIR}/examples/services/sampleVPNClient" try: - with open(fname, "r") as f: + with open(fname) as f: cfg += f.read() - except IOError: + except OSError: logger.exception( "error opening VPN client configuration template (%s)", fname ) @@ -44,10 +43,10 @@ class VPNClient(CoreService): class VPNServer(CoreService): name: str = "VPNServer" group: str = "Security" - configs: Tuple[str, ...] = ("vpnserver.sh",) - startup: Tuple[str, ...] = ("bash vpnserver.sh",) - shutdown: Tuple[str, ...] = ("killall openvpn",) - validate: Tuple[str, ...] = ("pidof openvpn",) + configs: tuple[str, ...] = ("vpnserver.sh",) + startup: tuple[str, ...] = ("bash vpnserver.sh",) + shutdown: tuple[str, ...] = ("killall openvpn",) + validate: tuple[str, ...] = ("pidof openvpn",) custom_needed: bool = True @classmethod @@ -60,9 +59,9 @@ class VPNServer(CoreService): cfg += "# custom VPN Server Configuration for service (security.py)\n" fname = f"{constants.CORE_DATA_DIR}/examples/services/sampleVPNServer" try: - with open(fname, "r") as f: + with open(fname) as f: cfg += f.read() - except IOError: + except OSError: logger.exception( "Error opening VPN server configuration template (%s)", fname ) @@ -72,9 +71,9 @@ class VPNServer(CoreService): class IPsec(CoreService): name: str = "IPsec" group: str = "Security" - configs: Tuple[str, ...] = ("ipsec.sh",) - startup: Tuple[str, ...] = ("bash ipsec.sh",) - shutdown: Tuple[str, ...] = ("killall racoon",) + configs: tuple[str, ...] = ("ipsec.sh",) + startup: tuple[str, ...] = ("bash ipsec.sh",) + shutdown: tuple[str, ...] = ("killall racoon",) custom_needed: bool = True @classmethod @@ -88,9 +87,9 @@ class IPsec(CoreService): cfg += "(security.py)\n" fname = f"{constants.CORE_DATA_DIR}/examples/services/sampleIPsec" try: - with open(fname, "r") as f: + with open(fname) as f: cfg += f.read() - except IOError: + except OSError: logger.exception("Error opening IPsec configuration template (%s)", fname) return cfg @@ -98,8 +97,8 @@ class IPsec(CoreService): class Firewall(CoreService): name: str = "Firewall" group: str = "Security" - configs: Tuple[str, ...] = ("firewall.sh",) - startup: Tuple[str, ...] = ("bash firewall.sh",) + configs: tuple[str, ...] = ("firewall.sh",) + startup: tuple[str, ...] = ("bash firewall.sh",) custom_needed: bool = True @classmethod @@ -111,9 +110,9 @@ class Firewall(CoreService): cfg += "# custom node firewall rules for service (security.py)\n" fname = f"{constants.CORE_DATA_DIR}/examples/services/sampleFirewall" try: - with open(fname, "r") as f: + with open(fname) as f: cfg += f.read() - except IOError: + except OSError: logger.exception( "Error opening Firewall configuration template (%s)", fname ) @@ -127,9 +126,9 @@ class Nat(CoreService): name: str = "NAT" group: str = "Security" - executables: Tuple[str, ...] = ("iptables",) - configs: Tuple[str, ...] = ("nat.sh",) - startup: Tuple[str, ...] = ("bash nat.sh",) + executables: tuple[str, ...] = ("iptables",) + configs: tuple[str, ...] = ("nat.sh",) + startup: tuple[str, ...] = ("bash nat.sh",) custom_needed: bool = False @classmethod diff --git a/daemon/core/services/ucarp.py b/daemon/core/services/ucarp.py index aa0d9a1a..c6f2256e 100644 --- a/daemon/core/services/ucarp.py +++ b/daemon/core/services/ucarp.py @@ -1,7 +1,6 @@ """ ucarp.py: defines high-availability IP address controlled by ucarp """ -from typing import Tuple from core.nodes.base import CoreNode from core.services.coreservices import CoreService @@ -12,16 +11,16 @@ UCARP_ETC = "/usr/local/etc/ucarp" class Ucarp(CoreService): name: str = "ucarp" group: str = "Utility" - dirs: Tuple[str, ...] = (UCARP_ETC,) - configs: Tuple[str, ...] = ( + dirs: tuple[str, ...] = (UCARP_ETC,) + configs: tuple[str, ...] = ( UCARP_ETC + "/default.sh", UCARP_ETC + "/default-up.sh", UCARP_ETC + "/default-down.sh", "ucarpboot.sh", ) - startup: Tuple[str, ...] = ("bash ucarpboot.sh",) - shutdown: Tuple[str, ...] = ("killall ucarp",) - validate: Tuple[str, ...] = ("pidof ucarp",) + startup: tuple[str, ...] = ("bash ucarpboot.sh",) + shutdown: tuple[str, ...] = ("killall ucarp",) + validate: tuple[str, ...] = ("pidof ucarp",) @classmethod def generate_config(cls, node: CoreNode, filename: str) -> str: @@ -45,13 +44,13 @@ class Ucarp(CoreService): Returns configuration file text. """ ucarp_bin = node.session.options.get("ucarp_bin", "/usr/sbin/ucarp") - return """\ + return f"""\ #!/bin/sh # Location of UCARP executable -UCARP_EXEC=%s +UCARP_EXEC={ucarp_bin} # Location of the UCARP config directory -UCARP_CFGDIR=%s +UCARP_CFGDIR={UCARP_ETC} # Logging Facility FACILITY=daemon @@ -92,40 +91,34 @@ OPTIONS="-z -n -M" # Send extra parameter to down and up scripts #XPARAM="-x " -XPARAM="-x ${VIRTUAL_NET}" +XPARAM="-x ${{VIRTUAL_NET}}" # The start and stop scripts -START_SCRIPT=${UCARP_CFGDIR}/default-up.sh -STOP_SCRIPT=${UCARP_CFGDIR}/default-down.sh +START_SCRIPT=${{UCARP_CFGDIR}}/default-up.sh +STOP_SCRIPT=${{UCARP_CFGDIR}}/default-down.sh # These line should not need to be touched UCARP_OPTS="$OPTIONS -b $UCARP_BASE -k $SKEW -i $INTERFACE -v $INSTANCE_ID -p $PASSWORD -u $START_SCRIPT -d $STOP_SCRIPT -a $VIRTUAL_ADDRESS -s $SOURCE_ADDRESS -f $FACILITY $XPARAM" -${UCARP_EXEC} -B ${UCARP_OPTS} -""" % ( - ucarp_bin, - UCARP_ETC, - ) +${{UCARP_EXEC}} -B ${{UCARP_OPTS}} +""" @classmethod def generate_ucarp_boot(cls, node: CoreNode) -> str: """ Generate a shell script used to boot the Ucarp daemons. """ - return ( - """\ + return f"""\ #!/bin/sh # Location of the UCARP config directory -UCARP_CFGDIR=%s +UCARP_CFGDIR={UCARP_ETC} -chmod a+x ${UCARP_CFGDIR}/*.sh +chmod a+x ${{UCARP_CFGDIR}}/*.sh # Start the default ucarp daemon configuration -${UCARP_CFGDIR}/default.sh +${{UCARP_CFGDIR}}/default.sh """ - % UCARP_ETC - ) @classmethod def generate_vip_up(cls, node: CoreNode) -> str: diff --git a/daemon/core/services/utility.py b/daemon/core/services/utility.py index 54a58b2a..e83cb9d5 100644 --- a/daemon/core/services/utility.py +++ b/daemon/core/services/utility.py @@ -1,7 +1,7 @@ """ utility.py: defines miscellaneous utility services. """ -from typing import Optional, Tuple +from typing import Optional import netaddr @@ -27,8 +27,8 @@ class UtilService(CoreService): class IPForwardService(UtilService): name: str = "IPForward" - configs: Tuple[str, ...] = ("ipforward.sh",) - startup: Tuple[str, ...] = ("bash ipforward.sh",) + configs: tuple[str, ...] = ("ipforward.sh",) + startup: tuple[str, ...] = ("bash ipforward.sh",) @classmethod def generate_config(cls, node: CoreNode, filename: str) -> str: @@ -36,32 +36,30 @@ class IPForwardService(UtilService): @classmethod def generateconfiglinux(cls, node: CoreNode, filename: str) -> str: - cfg = """\ + cfg = f"""\ #!/bin/sh # auto-generated by IPForward service (utility.py) -%(sysctl)s -w net.ipv4.conf.all.forwarding=1 -%(sysctl)s -w net.ipv4.conf.default.forwarding=1 -%(sysctl)s -w net.ipv6.conf.all.forwarding=1 -%(sysctl)s -w net.ipv6.conf.default.forwarding=1 -%(sysctl)s -w net.ipv4.conf.all.send_redirects=0 -%(sysctl)s -w net.ipv4.conf.default.send_redirects=0 -%(sysctl)s -w net.ipv4.conf.all.rp_filter=0 -%(sysctl)s -w net.ipv4.conf.default.rp_filter=0 -""" % { - "sysctl": SYSCTL - } +{SYSCTL} -w net.ipv4.conf.all.forwarding=1 +{SYSCTL} -w net.ipv4.conf.default.forwarding=1 +{SYSCTL} -w net.ipv6.conf.all.forwarding=1 +{SYSCTL} -w net.ipv6.conf.default.forwarding=1 +{SYSCTL} -w net.ipv4.conf.all.send_redirects=0 +{SYSCTL} -w net.ipv4.conf.default.send_redirects=0 +{SYSCTL} -w net.ipv4.conf.all.rp_filter=0 +{SYSCTL} -w net.ipv4.conf.default.rp_filter=0 +""" for iface in node.get_ifaces(): name = utils.sysctl_devname(iface.name) - cfg += "%s -w net.ipv4.conf.%s.forwarding=1\n" % (SYSCTL, name) - cfg += "%s -w net.ipv4.conf.%s.send_redirects=0\n" % (SYSCTL, name) - cfg += "%s -w net.ipv4.conf.%s.rp_filter=0\n" % (SYSCTL, name) + cfg += f"{SYSCTL} -w net.ipv4.conf.{name}.forwarding=1\n" + cfg += f"{SYSCTL} -w net.ipv4.conf.{name}.send_redirects=0\n" + cfg += f"{SYSCTL} -w net.ipv4.conf.{name}.rp_filter=0\n" return cfg class DefaultRouteService(UtilService): name: str = "DefaultRoute" - configs: Tuple[str, ...] = ("defaultroute.sh",) - startup: Tuple[str, ...] = ("bash defaultroute.sh",) + configs: tuple[str, ...] = ("defaultroute.sh",) + startup: tuple[str, ...] = ("bash defaultroute.sh",) @classmethod def generate_config(cls, node: CoreNode, filename: str) -> str: @@ -83,8 +81,8 @@ class DefaultRouteService(UtilService): class DefaultMulticastRouteService(UtilService): name: str = "DefaultMulticastRoute" - configs: Tuple[str, ...] = ("defaultmroute.sh",) - startup: Tuple[str, ...] = ("bash defaultmroute.sh",) + configs: tuple[str, ...] = ("defaultmroute.sh",) + startup: tuple[str, ...] = ("bash defaultmroute.sh",) @classmethod def generate_config(cls, node: CoreNode, filename: str) -> str: @@ -94,7 +92,7 @@ class DefaultMulticastRouteService(UtilService): cfg += "as needed\n" for iface in node.get_ifaces(control=False): rtcmd = "ip route add 224.0.0.0/4 dev" - cfg += "%s %s\n" % (rtcmd, iface.name) + cfg += f"{rtcmd} {iface.name}\n" cfg += "\n" break return cfg @@ -102,8 +100,8 @@ class DefaultMulticastRouteService(UtilService): class StaticRouteService(UtilService): name: str = "StaticRoute" - configs: Tuple[str, ...] = ("staticroute.sh",) - startup: Tuple[str, ...] = ("bash staticroute.sh",) + configs: tuple[str, ...] = ("staticroute.sh",) + startup: tuple[str, ...] = ("bash staticroute.sh",) custom_needed: bool = True @classmethod @@ -127,16 +125,16 @@ class StaticRouteService(UtilService): if ip[-2] == ip[1]: return "" else: - rtcmd = "#/sbin/ip route add %s via" % dst - return "%s %s" % (rtcmd, ip[1]) + rtcmd = f"#/sbin/ip route add {dst} via" + return f"{rtcmd} {ip[1]}" class SshService(UtilService): name: str = "SSH" - configs: Tuple[str, ...] = ("startsshd.sh", "/etc/ssh/sshd_config") - dirs: Tuple[str, ...] = ("/etc/ssh", "/var/run/sshd") - startup: Tuple[str, ...] = ("bash startsshd.sh",) - shutdown: Tuple[str, ...] = ("killall sshd",) + configs: tuple[str, ...] = ("startsshd.sh", "/etc/ssh/sshd_config") + dirs: tuple[str, ...] = ("/etc/ssh", "/var/run/sshd") + startup: tuple[str, ...] = ("bash startsshd.sh",) + shutdown: tuple[str, ...] = ("killall sshd",) validation_mode: ServiceMode = ServiceMode.BLOCKING @classmethod @@ -149,26 +147,22 @@ class SshService(UtilService): sshstatedir = cls.dirs[1] sshlibdir = "/usr/lib/openssh" if filename == "startsshd.sh": - return """\ + return f"""\ #!/bin/sh # auto-generated by SSH service (utility.py) -ssh-keygen -q -t rsa -N "" -f %s/ssh_host_rsa_key -chmod 655 %s +ssh-keygen -q -t rsa -N "" -f {sshcfgdir}/ssh_host_rsa_key +chmod 655 {sshstatedir} # wait until RSA host key has been generated to launch sshd -/usr/sbin/sshd -f %s/sshd_config -""" % ( - sshcfgdir, - sshstatedir, - sshcfgdir, - ) +/usr/sbin/sshd -f {sshcfgdir}/sshd_config +""" else: - return """\ + return f"""\ # auto-generated by SSH service (utility.py) Port 22 Protocol 2 -HostKey %s/ssh_host_rsa_key +HostKey {sshcfgdir}/ssh_host_rsa_key UsePrivilegeSeparation yes -PidFile %s/sshd.pid +PidFile {sshstatedir}/sshd.pid KeyRegenerationInterval 3600 ServerKeyBits 768 @@ -197,23 +191,19 @@ PrintLastLog yes TCPKeepAlive yes AcceptEnv LANG LC_* -Subsystem sftp %s/sftp-server +Subsystem sftp {sshlibdir}/sftp-server UsePAM yes UseDNS no -""" % ( - sshcfgdir, - sshstatedir, - sshlibdir, - ) +""" class DhcpService(UtilService): name: str = "DHCP" - configs: Tuple[str, ...] = ("/etc/dhcp/dhcpd.conf",) - dirs: Tuple[str, ...] = ("/etc/dhcp", "/var/lib/dhcp") - startup: Tuple[str, ...] = ("touch /var/lib/dhcp/dhcpd.leases", "dhcpd") - shutdown: Tuple[str, ...] = ("killall dhcpd",) - validate: Tuple[str, ...] = ("pidof dhcpd",) + configs: tuple[str, ...] = ("/etc/dhcp/dhcpd.conf",) + dirs: tuple[str, ...] = ("/etc/dhcp", "/var/lib/dhcp") + startup: tuple[str, ...] = ("touch /var/lib/dhcp/dhcpd.leases", "dhcpd") + shutdown: tuple[str, ...] = ("killall dhcpd",) + validate: tuple[str, ...] = ("pidof dhcpd",) @classmethod def generate_config(cls, node: CoreNode, filename: str) -> str: @@ -252,21 +242,15 @@ ddns-update-style none; index = (ip.size - 2) / 2 rangelow = ip[index] rangehigh = ip[-2] - return """ -subnet %s netmask %s { - pool { - range %s %s; + return f""" +subnet {ip.cidr.ip} netmask {ip.netmask} {{ + pool {{ + range {rangelow} {rangehigh}; default-lease-time 600; - option routers %s; - } -} -""" % ( - ip.cidr.ip, - ip.netmask, - rangelow, - rangehigh, - ip.ip, - ) + option routers {ip.ip}; + }} +}} +""" class DhcpClientService(UtilService): @@ -275,10 +259,10 @@ class DhcpClientService(UtilService): """ name: str = "DHCPClient" - configs: Tuple[str, ...] = ("startdhcpclient.sh",) - startup: Tuple[str, ...] = ("bash startdhcpclient.sh",) - shutdown: Tuple[str, ...] = ("killall dhclient",) - validate: Tuple[str, ...] = ("pidof dhclient",) + configs: tuple[str, ...] = ("startdhcpclient.sh",) + startup: tuple[str, ...] = ("bash startdhcpclient.sh",) + shutdown: tuple[str, ...] = ("killall dhclient",) + validate: tuple[str, ...] = ("pidof dhclient",) @classmethod def generate_config(cls, node: CoreNode, filename: str) -> str: @@ -291,10 +275,10 @@ class DhcpClientService(UtilService): cfg += "side DNS\n# resolution based on the DHCP server response.\n" cfg += "#mkdir -p /var/run/resolvconf/interface\n" for iface in node.get_ifaces(control=False): - cfg += "#ln -s /var/run/resolvconf/interface/%s.dhclient" % iface.name + cfg += f"#ln -s /var/run/resolvconf/interface/{iface.name}.dhclient" cfg += " /var/run/resolvconf/resolv.conf\n" - cfg += "/sbin/dhclient -nw -pf /var/run/dhclient-%s.pid" % iface.name - cfg += " -lf /var/run/dhclient-%s.lease %s\n" % (iface.name, iface.name) + cfg += f"/sbin/dhclient -nw -pf /var/run/dhclient-{iface.name}.pid" + cfg += f" -lf /var/run/dhclient-{iface.name}.lease {iface.name}\n" return cfg @@ -304,11 +288,11 @@ class FtpService(UtilService): """ name: str = "FTP" - configs: Tuple[str, ...] = ("vsftpd.conf",) - dirs: Tuple[str, ...] = ("/var/run/vsftpd/empty", "/var/ftp") - startup: Tuple[str, ...] = ("vsftpd ./vsftpd.conf",) - shutdown: Tuple[str, ...] = ("killall vsftpd",) - validate: Tuple[str, ...] = ("pidof vsftpd",) + configs: tuple[str, ...] = ("vsftpd.conf",) + dirs: tuple[str, ...] = ("/var/run/vsftpd/empty", "/var/ftp") + startup: tuple[str, ...] = ("vsftpd ./vsftpd.conf",) + shutdown: tuple[str, ...] = ("killall vsftpd",) + validate: tuple[str, ...] = ("pidof vsftpd",) @classmethod def generate_config(cls, node: CoreNode, filename: str) -> str: @@ -337,12 +321,12 @@ class HttpService(UtilService): """ name: str = "HTTP" - configs: Tuple[str, ...] = ( + configs: tuple[str, ...] = ( "/etc/apache2/apache2.conf", "/etc/apache2/envvars", "/var/www/index.html", ) - dirs: Tuple[str, ...] = ( + dirs: tuple[str, ...] = ( "/etc/apache2", "/var/run/apache2", "/var/log/apache2", @@ -350,9 +334,9 @@ class HttpService(UtilService): "/var/lock/apache2", "/var/www", ) - startup: Tuple[str, ...] = ("chown www-data /var/lock/apache2", "apache2ctl start") - shutdown: Tuple[str, ...] = ("apache2ctl stop",) - validate: Tuple[str, ...] = ("pidof apache2",) + startup: tuple[str, ...] = ("chown www-data /var/lock/apache2", "apache2ctl start") + shutdown: tuple[str, ...] = ("apache2ctl stop",) + validate: tuple[str, ...] = ("pidof apache2",) APACHEVER22: int = 22 APACHEVER24: int = 24 @@ -538,18 +522,15 @@ export LANG @classmethod def generatehtml(cls, node: CoreNode, filename: str) -> str: - body = ( - """\ + body = f"""\ -

%s web server

+

{node.name} web server

This is the default web page for this server.

The web server software is running but no content has been added, yet.

""" - % node.name - ) for iface in node.get_ifaces(control=False): - body += "
  • %s - %s
  • \n" % (iface.name, [str(x) for x in iface.ips()]) - return "%s" % body + body += f"
  • {iface.name} - {[str(x) for x in iface.ips()]}
  • \n" + return f"{body}" class PcapService(UtilService): @@ -558,10 +539,10 @@ class PcapService(UtilService): """ name: str = "pcap" - configs: Tuple[str, ...] = ("pcap.sh",) - startup: Tuple[str, ...] = ("bash pcap.sh start",) - shutdown: Tuple[str, ...] = ("bash pcap.sh stop",) - validate: Tuple[str, ...] = ("pidof tcpdump",) + configs: tuple[str, ...] = ("pcap.sh",) + startup: tuple[str, ...] = ("bash pcap.sh start",) + shutdown: tuple[str, ...] = ("bash pcap.sh stop",) + validate: tuple[str, ...] = ("pidof tcpdump",) meta: str = "logs network traffic to pcap packet capture files" @classmethod @@ -582,11 +563,9 @@ if [ "x$1" = "xstart" ]; then if iface.control: cfg += "# " redir = "< /dev/null" - cfg += "tcpdump ${DUMPOPTS} -w %s.%s.pcap -i %s %s &\n" % ( - node.name, - iface.name, - iface.name, - redir, + cfg += ( + f"tcpdump ${{DUMPOPTS}} -w {node.name}.{iface.name}.pcap " + f"-i {iface.name} {redir} &\n" ) cfg += """ @@ -600,13 +579,13 @@ fi; class RadvdService(UtilService): name: str = "radvd" - configs: Tuple[str, ...] = ("/etc/radvd/radvd.conf",) - dirs: Tuple[str, ...] = ("/etc/radvd", "/var/run/radvd") - startup: Tuple[str, ...] = ( + configs: tuple[str, ...] = ("/etc/radvd/radvd.conf",) + dirs: tuple[str, ...] = ("/etc/radvd", "/var/run/radvd") + startup: tuple[str, ...] = ( "radvd -C /etc/radvd/radvd.conf -m logfile -l /var/log/radvd.log", ) - shutdown: Tuple[str, ...] = ("pkill radvd",) - validate: Tuple[str, ...] = ("pidof radvd",) + shutdown: tuple[str, ...] = ("pkill radvd",) + validate: tuple[str, ...] = ("pidof radvd",) @classmethod def generate_config(cls, node: CoreNode, filename: str) -> str: @@ -619,32 +598,26 @@ class RadvdService(UtilService): prefixes = list(map(cls.subnetentry, iface.ips())) if len(prefixes) < 1: continue - cfg += ( - """\ -interface %s -{ + cfg += f"""\ +interface {iface.name} +{{ AdvSendAdvert on; MinRtrAdvInterval 3; MaxRtrAdvInterval 10; AdvDefaultPreference low; AdvHomeAgentFlag off; """ - % iface.name - ) for prefix in prefixes: if prefix == "": continue - cfg += ( - """\ - prefix %s - { + cfg += f"""\ + prefix {prefix} + {{ AdvOnLink on; AdvAutonomous on; AdvRouterAddr on; - }; + }}; """ - % prefix - ) cfg += "};\n" return cfg @@ -667,10 +640,10 @@ class AtdService(UtilService): """ name: str = "atd" - configs: Tuple[str, ...] = ("startatd.sh",) - dirs: Tuple[str, ...] = ("/var/spool/cron/atjobs", "/var/spool/cron/atspool") - startup: Tuple[str, ...] = ("bash startatd.sh",) - shutdown: Tuple[str, ...] = ("pkill atd",) + configs: tuple[str, ...] = ("startatd.sh",) + dirs: tuple[str, ...] = ("/var/spool/cron/atjobs", "/var/spool/cron/atspool") + startup: tuple[str, ...] = ("bash startatd.sh",) + shutdown: tuple[str, ...] = ("pkill atd",) @classmethod def generate_config(cls, node: CoreNode, filename: str) -> str: diff --git a/daemon/core/services/xorp.py b/daemon/core/services/xorp.py index 485fe159..ac29b299 100644 --- a/daemon/core/services/xorp.py +++ b/daemon/core/services/xorp.py @@ -2,7 +2,7 @@ xorp.py: defines routing services provided by the XORP routing suite. """ -from typing import Optional, Tuple +from typing import Optional import netaddr @@ -19,15 +19,14 @@ class XorpRtrmgr(CoreService): name: str = "xorp_rtrmgr" group: str = "XORP" - executables: Tuple[str, ...] = ("xorp_rtrmgr",) - dirs: Tuple[str, ...] = ("/etc/xorp",) - configs: Tuple[str, ...] = ("/etc/xorp/config.boot",) - startup: Tuple[str, ...] = ( - "xorp_rtrmgr -d -b %s -l /var/log/%s.log -P /var/run/%s.pid" - % (configs[0], name, name), - ) - shutdown: Tuple[str, ...] = ("killall xorp_rtrmgr",) - validate: Tuple[str, ...] = ("pidof xorp_rtrmgr",) + executables: tuple[str, ...] = ("xorp_rtrmgr",) + dirs: tuple[str, ...] = ("/etc/xorp",) + configs: tuple[str, ...] = ("/etc/xorp/config.boot",) + startup: tuple[ + str, ... + ] = f"xorp_rtrmgr -d -b {configs[0]} -l /var/log/{name}.log -P /var/run/{name}.pid" + shutdown: tuple[str, ...] = ("killall xorp_rtrmgr",) + validate: tuple[str, ...] = ("pidof xorp_rtrmgr",) @classmethod def generate_config(cls, node: CoreNode, filename: str) -> str: @@ -38,8 +37,8 @@ class XorpRtrmgr(CoreService): """ cfg = "interfaces {\n" for iface in node.get_ifaces(): - cfg += " interface %s {\n" % iface.name - cfg += "\tvif %s {\n" % iface.name + cfg += f" interface {iface.name} {{\n" + cfg += f"\tvif {iface.name} {{\n" cfg += "".join(map(cls.addrstr, iface.ips())) cfg += cls.lladdrstr(iface) cfg += "\t}\n" @@ -59,8 +58,8 @@ class XorpRtrmgr(CoreService): """ helper for mapping IP addresses to XORP config statements """ - cfg = "\t address %s {\n" % ip.ip - cfg += "\t\tprefix-length: %s\n" % ip.prefixlen + cfg = f"\t address {ip.ip} {{\n" + cfg += f"\t\tprefix-length: {ip.prefixlen}\n" cfg += "\t }\n" return cfg @@ -69,7 +68,7 @@ class XorpRtrmgr(CoreService): """ helper for adding link-local address entries (required by OSPFv3) """ - cfg = "\t address %s {\n" % iface.mac.eui64() + cfg = f"\t address {iface.mac.eui64()} {{\n" cfg += "\t\tprefix-length: 64\n" cfg += "\t }\n" return cfg @@ -83,8 +82,8 @@ class XorpService(CoreService): name: Optional[str] = None group: str = "XORP" - executables: Tuple[str, ...] = ("xorp_rtrmgr",) - dependencies: Tuple[str, ...] = ("xorp_rtrmgr",) + executables: tuple[str, ...] = ("xorp_rtrmgr",) + dependencies: tuple[str, ...] = ("xorp_rtrmgr",) meta: str = ( "The config file for this service can be found in the xorp_rtrmgr service." ) @@ -95,7 +94,7 @@ class XorpService(CoreService): Helper to add a forwarding engine entry to the config file. """ cfg = "fea {\n" - cfg += " %s {\n" % forwarding + cfg += f" {forwarding} {{\n" cfg += "\tdisable:false\n" cfg += " }\n" cfg += "}\n" @@ -111,10 +110,10 @@ class XorpService(CoreService): names.append(iface.name) names.append("register_vif") cfg = "plumbing {\n" - cfg += " %s {\n" % forwarding + cfg += f" {forwarding} {{\n" for name in names: - cfg += "\tinterface %s {\n" % name - cfg += "\t vif %s {\n" % name + cfg += f"\tinterface {name} {{\n" + cfg += f"\t vif {name} {{\n" cfg += "\t\tdisable: false\n" cfg += "\t }\n" cfg += "\t}\n" @@ -173,13 +172,13 @@ class XorpOspfv2(XorpService): rtrid = cls.router_id(node) cfg += "\nprotocols {\n" cfg += " ospf4 {\n" - cfg += "\trouter-id: %s\n" % rtrid + cfg += f"\trouter-id: {rtrid}\n" cfg += "\tarea 0.0.0.0 {\n" for iface in node.get_ifaces(control=False): - cfg += "\t interface %s {\n" % iface.name - cfg += "\t\tvif %s {\n" % iface.name + cfg += f"\t interface {iface.name} {{\n" + cfg += f"\t\tvif {iface.name} {{\n" for ip4 in iface.ip4s: - cfg += "\t\t address %s {\n" % ip4.ip + cfg += f"\t\t address {ip4.ip} {{\n" cfg += "\t\t }\n" cfg += "\t\t}\n" cfg += "\t }\n" @@ -204,11 +203,11 @@ class XorpOspfv3(XorpService): rtrid = cls.router_id(node) cfg += "\nprotocols {\n" cfg += " ospf6 0 { /* Instance ID 0 */\n" - cfg += "\trouter-id: %s\n" % rtrid + cfg += f"\trouter-id: {rtrid}\n" cfg += "\tarea 0.0.0.0 {\n" for iface in node.get_ifaces(control=False): - cfg += "\t interface %s {\n" % iface.name - cfg += "\t\tvif %s {\n" % iface.name + cfg += f"\t interface {iface.name} {{\n" + cfg += f"\t\tvif {iface.name} {{\n" cfg += "\t\t}\n" cfg += "\t }\n" cfg += "\t}\n" @@ -234,7 +233,7 @@ class XorpBgp(XorpService): rtrid = cls.router_id(node) cfg += "\nprotocols {\n" cfg += " bgp {\n" - cfg += "\tbgp-id: %s\n" % rtrid + cfg += f"\tbgp-id: {rtrid}\n" cfg += "\tlocal-as: 65001 /* change this */\n" cfg += '\texport: "export-connected"\n' cfg += "\tpeer 10.0.1.1 { /* change this */\n" @@ -262,10 +261,10 @@ class XorpRip(XorpService): cfg += " rip {\n" cfg += '\texport: "export-connected"\n' for iface in node.get_ifaces(control=False): - cfg += "\tinterface %s {\n" % iface.name - cfg += "\t vif %s {\n" % iface.name + cfg += f"\tinterface {iface.name} {{\n" + cfg += f"\t vif {iface.name} {{\n" for ip4 in iface.ip4s: - cfg += "\t\taddress %s {\n" % ip4.ip + cfg += f"\t\taddress {ip4.ip} {{\n" cfg += "\t\t disable: false\n" cfg += "\t\t}\n" cfg += "\t }\n" @@ -290,9 +289,9 @@ class XorpRipng(XorpService): cfg += " ripng {\n" cfg += '\texport: "export-connected"\n' for iface in node.get_ifaces(control=False): - cfg += "\tinterface %s {\n" % iface.name - cfg += "\t vif %s {\n" % iface.name - cfg += "\t\taddress %s {\n" % iface.mac.eui64() + cfg += f"\tinterface {iface.name} {{\n" + cfg += f"\t vif {iface.name} {{\n" + cfg += f"\t\taddress {iface.mac.eui64()} {{\n" cfg += "\t\t disable: false\n" cfg += "\t\t}\n" cfg += "\t }\n" @@ -317,8 +316,8 @@ class XorpPimSm4(XorpService): names = [] for iface in node.get_ifaces(control=False): names.append(iface.name) - cfg += "\tinterface %s {\n" % iface.name - cfg += "\t vif %s {\n" % iface.name + cfg += f"\tinterface {iface.name} {{\n" + cfg += f"\t vif {iface.name} {{\n" cfg += "\t\tdisable: false\n" cfg += "\t }\n" cfg += "\t}\n" @@ -329,20 +328,20 @@ class XorpPimSm4(XorpService): names.append("register_vif") for name in names: - cfg += "\tinterface %s {\n" % name - cfg += "\t vif %s {\n" % name + cfg += f"\tinterface {name} {{\n" + cfg += f"\t vif {name} {{\n" cfg += "\t\tdr-priority: 1\n" cfg += "\t }\n" cfg += "\t}\n" cfg += "\tbootstrap {\n" cfg += "\t cand-bsr {\n" cfg += "\t\tscope-zone 224.0.0.0/4 {\n" - cfg += '\t\t cand-bsr-by-vif-name: "%s"\n' % names[0] + cfg += f'\t\t cand-bsr-by-vif-name: "{names[0]}"\n' cfg += "\t\t}\n" cfg += "\t }\n" cfg += "\t cand-rp {\n" cfg += "\t\tgroup-prefix 224.0.0.0/4 {\n" - cfg += '\t\t cand-rp-by-vif-name: "%s"\n' % names[0] + cfg += f'\t\t cand-rp-by-vif-name: "{names[0]}"\n' cfg += "\t\t}\n" cfg += "\t }\n" cfg += "\t}\n" @@ -371,8 +370,8 @@ class XorpPimSm6(XorpService): names = [] for iface in node.get_ifaces(control=False): names.append(iface.name) - cfg += "\tinterface %s {\n" % iface.name - cfg += "\t vif %s {\n" % iface.name + cfg += f"\tinterface {iface.name} {{\n" + cfg += f"\t vif {iface.name} {{\n" cfg += "\t\tdisable: false\n" cfg += "\t }\n" cfg += "\t}\n" @@ -383,20 +382,20 @@ class XorpPimSm6(XorpService): names.append("register_vif") for name in names: - cfg += "\tinterface %s {\n" % name - cfg += "\t vif %s {\n" % name + cfg += f"\tinterface {name} {{\n" + cfg += f"\t vif {name} {{\n" cfg += "\t\tdr-priority: 1\n" cfg += "\t }\n" cfg += "\t}\n" cfg += "\tbootstrap {\n" cfg += "\t cand-bsr {\n" cfg += "\t\tscope-zone ff00::/8 {\n" - cfg += '\t\t cand-bsr-by-vif-name: "%s"\n' % names[0] + cfg += f'\t\t cand-bsr-by-vif-name: "{names[0]}"\n' cfg += "\t\t}\n" cfg += "\t }\n" cfg += "\t cand-rp {\n" cfg += "\t\tgroup-prefix ff00::/8 {\n" - cfg += '\t\t cand-rp-by-vif-name: "%s"\n' % names[0] + cfg += f'\t\t cand-rp-by-vif-name: "{names[0]}"\n' cfg += "\t\t}\n" cfg += "\t }\n" cfg += "\t}\n" @@ -423,12 +422,12 @@ class XorpOlsr(XorpService): rtrid = cls.router_id(node) cfg += "\nprotocols {\n" cfg += " olsr4 {\n" - cfg += "\tmain-address: %s\n" % rtrid + cfg += f"\tmain-address: {rtrid}\n" for iface in node.get_ifaces(control=False): - cfg += "\tinterface %s {\n" % iface.name - cfg += "\t vif %s {\n" % iface.name + cfg += f"\tinterface {iface.name} {{\n" + cfg += f"\t vif {iface.name} {{\n" for ip4 in iface.ip4s: - cfg += "\t\taddress %s {\n" % ip4.ip + cfg += f"\t\taddress {ip4.ip} {{\n" cfg += "\t\t}\n" cfg += "\t }\n" cfg += "\t}\n" diff --git a/daemon/core/utils.py b/daemon/core/utils.py index 244590f8..df00984c 100644 --- a/daemon/core/utils.py +++ b/daemon/core/utils.py @@ -17,23 +17,11 @@ import shutil import sys import threading from collections import OrderedDict +from collections.abc import Iterable from pathlib import Path from queue import Queue from subprocess import PIPE, STDOUT, Popen -from typing import ( - TYPE_CHECKING, - Any, - Callable, - Dict, - Generic, - Iterable, - List, - Optional, - Tuple, - Type, - TypeVar, - Union, -) +from typing import TYPE_CHECKING, Any, Callable, Generic, Optional, TypeVar, Union import netaddr @@ -70,7 +58,7 @@ def execute_script(coreemu: "CoreEmu", file_path: Path, args: str) -> None: def execute_file( - path: Path, exec_globals: Dict[str, str] = None, exec_locals: Dict[str, str] = None + path: Path, exec_globals: dict[str, str] = None, exec_locals: dict[str, str] = None ) -> None: """ Provides a way to execute a file. @@ -99,7 +87,7 @@ def hashkey(value: Union[str, int]) -> int: """ if isinstance(value, int): value = str(value) - value = value.encode("utf-8") + value = value.encode() return int(hashlib.sha256(value).hexdigest(), 16) @@ -131,7 +119,7 @@ def _valid_module(path: Path) -> bool: return True -def _is_class(module: Any, member: Type, clazz: Type) -> bool: +def _is_class(module: Any, member: type, clazz: type) -> bool: """ Validates if a module member is a class and an instance of a CoreService. @@ -175,7 +163,7 @@ def which(command: str, required: bool) -> str: return found_path -def make_tuple_fromstr(s: str, value_type: Callable[[str], T]) -> Tuple[T]: +def make_tuple_fromstr(s: str, value_type: Callable[[str], T]) -> tuple[T]: """ Create a tuple from a string. @@ -193,7 +181,7 @@ def make_tuple_fromstr(s: str, value_type: Callable[[str], T]) -> Tuple[T]: return tuple(value_type(i) for i in values) -def mute_detach(args: str, **kwargs: Dict[str, Any]) -> int: +def mute_detach(args: str, **kwargs: dict[str, Any]) -> int: """ Run a muted detached process by forking it. @@ -210,7 +198,7 @@ def mute_detach(args: str, **kwargs: Dict[str, Any]) -> int: def cmd( args: str, - env: Dict[str, str] = None, + env: dict[str, str] = None, cwd: Path = None, wait: bool = True, shell: bool = False, @@ -236,9 +224,9 @@ def cmd( p = Popen(args, stdout=output, stderr=output, env=env, cwd=cwd, shell=shell) if wait: stdout, stderr = p.communicate() - stdout = stdout.decode("utf-8").strip() - stderr = stderr.decode("utf-8").strip() - status = p.wait() + stdout = stdout.decode().strip() + stderr = stderr.decode().strip() + status = p.returncode if status != 0: raise CoreCommandError(status, input_args, stdout, stderr) return stdout @@ -249,7 +237,7 @@ def cmd( raise CoreCommandError(1, input_args, "", e.strerror) -def run_cmds(args: List[str], wait: bool = True, shell: bool = False) -> List[str]: +def run_cmds(args: list[str], wait: bool = True, shell: bool = False) -> list[str]: """ Execute a series of commands on the host and returns a list of the combined stderr stdout output. @@ -294,7 +282,7 @@ def file_demunge(pathname: str, header: str) -> None: :param header: header text to target for removal :return: nothing """ - with open(pathname, "r") as read_file: + with open(pathname) as read_file: lines = read_file.readlines() start = None @@ -348,7 +336,7 @@ def sysctl_devname(devname: str) -> Optional[str]: return devname.replace(".", "/") -def load_config(file_path: Path, d: Dict[str, str]) -> None: +def load_config(file_path: Path, d: dict[str, str]) -> None: """ Read key=value pairs from a file, into a dict. Skip comments; strip newline characters and spacing. @@ -369,7 +357,7 @@ def load_config(file_path: Path, d: Dict[str, str]) -> None: logger.exception("error reading file to dict: %s", file_path) -def load_module(import_statement: str, clazz: Generic[T]) -> List[T]: +def load_module(import_statement: str, clazz: Generic[T]) -> list[T]: classes = [] try: module = importlib.import_module(import_statement) @@ -384,7 +372,7 @@ def load_module(import_statement: str, clazz: Generic[T]) -> List[T]: return classes -def load_classes(path: Path, clazz: Generic[T]) -> List[T]: +def load_classes(path: Path, clazz: Generic[T]) -> list[T]: """ Dynamically load classes for use within CORE. @@ -426,18 +414,16 @@ def load_logging_config(config_path: Path) -> None: def run_cmds_threaded( - nodes: List["CoreNode"], - cmds: List[str], + node_cmds: list[tuple["CoreNode", list[str]]], wait: bool = True, shell: bool = False, workers: int = None, -) -> Tuple[Dict[int, List[str]], List[Exception]]: +) -> tuple[dict[int, list[str]], list[Exception]]: """ - Run a set of commands in order across a provided set of nodes. Each node will + Run the set of commands for the node provided. Each node will run the commands within the context of a threadpool. - :param nodes: nodes to run commands in - :param cmds: commands to run in nodes + :param node_cmds: list of tuples of nodes and commands to run within them :param wait: True to wait for status, False otherwise :param shell: True to run shell like, False otherwise :param workers: number of workers for threadpool, uses library default otherwise @@ -446,18 +432,18 @@ def run_cmds_threaded( """ def _node_cmds( - _target: "CoreNode", _cmds: List[str], _wait: bool, _shell: bool - ) -> List[str]: - outputs = [] + _target: "CoreNode", _cmds: list[str], _wait: bool, _shell: bool + ) -> list[str]: + cmd_outputs = [] for _cmd in _cmds: output = _target.cmd(_cmd, wait=_wait, shell=_shell) - outputs.append(output) - return outputs + cmd_outputs.append(output) + return cmd_outputs with concurrent.futures.ThreadPoolExecutor(max_workers=workers) as executor: futures = [] node_mappings = {} - for node in nodes: + for node, cmds in node_cmds: future = executor.submit(_node_cmds, node, cmds, wait, shell) node_mappings[future] = node futures.append(future) @@ -475,19 +461,17 @@ def run_cmds_threaded( def run_cmds_mp( - nodes: List["CoreNode"], - cmds: List[str], + node_cmds: list[tuple["CoreNode", list[str]]], wait: bool = True, shell: bool = False, workers: int = None, -) -> Tuple[Dict[int, List[str]], List[Exception]]: +) -> tuple[dict[int, list[str]], list[Exception]]: """ - Run a set of commands in order across a provided set of nodes. Each node will + Run the set of commands for the node provided. Each node will run the commands within the context of a process pool. This will not work for distributed nodes and throws an exception when encountered. - :param nodes: nodes to run commands in - :param cmds: commands to run in nodes + :param node_cmds: list of tuples of nodes and commands to run within them :param wait: True to wait for status, False otherwise :param shell: True to run shell like, False otherwise :param workers: number of workers for threadpool, uses library default otherwise @@ -498,7 +482,7 @@ def run_cmds_mp( with concurrent.futures.ProcessPoolExecutor(max_workers=workers) as executor: futures = [] node_mapping = {} - for node in nodes: + for node, cmds in node_cmds: node_cmds = [node.create_cmd(x) for x in cmds] if node.server: raise CoreError( @@ -521,8 +505,8 @@ def run_cmds_mp( def threadpool( - funcs: List[Tuple[Callable, Iterable[Any], Dict[Any, Any]]], workers: int = 10 -) -> Tuple[List[Any], List[Exception]]: + funcs: list[tuple[Callable, Iterable[Any], dict[Any, Any]]], workers: int = 10 +) -> tuple[list[Any], list[Exception]]: """ Run provided functions, arguments, and keywords within a threadpool collecting results and exceptions. @@ -575,7 +559,7 @@ def iface_config_id(node_id: int, iface_id: int = None) -> int: return node_id -def parse_iface_config_id(config_id: int) -> Tuple[int, Optional[int]]: +def parse_iface_config_id(config_id: int) -> tuple[int, Optional[int]]: """ Parses configuration id, that may be potentially derived from an interface for a node. diff --git a/daemon/core/xml/corexml.py b/daemon/core/xml/corexml.py index a413fc1a..d566b501 100644 --- a/daemon/core/xml/corexml.py +++ b/daemon/core/xml/corexml.py @@ -1,6 +1,6 @@ import logging from pathlib import Path -from typing import TYPE_CHECKING, Any, Dict, Generic, Optional, Type, TypeVar +from typing import TYPE_CHECKING, Any, Generic, Optional, TypeVar from lxml import etree @@ -17,6 +17,7 @@ from core.nodes.docker import DockerNode, DockerOptions from core.nodes.interface import CoreInterface from core.nodes.lxd import LxcNode, LxcOptions from core.nodes.network import CtrlNet, GreTapBridge, PtpNet, WlanNode +from core.nodes.podman import PodmanNode, PodmanOptions from core.nodes.wireless import WirelessNode from core.services.coreservices import CoreService @@ -26,7 +27,7 @@ if TYPE_CHECKING: from core.emane.emanemodel import EmaneModel from core.emulator.session import Session - EmaneModelType = Type[EmaneModel] + EmaneModelType = type[EmaneModel] T = TypeVar("T") @@ -86,7 +87,7 @@ def create_iface_data(iface_element: etree.Element) -> InterfaceData: def create_emane_model_config( node_id: int, model: "EmaneModelType", - config: Dict[str, str], + config: dict[str, str], iface_id: Optional[int], ) -> etree.Element: emane_element = etree.Element("emane_configuration") @@ -148,8 +149,8 @@ class NodeElement: class ServiceElement: - def __init__(self, service: Type[CoreService]) -> None: - self.service: Type[CoreService] = service + def __init__(self, service: type[CoreService]) -> None: + self.service: type[CoreService] = service self.element: etree.Element = etree.Element("service") add_attribute(self.element, "name", service.name) self.add_directories() @@ -225,6 +226,9 @@ class DeviceElement(NodeElement): elif isinstance(self.node, LxcNode): clazz = "lxc" image = self.node.image + elif isinstance(self.node, PodmanNode): + clazz = "podman" + image = self.node.image add_attribute(self.element, "class", clazz) add_attribute(self.element, "image", image) @@ -266,7 +270,7 @@ class NetworkElement(NodeElement): node_type = self.session.get_node_type(type(self.node)) add_attribute(self.element, "type", node_type.name) - def add_wireless_config(self, config: Dict[str, Configuration]) -> None: + def add_wireless_config(self, config: dict[str, Configuration]) -> None: wireless_element = etree.SubElement(self.element, "wireless") for config_item in config.values(): add_configuration(wireless_element, config_item.id, config_item.default) @@ -808,6 +812,8 @@ class CoreXmlReader: node_type = NodeTypes.DOCKER elif clazz == "lxc": node_type = NodeTypes.LXC + elif clazz == "podman": + node_type = NodeTypes.PODMAN _class = self.session.get_node_class(node_type) options = _class.create_options() options.icon = icon @@ -825,7 +831,7 @@ class CoreXmlReader: options.config_services.extend( x.get("name") for x in config_service_elements.iterchildren() ) - if isinstance(options, (DockerOptions, LxcOptions)): + if isinstance(options, (DockerOptions, LxcOptions, PodmanOptions)): options.image = image # get position information position_element = device_element.find("position") diff --git a/daemon/core/xml/corexmldeployment.py b/daemon/core/xml/corexmldeployment.py index c062a1d2..0b38e9b0 100644 --- a/daemon/core/xml/corexmldeployment.py +++ b/daemon/core/xml/corexmldeployment.py @@ -1,6 +1,6 @@ import os import socket -from typing import TYPE_CHECKING, List, Tuple +from typing import TYPE_CHECKING import netaddr from lxml import etree @@ -78,7 +78,7 @@ def get_address_type(address: str) -> str: return address_type -def get_ipv4_addresses(hostname: str) -> List[Tuple[str, str]]: +def get_ipv4_addresses(hostname: str) -> list[tuple[str, str]]: if hostname == "localhost": addresses = [] args = f"{IP} -o -f inet address show" diff --git a/daemon/core/xml/emanexml.py b/daemon/core/xml/emanexml.py index 91d8ce28..4b8ada70 100644 --- a/daemon/core/xml/emanexml.py +++ b/daemon/core/xml/emanexml.py @@ -1,7 +1,7 @@ import logging from pathlib import Path from tempfile import NamedTemporaryFile -from typing import TYPE_CHECKING, Dict, List, Optional, Set, Tuple +from typing import TYPE_CHECKING, Optional from lxml import etree @@ -22,7 +22,7 @@ if TYPE_CHECKING: _MAC_PREFIX = "02:02" -def is_external(config: Dict[str, str]) -> bool: +def is_external(config: dict[str, str]) -> bool: """ Checks if the configuration is for an external transport. @@ -32,7 +32,7 @@ def is_external(config: Dict[str, str]) -> bool: return config.get("external") == "1" -def _value_to_params(value: str) -> Optional[Tuple[str]]: +def _value_to_params(value: str) -> Optional[tuple[str]]: """ Helper to convert a parameter to a parameter tuple. @@ -113,9 +113,9 @@ def add_param(xml_element: etree.Element, name: str, value: str) -> None: def add_configurations( xml_element: etree.Element, - configurations: List[Configuration], - config: Dict[str, str], - config_ignore: Set, + configurations: list[Configuration], + config: dict[str, str], + config_ignore: set[str], ) -> None: """ Add emane model configurations to xml element. @@ -148,7 +148,7 @@ def build_platform_xml( nem_port: int, emane_net: EmaneNet, iface: CoreInterface, - config: Dict[str, str], + config: dict[str, str], ) -> None: """ Create platform xml for a nem/interface. @@ -209,7 +209,7 @@ def build_platform_xml( create_node_file(iface.node, platform_element, doc_name, file_name) -def create_transport_xml(iface: CoreInterface, config: Dict[str, str]) -> None: +def create_transport_xml(iface: CoreInterface, config: dict[str, str]) -> None: """ Build transport xml file for node and transport type. @@ -240,7 +240,7 @@ def create_transport_xml(iface: CoreInterface, config: Dict[str, str]) -> None: def create_phy_xml( - emane_model: "EmaneModel", iface: CoreInterface, config: Dict[str, str] + emane_model: "EmaneModel", iface: CoreInterface, config: dict[str, str] ) -> None: """ Create the phy xml document. @@ -261,7 +261,7 @@ def create_phy_xml( def create_mac_xml( - emane_model: "EmaneModel", iface: CoreInterface, config: Dict[str, str] + emane_model: "EmaneModel", iface: CoreInterface, config: dict[str, str] ) -> None: """ Create the mac xml document. @@ -284,7 +284,7 @@ def create_mac_xml( def create_nem_xml( - emane_model: "EmaneModel", iface: CoreInterface, config: Dict[str, str] + emane_model: "EmaneModel", iface: CoreInterface, config: dict[str, str] ) -> None: """ Create the nem xml document. diff --git a/daemon/poetry.lock b/daemon/poetry.lock index 2c8c6f28..c2aae40d 100644 --- a/daemon/poetry.lock +++ b/daemon/poetry.lock @@ -175,29 +175,26 @@ pyflakes = ">=2.2.0,<2.3.0" [[package]] name = "grpcio" -version = "1.49.1" +version = "1.54.2" description = "HTTP/2-based RPC framework" category = "main" optional = false python-versions = ">=3.7" -[package.dependencies] -six = ">=1.5.2" - [package.extras] -protobuf = ["grpcio-tools (>=1.49.1)"] +protobuf = ["grpcio-tools (>=1.54.2)"] [[package]] name = "grpcio-tools" -version = "1.49.1" +version = "1.54.2" description = "Protobuf code generator for gRPC" category = "dev" optional = false python-versions = ">=3.7" [package.dependencies] -grpcio = ">=1.49.1" -protobuf = ">=4.21.3,<5.0dev" +grpcio = ">=1.54.2" +protobuf = ">=4.21.6,<5.0dev" setuptools = "*" [[package]] @@ -374,14 +371,14 @@ python-versions = ">=3.7" [[package]] name = "Pillow" -version = "9.2.0" +version = "9.4.0" description = "Python Imaging Library (Fork)" category = "main" optional = false python-versions = ">=3.7" [package.extras] -docs = ["furo", "olefile", "sphinx (>=2.4)", "sphinx-copybutton", "sphinx-issues (>=3.0.1)", "sphinx-removed-in", "sphinxext-opengraph"] +docs = ["furo", "olefile", "sphinx (>=2.4)", "sphinx-copybutton", "sphinx-inline-tabs", "sphinx-issues (>=3.0.1)", "sphinx-removed-in", "sphinxext-opengraph"] tests = ["check-manifest", "coverage", "defusedxml", "markdown2", "olefile", "packaging", "pyroma", "pytest", "pytest-cov", "pytest-timeout"] [[package]] @@ -513,11 +510,11 @@ testing = ["argcomplete", "hypothesis (>=3.56)", "mock", "nose", "requests", "xm [[package]] name = "PyYAML" -version = "5.4" +version = "6.0.1" description = "YAML parser and emitter for Python" category = "main" optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*" +python-versions = ">=3.6" [[package]] name = "setuptools" @@ -584,7 +581,7 @@ test = ["covdefaults (>=2.2.2)", "coverage (>=7.1)", "coverage-enable-subprocess [metadata] lock-version = "1.1" python-versions = "^3.9" -content-hash = "b78118206a714bae7b839da039024e850a1fee06d2768acd6f452490de4abb0e" +content-hash = "10902a50368c4381aec5a3e72a221a4c4225ae1be17ee38600f89aaee4a49c1f" [metadata.files] atomicwrites = [ @@ -755,98 +752,98 @@ flake8 = [ {file = "flake8-3.8.2.tar.gz", hash = "sha256:c69ac1668e434d37a2d2880b3ca9aafd54b3a10a3ac1ab101d22f29e29cf8634"}, ] grpcio = [ - {file = "grpcio-1.49.1-cp310-cp310-linux_armv7l.whl", hash = "sha256:fd86040232e805b8e6378b2348c928490ee595b058ce9aaa27ed8e4b0f172b20"}, - {file = "grpcio-1.49.1-cp310-cp310-macosx_10_10_x86_64.whl", hash = "sha256:6fd0c9cede9552bf00f8c5791d257d5bf3790d7057b26c59df08be5e7a1e021d"}, - {file = "grpcio-1.49.1-cp310-cp310-manylinux_2_17_aarch64.whl", hash = "sha256:d0d402e158d4e84e49c158cb5204119d55e1baf363ee98d6cb5dce321c3a065d"}, - {file = "grpcio-1.49.1-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:822ceec743d42a627e64ea266059a62d214c5a3cdfcd0d7fe2b7a8e4e82527c7"}, - {file = "grpcio-1.49.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:2106d9c16527f0a85e2eea6e6b91a74fc99579c60dd810d8690843ea02bc0f5f"}, - {file = "grpcio-1.49.1-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:52dd02b7e7868233c571b49bc38ebd347c3bb1ff8907bb0cb74cb5f00c790afc"}, - {file = "grpcio-1.49.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:120fecba2ec5d14b5a15d11063b39783fda8dc8d24addd83196acb6582cabd9b"}, - {file = "grpcio-1.49.1-cp310-cp310-win32.whl", hash = "sha256:f1a3b88e3c53c1a6e6bed635ec1bbb92201bb6a1f2db186179f7f3f244829788"}, - {file = "grpcio-1.49.1-cp310-cp310-win_amd64.whl", hash = "sha256:a7d0017b92d3850abea87c1bdec6ea41104e71c77bca44c3e17f175c6700af62"}, - {file = "grpcio-1.49.1-cp311-cp311-linux_armv7l.whl", hash = "sha256:9fb17ff8c0d56099ac6ebfa84f670c5a62228d6b5c695cf21c02160c2ac1446b"}, - {file = "grpcio-1.49.1-cp311-cp311-macosx_10_10_x86_64.whl", hash = "sha256:075f2d06e3db6b48a2157a1bcd52d6cbdca980dd18988fe6afdb41795d51625f"}, - {file = "grpcio-1.49.1-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:46d93a1b4572b461a227f1db6b8d35a88952db1c47e5fadcf8b8a2f0e1dd9201"}, - {file = "grpcio-1.49.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:dc79b2b37d779ac42341ddef40ad5bf0966a64af412c89fc2b062e3ddabb093f"}, - {file = "grpcio-1.49.1-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:5f8b3a971c7820ea9878f3fd70086240a36aeee15d1b7e9ecbc2743b0e785568"}, - {file = "grpcio-1.49.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:49b301740cf5bc8fed4fee4c877570189ae3951432d79fa8e524b09353659811"}, - {file = "grpcio-1.49.1-cp311-cp311-win32.whl", hash = "sha256:1c66a25afc6c71d357867b341da594a5587db5849b48f4b7d5908d236bb62ede"}, - {file = "grpcio-1.49.1-cp311-cp311-win_amd64.whl", hash = "sha256:6b6c3a95d27846f4145d6967899b3ab25fffc6ae99544415e1adcacef84842d2"}, - {file = "grpcio-1.49.1-cp37-cp37m-linux_armv7l.whl", hash = "sha256:1cc400c8a2173d1c042997d98a9563e12d9bb3fb6ad36b7f355bc77c7663b8af"}, - {file = "grpcio-1.49.1-cp37-cp37m-macosx_10_10_x86_64.whl", hash = "sha256:34f736bd4d0deae90015c0e383885b431444fe6b6c591dea288173df20603146"}, - {file = "grpcio-1.49.1-cp37-cp37m-manylinux_2_17_aarch64.whl", hash = "sha256:196082b9c89ebf0961dcd77cb114bed8171964c8e3063b9da2fb33536a6938ed"}, - {file = "grpcio-1.49.1-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:8c9f89c42749890618cd3c2464e1fbf88446e3d2f67f1e334c8e5db2f3272bbd"}, - {file = "grpcio-1.49.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:64419cb8a5b612cdb1550c2fd4acbb7d4fb263556cf4625f25522337e461509e"}, - {file = "grpcio-1.49.1-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:8a5272061826e6164f96e3255405ef6f73b88fd3e8bef464c7d061af8585ac62"}, - {file = "grpcio-1.49.1-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:ea9d0172445241ad7cb49577314e39d0af2c5267395b3561d7ced5d70458a9f3"}, - {file = "grpcio-1.49.1-cp37-cp37m-win32.whl", hash = "sha256:2070e87d95991473244c72d96d13596c751cb35558e11f5df5414981e7ed2492"}, - {file = "grpcio-1.49.1-cp37-cp37m-win_amd64.whl", hash = "sha256:4fcedcab49baaa9db4a2d240ac81f2d57eb0052b1c6a9501b46b8ae912720fbf"}, - {file = "grpcio-1.49.1-cp38-cp38-linux_armv7l.whl", hash = "sha256:afbb3475cf7f4f7d380c2ca37ee826e51974f3e2665613996a91d6a58583a534"}, - {file = "grpcio-1.49.1-cp38-cp38-macosx_10_10_x86_64.whl", hash = "sha256:a4f9ba141380abde6c3adc1727f21529137a2552002243fa87c41a07e528245c"}, - {file = "grpcio-1.49.1-cp38-cp38-manylinux_2_17_aarch64.whl", hash = "sha256:cf0a1fb18a7204b9c44623dfbd1465b363236ce70c7a4ed30402f9f60d8b743b"}, - {file = "grpcio-1.49.1-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:17bb6fe72784b630728c6cff9c9d10ccc3b6d04e85da6e0a7b27fb1d135fac62"}, - {file = "grpcio-1.49.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:18305d5a082d1593b005a895c10041f833b16788e88b02bb81061f5ebcc465df"}, - {file = "grpcio-1.49.1-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:b6a1b39e59ac5a3067794a0e498911cf2e37e4b19ee9e9977dc5e7051714f13f"}, - {file = "grpcio-1.49.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:0e20d59aafc086b1cc68400463bddda6e41d3e5ed30851d1e2e0f6a2e7e342d3"}, - {file = "grpcio-1.49.1-cp38-cp38-win32.whl", hash = "sha256:e1e83233d4680863a421f3ee4a7a9b80d33cd27ee9ed7593bc93f6128302d3f2"}, - {file = "grpcio-1.49.1-cp38-cp38-win_amd64.whl", hash = "sha256:221d42c654d2a41fa31323216279c73ed17d92f533bc140a3390cc1bd78bf63c"}, - {file = "grpcio-1.49.1-cp39-cp39-linux_armv7l.whl", hash = "sha256:fa9e6e61391e99708ac87fc3436f6b7b9c6b845dc4639b406e5e61901e1aacde"}, - {file = "grpcio-1.49.1-cp39-cp39-macosx_10_10_x86_64.whl", hash = "sha256:9b449e966ef518ce9c860d21f8afe0b0f055220d95bc710301752ac1db96dd6a"}, - {file = "grpcio-1.49.1-cp39-cp39-manylinux_2_17_aarch64.whl", hash = "sha256:aa34d2ad9f24e47fa9a3172801c676e4037d862247e39030165fe83821a7aafd"}, - {file = "grpcio-1.49.1-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:5207f4eed1b775d264fcfe379d8541e1c43b878f2b63c0698f8f5c56c40f3d68"}, - {file = "grpcio-1.49.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0b24a74651438d45619ac67004638856f76cc13d78b7478f2457754cbcb1c8ad"}, - {file = "grpcio-1.49.1-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:fe763781669790dc8b9618e7e677c839c87eae6cf28b655ee1fa69ae04eea03f"}, - {file = "grpcio-1.49.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:2f2ff7ba0f8f431f32d4b4bc3a3713426949d3533b08466c4ff1b2b475932ca8"}, - {file = "grpcio-1.49.1-cp39-cp39-win32.whl", hash = "sha256:08ff74aec8ff457a89b97152d36cb811dcc1d17cd5a92a65933524e363327394"}, - {file = "grpcio-1.49.1-cp39-cp39-win_amd64.whl", hash = "sha256:274ffbb39717918c514b35176510ae9be06e1d93121e84d50b350861dcb9a705"}, - {file = "grpcio-1.49.1.tar.gz", hash = "sha256:d4725fc9ec8e8822906ae26bb26f5546891aa7fbc3443de970cc556d43a5c99f"}, + {file = "grpcio-1.54.2-cp310-cp310-linux_armv7l.whl", hash = "sha256:40e1cbf69d6741b40f750f3cccc64326f927ac6145a9914d33879e586002350c"}, + {file = "grpcio-1.54.2-cp310-cp310-macosx_12_0_universal2.whl", hash = "sha256:2288d76e4d4aa7ef3fe7a73c1c470b66ea68e7969930e746a8cd8eca6ef2a2ea"}, + {file = "grpcio-1.54.2-cp310-cp310-manylinux_2_17_aarch64.whl", hash = "sha256:c0e3155fc5335ec7b3b70f15230234e529ca3607b20a562b6c75fb1b1218874c"}, + {file = "grpcio-1.54.2-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:9bf88004fe086c786dc56ef8dd6cb49c026833fdd6f42cb853008bce3f907148"}, + {file = "grpcio-1.54.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:2be88c081e33f20630ac3343d8ad9f1125f32987968e9c8c75c051c9800896e8"}, + {file = "grpcio-1.54.2-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:33d40954199bddbb6a78f8f6f2b2082660f381cd2583ec860a6c2fa7c8400c08"}, + {file = "grpcio-1.54.2-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:b52d00d1793d290c81ad6a27058f5224a7d5f527867e5b580742e1bd211afeee"}, + {file = "grpcio-1.54.2-cp310-cp310-win32.whl", hash = "sha256:881d058c5ccbea7cc2c92085a11947b572498a27ef37d3eef4887f499054dca8"}, + {file = "grpcio-1.54.2-cp310-cp310-win_amd64.whl", hash = "sha256:0212e2f7fdf7592e4b9d365087da30cb4d71e16a6f213120c89b4f8fb35a3ab3"}, + {file = "grpcio-1.54.2-cp311-cp311-linux_armv7l.whl", hash = "sha256:1e623e0cf99a0ac114f091b3083a1848dbc64b0b99e181473b5a4a68d4f6f821"}, + {file = "grpcio-1.54.2-cp311-cp311-macosx_10_10_universal2.whl", hash = "sha256:66233ccd2a9371158d96e05d082043d47dadb18cbb294dc5accfdafc2e6b02a7"}, + {file = "grpcio-1.54.2-cp311-cp311-manylinux_2_17_aarch64.whl", hash = "sha256:4cb283f630624ebb16c834e5ac3d7880831b07cbe76cb08ab7a271eeaeb8943e"}, + {file = "grpcio-1.54.2-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:2a1e601ee31ef30a9e2c601d0867e236ac54c922d32ed9f727b70dd5d82600d5"}, + {file = "grpcio-1.54.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f8da84bbc61a4e92af54dc96344f328e5822d574f767e9b08e1602bb5ddc254a"}, + {file = "grpcio-1.54.2-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:5008964885e8d23313c8e5ea0d44433be9bfd7e24482574e8cc43c02c02fc796"}, + {file = "grpcio-1.54.2-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:a2f5a1f1080ccdc7cbaf1171b2cf384d852496fe81ddedeb882d42b85727f610"}, + {file = "grpcio-1.54.2-cp311-cp311-win32.whl", hash = "sha256:b74ae837368cfffeb3f6b498688a123e6b960951be4dec0e869de77e7fa0439e"}, + {file = "grpcio-1.54.2-cp311-cp311-win_amd64.whl", hash = "sha256:8cdbcbd687e576d48f7886157c95052825ca9948c0ed2afdc0134305067be88b"}, + {file = "grpcio-1.54.2-cp37-cp37m-linux_armv7l.whl", hash = "sha256:782f4f8662a2157c4190d0f99eaaebc602899e84fb1e562a944e5025929e351c"}, + {file = "grpcio-1.54.2-cp37-cp37m-macosx_10_10_universal2.whl", hash = "sha256:714242ad0afa63a2e6dabd522ae22e1d76e07060b5af2ddda5474ba4f14c2c94"}, + {file = "grpcio-1.54.2-cp37-cp37m-manylinux_2_17_aarch64.whl", hash = "sha256:f900ed4ad7a0f1f05d35f955e0943944d5a75f607a836958c6b8ab2a81730ef2"}, + {file = "grpcio-1.54.2-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:96a41817d2c763b1d0b32675abeb9179aa2371c72aefdf74b2d2b99a1b92417b"}, + {file = "grpcio-1.54.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:70fcac7b94f4c904152809a050164650ac81c08e62c27aa9f156ac518029ebbe"}, + {file = "grpcio-1.54.2-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:fd6c6c29717724acf9fc1847c4515d57e4dc12762452457b9cb37461f30a81bb"}, + {file = "grpcio-1.54.2-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:c2392f5b5d84b71d853918687d806c1aa4308109e5ca158a16e16a6be71041eb"}, + {file = "grpcio-1.54.2-cp37-cp37m-win_amd64.whl", hash = "sha256:51630c92591d6d3fe488a7c706bd30a61594d144bac7dee20c8e1ce78294f474"}, + {file = "grpcio-1.54.2-cp38-cp38-linux_armv7l.whl", hash = "sha256:b04202453941a63b36876a7172b45366dc0cde10d5fd7855c0f4a4e673c0357a"}, + {file = "grpcio-1.54.2-cp38-cp38-macosx_10_10_universal2.whl", hash = "sha256:89dde0ac72a858a44a2feb8e43dc68c0c66f7857a23f806e81e1b7cc7044c9cf"}, + {file = "grpcio-1.54.2-cp38-cp38-manylinux_2_17_aarch64.whl", hash = "sha256:09d4bfd84686cd36fd11fd45a0732c7628308d094b14d28ea74a81db0bce2ed3"}, + {file = "grpcio-1.54.2-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:7fc2b4edb938c8faa4b3c3ea90ca0dd89b7565a049e8e4e11b77e60e4ed2cc05"}, + {file = "grpcio-1.54.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:61f7203e2767800edee7a1e1040aaaf124a35ce0c7fe0883965c6b762defe598"}, + {file = "grpcio-1.54.2-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:e416c8baf925b5a1aff31f7f5aecc0060b25d50cce3a5a7255dc5cf2f1d4e5eb"}, + {file = "grpcio-1.54.2-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:dc80c9c6b608bf98066a038e0172013a49cfa9a08d53335aefefda2c64fc68f4"}, + {file = "grpcio-1.54.2-cp38-cp38-win32.whl", hash = "sha256:8d6192c37a30a115f4663592861f50e130caed33efc4eec24d92ec881c92d771"}, + {file = "grpcio-1.54.2-cp38-cp38-win_amd64.whl", hash = "sha256:46a057329938b08e5f0e12ea3d7aed3ecb20a0c34c4a324ef34e00cecdb88a12"}, + {file = "grpcio-1.54.2-cp39-cp39-linux_armv7l.whl", hash = "sha256:2296356b5c9605b73ed6a52660b538787094dae13786ba53080595d52df13a98"}, + {file = "grpcio-1.54.2-cp39-cp39-macosx_10_10_universal2.whl", hash = "sha256:c72956972e4b508dd39fdc7646637a791a9665b478e768ffa5f4fe42123d5de1"}, + {file = "grpcio-1.54.2-cp39-cp39-manylinux_2_17_aarch64.whl", hash = "sha256:9bdbb7624d65dc0ed2ed8e954e79ab1724526f09b1efa88dcd9a1815bf28be5f"}, + {file = "grpcio-1.54.2-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:4c44e1a765b31e175c391f22e8fc73b2a2ece0e5e6ff042743d8109b5d2eff9f"}, + {file = "grpcio-1.54.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5cc928cfe6c360c1df636cf7991ab96f059666ac7b40b75a769410cc6217df9c"}, + {file = "grpcio-1.54.2-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:a08920fa1a97d4b8ee5db2f31195de4a9def1a91bc003544eb3c9e6b8977960a"}, + {file = "grpcio-1.54.2-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:4864f99aac207e3e45c5e26c6cbb0ad82917869abc2f156283be86c05286485c"}, + {file = "grpcio-1.54.2-cp39-cp39-win32.whl", hash = "sha256:b38b3de8cff5bc70f8f9c615f51b48eff7313fc9aca354f09f81b73036e7ddfa"}, + {file = "grpcio-1.54.2-cp39-cp39-win_amd64.whl", hash = "sha256:be48496b0e00460717225e7680de57c38be1d8629dc09dadcd1b3389d70d942b"}, + {file = "grpcio-1.54.2.tar.gz", hash = "sha256:50a9f075eeda5097aa9a182bb3877fe1272875e45370368ac0ee16ab9e22d019"}, ] grpcio-tools = [ - {file = "grpcio-tools-1.49.1.tar.gz", hash = "sha256:84cc64e5b46bad43d5d7bd2fd772b656eba0366961187a847e908e2cb735db91"}, - {file = "grpcio_tools-1.49.1-cp310-cp310-linux_armv7l.whl", hash = "sha256:2dfb6c7ece84d46bd690b23d3e060d18115c8bc5047d2e8a33e6747ed323a348"}, - {file = "grpcio_tools-1.49.1-cp310-cp310-macosx_10_10_x86_64.whl", hash = "sha256:8f452a107c054a04db2570f7851a07f060313c6e841b0d394ce6030d598290e6"}, - {file = "grpcio_tools-1.49.1-cp310-cp310-manylinux_2_17_aarch64.whl", hash = "sha256:6a198871b582287213c4d70792bf275e1d7cf34eed1d019f534ddf4cd15ab039"}, - {file = "grpcio_tools-1.49.1-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a0cca67a7d0287bdc855d81fdd38dc949c4273273a74f832f9e520abe4f20bc6"}, - {file = "grpcio_tools-1.49.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bdaff4c89eecb37c247b93025410db68114d97fa093cbb028e9bd7cda5912473"}, - {file = "grpcio_tools-1.49.1-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:bb8773118ad315db317d7b22b5ff75d649ca20931733281209e7cbd8c0fad53e"}, - {file = "grpcio_tools-1.49.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:7cc5534023735b8a8f56760b7c533918f874ce5a9064d7c5456d2709ae2b31f9"}, - {file = "grpcio_tools-1.49.1-cp310-cp310-win32.whl", hash = "sha256:d277642acbe305f5586f9597b78fb9970d6633eb9f89c61e429c92c296c37129"}, - {file = "grpcio_tools-1.49.1-cp310-cp310-win_amd64.whl", hash = "sha256:eed599cf08fc1a06c72492d3c5750c32f58de3750eddd984af1f257c14326701"}, - {file = "grpcio_tools-1.49.1-cp311-cp311-linux_armv7l.whl", hash = "sha256:9e5c13809ab2f245398e8446c4c3b399a62d591db651e46806cccf52a700452e"}, - {file = "grpcio_tools-1.49.1-cp311-cp311-macosx_10_10_x86_64.whl", hash = "sha256:ab3d0ee9623720ee585fdf3753b3755d3144a4a8ae35bca8e3655fa2f41056be"}, - {file = "grpcio_tools-1.49.1-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:6ba87e3512bc91d78bf9febcfb522eadda171d2d4ddaf886066b0f01aa4929ad"}, - {file = "grpcio_tools-1.49.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:13e13b3643e7577a3ec13b79689eb4d7548890b1e104c04b9ed6557a3c3dd452"}, - {file = "grpcio_tools-1.49.1-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:324f67d9cb4b7058b6ce45352fb64c20cc1fa04c34d97ad44772cfe6a4ae0cf5"}, - {file = "grpcio_tools-1.49.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:a64bab81b220c50033f584f57978ebbea575f09c1ccee765cd5c462177988098"}, - {file = "grpcio_tools-1.49.1-cp311-cp311-win32.whl", hash = "sha256:f632d376f92f23e5931697a3acf1b38df7eb719774213d93c52e02acd2d529ac"}, - {file = "grpcio_tools-1.49.1-cp311-cp311-win_amd64.whl", hash = "sha256:28ff2b978d9509474928b9c096a0cce4eaa9c8f7046136aee1545f6211ed8126"}, - {file = "grpcio_tools-1.49.1-cp37-cp37m-linux_armv7l.whl", hash = "sha256:46afd3cb7e555187451a5d283f108cdef397952a662cb48680afc615b158864a"}, - {file = "grpcio_tools-1.49.1-cp37-cp37m-macosx_10_10_x86_64.whl", hash = "sha256:9284568b728e41fa8f7e9c2e7399545d605f75d8072ef0e9aa2a05655cb679eb"}, - {file = "grpcio_tools-1.49.1-cp37-cp37m-manylinux_2_17_aarch64.whl", hash = "sha256:aa34442cf787732cb41f2aa6172007e24f480b8b9d3dc5166de80d63e9072ea4"}, - {file = "grpcio_tools-1.49.1-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:3b8c9eb5a4250905414cd53a68caea3eb8f0c515aadb689e6e81b71ebe9ab5c6"}, - {file = "grpcio_tools-1.49.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ab15db024051bf21feb21c29cb2c3ea0a2e4f5cf341d46ef76e17fcf6aaef164"}, - {file = "grpcio_tools-1.49.1-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:502084b622f758bef620a9107c2db9fcdf66d26c7e0e481d6bb87db4dc917d70"}, - {file = "grpcio_tools-1.49.1-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:4085890b77c640085f82bf1e90a0ea166ce48000bc2f5180914b974783c9c0a8"}, - {file = "grpcio_tools-1.49.1-cp37-cp37m-win32.whl", hash = "sha256:da0edb984699769ce02e18e3392d54b59a7a3f93acd285a68043f5bde4fc028e"}, - {file = "grpcio_tools-1.49.1-cp37-cp37m-win_amd64.whl", hash = "sha256:9887cd622770271101a7dd1832845d64744c3f88fd11ccb2620394079197a42e"}, - {file = "grpcio_tools-1.49.1-cp38-cp38-linux_armv7l.whl", hash = "sha256:8440fe7dae6a40c279e3a24b82793735babd38ecbb0d07bb712ff9c8963185d9"}, - {file = "grpcio_tools-1.49.1-cp38-cp38-macosx_10_10_x86_64.whl", hash = "sha256:b5de2bb7dd6b6231da9b1556ade981513330b740e767f1d902c71ceee0a7d196"}, - {file = "grpcio_tools-1.49.1-cp38-cp38-manylinux_2_17_aarch64.whl", hash = "sha256:1e6f06a763aea7836b63d9c117347f2bf7038008ceef72758815c9e09c5fb1fc"}, - {file = "grpcio_tools-1.49.1-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:e31562f90120318c5395aabec0f2f69ad8c14b6676996b7730d9d2eaf9415d57"}, - {file = "grpcio_tools-1.49.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:49ef9a4e389a618157a9daa9fafdfeeaef1ece9adda7f50f85db928f24d4b3e8"}, - {file = "grpcio_tools-1.49.1-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:b384cb8e8d9bcb55ee8f9b064374561c7a1a05d848249581403d36fc7060032f"}, - {file = "grpcio_tools-1.49.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:73732f77943ac3e898879cbb29c27253aa3c47566b8a59780fd24c6a54de1b66"}, - {file = "grpcio_tools-1.49.1-cp38-cp38-win32.whl", hash = "sha256:b594b2745a5ba9e7a76ce561bc5ab40bc65bb44743c505529b1e4f12af29104d"}, - {file = "grpcio_tools-1.49.1-cp38-cp38-win_amd64.whl", hash = "sha256:680fbc88f8709ddcabb88f86749f2d8e429160890cff2c70680880a6970d4eef"}, - {file = "grpcio_tools-1.49.1-cp39-cp39-linux_armv7l.whl", hash = "sha256:e8c3869121860f6767eedb7d24fc54dfd71e737fdfbb26e1334684606f3274fd"}, - {file = "grpcio_tools-1.49.1-cp39-cp39-macosx_10_10_x86_64.whl", hash = "sha256:73e9d7c886ba10e20c97d1dab0ff961ba5800757ae5e31be21b1cda8130c52f8"}, - {file = "grpcio_tools-1.49.1-cp39-cp39-manylinux_2_17_aarch64.whl", hash = "sha256:1760de2dd2c4f08de87b039043a4797f3c17193656e7e3eb84e92f0517083c0c"}, - {file = "grpcio_tools-1.49.1-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:cd4b1e216dd04d9245ee8f4e601a1f98c25e6e417ea5cf8d825c50589a8b447e"}, - {file = "grpcio_tools-1.49.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c1c28751ab5955cae563d07677e799233f0fe1c0fc49d9cbd61ff1957e83617f"}, - {file = "grpcio_tools-1.49.1-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:c24239c3ee9ed16314c14b4e24437b5079ebc344f343f33629a582f8699f583b"}, - {file = "grpcio_tools-1.49.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:892d3dacf1942820f0b7a868a30e6fbcdf5bec08543b682c7274b0101cee632d"}, - {file = "grpcio_tools-1.49.1-cp39-cp39-win32.whl", hash = "sha256:704d21509ec06efc9d034dbe70e7152715aac004941f4f0f553cf3a0aff15bd5"}, - {file = "grpcio_tools-1.49.1-cp39-cp39-win_amd64.whl", hash = "sha256:1efa0c221c719433f441ac0e026fc3c4dbc9a1a08a552ecdc707775e2f2fbbae"}, + {file = "grpcio-tools-1.54.2.tar.gz", hash = "sha256:e11c2c2aee53f340992e8e4d6a59172cbbbd0193f1351de98c4f810a5041d5ca"}, + {file = "grpcio_tools-1.54.2-cp310-cp310-linux_armv7l.whl", hash = "sha256:2b96f5f17d3156058be247fd25b062b4768138665694c00b056659618b8fb418"}, + {file = "grpcio_tools-1.54.2-cp310-cp310-macosx_12_0_universal2.whl", hash = "sha256:11939c9a8a39bd4815c7e88cb2fee48e1948775b59dbb06de8fcae5991e84f9e"}, + {file = "grpcio_tools-1.54.2-cp310-cp310-manylinux_2_17_aarch64.whl", hash = "sha256:129de5579f95d6a55dde185f188b4cbe19d1e2f1471425431d9930c31d300d70"}, + {file = "grpcio_tools-1.54.2-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:c4128c01cd6f5ea8f7c2db405dbfd8582cd967d36e6fa0952565436633b0e591"}, + {file = "grpcio_tools-1.54.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e5c7292dd899ad8fa09a2be96719648cee37b17909fe8c12007e3bff58ebee61"}, + {file = "grpcio_tools-1.54.2-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:5ef30c2dbc63c1e0a462423ca4f95001814d26ef4fe66208e53fcf220ea3b717"}, + {file = "grpcio_tools-1.54.2-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:4abfc1892380abe6cef381eab86f9350cbd703bfe5d834095aa66fd91c886b6d"}, + {file = "grpcio_tools-1.54.2-cp310-cp310-win32.whl", hash = "sha256:9acf443dcf6f68fbea3b7fb519e1716e014db1a561939f5aecc4abda74e4015d"}, + {file = "grpcio_tools-1.54.2-cp310-cp310-win_amd64.whl", hash = "sha256:21b9d2dee80f3f77e4097252e7f0db89772335a7300b72ab3d2e5c280872b1db"}, + {file = "grpcio_tools-1.54.2-cp311-cp311-linux_armv7l.whl", hash = "sha256:7b24fbab9e7598518ce4549e066df00aab79c2bf9bedcdde23fb5ef6a3cf532f"}, + {file = "grpcio_tools-1.54.2-cp311-cp311-macosx_10_10_universal2.whl", hash = "sha256:7baa210c20f71a242d9ae0e02734628f6948e8bee3bf538647894af427d28800"}, + {file = "grpcio_tools-1.54.2-cp311-cp311-manylinux_2_17_aarch64.whl", hash = "sha256:e3d0e5188ff8dbaddac2ee44731d36f09c4eccd3eac7328e547862c44f75cacd"}, + {file = "grpcio_tools-1.54.2-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:27671c68c7e0e3c5ff9967f5500799f65a04e7b153b8ce10243c87c43199039d"}, + {file = "grpcio_tools-1.54.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f39d8e8806b8857fb473ca6a9c7bd800b0673dfdb7283ff569af0345a222f32c"}, + {file = "grpcio_tools-1.54.2-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:8e4c5a48f7b2e8798ce381498ee7b9a83c65b87ae66ee5022387394e5eb51771"}, + {file = "grpcio_tools-1.54.2-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:4f285f8ef3de422717a36bd372239ae778b8cc112ce780ca3c7fe266dadc49fb"}, + {file = "grpcio_tools-1.54.2-cp311-cp311-win32.whl", hash = "sha256:0f952c8a5c47e9204fe8959f7e9add149e660f6579d67cf65024c32736d34caf"}, + {file = "grpcio_tools-1.54.2-cp311-cp311-win_amd64.whl", hash = "sha256:3237149beec39e897fd62cef4aa1e1cd9422d7a95661d24bd0a79200b167e730"}, + {file = "grpcio_tools-1.54.2-cp37-cp37m-linux_armv7l.whl", hash = "sha256:0ab1b323905d449298523db5d34fa5bf5fffd645bd872b25598e2f8a01f0ea39"}, + {file = "grpcio_tools-1.54.2-cp37-cp37m-macosx_10_10_universal2.whl", hash = "sha256:7d7e6e8d62967b3f037f952620cb7381cc39a4bd31790c75fcfba56cc975d70b"}, + {file = "grpcio_tools-1.54.2-cp37-cp37m-manylinux_2_17_aarch64.whl", hash = "sha256:7f4624ef2e76a3a5313c4e61a81be38bcc16b59a68a85d30758b84cd2102b161"}, + {file = "grpcio_tools-1.54.2-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:e543f457935ba7b763b121f1bf893974393b4d30065042f947f85a8d81081b80"}, + {file = "grpcio_tools-1.54.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0239b929eb8b3b30b2397eef3b9abb245087754d77c3721e3be43c44796de87d"}, + {file = "grpcio_tools-1.54.2-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:0de05c7698c655e9a240dc34ae91d6017b93143ac89e5b20046d7ca3bd09c27c"}, + {file = "grpcio_tools-1.54.2-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:a3ce0b98fb581c471424d2cda45120f57658ed97677c6fec4d6decf5d7c1b976"}, + {file = "grpcio_tools-1.54.2-cp37-cp37m-win_amd64.whl", hash = "sha256:37393ef90674964175923afe3859fc5a208e1ece565f642b4f76a8c0224a0993"}, + {file = "grpcio_tools-1.54.2-cp38-cp38-linux_armv7l.whl", hash = "sha256:8e4531267736d88fde1022b36dd42ed8163e3575bcbd12bfed96662872aa93fe"}, + {file = "grpcio_tools-1.54.2-cp38-cp38-macosx_10_10_universal2.whl", hash = "sha256:a0b7049814442f918b522d66b1d015286afbeb9e6d141af54bbfafe31710a3c8"}, + {file = "grpcio_tools-1.54.2-cp38-cp38-manylinux_2_17_aarch64.whl", hash = "sha256:b80585e06c4f0082327eb5c9ad96fbdb2b0e7c14971ea5099fe78c22f4608451"}, + {file = "grpcio_tools-1.54.2-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:39fd530cfdf58dc05125775cc233b05554d553d27478f14ae5fd8a6306f0cb28"}, + {file = "grpcio_tools-1.54.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3bb9ec4aea0f2b3006fb002fa59e5c10f92b48fc374619fbffd14d2b0e388c3e"}, + {file = "grpcio_tools-1.54.2-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:d512de051342a576bb89777476d13c5266d9334cf4badb6468aed9dc8f5bdec1"}, + {file = "grpcio_tools-1.54.2-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:1b8ee3099c51ce987fa8a08e6b93fc342b10228415dd96b5c0caa0387f636a6f"}, + {file = "grpcio_tools-1.54.2-cp38-cp38-win32.whl", hash = "sha256:6037f123905dc0141f7c8383ca616ef0195e79cd3b4d82faaee789d4045e891b"}, + {file = "grpcio_tools-1.54.2-cp38-cp38-win_amd64.whl", hash = "sha256:10dd41862f579d185c60f629b5ee89103e216f63b576079d258d974d980bad87"}, + {file = "grpcio_tools-1.54.2-cp39-cp39-linux_armv7l.whl", hash = "sha256:f6787d07fdab31a32c433c1ba34883dea6559d8a3fbe08fb93d834ca34136b71"}, + {file = "grpcio_tools-1.54.2-cp39-cp39-macosx_10_10_universal2.whl", hash = "sha256:21b1467e31e44429d2a78b50135c9cdbd4b8f6d3b5cd548bc98985d3bdc352d0"}, + {file = "grpcio_tools-1.54.2-cp39-cp39-manylinux_2_17_aarch64.whl", hash = "sha256:30a49b8b168aced2a4ff40959e6c4383ad6cfd7a20839a47a215e9837eb722dc"}, + {file = "grpcio_tools-1.54.2-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:8742122782953d2fd038f0a199f047a24e941cc9718b1aac90876dbdb7167739"}, + {file = "grpcio_tools-1.54.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:503ef1351c62fb1d6747eaf74932b609d8fdd4345b3591ef910adef8fa9969d0"}, + {file = "grpcio_tools-1.54.2-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:72d15de4c4b6a764a76c4ae69d99c35f7a0751223688c3f7e62dfa95eb4f61be"}, + {file = "grpcio_tools-1.54.2-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:df079479fb1b9e488334312e35ebbf30cbf5ecad6c56599f1a961800b33ab7c1"}, + {file = "grpcio_tools-1.54.2-cp39-cp39-win32.whl", hash = "sha256:49c2846dcc4803476e839d8bd4db8845e928f19130e0ea86121f2d1f43d2b452"}, + {file = "grpcio_tools-1.54.2-cp39-cp39-win_amd64.whl", hash = "sha256:b82ca472db9c914c44e39a41e9e8bd3ed724523dd7aff5ce37592b8d16920ed9"}, ] identify = [ {file = "identify-2.5.18-py2.py3-none-any.whl", hash = "sha256:93aac7ecf2f6abf879b8f29a8002d3c6de7086b8c28d88e1ad15045a15ab63f9"}, @@ -1029,64 +1026,83 @@ pathspec = [ {file = "pathspec-0.11.0.tar.gz", hash = "sha256:64d338d4e0914e91c1792321e6907b5a593f1ab1851de7fc269557a21b30ebbc"}, ] Pillow = [ - {file = "Pillow-9.2.0-cp310-cp310-macosx_10_10_x86_64.whl", hash = "sha256:a9c9bc489f8ab30906d7a85afac4b4944a572a7432e00698a7239f44a44e6efb"}, - {file = "Pillow-9.2.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:510cef4a3f401c246cfd8227b300828715dd055463cdca6176c2e4036df8bd4f"}, - {file = "Pillow-9.2.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:7888310f6214f19ab2b6df90f3f06afa3df7ef7355fc025e78a3044737fab1f5"}, - {file = "Pillow-9.2.0-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:831e648102c82f152e14c1a0938689dbb22480c548c8d4b8b248b3e50967b88c"}, - {file = "Pillow-9.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:1cc1d2451e8a3b4bfdb9caf745b58e6c7a77d2e469159b0d527a4554d73694d1"}, - {file = "Pillow-9.2.0-cp310-cp310-manylinux_2_28_aarch64.whl", hash = "sha256:136659638f61a251e8ed3b331fc6ccd124590eeff539de57c5f80ef3a9594e58"}, - {file = "Pillow-9.2.0-cp310-cp310-manylinux_2_28_x86_64.whl", hash = "sha256:6e8c66f70fb539301e064f6478d7453e820d8a2c631da948a23384865cd95544"}, - {file = "Pillow-9.2.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:37ff6b522a26d0538b753f0b4e8e164fdada12db6c6f00f62145d732d8a3152e"}, - {file = "Pillow-9.2.0-cp310-cp310-win32.whl", hash = "sha256:c79698d4cd9318d9481d89a77e2d3fcaeff5486be641e60a4b49f3d2ecca4e28"}, - {file = "Pillow-9.2.0-cp310-cp310-win_amd64.whl", hash = "sha256:254164c57bab4b459f14c64e93df11eff5ded575192c294a0c49270f22c5d93d"}, - {file = "Pillow-9.2.0-cp311-cp311-macosx_10_10_x86_64.whl", hash = "sha256:adabc0bce035467fb537ef3e5e74f2847c8af217ee0be0455d4fec8adc0462fc"}, - {file = "Pillow-9.2.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:336b9036127eab855beec9662ac3ea13a4544a523ae273cbf108b228ecac8437"}, - {file = "Pillow-9.2.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:50dff9cc21826d2977ef2d2a205504034e3a4563ca6f5db739b0d1026658e004"}, - {file = "Pillow-9.2.0-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:cb6259196a589123d755380b65127ddc60f4c64b21fc3bb46ce3a6ea663659b0"}, - {file = "Pillow-9.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7b0554af24df2bf96618dac71ddada02420f946be943b181108cac55a7a2dcd4"}, - {file = "Pillow-9.2.0-cp311-cp311-manylinux_2_28_aarch64.whl", hash = "sha256:15928f824870535c85dbf949c09d6ae7d3d6ac2d6efec80f3227f73eefba741c"}, - {file = "Pillow-9.2.0-cp311-cp311-manylinux_2_28_x86_64.whl", hash = "sha256:bdd0de2d64688ecae88dd8935012c4a72681e5df632af903a1dca8c5e7aa871a"}, - {file = "Pillow-9.2.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:d5b87da55a08acb586bad5c3aa3b86505f559b84f39035b233d5bf844b0834b1"}, - {file = "Pillow-9.2.0-cp311-cp311-win32.whl", hash = "sha256:b6d5e92df2b77665e07ddb2e4dbd6d644b78e4c0d2e9272a852627cdba0d75cf"}, - {file = "Pillow-9.2.0-cp311-cp311-win_amd64.whl", hash = "sha256:6bf088c1ce160f50ea40764f825ec9b72ed9da25346216b91361eef8ad1b8f8c"}, - {file = "Pillow-9.2.0-cp37-cp37m-macosx_10_10_x86_64.whl", hash = "sha256:2c58b24e3a63efd22554c676d81b0e57f80e0a7d3a5874a7e14ce90ec40d3069"}, - {file = "Pillow-9.2.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:eef7592281f7c174d3d6cbfbb7ee5984a671fcd77e3fc78e973d492e9bf0eb3f"}, - {file = "Pillow-9.2.0-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:dcd7b9c7139dc8258d164b55696ecd16c04607f1cc33ba7af86613881ffe4ac8"}, - {file = "Pillow-9.2.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a138441e95562b3c078746a22f8fca8ff1c22c014f856278bdbdd89ca36cff1b"}, - {file = "Pillow-9.2.0-cp37-cp37m-manylinux_2_28_aarch64.whl", hash = "sha256:93689632949aff41199090eff5474f3990b6823404e45d66a5d44304e9cdc467"}, - {file = "Pillow-9.2.0-cp37-cp37m-manylinux_2_28_x86_64.whl", hash = "sha256:f3fac744f9b540148fa7715a435d2283b71f68bfb6d4aae24482a890aed18b59"}, - {file = "Pillow-9.2.0-cp37-cp37m-win32.whl", hash = "sha256:fa768eff5f9f958270b081bb33581b4b569faabf8774726b283edb06617101dc"}, - {file = "Pillow-9.2.0-cp37-cp37m-win_amd64.whl", hash = "sha256:69bd1a15d7ba3694631e00df8de65a8cb031911ca11f44929c97fe05eb9b6c1d"}, - {file = "Pillow-9.2.0-cp38-cp38-macosx_10_10_x86_64.whl", hash = "sha256:030e3460861488e249731c3e7ab59b07c7853838ff3b8e16aac9561bb345da14"}, - {file = "Pillow-9.2.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:74a04183e6e64930b667d321524e3c5361094bb4af9083db5c301db64cd341f3"}, - {file = "Pillow-9.2.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:2d33a11f601213dcd5718109c09a52c2a1c893e7461f0be2d6febc2879ec2402"}, - {file = "Pillow-9.2.0-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:1fd6f5e3c0e4697fa7eb45b6e93996299f3feee73a3175fa451f49a74d092b9f"}, - {file = "Pillow-9.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a647c0d4478b995c5e54615a2e5360ccedd2f85e70ab57fbe817ca613d5e63b8"}, - {file = "Pillow-9.2.0-cp38-cp38-manylinux_2_28_aarch64.whl", hash = "sha256:4134d3f1ba5f15027ff5c04296f13328fecd46921424084516bdb1b2548e66ff"}, - {file = "Pillow-9.2.0-cp38-cp38-manylinux_2_28_x86_64.whl", hash = "sha256:bc431b065722a5ad1dfb4df354fb9333b7a582a5ee39a90e6ffff688d72f27a1"}, - {file = "Pillow-9.2.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:1536ad017a9f789430fb6b8be8bf99d2f214c76502becc196c6f2d9a75b01b76"}, - {file = "Pillow-9.2.0-cp38-cp38-win32.whl", hash = "sha256:2ad0d4df0f5ef2247e27fc790d5c9b5a0af8ade9ba340db4a73bb1a4a3e5fb4f"}, - {file = "Pillow-9.2.0-cp38-cp38-win_amd64.whl", hash = "sha256:ec52c351b35ca269cb1f8069d610fc45c5bd38c3e91f9ab4cbbf0aebc136d9c8"}, - {file = "Pillow-9.2.0-cp39-cp39-macosx_10_10_x86_64.whl", hash = "sha256:0ed2c4ef2451de908c90436d6e8092e13a43992f1860275b4d8082667fbb2ffc"}, - {file = "Pillow-9.2.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:4ad2f835e0ad81d1689f1b7e3fbac7b01bb8777d5a985c8962bedee0cc6d43da"}, - {file = "Pillow-9.2.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ea98f633d45f7e815db648fd7ff0f19e328302ac36427343e4432c84432e7ff4"}, - {file = "Pillow-9.2.0-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:7761afe0126d046974a01e030ae7529ed0ca6a196de3ec6937c11df0df1bc91c"}, - {file = "Pillow-9.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9a54614049a18a2d6fe156e68e188da02a046a4a93cf24f373bffd977e943421"}, - {file = "Pillow-9.2.0-cp39-cp39-manylinux_2_28_aarch64.whl", hash = "sha256:5aed7dde98403cd91d86a1115c78d8145c83078e864c1de1064f52e6feb61b20"}, - {file = "Pillow-9.2.0-cp39-cp39-manylinux_2_28_x86_64.whl", hash = "sha256:13b725463f32df1bfeacbf3dd197fb358ae8ebcd8c5548faa75126ea425ccb60"}, - {file = "Pillow-9.2.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:808add66ea764ed97d44dda1ac4f2cfec4c1867d9efb16a33d158be79f32b8a4"}, - {file = "Pillow-9.2.0-cp39-cp39-win32.whl", hash = "sha256:337a74fd2f291c607d220c793a8135273c4c2ab001b03e601c36766005f36885"}, - {file = "Pillow-9.2.0-cp39-cp39-win_amd64.whl", hash = "sha256:fac2d65901fb0fdf20363fbd345c01958a742f2dc62a8dd4495af66e3ff502a4"}, - {file = "Pillow-9.2.0-pp37-pypy37_pp73-macosx_10_10_x86_64.whl", hash = "sha256:ad2277b185ebce47a63f4dc6302e30f05762b688f8dc3de55dbae4651872cdf3"}, - {file = "Pillow-9.2.0-pp37-pypy37_pp73-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:7c7b502bc34f6e32ba022b4a209638f9e097d7a9098104ae420eb8186217ebbb"}, - {file = "Pillow-9.2.0-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3d1f14f5f691f55e1b47f824ca4fdcb4b19b4323fe43cc7bb105988cad7496be"}, - {file = "Pillow-9.2.0-pp37-pypy37_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:dfe4c1fedfde4e2fbc009d5ad420647f7730d719786388b7de0999bf32c0d9fd"}, - {file = "Pillow-9.2.0-pp38-pypy38_pp73-macosx_10_10_x86_64.whl", hash = "sha256:f07f1f00e22b231dd3d9b9208692042e29792d6bd4f6639415d2f23158a80013"}, - {file = "Pillow-9.2.0-pp38-pypy38_pp73-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:1802f34298f5ba11d55e5bb09c31997dc0c6aed919658dfdf0198a2fe75d5490"}, - {file = "Pillow-9.2.0-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:17d4cafe22f050b46d983b71c707162d63d796a1235cdf8b9d7a112e97b15bac"}, - {file = "Pillow-9.2.0-pp38-pypy38_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:96b5e6874431df16aee0c1ba237574cb6dff1dcb173798faa6a9d8b399a05d0e"}, - {file = "Pillow-9.2.0-pp38-pypy38_pp73-win_amd64.whl", hash = "sha256:0030fdbd926fb85844b8b92e2f9449ba89607231d3dd597a21ae72dc7fe26927"}, - {file = "Pillow-9.2.0.tar.gz", hash = "sha256:75e636fd3e0fb872693f23ccb8a5ff2cd578801251f3a4f6854c6a5d437d3c04"}, + {file = "Pillow-9.4.0-1-cp310-cp310-macosx_10_10_x86_64.whl", hash = "sha256:1b4b4e9dda4f4e4c4e6896f93e84a8f0bcca3b059de9ddf67dac3c334b1195e1"}, + {file = "Pillow-9.4.0-1-cp311-cp311-macosx_10_10_x86_64.whl", hash = "sha256:fb5c1ad6bad98c57482236a21bf985ab0ef42bd51f7ad4e4538e89a997624e12"}, + {file = "Pillow-9.4.0-1-cp37-cp37m-macosx_10_10_x86_64.whl", hash = "sha256:f0caf4a5dcf610d96c3bd32932bfac8aee61c96e60481c2a0ea58da435e25acd"}, + {file = "Pillow-9.4.0-1-cp38-cp38-macosx_10_10_x86_64.whl", hash = "sha256:3f4cc516e0b264c8d4ccd6b6cbc69a07c6d582d8337df79be1e15a5056b258c9"}, + {file = "Pillow-9.4.0-1-cp39-cp39-macosx_10_10_x86_64.whl", hash = "sha256:b8c2f6eb0df979ee99433d8b3f6d193d9590f735cf12274c108bd954e30ca858"}, + {file = "Pillow-9.4.0-1-pp38-pypy38_pp73-macosx_10_10_x86_64.whl", hash = "sha256:b70756ec9417c34e097f987b4d8c510975216ad26ba6e57ccb53bc758f490dab"}, + {file = "Pillow-9.4.0-1-pp39-pypy39_pp73-macosx_10_10_x86_64.whl", hash = "sha256:43521ce2c4b865d385e78579a082b6ad1166ebed2b1a2293c3be1d68dd7ca3b9"}, + {file = "Pillow-9.4.0-2-cp310-cp310-macosx_10_10_x86_64.whl", hash = "sha256:9d9a62576b68cd90f7075876f4e8444487db5eeea0e4df3ba298ee38a8d067b0"}, + {file = "Pillow-9.4.0-2-cp311-cp311-macosx_10_10_x86_64.whl", hash = "sha256:87708d78a14d56a990fbf4f9cb350b7d89ee8988705e58e39bdf4d82c149210f"}, + {file = "Pillow-9.4.0-2-cp37-cp37m-macosx_10_10_x86_64.whl", hash = "sha256:8a2b5874d17e72dfb80d917213abd55d7e1ed2479f38f001f264f7ce7bae757c"}, + {file = "Pillow-9.4.0-2-cp38-cp38-macosx_10_10_x86_64.whl", hash = "sha256:83125753a60cfc8c412de5896d10a0a405e0bd88d0470ad82e0869ddf0cb3848"}, + {file = "Pillow-9.4.0-2-cp39-cp39-macosx_10_10_x86_64.whl", hash = "sha256:9e5f94742033898bfe84c93c831a6f552bb629448d4072dd312306bab3bd96f1"}, + {file = "Pillow-9.4.0-2-pp38-pypy38_pp73-macosx_10_10_x86_64.whl", hash = "sha256:013016af6b3a12a2f40b704677f8b51f72cb007dac785a9933d5c86a72a7fe33"}, + {file = "Pillow-9.4.0-2-pp39-pypy39_pp73-macosx_10_10_x86_64.whl", hash = "sha256:99d92d148dd03fd19d16175b6d355cc1b01faf80dae93c6c3eb4163709edc0a9"}, + {file = "Pillow-9.4.0-cp310-cp310-macosx_10_10_x86_64.whl", hash = "sha256:2968c58feca624bb6c8502f9564dd187d0e1389964898f5e9e1fbc8533169157"}, + {file = "Pillow-9.4.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:c5c1362c14aee73f50143d74389b2c158707b4abce2cb055b7ad37ce60738d47"}, + {file = "Pillow-9.4.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:bd752c5ff1b4a870b7661234694f24b1d2b9076b8bf337321a814c612665f343"}, + {file = "Pillow-9.4.0-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:9a3049a10261d7f2b6514d35bbb7a4dfc3ece4c4de14ef5876c4b7a23a0e566d"}, + {file = "Pillow-9.4.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:16a8df99701f9095bea8a6c4b3197da105df6f74e6176c5b410bc2df2fd29a57"}, + {file = "Pillow-9.4.0-cp310-cp310-manylinux_2_28_aarch64.whl", hash = "sha256:94cdff45173b1919350601f82d61365e792895e3c3a3443cf99819e6fbf717a5"}, + {file = "Pillow-9.4.0-cp310-cp310-manylinux_2_28_x86_64.whl", hash = "sha256:ed3e4b4e1e6de75fdc16d3259098de7c6571b1a6cc863b1a49e7d3d53e036070"}, + {file = "Pillow-9.4.0-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:d5b2f8a31bd43e0f18172d8ac82347c8f37ef3e0b414431157718aa234991b28"}, + {file = "Pillow-9.4.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:09b89ddc95c248ee788328528e6a2996e09eaccddeeb82a5356e92645733be35"}, + {file = "Pillow-9.4.0-cp310-cp310-win32.whl", hash = "sha256:f09598b416ba39a8f489c124447b007fe865f786a89dbfa48bb5cf395693132a"}, + {file = "Pillow-9.4.0-cp310-cp310-win_amd64.whl", hash = "sha256:f6e78171be3fb7941f9910ea15b4b14ec27725865a73c15277bc39f5ca4f8391"}, + {file = "Pillow-9.4.0-cp311-cp311-macosx_10_10_x86_64.whl", hash = "sha256:3fa1284762aacca6dc97474ee9c16f83990b8eeb6697f2ba17140d54b453e133"}, + {file = "Pillow-9.4.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:eaef5d2de3c7e9b21f1e762f289d17b726c2239a42b11e25446abf82b26ac132"}, + {file = "Pillow-9.4.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a4dfdae195335abb4e89cc9762b2edc524f3c6e80d647a9a81bf81e17e3fb6f0"}, + {file = "Pillow-9.4.0-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:6abfb51a82e919e3933eb137e17c4ae9c0475a25508ea88993bb59faf82f3b35"}, + {file = "Pillow-9.4.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:451f10ef963918e65b8869e17d67db5e2f4ab40e716ee6ce7129b0cde2876eab"}, + {file = "Pillow-9.4.0-cp311-cp311-manylinux_2_28_aarch64.whl", hash = "sha256:6663977496d616b618b6cfa43ec86e479ee62b942e1da76a2c3daa1c75933ef4"}, + {file = "Pillow-9.4.0-cp311-cp311-manylinux_2_28_x86_64.whl", hash = "sha256:60e7da3a3ad1812c128750fc1bc14a7ceeb8d29f77e0a2356a8fb2aa8925287d"}, + {file = "Pillow-9.4.0-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:19005a8e58b7c1796bc0167862b1f54a64d3b44ee5d48152b06bb861458bc0f8"}, + {file = "Pillow-9.4.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:f715c32e774a60a337b2bb8ad9839b4abf75b267a0f18806f6f4f5f1688c4b5a"}, + {file = "Pillow-9.4.0-cp311-cp311-win32.whl", hash = "sha256:b222090c455d6d1a64e6b7bb5f4035c4dff479e22455c9eaa1bdd4c75b52c80c"}, + {file = "Pillow-9.4.0-cp311-cp311-win_amd64.whl", hash = "sha256:ba6612b6548220ff5e9df85261bddc811a057b0b465a1226b39bfb8550616aee"}, + {file = "Pillow-9.4.0-cp37-cp37m-macosx_10_10_x86_64.whl", hash = "sha256:5f532a2ad4d174eb73494e7397988e22bf427f91acc8e6ebf5bb10597b49c493"}, + {file = "Pillow-9.4.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5dd5a9c3091a0f414a963d427f920368e2b6a4c2f7527fdd82cde8ef0bc7a327"}, + {file = "Pillow-9.4.0-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:ef21af928e807f10bf4141cad4746eee692a0dd3ff56cfb25fce076ec3cc8abe"}, + {file = "Pillow-9.4.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:847b114580c5cc9ebaf216dd8c8dbc6b00a3b7ab0131e173d7120e6deade1f57"}, + {file = "Pillow-9.4.0-cp37-cp37m-manylinux_2_28_aarch64.whl", hash = "sha256:653d7fb2df65efefbcbf81ef5fe5e5be931f1ee4332c2893ca638c9b11a409c4"}, + {file = "Pillow-9.4.0-cp37-cp37m-manylinux_2_28_x86_64.whl", hash = "sha256:46f39cab8bbf4a384ba7cb0bc8bae7b7062b6a11cfac1ca4bc144dea90d4a9f5"}, + {file = "Pillow-9.4.0-cp37-cp37m-win32.whl", hash = "sha256:7ac7594397698f77bce84382929747130765f66406dc2cd8b4ab4da68ade4c6e"}, + {file = "Pillow-9.4.0-cp37-cp37m-win_amd64.whl", hash = "sha256:46c259e87199041583658457372a183636ae8cd56dbf3f0755e0f376a7f9d0e6"}, + {file = "Pillow-9.4.0-cp38-cp38-macosx_10_10_x86_64.whl", hash = "sha256:0e51f608da093e5d9038c592b5b575cadc12fd748af1479b5e858045fff955a9"}, + {file = "Pillow-9.4.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:765cb54c0b8724a7c12c55146ae4647e0274a839fb6de7bcba841e04298e1011"}, + {file = "Pillow-9.4.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:519e14e2c49fcf7616d6d2cfc5c70adae95682ae20f0395e9280db85e8d6c4df"}, + {file = "Pillow-9.4.0-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:d197df5489004db87d90b918033edbeee0bd6df3848a204bca3ff0a903bef837"}, + {file = "Pillow-9.4.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0845adc64fe9886db00f5ab68c4a8cd933ab749a87747555cec1c95acea64b0b"}, + {file = "Pillow-9.4.0-cp38-cp38-manylinux_2_28_aarch64.whl", hash = "sha256:e1339790c083c5a4de48f688b4841f18df839eb3c9584a770cbd818b33e26d5d"}, + {file = "Pillow-9.4.0-cp38-cp38-manylinux_2_28_x86_64.whl", hash = "sha256:a96e6e23f2b79433390273eaf8cc94fec9c6370842e577ab10dabdcc7ea0a66b"}, + {file = "Pillow-9.4.0-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:7cfc287da09f9d2a7ec146ee4d72d6ea1342e770d975e49a8621bf54eaa8f30f"}, + {file = "Pillow-9.4.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:d7081c084ceb58278dd3cf81f836bc818978c0ccc770cbbb202125ddabec6628"}, + {file = "Pillow-9.4.0-cp38-cp38-win32.whl", hash = "sha256:df41112ccce5d47770a0c13651479fbcd8793f34232a2dd9faeccb75eb5d0d0d"}, + {file = "Pillow-9.4.0-cp38-cp38-win_amd64.whl", hash = "sha256:7a21222644ab69ddd9967cfe6f2bb420b460dae4289c9d40ff9a4896e7c35c9a"}, + {file = "Pillow-9.4.0-cp39-cp39-macosx_10_10_x86_64.whl", hash = "sha256:0f3269304c1a7ce82f1759c12ce731ef9b6e95b6df829dccd9fe42912cc48569"}, + {file = "Pillow-9.4.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:cb362e3b0976dc994857391b776ddaa8c13c28a16f80ac6522c23d5257156bed"}, + {file = "Pillow-9.4.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a2e0f87144fcbbe54297cae708c5e7f9da21a4646523456b00cc956bd4c65815"}, + {file = "Pillow-9.4.0-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:28676836c7796805914b76b1837a40f76827ee0d5398f72f7dcc634bae7c6264"}, + {file = "Pillow-9.4.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0884ba7b515163a1a05440a138adeb722b8a6ae2c2b33aea93ea3118dd3a899e"}, + {file = "Pillow-9.4.0-cp39-cp39-manylinux_2_28_aarch64.whl", hash = "sha256:53dcb50fbdc3fb2c55431a9b30caeb2f7027fcd2aeb501459464f0214200a503"}, + {file = "Pillow-9.4.0-cp39-cp39-manylinux_2_28_x86_64.whl", hash = "sha256:e8c5cf126889a4de385c02a2c3d3aba4b00f70234bfddae82a5eaa3ee6d5e3e6"}, + {file = "Pillow-9.4.0-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:6c6b1389ed66cdd174d040105123a5a1bc91d0aa7059c7261d20e583b6d8cbd2"}, + {file = "Pillow-9.4.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:0dd4c681b82214b36273c18ca7ee87065a50e013112eea7d78c7a1b89a739153"}, + {file = "Pillow-9.4.0-cp39-cp39-win32.whl", hash = "sha256:6d9dfb9959a3b0039ee06c1a1a90dc23bac3b430842dcb97908ddde05870601c"}, + {file = "Pillow-9.4.0-cp39-cp39-win_amd64.whl", hash = "sha256:54614444887e0d3043557d9dbc697dbb16cfb5a35d672b7a0fcc1ed0cf1c600b"}, + {file = "Pillow-9.4.0-pp38-pypy38_pp73-macosx_10_10_x86_64.whl", hash = "sha256:b9b752ab91e78234941e44abdecc07f1f0d8f51fb62941d32995b8161f68cfe5"}, + {file = "Pillow-9.4.0-pp38-pypy38_pp73-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:d3b56206244dc8711f7e8b7d6cad4663917cd5b2d950799425076681e8766286"}, + {file = "Pillow-9.4.0-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:aabdab8ec1e7ca7f1434d042bf8b1e92056245fb179790dc97ed040361f16bfd"}, + {file = "Pillow-9.4.0-pp38-pypy38_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:db74f5562c09953b2c5f8ec4b7dfd3f5421f31811e97d1dbc0a7c93d6e3a24df"}, + {file = "Pillow-9.4.0-pp38-pypy38_pp73-win_amd64.whl", hash = "sha256:e9d7747847c53a16a729b6ee5e737cf170f7a16611c143d95aa60a109a59c336"}, + {file = "Pillow-9.4.0-pp39-pypy39_pp73-macosx_10_10_x86_64.whl", hash = "sha256:b52ff4f4e002f828ea6483faf4c4e8deea8d743cf801b74910243c58acc6eda3"}, + {file = "Pillow-9.4.0-pp39-pypy39_pp73-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:575d8912dca808edd9acd6f7795199332696d3469665ef26163cd090fa1f8bfa"}, + {file = "Pillow-9.4.0-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c3c4ed2ff6760e98d262e0cc9c9a7f7b8a9f61aa4d47c58835cdaf7b0b8811bb"}, + {file = "Pillow-9.4.0-pp39-pypy39_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:e621b0246192d3b9cb1dc62c78cfa4c6f6d2ddc0ec207d43c0dedecb914f152a"}, + {file = "Pillow-9.4.0-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:8f127e7b028900421cad64f51f75c051b628db17fb00e099eb148761eed598c9"}, + {file = "Pillow-9.4.0.tar.gz", hash = "sha256:a1c2d7780448eb93fbcc3789bf3916aa5720d942e37945f4056680317f1cd23e"}, ] platformdirs = [ {file = "platformdirs-3.0.0-py3-none-any.whl", hash = "sha256:b1d5eb14f221506f50d6604a561f4c5786d9e80355219694a1b244bcd96f4567"}, @@ -1176,27 +1192,46 @@ pytest = [ {file = "pytest-6.2.5.tar.gz", hash = "sha256:131b36680866a76e6781d13f101efb86cf674ebb9762eb70d3082b6f29889e89"}, ] PyYAML = [ - {file = "PyYAML-5.4-cp27-cp27m-macosx_10_9_x86_64.whl", hash = "sha256:f7a21e3d99aa3095ef0553e7ceba36fb693998fbb1226f1392ce33681047465f"}, - {file = "PyYAML-5.4-cp27-cp27m-win32.whl", hash = "sha256:52bf0930903818e600ae6c2901f748bc4869c0c406056f679ab9614e5d21a166"}, - {file = "PyYAML-5.4-cp27-cp27m-win_amd64.whl", hash = "sha256:a36a48a51e5471513a5aea920cdad84cbd56d70a5057cca3499a637496ea379c"}, - {file = "PyYAML-5.4-cp27-cp27mu-manylinux1_x86_64.whl", hash = "sha256:5e7ac4e0e79a53451dc2814f6876c2fa6f71452de1498bbe29c0b54b69a986f4"}, - {file = "PyYAML-5.4-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:cc552b6434b90d9dbed6a4f13339625dc466fd82597119897e9489c953acbc22"}, - {file = "PyYAML-5.4-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:0dc9f2eb2e3c97640928dec63fd8dc1dd91e6b6ed236bd5ac00332b99b5c2ff9"}, - {file = "PyYAML-5.4-cp36-cp36m-win32.whl", hash = "sha256:5a3f345acff76cad4aa9cb171ee76c590f37394186325d53d1aa25318b0d4a09"}, - {file = "PyYAML-5.4-cp36-cp36m-win_amd64.whl", hash = "sha256:f3790156c606299ff499ec44db422f66f05a7363b39eb9d5b064f17bd7d7c47b"}, - {file = "PyYAML-5.4-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:124fd7c7bc1e95b1eafc60825f2daf67c73ce7b33f1194731240d24b0d1bf628"}, - {file = "PyYAML-5.4-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:8b818b6c5a920cbe4203b5a6b14256f0e5244338244560da89b7b0f1313ea4b6"}, - {file = "PyYAML-5.4-cp37-cp37m-win32.whl", hash = "sha256:737bd70e454a284d456aa1fa71a0b429dd527bcbf52c5c33f7c8eee81ac16b89"}, - {file = "PyYAML-5.4-cp37-cp37m-win_amd64.whl", hash = "sha256:7242790ab6c20316b8e7bb545be48d7ed36e26bbe279fd56f2c4a12510e60b4b"}, - {file = "PyYAML-5.4-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:cc547d3ead3754712223abb7b403f0a184e4c3eae18c9bb7fd15adef1597cc4b"}, - {file = "PyYAML-5.4-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:8635d53223b1f561b081ff4adecb828fd484b8efffe542edcfdff471997f7c39"}, - {file = "PyYAML-5.4-cp38-cp38-win32.whl", hash = "sha256:26fcb33776857f4072601502d93e1a619f166c9c00befb52826e7b774efaa9db"}, - {file = "PyYAML-5.4-cp38-cp38-win_amd64.whl", hash = "sha256:b2243dd033fd02c01212ad5c601dafb44fbb293065f430b0d3dbf03f3254d615"}, - {file = "PyYAML-5.4-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:31ba07c54ef4a897758563e3a0fcc60077698df10180abe4b8165d9895c00ebf"}, - {file = "PyYAML-5.4-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:02c78d77281d8f8d07a255e57abdbf43b02257f59f50cc6b636937d68efa5dd0"}, - {file = "PyYAML-5.4-cp39-cp39-win32.whl", hash = "sha256:fdc6b2cb4b19e431994f25a9160695cc59a4e861710cc6fc97161c5e845fc579"}, - {file = "PyYAML-5.4-cp39-cp39-win_amd64.whl", hash = "sha256:8bf38641b4713d77da19e91f8b5296b832e4db87338d6aeffe422d42f1ca896d"}, - {file = "PyYAML-5.4.tar.gz", hash = "sha256:3c49e39ac034fd64fd576d63bb4db53cda89b362768a67f07749d55f128ac18a"}, + {file = "PyYAML-6.0.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:d858aa552c999bc8a8d57426ed01e40bef403cd8ccdd0fc5f6f04a00414cac2a"}, + {file = "PyYAML-6.0.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:fd66fc5d0da6d9815ba2cebeb4205f95818ff4b79c3ebe268e75d961704af52f"}, + {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:69b023b2b4daa7548bcfbd4aa3da05b3a74b772db9e23b982788168117739938"}, + {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:81e0b275a9ecc9c0c0c07b4b90ba548307583c125f54d5b6946cfee6360c733d"}, + {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ba336e390cd8e4d1739f42dfe9bb83a3cc2e80f567d8805e11b46f4a943f5515"}, + {file = "PyYAML-6.0.1-cp310-cp310-win32.whl", hash = "sha256:bd4af7373a854424dabd882decdc5579653d7868b8fb26dc7d0e99f823aa5924"}, + {file = "PyYAML-6.0.1-cp310-cp310-win_amd64.whl", hash = "sha256:fd1592b3fdf65fff2ad0004b5e363300ef59ced41c2e6b3a99d4089fa8c5435d"}, + {file = "PyYAML-6.0.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:6965a7bc3cf88e5a1c3bd2e0b5c22f8d677dc88a455344035f03399034eb3007"}, + {file = "PyYAML-6.0.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:f003ed9ad21d6a4713f0a9b5a7a0a79e08dd0f221aff4525a2be4c346ee60aab"}, + {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:42f8152b8dbc4fe7d96729ec2b99c7097d656dc1213a3229ca5383f973a5ed6d"}, + {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:062582fca9fabdd2c8b54a3ef1c978d786e0f6b3a1510e0ac93ef59e0ddae2bc"}, + {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d2b04aac4d386b172d5b9692e2d2da8de7bfb6c387fa4f801fbf6fb2e6ba4673"}, + {file = "PyYAML-6.0.1-cp311-cp311-win32.whl", hash = "sha256:1635fd110e8d85d55237ab316b5b011de701ea0f29d07611174a1b42f1444741"}, + {file = "PyYAML-6.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34"}, + {file = "PyYAML-6.0.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:50550eb667afee136e9a77d6dc71ae76a44df8b3e51e41b77f6de2932bfe0f47"}, + {file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1fe35611261b29bd1de0070f0b2f47cb6ff71fa6595c077e42bd0c419fa27b98"}, + {file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:704219a11b772aea0d8ecd7058d0082713c3562b4e271b849ad7dc4a5c90c13c"}, + {file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:afd7e57eddb1a54f0f1a974bc4391af8bcce0b444685d936840f125cf046d5bd"}, + {file = "PyYAML-6.0.1-cp36-cp36m-win32.whl", hash = "sha256:fca0e3a251908a499833aa292323f32437106001d436eca0e6e7833256674585"}, + {file = "PyYAML-6.0.1-cp36-cp36m-win_amd64.whl", hash = "sha256:f22ac1c3cac4dbc50079e965eba2c1058622631e526bd9afd45fedd49ba781fa"}, + {file = "PyYAML-6.0.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:b1275ad35a5d18c62a7220633c913e1b42d44b46ee12554e5fd39c70a243d6a3"}, + {file = "PyYAML-6.0.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:18aeb1bf9a78867dc38b259769503436b7c72f7a1f1f4c93ff9a17de54319b27"}, + {file = "PyYAML-6.0.1-cp37-cp37m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:596106435fa6ad000c2991a98fa58eeb8656ef2325d7e158344fb33864ed87e3"}, + {file = "PyYAML-6.0.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:baa90d3f661d43131ca170712d903e6295d1f7a0f595074f151c0aed377c9b9c"}, + {file = "PyYAML-6.0.1-cp37-cp37m-win32.whl", hash = "sha256:9046c58c4395dff28dd494285c82ba00b546adfc7ef001486fbf0324bc174fba"}, + {file = "PyYAML-6.0.1-cp37-cp37m-win_amd64.whl", hash = "sha256:4fb147e7a67ef577a588a0e2c17b6db51dda102c71de36f8549b6816a96e1867"}, + {file = "PyYAML-6.0.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:1d4c7e777c441b20e32f52bd377e0c409713e8bb1386e1099c2415f26e479595"}, + {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a0cd17c15d3bb3fa06978b4e8958dcdc6e0174ccea823003a106c7d4d7899ac5"}, + {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:28c119d996beec18c05208a8bd78cbe4007878c6dd15091efb73a30e90539696"}, + {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7e07cbde391ba96ab58e532ff4803f79c4129397514e1413a7dc761ccd755735"}, + {file = "PyYAML-6.0.1-cp38-cp38-win32.whl", hash = "sha256:184c5108a2aca3c5b3d3bf9395d50893a7ab82a38004c8f61c258d4428e80206"}, + {file = "PyYAML-6.0.1-cp38-cp38-win_amd64.whl", hash = "sha256:1e2722cc9fbb45d9b87631ac70924c11d3a401b2d7f410cc0e3bbf249f2dca62"}, + {file = "PyYAML-6.0.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:9eb6caa9a297fc2c2fb8862bc5370d0303ddba53ba97e71f08023b6cd73d16a8"}, + {file = "PyYAML-6.0.1-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:c8098ddcc2a85b61647b2590f825f3db38891662cfc2fc776415143f599bb859"}, + {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5773183b6446b2c99bb77e77595dd486303b4faab2b086e7b17bc6bef28865f6"}, + {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:b786eecbdf8499b9ca1d697215862083bd6d2a99965554781d0d8d1ad31e13a0"}, + {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bc1bf2925a1ecd43da378f4db9e4f799775d6367bdb94671027b73b393a7c42c"}, + {file = "PyYAML-6.0.1-cp39-cp39-win32.whl", hash = "sha256:faca3bdcf85b2fc05d06ff3fbc1f83e1391b3e724afa3feba7d13eeab355484c"}, + {file = "PyYAML-6.0.1-cp39-cp39-win_amd64.whl", hash = "sha256:510c9deebc5c0225e8c96813043e62b680ba2f9c50a08d3724c7f28a747d1486"}, + {file = "PyYAML-6.0.1.tar.gz", hash = "sha256:bfdf460b1736c775f2ba9f6a92bca30bc2095067b8a9d77876d1fad6cc3b4a43"}, ] setuptools = [ {file = "setuptools-67.4.0-py3-none-any.whl", hash = "sha256:f106dee1b506dee5102cc3f3e9e68137bbad6d47b616be7991714b0c62204251"}, diff --git a/daemon/proto/core/api/grpc/configservices.proto b/daemon/proto/core/api/grpc/configservices.proto index 28e00bcb..25be616d 100644 --- a/daemon/proto/core/api/grpc/configservices.proto +++ b/daemon/proto/core/api/grpc/configservices.proto @@ -41,6 +41,8 @@ message ConfigMode { message GetConfigServiceDefaultsRequest { string name = 1; + int32 session_id = 2; + int32 node_id = 3; } message GetConfigServiceDefaultsResponse { diff --git a/daemon/proto/core/api/grpc/core.proto b/daemon/proto/core/api/grpc/core.proto index d2f024da..09f2c764 100644 --- a/daemon/proto/core/api/grpc/core.proto +++ b/daemon/proto/core/api/grpc/core.proto @@ -545,6 +545,8 @@ message NodeType { CONTROL_NET = 13; DOCKER = 15; LXC = 16; + WIRELESS = 17; + PODMAN = 18; } } diff --git a/daemon/pyproject.toml b/daemon/pyproject.toml index 48a3590b..0d1acf7a 100644 --- a/daemon/pyproject.toml +++ b/daemon/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "core" -version = "9.0.2" +version = "9.0.3" description = "CORE Common Open Research Emulator" authors = ["Boeing Research and Technology"] license = "BSD-2-Clause" @@ -26,19 +26,19 @@ core-cleanup = "core.scripts.cleanup:main" [tool.poetry.dependencies] python = "^3.9" fabric = "2.7.1" -grpcio = "1.49.1" +grpcio = "1.54.2" invoke = "1.7.3" lxml = "4.9.1" netaddr = "0.7.19" protobuf = "4.21.9" pyproj = "3.3.1" -pyyaml = "5.4" -Pillow = "9.2.0" +Pillow = "9.4.0" Mako = "1.2.3" +PyYAML = "6.0.1" [tool.poetry.group.dev.dependencies] pytest = "6.2.5" -grpcio-tools = "1.49.1" +grpcio-tools = "1.54.2" black = "22.12.0" flake8 = "3.8.2" isort = "4.3.21" diff --git a/dockerfiles/Dockerfile.centos b/dockerfiles/Dockerfile.centos index c8e8982b..06654486 100644 --- a/dockerfiles/Dockerfile.centos +++ b/dockerfiles/Dockerfile.centos @@ -13,6 +13,7 @@ WORKDIR /opt # install system dependencies RUN yum -y update && \ yum install -y \ + xterm \ git \ sudo \ wget \ @@ -27,7 +28,8 @@ RUN yum -y update && \ tcpdump \ make && \ yum-builddep -y python3 && \ - yum autoremove -y + yum autoremove -y && \ + yum install -y hostname # install python3.9 RUN wget https://www.python.org/ftp/python/3.9.15/Python-3.9.15.tgz && \ @@ -43,8 +45,8 @@ RUN wget https://www.python.org/ftp/python/3.9.15/Python-3.9.15.tgz && \ RUN git clone https://github.com/coreemu/core && \ cd core && \ git checkout ${BRANCH} && \ - PYTHON=/usr/local/bin/python3.9 ./setup.sh && \ - . /root/.bashrc && PYTHON=/usr/local/bin/python3.9 inv install -v -p ${PREFIX} --no-python + NO_SYSTEM=1 PYTHON=/usr/local/bin/python3.9 ./setup.sh && \ + PATH=/root/.local/bin:$PATH PYTHON=/usr/local/bin/python3.9 inv install -v -p ${PREFIX} --no-python # install emane RUN wget -q https://adjacentlink.com/downloads/emane/emane-1.3.3-release-1.el7.x86_64.tar.gz && \ diff --git a/dockerfiles/Dockerfile.centos-package b/dockerfiles/Dockerfile.centos-package index 5c2366ed..8d4a1296 100644 --- a/dockerfiles/Dockerfile.centos-package +++ b/dockerfiles/Dockerfile.centos-package @@ -11,6 +11,7 @@ WORKDIR /opt # install basic dependencies RUN yum -y update && \ yum install -y \ + xterm \ git \ sudo \ wget \ @@ -30,7 +31,8 @@ RUN yum -y update && \ pkg-config \ make && \ yum-builddep -y python3 && \ - yum autoremove -y + yum autoremove -y && \ + yum install -y hostname # install python3.9 RUN wget https://www.python.org/ftp/python/3.9.15/Python-3.9.15.tgz && \ diff --git a/dockerfiles/Dockerfile.ubuntu b/dockerfiles/Dockerfile.ubuntu index 9762fd05..8eceebf7 100644 --- a/dockerfiles/Dockerfile.ubuntu +++ b/dockerfiles/Dockerfile.ubuntu @@ -35,8 +35,7 @@ RUN git clone https://github.com/coreemu/core && \ cd core && \ git checkout ${BRANCH} && \ ./setup.sh && \ - . /root/.bashrc && \ - inv install -v -p ${PREFIX} && \ + PATH=/root/.local/bin:$PATH inv install -v -p ${PREFIX} && \ cd /opt && \ rm -rf ospf-mdr diff --git a/docs/architecture.md b/docs/architecture.md index 410b37ac..b9c5c91c 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -1,25 +1,22 @@ # CORE Architecture -* Table of Contents -{:toc} - ## Main Components * core-daemon - * Manages emulated sessions of nodes and links for a given network - * Nodes are created using Linux namespaces - * Links are created using Linux bridges and virtual ethernet peers - * Packets sent over links are manipulated using traffic control - * Provides gRPC API + * Manages emulated sessions of nodes and links for a given network + * Nodes are created using Linux namespaces + * Links are created using Linux bridges and virtual ethernet peers + * Packets sent over links are manipulated using traffic control + * Provides gRPC API * core-gui - * GUI and daemon communicate over gRPC API - * Drag and drop creation for nodes and links - * Can launch terminals for emulated nodes in running sessions - * Can save/open scenario files to recreate previous sessions + * GUI and daemon communicate over gRPC API + * Drag and drop creation for nodes and links + * Can launch terminals for emulated nodes in running sessions + * Can save/open scenario files to recreate previous sessions * vnoded - * Command line utility for creating CORE node namespaces + * Command line utility for creating CORE node namespaces * vcmd - * Command line utility for sending shell commands to nodes + * Command line utility for sending shell commands to nodes ![](static/architecture.png) @@ -57,5 +54,5 @@ rules. CORE has been released by Boeing to the open source community under the BSD license. If you find CORE useful for your work, please contribute back to the project. Contributions can be as simple as reporting a bug, dropping a line of -encouragement, or can also include submitting patches or maintaining aspects +encouragement, or can also include submitting patches or maintaining aspects of the tool. diff --git a/docs/configservices.md b/docs/configservices.md index f0fa7bdd..da81aa48 100644 --- a/docs/configservices.md +++ b/docs/configservices.md @@ -1,7 +1,4 @@ -# CORE Config Services - -* Table of Contents -{:toc} +# Config Services ## Overview @@ -15,6 +12,7 @@ CORE services are a convenience for creating reusable dynamic scripts to run on nodes, for carrying out specific task(s). This boilds down to the following functions: + * generating files the service will use, either directly for commands or for configuration * command(s) for starting a service * command(s) for validating a service @@ -81,30 +79,28 @@ introduced to automate tasks. ### Creating New Services +!!! note + + The directory base name used in **custom_services_dir** below should + be unique and should not correspond to any existing Python module name. + For example, don't use the name **subprocess** or **services**. + 1. Modify the example service shown below to do what you want. It could generate config/script files, mount per-node directories, start processes/scripts, etc. Your file can define one or more classes to be imported. You can create multiple Python files that will be imported. -2. Put these files in a directory such as ~/.coregui/custom_services - Note that the last component of this directory name **myservices** should not - be named something like **services** which conflicts with an existing module. +2. Put these files in a directory such as **~/.coregui/custom_services**. 3. Add a **custom_config_services_dir = ~/.coregui/custom_services** entry to the /etc/core/core.conf file. - **NOTE:** - The directory name used in **custom_services_dir** should be unique and - should not correspond to - any existing Python module name. For example, don't use the name **subprocess** - or **services**. - 4. Restart the CORE daemon (core-daemon). Any import errors (Python syntax) should be displayed in the terminal (or service log, like journalctl). 5. Start using your custom service on your nodes. You can create a new node type that uses your service, or change the default services for an existing - node type, or change individual nodes. . + node type, or change individual nodes. ### Example Custom Service @@ -121,6 +117,7 @@ from typing import Dict, List from core.config import ConfigString, ConfigBool, Configuration from core.configservice.base import ConfigService, ConfigServiceMode, ShadowDir + # class that subclasses ConfigService class ExampleService(ConfigService): # unique name for your service within CORE @@ -129,7 +126,7 @@ class ExampleService(ConfigService): group: str = "ExampleGroup" # directories that the service should shadow mount, hiding the system directory directories: List[str] = [ - "/usr/local/core", + "/usr/local/core", ] # files that this service should generate, defaults to nodes home directory # or can provide an absolute path to a mounted directory diff --git a/docs/ctrlnet.md b/docs/ctrlnet.md index 9ecc2e3f..d20e3a41 100644 --- a/docs/ctrlnet.md +++ b/docs/ctrlnet.md @@ -1,13 +1,10 @@ # CORE Control Network -* Table of Contents -{:toc} - ## Overview The CORE control network allows the virtual nodes to communicate with their host environment. There are two types: the primary control network and -auxiliary control networks. The primary control network is used mainly for +auxiliary control networks. The primary control network is used mainly for communicating with the virtual nodes from host machines and for master-slave communications in a multi-server distributed environment. Auxiliary control networks have been introduced to for routing namespace hosted emulation @@ -30,15 +27,19 @@ new sessions will use by default. To simultaneously run multiple sessions with control networks, the session option should be used instead of the *core.conf* default. -> **NOTE:** If you have a large scenario with more than 253 nodes, use a control -network prefix that allows more than the suggested */24*, such as */23* or -greater. +!!! note -> **NOTE:** Running a session with a control network can fail if a previous -session has set up a control network and the its bridge is still up. Close -the previous session first or wait for it to complete. If unable to, the -*core-daemon* may need to be restarted and the lingering bridge(s) removed -manually. + If you have a large scenario with more than 253 nodes, use a control + network prefix that allows more than the suggested */24*, such as */23* or + greater. + +!!! note + + Running a session with a control network can fail if a previous + session has set up a control network and the its bridge is still up. Close + the previous session first or wait for it to complete. If unable to, the + **core-daemon** may need to be restarted and the lingering bridge(s) removed + manually. ```shell # Restart the CORE Daemon @@ -52,11 +53,13 @@ for cb in $ctrlbridges; do done ``` -> **NOTE:** If adjustments to the primary control network configuration made in -*/etc/core/core.conf* do not seem to take affect, check if there is anything -set in the *Session Menu*, the *Options...* dialog. They may need to be -cleared. These per session settings override the defaults in -*/etc/core/core.conf*. +!!! note + + If adjustments to the primary control network configuration made in + **/etc/core/core.conf** do not seem to take affect, check if there is anything + set in the *Session Menu*, the *Options...* dialog. They may need to be + cleared. These per session settings override the defaults in + **/etc/core/core.conf**. ## Control Network in Distributed Sessions @@ -102,9 +105,9 @@ argument being the keyword *"shutdown"*. Starting with EMANE 0.9.2, CORE will run EMANE instances within namespaces. Since it is advisable to separate the OTA traffic from other traffic, we will need more than single channel leading out from the namespace. Up to three -auxiliary control networks may be defined. Multiple control networks are set -up in */etc/core/core.conf* file. Lines *controlnet1*, *controlnet2* and -*controlnet3* define the auxiliary networks. +auxiliary control networks may be defined. Multiple control networks are set +up in */etc/core/core.conf* file. Lines *controlnet1*, *controlnet2* and +*controlnet3* define the auxiliary networks. For example, having the following */etc/core/core.conf*: @@ -114,18 +117,20 @@ controlnet1 = core1:172.18.1.0/24 core2:172.18.2.0/24 core3:172.18.3.0/24 controlnet2 = core1:172.19.1.0/24 core2:172.19.2.0/24 core3:172.19.3.0/24 ``` -This will activate the primary and two auxiliary control networks and add +This will activate the primary and two auxiliary control networks and add interfaces *ctrl0*, *ctrl1*, *ctrl2* to each node. One use case would be to assign *ctrl1* to the OTA manager device and *ctrl2* to the Event Service device in the EMANE Options dialog box and leave *ctrl0* for CORE control traffic. -> **NOTE:** *controlnet0* may be used in place of *controlnet* to configure ->the primary control network. +!!! note + + *controlnet0* may be used in place of *controlnet* to configure + the primary control network. Unlike the primary control network, the auxiliary control networks will not -employ tunneling since their primary purpose is for efficiently transporting -multicast EMANE OTA and event traffic. Note that there is no per-session +employ tunneling since their primary purpose is for efficiently transporting +multicast EMANE OTA and event traffic. Note that there is no per-session configuration for auxiliary control networks. To extend the auxiliary control networks across a distributed test @@ -139,9 +144,11 @@ controlnetif2 = eth2 controlnetif3 = eth3 ``` -> **NOTE:** There is no need to assign an interface to the primary control ->network because tunnels are formed between the master and the slaves using IP ->addresses that are provided in *servers.conf*. +!!! note + + There is no need to assign an interface to the primary control + network because tunnels are formed between the master and the slaves using IP + addresses that are provided in *servers.conf*. Shown below is a representative diagram of the configuration above. diff --git a/docs/devguide.md b/docs/devguide.md index 160e4969..4fa43977 100644 --- a/docs/devguide.md +++ b/docs/devguide.md @@ -1,9 +1,6 @@ # CORE Developer's Guide -* Table of Contents -{:toc} - -## Repository Overview +## Overview The CORE source consists of several programming languages for historical reasons. Current development focuses on the Python modules and @@ -65,7 +62,7 @@ inv test-mock ## Linux Network Namespace Commands Linux network namespace containers are often managed using the *Linux Container Tools* or *lxc-tools* package. -The lxc-tools website is available here http://lxc.sourceforge.net/ for more information. CORE does not use these +The lxc-tools website is available here http://lxc.sourceforge.net/ for more information. CORE does not use these management utilities, but includes its own set of tools for instantiating and configuring network namespace containers. This section describes these tools. @@ -100,7 +97,7 @@ vcmd -c /tmp/pycore.50160/n1 -- /sbin/ip -4 ro A script named *core-cleanup* is provided to clean up any running CORE emulations. It will attempt to kill any remaining vnoded processes, kill any EMANE processes, remove the :file:`/tmp/pycore.*` session directories, and remove -any bridges or *nftables* rules. With a *-d* option, it will also kill any running CORE daemon. +any bridges or *nftables* rules. With a *-d* option, it will also kill any running CORE daemon. ### netns command diff --git a/docs/distributed.md b/docs/distributed.md index 65429f03..95ec7268 100644 --- a/docs/distributed.md +++ b/docs/distributed.md @@ -1,8 +1,5 @@ # CORE - Distributed Emulation -* Table of Contents -{:toc} - ## Overview A large emulation scenario can be deployed on multiple emulation servers and @@ -61,6 +58,7 @@ First the distributed servers must be configured to allow passwordless root login over SSH. On distributed server: + ```shelll # install openssh-server sudo apt install openssh-server @@ -81,6 +79,7 @@ sudo systemctl restart sshd ``` On master server: + ```shell # install package if needed sudo apt install openssh-client @@ -99,6 +98,7 @@ connect_kwargs: {"key_filename": "/home/user/.ssh/core"} ``` On distributed server: + ```shell # open sshd config vi /etc/ssh/sshd_config @@ -116,8 +116,9 @@ Make sure the value used below is the absolute path to the file generated above **~/.ssh/core**" Add/update the fabric configuration file **/etc/fabric.yml**: + ```yaml -connect_kwargs: {"key_filename": "/home/user/.ssh/core"} +connect_kwargs: { "key_filename": "/home/user/.ssh/core" } ``` ## Add Emulation Servers in GUI @@ -169,8 +170,10 @@ only if an EMANE model is used for the WLAN. The basic range model does not work across multiple servers due to the Linux bridging and nftables rules that are used. -**NOTE: The basic range wireless model does not support distributed emulation, -but EMANE does.** +!!! note + + The basic range wireless model does not support distributed emulation, + but EMANE does. When nodes are linked across servers **core-daemons** will automatically create necessary tunnels between the nodes when executed. Care should be taken @@ -181,10 +184,10 @@ These tunnels are created using GRE tunneling, similar to the Tunnel Tool. ## Distributed Checklist 1. Install CORE on master server -1. Install distributed CORE package on all servers needed -1. Installed and configure public-key SSH access on all servers (if you want to use -double-click shells or Widgets.) for both the GUI user (for terminals) and root for running CORE commands -1. Update CORE configuration as needed -1. Choose the servers that participate in distributed emulation. -1. Assign nodes to desired servers, empty for master server. -1. Press the **Start** button to launch the distributed emulation. +2. Install distributed CORE package on all servers needed +3. Installed and configure public-key SSH access on all servers (if you want to use + double-click shells or Widgets.) for both the GUI user (for terminals) and root for running CORE commands +4. Update CORE configuration as needed +5. Choose the servers that participate in distributed emulation. +6. Assign nodes to desired servers, empty for master server. +7. Press the **Start** button to launch the distributed emulation. diff --git a/docs/docker.md b/docs/docker.md index 0c730369..562fd453 100644 --- a/docs/docker.md +++ b/docs/docker.md @@ -15,7 +15,6 @@ sudo apt install docker.io ### RHEL Systems - ## Configuration Custom configuration required to avoid iptable rules being added and removing @@ -26,8 +25,8 @@ Place the file below in **/etc/docker/docker.json** ```json { - "bridge": "none", - "iptables": false + "bridge": "none", + "iptables": false } ``` @@ -53,6 +52,7 @@ Images used by Docker nodes in CORE need to have networking tools installed for CORE to automate setup and configuration of the network within the container. Example Dockerfile: + ``` FROM ubuntu:latest RUN apt-get update @@ -60,6 +60,7 @@ RUN apt-get install -y iproute2 ethtool ``` Build image: + ```shell sudo docker build -t . ``` diff --git a/docs/emane.md b/docs/emane.md index 7f83aa25..a034c63b 100644 --- a/docs/emane.md +++ b/docs/emane.md @@ -1,7 +1,4 @@ -# CORE/EMANE - -* Table of Contents -{:toc} +# EMANE (Extendable Mobile Ad-hoc Network Emulator) ## What is EMANE? @@ -31,7 +28,7 @@ and instantiates one EMANE process in the namespace. The EMANE process binds a user space socket to the TAP device for sending and receiving data from CORE. An EMANE instance sends and receives OTA (Over-The-Air) traffic to and from -other EMANE instances via a control port (e.g. *ctrl0*, *ctrl1*). It also +other EMANE instances via a control port (e.g. *ctrl0*, *ctrl1*). It also sends and receives Events to and from the Event Service using the same or a different control port. EMANE models are configured through the GUI's configuration dialog. A corresponding EmaneModel Python class is sub-classed @@ -60,7 +57,9 @@ You can find more detailed tutorials and examples at the Every topic below assumes CORE, EMANE, and OSPF MDR have been installed. -> **WARNING:** demo files will be found within the new `core-gui` +!!! info + + Demo files will be found within the `core-gui` **~/.coregui/xmls** directory | Topic | Model | Description | |--------------------------------------|---------|-----------------------------------------------------------| @@ -92,8 +91,10 @@ If you have an EMANE event generator (e.g. mobility or pathloss scripts) and want to have CORE subscribe to EMANE location events, set the following line in the **core.conf** configuration file. -> **NOTE:** Do not set this option to True if you want to manually drag nodes around -on the canvas to update their location in EMANE. +!!! note + + Do not set this option to True if you want to manually drag nodes around + on the canvas to update their location in EMANE. ```shell emane_event_monitor = True @@ -104,6 +105,7 @@ prefix will place the DTD files in **/usr/local/share/emane/dtd** while CORE expects them in **/usr/share/emane/dtd**. Update the EMANE prefix configuration to resolve this problem. + ```shell emane_prefix = /usr/local ``` @@ -116,6 +118,7 @@ placed within the path defined by **emane_models_dir** in the CORE configuration file. This path cannot end in **/emane**. Here is an example model with documentation describing functionality: + ```python """ Example custom emane model. @@ -181,6 +184,7 @@ class ExampleModel(emanemodel.EmaneModel): :param emane_prefix: configured emane prefix path :return: nothing """ + cls._load_platform_config(emane_prefix) manifest_path = "share/emane/manifest" # load mac configuration mac_xml_path = emane_prefix / manifest_path / cls.mac_xml @@ -210,7 +214,7 @@ The EMANE models should be listed here for selection. (You may need to restart t CORE daemon if it was running prior to installing the EMANE Python bindings.) When an EMANE model is selected, you can click on the models option button -causing the GUI to query the CORE daemon for configuration items. +causing the GUI to query the CORE daemon for configuration items. Each model will have different parameters, refer to the EMANE documentation for an explanation of each item. The defaults values are presented in the dialog. Clicking *Apply* and *Apply* again will store the @@ -220,7 +224,7 @@ The RF-PIPE and IEEE 802.11abg models use a Universal PHY that supports geographic location information for determining pathloss between nodes. A default latitude and longitude location is provided by CORE and this location-based pathloss is enabled by default; this is the *pathloss mode* -setting for the Universal PHY. Moving a node on the canvas while the +setting for the Universal PHY. Moving a node on the canvas while the emulation is running generates location events for EMANE. To view or change the geographic location or scale of the canvas use the *Canvas Size and Scale* dialog available from the *Canvas* menu. @@ -237,7 +241,7 @@ to be created in the virtual nodes that are linked to the EMANE WLAN. These devices appear with interface names such as eth0, eth1, etc. The EMANE processes should now be running in each namespace. -To view the configuration generated by CORE, look in the */tmp/pycore.nnnnn/* session +To view the configuration generated by CORE, look in the */tmp/pycore.nnnnn/* session directory to find the generated EMANE xml files. One easy way to view this information is by double-clicking one of the virtual nodes and listing the files in the shell. @@ -279,14 +283,15 @@ being used, along with changing any configuration setting from their defaults. ![](static/emane-configuration.png) -> **NOTE:** Here is a quick checklist for distributed emulation with EMANE. +!!! note - 1. Follow the steps outlined for normal CORE. - 2. Assign nodes to desired servers - 3. Synchronize your machine's clocks prior to starting the emulation, - using *ntp* or *ptp*. Some EMANE models are sensitive to timing. - 4. Press the *Start* button to launch the distributed emulation. + Here is a quick checklist for distributed emulation with EMANE. +1. Follow the steps outlined for normal CORE. +2. Assign nodes to desired servers +3. Synchronize your machine's clocks prior to starting the emulation, + using *ntp* or *ptp*. Some EMANE models are sensitive to timing. +4. Press the *Start* button to launch the distributed emulation. Now when the Start button is used to instantiate the emulation, the local CORE daemon will connect to other emulation servers that have been assigned diff --git a/docs/emane/antenna.md b/docs/emane/antenna.md index c8a86eaa..79c023ac 100644 --- a/docs/emane/antenna.md +++ b/docs/emane/antenna.md @@ -1,8 +1,7 @@ # EMANE Antenna Profiles -* Table of Contents -{:toc} ## Overview + Introduction to using the EMANE antenna profile in CORE, based on the example EMANE Demo linked below. @@ -10,340 +9,348 @@ EMANE Demo linked below. for more specifics. ## Demo Setup + We will need to create some files in advance of starting this session. Create directory to place antenna profile files. + ```shell mkdir /tmp/emane ``` Create `/tmp/emane/antennaprofile.xml` with the following contents. + ```xml - - - - - - + + + + + + ``` Create `/tmp/emane/antenna30dsector.xml` with the following contents. + ```xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ``` Create `/tmp/emane/blockageaft.xml` with the following contents. + ```xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ``` ## Run Demo + 1. Select `Open...` within the GUI 1. Load `emane-demo-antenna.xml` 1. Click ![Start Button](../static/gui/start.png) 1. After startup completes, double click n1 to bring up the nodes terminal ## Example Demo + This demo will cover running an EMANE event service to feed in antenna, location, and pathloss events to demonstrate how antenna profiles can be used. ### EMANE Event Dump + On n1 lets dump EMANE events, so when we later run the EMANE event service you can monitor when and what is sent. @@ -352,38 +359,44 @@ root@n1:/tmp/pycore.44917/n1.conf# emaneevent-dump -i ctrl0 ``` ### Send EMANE Events + On the host machine create the following to send EMANE events. -> **WARNING:** make sure to set the `eventservicedevice` to the proper control -> network value +!!! warning + + Make sure to set the `eventservicedevice` to the proper control + network value Create `eventservice.xml` with the following contents. + ```xml - - - + + + ``` Create `eelgenerator.xml` with the following contents. + ```xml - + - - - - + + + + ``` Create `scenario.eel` with the following contents. + ```shell 0.0 nem:1 antennaprofile 1,0.0,0.0 0.0 nem:4 antennaprofile 2,0.0,0.0 @@ -413,23 +426,25 @@ Create `scenario.eel` with the following contents. Run the EMANE event service, monitor what is output on n1 for events dumped and see the link changes within the CORE GUI. + ```shell emaneeventservice -l 3 eventservice.xml ``` ### Stages + The events sent will trigger 4 different states. * State 1 - * n2 and n3 see each other - * n4 and n3 are pointing away + * n2 and n3 see each other + * n4 and n3 are pointing away * State 2 - * n2 and n3 see each other - * n1 and n2 see each other - * n4 and n3 see each other + * n2 and n3 see each other + * n1 and n2 see each other + * n4 and n3 see each other * State 3 - * n2 and n3 see each other - * n4 and n3 are pointing at each other but blocked + * n2 and n3 see each other + * n4 and n3 are pointing at each other but blocked * State 4 - * n2 and n3 see each other - * n4 and n3 see each other + * n2 and n3 see each other + * n4 and n3 see each other diff --git a/docs/emane/eel.md b/docs/emane/eel.md index ca094542..c2dad86a 100644 --- a/docs/emane/eel.md +++ b/docs/emane/eel.md @@ -1,44 +1,51 @@ # EMANE Emulation Event Log (EEL) Generator -* Table of Contents -{:toc} ## Overview + Introduction to using the EMANE event service and eel files to provide events. [EMANE Demo 1](https://github.com/adjacentlink/emane-tutorial/wiki/Demonstration-1) for more specifics. ## Run Demo + 1. Select `Open...` within the GUI -1. Load `emane-demo-eel.xml` -1. Click ![Start Button](../static/gui/start.png) -1. After startup completes, double click n1 to bring up the nodes terminal +2. Load `emane-demo-eel.xml` +3. Click ![Start Button](../static/gui/start.png) +4. After startup completes, double click n1 to bring up the nodes terminal ## Example Demo + This demo will go over defining an EMANE event service and eel file to drive an emane event service. ### Viewing Events + On n1 we will use the EMANE event dump utility to listen to events. + ```shell root@n1:/tmp/pycore.46777/n1.conf# emaneevent-dump -i ctrl0 ``` ### Sending Events + On the host machine we will create the following files and start the EMANE event service targeting the control network. -> **WARNING:** make sure to set the `eventservicedevice` to the proper control -> network value +!!! warning + + Make sure to set the `eventservicedevice` to the proper control + network value Create `eventservice.xml` with the following contents. + ```xml - - - + + + ``` @@ -57,21 +64,23 @@ These configuration items tell the EEL Generator which sentences to map to which plugin and whether to issue delta or full updates. Create `eelgenerator.xml` with the following contents. + ```xml - + - - - - + + + + ``` Finally, create `scenario.eel` with the following contents. + ```shell 0.0 nem:1 pathloss nem:2,90.0 0.0 nem:2 pathloss nem:1,90.0 @@ -80,11 +89,13 @@ Finally, create `scenario.eel` with the following contents. ``` Start the EMANE event service using the files created above. + ```shell emaneeventservice eventservice.xml -l 3 ``` ### Sent Events + If we go back to look at our original terminal we will see the events logged out to the terminal. diff --git a/docs/emane/files.md b/docs/emane/files.md index c9bc35e8..c04b0f6b 100644 --- a/docs/emane/files.md +++ b/docs/emane/files.md @@ -1,8 +1,7 @@ # EMANE XML Files -* Table of Contents -{:toc} ## Overview + Introduction to the XML files generated by CORE used to drive EMANE for a given node. @@ -10,12 +9,14 @@ a given node. may provide more helpful details. ## Run Demo + 1. Select `Open...` within the GUI -1. Load `emane-demo-files.xml` -1. Click ![Start Button](../static/gui/start.png) -1. After startup completes, double click n1 to bring up the nodes terminal +2. Load `emane-demo-files.xml` +3. Click ![Start Button](../static/gui/start.png) +4. After startup completes, double click n1 to bring up the nodes terminal ## Example Demo + We will take a look at the files generated in the example demo provided. In this case we are running the RF Pipe model. @@ -31,6 +32,7 @@ case we are running the RF Pipe model. | \-trans.xml | configuration when a raw transport is being used | ### Listing File + Below are the files within n1 after starting the demo session. ```shell @@ -41,6 +43,7 @@ eth0-phy.xml n1-emane.log usr.local.etc.quagga var.run.quagga ``` ### Platform XML + The root configuration file used to run EMANE for a node is the platform xml file. In this demo we are looking at `n1-platform.xml`. @@ -78,6 +81,7 @@ root@n1:/tmp/pycore.46777/n1.conf# cat n1-platform.xml ``` ### NEM XML + The nem definition will contain reference to the transport, mac, and phy xml definitions being used for a given nem. @@ -93,6 +97,7 @@ root@n1:/tmp/pycore.46777/n1.conf# cat eth0-nem.xml ``` ### MAC XML + MAC layer configuration settings would be found in this file. CORE will write out all values, even if the value is a default value. @@ -115,6 +120,7 @@ root@n1:/tmp/pycore.46777/n1.conf# cat eth0-mac.xml ``` ### PHY XML + PHY layer configuration settings would be found in this file. CORE will write out all values, even if the value is a default value. @@ -149,6 +155,7 @@ root@n1:/tmp/pycore.46777/n1.conf# cat eth0-phy.xml ``` ### Transport XML + ```shell root@n1:/tmp/pycore.46777/n1.conf# cat eth0-trans-virtual.xml diff --git a/docs/emane/gpsd.md b/docs/emane/gpsd.md index f20cc8fe..eadf8af2 100644 --- a/docs/emane/gpsd.md +++ b/docs/emane/gpsd.md @@ -1,54 +1,62 @@ # EMANE GPSD Integration -* Table of Contents -{:toc} ## Overview + Introduction to integrating gpsd in CORE with EMANE. [EMANE Demo 0](https://github.com/adjacentlink/emane-tutorial/wiki/Demonstration-0) may provide more helpful details. -> **WARNING:** requires installation of [gpsd](https://gpsd.gitlab.io/gpsd/index.html) +!!! warning + + Requires installation of [gpsd](https://gpsd.gitlab.io/gpsd/index.html) ## Run Demo + 1. Select `Open...` within the GUI -1. Load `emane-demo-gpsd.xml` -1. Click ![Start Button](../static/gui/start.png) -1. After startup completes, double click n1 to bring up the nodes terminal +2. Load `emane-demo-gpsd.xml` +3. Click ![Start Button](../static/gui/start.png) +4. After startup completes, double click n1 to bring up the nodes terminal ## Example Demo + This section will cover how to run a gpsd location agent within EMANE, that will write out locations to a pseudo terminal file. That file can be read in by the gpsd server and make EMANE location events available to gpsd clients. ### EMANE GPSD Event Daemon + First create an `eventdaemon.xml` file on n1 with the following contents. + ```xml - - - + + + ``` Then create the `gpsdlocationagent.xml` file on n1 with the following contents. + ```xml - + ``` Start the EMANE event agent. This will facilitate feeding location events out to a pseudo terminal file defined above. + ```shell emaneeventd eventdaemon.xml -r -d -l 3 -f emaneeventd.log ``` Start gpsd, reading in the pseudo terminal file. + ```shell gpsd -G -n -b $(cat gps.pty) ``` @@ -59,36 +67,41 @@ EEL Events will be played out from the actual host machine over the designated control network interface. Create the following files in the same directory somewhere on your host. -> **NOTE:** make sure the below eventservicedevice matches the control network -> device being used on the host for EMANE +!!! note + + Make sure the below eventservicedevice matches the control network + device being used on the host for EMANE Create `eventservice.xml` on the host machine with the following contents. + ```xml - - - + + + ``` Create `eelgenerator.xml` on the host machine with the following contents. + ```xml - + - - - - + + + + ``` Create `scenario.eel` file with the following contents. + ```shell 0.0 nem:1 location gps 40.031075,-74.523518,3.000000 0.0 nem:2 location gps 40.031165,-74.523412,3.000000 @@ -96,7 +109,8 @@ Create `scenario.eel` file with the following contents. Start the EEL event service, which will send the events defined in the file above over the control network to all EMANE nodes. These location events will be received -and provided to gpsd. This allow gpsd client to connect to and get gps locations. +and provided to gpsd. This allows gpsd client to connect to and get gps locations. + ```shell emaneeventservice eventservice.xml -l 3 ``` diff --git a/docs/emane/precomputed.md b/docs/emane/precomputed.md index 53da75eb..4d0234ae 100644 --- a/docs/emane/precomputed.md +++ b/docs/emane/precomputed.md @@ -1,35 +1,40 @@ # EMANE Procomputed -* Table of Contents -{:toc} ## Overview + Introduction to using the precomputed propagation model. [EMANE Demo 1](https://github.com/adjacentlink/emane-tutorial/wiki/Demonstration-1) for more specifics. ## Run Demo + 1. Select `Open...` within the GUI -1. Load `emane-demo-precomputed.xml` -1. Click ![Start Button](../static/gui/start.png) -1. After startup completes, double click n1 to bring up the nodes terminal +2. Load `emane-demo-precomputed.xml` +3. Click ![Start Button](../static/gui/start.png) +4. After startup completes, double click n1 to bring up the nodes terminal ## Example Demo -This demo is uing the RF Pipe model witht he propagation model set to + +This demo is using the RF Pipe model with the propagation model set to precomputed. ### Failed Pings + Due to using precomputed and having not sent any pathloss events, the nodes -cannot ping eachother yet. +cannot ping each other yet. Open a terminal on n1. + ```shell root@n1:/tmp/pycore.46777/n1.conf# ping 10.0.0.2 connect: Network is unreachable ``` ### EMANE Shell + You can leverage `emanesh` to investigate why packets are being dropped. + ```shell root@n1:/tmp/pycore.46777/n1.conf# emanesh localhost get table nems phy BroadcastPacketDropTable0 UnicastPacketDropTable0 nem 1 phy BroadcastPacketDropTable0 @@ -43,6 +48,7 @@ nem 1 phy UnicastPacketDropTable0 In the example above we can see that the reason packets are being dropped is due to the propogation model and that is because we have not issued any pathloss events. You can run another command to validate if you have received any pathloss events. + ```shell root@n1:/tmp/pycore.46777/n1.conf# emanesh localhost get table nems phy PathlossEventInfoTable nem 1 phy PathlossEventInfoTable @@ -50,15 +56,19 @@ nem 1 phy PathlossEventInfoTable ``` ### Pathloss Events + On the host we will send pathloss events from all nems to all other nems. -> **NOTE:** make sure properly specify the right control network device +!!! note + + Make sure properly specify the right control network device ```shell emaneevent-pathloss 1:2 90 -i ``` Now if we check for pathloss events on n2 we will see what was just sent above. + ```shell root@n1:/tmp/pycore.46777/n1.conf# emanesh localhost get table nems phy PathlossEventInfoTable nem 1 phy PathlossEventInfoTable @@ -67,6 +77,7 @@ nem 1 phy PathlossEventInfoTable ``` You should also now be able to ping n1 from n2. + ```shell root@n1:/tmp/pycore.46777/n1.conf# ping -c 3 10.0.0.2 PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data. diff --git a/docs/grpc.md b/docs/grpc.md index 9fff1f80..3266a57d 100644 --- a/docs/grpc.md +++ b/docs/grpc.md @@ -1,7 +1,6 @@ -# gRPC API - * Table of Contents -{:toc} + +## Overview [gRPC](https://grpc.io/) is a client/server API for interfacing with CORE and used by the python GUI for driving all functionality. It is dependent @@ -9,7 +8,7 @@ on having a running `core-daemon` instance to be leveraged. A python client can be created from the raw generated grpc files included with CORE or one can leverage a provided gRPC client that helps encapsulate -some of the functionality to try and help make things easier. +some functionality to try and help make things easier. ## Python Client @@ -19,7 +18,7 @@ to help provide some conveniences when using the API. ### Client HTTP Proxy -Since gRPC is HTTP2 based, proxy configurations can cause issues. By default +Since gRPC is HTTP2 based, proxy configurations can cause issues. By default, the client disables proxy support to avoid issues when a proxy is present. You can enable and properly account for this issue when needed. @@ -41,13 +40,13 @@ When creating nodes of type `NodeType.DEFAULT` these are the default models and the services they map to. * mdr - * zebra, OSPFv3MDR, IPForward + * zebra, OSPFv3MDR, IPForward * PC - * DefaultRoute + * DefaultRoute * router - * zebra, OSPFv2, OSPFv3, IPForward + * zebra, OSPFv2, OSPFv3, IPForward * host - * DefaultRoute, SSH + * DefaultRoute, SSH ### Interface Helper @@ -56,8 +55,10 @@ when creating interface data for nodes. Alternatively one can manually create a `core.api.grpc.wrappers.Interface` class instead with appropriate information. Manually creating gRPC client interface: + ```python from core.api.grpc.wrappers import Interface + # id is optional and will set to the next available id # name is optional and will default to eth # mac is optional and will result in a randomly generated mac @@ -72,6 +73,7 @@ iface = Interface( ``` Leveraging the interface helper class: + ```python from core.api.grpc import client @@ -90,6 +92,7 @@ iface_data = iface_helper.create_iface( Various events that can occur within a session can be listened to. Event types: + * session - events for changes in session state and mobility start/stop/pause * node - events for node movements and icon changes * link - events for link configuration changes and wireless link add/delete @@ -101,9 +104,11 @@ Event types: from core.api.grpc import client from core.api.grpc.wrappers import EventType + def event_listener(event): print(event) + # create grpc client and connect core = client.CoreGrpcClient() core.connect() @@ -123,6 +128,7 @@ core.events(session.id, event_listener, [EventType.NODE]) Links can be configured at the time of creation or during runtime. Currently supported configuration options: + * bandwidth (bps) * delay (us) * duplicate (%) @@ -167,10 +173,11 @@ core.edit_link(session.id, link) ``` ### Peer to Peer Example + ```python # required imports from core.api.grpc import client -from core.api.grpc.core_pb2 import Position +from core.api.grpc.wrappers import Position # interface helper iface_helper = client.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001::/64") @@ -198,10 +205,11 @@ core.start_session(session) ``` ### Switch/Hub Example + ```python # required imports from core.api.grpc import client -from core.api.grpc.core_pb2 import NodeType, Position +from core.api.grpc.wrappers import NodeType, Position # interface helper iface_helper = client.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001::/64") @@ -232,10 +240,11 @@ core.start_session(session) ``` ### WLAN Example + ```python # required imports from core.api.grpc import client -from core.api.grpc.core_pb2 import NodeType, Position +from core.api.grpc.wrappers import NodeType, Position # interface helper iface_helper = client.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001::/64") @@ -283,6 +292,7 @@ For EMANE you can import and use one of the existing models and use its name for configuration. Current models: + * core.emane.ieee80211abg.EmaneIeee80211abgModel * core.emane.rfpipe.EmaneRfPipeModel * core.emane.tdma.EmaneTdmaModel @@ -299,7 +309,7 @@ will use the defaults. When no configuration is used, the defaults are used. ```python # required imports from core.api.grpc import client -from core.api.grpc.core_pb2 import NodeType, Position +from core.api.grpc.wrappers import NodeType, Position from core.emane.models.ieee80211abg import EmaneIeee80211abgModel # interface helper @@ -315,7 +325,7 @@ session = core.create_session() # create nodes position = Position(x=200, y=200) emane = session.add_node( - 1, _type=NodeType.EMANE, position=position, emane=EmaneIeee80211abgModel.name + 1, _type=NodeType.EMANE, position=position, emane=EmaneIeee80211abgModel.name ) position = Position(x=100, y=100) node1 = session.add_node(2, model="mdr", position=position) @@ -330,8 +340,8 @@ session.add_link(node1=node2, node2=emane, iface1=iface1) # setting emane specific emane model configuration emane.set_emane_model(EmaneIeee80211abgModel.name, { - "eventservicettl": "2", - "unicastrate": "3", + "eventservicettl": "2", + "unicastrate": "3", }) # start session @@ -339,6 +349,7 @@ core.start_session(session) ``` EMANE Model Configuration: + ```python # emane network specific config, set on an emane node # this setting applies to all nodes connected @@ -359,6 +370,7 @@ Configuring the files of a service results in a specific hard coded script being generated, instead of the default scripts, that may leverage dynamic generation. The following features can be configured for a service: + * files - files that will be generated * directories - directories that will be mounted unique to the node * startup - commands to run start a service @@ -366,6 +378,7 @@ The following features can be configured for a service: * shutdown - commands to run to stop a service Editing service properties: + ```python # configure a service, for a node, for a given session node.service_configs[service_name] = NodeServiceData( @@ -381,6 +394,7 @@ When editing a service file, it must be the name of `config` file that the service will generate. Editing a service file: + ```python # to edit the contents of a generated file you can specify # the service, the file name, and its contents diff --git a/docs/gui.md b/docs/gui.md index ebd4afc1..c296ac18 100644 --- a/docs/gui.md +++ b/docs/gui.md @@ -1,9 +1,5 @@ - # CORE GUI -* Table of Contents -{:toc} - ![](static/core-gui.png) ## Overview @@ -12,7 +8,7 @@ The GUI is used to draw nodes and network devices on a canvas, linking them together to create an emulated network session. After pressing the start button, CORE will proceed through these phases, -staying in the **runtime** phase. After the session is stopped, CORE will +staying in the **runtime** phase. After the session is stopped, CORE will proceed to the **data collection** phase before tearing down the emulated state. @@ -22,7 +18,7 @@ when these session states are reached. ## Prerequisites -Beyond installing CORE, you must have the CORE daemon running. This is done +Beyond installing CORE, you must have the CORE daemon running. This is done on the command line with either systemd or sysv. ```shell @@ -40,24 +36,24 @@ The GUI will create a directory in your home directory on first run called ~/.coregui. This directory will help layout various files that the GUI may use. * .coregui/ - * backgrounds/ - * place backgrounds used for display in the GUI - * custom_emane/ - * place to keep custom emane models to use with the core-daemon - * custom_services/ - * place to keep custom services to use with the core-daemon - * icons/ - * icons the GUI uses along with customs icons desired - * mobility/ - * place to keep custom mobility files - * scripts/ - * place to keep core related scripts - * xmls/ - * place to keep saved session xml files - * gui.log - * log file when running the gui, look here when issues occur for exceptions etc - * config.yaml - * configuration file used to save/load various gui related settings (custom nodes, layouts, addresses, etc) + * backgrounds/ + * place backgrounds used for display in the GUI + * custom_emane/ + * place to keep custom emane models to use with the core-daemon + * custom_services/ + * place to keep custom services to use with the core-daemon + * icons/ + * icons the GUI uses along with customs icons desired + * mobility/ + * place to keep custom mobility files + * scripts/ + * place to keep core related scripts + * xmls/ + * place to keep saved session xml files + * gui.log + * log file when running the gui, look here when issues occur for exceptions etc + * config.yaml + * configuration file used to save/load various gui related settings (custom nodes, layouts, addresses, etc) ## Modes of Operation @@ -309,168 +305,6 @@ and options. | CORE Documentation (www) | Lnk to the CORE Documentation page. | | About | Invokes the About dialog box for viewing version information. | -## Connecting with Physical Networks - -CORE's emulated networks run in real time, so they can be connected to live -physical networks. The RJ45 tool and the Tunnel tool help with connecting to -the real world. These tools are available from the **Link-layer nodes** menu. - -When connecting two or more CORE emulations together, MAC address collisions -should be avoided. CORE automatically assigns MAC addresses to interfaces when -the emulation is started, starting with **00:00:00:aa:00:00** and incrementing -the bottom byte. The starting byte should be changed on the second CORE machine -using the **Tools->MAC Addresses** option the menu. - -### RJ45 Tool - -The RJ45 node in CORE represents a physical interface on the real CORE machine. -Any real-world network device can be connected to the interface and communicate -with the CORE nodes in real time. - -The main drawback is that one physical interface is required for each -connection. When the physical interface is assigned to CORE, it may not be used -for anything else. Another consideration is that the computer or network that -you are connecting to must be co-located with the CORE machine. - -To place an RJ45 connection, click on the **Link-layer nodes** toolbar and select -the **RJ45 Tool** from the submenu. Click on the canvas near the node you want to -connect to. This could be a router, hub, switch, or WLAN, for example. Now -click on the *Link Tool* and draw a link between the RJ45 and the other node. -The RJ45 node will display "UNASSIGNED". Double-click the RJ45 node to assign a -physical interface. A list of available interfaces will be shown, and one may -be selected by double-clicking its name in the list, or an interface name may -be entered into the text box. - -> **NOTE:** When you press the Start button to instantiate your topology, the - interface assigned to the RJ45 will be connected to the CORE topology. The - interface can no longer be used by the system. - -Multiple RJ45 nodes can be used within CORE and assigned to the same physical -interface if 802.1x VLANs are used. This allows for more RJ45 nodes than -physical ports are available, but the (e.g. switching) hardware connected to -the physical port must support the VLAN tagging, and the available bandwidth -will be shared. - -You need to create separate VLAN virtual devices on the Linux host, -and then assign these devices to RJ45 nodes inside of CORE. The VLANning is -actually performed outside of CORE, so when the CORE emulated node receives a -packet, the VLAN tag will already be removed. - -Here are example commands for creating VLAN devices under Linux: - -```shell -ip link add link eth0 name eth0.1 type vlan id 1 -ip link add link eth0 name eth0.2 type vlan id 2 -ip link add link eth0 name eth0.3 type vlan id 3 -``` - -### Tunnel Tool - -The tunnel tool builds GRE tunnels between CORE emulations or other hosts. -Tunneling can be helpful when the number of physical interfaces is limited or -when the peer is located on a different network. Also a physical interface does -not need to be dedicated to CORE as with the RJ45 tool. - -The peer GRE tunnel endpoint may be another CORE machine or another -host that supports GRE tunneling. When placing a Tunnel node, initially -the node will display "UNASSIGNED". This text should be replaced with the IP -address of the tunnel peer. This is the IP address of the other CORE machine or -physical machine, not an IP address of another virtual node. - -> **NOTE:** Be aware of possible MTU (Maximum Transmission Unit) issues with GRE devices. The *gretap* device - has an interface MTU of 1,458 bytes; when joined to a Linux bridge, the - bridge's MTU - becomes 1,458 bytes. The Linux bridge will not perform fragmentation for - large packets if other bridge ports have a higher MTU such as 1,500 bytes. - -The GRE key is used to identify flows with GRE tunneling. This allows multiple -GRE tunnels to exist between that same pair of tunnel peers. A unique number -should be used when multiple tunnels are used with the same peer. When -configuring the peer side of the tunnel, ensure that the matching keys are -used. - -Here are example commands for building the other end of a tunnel on a Linux -machine. In this example, a router in CORE has the virtual address -**10.0.0.1/24** and the CORE host machine has the (real) address -**198.51.100.34/24**. The Linux box -that will connect with the CORE machine is reachable over the (real) network -at **198.51.100.76/24**. -The emulated router is linked with the Tunnel Node. In the -Tunnel Node configuration dialog, the address **198.51.100.76** is entered, with -the key set to **1**. The gretap interface on the Linux box will be assigned -an address from the subnet of the virtual router node, -**10.0.0.2/24**. - -```shell -# these commands are run on the tunnel peer -sudo ip link add gt0 type gretap remote 198.51.100.34 local 198.51.100.76 key 1 -sudo ip addr add 10.0.0.2/24 dev gt0 -sudo ip link set dev gt0 up -``` - -Now the virtual router should be able to ping the Linux machine: - -```shell -# from the CORE router node -ping 10.0.0.2 -``` - -And the Linux machine should be able to ping inside the CORE emulation: - -```shell -# from the tunnel peer -ping 10.0.0.1 -``` - -To debug this configuration, **tcpdump** can be run on the gretap devices, or -on the physical interfaces on the CORE or Linux machines. Make sure that a -firewall is not blocking the GRE traffic. - -### Communicating with the Host Machine - -The host machine that runs the CORE GUI and/or daemon is not necessarily -accessible from a node. Running an X11 application on a node, for example, -requires some channel of communication for the application to connect with -the X server for graphical display. There are different ways to -connect from the node to the host and vice versa. - -#### Control Network - -The quickest way to connect with the host machine through the primary control -network. - -With a control network, the host can launch an X11 application on a node. -To run an X11 application on the node, the **SSH** service can be enabled on -the node, and SSH with X11 forwarding can be used from the host to the node. - -```shell -# SSH from host to node n5 to run an X11 app -ssh -X 172.16.0.5 xclock -``` - -#### Other Methods - -There are still other ways to connect a host with a node. The RJ45 Tool -can be used in conjunction with a dummy interface to access a node: - -```shell -sudo modprobe dummy numdummies=1 -``` - -A **dummy0** interface should appear on the host. Use the RJ45 tool assigned -to **dummy0**, and link this to a node in your scenario. After starting the -session, configure an address on the host. - -```shell -sudo ip link show type bridge -# determine bridge name from the above command -# assign an IP address on the same network as the linked node -sudo ip addr add 10.0.1.2/24 dev b.48304.34658 -``` - -In the example shown above, the host will have the address **10.0.1.2** and -the node linked to the RJ45 may have the address **10.0.1.1**. - ## Building Sample Networks ### Wired Networks @@ -501,21 +335,20 @@ CORE offers several levels of wireless emulation fidelity, depending on modeling hardware. * WLAN Node - * uses set bandwidth, delay, and loss - * links are enabled or disabled based on a set range - * uses the least CPU when moving, but nothing extra when not moving + * uses set bandwidth, delay, and loss + * links are enabled or disabled based on a set range + * uses the least CPU when moving, but nothing extra when not moving * Wireless Node - * uses set bandwidth, delay, and initial loss - * loss dynamically changes based on distance between nodes, which can be configured with range parameters - * links are enabled or disabled based on a set range - * uses more CPU to calculate loss for every movement, but nothing extra when not moving + * uses set bandwidth, delay, and initial loss + * loss dynamically changes based on distance between nodes, which can be configured with range parameters + * links are enabled or disabled based on a set range + * uses more CPU to calculate loss for every movement, but nothing extra when not moving * EMANE Node - * uses a physical layer model to account for signal propagation, antenna profile effects and interference - sources in order to provide a realistic environment for wireless experimentation - * uses the most CPU for every packet, as complex calculations are used for fidelity - * See [Wiki](https://github.com/adjacentlink/emane/wiki) for details on general EMANE usage - * See [CORE EMANE](emane.md) for details on using EMANE in CORE - + * uses a physical layer model to account for signal propagation, antenna profile effects and interference + sources in order to provide a realistic environment for wireless experimentation + * uses the most CPU for every packet, as complex calculations are used for fidelity + * See [Wiki](https://github.com/adjacentlink/emane/wiki) for details on general EMANE usage + * See [CORE EMANE](emane.md) for details on using EMANE in CORE | Model | Type | Supported Platform(s) | Fidelity | Description | |----------|--------|-----------------------|----------|-------------------------------------------------------------------------------| @@ -545,11 +378,27 @@ The default configuration of the WLAN is set to use the basic range model. Havin selected causes **core-daemon** to calculate the distance between nodes based on screen pixels. A numeric range in screen pixels is set for the wireless network using the **Range** slider. When two wireless nodes are within range of -each other, a green line is drawn between them and they are linked. Two +each other, a green line is drawn between them and they are linked. Two wireless nodes that are farther than the range pixels apart are not linked. During Execute mode, users may move wireless nodes around by clicking and dragging them, and wireless links will be dynamically made or broken. +### Running Commands within Nodes + +You can double click a node to bring up a terminal for running shell commands. Within +the terminal you can run anything you like and those commands will be run in context of the node. +For standard CORE nodes, the only thing to keep in mind is that you are using the host file +system and anything you change or do can impact the greater system. By default, your terminal +will open within the nodes home directory for the running session, but it is temporary and +will be removed when the session is stopped. + +You can also launch GUI based applications from within standard CORE nodes, but you need to +enable xhost access to root. + +```shell +xhost +local:root +``` + ### Mobility Scripting CORE has a few ways to script mobility. @@ -561,7 +410,8 @@ CORE has a few ways to script mobility. | EMANE events | See [EMANE](emane.md) for details on using EMANE scripts to move nodes around. Location information is typically given as latitude, longitude, and altitude. | For the first method, you can create a mobility script using a text -editor, or using a tool such as [BonnMotion](http://net.cs.uni-bonn.de/wg/cs/applications/bonnmotion/), and associate the script with one of the wireless +editor, or using a tool such as [BonnMotion](http://net.cs.uni-bonn.de/wg/cs/applications/bonnmotion/), and associate +the script with one of the wireless using the WLAN configuration dialog box. Click the *ns-2 mobility script...* button, and set the *mobility script file* field in the resulting *ns2script* configuration dialog. diff --git a/docs/hitl.md b/docs/hitl.md new file mode 100644 index 00000000..b659a36f --- /dev/null +++ b/docs/hitl.md @@ -0,0 +1,127 @@ +# Hardware In The Loop + +## Overview + +In some cases it may be impossible or impractical to run software using CORE +nodes alone. You may need to bring in external hardware into the network. +CORE's emulated networks run in real time, so they can be connected to live +physical networks. The RJ45 tool and the Tunnel tool help with connecting to +the real world. These tools are available from the **Link Layer Nodes** menu. + +When connecting two or more CORE emulations together, MAC address collisions +should be avoided. CORE automatically assigns MAC addresses to interfaces when +the emulation is started, starting with **00:00:00:aa:00:00** and incrementing +the bottom byte. The starting byte should be changed on the second CORE machine +using the **Tools->MAC Addresses** option the menu. + +## RJ45 Node + +CORE provides the RJ45 node, which represents a physical +interface within the host that is running CORE. Any real-world network +devices can be connected to the interface and communicate with the CORE nodes in real time. + +The main drawback is that one physical interface is required for each +connection. When the physical interface is assigned to CORE, it may not be used +for anything else. Another consideration is that the computer or network that +you are connecting to must be co-located with the CORE machine. + +### GUI Usage + +To place an RJ45 connection, click on the **Link Layer Nodes** toolbar and select +the **RJ45 Node** from the options. Click on the canvas, where you would like +the nodes to place. Now click on the **Link Tool** and draw a link between the RJ45 +and the other node you wish to be connected to. The RJ45 node will display "UNASSIGNED". +Double-click the RJ45 node to assign a physical interface. A list of available +interfaces will be shown, and one may be selected, then selecting **Apply**. + +!!! note + + When you press the Start button to instantiate your topology, the + interface assigned to the RJ45 will be connected to the CORE topology. The + interface can no longer be used by the system. + +### Multiple RJ45s with One Interface (VLAN) + +It is possible to have multiple RJ45 nodes using the same physical interface +by leveraging 802.1x VLANs. This allows for more RJ45 nodes than physical ports +are available, but the (e.g. switching) hardware connected to the physical port +must support the VLAN tagging, and the available bandwidth will be shared. + +You need to create separate VLAN virtual devices on the Linux host, +and then assign these devices to RJ45 nodes inside of CORE. The VLANing is +actually performed outside of CORE, so when the CORE emulated node receives a +packet, the VLAN tag will already be removed. + +Here are example commands for creating VLAN devices under Linux: + +```shell +ip link add link eth0 name eth0.1 type vlan id 1 +ip link add link eth0 name eth0.2 type vlan id 2 +ip link add link eth0 name eth0.3 type vlan id 3 +``` + +## Tunnel Tool + +The tunnel tool builds GRE tunnels between CORE emulations or other hosts. +Tunneling can be helpful when the number of physical interfaces is limited or +when the peer is located on a different network. In this case a physical interface does +not need to be dedicated to CORE as with the RJ45 tool. + +The peer GRE tunnel endpoint may be another CORE machine or another +host that supports GRE tunneling. When placing a Tunnel node, initially +the node will display "UNASSIGNED". This text should be replaced with the IP +address of the tunnel peer. This is the IP address of the other CORE machine or +physical machine, not an IP address of another virtual node. + +!!! note + + Be aware of possible MTU (Maximum Transmission Unit) issues with GRE devices. + The *gretap* device has an interface MTU of 1,458 bytes; when joined to a Linux + bridge, the bridge's MTU becomes 1,458 bytes. The Linux bridge will not perform + fragmentation for large packets if other bridge ports have a higher MTU such + as 1,500 bytes. + +The GRE key is used to identify flows with GRE tunneling. This allows multiple +GRE tunnels to exist between that same pair of tunnel peers. A unique number +should be used when multiple tunnels are used with the same peer. When +configuring the peer side of the tunnel, ensure that the matching keys are +used. + +### Example Usage + +Here are example commands for building the other end of a tunnel on a Linux +machine. In this example, a router in CORE has the virtual address +**10.0.0.1/24** and the CORE host machine has the (real) address +**198.51.100.34/24**. The Linux box +that will connect with the CORE machine is reachable over the (real) network +at **198.51.100.76/24**. +The emulated router is linked with the Tunnel Node. In the +Tunnel Node configuration dialog, the address **198.51.100.76** is entered, with +the key set to **1**. The gretap interface on the Linux box will be assigned +an address from the subnet of the virtual router node, +**10.0.0.2/24**. + +```shell +# these commands are run on the tunnel peer +sudo ip link add gt0 type gretap remote 198.51.100.34 local 198.51.100.76 key 1 +sudo ip addr add 10.0.0.2/24 dev gt0 +sudo ip link set dev gt0 up +``` + +Now the virtual router should be able to ping the Linux machine: + +```shell +# from the CORE router node +ping 10.0.0.2 +``` + +And the Linux machine should be able to ping inside the CORE emulation: + +```shell +# from the tunnel peer +ping 10.0.0.1 +``` + +To debug this configuration, **tcpdump** can be run on the gretap devices, or +on the physical interfaces on the CORE or Linux machines. Make sure that a +firewall is not blocking the GRE traffic. diff --git a/docs/index.md b/docs/index.md index e17a2e3b..4afec59f 100644 --- a/docs/index.md +++ b/docs/index.md @@ -4,32 +4,15 @@ CORE (Common Open Research Emulator) is a tool for building virtual networks. As an emulator, CORE builds a representation of a real computer network that runs in real time, as opposed to simulation, where abstract models are -used. The live-running emulation can be connected to physical networks and routers. It provides an environment for +used. The live-running emulation can be connected to physical networks and routers. It provides an environment for running real applications and protocols, taking advantage of tools provided by the Linux operating system. CORE is typically used for network and protocol research, demonstrations, application and platform testing, evaluating networking scenarios, security studies, and increasing the size of physical test networks. ### Key Features + * Efficient and scalable * Runs applications and protocols without modification * Drag and drop GUI * Highly customizable - -## Topics - -| Topic | Description | -|--------------------------------------|-------------------------------------------------------------------| -| [Installation](install.md) | How to install CORE and its requirements | -| [Architecture](architecture.md) | Overview of the architecture | -| [Node Types](nodetypes.md) | Overview of node types supported within CORE | -| [GUI](gui.md) | How to use the GUI | -| [Python API](python.md) | Covers how to control core directly using python | -| [gRPC API](grpc.md) | Covers how control core using gRPC | -| [Distributed](distributed.md) | Details for running CORE across multiple servers | -| [Control Network](ctrlnet.md) | How to use control networks to communicate with nodes from host | -| [Config Services](configservices.md) | Overview of provided config services and creating custom ones | -| [Services](services.md) | Overview of provided services and creating custom ones | -| [EMANE](emane.md) | Overview of EMANE integration and integrating custom EMANE models | -| [Performance](performance.md) | Notes on performance when using CORE | -| [Developers Guide](devguide.md) | Overview on how to contribute to CORE | diff --git a/docs/install.md b/docs/install.md index b3890cf7..51c05dbc 100644 --- a/docs/install.md +++ b/docs/install.md @@ -1,11 +1,12 @@ # Installation -* Table of Contents -{:toc} -> **WARNING:** if Docker is installed, the default iptable rules will block CORE traffic +!!! warning + + If Docker is installed, the default iptable rules will block CORE traffic ## Overview -CORE currently supports and provides the following install options, with the package + +CORE currently supports and provides the following installation options, with the package option being preferred. * [Package based install (rpm/deb)](#package-based-install) @@ -13,6 +14,7 @@ option being preferred. * [Dockerfile based install](#dockerfile-based-install) ### Requirements + Any computer capable of running Linux should be able to run CORE. Since the physical machine will be hosting numerous containers, as a general rule you should select a machine having as much RAM and CPU resources as possible. @@ -21,31 +23,35 @@ containers, as a general rule you should select a machine having as much RAM and * nftables compatible kernel and nft command line tool ### Supported Linux Distributions + Plan is to support recent Ubuntu and CentOS LTS releases. Verified: + * Ubuntu - 18.04, 20.04, 22.04 * CentOS - 7.8 ### Files + The following is a list of files that would be installed after installation. * executables - * `/bin/{vcmd, vnode}` - * can be adjusted using script based install , package will be /usr + * `/bin/{vcmd, vnode}` + * can be adjusted using script based install , package will be /usr * python files - * virtual environment `/opt/core/venv` - * local install will be local to the python version used - * `python3 -c "import core; print(core.__file__)"` - * scripts {core-daemon, core-cleanup, etc} - * virtualenv `/opt/core/venv/bin` - * local `/usr/local/bin` + * virtual environment `/opt/core/venv` + * local install will be local to the python version used + * `python3 -c "import core; print(core.__file__)"` + * scripts {core-daemon, core-cleanup, etc} + * virtualenv `/opt/core/venv/bin` + * local `/usr/local/bin` * configuration files - * `/etc/core/{core.conf, logging.conf}` + * `/etc/core/{core.conf, logging.conf}` * ospf mdr repository files when using script based install - * `/../ospf-mdr` + * `/../ospf-mdr` ### Installed Scripts + The following python scripts are provided. | Name | Description | @@ -59,17 +65,20 @@ The following python scripts are provided. | core-service-update | tool to update automate modifying a legacy service to match current naming | ### Upgrading from Older Release + Please make sure to uninstall any previous installations of CORE cleanly before proceeding to install. Clearing out a current install from 7.0.0+, making sure to provide options used for install (`-l` or `-p`). + ```shell cd inv uninstall ``` Previous install was built from source for CORE release older than 7.0.0: + ```shell cd sudo make uninstall @@ -78,6 +87,7 @@ make clean ``` Installed from previously built packages: + ```shell # centos sudo yum remove core @@ -85,6 +95,15 @@ sudo yum remove core sudo apt remove core ``` +## Installation Examples + +The below links will take you to sections providing complete examples for installing +CORE and related utilities on fresh installations. Otherwise, a breakdown for installing +different components and the options available are detailed below. + +* [Ubuntu 22.04](install_ubuntu.md) +* [CentOS 7](install_centos.md) + ## Package Based Install Starting with 9.0.0 there are pre-built rpm/deb packages. You can retrieve the @@ -94,10 +113,13 @@ The built packages will require and install system level dependencies, as well a a post install script to install the provided CORE python wheel. A similar uninstall script is ran when uninstalling and would require the same options as given, during the install. -> **NOTE:** PYTHON defaults to python3 for installs below, CORE requires python3.9+, pip, -> tk compatibility for python gui, and venv for virtual environments +!!! note + + PYTHON defaults to python3 for installs below, CORE requires python3.9+, pip, + tk compatibility for python gui, and venv for virtual environments Examples for install: + ```shell # recommended to upgrade to the latest version of pip before installation # in python, can help avoid building from source issues @@ -119,6 +141,7 @@ sudo -m pip install /opt/core/core--py3-none-any.whl ``` Example for removal, requires using the same options as install: + ```shell # remove a standard install sudo remove core @@ -133,6 +156,7 @@ sudo NO_PYTHON=1 remove core ``` ### Installing OSPF MDR + You will need to manually install OSPF MDR for routing nodes, since this is not provided by the package. @@ -150,6 +174,7 @@ sudo make install When done see [Post Install](#post-install). ## Script Based Install + The script based installation will install system level dependencies, python library and dependencies, as well as dependencies for building CORE. @@ -157,17 +182,22 @@ The script based install also automatically builds and installs OSPF MDR, used b on routing nodes. This can optionally be skipped. Installaion will carry out the following steps: + * installs system dependencies for building core * builds vcmd/vnoded and python grpc files * installs core into poetry managed virtual environment or locally, if flag is passed * installs systemd service pointing to appropriate python location based on install type * clone/build/install working version of [OPSF MDR](https://github.com/USNavalResearchLaboratory/ospf-mdr) -> **NOTE:** installing locally comes with its own risks, it can result it potential -> dependency conflicts with system package manager installed python dependencies +!!! note -> **NOTE:** provide a prefix that will be found on path when running as sudo, -> if the default prefix /usr/local will not be valid + Installing locally comes with its own risks, it can result it potential + dependency conflicts with system package manager installed python dependencies + +!!! note + + Provide a prefix that will be found on path when running as sudo, + if the default prefix /usr/local will not be valid The following tools will be leveraged during installation: @@ -179,6 +209,7 @@ The following tools will be leveraged during installation: | [poetry](https://python-poetry.org/) | used to install python virtual environment or building a python wheel | First we will need to clone and navigate to the CORE repo. + ```shell # clone CORE repo git clone https://github.com/coreemu/core.git @@ -220,6 +251,7 @@ Options: When done see [Post Install](#post-install). ### Unsupported Linux Distribution + For unsupported OSs you could attempt to do the following to translate an installation to your use case. @@ -234,6 +266,7 @@ inv install --dry -v -p -i ``` ## Dockerfile Based Install + You can leverage one of the provided Dockerfiles, to run and launch CORE within a Docker container. Since CORE nodes will leverage software available within the system for a given use case, @@ -244,7 +277,7 @@ make sure to update and build the Dockerfile with desired software. git clone https://github.com/coreemu/core.git cd core # build image -sudo docker build -t core -f Dockerfile. . +sudo docker build -t core -f dockerfiles/Dockerfile. . # start container sudo docker run -itd --name core -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix:rw --privileged core # enable xhost access to the root user @@ -256,7 +289,10 @@ sudo docker exec -it core core-gui When done see [Post Install](#post-install). ## Installing EMANE -> **NOTE:** installing EMANE for the virtual environment is known to work for 1.21+ + +!!! note + + Installing EMANE for the virtual environment is known to work for 1.21+ The recommended way to install EMANE is using prebuilt packages, otherwise you can follow their instructions for installing from source. Installation @@ -273,6 +309,7 @@ Also, these EMANE bindings need to be built using `protoc` 3.19+. So make sure that is available and being picked up on PATH properly. Examples for building and installing EMANE python bindings for use in CORE: + ```shell # if your system does not have protoc 3.19+ wget https://github.com/protocolbuffers/protobuf/releases/download/v3.19.6/protoc-3.19.6-linux-x86_64.zip @@ -297,32 +334,39 @@ inv install-emane -e ``` ## Post Install + After installation completes you are now ready to run CORE. ### Resolving Docker Issues + If you have Docker installed, by default it will change the iptables forwarding chain to drop packets, which will cause issues for CORE traffic. You can temporarily resolve the issue with the following command: + ```shell sudo iptables --policy FORWARD ACCEPT ``` + Alternatively, you can configure Docker to avoid doing this, but will likely break normal Docker networking usage. Using the setting below will require a restart. Place the file contents below in **/etc/docker/docker.json** + ```json { - "iptables": false + "iptables": false } ``` ### Resolving Path Issues + One problem running CORE you may run into, using the virtual environment or locally can be issues related to your path. To add support for your user to run scripts from the virtual environment: + ```shell # can add to ~/.bashrc export PATH=$PATH:/opt/core/venv/bin @@ -330,6 +374,7 @@ export PATH=$PATH:/opt/core/venv/bin This will not solve the path issue when running as sudo, so you can do either of the following to compensate. + ```shell # run command passing in the right PATH to pickup from the user running the command sudo env PATH=$PATH core-daemon @@ -341,6 +386,7 @@ sudop core-daemon ``` ### Running CORE + The following assumes I have resolved PATH issues and setup the `sudop` alias. ```shell @@ -351,6 +397,7 @@ core-gui ``` ### Enabling Service + After installation, the core service is not enabled by default. If you desire to use the service, run the following commands. diff --git a/docs/install_centos.md b/docs/install_centos.md new file mode 100644 index 00000000..53de2af6 --- /dev/null +++ b/docs/install_centos.md @@ -0,0 +1,144 @@ +# Install CentOS + +## Overview + +Below is a detailed path for installing CORE and related tooling on a fresh +CentOS 7 install. Both of the examples below will install CORE into its +own virtual environment located at **/opt/core/venv**. Both examples below +also assume using **~/Documents** as the working directory. + +## Script Install + +This section covers step by step commands that can be used to install CORE using +the script based installation path. + +``` shell +# install system packages +sudo yum -y update +sudo yum install -y git sudo wget tzdata unzip libpcap-devel libpcre3-devel \ + libxml2-devel protobuf-devel unzip uuid-devel tcpdump make epel-release +sudo yum-builddep -y python3 + +# install python3.9 +cd ~/Documents +wget https://www.python.org/ftp/python/3.9.15/Python-3.9.15.tgz +tar xf Python-3.9.15.tgz +cd Python-3.9.15 +./configure --enable-optimizations --with-ensurepip=install +sudo make -j$(nproc) altinstall +python3.9 -m pip install --upgrade pip + +# install core +cd ~/Documents +git clone https://github.com/coreemu/core +cd core +NO_SYSTEM=1 PYTHON=/usr/local/bin/python3.9 ./setup.sh +source ~/.bashrc +PYTHON=python3.9 inv install -p /usr --no-python + +# install emane +cd ~/Documents +wget -q https://adjacentlink.com/downloads/emane/emane-1.3.3-release-1.el7.x86_64.tar.gz +tar xf emane-1.3.3-release-1.el7.x86_64.tar.gz +cd emane-1.3.3-release-1/rpms/el7/x86_64 +sudo yum install -y ./openstatistic*.rpm ./emane*.rpm ./python3-emane_*.rpm + +# install emane python bindings into CORE virtual environment +cd ~/Documents +wget https://github.com/protocolbuffers/protobuf/releases/download/v3.19.6/protoc-3.19.6-linux-x86_64.zip +mkdir protoc +unzip protoc-3.19.6-linux-x86_64.zip -d protoc +git clone https://github.com/adjacentlink/emane.git +cd emane +git checkout v1.3.3 +./autogen.sh +PYTHON=/opt/core/venv/bin/python ./configure --prefix=/usr +cd src/python +PATH=~/Documents/protoc/bin:$PATH make +sudo /opt/core/venv/bin/python -m pip install . +``` + +## Package Install + +This section covers step by step commands that can be used to install CORE using +the package based installation path. This will require downloading a package from the release +page, to use during the install CORE step below. + +``` shell +# install system packages +sudo yum -y update +sudo yum install -y git sudo wget tzdata unzip libpcap-devel libpcre3-devel libxml2-devel \ + protobuf-devel unzip uuid-devel tcpdump automake gawk libreadline-devel libtool \ + pkg-config make +sudo yum-builddep -y python3 + +# install python3.9 +cd ~/Documents +wget https://www.python.org/ftp/python/3.9.15/Python-3.9.15.tgz +tar xf Python-3.9.15.tgz +cd Python-3.9.15 +./configure --enable-optimizations --with-ensurepip=install +sudo make -j$(nproc) altinstall +python3.9 -m pip install --upgrade pip + +# install core +cd ~/Documents +sudo PYTHON=python3.9 yum install -y ./core_*.rpm + +# install ospf mdr +cd ~/Documents +git clone https://github.com/USNavalResearchLaboratory/ospf-mdr.git +cd ospf-mdr +./bootstrap.sh +./configure --disable-doc --enable-user=root --enable-group=root \ + --with-cflags=-ggdb --sysconfdir=/usr/local/etc/quagga --enable-vtysh \ + --localstatedir=/var/run/quagga +make -j$(nproc) +sudo make install + +# install emane +cd ~/Documents +wget -q https://adjacentlink.com/downloads/emane/emane-1.3.3-release-1.el7.x86_64.tar.gz +tar xf emane-1.3.3-release-1.el7.x86_64.tar.gz +cd emane-1.3.3-release-1/rpms/el7/x86_64 +sudo yum install -y ./openstatistic*.rpm ./emane*.rpm ./python3-emane_*.rpm + +# install emane python bindings into CORE virtual environment +cd ~/Documents +wget https://github.com/protocolbuffers/protobuf/releases/download/v3.19.6/protoc-3.19.6-linux-x86_64.zip +mkdir protoc +unzip protoc-3.19.6-linux-x86_64.zip -d protoc +git clone https://github.com/adjacentlink/emane.git +cd emane +git checkout v1.3.3 +./autogen.sh +PYTHON=/opt/core/venv/bin/python ./configure --prefix=/usr +cd src/python +PATH=~/Documents/protoc/bin:$PATH make +sudo /opt/core/venv/bin/python -m pip install . +``` + +## Setup PATH + +The CORE virtual environment and related scripts will not be found on your PATH, +so some adjustments needs to be made. + +To add support for your user to run scripts from the virtual environment: + +```shell +# can add to ~/.bashrc +export PATH=$PATH:/opt/core/venv/bin +``` + +This will not solve the path issue when running as sudo, so you can do either +of the following to compensate. + +```shell +# run command passing in the right PATH to pickup from the user running the command +sudo env PATH=$PATH core-daemon + +# add an alias to ~/.bashrc or something similar +alias sudop='sudo env PATH=$PATH' +# now you can run commands like so +sudop core-daemon +``` diff --git a/docs/install_ubuntu.md b/docs/install_ubuntu.md new file mode 100644 index 00000000..57274a4f --- /dev/null +++ b/docs/install_ubuntu.md @@ -0,0 +1,116 @@ +# Install Ubuntu + +## Overview + +Below is a detailed path for installing CORE and related tooling on a fresh +Ubuntu 22.04 installation. Both of the examples below will install CORE into its +own virtual environment located at **/opt/core/venv**. Both examples below +also assume using **~/Documents** as the working directory. + +## Script Install + +This section covers step by step commands that can be used to install CORE using +the script based installation path. + +``` shell +# install system packages +sudo apt-get update -y +sudo apt-get install -y ca-certificates git sudo wget tzdata libpcap-dev libpcre3-dev \ + libprotobuf-dev libxml2-dev protobuf-compiler unzip uuid-dev iproute2 iputils-ping \ + tcpdump + +# install core +cd ~/Documents +git clone https://github.com/coreemu/core +cd core +./setup.sh +source ~/.bashrc +inv install + +# install emane +cd ~/Documents +wget https://github.com/protocolbuffers/protobuf/releases/download/v3.19.6/protoc-3.19.6-linux-x86_64.zip +mkdir protoc +unzip protoc-3.19.6-linux-x86_64.zip -d protoc +git clone https://github.com/adjacentlink/emane.git +cd emane +./autogen.sh +./configure --prefix=/usr +make -j$(nproc) +sudo make install +cd src/python +make clean +PATH=~/Documents/protoc/bin:$PATH make +sudo /opt/core/venv/bin/python -m pip install . +``` + +## Package Install + +This section covers step by step commands that can be used to install CORE using +the package based installation path. This will require downloading a package from the release +page, to use during the install CORE step below. + +``` shell +# install system packages +sudo apt-get update -y +sudo apt-get install -y ca-certificates python3 python3-tk python3-pip python3-venv \ + libpcap-dev libpcre3-dev libprotobuf-dev libxml2-dev protobuf-compiler unzip \ + uuid-dev automake gawk git wget libreadline-dev libtool pkg-config g++ make \ + iputils-ping tcpdump + +# install core +cd ~/Documents +sudo apt-get install -y ./core_*.deb + +# install ospf mdr +cd ~/Documents +git clone https://github.com/USNavalResearchLaboratory/ospf-mdr.git +cd ospf-mdr +./bootstrap.sh +./configure --disable-doc --enable-user=root --enable-group=root \ + --with-cflags=-ggdb --sysconfdir=/usr/local/etc/quagga --enable-vtysh \ + --localstatedir=/var/run/quagga +make -j$(nproc) +sudo make install + +# install emane +cd ~/Documents +wget https://github.com/protocolbuffers/protobuf/releases/download/v3.19.6/protoc-3.19.6-linux-x86_64.zip +mkdir protoc +unzip protoc-3.19.6-linux-x86_64.zip -d protoc +git clone https://github.com/adjacentlink/emane.git +cd emane +./autogen.sh +./configure --prefix=/usr +make -j$(nproc) +sudo make install +cd src/python +make clean +PATH=~/Documents/protoc/bin:$PATH make +sudo /opt/core/venv/bin/python -m pip install . +``` + +## Setup PATH + +The CORE virtual environment and related scripts will not be found on your PATH, +so some adjustments needs to be made. + +To add support for your user to run scripts from the virtual environment: + +```shell +# can add to ~/.bashrc +export PATH=$PATH:/opt/core/venv/bin +``` + +This will not solve the path issue when running as sudo, so you can do either +of the following to compensate. + +```shell +# run command passing in the right PATH to pickup from the user running the command +sudo env PATH=$PATH core-daemon + +# add an alias to ~/.bashrc or something similar +alias sudop='sudo env PATH=$PATH' +# now you can run commands like so +sudop core-daemon +``` diff --git a/docs/lxc.md b/docs/lxc.md index 0df9e9d0..1ee11453 100644 --- a/docs/lxc.md +++ b/docs/lxc.md @@ -1,5 +1,7 @@ # LXC Support +## Overview + LXC nodes are provided by way of LXD to create nodes using predefined images and provide file system separation. diff --git a/docs/nodetypes.md b/docs/nodetypes.md index ad8e3ff9..8f095746 100644 --- a/docs/nodetypes.md +++ b/docs/nodetypes.md @@ -1,7 +1,4 @@ -# CORE Node Types - -* Table of Contents -{:toc} +# Node Types ## Overview diff --git a/docs/performance.md b/docs/performance.md index 5c3ae3a0..449e3837 100644 --- a/docs/performance.md +++ b/docs/performance.md @@ -1,8 +1,5 @@ # CORE Performance -* Table of Contents -{:toc} - ## Overview The top question about the performance of CORE is often *how many nodes can it @@ -16,7 +13,6 @@ handle?* The answer depends on several factors: | Network traffic | the more packets that are sent around the virtual network increases the amount of CPU usage. | | GUI usage | widgets that run periodically, mobility scenarios, and other GUI interactions generally consume CPU cycles that may be needed for emulation. | - On a typical single-CPU Xeon 3.0GHz server machine with 2GB RAM running Linux, we have found it reasonable to run 30-75 nodes running OSPFv2 and OSPFv3 routing. On this hardware CORE can instantiate 100 or more nodes, but at @@ -32,15 +28,17 @@ the number of times the system as a whole needed to deal with a packet. As more network hops are added, this increases the number of context switches and decreases the throughput seen on the full length of the network path. -> **NOTE:** The right question to be asking is *"how much traffic?"*, not -*"how many nodes?"*. +!!! note + + The right question to be asking is *"how much traffic?"*, not + *"how many nodes?"*. For a more detailed study of performance in CORE, refer to the following publications: * J\. Ahrenholz, T. Goff, and B. Adamson, Integration of the CORE and EMANE - Network Emulators, Proceedings of the IEEE Military Communications Conference 2011, November 2011. + Network Emulators, Proceedings of the IEEE Military Communications Conference 2011, November 2011. * Ahrenholz, J., Comparison of CORE Network Emulation Platforms, Proceedings - of the IEEE Military Communications Conference 2010, pp. 864-869, November 2010. + of the IEEE Military Communications Conference 2010, pp. 864-869, November 2010. * J\. Ahrenholz, C. Danilov, T. Henderson, and J.H. Kim, CORE: A real-time - network emulator, Proceedings of IEEE MILCOM Conference, 2008. + network emulator, Proceedings of IEEE MILCOM Conference, 2008. diff --git a/docs/python.md b/docs/python.md index 733bf5b4..0985bb8d 100644 --- a/docs/python.md +++ b/docs/python.md @@ -1,8 +1,5 @@ # Python API -* Table of Contents - {:toc} - ## Overview Writing your own Python scripts offers a rich programming environment with diff --git a/docs/services.md b/docs/services.md index 7ff50c0e..9e6e3642 100644 --- a/docs/services.md +++ b/docs/services.md @@ -1,9 +1,6 @@ -# CORE Services +# Services (Deprecated) -* Table of Contents -{:toc} - -## Services +## Overview CORE uses the concept of services to specify what processes or scripts run on a node when it is started. Layer-3 nodes such as routers and PCs are defined by @@ -15,9 +12,11 @@ set of default services. Each service defines the per-node directories, configuration files, startup index, starting commands, validation commands, shutdown commands, and meta-data associated with a node. -> **NOTE:** **Network namespace nodes do not undergo the normal Linux boot process** - using the **init**, **upstart**, or **systemd** frameworks. These - lightweight nodes use configured CORE *services*. +!!! note + + **Network namespace nodes do not undergo the normal Linux boot process** + using the **init**, **upstart**, or **systemd** frameworks. These + lightweight nodes use configured CORE *services*. ## Available Services @@ -71,11 +70,13 @@ the service customization dialog for that service. The dialog has three tabs for configuring the different aspects of the service: files, directories, and startup/shutdown. -> **NOTE:** A **yellow** customize icon next to a service indicates that service - requires customization (e.g. the *Firewall* service). - A **green** customize icon indicates that a custom configuration exists. - Click the *Defaults* button when customizing a service to remove any - customizations. +!!! note + + A **yellow** customize icon next to a service indicates that service + requires customization (e.g. the *Firewall* service). + A **green** customize icon indicates that a custom configuration exists. + Click the *Defaults* button when customizing a service to remove any + customizations. The Files tab is used to display or edit the configuration files or scripts that are used for this service. Files can be selected from a drop-down list, and @@ -90,10 +91,11 @@ per-node directories that are defined by the services. For example, the the Zebra service, because Quagga running on each node needs to write separate PID files to that directory. -> **NOTE:** The **/var/log** and **/var/run** directories are - mounted uniquely per-node by default. - Per-node mount targets can be found in **/tmp/pycore.nnnnn/nN.conf/** - (where *nnnnn* is the session number and *N* is the node number.) +!!! note + + The **/var/log** and **/var/run** directories are + mounted uniquely per-node by default. + Per-node mount targets can be found in **/tmp/pycore./.conf/** The Startup/shutdown tab lists commands that are used to start and stop this service. The startup index allows configuring when this service starts relative @@ -120,8 +122,10 @@ if a process is running and return zero when found. When a validate command produces a non-zero return value, an exception is generated, which will cause an error to be displayed in the Check Emulation Light. -> **NOTE:** To start, stop, and restart services during run-time, right-click a - node and use the *Services...* menu. +!!! note + + To start, stop, and restart services during run-time, right-click a + node and use the *Services...* menu. ## New Services @@ -138,6 +142,12 @@ ideas for a service before adding a new service type. ### Creating New Services +!!! note + + The directory name used in **custom_services_dir** below should be unique and + should not correspond to any existing Python module name. For example, don't + use the name **subprocess** or **services**. + 1. Modify the example service shown below to do what you want. It could generate config/script files, mount per-node directories, start processes/scripts, etc. sample.py is a Python file that @@ -151,12 +161,6 @@ ideas for a service before adding a new service type. 3. Add a **custom_services_dir = `/home//.coregui/custom_services`** entry to the /etc/core/core.conf file. - **NOTE:** - The directory name used in **custom_services_dir** should be unique and - should not correspond to - any existing Python module name. For example, don't use the name **subprocess** - or **services**. - 4. Restart the CORE daemon (core-daemon). Any import errors (Python syntax) should be displayed in the daemon output. diff --git a/docs/services/bird.md b/docs/services/bird.md index 8fa7b895..db2f7701 100644 --- a/docs/services/bird.md +++ b/docs/services/bird.md @@ -1,8 +1,5 @@ # BIRD Internet Routing Daemon -* Table of Contents -{:toc} - ## Overview The [BIRD Internet Routing Daemon](https://bird.network.cz/) is a routing @@ -30,6 +27,7 @@ sudo apt-get install bird You can download BIRD source code from its [official repository.](https://gitlab.labs.nic.cz/labs/bird/) + ```shell ./configure make @@ -37,6 +35,7 @@ su make install vi /etc/bird/bird.conf ``` + The installation will place the bird directory inside */etc* where you will also find its config file. diff --git a/docs/services/emane.md b/docs/services/emane.md index 91a0f769..3f904091 100644 --- a/docs/services/emane.md +++ b/docs/services/emane.md @@ -1,8 +1,5 @@ # EMANE Services -* Table of Contents -{:toc} - ## Overview EMANE related services for CORE. diff --git a/docs/services/frr.md b/docs/services/frr.md index e69a9d1e..aa2db6ff 100644 --- a/docs/services/frr.md +++ b/docs/services/frr.md @@ -1,13 +1,14 @@ # FRRouting -* Table of Contents -{:toc} - ## Overview -FRRouting is a routing software package that provides TCP/IP based routing services with routing protocols support such as BGP, RIP, OSPF, IS-IS and more. FRR also supports special BGP Route Reflector and Route Server behavior. In addition to traditional IPv4 routing protocols, FRR also supports IPv6 routing protocols. With an SNMP daemon that supports the AgentX protocol, FRR provides routing protocol MIB read-only access (SNMP Support). +FRRouting is a routing software package that provides TCP/IP based routing services with routing protocols support such +as BGP, RIP, OSPF, IS-IS and more. FRR also supports special BGP Route Reflector and Route Server behavior. In addition +to traditional IPv4 routing protocols, FRR also supports IPv6 routing protocols. With an SNMP daemon that supports the +AgentX protocol, FRR provides routing protocol MIB read-only access (SNMP Support). FRR (as of v7.2) currently supports the following protocols: + * BGPv4 * OSPFv2 * OSPFv3 @@ -26,11 +27,13 @@ FRR (as of v7.2) currently supports the following protocols: ## FRRouting Package Install Ubuntu 19.10 and later + ```shell sudo apt update && sudo apt install frr ``` Ubuntu 16.04 and Ubuntu 18.04 + ```shell sudo apt install curl curl -s https://deb.frrouting.org/frr/keys.asc | sudo apt-key add - @@ -38,25 +41,35 @@ FRRVER="frr-stable" echo deb https://deb.frrouting.org/frr $(lsb_release -s -c) $FRRVER | sudo tee -a /etc/apt/sources.list.d/frr.list sudo apt update && sudo apt install frr frr-pythontools ``` + Fedora 31 + ```shell sudo dnf update && sudo dnf install frr ``` ## FRRouting Source Code Install -Building FRR from source is the best way to ensure you have the latest features and bug fixes. Details for each supported platform, including dependency package listings, permissions, and other gotchas, are in the developer’s documentation. +Building FRR from source is the best way to ensure you have the latest features and bug fixes. Details for each +supported platform, including dependency package listings, permissions, and other gotchas, are in the developer’s +documentation. FRR’s source is available on the project [GitHub page](https://github.com/FRRouting/frr). + ```shell git clone https://github.com/FRRouting/frr.git ``` Change into your FRR source directory and issue: + ```shell ./bootstrap.sh ``` -Then, choose the configuration options that you wish to use for the installation. You can find these options on FRR's [official webpage](http://docs.frrouting.org/en/latest/installation.html). Once you have chosen your configure options, run the configure script and pass the options you chose: + +Then, choose the configuration options that you wish to use for the installation. You can find these options on +FRR's [official webpage](http://docs.frrouting.org/en/latest/installation.html). Once you have chosen your configure +options, run the configure script and pass the options you chose: + ```shell ./configure \ --prefix=/usr \ @@ -68,8 +81,11 @@ Then, choose the configuration options that you wish to use for the installation --enable-watchfrr \ ... ``` + After configuring the software, you are ready to build and install it in your system. + ```shell make && sudo make install ``` + If everything finishes successfully, FRR should be installed. diff --git a/docs/services/nrl.md b/docs/services/nrl.md index c7e84920..da26ab25 100644 --- a/docs/services/nrl.md +++ b/docs/services/nrl.md @@ -1,13 +1,21 @@ # NRL Services -* Table of Contents -{:toc} - ## Overview -The Protean Protocol Prototyping Library (ProtoLib) is a cross-platform library that allows applications to be built while supporting a variety of platforms including Linux, Windows, WinCE/PocketPC, MacOS, FreeBSD, Solaris, etc as well as the simulation environments of NS2 and Opnet. The goal of the Protolib is to provide a set of simple, cross-platform C++ classes that allow development of network protocols and applications that can run on different platforms and in network simulation environments. While Protolib provides an overall framework for developing working protocol implementations, applications, and simulation modules, the individual classes are designed for use as stand-alone components when possible. Although Protolib is principally for research purposes, the code has been constructed to provide robust, efficient performance and adaptability to real applications. In some cases, the code consists of data structures, etc useful in protocol implementations and, in other cases, provides common, cross-platform interfaces to system services and functions (e.g., sockets, timers, routing tables, etc). +The Protean Protocol Prototyping Library (ProtoLib) is a cross-platform library that allows applications to be built +while supporting a variety of platforms including Linux, Windows, WinCE/PocketPC, MacOS, FreeBSD, Solaris, etc as well +as the simulation environments of NS2 and Opnet. The goal of the Protolib is to provide a set of simple, cross-platform +C++ classes that allow development of network protocols and applications that can run on different platforms and in +network simulation environments. While Protolib provides an overall framework for developing working protocol +implementations, applications, and simulation modules, the individual classes are designed for use as stand-alone +components when possible. Although Protolib is principally for research purposes, the code has been constructed to +provide robust, efficient performance and adaptability to real applications. In some cases, the code consists of data +structures, etc useful in protocol implementations and, in other cases, provides common, cross-platform interfaces to +system services and functions (e.g., sockets, timers, routing tables, etc). + +Currently, the Naval Research Laboratory uses this library to develop a wide variety of protocols.The NRL Protolib +currently supports the following protocols: -Currently the Naval Research Laboratory uses this library to develop a wide variety of protocols.The NRL Protolib currently supports the following protocols: * MGEN_Sink * NHDP * SMF @@ -19,11 +27,14 @@ Currently the Naval Research Laboratory uses this library to develop a wide vari ## NRL Installation -In order to be able to use the different protocols that NRL offers, you must first download the support library itself. You can get the source code from their [NRL Protolib Repo](https://github.com/USNavalResearchLaboratory/protolib). +In order to be able to use the different protocols that NRL offers, you must first download the support library itself. +You can get the source code from their [NRL Protolib Repo](https://github.com/USNavalResearchLaboratory/protolib). ## Multi-Generator (MGEN) -Download MGEN from the [NRL MGEN Repo](https://github.com/USNavalResearchLaboratory/mgen), unpack it and copy the protolib library into the main folder *mgen*. Execute the following commands to build the protocol. +Download MGEN from the [NRL MGEN Repo](https://github.com/USNavalResearchLaboratory/mgen), unpack it and copy the +protolib library into the main folder *mgen*. Execute the following commands to build the protocol. + ```shell cd mgen/makefiles make -f Makefile.{os} mgen @@ -32,16 +43,22 @@ make -f Makefile.{os} mgen ## Neighborhood Discovery Protocol (NHDP) Download NHDP from the [NRL NHDP Repo](https://github.com/USNavalResearchLaboratory/NCS-Downloads/tree/master/nhdp). + ```shell sudo apt-get install libpcap-dev libboost-all-dev wget https://github.com/protocolbuffers/protobuf/releases/download/v3.8.0/protoc-3.8.0-linux-x86_64.zip unzip protoc-3.8.0-linux-x86_64.zip ``` + Then place the binaries in your $PATH. To know your paths you can issue the following command + ```shell echo $PATH ``` -Go to the downloaded *NHDP* tarball, unpack it and place the protolib library inside the NHDP main folder. Now, compile the NHDP Protocol. + +Go to the downloaded *NHDP* tarball, unpack it and place the protolib library inside the NHDP main folder. Now, compile +the NHDP Protocol. + ```shell cd nhdp/unix make -f Makefile.{os} @@ -49,7 +66,9 @@ make -f Makefile.{os} ## Simplified Multicast Forwarding (SMF) -Download SMF from the [NRL SMF Repo](https://github.com/USNavalResearchLaboratory/nrlsmf) , unpack it and place the protolib library inside the *smf* main folder. +Download SMF from the [NRL SMF Repo](https://github.com/USNavalResearchLaboratory/nrlsmf) , unpack it and place the +protolib library inside the *smf* main folder. + ```shell cd mgen/makefiles make -f Makefile.{os} @@ -57,7 +76,10 @@ make -f Makefile.{os} ## Optimized Link State Routing Protocol (OLSR) -To install the OLSR protocol, download their source code from their [NRL OLSR Repo](https://github.com/USNavalResearchLaboratory/nrlolsr). Unpack it and place the previously downloaded protolib library inside the *nrlolsr* main directory. Then execute the following commands: +To install the OLSR protocol, download their source code from +their [NRL OLSR Repo](https://github.com/USNavalResearchLaboratory/nrlolsr). Unpack it and place the previously +downloaded protolib library inside the *nrlolsr* main directory. Then execute the following commands: + ```shell cd ./unix make -f Makefile.{os} diff --git a/docs/services/quagga.md b/docs/services/quagga.md index d894d431..6842b5e7 100644 --- a/docs/services/quagga.md +++ b/docs/services/quagga.md @@ -1,12 +1,13 @@ # Quagga Routing Suite -* Table of Contents -{:toc} - ## Overview - Quagga is a routing software suite, providing implementations of OSPFv2, OSPFv3, RIP v1 and v2, RIPng and BGP-4 for Unix platforms, particularly FreeBSD, Linux, Solaris and NetBSD. Quagga is a fork of GNU Zebra which was developed by Kunihiro Ishiguro. -The Quagga architecture consists of a core daemon, zebra, which acts as an abstraction layer to the underlying Unix kernel and presents the Zserv API over a Unix or TCP stream to Quagga clients. It is these Zserv clients which typically implement a routing protocol and communicate routing updates to the zebra daemon. +Quagga is a routing software suite, providing implementations of OSPFv2, OSPFv3, RIP v1 and v2, RIPng and BGP-4 for Unix +platforms, particularly FreeBSD, Linux, Solaris and NetBSD. Quagga is a fork of GNU Zebra which was developed by +Kunihiro Ishiguro. +The Quagga architecture consists of a core daemon, zebra, which acts as an abstraction layer to the underlying Unix +kernel and presents the Zserv API over a Unix or TCP stream to Quagga clients. It is these Zserv clients which typically +implement a routing protocol and communicate routing updates to the zebra daemon. ## Quagga Package Install @@ -17,10 +18,13 @@ sudo apt-get install quagga ## Quagga Source Install First, download the source code from their [official webpage](https://www.quagga.net/). + ```shell sudo apt-get install gawk ``` + Extract the tarball, go to the directory of your currently extracted code and issue the following commands. + ```shell ./configure make diff --git a/docs/services/sdn.md b/docs/services/sdn.md index 9381fef5..05e8606e 100644 --- a/docs/services/sdn.md +++ b/docs/services/sdn.md @@ -1,11 +1,11 @@ # Software Defined Networking -* Table of Contents -{:toc} - ## Overview -Ryu is a component-based software defined networking framework. Ryu provides software components with well defined API that make it easy for developers to create new network management and control applications. Ryu supports various protocols for managing network devices, such as OpenFlow, Netconf, OF-config, etc. About OpenFlow, Ryu supports fully 1.0, 1.2, 1.3, 1.4, 1.5 and Nicira Extensions. All of the code is freely available under the Apache 2.0 license. +Ryu is a component-based software defined networking framework. Ryu provides software components with well defined API +that make it easy for developers to create new network management and control applications. Ryu supports various +protocols for managing network devices, such as OpenFlow, Netconf, OF-config, etc. About OpenFlow, Ryu supports fully +1.0, 1.2, 1.3, 1.4, 1.5 and Nicira Extensions. All of the code is freely available under the Apache 2.0 license. ## Installation diff --git a/docs/services/security.md b/docs/services/security.md index c8856e13..a621009d 100644 --- a/docs/services/security.md +++ b/docs/services/security.md @@ -1,15 +1,15 @@ # Security Services -* Table of Contents -{:toc} - ## Overview -The security services offer a wide variety of protocols capable of satisfying the most use cases available. Security services such as IP security protocols, for providing security at the IP layer, as well as the suite of protocols designed to provide that security, through authentication and encryption of IP network packets. Virtual Private Networks (VPNs) and Firewalls are also available for use to the user. +The security services offer a wide variety of protocols capable of satisfying the most use cases available. Security +services such as IP security protocols, for providing security at the IP layer, as well as the suite of protocols +designed to provide that security, through authentication and encryption of IP network packets. Virtual Private +Networks (VPNs) and Firewalls are also available for use to the user. ## Installation -Libraries needed for some of the security services. +Libraries needed for some security services. ```shell sudo apt-get install ipsec-tools racoon @@ -71,7 +71,9 @@ sudo cp pki/dh.pem $KEYDIR/dh1024.pem Add VPNServer service to nodes desired for running an OpenVPN server. -Modify [sampleVPNServer](https://github.com/coreemu/core/blob/master/package/examples/services/sampleVPNServer) for the following +Modify [sampleVPNServer](https://github.com/coreemu/core/blob/master/package/examples/services/sampleVPNServer) for the +following + * Edit keydir key/cert directory * Edit keyname to use generated server name above * Edit vpnserver to match an address that the server node will have @@ -80,7 +82,9 @@ Modify [sampleVPNServer](https://github.com/coreemu/core/blob/master/package/exa Add VPNClient service to nodes desired for acting as an OpenVPN client. -Modify [sampleVPNClient](https://github.com/coreemu/core/blob/master/package/examples/services/sampleVPNClient) for the following +Modify [sampleVPNClient](https://github.com/coreemu/core/blob/master/package/examples/services/sampleVPNClient) for the +following + * Edit keydir key/cert directory * Edit keyname to use generated client name above * Edit vpnserver to match the address a server was configured to use diff --git a/docs/services/utility.md b/docs/services/utility.md index b2fa87b8..698de4f8 100644 --- a/docs/services/utility.md +++ b/docs/services/utility.md @@ -1,13 +1,11 @@ # Utility Services -* Table of Contents -{:toc} - -# Overview +## Overview Variety of convenience services for carrying out common networking changes. The following services are provided as utilities: + * UCARP * IP Forward * Default Routing @@ -25,15 +23,19 @@ The following services are provided as utilities: ## Installation To install the functionality of the previously metioned services you can run the following command: + ```shell sudo apt-get install isc-dhcp-server apache2 libpcap-dev radvd at ``` ## UCARP -UCARP allows a couple of hosts to share common virtual IP addresses in order to provide automatic failover. It is a portable userland implementation of the secure and patent-free Common Address Redundancy Protocol (CARP, OpenBSD's alternative to the patents-bloated VRRP). +UCARP allows a couple of hosts to share common virtual IP addresses in order to provide automatic failover. It is a +portable userland implementation of the secure and patent-free Common Address Redundancy Protocol (CARP, OpenBSD's +alternative to the patents-bloated VRRP). -Strong points of the CARP protocol are: very low overhead, cryptographically signed messages, interoperability between different operating systems and no need for any dedicated extra network link between redundant hosts. +Strong points of the CARP protocol are: very low overhead, cryptographically signed messages, interoperability between +different operating systems and no need for any dedicated extra network link between redundant hosts. ### Installation diff --git a/docs/services/xorp.md b/docs/services/xorp.md index 6b786964..a9bd108d 100644 --- a/docs/services/xorp.md +++ b/docs/services/xorp.md @@ -1,36 +1,48 @@ # XORP routing suite -* Table of Contents -{:toc} - ## Overview -XORP is an open networking platform that supports OSPF, RIP, BGP, OLSR, VRRP, PIM, IGMP (Multicast) and other routing protocols. Most protocols support IPv4 and IPv6 where applicable. It is known to work on various Linux distributions and flavors of BSD. +XORP is an open networking platform that supports OSPF, RIP, BGP, OLSR, VRRP, PIM, IGMP (Multicast) and other routing +protocols. Most protocols support IPv4 and IPv6 where applicable. It is known to work on various Linux distributions and +flavors of BSD. -XORP started life as a project at the ICSI Center for Open Networking (ICON) at the International Computer Science Institute in Berkeley, California, USA, and spent some time with the team at XORP, Inc. It is now maintained and improved on a volunteer basis by a core of long-term XORP developers and some newer contributors. +XORP started life as a project at the ICSI Center for Open Networking (ICON) at the International Computer Science +Institute in Berkeley, California, USA, and spent some time with the team at XORP, Inc. It is now maintained and +improved on a volunteer basis by a core of long-term XORP developers and some newer contributors. -XORP's primary goal is to be an open platform for networking protocol implementations and an alternative to proprietary and closed networking products in the marketplace today. It is the only open source platform to offer integrated multicast capability. +XORP's primary goal is to be an open platform for networking protocol implementations and an alternative to proprietary +and closed networking products in the marketplace today. It is the only open source platform to offer integrated +multicast capability. XORP design philosophy is: - * modularity - * extensibility - * performance - * robustness -This is achieved by carefully separating functionalities into independent modules, and by providing an API for each module. -XORP divides into two subsystems. The higher-level ("user-level") subsystem consists of the routing protocols. The lower-level ("kernel") manages the forwarding path, and provides APIs for the higher-level to access. +* modularity +* extensibility +* performance +* robustness + This is achieved by carefully separating functionalities into independent modules, and by providing an API for each + module. -User-level XORP uses multi-process architecture with one process per routing protocol, and a novel inter-process communication mechanism called XRL (XORP Resource Locator). +XORP divides into two subsystems. The higher-level ("user-level") subsystem consists of the routing protocols. The +lower-level ("kernel") manages the forwarding path, and provides APIs for the higher-level to access. -The lower-level subsystem can use traditional UNIX kernel forwarding, or Click modular router. The modularity and independency of the lower-level from the user-level subsystem allows for its easily replacement with other solutions including high-end hardware-based forwarding engines. +User-level XORP uses multi-process architecture with one process per routing protocol, and a novel inter-process +communication mechanism called XRL (XORP Resource Locator). + +The lower-level subsystem can use traditional UNIX kernel forwarding, or Click modular router. The modularity and +independency of the lower-level from the user-level subsystem allows for its easily replacement with other solutions +including high-end hardware-based forwarding engines. ## Installation In order to be able to install the XORP Routing Suite, you must first install scons in order to compile it. + ```shell sudo apt-get install scons ``` + Then, download XORP from its official [release web page](http://www.xorp.org/releases/current/). + ```shell http://www.xorp.org/releases/current/ cd xorp diff --git a/docs/static/tutorial-common/running-join.png b/docs/static/tutorial-common/running-join.png new file mode 100644 index 00000000..30fbcb80 Binary files /dev/null and b/docs/static/tutorial-common/running-join.png differ diff --git a/docs/static/tutorial-common/running-open.png b/docs/static/tutorial-common/running-open.png new file mode 100644 index 00000000..7e3e722c Binary files /dev/null and b/docs/static/tutorial-common/running-open.png differ diff --git a/docs/static/tutorial1/link-config-dialog.png b/docs/static/tutorial1/link-config-dialog.png new file mode 100644 index 00000000..73d4ed2d Binary files /dev/null and b/docs/static/tutorial1/link-config-dialog.png differ diff --git a/docs/static/tutorial1/link-config.png b/docs/static/tutorial1/link-config.png new file mode 100644 index 00000000..35f45327 Binary files /dev/null and b/docs/static/tutorial1/link-config.png differ diff --git a/docs/static/tutorial1/scenario.png b/docs/static/tutorial1/scenario.png new file mode 100644 index 00000000..c1a2dfc7 Binary files /dev/null and b/docs/static/tutorial1/scenario.png differ diff --git a/docs/static/tutorial2/wireless-config-delay.png b/docs/static/tutorial2/wireless-config-delay.png new file mode 100644 index 00000000..b375af76 Binary files /dev/null and b/docs/static/tutorial2/wireless-config-delay.png differ diff --git a/docs/static/tutorial2/wireless-configuration.png b/docs/static/tutorial2/wireless-configuration.png new file mode 100644 index 00000000..9b87959c Binary files /dev/null and b/docs/static/tutorial2/wireless-configuration.png differ diff --git a/docs/static/tutorial2/wireless.png b/docs/static/tutorial2/wireless.png new file mode 100644 index 00000000..8543117d Binary files /dev/null and b/docs/static/tutorial2/wireless.png differ diff --git a/docs/static/tutorial3/mobility-script.png b/docs/static/tutorial3/mobility-script.png new file mode 100644 index 00000000..6f32e5b1 Binary files /dev/null and b/docs/static/tutorial3/mobility-script.png differ diff --git a/docs/static/tutorial3/motion_continued_breaks_link.png b/docs/static/tutorial3/motion_continued_breaks_link.png new file mode 100644 index 00000000..cc1f5dcd Binary files /dev/null and b/docs/static/tutorial3/motion_continued_breaks_link.png differ diff --git a/docs/static/tutorial3/motion_from_ns2_file.png b/docs/static/tutorial3/motion_from_ns2_file.png new file mode 100644 index 00000000..704cc1d9 Binary files /dev/null and b/docs/static/tutorial3/motion_from_ns2_file.png differ diff --git a/docs/static/tutorial3/move-n2.png b/docs/static/tutorial3/move-n2.png new file mode 100644 index 00000000..befcd4b0 Binary files /dev/null and b/docs/static/tutorial3/move-n2.png differ diff --git a/docs/static/tutorial5/VM-network-settings.png b/docs/static/tutorial5/VM-network-settings.png new file mode 100644 index 00000000..5d47738e Binary files /dev/null and b/docs/static/tutorial5/VM-network-settings.png differ diff --git a/docs/static/tutorial5/configure-the-rj45.png b/docs/static/tutorial5/configure-the-rj45.png new file mode 100644 index 00000000..0e2b8f8b Binary files /dev/null and b/docs/static/tutorial5/configure-the-rj45.png differ diff --git a/docs/static/tutorial5/rj45-connector.png b/docs/static/tutorial5/rj45-connector.png new file mode 100644 index 00000000..8c8e86ef Binary files /dev/null and b/docs/static/tutorial5/rj45-connector.png differ diff --git a/docs/static/tutorial5/rj45-unassigned.png b/docs/static/tutorial5/rj45-unassigned.png new file mode 100644 index 00000000..eda4a3b6 Binary files /dev/null and b/docs/static/tutorial5/rj45-unassigned.png differ diff --git a/docs/static/tutorial6/configure-icon.png b/docs/static/tutorial6/configure-icon.png new file mode 100644 index 00000000..52a9e2e8 Binary files /dev/null and b/docs/static/tutorial6/configure-icon.png differ diff --git a/docs/static/tutorial6/create-nodes.png b/docs/static/tutorial6/create-nodes.png new file mode 100644 index 00000000..38257e24 Binary files /dev/null and b/docs/static/tutorial6/create-nodes.png differ diff --git a/docs/static/tutorial6/hidden-nodes.png b/docs/static/tutorial6/hidden-nodes.png new file mode 100644 index 00000000..604829dd Binary files /dev/null and b/docs/static/tutorial6/hidden-nodes.png differ diff --git a/docs/static/tutorial6/linked-nodes.png b/docs/static/tutorial6/linked-nodes.png new file mode 100644 index 00000000..8e75007e Binary files /dev/null and b/docs/static/tutorial6/linked-nodes.png differ diff --git a/docs/static/tutorial6/only-node1-moving.png b/docs/static/tutorial6/only-node1-moving.png new file mode 100644 index 00000000..01ac2ebd Binary files /dev/null and b/docs/static/tutorial6/only-node1-moving.png differ diff --git a/docs/static/tutorial6/scenario-with-motion.png b/docs/static/tutorial6/scenario-with-motion.png new file mode 100644 index 00000000..e30e781c Binary files /dev/null and b/docs/static/tutorial6/scenario-with-motion.png differ diff --git a/docs/static/tutorial6/scenario-with-terrain.png b/docs/static/tutorial6/scenario-with-terrain.png new file mode 100644 index 00000000..db424e9b Binary files /dev/null and b/docs/static/tutorial6/scenario-with-terrain.png differ diff --git a/docs/static/tutorial6/select-wallpaper.png b/docs/static/tutorial6/select-wallpaper.png new file mode 100644 index 00000000..41d40f57 Binary files /dev/null and b/docs/static/tutorial6/select-wallpaper.png differ diff --git a/docs/static/tutorial6/wlan-links.png b/docs/static/tutorial6/wlan-links.png new file mode 100644 index 00000000..ab6c152d Binary files /dev/null and b/docs/static/tutorial6/wlan-links.png differ diff --git a/docs/static/tutorial7/scenario.png b/docs/static/tutorial7/scenario.png new file mode 100644 index 00000000..1c677aa3 Binary files /dev/null and b/docs/static/tutorial7/scenario.png differ diff --git a/docs/tutorials/common/grpc.md b/docs/tutorials/common/grpc.md new file mode 100644 index 00000000..71630d38 --- /dev/null +++ b/docs/tutorials/common/grpc.md @@ -0,0 +1,22 @@ +## gRPC Python Scripts + +You can also run the same steps above, using the provided gRPC script versions of scenarios. +Below are the steps to run and join one of these scenario, then you can continue with +the remaining steps of a given section. + +1. Make sure the CORE daemon is running a terminal, if not already + ``` shell + sudop core-daemon + ``` +2. From another terminal run the tutorial python script, which will create a session to join + ``` shell + /opt/core/venv/bin/python scenario.py + ``` +3. In another terminal run the CORE GUI + ``` shell + core-gui + ``` +4. You will be presented with sessions to join, select the one created by the script +

    + +

    diff --git a/docs/tutorials/overview.md b/docs/tutorials/overview.md new file mode 100644 index 00000000..6ec0d275 --- /dev/null +++ b/docs/tutorials/overview.md @@ -0,0 +1,29 @@ +# CORE Tutorials + +These tutorials will cover various use cases within CORE. These +tutorials will provide example python, gRPC, XML, and related files, as well +as an explanation for their usage and purpose. + +## Checklist + +These are the items you should become familiar with for running all the tutorials below. + +* [Install CORE](../install.md) +* [Tutorial Setup](setup.md) + +## Tutorials + +* [Tutorial 1 - Wired Network](tutorial1.md) + * Covers interactions when using a simple 2 node wired network +* [Tutorial 2 - Wireless Network](tutorial2.md) + * Covers interactions when using a simple 3 node wireless network +* [Tutorial 3 - Basic Mobility](tutorial3.md) + * Covers mobility interactions when using a simple 3 node wireless network +* [Tutorial 4 - Tests](tutorial4.md) + * Covers automating scenarios as tests to validate software +* [Tutorial 5 - RJ45 Node](tutorial5.md) + * Covers using the RJ45 node to connect a Windows OS +* [Tutorial 6 - Improve Visuals](tutorial6.md) + * Covers changing the look of a scenario within the CORE GUI +* [Tutorial 7 - EMANE](tutorial7.md) + * Covers using EMANE within CORE for higher fidelity RF networks diff --git a/docs/tutorials/setup.md b/docs/tutorials/setup.md new file mode 100644 index 00000000..858b0f1d --- /dev/null +++ b/docs/tutorials/setup.md @@ -0,0 +1,82 @@ +# Tutorial Setup + +## Setup for CORE + +We assume the prior installation of CORE, using a virtual environment. You can +then adjust your PATH and add an alias to help more conveniently run CORE +commands. + +This can be setup in your **.bashrc** + +```shell +export PATH=$PATH:/opt/core/venv/bin +alias sudop='sudo env PATH=$PATH' +``` + +## Setup for Chat App + +There is a simple TCP chat app provided as example software to use and run within +the tutorials provided. + +### Installation + +The following will install chatapp and its scripts into **/usr/local**, which you +may need to add to PATH within node to be able to use command directly. + +``` shell +sudo python3 -m pip install . +``` + +!!! note + + Some Linux distros will not have **/usr/local** in their PATH and you + will need to compensate. + +``` shell +export PATH=$PATH:/usr/local +``` + +### Running the Server + +The server will print and log connected clients and their messages. + +``` shell +usage: chatapp-server [-h] [-a ADDRESS] [-p PORT] + +chat app server + +optional arguments: + -h, --help show this help message and exit + -a ADDRESS, --address ADDRESS + address to listen on (default: ) + -p PORT, --port PORT port to listen on (default: 9001) +``` + +### Running the Client + +The client will print and log messages from other clients and their join/leave status. + +``` shell +usage: chatapp-client [-h] -a ADDRESS [-p PORT] + +chat app client + +optional arguments: + -h, --help show this help message and exit + -a ADDRESS, --address ADDRESS + address to listen on (default: None) + -p PORT, --port PORT port to listen on (default: 9001) +``` + +### Installing the Chat App Service + +1. You will first need to edit **/etc/core/core.conf** to update the config + service path to pick up your service + ``` shell + custom_config_services_dir = + ``` +2. Then you will need to copy/move **chatapp/chatapp_service.py** to the directory + configured above +3. Then you will need to restart the **core-daemon** to pick up this new service +4. Now the service will be an available option under the group **ChatApp** with + the name **ChatApp Server** diff --git a/docs/tutorials/tutorial1.md b/docs/tutorials/tutorial1.md new file mode 100644 index 00000000..75f13c7c --- /dev/null +++ b/docs/tutorials/tutorial1.md @@ -0,0 +1,252 @@ +# Tutorial 1 - Wired Network + +## Overview + +This tutorial will cover some use cases when using a wired 2 node +scenario in CORE. + +

    + +

    + +## Files + +Below is the list of files used for this tutorial. + +* 2 node wired scenario + * scenario.xml + * scenario.py +* 2 node wired scenario, with **n1** running the "Chat App Server" service + * scenario_service.xml + * scenario_service.py + +## Running this Tutorial + +This section covers interactions that can be carried out for this scenario. + +Our scenario has the following nodes and addresses: + +* n1 - 10.0.0.20 +* n2 - 10.0.0.21 + +All usages below assume a clean scenario start. + +### Using Ping + +Using the command line utility **ping** can be a good way to verify connectivity +between nodes in CORE. + +* Make sure the CORE daemon is running a terminal, if not already + ``` shell + sudop core-daemon + ``` +* In another terminal run the GUI + ``` shell + core-gui + ``` +* In the GUI menu bar select **File->Open...**, then navigate to and select **scenario.xml** +

    + +

    +* You can now click on the **Start Session** button to run the scenario +

    + +

    +* Open a terminal on **n1** by double clicking it in the GUI +* Run the following in **n1** terminal + ``` shell + ping -c 3 10.0.0.21 + ``` +* You should see the following output + ``` shell + PING 10.0.0.21 (10.0.0.21) 56(84) bytes of data. + 64 bytes from 10.0.0.21: icmp_seq=1 ttl=64 time=0.085 ms + 64 bytes from 10.0.0.21: icmp_seq=2 ttl=64 time=0.079 ms + 64 bytes from 10.0.0.21: icmp_seq=3 ttl=64 time=0.072 ms + + --- 10.0.0.21 ping statistics --- + 3 packets transmitted, 3 received, 0% packet loss, time 1999ms + rtt min/avg/max/mdev = 0.072/0.078/0.085/0.011 ms + ``` + +### Using Tcpdump + +Using **tcpdump** can be very beneficial for examining a network. You can verify +traffic being sent/received among many other uses. + +* Make sure the CORE daemon is running a terminal, if not already + ``` shell + sudop core-daemon + ``` +* In another terminal run the GUI + ``` shell + core-gui + ``` +* In the GUI menu bar select **File->Open...**, then navigate to and select **scenario.xml** +

    + +

    +* You can now click on the **Start Session** button to run the scenario +

    + +

    +* Open a terminal on **n1** by double clicking it in the GUI +* Open a terminal on **n2** by double clicking it in the GUI +* Run the following in **n2** terminal + ``` shell + tcpdump -lenni eth0 + ``` +* Run the following in **n1** terminal + ``` shell + ping -c 1 10.0.0.21 + ``` +* You should see the following in **n2** terminal + ``` shell + tcpdump: verbose output suppressed, use -v or -vv for full protocol decode + listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes + 10:23:04.685292 00:00:00:aa:00:00 > 00:00:00:aa:00:01, ethertype IPv4 (0x0800), length 98: 10.0.0.20 > 10.0.0.21: ICMP echo request, id 67, seq 1, length 64 + 10:23:04.685329 00:00:00:aa:00:01 > 00:00:00:aa:00:00, ethertype IPv4 (0x0800), length 98: 10.0.0.21 > 10.0.0.20: ICMP echo reply, id 67, seq 1, length 64 + ``` + +### Editing a Link + +You can edit links between nodes in CORE to modify loss, delay, bandwidth, and more. This can be +beneficial for understanding how software will behave in adverse conditions. + +* Make sure the CORE daemon is running a terminal, if not already + ``` shell + sudop core-daemon + ``` +* In another terminal run the GUI + ``` shell + core-gui + ``` +* In the GUI menu bar select **File->Open...**, then navigate to and select **scenario.xml** +

    + +

    +* You can now click on the **Start Session** button to run the scenario +

    + +

    +* Right click the link between **n1** and **n2** +* Select **Configure** +

    + +

    +* Update the loss to **25** +

    + +

    +* Open a terminal on **n1** by double clicking it in the GUI +* Run the following in **n1** terminal + ``` shell + ping -c 10 10.0.0.21 + ``` +* You should see something similar for the summary output, reflecting the change in loss + ``` shell + --- 10.0.0.21 ping statistics --- + 10 packets transmitted, 6 received, 40% packet loss, time 9000ms + rtt min/avg/max/mdev = 0.077/0.093/0.108/0.016 ms + ``` +* Remember that the loss above is compounded, since a ping and the loss applied occurs in both directions + +### Running Software + +We will now leverage the installed Chat App software to stand up a server and client +within the nodes of our scenario. + +* Make sure the CORE daemon is running a terminal, if not already + ``` shell + sudop core-daemon + ``` +* In another terminal run the GUI + ``` shell + core-gui + ``` +* In the GUI menu bar select **File->Open...**, then navigate to and select **scenario.xml** +

    + +

    +* You can now click on the **Start Session** button to run the scenario +

    + +

    +* Open a terminal on **n1** by double clicking it in the GUI +* Run the following in **n1** terminal + ``` shell + export PATH=$PATH:/usr/local/bin + chatapp-server + ``` +* Open a terminal on **n2** by double clicking it in the GUI +* Run the following in **n2** terminal + ``` shell + export PATH=$PATH:/usr/local/bin + chatapp-client -a 10.0.0.20 + ``` +* You will see the following output in **n1** terminal + ``` shell + chat server listening on: :9001 + [server] 10.0.0.21:44362 joining + ``` +* Type the following in **n2** terminal and hit enter + ``` shell + hello world + ``` +* You will see the following output in **n1** terminal + ``` shell + chat server listening on: :9001 + [server] 10.0.0.21:44362 joining + [10.0.0.21:44362] hello world + ``` + +### Tailing a Log + +In this case we are using the service based scenario. This will automatically start +and run the Chat App Server on **n1** and log to a file. This case will demonstrate +using `tail -f` to observe the output of running software. + +* Make sure the CORE daemon is running a terminal, if not already + ``` shell + sudop core-daemon + ``` +* In another terminal run the GUI + ``` shell + core-gui + ``` +* In the GUI menu bar select **File->Open...**, then navigate to and select **scenario_service.xml** +

    + +

    +* You can now click on the **Start Session** button to run the scenario +

    + +

    +* Open a terminal on **n1** by double clicking it in the GUI +* Run the following in **n1** terminal + ``` shell + tail -f chatapp.log + ``` +* Open a terminal on **n2** by double clicking it in the GUI +* Run the following in **n2** terminal + ``` shell + export PATH=$PATH:/usr/local/bin + chatapp-client -a 10.0.0.20 + ``` +* You will see the following output in **n1** terminal + ``` shell + chat server listening on: :9001 + [server] 10.0.0.21:44362 joining + ``` +* Type the following in **n2** terminal and hit enter + ``` shell + hello world + ``` +* You will see the following output in **n1** terminal + ``` shell + chat server listening on: :9001 + [server] 10.0.0.21:44362 joining + [10.0.0.21:44362] hello world + ``` + +--8<-- "tutorials/common/grpc.md" diff --git a/docs/tutorials/tutorial2.md b/docs/tutorials/tutorial2.md new file mode 100644 index 00000000..5455917b --- /dev/null +++ b/docs/tutorials/tutorial2.md @@ -0,0 +1,145 @@ +# Tutorial 2 - Wireless Network + +## Overview + +This tutorial will cover the use of a 3 node scenario in CORE. Then +running a chat server on one node and a chat client on the other. The client will +send a simple message and the server will log receipt of the message. + +## Files + +Below is the list of files used for this tutorial. + +* scenario.xml - 3 node CORE xml scenario file (wireless) +* scenario.py - 3 node CORE gRPC python script (wireless) + +## Running with the XML Scenario File + +This section will cover running this sample tutorial using the +XML scenario file, leveraging an NS2 mobility file. + +* Make sure the **core-daemon** is running a terminal + ```shell + sudop core-daemon + ``` +* In another terminal run the GUI + ```shell + core-gui + ``` +* In the GUI menu bar select **File->Open...** +* Navigate to and select this tutorials **scenario.xml** file +* You can now click play to start the session +

    + +

    +* Note that OSPF routing protocol is included in the scenario to provide routes to other nodes, as they are discovered +* Double click node **n4** to open a terminal and ping node **n2** + ```shell + ping -c 2 10.0.0.2 + PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data. + 64 bytes from 10.0.0.2: icmp_seq=1 ttl=63 time=20.2 ms + 64 bytes from 10.0.0.2: icmp_seq=2 ttl=63 time=20.2 ms + + --- 10.0.0.2 ping statistics --- + 2 packets transmitted, 2 received, 0% packet loss, time 1000ms + rtt min/avg/max/mdev = 20.168/20.173/20.178/0.005 ms + ``` + +### Configuring Delay + +* Right click on the **wlan1** node and select **WLAN Config**, then set delay to 500000 +

    + +

    +* Using the open terminal for node **n4**, ping **n2** again, expect about 2 seconds delay + ```shell + ping -c 5 10.0.0.2 + 64 bytes from 10.0.0.2: icmp_seq=1 ttl=63 time=2001 ms + 64 bytes from 10.0.0.2: icmp_seq=2 ttl=63 time=2000 ms + 64 bytes from 10.0.0.2: icmp_seq=3 ttl=63 time=2000 ms + 64 bytes from 10.0.0.2: icmp_seq=4 ttl=63 time=2000 ms + 64 bytes from 10.0.0.2: icmp_seq=5 ttl=63 time=2000 ms + + --- 10.0.0.2 ping statistics --- + 5 packets transmitted, 5 received, 0% packet loss, time 4024ms + rtt min/avg/max/mdev = 2000.176/2000.438/2001.166/0.376 ms, pipe 2 + ``` + +### Configure Loss + +* Right click on the **wlan1** node and select **WLAN Config**, set delay back to 5000 and loss to 10 +

    + +

    +* Using the open terminal for node **n4**, ping **n2** again, expect to notice considerable loss + ```shell + ping -c 10 10.0.0.2 + PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data. + 64 bytes from 10.0.0.2: icmp_seq=1 ttl=63 time=20.4 ms + 64 bytes from 10.0.0.2: icmp_seq=2 ttl=63 time=20.5 ms + 64 bytes from 10.0.0.2: icmp_seq=3 ttl=63 time=20.2 ms + 64 bytes from 10.0.0.2: icmp_seq=4 ttl=63 time=20.8 ms + 64 bytes from 10.0.0.2: icmp_seq=5 ttl=63 time=21.9 ms + 64 bytes from 10.0.0.2: icmp_seq=8 ttl=63 time=22.7 ms + 64 bytes from 10.0.0.2: icmp_seq=9 ttl=63 time=22.4 ms + 64 bytes from 10.0.0.2: icmp_seq=10 ttl=63 time=20.3 ms + + --- 10.0.0.2 ping statistics --- + 10 packets transmitted, 8 received, 20% packet loss, time 9064ms + rtt min/avg/max/mdev = 20.188/21.143/22.717/0.967 ms + ``` +* Make sure to set loss back to 0 when done + +## Running with the gRPC Python Script + +This section will cover running this sample tutorial using the +gRPC python script and providing mobility over the gRPC interface. + +* Make sure the **core-daemon** is running a terminal + ```shell + sudop core-daemon + ``` +* In another terminal run the GUI + ```shell + core-gui + ``` +* From another terminal run the **scenario.py** script + ```shell + /opt/core/venv/bin/python scenario.py + ``` +* In the GUI dialog box select the session and click connect +* You will now have joined the already running scenario + +

    + +

    + +## Running Software + +We will now leverage the installed Chat App software to stand up a server and client +within the nodes of our scenario. You can use the bases of the running scenario from +either **scenario.xml** or the **scenario.py** gRPC script. + +* In the GUI double click on node **n4**, this will bring up a terminal for this node +* In the **n4** terminal, run the server + ```shell + export PATH=$PATH:/usr/local/bin + chatapp-server + ``` +* In the GUI double click on node **n2**, this will bring up a terminal for this node +* In the **n2** terminal, run the client + ```shell + export PATH=$PATH:/usr/local/bin + chatapp-client -a 10.0.0.4 + ``` +* This will result in **n2** connecting to the server +* In the **n2** terminal, type a message at the client prompt + ```shell + >>hello world + ``` +* Observe that text typed at client then appears in the terminal of **n4** + ```shell + chat server listening on: :9001 + [server] 10.0.0.2:53684 joining + [10.0.0.2:53684] hello world + ``` diff --git a/docs/tutorials/tutorial3.md b/docs/tutorials/tutorial3.md new file mode 100644 index 00000000..362803fc --- /dev/null +++ b/docs/tutorials/tutorial3.md @@ -0,0 +1,155 @@ +# Tutorial 3 - Basic Mobility + +## Overview + +This tutorial will cover using a 3 node scenario in CORE with basic mobility. +Mobility can be provided from a NS2 file or by including mobility commands in a gRPC script. + +## Files + +Below is the list of files used for this tutorial. + +* movements1.txt - a NS2 mobility input file +* scenario.xml - 3 node CORE xml scenario file (wireless) +* scenario.py - 3 node CORE gRPC python script (wireless) +* printout.py - event listener + +## Running with XML file using NS2 Movement + +This section will cover running this sample tutorial using the XML scenario +file, leveraging an NS2 file for mobility. + +* Make sure the **core-daemon** is running a terminal + ```shell + sudop core-daemon + ``` +* In another terminal run the GUI + ```shell + core-gui + ``` +* Observe the format of the N2 file, cat movements1.txt. Note that this file was manually developed. + ```shell + $node_(1) set X_ 208.1 + $node_(1) set Y_ 211.05 + $node_(1) set Z_ 0 + $ns_ at 0.0 "$node_(1) setdest 208.1 211.05 0.00" + $node_(2) set X_ 393.1 + $node_(2) set Y_ 223.05 + $node_(2) set Z_ 0 + $ns_ at 0.0 "$node_(2) setdest 393.1 223.05 0.00" + $node_(4) set X_ 499.1 + $node_(4) set Y_ 186.05 + $node_(4) set Z_ 0 + $ns_ at 0.0 "$node_(4) setdest 499.1 186.05 0.00" + $ns_ at 1.0 "$node_(1) setdest 190.1 225.05 0.00" + $ns_ at 1.0 "$node_(2) setdest 393.1 225.05 0.00" + $ns_ at 1.0 "$node_(4) setdest 515.1 186.05 0.00" + $ns_ at 2.0 "$node_(1) setdest 175.1 250.05 0.00" + $ns_ at 2.0 "$node_(2) setdest 393.1 250.05 0.00" + $ns_ at 2.0 "$node_(4) setdest 530.1 186.05 0.00" + $ns_ at 3.0 "$node_(1) setdest 160.1 275.05 0.00" + $ns_ at 3.0 "$node_(2) setdest 393.1 275.05 0.00" + $ns_ at 3.0 "$node_(4) setdest 530.1 186.05 0.00" + $ns_ at 4.0 "$node_(1) setdest 160.1 300.05 0.00" + $ns_ at 4.0 "$node_(2) setdest 393.1 300.05 0.00" + $ns_ at 4.0 "$node_(4) setdest 550.1 186.05 0.00" + $ns_ at 5.0 "$node_(1) setdest 160.1 275.05 0.00" + $ns_ at 5.0 "$node_(2) setdest 393.1 275.05 0.00" + $ns_ at 5.0 "$node_(4) setdest 530.1 186.05 0.00" + $ns_ at 6.0 "$node_(1) setdest 175.1 250.05 0.00" + $ns_ at 6.0 "$node_(2) setdest 393.1 250.05 0.00" + $ns_ at 6.0 "$node_(4) setdest 515.1 186.05 0.00" + $ns_ at 7.0 "$node_(1) setdest 190.1 225.05 0.00" + $ns_ at 7.0 "$node_(2) setdest 393.1 225.05 0.00" + $ns_ at 7.0 "$node_(4) setdest 499.1 186.05 0.00" + ``` +* In the GUI menu bar select **File->Open...**, and select this tutorials **scenario.xml** file +* You can now click play to start the session +* Select the play button on the Mobility Player to start mobility +* Observe movement of the nodes +* Note that OSPF routing protocol is included in the scenario to build routing table so that routes to other nodes are + known and when the routes are discovered, ping will work + +

    + +

    + +## Running with the gRPC Script + +This section covers using a gRPC script to create and provide scenario movement. + +* Make sure the **core-daemon** is running a terminal + ```shell + sudop core-daemon + ``` +* From another terminal run the **scenario.py** script + ```shell + /opt/core/venv/bin/python scenario.py + ``` +* In another terminal run the GUI + ```shell + core-gui + ``` +* In the GUI dialog box select the session and click connect +* You will now have joined the already running scenario +* In the terminal running the **scenario.py**, hit a key to start motion +

    + +

    +* Observe the link between **n3** and **n4** is shown and then as motion continues the link breaks +

    + +

    + +## Running the Chat App Software + +This section covers using one of the above 2 scenarios to run software within +the nodes. + +* In the GUI double click on **n4**, this will bring up a terminal for this node +* in the **n4** terminal, run the server + ```shell + export PATH=$PATH:/usr/local/bin + chatapp-server + ``` +* In the GUI double click on **n2**, this will bring up a terminal for this node +* In the **n2** terminal, run the client + ```shell + export PATH=$PATH:/usr/local/bin + chatapp-client -a 10.0.0.4 + ``` +* This will result in **n2** connecting to the server +* In the **n2** terminal, type a message at the client prompt and hit enter + ```shell + >>hello world + ``` +* Observe that text typed at client then appears in the server terminal + ```shell + chat server listening on: :9001 + [server] 10.0.0.2:53684 joining + [10.0.0.2:53684] hello world + ``` + +## Running Mobility from a Node + +This section provides an example for running a script within a node, that +leverages a control network in CORE for issuing mobility using the gRPC +API. + +* Edit the following line in **/etc/core/core.conf** + ```shell + grpcaddress = 0.0.0.0 + ``` +* Start the scenario from the **scenario.xml** +* From the GUI open **Session -> Options** and set **Control Network** to **172.16.0.0/24** +* Click to play the scenario +* Double click on **n2** to get a terminal window +* From the terminal window for **n2**, run the script + ```shell + /opt/core/venv/bin/python move-node2.py + ``` +* Observe that node 2 moves and continues to move + +

    + +

    diff --git a/docs/tutorials/tutorial4.md b/docs/tutorials/tutorial4.md new file mode 100644 index 00000000..77ac1c94 --- /dev/null +++ b/docs/tutorials/tutorial4.md @@ -0,0 +1,121 @@ +# Tutorial 4 - Tests + +## Overview + +A use case for CORE would be to help automate integration tests for running +software within a network. This tutorial covers using CORE with the python +pytest testing framework. It will show how you can define tests, for different +use cases to validate software and outcomes within a defined network. Using +pytest, you would create tests using all the standard pytest functionality. +Creating a test file, and then defining test functions to run. For these tests, +we are leveraging the CORE library directly and the API it provides. + +Refer to the [pytest documentation](https://docs.pytest.org) for indepth +information on how to write tests with pytest. + +## Files + +A directory is used for containing your tests. Within this directory we need a +**conftest.py**, which pytest will pick up to help define and provide +test fixtures, which will be leveraged within our tests. + +* tests + * conftest.py - file used by pytest to define fixtures, which can be shared across tests + * test_ping.py - defines test classes/functions to run + +## Test Fixtures + +Below are the definitions for fixture you can define to facilitate and make +creating CORE based tests easier. + +The global session fixture creates one **CoreEmu** object for the entire +test session, yields it for testing, and calls shutdown when everything +is over. + +``` python +@pytest.fixture(scope="session") +def global_session(): + core = CoreEmu() + session = core.create_session() + session.set_state(EventTypes.CONFIGURATION_STATE) + yield session + core.shutdown() +``` + +The regular session fixture leverages the global session fixture. It +will set the correct state for each test case, yield the session for a test, +and then clear the session after a test finishes to prepare for the next +test. + +``` python +@pytest.fixture +def session(global_session): + global_session.set_state(EventTypes.CONFIGURATION_STATE) + yield global_session + global_session.clear() +``` + +The ip prefixes fixture help provide a preconfigured convenience for +creating and assigning interfaces to nodes, when creating your network +within a test. The address subnet can be whatever you desire. + +``` python +@pytest.fixture(scope="session") +def ip_prefixes(): + return IpPrefixes(ip4_prefix="10.0.0.0/24") +``` + +## Test Functions + +Within a pytest test file, you have the freedom to create any kind of +test you like, but they will all follow a similar formula. + +* define a test function that will leverage the session and ip prefixes fixtures +* then create a network to test, using the session fixture +* run commands within nodes as desired, to test out your use case +* validate command result or output for expected behavior to pass or fail + +In the test below, we create a simple 2 node wired network and validate +node1 can ping node2 successfully. + +``` python +def test_success(self, session: Session, ip_prefixes: IpPrefixes): + # create nodes + node1 = session.add_node(CoreNode) + node2 = session.add_node(CoreNode) + + # link nodes together + iface1_data = ip_prefixes.create_iface(node1) + iface2_data = ip_prefixes.create_iface(node2) + session.add_link(node1.id, node2.id, iface1_data, iface2_data) + + # ping node, expect a successful command + node1.cmd(f"ping -c 1 {iface2_data.ip4}") +``` + +## Install Pytest + +Since we are running an automated test within CORE, we will need to install +pytest within the python interpreter used by CORE. + +``` shell +sudo /opt/core/venv/bin/python -m pip install pytest +``` + +## Running Tests + +You can run your own or the provided tests, by running the following. + +``` shell +cd +sudo /opt/core/venv/bin/python -m pytest -v +``` + +If you run the provided tests, you would expect to see the two tests +running and passing. + +``` shell +tests/test_ping.py::TestPing::test_success PASSED [ 50%] +tests/test_ping.py::TestPing::test_failure PASSED [100%] +``` + diff --git a/docs/tutorials/tutorial5.md b/docs/tutorials/tutorial5.md new file mode 100644 index 00000000..7f2d151e --- /dev/null +++ b/docs/tutorials/tutorial5.md @@ -0,0 +1,168 @@ +# Tutorial 5 - RJ45 Node + +## Overview + +This tutorial will cover connecting CORE VM to a Windows host machine using a RJ45 node. + +## Files + +Below is the list of files used for this tutorial. + +* scenario.xml - the scenario with RJ45 unassigned +* scenario.py- grpc script to create the RJ45 in simple CORE scenario +* client_for_windows.py - chat app client modified for windows + +## Running with the Saved XML File + +This section covers using the saved **scenario.xml** file to get and up and running. + +* Configure the Windows host VM to have a bridged network adapter +

    + +

    +* Make sure the **core-daemon** is running in a terminal + ```shell + sudop core-daemon + ``` +* In another terminal run the GUI + ```shell + core-gui + ``` +* Open the **scenario.xml** with the unassigned RJ45 node +

    + +

    +* Configure the RJ45 node name to use the bridged interface +

    + +

    +* After configuring the RJ45, run the scenario: +

    + +

    +* Double click node **n1** to open a terminal and add a route to the Windows host + ```shell + ip route add 192.168.0.0/24 via 10.0.0.20 + ``` +* On the Windows host using Windows command prompt with administrator privilege, add a route that uses the interface + connected to the associated interface assigned to the RJ45 node + ```shell + # if enp0s3 is ssigned 192.168.0.6/24 + route add 10.0.0.0 mask 255.255.255.0 192.168.0.6 + ``` +* Now you should be able to ping from the Windows host to **n1** + ```shell + C:\WINDOWS\system32>ping 10.0.0.20 + + Pinging 10.0.0.20 with 32 bytes of data: + Reply from 10.0.0.20: bytes=32 time<1ms TTL=64 + Reply from 10.0.0.20: bytes=32 time<1ms TTL=64 + Reply from 10.0.0.20: bytes=32 time<1ms TTL=64 + Reply from 10.0.0.20: bytes=32 time<1ms TTL=64 + + Ping statistics for 10.0.0.20: + Packets: Sent = 4, Received = 4, Lost = 0 (0% loss) + Approximate round trip times in milli-seconds: + Minimum = 0ms, Maximum = 0ms, Average = 0ms + ``` +* After pinging successfully, run the following in the **n1** terminal to start the chatapp server + ```shell + export PATH=$PATH:/usr/local/bin + chatapp-server + ``` +* On the Windows host, run the **client_for_windows.py** + ```shell + python3 client_for_windows.py -a 10.0.0.20 + connected to server(10.0.0.20:9001) as client(192.168.0.6:49960) + >> .Hello WORLD + .Hello WORLD Again + . + ``` +* Observe output on **n1** + ```shell + chat server listening on: :9001 + [server] 192.168.0.6:49960 joining + [192.168.0.6:49960] Hello WORLD + [192.168.0.6:49960] Hello WORLD Again + ``` +* When finished, you can stop the CORE scenario and cleanup +* On the Windows host remove the added route + ```shell + route delete 10.0.0.0 + ``` + +## Running with the gRPC Script + +This section covers leveraging the gRPC script to get up and running. + +* Configure the Windows host VM to have a bridged network adapter +

    + +

    +* Make sure the **core-daemon** is running in a terminal + ```shell + sudop core-daemon + ``` +* In another terminal run the GUI + ```shell + core-gui + ``` +* Run the gRPC script in the VM + ```shell + # use the desired interface name, in this case enp0s3 + /opt/core/venv/bin/python scenario.py enp0s3 + ``` +* In the **core-gui** connect to the running session that was created +

    + +

    +* Double click node **n1** to open a terminal and add a route to the Windows host + ```shell + ip route add 192.168.0.0/24 via 10.0.0.20 + ``` +* On the Windows host using Windows command prompt with administrator privilege, add a route that uses the interface + connected to the associated interface assigned to the RJ45 node + ```shell + # if enp0s3 is ssigned 192.168.0.6/24 + route add 10.0.0.0 mask 255.255.255.0 192.168.0.6 + ``` +* Now you should be able to ping from the Windows host to **n1** + ```shell + C:\WINDOWS\system32>ping 10.0.0.20 + + Pinging 10.0.0.20 with 32 bytes of data: + Reply from 10.0.0.20: bytes=32 time<1ms TTL=64 + Reply from 10.0.0.20: bytes=32 time<1ms TTL=64 + Reply from 10.0.0.20: bytes=32 time<1ms TTL=64 + Reply from 10.0.0.20: bytes=32 time<1ms TTL=64 + + Ping statistics for 10.0.0.20: + Packets: Sent = 4, Received = 4, Lost = 0 (0% loss) + Approximate round trip times in milli-seconds: + Minimum = 0ms, Maximum = 0ms, Average = 0ms + ``` +* After pinging successfully, run the following in the **n1** terminal to start the chatapp server + ```shell + export PATH=$PATH:/usr/local/bin + chatapp-server + ``` +* On the Windows host, run the **client_for_windows.py** + ```shell + python3 client_for_windows.py -a 10.0.0.20 + connected to server(10.0.0.20:9001) as client(192.168.0.6:49960) + >> .Hello WORLD + .Hello WORLD Again + . + ``` +* Observe output on **n1** + ```shell + chat server listening on: :9001 + [server] 192.168.0.6:49960 joining + [192.168.0.6:49960] Hello WORLD + [192.168.0.6:49960] Hello WORLD Again + ``` +* When finished, you can stop the CORE scenario and cleanup +* On the Windows host remove the added route + ```shell + route delete 10.0.0.0 + ``` diff --git a/docs/tutorials/tutorial6.md b/docs/tutorials/tutorial6.md new file mode 100644 index 00000000..6135d21e --- /dev/null +++ b/docs/tutorials/tutorial6.md @@ -0,0 +1,97 @@ +# Tutorial 6 - Improved Visuals + +## Overview + +This tutorial will cover changing the node icons, changing the background, and changing or hiding links. + +## Files + +Below is the list of files used for this tutorial. + +* drone.png - icon for a drone +* demo.py - a mobility script for a node +* terrain.png - a background +* completed-scenario.xml - the scenario after making all changes below + +## Running this Tutorial + +This section will cover running this sample tutorial that develops a scenario file. + +* Ensure that **/etc/core/core.conf** has **grpcaddress** set to **0.0.0.0** +* Make sure the **core-daemon** is running in a terminal + ```shell + sudop core-daemon + ``` +* In another terminal run the GUI + ```shell + core-gui + ``` + +### Changing Node Icons + +* Create three MDR nodes +

    + +

    +* Double click on each node for configuration, click the icon and set it to use the **drone.png** image +

    + +

    +* Use **Session -> Options** and set **Control Network 0** to **172.16.0.0./24** + +### Linking Nodes to WLAN + +* Add a WLAN Node +* Link the three prior MDR nodes to the WLAN node +

    + +

    +* Click play to start the scenario +* Observe wireless links being created +

    + +

    +* Click stop to end the scenario +* Right click the WLAN node and select **Edit -> Hide** +* Now you can view the nodes in isolation +

    + +

    + +### Changing Canvas Background + +* Click **Canvas -> Wallpaper** to set the background to terrain.png +

    + +

    +* Click play to start the scenario again +* You now have a scenario with drone icons, terrain background, links displayed and hidden WLAN node +

    + +

    + +## Adding Mobility + +* Open and play the **completed-scenario.xml** +* Double click on **n1** and run the **demo.py** script + ```shell + # node id is first parameter, second is total nodes + /opt/core/venv/bin/python demo.py 1 3 + ``` +* Let it run to see the link break as the node 1 drone approches the right side +

    + +

    +* Repeat for other nodes, double click on **n2** and **n3** and run the demo.py script + ```shell + # n2 + /opt/core/venv/bin/python demo.py 2 3 + # n3 + /opt/core/venv/bin/python demo.py 3 3 + ``` +* You can turn off wireless links via **View -> Wireless Links** +* Observe nodes moving in parallel tracks, when the far right is reached, the node will move down + and then move to the left. When the far left is reached, the drone will move down and then move to the right. +

    + +

    diff --git a/docs/tutorials/tutorial7.md b/docs/tutorials/tutorial7.md new file mode 100644 index 00000000..89a84555 --- /dev/null +++ b/docs/tutorials/tutorial7.md @@ -0,0 +1,236 @@ +# Tutorial 7 - EMANE + +## Overview + +This tutorial will cover basic usage and some concepts one may want to +use or leverage when working with and creating EMANE based networks. + +

    + +

    + +For more detailed information on EMANE see the following: + +* [EMANE in CORE](../emane.md) +* [EMANE Wiki](https://github.com/adjacentlink/emane/wiki) + +## Files + +Below is a list of the files used for this tutorial. + +* 2 node EMANE ieee80211abg scenario + * scenario.xml + * scenario.py +* 2 node EMANE ieee80211abg scenario, with **n2** running the "Chat App Server" service + * scenario_service.xml + * scenario_service.py + +## Running this Tutorial + +This section covers interactions that can be carried out for this scenario. + +Our scenario has the following nodes and addresses: + +* emane1 - no address, this is a representative node for the EMANE network +* n2 - 10.0.0.1 +* n3 - 10.0.0.2 + +All usages below assume a clean scenario start. + +### Using Ping + +Using the command line utility **ping** can be a good way to verify connectivity +between nodes in CORE. + +* Make sure the CORE daemon is running a terminal, if not already + ``` shell + sudop core-daemon + ``` +* In another terminal run the GUI + ``` shell + core-gui + ``` +* In the GUI menu bar select **File->Open...**, then navigate to and select **scenario.xml** +

    + +

    +* You can now click on the **Start Session** button to run the scenario +

    + +

    +* Open a terminal on **n2** by double clicking it in the GUI +* Run the following in **n2** terminal + ``` shell + ping -c 3 10.0.0.2 + ``` +* You should see the following output + ``` shell + PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data. + 64 bytes from 10.0.0.2: icmp_seq=1 ttl=64 time=7.93 ms + 64 bytes from 10.0.0.2: icmp_seq=2 ttl=64 time=3.07 ms + 64 bytes from 10.0.0.2: icmp_seq=3 ttl=64 time=3.05 ms + + --- 10.0.0.2 ping statistics --- + 3 packets transmitted, 3 received, 0% packet loss, time 2000ms + rtt min/avg/max/mdev = 3.049/4.685/7.932/2.295 ms + ``` + +### Using Tcpdump + +Using **tcpdump** can be very beneficial for examining a network. You can verify +traffic being sent/received among many other uses. + +* Make sure the CORE daemon is running a terminal, if not already + ``` shell + sudop core-daemon + ``` +* In another terminal run the GUI + ``` shell + core-gui + ``` +* In the GUI menu bar select **File->Open...**, then navigate to and select **scenario.xml** +

    + +

    +* You can now click on the **Start Session** button to run the scenario +

    + +

    +* Open a terminal on **n2** by double clicking it in the GUI +* Open a terminal on **n3** by double clicking it in the GUI +* Run the following in **n3** terminal + ``` shell + tcpdump -lenni eth0 + ``` +* Run the following in **n2** terminal + ``` shell + ping -c 1 10.0.0.2 + ``` +* You should see the following in **n2** terminal + ``` shell + tcpdump: verbose output suppressed, use -v[v]... for full protocol decode + listening on eth0, link-type EN10MB (Ethernet), snapshot length 262144 bytes + 14:56:25.414283 02:02:00:00:00:01 > 02:02:00:00:00:02, ethertype IPv4 (0x0800), length 98: 10.0.0.1 > 10.0.0.2: ICMP echo request, id 64832, seq 1, length 64 + 14:56:25.414303 02:02:00:00:00:02 > 02:02:00:00:00:01, ethertype IPv4 (0x0800), length 98: 10.0.0.2 > 10.0.0.1: ICMP echo reply, id 64832, seq 1, length 64 + ``` + +### Running Software + +We will now leverage the installed Chat App software to stand up a server and client +within the nodes of our scenario. + +* Make sure the CORE daemon is running a terminal, if not already + ``` shell + sudop core-daemon + ``` +* In another terminal run the GUI + ``` shell + core-gui + ``` +* In the GUI menu bar select **File->Open...**, then navigate to and select **scenario.xml** +

    + +

    +* You can now click on the **Start Session** button to run the scenario +

    + +

    +* Open a terminal on **n2** by double clicking it in the GUI +* Run the following in **n2** terminal + ``` shell + export PATH=$PATH:/usr/local/bin + chatapp-server + ``` +* Open a terminal on **n3** by double clicking it in the GUI +* Run the following in **n3** terminal + ``` shell + export PATH=$PATH:/usr/local/bin + chatapp-client -a 10.0.0.1 + ``` +* You will see the following output in **n1** terminal + ``` shell + chat server listening on: :9001 + [server] 10.0.0.1:44362 joining + ``` +* Type the following in **n2** terminal and hit enter + ``` shell + hello world + ``` +* You will see the following output in **n1** terminal + ``` shell + chat server listening on: :9001 + [server] 10.0.0.2:44362 joining + [10.0.0.2:44362] hello world + ``` + +### Tailing a Log + +In this case we are using the service based scenario. This will automatically start +and run the Chat App Server on **n2** and log to a file. This case will demonstrate +using `tail -f` to observe the output of running software. + +* Make sure the CORE daemon is running a terminal, if not already + ``` shell + sudop core-daemon + ``` +* In another terminal run the GUI + ``` shell + core-gui + ``` +* In the GUI menu bar select **File->Open...**, then navigate to and select **scenario_service.xml** +

    + +

    +* You can now click on the **Start Session** button to run the scenario +

    + +

    +* Open a terminal on **n2** by double clicking it in the GUI +* Run the following in **n2** terminal + ``` shell + tail -f chatapp.log + ``` +* Open a terminal on **n3** by double clicking it in the GUI +* Run the following in **n3** terminal + ``` shell + export PATH=$PATH:/usr/local/bin + chatapp-client -a 10.0.0.1 + ``` +* You will see the following output in **n2** terminal + ``` shell + chat server listening on: :9001 + [server] 10.0.0.2:44362 joining + ``` +* Type the following in **n3** terminal and hit enter + ``` shell + hello world + ``` +* You will see the following output in **n2** terminal + ``` shell + chat server listening on: :9001 + [server] 10.0.0.2:44362 joining + [10.0.0.2:44362] hello world + ``` + +## Advanced Topics + +This section will cover some high level topics and examples for running and +using EMANE in CORE. You can find more detailed tutorials and examples at +the [EMANE Tutorial](https://github.com/adjacentlink/emane-tutorial/wiki). + +!!! note + + Every topic below assumes CORE, EMANE, and OSPF MDR have been installed. + + Scenario files to support the EMANE topics below will be found in + the GUI default directory for opening XML files. + +| Topic | Model | Description | +|-----------------------------------------|---------|-----------------------------------------------------------| +| [XML Files](../emane/files.md) | RF Pipe | Overview of generated XML files used to drive EMANE | +| [GPSD](../emane/gpsd.md) | RF Pipe | Overview of running and integrating gpsd with EMANE | +| [Precomputed](../emane/precomputed.md) | RF Pipe | Overview of using the precomputed propagation model | +| [EEL](../emane/eel.md) | RF Pipe | Overview of using the Emulation Event Log (EEL) Generator | +| [Antenna Profiles](../emane/antenna.md) | RF Pipe | Overview of using antenna profiles in EMANE | + +--8<-- "tutorials/common/grpc.md" diff --git a/mkdocs.yml b/mkdocs.yml new file mode 100644 index 00000000..c2fbc03c --- /dev/null +++ b/mkdocs.yml @@ -0,0 +1,84 @@ +site_name: CORE Documentation +use_directory_urls: false +theme: + name: material + palette: + - scheme: slate + toggle: + icon: material/brightness-4 + name: Switch to Light Mode + primary: teal + accent: teal + - scheme: default + toggle: + icon: material/brightness-7 + name: Switch to Dark Mode + primary: teal + accent: teal + features: + - navigation.path + - navigation.instant + - navigation.footer + - content.code.copy +markdown_extensions: + - pymdownx.snippets: + base_path: docs + - admonition + - pymdownx.details + - pymdownx.superfences + - pymdownx.tabbed: + alternate_style: true + - pymdownx.inlinehilite +nav: + - Home: index.md + - Overview: + - Architecture: architecture.md + - Performance: performance.md + - Installation: + - Overview: install.md + - Ubuntu: install_ubuntu.md + - CentOS: install_centos.md + - Tutorials: + - Overview: tutorials/overview.md + - Setup: tutorials/setup.md + - Tutorial 1 - Wired Network: tutorials/tutorial1.md + - Tutorial 2 - Wireless Network: tutorials/tutorial2.md + - Tutorial 3 - Basic Mobility: tutorials/tutorial3.md + - Tutorial 4 - Tests: tutorials/tutorial4.md + - Tutorial 5 - RJ45 Node: tutorials/tutorial5.md + - Tutorial 6 - Improve Visuals: tutorials/tutorial6.md + - Tutorial 7 - EMANE: tutorials/tutorial7.md + - Detailed Topics: + - GUI: gui.md + - Node Types: + - Overview: nodetypes.md + - Docker: docker.md + - LXC: lxc.md + - Services: + - Config Services: configservices.md + - Services (Deprecated): services.md + - Provided: + - Bird: services/bird.md + - EMANE: services/emane.md + - FRR: services/frr.md + - NRL: services/nrl.md + - Quagga: services/quagga.md + - SDN: services/sdn.md + - Security: services/security.md + - Utility: services/utility.md + - XORP: services/xorp.md + - API: + - Python: python.md + - gRPC: grpc.md + - Distributed: distributed.md + - Control Network: ctrlnet.md + - Hardware In The Loop: hitl.md + - EMANE: + - Overview: emane.md + - Examples: + - Antenna: emane/antenna.md + - EEL: emane/eel.md + - Files: emane/files.md + - GPSD: emane/gpsd.md + - Precomputed: emane/precomputed.md + - Developers Guide: devguide.md diff --git a/package/etc/core.conf b/package/etc/core.conf index 874ba567..1923250d 100644 --- a/package/etc/core.conf +++ b/package/etc/core.conf @@ -5,7 +5,7 @@ grpcport = 50051 quagga_bin_search = "/usr/local/bin /usr/bin /usr/lib/quagga" quagga_sbin_search = "/usr/local/sbin /usr/sbin /usr/lib/quagga" frr_bin_search = "/usr/local/bin /usr/bin /usr/lib/frr" -frr_sbin_search = "/usr/local/sbin /usr/sbin /usr/lib/frr" +frr_sbin_search = "/usr/local/sbin /usr/sbin /usr/lib/frr /usr/libexec/frr" # uncomment the following line to load custom services from the specified dir # this may be a comma-separated list, and directory names should be unique diff --git a/package/examples/myemane/examplemodel.py b/package/examples/myemane/examplemodel.py index c33ac166..bd5102e4 100644 --- a/package/examples/myemane/examplemodel.py +++ b/package/examples/myemane/examplemodel.py @@ -64,6 +64,7 @@ class ExampleModel(emanemodel.EmaneModel): :param emane_prefix: configured emane prefix path :return: nothing """ + cls._load_platform_config(emane_prefix) manifest_path = "share/emane/manifest" # load mac configuration mac_xml_path = emane_prefix / manifest_path / cls.mac_xml diff --git a/package/examples/python/emane80211.py b/package/examples/python/emane80211.py index 488983d6..f369a718 100644 --- a/package/examples/python/emane80211.py +++ b/package/examples/python/emane80211.py @@ -41,10 +41,7 @@ n2 = session.add_node(CoreNode, position=position, options=options) session.emane.set_config( emane.id, EmaneIeee80211abgModel.name, - { - "unicastrate": "3", - "eventservicettl": "2" - }, + {"unicastrate": "3", "eventservicettl": "2"}, ) # link nodes to emane diff --git a/package/examples/tutorials/chatapp/chatapp/__init__.py b/package/examples/tutorials/chatapp/chatapp/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/package/examples/tutorials/chatapp/chatapp/client.py b/package/examples/tutorials/chatapp/chatapp/client.py new file mode 100644 index 00000000..06107127 --- /dev/null +++ b/package/examples/tutorials/chatapp/chatapp/client.py @@ -0,0 +1,70 @@ +import argparse +import select +import socket +import sys +import termios + +DEFAULT_PORT: int = 9001 +READ_SIZE: int = 4096 + + +def prompt(): + sys.stdout.write(">> ") + sys.stdout.flush() + + +class ChatClient: + def __init__(self, address, port): + self.address = address + self.port = port + + def run(self): + server = socket.create_connection((self.address, self.port)) + sockname = server.getsockname() + print( + f"connected to server({self.address}:{self.port}) as " + f"client({sockname[0]}:{sockname[1]})" + ) + sockets = [sys.stdin, server] + prompt() + try: + while True: + read_sockets, write_socket, error_socket = select.select( + sockets, [], [] + ) + for sock in read_sockets: + if sock == server: + message = server.recv(READ_SIZE) + if not message: + print("server closed") + sys.exit(1) + else: + termios.tcflush(sys.stdin, termios.TCIOFLUSH) + print("\x1b[2K\r", end="") + print(message.decode().strip()) + prompt() + else: + message = sys.stdin.readline().strip() + server.sendall(f"{message}\n".encode()) + prompt() + except KeyboardInterrupt: + print("client exiting") + server.close() + + +def main(): + parser = argparse.ArgumentParser( + description="chat app client", + formatter_class=argparse.ArgumentDefaultsHelpFormatter, + ) + parser.add_argument("-a", "--address", help="address to listen on", required=True) + parser.add_argument( + "-p", "--port", type=int, help="port to listen on", default=DEFAULT_PORT + ) + args = parser.parse_args() + client = ChatClient(args.address, args.port) + client.run() + + +if __name__ == "__main__": + main() diff --git a/package/examples/tutorials/chatapp/chatapp/server.py b/package/examples/tutorials/chatapp/chatapp/server.py new file mode 100644 index 00000000..dcd874bf --- /dev/null +++ b/package/examples/tutorials/chatapp/chatapp/server.py @@ -0,0 +1,85 @@ +import argparse +import select +import socket + +DEFAULT_ADDRESS: str = "" +DEFAULT_PORT: int = 9001 +READ_SIZE: int = 4096 + + +class ChatServer: + def __init__(self, address, port): + self.address = address + self.port = port + self.sockets = [] + + def broadcast(self, ignore, message): + for sock in self.sockets: + if sock not in ignore: + sock.sendall(message.encode()) + + def run(self): + print(f"chat server listening on: {self.address}:{self.port}") + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as server: + server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + server.bind((self.address, self.port)) + server.listen() + self.sockets.append(server) + try: + while True: + read_sockets, write_sockets, error_sockets = select.select( + self.sockets, [], [] + ) + for sock in read_sockets: + if sock == server: + client_sock, addr = server.accept() + self.sockets.append(client_sock) + name = f"{addr[0]}:{addr[1]}" + print(f"[server] {name} joining") + self.broadcast( + {server, client_sock}, f"[server] {name} entered room\n" + ) + else: + peer = sock.getpeername() + name = f"{peer[0]}:{peer[1]}" + try: + data = sock.recv(READ_SIZE).decode().strip() + if data: + print(f"[{name}] {data}") + self.broadcast({server, sock}, f"[{name}] {data}\n") + else: + print(f"[server] {name} leaving") + self.broadcast( + {server, sock}, f"[server] {name} leaving\n" + ) + sock.close() + self.sockets.remove(sock) + except socket.error: + print(f"[server] {name} leaving") + self.broadcast( + {server, sock}, f"[server] {name} leaving\n" + ) + sock.close() + self.sockets.remove(sock) + except KeyboardInterrupt: + print("closing server") + + +def main(): + parser = argparse.ArgumentParser( + description="chat app server", + formatter_class=argparse.ArgumentDefaultsHelpFormatter, + ) + parser.add_argument( + "-a", "--address", help="address to listen on", default=DEFAULT_ADDRESS + ) + parser.add_argument( + "-p", "--port", type=int, help="port to listen on", default=DEFAULT_PORT + ) + args = parser.parse_args() + server = ChatServer(args.address, args.port) + server.run() + + +if __name__ == "__main__": + main() diff --git a/package/examples/tutorials/chatapp/chatapp_service.py b/package/examples/tutorials/chatapp/chatapp_service.py new file mode 100644 index 00000000..6faf8071 --- /dev/null +++ b/package/examples/tutorials/chatapp/chatapp_service.py @@ -0,0 +1,26 @@ +from typing import Dict, List + +from core.config import Configuration +from core.configservice.base import ConfigService, ConfigServiceMode, ShadowDir + + +class ChatAppService(ConfigService): + name: str = "ChatApp Server" + group: str = "ChatApp" + directories: List[str] = [] + files: List[str] = ["chatapp.sh"] + executables: List[str] = [] + dependencies: List[str] = [] + startup: List[str] = [f"bash {files[0]}"] + validate: List[str] = [] + shutdown: List[str] = [] + validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING + default_configs: List[Configuration] = [] + modes: Dict[str, Dict[str, str]] = {} + shadow_directories: List[ShadowDir] = [] + + def get_text_template(self, _name: str) -> str: + return """ + export PATH=$PATH:/usr/local/bin + PYTHONUNBUFFERED=1 chatapp-server > chatapp.log 2>&1 & + """ diff --git a/package/examples/tutorials/chatapp/setup.py b/package/examples/tutorials/chatapp/setup.py new file mode 100644 index 00000000..7c48ecd3 --- /dev/null +++ b/package/examples/tutorials/chatapp/setup.py @@ -0,0 +1,17 @@ +from setuptools import setup, find_packages + +setup( + name="chatapp", + version="0.1.0", + packages=find_packages(), + description="Chat App", + entry_points={ + "console_scripts": [ + "chatapp-client = chatapp.client:main", + "chatapp-server = chatapp.server:main", + ], + }, + include_package_data=True, + zip_safe=False, + python_requires=">=3.6", +) diff --git a/package/examples/tutorials/tutorial1/scenario.py b/package/examples/tutorials/tutorial1/scenario.py new file mode 100644 index 00000000..0c7d33ac --- /dev/null +++ b/package/examples/tutorials/tutorial1/scenario.py @@ -0,0 +1,39 @@ +from core.api.grpc import client +from core.api.grpc.wrappers import Position + + +def main(): + # interface helper + iface_helper = client.InterfaceHelper( + ip4_prefix="10.0.0.0/24", + ip6_prefix="2001::/64", + ) + + # create grpc client and connect + core = client.CoreGrpcClient() + core.connect() + + # create session + session = core.create_session() + + # create nodes + position = Position(x=250, y=250) + node1 = session.add_node(_id=1, name="n1", position=position) + position = Position(x=500, y=250) + node2 = session.add_node(_id=2, name="n2", position=position) + + # create link + node1_iface = iface_helper.create_iface(node_id=node1.id, iface_id=0) + node1_iface.ip4 = "10.0.0.20" + node1_iface.ip6 = "2001::14" + node2_iface = iface_helper.create_iface(node_id=node2.id, iface_id=0) + node2_iface.ip4 = "10.0.0.21" + node2_iface.ip6 = "2001::15" + session.add_link(node1=node1, node2=node2, iface1=node1_iface, iface2=node2_iface) + + # start session + core.start_session(session=session) + + +if __name__ == "__main__": + main() diff --git a/package/examples/tutorials/tutorial1/scenario.xml b/package/examples/tutorials/tutorial1/scenario.xml new file mode 100644 index 00000000..428fe4ca --- /dev/null +++ b/package/examples/tutorials/tutorial1/scenario.xml @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/package/examples/tutorials/tutorial1/scenario_service.py b/package/examples/tutorials/tutorial1/scenario_service.py new file mode 100644 index 00000000..5a3c5508 --- /dev/null +++ b/package/examples/tutorials/tutorial1/scenario_service.py @@ -0,0 +1,40 @@ +from core.api.grpc import client +from core.api.grpc.wrappers import Position + + +def main(): + # interface helper + iface_helper = client.InterfaceHelper( + ip4_prefix="10.0.0.0/24", + ip6_prefix="2001::/64", + ) + + # create grpc client and connect + core = client.CoreGrpcClient() + core.connect() + + # create session + session = core.create_session() + + # create nodes + position = Position(x=250, y=250) + node1 = session.add_node(_id=1, name="n1", position=position) + node1.config_services.add("ChatApp Server") + position = Position(x=500, y=250) + node2 = session.add_node(_id=2, name="n2", position=position) + + # create link + node1_iface = iface_helper.create_iface(node_id=node1.id, iface_id=0) + node1_iface.ip4 = "10.0.0.20" + node1_iface.ip6 = "2001::14" + node2_iface = iface_helper.create_iface(node_id=node2.id, iface_id=0) + node2_iface.ip4 = "10.0.0.21" + node2_iface.ip6 = "2001::15" + session.add_link(node1=node1, node2=node2, iface1=node1_iface, iface2=node2_iface) + + # start session + core.start_session(session=session) + + +if __name__ == "__main__": + main() diff --git a/package/examples/tutorials/tutorial1/scenario_service.xml b/package/examples/tutorials/tutorial1/scenario_service.xml new file mode 100644 index 00000000..ab092f4c --- /dev/null +++ b/package/examples/tutorials/tutorial1/scenario_service.xml @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/package/examples/tutorials/tutorial2/scenario.py b/package/examples/tutorials/tutorial2/scenario.py new file mode 100644 index 00000000..5b9f252a --- /dev/null +++ b/package/examples/tutorials/tutorial2/scenario.py @@ -0,0 +1,43 @@ +from core.api.grpc import client +from core.api.grpc.wrappers import NodeType, Position + + +def main(): + # interface helper + iface_helper = client.InterfaceHelper( + ip4_prefix="10.0.0.0/24", ip6_prefix="2001::/64" + ) + + # create grpc client and connect + core = client.CoreGrpcClient() + core.connect() + + # add session + session = core.create_session() + + # create nodes + position = Position(x=200, y=200) + wlan = session.add_node( + 1, name="wlan1", _type=NodeType.WIRELESS_LAN, position=position + ) + position = Position(x=100, y=100) + node1 = session.add_node(2, name="n2", model="mdr", position=position) + position = Position(x=300, y=100) + node2 = session.add_node(3, name="n3", model="mdr", position=position) + position = Position(x=500, y=100) + node3 = session.add_node(4, name="n4", model="mdr", position=position) + + # create links + iface1 = iface_helper.create_iface(node1.id, 0) + session.add_link(node1=node1, node2=wlan, iface1=iface1) + iface1 = iface_helper.create_iface(node2.id, 0) + session.add_link(node1=node2, node2=wlan, iface1=iface1) + iface1 = iface_helper.create_iface(node3.id, 0) + session.add_link(node1=node3, node2=wlan, iface1=iface1) + + # start session + core.start_session(session) + + +if __name__ == "__main__": + main() diff --git a/package/examples/tutorials/tutorial2/scenario.xml b/package/examples/tutorials/tutorial2/scenario.xml new file mode 100644 index 00000000..ee60f792 --- /dev/null +++ b/package/examples/tutorials/tutorial2/scenario.xml @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/package/examples/tutorials/tutorial3/move-node2.py b/package/examples/tutorials/tutorial3/move-node2.py new file mode 100644 index 00000000..06f96f7d --- /dev/null +++ b/package/examples/tutorials/tutorial3/move-node2.py @@ -0,0 +1,25 @@ +import time + +from core.api.grpc import client +from core.api.grpc.wrappers import Position + + +def main(): + # create grpc client and connect + core = client.CoreGrpcClient("172.16.0.254:50051") + core.connect() + + # get session + sessions = core.get_sessions() + + print("sessions=", sessions) + for i in range(300): + position = Position(x=100, y=100 + i) + core.move_node(sessions[0].id, 2, position=position) + time.sleep(1) + print("press enter to quit") + input() + + +if __name__ == "__main__": + main() diff --git a/package/examples/tutorials/tutorial3/movements1.txt b/package/examples/tutorials/tutorial3/movements1.txt new file mode 100644 index 00000000..b8271016 --- /dev/null +++ b/package/examples/tutorials/tutorial3/movements1.txt @@ -0,0 +1,33 @@ +$node_(1) set X_ 208.1 +$node_(1) set Y_ 211.05 +$node_(1) set Z_ 0 +$ns_ at 0.0 "$node_(1) setdest 208.1 211.05 0.00" +$node_(2) set X_ 393.1 +$node_(2) set Y_ 223.05 +$node_(2) set Z_ 0 +$ns_ at 0.0 "$node_(2) setdest 393.1 223.05 0.00" +$node_(4) set X_ 499.1 +$node_(4) set Y_ 186.05 +$node_(4) set Z_ 0 +$ns_ at 0.0 "$node_(4) setdest 499.1 186.05 0.00" +$ns_ at 1.0 "$node_(1) setdest 190.1 225.05 0.00" +$ns_ at 1.0 "$node_(2) setdest 393.1 225.05 0.00" +$ns_ at 1.0 "$node_(4) setdest 515.1 186.05 0.00" +$ns_ at 2.0 "$node_(1) setdest 175.1 250.05 0.00" +$ns_ at 2.0 "$node_(2) setdest 393.1 250.05 0.00" +$ns_ at 2.0 "$node_(4) setdest 530.1 186.05 0.00" +$ns_ at 3.0 "$node_(1) setdest 160.1 275.05 0.00" +$ns_ at 3.0 "$node_(2) setdest 393.1 275.05 0.00" +$ns_ at 3.0 "$node_(4) setdest 530.1 186.05 0.00" +$ns_ at 4.0 "$node_(1) setdest 160.1 300.05 0.00" +$ns_ at 4.0 "$node_(2) setdest 393.1 300.05 0.00" +$ns_ at 4.0 "$node_(4) setdest 550.1 186.05 0.00" +$ns_ at 5.0 "$node_(1) setdest 160.1 275.05 0.00" +$ns_ at 5.0 "$node_(2) setdest 393.1 275.05 0.00" +$ns_ at 5.0 "$node_(4) setdest 530.1 186.05 0.00" +$ns_ at 6.0 "$node_(1) setdest 175.1 250.05 0.00" +$ns_ at 6.0 "$node_(2) setdest 393.1 250.05 0.00" +$ns_ at 6.0 "$node_(4) setdest 515.1 186.05 0.00" +$ns_ at 7.0 "$node_(1) setdest 190.1 225.05 0.00" +$ns_ at 7.0 "$node_(2) setdest 393.1 225.05 0.00" +$ns_ at 7.0 "$node_(4) setdest 499.1 186.05 0.00" diff --git a/package/examples/tutorials/tutorial3/scenario.py b/package/examples/tutorials/tutorial3/scenario.py new file mode 100644 index 00000000..fe6e024d --- /dev/null +++ b/package/examples/tutorials/tutorial3/scenario.py @@ -0,0 +1,61 @@ +import time + +from core.api.grpc import client +from core.api.grpc.wrappers import NodeType, Position + + +def main(): + # interface helper + iface_helper = client.InterfaceHelper( + ip4_prefix="10.0.0.0/24", + ip6_prefix="2001::/64", + ) + + # create grpc client and connect + core = client.CoreGrpcClient() + core.connect() + + # add session + session = core.create_session() + + # create nodes + position = Position(x=200, y=200) + wlan = session.add_node( + 3, + name="wlan3", + _type=NodeType.WIRELESS_LAN, + position=position, + ) + position = Position(x=100, y=100) + node1 = session.add_node(1, name="n1", model="mdr", position=position) + position = Position(x=300, y=100) + node2 = session.add_node(2, name="n2", model="mdr", position=position) + position = Position(x=500, y=100) + node3 = session.add_node(4, name="n4", model="mdr", position=position) + + # create links + iface1 = iface_helper.create_iface(node1.id, 0) + session.add_link(node1=node1, node2=wlan, iface1=iface1) + iface1 = iface_helper.create_iface(node2.id, 0) + session.add_link(node1=node2, node2=wlan, iface1=iface1) + iface1 = iface_helper.create_iface(node3.id, 0) + session.add_link(node1=node3, node2=wlan, iface1=iface1) + + # start session + core.start_session(session) + input("start motion, press enter") + + # move node 4 + for i in range(300): + position = Position(x=500 + i, y=100) + core.move_node(session.id, 4, position=position) + time.sleep(1) + x = 800 + for i in range(300): + position = Position(x=800 - i, y=100) + core.move_node(session.id, 4, position=position) + time.sleep(1) + + +if __name__ == "__main__": + main() diff --git a/package/examples/tutorials/tutorial3/scenario.xml b/package/examples/tutorials/tutorial3/scenario.xml new file mode 100644 index 00000000..dbe68d4d --- /dev/null +++ b/package/examples/tutorials/tutorial3/scenario.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/package/examples/tutorials/tutorial4/tests/conftest.py b/package/examples/tutorials/tutorial4/tests/conftest.py new file mode 100644 index 00000000..72fcd120 --- /dev/null +++ b/package/examples/tutorials/tutorial4/tests/conftest.py @@ -0,0 +1,25 @@ +import pytest + +from core.emulator.coreemu import CoreEmu +from core.emulator.data import IpPrefixes +from core.emulator.enumerations import EventTypes + + +@pytest.fixture(scope="session") +def global_session(): + core = CoreEmu() + session = core.create_session() + yield session + core.shutdown() + + +@pytest.fixture +def session(global_session): + global_session.set_state(EventTypes.CONFIGURATION_STATE) + yield global_session + global_session.clear() + + +@pytest.fixture(scope="session") +def ip_prefixes(): + return IpPrefixes(ip4_prefix="10.0.0.0/24") diff --git a/package/examples/tutorials/tutorial4/tests/test_ping.py b/package/examples/tutorials/tutorial4/tests/test_ping.py new file mode 100644 index 00000000..fbd2ae6c --- /dev/null +++ b/package/examples/tutorials/tutorial4/tests/test_ping.py @@ -0,0 +1,36 @@ +import pytest + +from core.emulator.data import IpPrefixes, LinkOptions +from core.emulator.session import Session +from core.errors import CoreCommandError +from core.nodes.base import CoreNode + + +class TestPing: + def test_success(self, session: Session, ip_prefixes: IpPrefixes): + # create nodes + node1 = session.add_node(CoreNode) + node2 = session.add_node(CoreNode) + + # link nodes together + iface1_data = ip_prefixes.create_iface(node1) + iface2_data = ip_prefixes.create_iface(node2) + session.add_link(node1.id, node2.id, iface1_data, iface2_data) + + # ping node, expect a successful command + node1.cmd(f"ping -c 1 {iface2_data.ip4}") + + def test_failure(self, session: Session, ip_prefixes: IpPrefixes): + # create nodes + node1 = session.add_node(CoreNode) + node2 = session.add_node(CoreNode) + + # link nodes together + iface1_data = ip_prefixes.create_iface(node1) + iface2_data = ip_prefixes.create_iface(node2) + options = LinkOptions(loss=100.0) + session.add_link(node1.id, node2.id, iface1_data, iface2_data, options) + + # ping node, expect command to fail and raise exception due to 100% loss + with pytest.raises(CoreCommandError): + node1.cmd(f"ping -c 1 {iface2_data.ip4}") diff --git a/package/examples/tutorials/tutorial5/client_for_windows.py b/package/examples/tutorials/tutorial5/client_for_windows.py new file mode 100644 index 00000000..2f1dcbff --- /dev/null +++ b/package/examples/tutorials/tutorial5/client_for_windows.py @@ -0,0 +1,67 @@ +import argparse +import select +import socket +import sys + +DEFAULT_PORT: int = 9001 +READ_SIZE: int = 4096 + + +def prompt(): + sys.stdout.write(">> ") + sys.stdout.flush() + + +class ChatClient: + def __init__(self, address, port): + self.address = address + self.port = port + + def run(self): + server = socket.create_connection((self.address, self.port)) + sockname = server.getsockname() + print( + f"connected to server({self.address}:{self.port}) as " + f"client({sockname[0]}:{sockname[1]})" + ) + sockets = [server] + prompt() + try: + while True: + read_sockets, write_socket, error_socket = select.select( + sockets, [], [], 10 + ) + for sock in read_sockets: + if sock == server: + message = server.recv(READ_SIZE) + if not message: + print("server closed") + sys.exit(1) + else: + print("\x1b[2K\r", end="") + print(message.decode().strip()) + prompt() + # waiting for input + message = input(".") + server.sendall(f"{message}\n".encode()) + except KeyboardInterrupt: + print("client exiting") + server.close() + + +def main(): + parser = argparse.ArgumentParser( + description="chat app client", + formatter_class=argparse.ArgumentDefaultsHelpFormatter, + ) + parser.add_argument("-a", "--address", help="address to listen on", required=True) + parser.add_argument( + "-p", "--port", type=int, help="port to listen on", default=DEFAULT_PORT + ) + args = parser.parse_args() + client = ChatClient(args.address, args.port) + client.run() + + +if __name__ == "__main__": + main() diff --git a/package/examples/tutorials/tutorial5/scenario.py b/package/examples/tutorials/tutorial5/scenario.py new file mode 100644 index 00000000..9a9500f7 --- /dev/null +++ b/package/examples/tutorials/tutorial5/scenario.py @@ -0,0 +1,43 @@ +import sys + +from core.api.grpc import client, wrappers +from core.api.grpc.wrappers import NodeType, Position + + +def main(): + if len(sys.argv) != 2: + print("usage core-python scenario.py ") + exit() + + # interface helper + iface_helper = client.InterfaceHelper( + ip4_prefix="10.0.0.0/24", + ip6_prefix="2001::/64", + ) + + # create grpc client and connect + core = client.CoreGrpcClient() + core.connect() + + # add session + session = core.create_session() + + # create nodes + position = Position(x=100, y=100) + node1 = session.add_node(1, name="n1", position=position) + position = Position(x=300, y=100) + rj45 = session.add_node(2, name=sys.argv[1], _type=NodeType.RJ45, position=position) + + # create link + iface1 = iface_helper.create_iface(node1.id, 0) + iface1.ip4 = "10.0.0.20" + iface1.ip6 = "2001::14" + rj45_iface1 = wrappers.Interface(0) + session.add_link(node1=node1, node2=rj45, iface1=iface1, iface2=rj45_iface1) + + # start session + core.start_session(session) + + +if __name__ == "__main__": + main() diff --git a/package/examples/tutorials/tutorial5/scenario.xml b/package/examples/tutorials/tutorial5/scenario.xml new file mode 100644 index 00000000..05d93045 --- /dev/null +++ b/package/examples/tutorials/tutorial5/scenario.xml @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/package/examples/tutorials/tutorial6/completed-scenario.xml b/package/examples/tutorials/tutorial6/completed-scenario.xml new file mode 100644 index 00000000..2b985727 --- /dev/null +++ b/package/examples/tutorials/tutorial6/completed-scenario.xml @@ -0,0 +1,114 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/package/examples/tutorials/tutorial6/demo.py b/package/examples/tutorials/tutorial6/demo.py new file mode 100644 index 00000000..b462b382 --- /dev/null +++ b/package/examples/tutorials/tutorial6/demo.py @@ -0,0 +1,104 @@ +import sys +import time + +from core.api.grpc import client +from core.api.grpc.wrappers import Position + + +# start_row can be used to share a search +def find_next_position(arr, start_row): + # find next position with value of 0 for 'not visited' + min_rows, min_cols = (25, 25) + rows, cols = (470, 900) + if start_row < min_rows: + start_row = min_rows + for y in range(start_row, rows): + for x in range(min_cols, cols): + if (y % 2) == 0: + print(f"search_x={x}") + print(f"search_y={y}") + val = arr[x][y] + if (val == 0) or (val == 100): + return x, y + else: + search_x = cols - (x - min_cols + 1) + print(f"search_x={search_x}") + print(f"search_y={y}") + val = arr[search_x][y] + if val == 0: + return search_x, y + + +def move(current_x, current_y, to_x, to_y): + # move 1 pixel + speed = 1 + if to_x > current_x: + move_x = current_x + speed + elif to_x < current_x: + move_x = current_x - speed + else: + move_x = current_x + if to_y > current_y: + move_y = current_y + speed + elif to_y < current_y: + move_y = current_y - speed + else: + move_y = current_y + return move_x, move_y + + +def main(): + n = len(sys.argv) + if n < 3: + print("Usage: core-python demo.py ") + exit() + + # number of search nodes + num_search_nodes = int(sys.argv[2]) + + # create grpc client and connect + core = client.CoreGrpcClient("172.16.0.254:50051") + core.connect() + + # get session + sessions = core.get_sessions() + rows_per_zone = (499 - 25) / num_search_nodes + node_number = int(sys.argv[1]) + y_start = (node_number - 1) * int(rows_per_zone) + current_x = 25 + current_y = y_start + + # max x and y + rows, cols = (470, 900) + arr = [[0 for i in range(rows)] for j in range(cols)] + print(arr, "before") + + # place target + # update one element as target + arr[200][165] = 100 + print(arr, "after") + + position = None + while True: + val = arr[current_x][current_y] + # if position has target, stop + if val == 100: + print(f"found target, position={position}") + else: + # update one element for this starting position + arr[current_x][current_y] = 1 + # move + to_x, to_y = find_next_position(arr, y_start) + print(f"next x={to_x}, next y={to_y}") + x, y = move(current_x, current_y, to_x, to_y) + # command the move + position = Position(x, y) + print(f"move to position {position}") + core.move_node(sessions[0].id, node_number, position=position) + current_x = x + current_y = y + time.sleep(0.25) + + +if __name__ == "__main__": + main() diff --git a/package/examples/tutorials/tutorial6/drone.png b/package/examples/tutorials/tutorial6/drone.png new file mode 100644 index 00000000..61350373 Binary files /dev/null and b/package/examples/tutorials/tutorial6/drone.png differ diff --git a/package/examples/tutorials/tutorial6/terrain.png b/package/examples/tutorials/tutorial6/terrain.png new file mode 100644 index 00000000..cd06728b Binary files /dev/null and b/package/examples/tutorials/tutorial6/terrain.png differ diff --git a/package/examples/tutorials/tutorial7/scenario.py b/package/examples/tutorials/tutorial7/scenario.py new file mode 100644 index 00000000..31008d1c --- /dev/null +++ b/package/examples/tutorials/tutorial7/scenario.py @@ -0,0 +1,53 @@ +from core.api.grpc import client +from core.api.grpc.wrappers import Position, NodeType +from core.emane.models.ieee80211abg import EmaneIeee80211abgModel + + +def main(): + # interface helper + iface_helper = client.InterfaceHelper( + ip4_prefix="10.0.0.0/24", + ip6_prefix="2001::/64", + ) + + # create grpc client and connect + core = client.CoreGrpcClient() + core.connect() + + # create session + session = core.create_session() + + # create nodes + position = Position(x=375, y=500) + emane_net = session.add_node( + _id=1, + _type=NodeType.EMANE, + name="emane1", + position=position, + emane=EmaneIeee80211abgModel.name, + ) + position = Position(x=250, y=250) + node2 = session.add_node(_id=2, model="mdr", name="n2", position=position) + position = Position(x=500, y=250) + node3 = session.add_node(_id=3, model="mdr", name="n3", position=position) + + # create links to emane + node2_iface = iface_helper.create_iface(node_id=node2.id, iface_id=0) + node2_iface.ip4 = "10.0.0.1" + node2_iface.ip4_mask = 32 + node2_iface.ip6 = "2001::1" + node2_iface.ip6_mask = 128 + session.add_link(node1=node2, node2=emane_net, iface1=node2_iface) + node3_iface = iface_helper.create_iface(node_id=node3.id, iface_id=0) + node3_iface.ip4 = "10.0.0.2" + node3_iface.ip4_mask = 32 + node3_iface.ip6 = "2001::2" + node3_iface.ip6_mask = 128 + session.add_link(node1=node3, node2=emane_net, iface1=node3_iface) + + # start session + core.start_session(session=session) + + +if __name__ == "__main__": + main() diff --git a/package/examples/tutorials/tutorial7/scenario.xml b/package/examples/tutorials/tutorial7/scenario.xml new file mode 100644 index 00000000..721a7b8f --- /dev/null +++ b/package/examples/tutorials/tutorial7/scenario.xml @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/package/examples/tutorials/tutorial7/scenario_service.py b/package/examples/tutorials/tutorial7/scenario_service.py new file mode 100644 index 00000000..f0626ac2 --- /dev/null +++ b/package/examples/tutorials/tutorial7/scenario_service.py @@ -0,0 +1,54 @@ +from core.api.grpc import client +from core.api.grpc.wrappers import Position, NodeType +from core.emane.models.ieee80211abg import EmaneIeee80211abgModel + + +def main(): + # interface helper + iface_helper = client.InterfaceHelper( + ip4_prefix="10.0.0.0/24", + ip6_prefix="2001::/64", + ) + + # create grpc client and connect + core = client.CoreGrpcClient() + core.connect() + + # create session + session = core.create_session() + + # create nodes + position = Position(x=375, y=500) + emane_net = session.add_node( + _id=1, + _type=NodeType.EMANE, + name="emane1", + position=position, + emane=EmaneIeee80211abgModel.name, + ) + position = Position(x=250, y=250) + node2 = session.add_node(_id=2, model="mdr", name="n2", position=position) + node2.config_services.add("ChatApp Server") + position = Position(x=500, y=250) + node3 = session.add_node(_id=3, model="mdr", name="n3", position=position) + + # create links to emane + node2_iface = iface_helper.create_iface(node_id=node2.id, iface_id=0) + node2_iface.ip4 = "10.0.0.1" + node2_iface.ip4_mask = 32 + node2_iface.ip6 = "2001::1" + node2_iface.ip6_mask = 128 + session.add_link(node1=node2, node2=emane_net, iface1=node2_iface) + node3_iface = iface_helper.create_iface(node_id=node3.id, iface_id=0) + node3_iface.ip4 = "10.0.0.2" + node3_iface.ip4_mask = 32 + node3_iface.ip6 = "2001::2" + node3_iface.ip6_mask = 128 + session.add_link(node1=node3, node2=emane_net, iface1=node3_iface) + + # start session + core.start_session(session=session) + + +if __name__ == "__main__": + main() diff --git a/package/examples/tutorials/tutorial7/scenario_service.xml b/package/examples/tutorials/tutorial7/scenario_service.xml new file mode 100644 index 00000000..da2cb8e8 --- /dev/null +++ b/package/examples/tutorials/tutorial7/scenario_service.xml @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tasks.py b/tasks.py index d8e55fec..b235e478 100644 --- a/tasks.py +++ b/tasks.py @@ -141,7 +141,7 @@ def get_os(install_type: Optional[str]) -> OsInfo: if not line: continue key, value = line.split("=") - d[key] = value.strip("\"") + d[key] = value.strip('"') name_value = d["ID"] like_value = d.get("ID_LIKE", "") version_value = d["VERSION_ID"] @@ -149,10 +149,10 @@ def get_os(install_type: Optional[str]) -> OsInfo: def check_existing_core(c: Context, hide: bool) -> None: - if c.run("python -c \"import core\"", warn=True, hide=hide): + if c.run('python -c "import core"', warn=True, hide=hide): raise SystemError("existing python core installation detected, please remove") python_bin = get_env_python() - if c.run(f"{python_bin} -c \"import core\"", warn=True, hide=hide): + if c.run(f'{python_bin} -c "import core"', warn=True, hide=hide): raise SystemError( f"existing {python_bin} core installation detected, please remove" ) @@ -166,7 +166,7 @@ def install_system(c: Context, os_info: OsInfo, hide: bool, no_python: bool) -> c.run( "sudo apt install -y automake pkg-config gcc libev-dev nftables " f"iproute2 ethtool tk bash", - hide=hide + hide=hide, ) if not no_python: c.run(f"sudo apt install -y {python_dep}-tk", hide=hide) @@ -194,7 +194,7 @@ def install_system(c: Context, os_info: OsInfo, hide: bool, no_python: bool) -> def install_grpcio(c: Context, hide: bool) -> None: python_bin = get_env_python() c.run( - f"{python_bin} -m pip install --user grpcio==1.49.1 grpcio-tools==1.49.1", + f"{python_bin} -m pip install --user grpcio==1.54.2 grpcio-tools==1.54.2", hide=hide, ) @@ -214,7 +214,7 @@ def install_poetry(c: Context, dev: bool, local: bool, hide: bool) -> None: if local: with c.cd(DAEMON_DIR): c.run("poetry build -f wheel", hide=hide) - c.run(f"sudo {python_bin} -m pip install dist/*") + c.run(f"sudo {python_bin} -m pip install dist/*") else: args = "" if dev else "--only main" with c.cd(DAEMON_DIR): @@ -243,7 +243,7 @@ def install_ospf_mdr(c: Context, os_info: OsInfo, hide: bool) -> None: "./configure --disable-doc --enable-user=root --enable-group=root " "--with-cflags=-ggdb --sysconfdir=/usr/local/etc/quagga --enable-vtysh " "--localstatedir=/var/run/quagga", - hide=hide + hide=hide, ) c.run("make -j$(nproc)", hide=hide) c.run("sudo make install", hide=hide) @@ -258,7 +258,8 @@ def install_service(c, verbose=False, prefix=DEFAULT_PREFIX): systemd_dir = Path("/lib/systemd/system/") service_file = systemd_dir.joinpath("core-daemon.service") if systemd_dir.exists(): - service_data = inspect.cleandoc(f""" + service_data = inspect.cleandoc( + f""" [Unit] Description=Common Open Research Emulator Service After=network.target @@ -270,7 +271,8 @@ def install_service(c, verbose=False, prefix=DEFAULT_PREFIX): [Install] WantedBy=multi-user.target - """) + """ + ) temp = NamedTemporaryFile("w", delete=False) temp.write(service_data) temp.close() @@ -289,10 +291,12 @@ def install_core_files(c, local=False, verbose=False, prefix=DEFAULT_PREFIX): if not local: core_python = bin_dir.joinpath("core-python") temp = NamedTemporaryFile("w", delete=False) - temp.writelines([ - "#!/bin/bash\n", - f'exec "{VENV_PYTHON}" "$@"\n', - ]) + temp.writelines( + [ + "#!/bin/bash\n", + f'exec "{VENV_PYTHON}" "$@"\n', + ] + ) temp.close() c.run(f"sudo cp {temp.name} {core_python}", hide=hide) c.run(f"sudo chmod 755 {core_python}", hide=hide) @@ -312,7 +316,7 @@ def install_core_files(c, local=False, verbose=False, prefix=DEFAULT_PREFIX): help={ "verbose": "enable verbose", "install-type": "used to force an install type, " - "can be one of the following (redhat, debian)", + "can be one of the following (redhat, debian)", "no-python": "avoid installing python system dependencies", }, ) @@ -344,7 +348,7 @@ def build( "local": "determines if core will install to local system, default is False", "prefix": f"prefix where scripts are installed, default is {DEFAULT_PREFIX}", "install-type": "used to force an install type, " - "can be one of the following (redhat, debian)", + "can be one of the following (redhat, debian)", "ospf": "disable ospf installation", "no-python": "avoid installing python system dependencies", }, @@ -399,7 +403,7 @@ def install( "emane-version": "version of emane install", "verbose": "enable verbose", "install-type": "used to force an install type, " - "can be one of the following (redhat, debian)", + "can be one of the following (redhat, debian)", }, ) def install_emane(c, emane_version, verbose=False, install_type=None): @@ -444,9 +448,7 @@ def install_emane(c, emane_version, verbose=False, install_type=None): c.run("make -j$(nproc)", hide=hide) with p.start("installing emane python bindings for core virtual environment"): with c.cd(DAEMON_DIR): - c.run( - f"poetry run pip install {emane_python_dir.absolute()}", hide=hide - ) + c.run(f"poetry run pip install {emane_python_dir.absolute()}", hide=hide) @task( @@ -489,7 +491,10 @@ def uninstall( if Path(VENV_PYTHON).is_file(): with c.cd(DAEMON_DIR): if dev: - c.run(f"{ACTIVATE_VENV} && poetry run pre-commit uninstall", hide=hide) + c.run( + f"{ACTIVATE_VENV} && poetry run pre-commit uninstall", + hide=hide, + ) c.run(f"sudo {VENV_PYTHON} -m pip uninstall -y core", hide=hide) # remove installed files bin_dir = Path(prefix).joinpath("bin") @@ -518,7 +523,7 @@ def uninstall( "prefix": f"prefix where scripts are installed, default is {DEFAULT_PREFIX}", "branch": "branch to install latest code from, default is current branch", "install-type": "used to force an install type, " - "can be one of the following (redhat, debian)", + "can be one of the following (redhat, debian)", }, ) def reinstall( @@ -528,7 +533,7 @@ def reinstall( local=False, prefix=DEFAULT_PREFIX, branch=None, - install_type=None + install_type=None, ): """ run the uninstall task, get latest from specified branch, and run install task