#2912 - Changes for extensible actions

This commit is contained in:
Charlie Crane
2024-12-13 09:49:21 +00:00
parent 47ed585ee2
commit 3c0a70be71
2 changed files with 9 additions and 22 deletions

View File

@@ -76,28 +76,8 @@ class ACLRemoveRuleAbstractAction(AbstractAction, identifier="acl_remove_rule_ab
class ConfigSchema(AbstractAction.ConfigSchema):
"""Configuration Schema base for ACL remove rule abstract actions."""
src_ip: str
protocol_name: str
position: int
@field_validator(
"src_ip",
mode="before",
)
@classmethod
def valid_ip(cls, v: str) -> str:
"""Check that a valid IP has been provided for src and dst."""
return ipv4_validator(v)
@field_validator(
"protocol_name",
mode="before",
)
@classmethod
def is_valid_protocol(cls, v: str) -> bool:
"""Check that we are using a valid protocol."""
return protocol_validator(v)
class RouterACLAddRuleAction(ACLAddRuleAbstractAction, identifier="router_acl_add_rule"):
"""Action which adds a rule to a router's ACL."""

View File

@@ -38,12 +38,18 @@ class DataManipulationAgent(AbstractScriptedAgent):
:rtype: Tuple[str, Dict]
"""
if timestep < self.next_execution_timestep:
self.logger.debug(msg="Performing do NOTHING")
self.logger.debug(msg="Performing do nothing")
return "do_nothing", {}
self._set_next_execution_timestep(timestep + self.agent_settings.start_settings.frequency)
self.logger.info(msg="Performing a data manipulation attack!")
return "NODE_APPLICATION_EXECUTE", {"node_id": self.starting_node_idx, "application_id": 0}
self.logger.info(msg=f"Chosen to attack {self.starting_node}")
# TODO: Why is the application_id hardcoded to target application 0?
return "node_application_execute", {
"type": "node_application_execute",
"node_name": self.starting_node,
"application_name": "test",
}
def setup_agent(self) -> None:
"""Set the next execution timestep when the episode resets."""
@@ -55,4 +61,5 @@ class DataManipulationAgent(AbstractScriptedAgent):
# we are assuming that every node in the node manager has a data manipulation application at idx 0
num_nodes = len(self.action_manager.node_names)
self.starting_node_idx = random.randint(0, num_nodes - 1)
self.starting_node = self.action_manager.node_names[self.starting_node_idx]
self.logger.debug(msg=f"Select Start Node ID: {self.starting_node_idx}")