Merged PR 447: Bandwidth load / capacity checks before transmission
## Summary This pull request introduces significant enhancements to the AirSpace class within our network simulation software, aimed at improving the realism, configurability, and accuracy of wireless network simulations. These changes include the addition of new enums and attributes, enhancements to the configuration schema, and improvements in bandwidth management and transmission logic. **Additions** - **Enums and Attributes:** - **AirSpaceEnvironmentType Enum**: Defines various environmental settings that affect wireless signal propagation and interference. - **ChannelWidth Enum**: Specifies available channel width options for wireless interfaces. - **Channel Width Attribute**: Added to WirelessNetworkInterface for dynamic adjustments based on the operational environment. - **airspace_key Attribute**: A tuple identifying the frequency and channel width combination for bandwidth management. - **airspace_environment_type Attribute**: Sets the overall environmental context of the airspace, influencing all contained devices. - **Functional Enhancements:** - **SNR and Capacity Calculation Functions**: New functions estimate_snr and calculate_total_channel_capacity have been implemented to compute signal-to-noise ratios and channel capacities dynamically. - **show_bandwidth_load Function**: Provides a visual representation of the current bandwidth load across different channels. - **Dynamic Speed Setting**: The speed attribute of WirelessInterface is now adjusted dynamically based on frequency, channel width, and environment. - **Configuration and Testing:** - **Configuration Schema Update**: The simulation.network config file schema now supports setting the airspace_environment_type. **Changes** - **Interface and Performance Adjustments:** - **NetworkInterface Speed Type**: Changed from int to float for more precise speed definitions. - **Transmission Feasibility Check**: Updated the _can_transmit function in Link to better handle current load and bandwidth capacities. - **WirelessRouter Configurations**: The configure_wireless_access_point function now takes channel_width as an additional parameter. - **Grouping Adjustments**: WirelessNetworkInterfaces are now categorized by both AirSpaceFrequency and ChannelWidth. - **Transmission Logic Overhaul:** - **Interface Adjustments**: Modifying an interface's settings now necessitates its temporary removal from the airspace, followed by a recalculation of its data rate and reintegration under new settings. - **Blocking Overloads**: Strengthened the logic in AirSpace to prevent transmissions that would surpass the available capacity. **Fixes** - **Transmission Permission Logic**: Fixed the can_transmit_frame function to accurately enforce transmission limits based on current network load and available bandwidth. **Conclusion** These updates significantly enhance the fidelity and flexibility of our network simulation tool, enabling more accurate m...
This commit is contained in:
@@ -87,7 +87,7 @@ class NetworkInterface(SimComponent, ABC):
|
||||
mac_address: str = Field(default_factory=generate_mac_address)
|
||||
"The MAC address of the interface."
|
||||
|
||||
speed: int = 100
|
||||
speed: float = 100.0
|
||||
"The speed of the interface in Mbps. Default is 100 Mbps."
|
||||
|
||||
mtu: int = 1500
|
||||
@@ -499,14 +499,17 @@ class WiredNetworkInterface(NetworkInterface, ABC):
|
||||
:param frame: The network frame to be sent.
|
||||
:return: True if the frame is sent, False if the Network Interface is disabled or not connected to a link.
|
||||
"""
|
||||
if not self.enabled:
|
||||
return False
|
||||
if not self._connected_link.can_transmit_frame(frame):
|
||||
# Drop frame for now. Queuing will happen here (probably) if it's done in the future.
|
||||
self._connected_node.sys_log.info(f"{self}: Frame dropped as Link is at capacity")
|
||||
return False
|
||||
super().send_frame(frame)
|
||||
if self.enabled:
|
||||
frame.set_sent_timestamp()
|
||||
self.pcap.capture_outbound(frame)
|
||||
self._connected_link.transmit_frame(sender_nic=self, frame=frame)
|
||||
return True
|
||||
# Cannot send Frame as the NIC is not enabled
|
||||
return False
|
||||
frame.set_sent_timestamp()
|
||||
self.pcap.capture_outbound(frame)
|
||||
self._connected_link.transmit_frame(sender_nic=self, frame=frame)
|
||||
return True
|
||||
|
||||
@abstractmethod
|
||||
def receive_frame(self, frame: Frame) -> bool:
|
||||
@@ -737,12 +740,21 @@ class Link(SimComponent):
|
||||
"""
|
||||
return self.endpoint_a.enabled and self.endpoint_b.enabled
|
||||
|
||||
def _can_transmit(self, frame: Frame) -> bool:
|
||||
def can_transmit_frame(self, frame: Frame) -> bool:
|
||||
"""
|
||||
Determines whether a frame can be transmitted considering the current Link load and the Link's bandwidth.
|
||||
|
||||
This method assesses if the transmission of a given frame is possible without exceeding the Link's total
|
||||
bandwidth capacity. It checks if the current load of the Link plus the size of the frame (expressed in Mbps)
|
||||
would remain within the defined bandwidth limits. The transmission is only feasible if the Link is active
|
||||
('up') and the total load including the new frame does not surpass the bandwidth limit.
|
||||
|
||||
:param frame: The frame intended for transmission, which contains its size in Mbps.
|
||||
:return: True if the frame can be transmitted without exceeding the bandwidth limit, False otherwise.
|
||||
"""
|
||||
if self.is_up:
|
||||
frame_size_Mbits = frame.size_Mbits # noqa - Leaving it as Mbits as this is how they're expressed
|
||||
# return self.current_load + frame_size_Mbits <= self.bandwidth
|
||||
# TODO: re add this check once packet size limiting and MTU checks are implemented
|
||||
return True
|
||||
return self.current_load + frame.size_Mbits <= self.bandwidth
|
||||
return False
|
||||
|
||||
def transmit_frame(self, sender_nic: WiredNetworkInterface, frame: Frame) -> bool:
|
||||
@@ -753,11 +765,6 @@ class Link(SimComponent):
|
||||
:param frame: The network frame to be sent.
|
||||
:return: True if the Frame can be sent, otherwise False.
|
||||
"""
|
||||
can_transmit = self._can_transmit(frame)
|
||||
if not can_transmit:
|
||||
_LOGGER.debug(f"Cannot transmit frame as {self} is at capacity")
|
||||
return False
|
||||
|
||||
receiver = self.endpoint_a
|
||||
if receiver == sender_nic:
|
||||
receiver = self.endpoint_b
|
||||
|
||||
@@ -58,12 +58,16 @@ class SwitchPort(WiredNetworkInterface):
|
||||
:param frame: The network frame to be sent.
|
||||
:return: A boolean indicating whether the frame was successfully sent.
|
||||
"""
|
||||
if self.enabled:
|
||||
self.pcap.capture_outbound(frame)
|
||||
self._connected_link.transmit_frame(sender_nic=self, frame=frame)
|
||||
return True
|
||||
# Cannot send Frame as the SwitchPort is not enabled
|
||||
return False
|
||||
if not self.enabled:
|
||||
return False
|
||||
if not self._connected_link.can_transmit_frame(frame):
|
||||
# Drop frame for now. Queuing will happen here (probably) if it's done in the future.
|
||||
self._connected_node.sys_log.info(f"{self}: Frame dropped as Link is at capacity")
|
||||
return False
|
||||
|
||||
self.pcap.capture_outbound(frame)
|
||||
self._connected_link.transmit_frame(sender_nic=self, frame=frame)
|
||||
return True
|
||||
|
||||
def receive_frame(self, frame: Frame) -> bool:
|
||||
"""
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
# © Crown-owned copyright 2024, Defence Science and Technology Laboratory UK
|
||||
from ipaddress import IPv4Address
|
||||
from typing import Any, Dict, Union
|
||||
from typing import Any, Dict, Optional, Union
|
||||
|
||||
from pydantic import validate_call
|
||||
|
||||
from primaite.simulator.network.airspace import AirSpace, AirSpaceFrequency, IPWirelessNetworkInterface
|
||||
from primaite.simulator.network.airspace import AirSpace, AirSpaceFrequency, ChannelWidth, IPWirelessNetworkInterface
|
||||
from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState
|
||||
from primaite.simulator.network.hardware.nodes.network.router import ACLAction, Router, RouterInterface
|
||||
from primaite.simulator.network.transmission.data_link_layer import Frame
|
||||
@@ -153,7 +153,8 @@ class WirelessRouter(Router):
|
||||
self,
|
||||
ip_address: IPV4Address,
|
||||
subnet_mask: IPV4Address,
|
||||
frequency: AirSpaceFrequency = AirSpaceFrequency.WIFI_2_4,
|
||||
frequency: Optional[AirSpaceFrequency] = AirSpaceFrequency.WIFI_2_4,
|
||||
channel_width: Optional[ChannelWidth] = ChannelWidth.WIDTH_40_MHZ,
|
||||
):
|
||||
"""
|
||||
Configures a wireless access point (WAP).
|
||||
@@ -170,13 +171,23 @@ class WirelessRouter(Router):
|
||||
enum. This determines the frequency band (e.g., 2.4 GHz or 5 GHz) the access point will use for wireless
|
||||
communication. Default is AirSpaceFrequency.WIFI_2_4.
|
||||
"""
|
||||
if not frequency:
|
||||
frequency = AirSpaceFrequency.WIFI_2_4
|
||||
if not channel_width:
|
||||
channel_width = ChannelWidth.WIDTH_40_MHZ
|
||||
self.sys_log.info("Configuring wireless access point")
|
||||
|
||||
self.wireless_access_point.disable() # Temporarily disable the WAP for reconfiguration
|
||||
|
||||
network_interface = self.network_interface[1]
|
||||
|
||||
network_interface.ip_address = ip_address
|
||||
network_interface.subnet_mask = subnet_mask
|
||||
self.sys_log.info(f"Configured WAP {network_interface}")
|
||||
|
||||
self.wireless_access_point.frequency = frequency # Set operating frequency
|
||||
self.wireless_access_point.channel_width = channel_width
|
||||
self.wireless_access_point.enable() # Re-enable the WAP with new settings
|
||||
self.sys_log.info(f"Configured WAP {network_interface}")
|
||||
|
||||
@property
|
||||
def router_interface(self) -> RouterInterface:
|
||||
@@ -258,7 +269,12 @@ class WirelessRouter(Router):
|
||||
ip_address = cfg["wireless_access_point"]["ip_address"]
|
||||
subnet_mask = cfg["wireless_access_point"]["subnet_mask"]
|
||||
frequency = AirSpaceFrequency[cfg["wireless_access_point"]["frequency"]]
|
||||
router.configure_wireless_access_point(ip_address=ip_address, subnet_mask=subnet_mask, frequency=frequency)
|
||||
channel_width = cfg["wireless_access_point"].get("channel_width")
|
||||
if channel_width:
|
||||
channel_width = ChannelWidth(channel_width)
|
||||
router.configure_wireless_access_point(
|
||||
ip_address=ip_address, subnet_mask=subnet_mask, frequency=frequency, channel_width=channel_width
|
||||
)
|
||||
|
||||
if "acl" in cfg:
|
||||
for r_num, r_cfg in cfg["acl"].items():
|
||||
|
||||
Reference in New Issue
Block a user