#1706 - Got the core Node class build and working with ARP and the ability to ping another node. Added some basic tests in. Next job is to create the Node subclasses. Then move ARP and ICMP into a service that is used by all nodes.
This commit is contained in:
27
src/primaite/simulator/network/utils.py
Normal file
27
src/primaite/simulator/network/utils.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from typing import Union
|
||||
|
||||
|
||||
def convert_bytes_to_megabits(B: Union[int, float]) -> float: # noqa - Keep it as B as this is how Bytes are expressed
|
||||
"""
|
||||
Convert Bytes (file size) to Megabits (data transfer).
|
||||
|
||||
:param B: The file size in Bytes.
|
||||
:return: File bits to transfer in Megabits.
|
||||
"""
|
||||
if isinstance(B, int):
|
||||
B = float(B)
|
||||
bits = B * 8.0
|
||||
return bits / 1024.0**2.0
|
||||
|
||||
|
||||
def convert_megabits_to_bytes(Mbits: Union[int, float]) -> float: # noqa - The same for Mbits
|
||||
"""
|
||||
Convert Megabits (data transfer) to Bytes (file size).
|
||||
|
||||
:param Mbits bits to transfer in Megabits.
|
||||
:return: The file size in Bytes.
|
||||
"""
|
||||
if isinstance(Mbits, int):
|
||||
Mbits = float(Mbits)
|
||||
bits = Mbits * 1024.0**2.0
|
||||
return bits / 8
|
||||
Reference in New Issue
Block a user