Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
enriquetomasmb committed Nov 6, 2024
2 parents 4a9a2ce + 6ea274c commit 4d58cfa
Show file tree
Hide file tree
Showing 6 changed files with 838 additions and 98 deletions.
25 changes: 25 additions & 0 deletions nebula/addons/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
This package consists of several modules that handle different aspects of the network simulation:
1. `env.py`:
- Manages the environment configuration and settings.
- It initializes the system environment, loads configuration parameters, and ensures correct operation of other components based on the simulation's settings.
2. `functions.py`:
- Contains utility functions that are used across different parts of the simulation.
- It provides helper methods for common operations like data processing, mathematical calculations, and other reusable functionalities.
3. `mobility.py`:
- Models and simulates the mobility of nodes within the network.
- It handles dynamic aspects of the simulation, such as node movement and position updates, based on mobility models and the simulation's configuration.
4. `reporter.py`:
- Responsible for collecting and reporting data during the simulation.
- It tracks various system metrics, including node status and network performance, and periodically sends updates to a controller or dashboard for analysis and monitoring.
5. `topologymanager.py`:
- Manages the topology of the network.
- It handles the creation and maintenance of the network's structure (e.g., nodes and their connections), including generating different types of topologies like ring, random, or fully connected based on simulation parameters.
Each of these modules plays a critical role in simulating a network environment, enabling real-time tracking, topology management, mobility simulation, and efficient reporting of results.
"""
51 changes: 44 additions & 7 deletions nebula/addons/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,29 @@


def check_version():
# Check version of NEBULA (__version__ is defined in __init__.py) and compare with __version__ in https://raw.githubusercontent.com/CyberDataLab/nebula/main/nebula/__init__.py
"""
Checks the current version of NEBULA and compares it with the latest version available in the repository.
This function retrieves the latest NEBULA version from the specified GitHub repository and compares
it with the version defined in the local NEBULA package. If the versions do not match, it logs a message
prompting the user to update to the latest version.
Returns:
None
Raises:
SystemExit: If the version check fails or an exception occurs during the request.
Notes:
- The version information is expected to be defined in the `__init__.py` file of the NEBULA package
using the `__version__` variable.
- If the latest version is not the same as the local version, the program will exit after logging
the necessary information.
- An exception during the request will be logged, and the program will also exit.
"""
logging.info("Checking NEBULA version...")
try:
r = requests.get("https://raw.githubusercontent.com/CyberDataLab/nebula/main/nebula/__init__.py")
r = requests.get("https://raw.githubusercontent.com/CyberDataLab/nebula/main/nebula/__init__.py", timeout=5)
if r.status_code == 200:
version = re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]', r.text, re.MULTILINE).group(1)
if version != __version__:
Expand All @@ -26,12 +45,30 @@ def check_version():
sys.exit(0)
else:
logging.info(f"Your NEBULA version is {__version__} and it is the latest version.")
except Exception as e:
logging.exception(f"Error while checking NEBULA version: {e}")
except Exception:
logging.exception("Error while checking NEBULA version")
sys.exit(0)


def check_environment():
"""
Logs the current environment configuration for the NEBULA platform.
This function gathers and logs information about the operating system, hardware, Python version,
PyTorch version (if installed), CPU configuration, and GPU configuration (if applicable). It provides
insights into the system's capabilities and current usage statistics.
Returns:
None
Notes:
- The function logs the NEBULA platform version using the `__version__` variable.
- It checks the system's CPU load, available memory, and detailed GPU statistics using the `pynvml`
library if running on Windows or Linux.
- If any of the libraries required for gathering information (like `torch`, `psutil`, or `pynvml`)
are not installed, appropriate log messages will be generated indicating the absence of that information.
- If any unexpected error occurs during execution, it will be logged as an exception.
"""
logging.info(f"NEBULA Platform version: {__version__}")
# check_version()

Expand All @@ -46,7 +83,7 @@ def check_environment():
logging.info("PyTorch version: " + torch.__version__)
except ImportError:
logging.info("PyTorch is not installed properly")
except Exception:
except Exception: # noqa: S110
pass

logging.info("======== CPU Configuration ========")
Expand All @@ -62,7 +99,7 @@ def check_environment():
)
except ImportError:
logging.info("No CPU information available")
except Exception:
except Exception: # noqa: S110
pass

if sys.platform == "win32" or sys.platform == "linux":
Expand Down Expand Up @@ -93,7 +130,7 @@ def check_environment():
logging.info(f"GPU{i} fan speed: {gpu_fan_speed}")
except ImportError:
logging.info("pynvml module not found, GPU information unavailable")
except Exception:
except Exception: # noqa: S110
pass
else:
logging.info("GPU information unavailable")
36 changes: 29 additions & 7 deletions nebula/addons/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,36 @@


def print_msg_box(msg, indent=1, width=None, title=None, logger_name=None):
"""Print message-box with optional title."""
if logger_name:
logger = logging.getLogger(logger_name)
else:
logger = logging.getLogger()
"""
Prints a formatted message box to the logger with an optional title.
This function creates a visually appealing message box format for logging messages.
It allows for indentation, custom width, and inclusion of a title. If the message is
multiline, each line will be included in the box.
Args:
msg (str): The message to be displayed inside the box. Must be a string.
indent (int, optional): The number of spaces to indent the message box. Default is 1.
width (int, optional): The width of the message box. If not provided, it will be calculated
based on the longest line of the message and the title (if provided).
title (str, optional): An optional title for the message box. Must be a string if provided.
logger_name (str, optional): The name of the logger to use. If not provided, the root logger
will be used.
Raises:
TypeError: If `msg` or `title` is not a string.
Returns:
None
Notes:
- The message box is bordered with decorative characters to enhance visibility in the logs.
- If the `width` is not provided, it will automatically adjust to fit the content.
"""
logger = logging.getLogger(logger_name) if logger_name else logging.getLogger()

if not isinstance(msg, str):
raise TypeError("msg parameter must be a string")
raise TypeError("msg parameter must be a string") # noqa: TRY003

lines = msg.split("\n")
space = " " * indent
Expand All @@ -20,7 +42,7 @@ def print_msg_box(msg, indent=1, width=None, title=None, logger_name=None):
box = f"\n{'═' * (width + indent * 2)}\n" # upper_border
if title:
if not isinstance(title, str):
raise TypeError("title parameter must be a string")
raise TypeError("title parameter must be a string") # noqa: TRY003
box += f"║{space}{title:<{width}}{space}\n" # title
box += f"║{space}{'-' * len(title):<{width}}{space}\n" # underscore
box += "".join([f"║{space}{line:<{width}}{space}\n" for line in lines])
Expand Down
Loading

0 comments on commit 4d58cfa

Please sign in to comment.