fix instantiation of network nodes
This commit is contained in:
@@ -639,10 +639,8 @@ class IPWiredNetworkInterface(WiredNetworkInterface, Layer3Interface, ABC):
|
|||||||
`default_gateway_hello` method is not defined, ignoring such errors to proceed without interruption.
|
`default_gateway_hello` method is not defined, ignoring such errors to proceed without interruption.
|
||||||
"""
|
"""
|
||||||
super().enable()
|
super().enable()
|
||||||
try:
|
if hasattr(self._connected_node, "default_gateway_hello"):
|
||||||
self._connected_node.default_gateway_hello()
|
self._connected_node.default_gateway_hello()
|
||||||
except AttributeError:
|
|
||||||
pass
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
|
|||||||
@@ -333,7 +333,7 @@ class HostNode(Node, discriminator="host-node"):
|
|||||||
class ConfigSchema(Node.ConfigSchema):
|
class ConfigSchema(Node.ConfigSchema):
|
||||||
"""Configuration Schema for HostNode class."""
|
"""Configuration Schema for HostNode class."""
|
||||||
|
|
||||||
type: Literal["host-node"]
|
type: Literal["host-node"] = "host-node"
|
||||||
hostname: str = "HostNode"
|
hostname: str = "HostNode"
|
||||||
subnet_mask: IPV4Address = "255.255.255.0"
|
subnet_mask: IPV4Address = "255.255.255.0"
|
||||||
ip_address: IPV4Address
|
ip_address: IPV4Address
|
||||||
@@ -375,7 +375,7 @@ class HostNode(Node, discriminator="host-node"):
|
|||||||
This method is invoked to ensure the host node can communicate with its default gateway, primarily to confirm
|
This method is invoked to ensure the host node can communicate with its default gateway, primarily to confirm
|
||||||
network connectivity and populate the ARP cache with the gateway's MAC address.
|
network connectivity and populate the ARP cache with the gateway's MAC address.
|
||||||
"""
|
"""
|
||||||
if self.operating_state == NodeOperatingState.ON and self.default_gateway:
|
if self.operating_state == NodeOperatingState.ON and self.config.default_gateway:
|
||||||
self.software_manager.arp.get_default_gateway_mac_address()
|
self.software_manager.arp.get_default_gateway_mac_address()
|
||||||
|
|
||||||
def receive_frame(self, frame: Frame, from_network_interface: NIC):
|
def receive_frame(self, frame: Frame, from_network_interface: NIC):
|
||||||
|
|||||||
@@ -1351,7 +1351,6 @@ class Router(NetworkNode, discriminator="router"):
|
|||||||
:return: A dictionary representing the current state.
|
:return: A dictionary representing the current state.
|
||||||
"""
|
"""
|
||||||
state = super().describe_state()
|
state = super().describe_state()
|
||||||
state["num_ports"] = self.config.num_ports
|
|
||||||
state["acl"] = self.acl.describe_state()
|
state["acl"] = self.acl.describe_state()
|
||||||
return state
|
return state
|
||||||
|
|
||||||
|
|||||||
@@ -103,8 +103,8 @@ class Switch(NetworkNode, discriminator="switch"):
|
|||||||
|
|
||||||
type: Literal["switch"] = "switch"
|
type: Literal["switch"] = "switch"
|
||||||
hostname: str = "Switch"
|
hostname: str = "Switch"
|
||||||
num_ports: int = 24
|
num_ports: int = 8
|
||||||
"The number of ports on the switch. Default is 24."
|
"The number of ports on the switch."
|
||||||
|
|
||||||
config: ConfigSchema = Field(default_factory=lambda: Switch.ConfigSchema())
|
config: ConfigSchema = Field(default_factory=lambda: Switch.ConfigSchema())
|
||||||
|
|
||||||
@@ -139,7 +139,6 @@ class Switch(NetworkNode, discriminator="switch"):
|
|||||||
"""
|
"""
|
||||||
state = super().describe_state()
|
state = super().describe_state()
|
||||||
state["ports"] = {port_num: port.describe_state() for port_num, port in self.network_interface.items()}
|
state["ports"] = {port_num: port.describe_state() for port_num, port in self.network_interface.items()}
|
||||||
state["num_ports"] = self.config.num_ports # redundant?
|
|
||||||
state["mac_address_table"] = {mac: port.port_num for mac, port in self.mac_address_table.items()}
|
state["mac_address_table"] = {mac: port.port_num for mac, port in self.mac_address_table.items()}
|
||||||
return state
|
return state
|
||||||
|
|
||||||
|
|||||||
@@ -137,8 +137,8 @@ class ARP(Service, discriminator="arp"):
|
|||||||
break
|
break
|
||||||
|
|
||||||
if use_default_gateway:
|
if use_default_gateway:
|
||||||
if self.software_manager.node.default_gateway:
|
if self.software_manager.node.config.default_gateway:
|
||||||
target_ip_address = self.software_manager.node.default_gateway
|
target_ip_address = self.software_manager.node.config.default_gateway
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ class Software(SimComponent, ABC):
|
|||||||
"""Configurable options for all software."""
|
"""Configurable options for all software."""
|
||||||
|
|
||||||
model_config = ConfigDict(extra="forbid")
|
model_config = ConfigDict(extra="forbid")
|
||||||
starting_health_state: SoftwareHealthState = SoftwareHealthState.UNUSED
|
starting_health_state: SoftwareHealthState = SoftwareHealthState.GOOD
|
||||||
criticality: SoftwareCriticality = SoftwareCriticality.LOWEST
|
criticality: SoftwareCriticality = SoftwareCriticality.LOWEST
|
||||||
fixing_duration: int = 2
|
fixing_duration: int = 2
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user