2025-01-03 14:40:00 +00:00
|
|
|
# © Crown-owned copyright 2025, Defence Science and Technology Laboratory UK
|
2024-11-19 18:57:40 +00:00
|
|
|
from typing import ClassVar
|
2024-11-19 18:58:51 +00:00
|
|
|
|
2024-10-17 16:59:44 +01:00
|
|
|
from primaite.game.agent.actions.manager import AbstractAction
|
|
|
|
|
from primaite.interface.request import RequestFormat
|
|
|
|
|
|
2024-10-21 17:51:55 +01:00
|
|
|
__all__ = ("HostNICEnableAction", "HostNICDisableAction")
|
2024-10-18 12:07:53 +01:00
|
|
|
|
2024-10-21 17:51:55 +01:00
|
|
|
|
|
|
|
|
class HostNICAbstractAction(AbstractAction, identifier="host_nic_abstract"):
|
2024-10-17 16:59:44 +01:00
|
|
|
"""
|
|
|
|
|
Abstract base class for NIC actions.
|
|
|
|
|
|
|
|
|
|
Any action which applies to a NIC and uses node_id and nic_id as its only two parameters can inherit from this base
|
|
|
|
|
class.
|
|
|
|
|
"""
|
|
|
|
|
|
2024-11-19 18:57:40 +00:00
|
|
|
config: "HostNICAbstractAction.ConfigSchema"
|
2024-10-30 18:34:05 +00:00
|
|
|
|
2024-10-17 16:59:44 +01:00
|
|
|
class ConfigSchema(AbstractAction.ConfigSchema):
|
|
|
|
|
"""Base Configuration schema for HostNIC actions."""
|
2024-10-18 12:07:53 +01:00
|
|
|
|
2024-10-17 16:59:44 +01:00
|
|
|
node_name: str
|
2024-11-19 18:57:40 +00:00
|
|
|
nic_num: int
|
|
|
|
|
verb: ClassVar[str]
|
2024-10-17 16:59:44 +01:00
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def form_request(cls, config: ConfigSchema) -> RequestFormat:
|
|
|
|
|
"""Return the action formatted as a request which can be ingested by the PrimAITE simulation."""
|
|
|
|
|
if config.node_name is None or config.nic_num is None:
|
|
|
|
|
return ["do_nothing"]
|
2024-10-30 18:34:05 +00:00
|
|
|
return [
|
|
|
|
|
"network",
|
|
|
|
|
"node",
|
|
|
|
|
config.node_name,
|
|
|
|
|
"network_interface",
|
|
|
|
|
config.nic_num,
|
2024-11-19 18:57:40 +00:00
|
|
|
config.verb,
|
2024-10-30 18:34:05 +00:00
|
|
|
]
|
2024-10-17 16:59:44 +01:00
|
|
|
|
2024-10-18 12:07:53 +01:00
|
|
|
|
2024-10-18 14:52:50 +01:00
|
|
|
class HostNICEnableAction(HostNICAbstractAction, identifier="host_nic_enable"):
|
2024-10-17 16:59:44 +01:00
|
|
|
"""Action which enables a NIC."""
|
|
|
|
|
|
2024-11-19 18:57:40 +00:00
|
|
|
config: "HostNICEnableAction.ConfigSchema"
|
2024-10-30 18:34:05 +00:00
|
|
|
|
2024-10-17 16:59:44 +01:00
|
|
|
class ConfigSchema(HostNICAbstractAction.ConfigSchema):
|
|
|
|
|
"""Configuration schema for HostNICEnableAction."""
|
2024-10-18 12:07:53 +01:00
|
|
|
|
2024-10-17 16:59:44 +01:00
|
|
|
verb: str = "enable"
|
|
|
|
|
|
|
|
|
|
|
2024-10-18 14:52:50 +01:00
|
|
|
class HostNICDisableAction(HostNICAbstractAction, identifier="host_nic_disable"):
|
2024-10-17 16:59:44 +01:00
|
|
|
"""Action which disables a NIC."""
|
|
|
|
|
|
2024-11-19 18:57:40 +00:00
|
|
|
config: "HostNICDisableAction.ConfigSchema"
|
2024-10-30 18:34:05 +00:00
|
|
|
|
2024-10-17 16:59:44 +01:00
|
|
|
class ConfigSchema(HostNICAbstractAction.ConfigSchema):
|
|
|
|
|
"""Configuration schema for HostNICDisableAction."""
|
2024-10-18 12:07:53 +01:00
|
|
|
|
|
|
|
|
verb: str = "disable"
|