diff --git a/.gitignore b/.gitignore index 8b12dbe..b9db6e7 100644 --- a/.gitignore +++ b/.gitignore @@ -60,4 +60,4 @@ demo/images/ue_amr/nav_stack .DS_Store demo/open5gs_setup/db_data/* -demo_containerized/open5gs_setup/db_data/* \ No newline at end of file +demo_containerized/open5gs_setup/db_data/* diff --git a/README.md b/README.md index 2243c20..cc5166d 100644 --- a/README.md +++ b/README.md @@ -32,9 +32,27 @@ The table of content of this README file is: - [UE World file declaration](#-ue-world-file-declaration) -5. [Modifying the source code](#modify-gnb-source-code) +5. [Network Monitor Plugin](#-network-monitor-plugin) -6. [Upcoming features](#upcoming-features) + - [Why monitor the network in a ROS 2 5G simulation](#-why-monitor-the-network-in-a-ros-2-5g-simulation) + + - [Plugin behavior](#-plugin-behavior) + + - [Usage](#-usage) + + - [Configuration parameters](#-configuration-parameters) + +6. [gNB Power and UE Power Control Plugins](#-gnb-power-and-ue-power-control-plugins) + + - [What they do](#-what-they-do) + + - [How they work](#-how-they-work) + + - [Usage](#-usage-1) + + - [Configuration parameters](#-configuration-parameters-1) + +7. [Modifying the source code](#modify-gnb-source-code) If something goes wrong in following this README file or you have any questions, you can write on our [slack chat](https://join.slack.com/t/robosimworkspace/shared_invite/zt-38i7sbsit-FpsT6d7PU241~nGz0fcUig). @@ -761,6 +779,286 @@ To add the UE plugin to your SDF world file, include: - Be sure to follow the same network and workspace structure as the demo for compatibility. +## 📊 Network Monitor Plugin + +The **Network Monitor** is an Ignition Gazebo GUI plugin that provides real-time measurement of **latency** and **bandwidth** over the simulated 5G link between a User Equipment (UE) container and the Data Network (DN) container. It uses `ping` for latency and `iperf3` for bandwidth, executed via `docker exec` on the respective containers. + +--- + +### 🤔 Why Monitor the Network in a ROS 2 5G Simulation + +In any ROS 2 robotic application, the communication layer has a direct impact on system performance and safety. ROS 2 relies on DDS (Data Distribution Service) for all inter-node communication — including publishing sensor data, sending navigation goals, and exchanging control commands. When this communication happens over a **5G network** instead of a local Ethernet or Wi-Fi link, the characteristics of that network become a critical factor: + +- **Latency affects control loops.** ROS 2 navigation stacks (e.g., Nav2) and teleoperation nodes depend on timely delivery of odometry, laser scans, and velocity commands. A latency spike over the 5G link can cause the robot to overshoot a waypoint, react late to an obstacle, or lose localization. Knowing the real-time round-trip time helps you understand whether your control loop frequency is achievable. + +- **Bandwidth affects data-heavy topics.** Point clouds, camera images, and map updates are large messages. If the 5G uplink or downlink bandwidth is insufficient, DDS will drop messages or queue them, leading to stale data at the subscriber side. Monitoring bandwidth lets you verify that the 5G link can sustain the throughput your application requires. + +- **5G behavior is not static.** Unlike a wired connection, a 5G link is subject to variability due to radio scheduling, handovers, and shared spectrum. Having a live monitor during simulation lets you correlate network conditions with robot behavior — for example, observing that navigation failures coincide with a bandwidth drop. + +- **Validation before field deployment.** RoboSim5G is designed to let roboticists test their applications over a realistic 5G stack before deploying on physical hardware. The Network Monitor closes the loop: you can verify that the network performance meets the requirements of your ROS 2 application (e.g., < 50 ms RTT for teleoperation, > 10 Mbits/sec for video streaming) entirely within the simulation. + +In short, if you are running ROS 2 topics over a 5G network, you should monitor that network — the Network Monitor plugin gives you that visibility directly inside Gazebo. + +--- + +### ⚙️ Plugin Behavior + +Once started, the plugin: + +1. Launches an **iperf3 server** in daemon mode on the UE container. +2. Enters a continuous measurement loop that performs, in each cycle: + - **Downlink latency**: `ping` from the DN container to the UE IP (1 packet, 1 s timeout). + - **Uplink latency**: `ping` from the UE container to the DN IP (1 packet, 1 s timeout). + - **Downlink bandwidth**: `iperf3` from the DN client to the UE server (1 s test). + - **Uplink bandwidth**: `iperf3` in reverse mode (`-R` flag) (1 s test). +3. Updates the GUI with the latest results after each cycle. +4. When stopped, kills the iperf3 server on the UE container. + +Each measurement cycle takes approximately **4 seconds**, keeping the overhead low enough to avoid slowing down the simulation. + +--- + +### 🚀 Usage + +The Network Monitor is a **GUI plugin** that can be added to your Gazebo Ignition world file or loaded at runtime from the Gazebo GUI plugin menu. + +#### Adding to an SDF World File + +Add the following block inside the `` section of your world file: + +```xml + + + 10.0.0.1 + 192.168.70.135 + ue_turtlebot + oai-ext-dn + + +``` + +All parameters are optional — they can also be set at runtime from the GUI text fields. + +#### Environment Variable + +The UE container name can also be set via the `UE_NAME_FOR_BUTTON` environment variable: + +```bash +export UE_NAME_FOR_BUTTON=ue_turtlebot +``` + +If set, it overrides the default value (`ue_turtlebot`). A value provided in the SDF `` element takes precedence over the environment variable. + +#### Runtime + +Once the plugin is loaded in Gazebo: + +1. Enter the **UE IP** (the 5G tunnel IP assigned to the UE, e.g., `10.0.0.1`) and the **DN IP** (the Data Network container IP, e.g., `192.168.70.135`). +2. Click **Start Test** to begin continuous monitoring. +3. The panel displays live uplink/downlink latency and bandwidth. +4. Click **Stop Test** to end the measurement loop. + +--- + +### 🔧 Configuration Parameters + +| **Parameter** | **Description** | **Default** | +| -------------------- | ------------------------------------------------------------------------------- | --------------- | +| `ue_ip` | 5G tunnel IP of the UE (e.g., `10.0.0.1`). Can be set from the GUI at runtime. | _(empty)_ | +| `dn_ip` | IP of the Data Network container (e.g., `192.168.70.135`). Can be set from GUI. | _(empty)_ | +| `ue_container_name` | Docker container name of the UE | `ue_turtlebot` | +| `dn_container_name` | Docker container name of the Data Network node | `oai-ext-dn` | + +--- + +### ⚠️ Prerequisites + +- **iperf3** must be installed inside both the UE and DN containers. +- **ping** must be available inside both containers. +- The Gazebo host must have **Docker access** (the plugin runs `docker exec` commands). +- The plugin shared library (`libNetworkMonitor.so`) must be in a path listed in `IGN_GAZEBO_GUI_PLUGIN_PATH`. + +--- + +## 🔌 gNB Power and UE Power Control Plugins + +The **gNB Power Plugin** and **UE Power Plugin** are Ignition Gazebo GUI plugins that provide **runtime control** over the 5G radio processes (gNB and UE softmodems) running inside Docker containers. These plugins allow you to **start, stop, and monitor** the OAI radio software directly from the Gazebo GUI without needing to manually execute Docker commands. + +--- + +### 🎯 What They Do + +Both plugins provide a graphical interface to: + +- 🟢 **Start/Stop** the radio process (`nr-softmodem` for gNB, `nr-uesoftmodem` for UE) inside the container +- 🔄 **Toggle between OAI versions** (v24 and v26) which use different configuration file formats +- 📊 **Monitor process state** (running/stopped) with visual indicators +- 🔧 **Configure runtime parameters** like container names, IP addresses, and OAI version + +This is particularly useful during simulation development and testing, where you may need to: +- Verify 5G connectivity by restarting the UE or gNB +- Test failure scenarios by stopping the radio link +- Switch between OAI versions without rebuilding containers +- Observe how your robot application handles connection loss + +--- + +### ⚡ How They Work + +#### gNB Power Plugin + +1. **First Click** (Connect): Checks if the `nr-softmodem` process is running in the specified gNB container +2. **Subsequent Clicks** (Toggle): Starts or stops the gNB radio process using the appropriate command for the selected version: + - **v24**: Launches with `.conf` configuration file and `--sa` flag + - **v26**: Launches with `.yaml` configuration file (no `--sa` flag) + +#### UE Power Plugin + +Works similarly to the gNB plugin, but controls the `nr-uesoftmodem` process in the UE container: +- **v24**: Uses `.conf` file with frequency `3619200000` Hz +- **v26**: Uses `.yaml` file with frequency `3319680000` Hz +- Requires the **gNB IP address** to establish the RF simulator connection + +--- + +### 🚀 Usage + +Both plugins are **GUI plugins** that can be added to your Gazebo Ignition world file or loaded at runtime from the Gazebo GUI plugin menu. + +#### Adding to an SDF World File + +Add the following blocks inside the `` section of your world file: + +##### gNB Power Plugin + +```xml + + + oai-gNB1 + v24 + + +``` + +##### UE Power Plugin + +```xml + + + ue_turtlebot + v24 + 192.168.70.160 + + +``` + +All parameters are optional and can be configured at runtime from the GUI. + +#### Environment Variable for UE Plugin + +The UE container name can be set via the `UE_NAME_FOR_BUTTON` environment variable: + +```bash +export UE_NAME_FOR_BUTTON=ue_turtlebot +``` + +If set, this overrides the default value. A value provided in the SDF `` element takes precedence. + +--- + +### 🖥️ GUI Interface + +#### gNB Power Control Panel + +When loaded, the plugin displays: +- **Container Name Field**: Name of the gNB Docker container (e.g., `oai-gNB1`) +- **Version Selector**: Dropdown to choose between "v24 (.conf)" and "v26 (.yaml)" +- **Power Button**: + - First click: **Connect** to the container and check process status + - Subsequent clicks: **Toggle** the gNB process on/off + - Color indicators: 🟢 Green (running) / 🔴 Red (stopped) +- **Status Display**: Shows current connection and process state + +#### UE Power Control Panel + +Similar to gNB, with an additional field: +- **Container Name Field**: Name of the UE Docker container (e.g., `ue_turtlebot`) +- **Version Selector**: Choose between v24 and v26 +- **gNB IP Field**: IP address of the gNB for RF simulator connection (e.g., `192.168.70.160`) +- **Power Button**: Connect and toggle the UE process +- **Status Display**: Connection and process state + +**Note**: Container name, version, and gNB IP can only be changed **before** the first connection. Once connected, these fields are locked to prevent accidental misconfiguration during active radio sessions. + +--- + +### 🔧 Configuration Parameters + +#### gNB Power Plugin Parameters + +| **Parameter** | **Description** | **Default** | +| ---------------- | --------------------------------------------------------- | ------------- | +| `container_name` | Docker container name of the gNB | `oai-gNB1` | +| `version` | OAI version: `v24` (uses .conf) or `v26` (uses .yaml) | `v24` | + +#### UE Power Plugin Parameters + +| **Parameter** | **Description** | **Default** | +| ---------------- | --------------------------------------------------------- | ----------------- | +| `container_name` | Docker container name of the UE | `ue_turtlebot` | +| `version` | OAI version: `v24` (uses .conf) or `v26` (uses .yaml) | `v24` | +| `gnb_ip` | IP address of the gNB container for RF simulator | `192.168.70.160` | + +--- + +### ✅ Tested Configurations + +These plugins have been **tested and verified** with: +- **OAI 5G Core Network** (`oai_setup`) +- **demo** mode (Gazebo on host) +- **demo_containerized** mode (Gazebo in Docker) + +Support for **free5GC** and **Open5GS** core networks is planned for future releases. + +--- + +### 💡 Typical Workflow + +1. **Launch your OAI 5G core network**: + ```bash + cd path/demo/oai_setup + docker compose up -d + ``` + +2. **Launch gNB and UE containers** (without starting the radio processes): + ```bash + docker compose -f docker-compose-gNB.yml up -d + docker compose -f docker-compose-ue.yml up -d + ``` + +3. **Start Gazebo** with your world file that includes the power plugins + +4. **In Gazebo GUI**: + - Open the **gNB Power Control** panel + - Verify container name and version + - Click **Connect** to check status + - Click **Power Toggle** to start the gNB radio + +5. **Then control the UE**: + - Open the **UE Power Control** panel + - Verify container name, version, and gNB IP + - Click **Connect** to check status + - Click **Power Toggle** to start the UE and establish the 5G connection + +6. **Monitor AMF logs** to verify successful registration: + ```bash + docker logs oai-amf + ``` + +You should see the UE appear in the AMF's registered UEs table. + +--- + ## Modify source code The source code of the plugins is at `path/phine-plugins/src/phine_plugins/src`. You can modify it as you wish consulting [Coding Guidelines](CODE_OF_CONDUCT.md) and [Contributing](CONTRIBUTING.md) and in case you would like to share your work. Once you have modified the code, delete `path/phine-plugins/log`,`path/phine-plugins/install`,`path/phine-plugins/build` and run in `path/phine-plugins`(with `path` the path to main folder of the repo): diff --git a/demo/gazebo_launch/src/ign_turtlebot/gui_plugins/libNetworkMonitor.so b/demo/gazebo_launch/src/ign_turtlebot/gui_plugins/libNetworkMonitor.so new file mode 100755 index 0000000..669b704 Binary files /dev/null and b/demo/gazebo_launch/src/ign_turtlebot/gui_plugins/libNetworkMonitor.so differ diff --git a/demo/gazebo_launch/src/ign_turtlebot/gui_plugins/libUE_PowerPlugin.so b/demo/gazebo_launch/src/ign_turtlebot/gui_plugins/libUE_PowerPlugin.so deleted file mode 100755 index dd08798..0000000 Binary files a/demo/gazebo_launch/src/ign_turtlebot/gui_plugins/libUE_PowerPlugin.so and /dev/null differ diff --git a/demo/gazebo_launch/src/ign_turtlebot/gui_plugins/libUePowerPlugin.so b/demo/gazebo_launch/src/ign_turtlebot/gui_plugins/libUePowerPlugin.so new file mode 100755 index 0000000..f616df7 Binary files /dev/null and b/demo/gazebo_launch/src/ign_turtlebot/gui_plugins/libUePowerPlugin.so differ diff --git a/demo/gazebo_launch/src/ign_turtlebot/gui_plugins/libgNBPowerPlugin.so b/demo/gazebo_launch/src/ign_turtlebot/gui_plugins/libgNBPowerPlugin.so new file mode 100755 index 0000000..5f0ab46 Binary files /dev/null and b/demo/gazebo_launch/src/ign_turtlebot/gui_plugins/libgNBPowerPlugin.so differ diff --git a/demo/gazebo_launch/src/ign_turtlebot/gui_plugins/libgNB_PowerPlugin.so b/demo/gazebo_launch/src/ign_turtlebot/gui_plugins/libgNB_PowerPlugin.so deleted file mode 100755 index fbdc069..0000000 Binary files a/demo/gazebo_launch/src/ign_turtlebot/gui_plugins/libgNB_PowerPlugin.so and /dev/null differ diff --git a/demo/images/ue_amr/Dockerfile b/demo/images/ue_amr/Dockerfile index ecb2308..4f8f272 100644 --- a/demo/images/ue_amr/Dockerfile +++ b/demo/images/ue_amr/Dockerfile @@ -49,6 +49,7 @@ RUN apt-get install -y libignition-transport8-dev RUN apt-get install -y libignition-tools-dev RUN apt-get install -y ros-humble-ros-ign-bridge RUN apt-get install -y iptables +RUN apt-get install -y iperf3 iputils-ping WORKDIR /app diff --git a/demo/oai_setup/conf/gnb.sa.bandn78.fr1.106PRB.rfsim.conf b/demo/oai_setup/conf/gnb.sa.bandn78.fr1.106PRB.rfsim.conf index 2a9b0d6..3b411b7 100644 --- a/demo/oai_setup/conf/gnb.sa.bandn78.fr1.106PRB.rfsim.conf +++ b/demo/oai_setup/conf/gnb.sa.bandn78.fr1.106PRB.rfsim.conf @@ -1,4 +1,4 @@ -Active_gNBs = ("gNB1"); +Active_gNBs = ("gNB1"); # Asn1_verbosity, choice in: none, info, annoying Asn1_verbosity = "none"; @@ -6,17 +6,17 @@ gNBs = ( { ////////// Identification parameters: - gNB_ID = 0x1; + gNB_ID = 0x1; # cell_type = "CELL_MACRO_GNB"; - gNB_name = "gNB1"; + gNB_name = "gNB1"; // Tracking area code, 0x0000 and 0xfffe are reserved values tracking_area_code = 1; - plmn_list = ({ mcc = 001; - mnc = 01; + plmn_list = ({ mcc = 001; + mnc = 01; mnc_length = 2; snssaiList = ({ sst = 1, sd = 0xffffff }, { sst = 1, sd = 0x1 }) }); @@ -183,7 +183,7 @@ gNBs = ////////// AMF parameters: ##modify - amf_ip_address = ( { ipv4 = "192.168.70.132"; + amf_ip_address = ( { ipv4 = "192.168.70.132"; ipv6 = "192:168:30::17"; active = "yes"; preference = "ipv4"; @@ -194,9 +194,9 @@ gNBs = { ## modify GNB_INTERFACE_NAME_FOR_NG_AMF = "eth0"; - GNB_IPV4_ADDRESS_FOR_NG_AMF = "192.168.70.160"; + GNB_IPV4_ADDRESS_FOR_NG_AMF = "192.168.70.160"; GNB_INTERFACE_NAME_FOR_NGU = "eth0"; - GNB_IPV4_ADDRESS_FOR_NGU = "192.168.70.160"; + GNB_IPV4_ADDRESS_FOR_NGU = "192.168.70.160"; GNB_PORT_FOR_S1U = 2152; # Spec 2152 }; diff --git a/demo/oai_setup/conf/ue1.conf b/demo/oai_setup/conf/ue1.conf index 326e1aa..8168379 100644 --- a/demo/oai_setup/conf/ue1.conf +++ b/demo/oai_setup/conf/ue1.conf @@ -1,8 +1,8 @@ uicc0 = { -imsi = "001010000000101"; -key = "fec86ba6eb707ed08905757b1bb44b8f"; -opc = "C42449363BBAD02B66D16BC975D77CC1"; -dnn = "oai"; -nssai_sst = "1"; -#nssai_sd = "no"; +imsi = "001010000000101"; +key = "fec86ba6eb707ed08905757b1bb44b8f"; +opc = "C42449363BBAD02B66D16BC975D77CC1"; +dnn = "oai"; +nssai_sst = "1"; +#nssai_sd = "no"; } diff --git a/demo_containerized/images/simulation/Dockerfile b/demo_containerized/images/simulation/Dockerfile index 8339a85..4205c87 100644 --- a/demo_containerized/images/simulation/Dockerfile +++ b/demo_containerized/images/simulation/Dockerfile @@ -16,7 +16,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ # Clean up apt cache in the same RUN instruction && rm -rf /var/lib/apt/lists/* -RUN apt-get update && apt-get install -y net-tools iproute2 iputils-ping +RUN apt-get update && apt-get install -y net-tools iproute2 iputils-ping iperf3 RUN apt-get update && apt-get install -y \ curl \ diff --git a/demo_containerized/images/simulation/gazebo_launch/src/ign_turtlebot/gui_plugins/libNetworkMonitor.so b/demo_containerized/images/simulation/gazebo_launch/src/ign_turtlebot/gui_plugins/libNetworkMonitor.so new file mode 100755 index 0000000..669b704 Binary files /dev/null and b/demo_containerized/images/simulation/gazebo_launch/src/ign_turtlebot/gui_plugins/libNetworkMonitor.so differ diff --git a/demo_containerized/images/simulation/gazebo_launch/src/ign_turtlebot/gui_plugins/libUePowerPlugin.so b/demo_containerized/images/simulation/gazebo_launch/src/ign_turtlebot/gui_plugins/libUePowerPlugin.so new file mode 100755 index 0000000..f616df7 Binary files /dev/null and b/demo_containerized/images/simulation/gazebo_launch/src/ign_turtlebot/gui_plugins/libUePowerPlugin.so differ diff --git a/demo_containerized/images/simulation/gazebo_launch/src/ign_turtlebot/gui_plugins/libgNBPowerPlugin.so b/demo_containerized/images/simulation/gazebo_launch/src/ign_turtlebot/gui_plugins/libgNBPowerPlugin.so new file mode 100755 index 0000000..5f0ab46 Binary files /dev/null and b/demo_containerized/images/simulation/gazebo_launch/src/ign_turtlebot/gui_plugins/libgNBPowerPlugin.so differ diff --git a/demo_containerized/images/simulation/images/ue_amr/Dockerfile b/demo_containerized/images/simulation/images/ue_amr/Dockerfile index ecb2308..4f8f272 100644 --- a/demo_containerized/images/simulation/images/ue_amr/Dockerfile +++ b/demo_containerized/images/simulation/images/ue_amr/Dockerfile @@ -49,6 +49,7 @@ RUN apt-get install -y libignition-transport8-dev RUN apt-get install -y libignition-tools-dev RUN apt-get install -y ros-humble-ros-ign-bridge RUN apt-get install -y iptables +RUN apt-get install -y iperf3 iputils-ping WORKDIR /app diff --git a/phine-plugins/src/phine_plugins/CMakeLists.txt b/phine-plugins/src/phine_plugins/CMakeLists.txt index b4eb8e5..ae2a620 100644 --- a/phine-plugins/src/phine_plugins/CMakeLists.txt +++ b/phine-plugins/src/phine_plugins/CMakeLists.txt @@ -1,6 +1,9 @@ cmake_minimum_required(VERSION 3.8) project(phine_plugins) +# Allow AUTOMOC to process .hh files +cmake_policy(SET CMP0100 NEW) + if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-Wall -Wextra -Wpedantic) endif() @@ -35,9 +38,78 @@ set_property(TARGET UE_plugin PROPERTY CXX_STANDARD 17) # adding gazebo gazebo-plugin and ros libraries ament_target_dependencies(UE_plugin ignition-plugin${IGN_PLUGIN_VER} ignition-gazebo${IGN_GAZEBO_VER} rclcpp std_msgs) -# Install the plugin + +# ---- NetworkMonitor GUI Plugin ---- +find_package(Qt5 REQUIRED COMPONENTS Core Quick) +ign_find_package(ignition-gui6 REQUIRED) +set(IGN_GUI_VER ${ignition-gui6_VERSION_MAJOR}) + +# Process Qt resource file (embeds QML into the shared library) +qt5_add_resources(NETWORK_MONITOR_QRC src/NetworkMonitor.qrc) + +add_library(NetworkMonitor SHARED + src/NetworkMonitor.cc + ${NETWORK_MONITOR_QRC} +) +set_property(TARGET NetworkMonitor PROPERTY CXX_STANDARD 17) +set_target_properties(NetworkMonitor PROPERTIES AUTOMOC ON) + +target_include_directories(NetworkMonitor PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/src +) + +target_link_libraries(NetworkMonitor + ignition-gui${IGN_GUI_VER}::ignition-gui${IGN_GUI_VER} + ignition-plugin${IGN_PLUGIN_VER}::register + Qt5::Core + Qt5::Quick +) + +# ---- gNBPowerPlugin GUI Plugin ---- +qt5_add_resources(GNB_POWER_QRC src/gNBPowerPlugin.qrc) + +add_library(gNBPowerPlugin SHARED + src/gNBPowerPlugin.cc + ${GNB_POWER_QRC} +) +set_property(TARGET gNBPowerPlugin PROPERTY CXX_STANDARD 17) +set_target_properties(gNBPowerPlugin PROPERTIES AUTOMOC ON) + +target_include_directories(gNBPowerPlugin PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/src +) + +target_link_libraries(gNBPowerPlugin + ignition-gui${IGN_GUI_VER}::ignition-gui${IGN_GUI_VER} + ignition-plugin${IGN_PLUGIN_VER}::register + Qt5::Core + Qt5::Quick +) + +# ---- UePowerPlugin GUI Plugin ---- +qt5_add_resources(UE_POWER_QRC src/UePowerPlugin.qrc) + +add_library(UePowerPlugin SHARED + src/UePowerPlugin.cc + ${UE_POWER_QRC} +) +set_property(TARGET UePowerPlugin PROPERTY CXX_STANDARD 17) +set_target_properties(UePowerPlugin PROPERTIES AUTOMOC ON) + +target_include_directories(UePowerPlugin PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/src +) + +target_link_libraries(UePowerPlugin + ignition-gui${IGN_GUI_VER}::ignition-gui${IGN_GUI_VER} + ignition-plugin${IGN_PLUGIN_VER}::register + Qt5::Core + Qt5::Quick +) + +# Install the plugins install(TARGETS -UE_plugin gNB_plugin +UE_plugin gNB_plugin NetworkMonitor gNBPowerPlugin UePowerPlugin DESTINATION lib/${PROJECT_NAME}) ament_package() diff --git a/phine-plugins/src/phine_plugins/src/NetworkMonitor.cc b/phine-plugins/src/phine_plugins/src/NetworkMonitor.cc new file mode 100644 index 0000000..c638470 --- /dev/null +++ b/phine-plugins/src/phine_plugins/src/NetworkMonitor.cc @@ -0,0 +1,347 @@ +/* Copyright 2025 phine.tech GmbH + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License.*/ + +#include "NetworkMonitor.hh" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Register this plugin with Ignition GUI +IGNITION_ADD_PLUGIN(phine_plugins::NetworkMonitor, ignition::gui::Plugin) + +using namespace phine_plugins; + +NetworkMonitor::NetworkMonitor() { + ignmsg << "[NetworkMonitor] constructor called" << std::endl; + + // Read UE container name from environment variable, fallback to default + const char *ue_name_env = std::getenv("UE_NAME_FOR_BUTTON"); + if (ue_name_env != nullptr) { + this->ue_container_name = std::string(ue_name_env); + } else { + this->ue_container_name = "ue_turtlebot"; + } + + ignmsg << "[NetworkMonitor] UE container: " << this->ue_container_name + << std::endl; + ignmsg << "[NetworkMonitor] DN container: " << this->dn_container_name + << std::endl; +} + +NetworkMonitor::~NetworkMonitor() { + ignmsg << "[NetworkMonitor] destructor called" << std::endl; + // Stop the test loop if still running + if (this->is_running.load()) { + this->is_running.store(false); + } + if (this->test_thread.joinable()) { + this->test_thread.join(); + } +} + +/** + * @brief Loads plugin configuration from an XML element. + * + * Optionally reads default IP addresses and container names from the plugin + * configuration in the SDF or GUI config file. + * + * @param _pluginElem Pointer to the XML element containing plugin config. + */ +void NetworkMonitor::LoadConfig(const tinyxml2::XMLElement *_pluginElem) { + if (this->title.empty()) { + this->title = "Network Monitor"; + } + + if (_pluginElem == nullptr) { + return; + } + + // Read optional default UE IP from config + auto *ue_ip_elem = _pluginElem->FirstChildElement("ue_ip"); + if (ue_ip_elem != nullptr && ue_ip_elem->GetText() != nullptr) { + this->ue_ip = QString::fromStdString(ue_ip_elem->GetText()); + } + + // Read optional default DN IP from config + auto *dn_ip_elem = _pluginElem->FirstChildElement("dn_ip"); + if (dn_ip_elem != nullptr && dn_ip_elem->GetText() != nullptr) { + this->dn_ip = QString::fromStdString(dn_ip_elem->GetText()); + } + + // Allow overriding container names via config + auto *ue_container_elem = + _pluginElem->FirstChildElement("ue_container_name"); + if (ue_container_elem != nullptr && + ue_container_elem->GetText() != nullptr) { + this->ue_container_name = ue_container_elem->GetText(); + } + + auto *dn_container_elem = + _pluginElem->FirstChildElement("dn_container_name"); + if (dn_container_elem != nullptr && + dn_container_elem->GetText() != nullptr) { + this->dn_container_name = dn_container_elem->GetText(); + } +} + +QString NetworkMonitor::getUeIp() const { return this->ue_ip; } + +void NetworkMonitor::setUeIp(const QString &ip) { + if (this->ue_ip != ip) { + this->ue_ip = ip; + emit ueIpChanged(); + } +} + +QString NetworkMonitor::getDnIp() const { return this->dn_ip; } + +void NetworkMonitor::setDnIp(const QString &ip) { + if (this->dn_ip != ip) { + this->dn_ip = ip; + emit dnIpChanged(); + } +} + +QString NetworkMonitor::getUplinkLatency() const { + return this->uplink_latency; +} + +QString NetworkMonitor::getDownlinkLatency() const { + return this->downlink_latency; +} + +QString NetworkMonitor::getUplinkBandwidth() const { + return this->uplink_bandwidth; +} + +QString NetworkMonitor::getDownlinkBandwidth() const { + return this->downlink_bandwidth; +} + +bool NetworkMonitor::isRunning() const { return this->is_running.load(); } + +/** + * @brief Executes a shell command and captures its stdout output. + * + * Uses popen() to run the command and reads the output into a string. + * + * @param cmd The command string to execute. + * @return std::string The captured stdout output. + */ +std::string NetworkMonitor::executeCommand(const std::string &cmd) { + std::string result; + FILE *pipe = popen(cmd.c_str(), "r"); + if (pipe == nullptr) { + ignerr << "[NetworkMonitor] Failed to run command: " << cmd + << std::endl; + return result; + } + char buffer[256]; + while (fgets(buffer, sizeof(buffer), pipe) != nullptr) { + result += buffer; + } + pclose(pipe); + return result; +} + +/** + * @brief Parses ping output to extract the average round-trip time. + * + * Looks for the "rtt min/avg/max/mdev" summary line and extracts the + * average value. Falls back to extracting a single "time=X ms" value + * if the summary is not found. + * + * @param output The raw output from the ping command. + * @return std::string The average latency (e.g. "12.34 ms"), or "N/A". + */ +std::string NetworkMonitor::parsePingOutput(const std::string &output) { + // Match the rtt summary line: rtt min/avg/max/mdev = X/Y/Z/W ms + std::regex rtt_regex( + R"(rtt min/avg/max/mdev\s*=\s*[\d.]+/([\d.]+)/[\d.]+/[\d.]+\s*ms)"); + std::smatch match; + if (std::regex_search(output, match, rtt_regex)) { + return match[1].str() + " ms"; + } + // Fallback: extract a single time= value from a reply line + std::regex time_regex(R"(time=([\d.]+)\s*ms)"); + if (std::regex_search(output, match, time_regex)) { + return match[1].str() + " ms"; + } + return "N/A"; +} + +/** + * @brief Parses iperf3 text output to extract the bandwidth measurement. + * + * Looks for the receiver summary line and extracts the bitrate value. + * Falls back to the sender summary if the receiver line is not found. + * + * @param output The raw output from the iperf3 command. + * @return std::string The bandwidth (e.g. "94.1 Mbits/sec"), or "N/A". + */ +std::string NetworkMonitor::parseIperfOutput(const std::string &output) { + // Match receiver summary line bitrate + std::regex receiver_regex( + R"(([\d.]+)\s+(Mbits/sec|Kbits/sec|Gbits/sec)\s+.*receiver)"); + std::smatch match; + if (std::regex_search(output, match, receiver_regex)) { + return match[1].str() + " " + match[2].str(); + } + // Fallback: match sender summary line bitrate + std::regex sender_regex( + R"(([\d.]+)\s+(Mbits/sec|Kbits/sec|Gbits/sec)\s+.*sender)"); + if (std::regex_search(output, match, sender_regex)) { + return match[1].str() + " " + match[2].str(); + } + return "N/A"; +} + +/** + * @brief Starts the network performance test in a background thread. + * + * Launches an iperf3 server on the UE container, then continuously measures + * uplink/downlink latency (via ping) and bandwidth (via iperf3) between + * the UE and DN containers. Results are pushed to the GUI thread via + * queued connections. + * + * Uplink = UE -> DN direction, Downlink = DN -> UE direction. + * The UE acts as iperf3 server. The DN acts as iperf3 client. + * - Default iperf3 (client sends to server): DN -> UE = Downlink + * - Reverse iperf3 (-R flag): UE -> DN = Uplink + */ +void NetworkMonitor::startTest() { + if (this->is_running.load()) { + return; + } + + if (this->ue_ip.isEmpty() || this->dn_ip.isEmpty()) { + ignerr << "[NetworkMonitor] UE IP or DN IP is empty. Cannot start test." + << std::endl; + return; + } + + this->is_running.store(true); + emit runningChanged(); + + std::string ue_ip_str = this->ue_ip.toStdString(); + std::string dn_ip_str = this->dn_ip.toStdString(); + std::string ue_name = this->ue_container_name; + std::string dn_name = this->dn_container_name; + + // Join any previous thread before launching a new one + if (this->test_thread.joinable()) { + this->test_thread.join(); + } + + this->test_thread = std::thread([this, ue_ip_str, dn_ip_str, ue_name, + dn_name]() { + ignmsg << "[NetworkMonitor] Starting network performance test" + << std::endl; + + // Start iperf3 server on UE container in daemon mode + std::string start_server = + "docker exec -d " + ue_name + " iperf3 -s 2>&1"; + executeCommand(start_server); + + // Allow iperf3 server to initialize + std::this_thread::sleep_for(std::chrono::seconds(1)); + + while (this->is_running.load()) { + // Downlink latency: ping from DN to UE (through 5G) + std::string ping_dl = "docker exec " + dn_name + + " ping -c 1 -W 1 " + ue_ip_str + " 2>&1"; + std::string dl_lat = parsePingOutput(executeCommand(ping_dl)); + + if (!this->is_running.load()) { + break; + } + + // Uplink latency: ping from UE to DN + std::string ping_ul = "docker exec " + ue_name + + " ping -c 1 -W 1 " + dn_ip_str + " 2>&1"; + std::string ul_lat = parsePingOutput(executeCommand(ping_ul)); + + if (!this->is_running.load()) { + break; + } + + // Downlink bandwidth: DN client sends to UE server + std::string iperf_dl = "docker exec " + dn_name + " iperf3 -c " + + ue_ip_str + " -t 1 -f m 2>&1"; + std::string dl_bw = parseIperfOutput(executeCommand(iperf_dl)); + + if (!this->is_running.load()) { + break; + } + + // Uplink bandwidth: reverse mode (UE sends to DN via + // DN client with -R flag) + std::string iperf_ul = "docker exec " + dn_name + " iperf3 -c " + + ue_ip_str + " -t 1 -R -f m 2>&1"; + std::string ul_bw = parseIperfOutput(executeCommand(iperf_ul)); + + // Update GUI properties from the main Qt thread + QMetaObject::invokeMethod( + this, + [this, dl_lat, ul_lat, dl_bw, ul_bw]() { + this->downlink_latency = QString::fromStdString(dl_lat); + this->uplink_latency = QString::fromStdString(ul_lat); + this->downlink_bandwidth = QString::fromStdString(dl_bw); + this->uplink_bandwidth = QString::fromStdString(ul_bw); + emit downlinkLatencyChanged(); + emit uplinkLatencyChanged(); + emit downlinkBandwidthChanged(); + emit uplinkBandwidthChanged(); + }, + Qt::QueuedConnection); + + // Wait before next measurement cycle + std::this_thread::sleep_for(std::chrono::seconds(1)); + } + + // Stop iperf3 server on UE container + std::string stop_server = + "docker exec " + ue_name + " pkill iperf3 2>&1"; + executeCommand(stop_server); + + ignmsg << "[NetworkMonitor] Network performance test stopped" + << std::endl; + }); +} + +/** + * @brief Stops the running network performance test. + * + * Sets the running flag to false and waits for the background thread + * to complete. The iperf3 server on the UE container is cleaned up + * by the thread before it exits. + */ +void NetworkMonitor::stopTest() { + if (!this->is_running.load()) { + return; + } + this->is_running.store(false); + + if (this->test_thread.joinable()) { + this->test_thread.join(); + } + + emit runningChanged(); +} diff --git a/phine-plugins/src/phine_plugins/src/NetworkMonitor.hh b/phine-plugins/src/phine_plugins/src/NetworkMonitor.hh new file mode 100644 index 0000000..c64d89d --- /dev/null +++ b/phine-plugins/src/phine_plugins/src/NetworkMonitor.hh @@ -0,0 +1,165 @@ +/* Copyright 2025 phine.tech GmbH + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License.*/ + +#ifndef NETWORK_MONITOR_HH_ +#define NETWORK_MONITOR_HH_ + +#include +#include +#include +#include +#include + +/** + * @namespace phine_plugins + * @brief Contains plugins for the RoboSim5G simulation environment. + */ +namespace phine_plugins { + +/** + * @class NetworkMonitor + * @brief Ignition Gazebo GUI plugin for monitoring 5G network performance + * between a User Equipment (UE) container and a Data Network (DN) container. + * + * This plugin provides real-time uplink/downlink latency and bandwidth + * measurements using ping and iperf3 commands executed via docker exec + * on the respective containers. + */ +class NetworkMonitor : public ignition::gui::Plugin { + Q_OBJECT + + Q_PROPERTY(QString ueIp READ getUeIp WRITE setUeIp NOTIFY ueIpChanged) + Q_PROPERTY(QString dnIp READ getDnIp WRITE setDnIp NOTIFY dnIpChanged) + Q_PROPERTY( + QString uplinkLatency READ getUplinkLatency NOTIFY uplinkLatencyChanged) + Q_PROPERTY(QString downlinkLatency READ getDownlinkLatency NOTIFY + downlinkLatencyChanged) + Q_PROPERTY(QString uplinkBandwidth READ getUplinkBandwidth NOTIFY + uplinkBandwidthChanged) + Q_PROPERTY(QString downlinkBandwidth READ getDownlinkBandwidth NOTIFY + downlinkBandwidthChanged) + Q_PROPERTY(bool running READ isRunning NOTIFY runningChanged) + + public: + /// \brief Constructor + NetworkMonitor(); + + /// \brief Destructor + ~NetworkMonitor() override; + + /// \brief Load plugin configuration from XML element + void LoadConfig(const tinyxml2::XMLElement *_pluginElem) override; + + /// \brief Get UE IP address + /// \return Current UE IP as QString + QString getUeIp() const; + + /// \brief Set UE IP address + /// \param ip The IP address to set + void setUeIp(const QString &ip); + + /// \brief Get DN IP address + /// \return Current DN IP as QString + QString getDnIp() const; + + /// \brief Set DN IP address + /// \param ip The IP address to set + void setDnIp(const QString &ip); + + /// \brief Get uplink latency result + /// \return Uplink latency string (e.g. "12.34 ms") + QString getUplinkLatency() const; + + /// \brief Get downlink latency result + /// \return Downlink latency string (e.g. "15.67 ms") + QString getDownlinkLatency() const; + + /// \brief Get uplink bandwidth result + /// \return Uplink bandwidth string (e.g. "94.1 Mbits/sec") + QString getUplinkBandwidth() const; + + /// \brief Get downlink bandwidth result + /// \return Downlink bandwidth string (e.g. "98.2 Mbits/sec") + QString getDownlinkBandwidth() const; + + /// \brief Check if test is currently running + /// \return true if test loop is active + bool isRunning() const; + + public slots: + /// \brief Start the network performance test loop + void startTest(); + + /// \brief Stop the network performance test loop + void stopTest(); + + signals: + void ueIpChanged(); + void dnIpChanged(); + void uplinkLatencyChanged(); + void downlinkLatencyChanged(); + void uplinkBandwidthChanged(); + void downlinkBandwidthChanged(); + void runningChanged(); + + private: + /// \brief Execute a shell command and return its stdout output + /// \param cmd The shell command to execute + /// \return Captured stdout output + std::string executeCommand(const std::string &cmd); + + /// \brief Parse ping output to extract average round-trip time + /// \param output Raw ping command output + /// \return Parsed latency string or "N/A" + std::string parsePingOutput(const std::string &output); + + /// \brief Parse iperf3 output to extract bandwidth measurement + /// \param output Raw iperf3 command output + /// \return Parsed bandwidth string or "N/A" + std::string parseIperfOutput(const std::string &output); + + /// \brief UE IP address (5G tunnel IP, e.g. 10.0.0.1) + QString ue_ip; + + /// \brief DN container IP address (e.g. 192.168.70.135) + QString dn_ip; + + /// \brief Uplink latency measurement result + QString uplink_latency{"N/A"}; + + /// \brief Downlink latency measurement result + QString downlink_latency{"N/A"}; + + /// \brief Uplink bandwidth measurement result + QString uplink_bandwidth{"N/A"}; + + /// \brief Downlink bandwidth measurement result + QString downlink_bandwidth{"N/A"}; + + /// \brief Flag indicating whether the test loop is running + std::atomic is_running{false}; + + /// \brief Background thread for running measurement loop + std::thread test_thread; + + /// \brief UE container name (read from UE_NAME_FOR_BUTTON env var) + std::string ue_container_name; + + /// \brief DN container name (default: oai-ext-dn) + std::string dn_container_name{"oai-ext-dn"}; +}; + +} // namespace phine_plugins + +#endif // NETWORK_MONITOR_HH_ diff --git a/phine-plugins/src/phine_plugins/src/NetworkMonitor.qml b/phine-plugins/src/phine_plugins/src/NetworkMonitor.qml new file mode 100644 index 0000000..efe1eca --- /dev/null +++ b/phine-plugins/src/phine_plugins/src/NetworkMonitor.qml @@ -0,0 +1,187 @@ +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Layouts 1.3 + +Rectangle { + id: networkMonitor + color: "#2b2b2b" + Layout.minimumWidth: 320 + Layout.minimumHeight: 420 + + ColumnLayout { + anchors.fill: parent + anchors.margins: 10 + spacing: 8 + + // Title + Label { + text: "Network Performance Monitor" + font.bold: true + font.pixelSize: 16 + color: "#ffffff" + Layout.alignment: Qt.AlignHCenter + } + + // Separator + Rectangle { + Layout.fillWidth: true + height: 1 + color: "#555555" + } + + // UE IP Input + RowLayout { + spacing: 8 + Label { + text: "UE IP:" + color: "#cccccc" + font.pixelSize: 13 + Layout.preferredWidth: 50 + } + TextField { + id: ueIpField + text: NetworkMonitor.ueIp + placeholderText: "e.g. 10.0.0.1" + Layout.fillWidth: true + onTextChanged: NetworkMonitor.ueIp = text + enabled: !NetworkMonitor.running + font.pixelSize: 13 + background: Rectangle { + color: ueIpField.enabled ? "#3c3c3c" : "#2a2a2a" + border.color: "#666666" + radius: 3 + } + color: "#ffffff" + } + } + + // DN IP Input + RowLayout { + spacing: 8 + Label { + text: "DN IP:" + color: "#cccccc" + font.pixelSize: 13 + Layout.preferredWidth: 50 + } + TextField { + id: dnIpField + text: NetworkMonitor.dnIp + placeholderText: "e.g. 192.168.70.135" + Layout.fillWidth: true + onTextChanged: NetworkMonitor.dnIp = text + enabled: !NetworkMonitor.running + font.pixelSize: 13 + background: Rectangle { + color: dnIpField.enabled ? "#3c3c3c" : "#2a2a2a" + border.color: "#666666" + radius: 3 + } + color: "#ffffff" + } + } + + // Start/Stop Button + Button { + id: testButton + text: NetworkMonitor.running ? "Stop Test" : "Start Test" + Layout.fillWidth: true + Layout.preferredHeight: 40 + font.pixelSize: 14 + font.bold: true + onClicked: { + if (NetworkMonitor.running) + NetworkMonitor.stopTest() + else + NetworkMonitor.startTest() + } + background: Rectangle { + color: NetworkMonitor.running ? "#cc4444" : "#44aa44" + radius: 5 + } + contentItem: Text { + text: testButton.text + font: testButton.font + color: "#ffffff" + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + } + } + + // Separator + Rectangle { + Layout.fillWidth: true + height: 1 + color: "#555555" + } + + // Results Header + Label { + text: "Results" + font.bold: true + font.pixelSize: 14 + color: "#ffffff" + } + + // Results Grid + GridLayout { + columns: 2 + columnSpacing: 12 + rowSpacing: 8 + Layout.fillWidth: true + + Label { + text: "Uplink Latency:" + color: "#aaaaaa" + font.pixelSize: 13 + } + Label { + text: NetworkMonitor.uplinkLatency + color: "#66ff66" + font.pixelSize: 13 + font.bold: true + } + + Label { + text: "Downlink Latency:" + color: "#aaaaaa" + font.pixelSize: 13 + } + Label { + text: NetworkMonitor.downlinkLatency + color: "#66ff66" + font.pixelSize: 13 + font.bold: true + } + + Label { + text: "Uplink Bandwidth:" + color: "#aaaaaa" + font.pixelSize: 13 + } + Label { + text: NetworkMonitor.uplinkBandwidth + color: "#6699ff" + font.pixelSize: 13 + font.bold: true + } + + Label { + text: "Downlink Bandwidth:" + color: "#aaaaaa" + font.pixelSize: 13 + } + Label { + text: NetworkMonitor.downlinkBandwidth + color: "#6699ff" + font.pixelSize: 13 + font.bold: true + } + } + + // Spacer + Item { + Layout.fillHeight: true + } + } +} diff --git a/phine-plugins/src/phine_plugins/src/NetworkMonitor.qrc b/phine-plugins/src/phine_plugins/src/NetworkMonitor.qrc new file mode 100644 index 0000000..631d846 --- /dev/null +++ b/phine-plugins/src/phine_plugins/src/NetworkMonitor.qrc @@ -0,0 +1,5 @@ + + + NetworkMonitor.qml + + diff --git a/phine-plugins/src/phine_plugins/src/UePowerPlugin.cc b/phine-plugins/src/phine_plugins/src/UePowerPlugin.cc new file mode 100644 index 0000000..24076ba --- /dev/null +++ b/phine-plugins/src/phine_plugins/src/UePowerPlugin.cc @@ -0,0 +1,203 @@ +/* Copyright 2025 phine.tech GmbH + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License.*/ + +#include "UePowerPlugin.hh" +#include +#include +#include +#include +#include + +IGNITION_ADD_PLUGIN(phine_plugins::UePowerPlugin, ignition::gui::Plugin) + +using namespace phine_plugins; + +UePowerPlugin::UePowerPlugin() { + ignmsg << "[UePowerPlugin] constructor called" << std::endl; + + const char *ue_name_env = std::getenv("UE_NAME_FOR_BUTTON"); + if (ue_name_env != nullptr) { + this->container_name = QString::fromStdString(std::string(ue_name_env)); + } + + ignmsg << "[UePowerPlugin] UE container: " + << this->container_name.toStdString() << std::endl; +} + +UePowerPlugin::~UePowerPlugin() {} + +void UePowerPlugin::LoadConfig(const tinyxml2::XMLElement *_pluginElem) { + if (this->title.empty()) { + this->title = "UE Power Control"; + } + + if (_pluginElem != nullptr) { + auto *name_elem = _pluginElem->FirstChildElement("container_name"); + if (name_elem != nullptr && name_elem->GetText() != nullptr) { + container_name = QString::fromStdString(name_elem->GetText()); + } + + auto *ver_elem = _pluginElem->FirstChildElement("version"); + if (ver_elem != nullptr && ver_elem->GetText() != nullptr) { + std::string ver = ver_elem->GetText(); + if (ver == "v24") { + version_index = 0; + } else if (ver == "v26") { + version_index = 1; + } + } + + auto *ip_elem = _pluginElem->FirstChildElement("gnb_ip"); + if (ip_elem != nullptr && ip_elem->GetText() != nullptr) { + gnb_ip = QString::fromStdString(ip_elem->GetText()); + } + } +} + +QString UePowerPlugin::getContainerName() const { return container_name; } + +void UePowerPlugin::setContainerName(const QString &name) { + if (container_name != name) { + container_name = name; + emit containerNameChanged(); + } +} + +int UePowerPlugin::getVersionIndex() const { return version_index; } + +void UePowerPlugin::setVersionIndex(int index) { + if (version_index != index) { + version_index = index; + emit versionIndexChanged(); + } +} + +QString UePowerPlugin::getGnbIp() const { return gnb_ip; } + +void UePowerPlugin::setGnbIp(const QString &ip) { + if (gnb_ip != ip) { + gnb_ip = ip; + emit gnbIpChanged(); + } +} + +bool UePowerPlugin::isProcessRunning() const { return process_running; } + +bool UePowerPlugin::isConnected() const { return connected; } + +bool UePowerPlugin::isValidContainerName(const std::string &name) { + if (name.empty() || name.size() > 128) { + return false; + } + static const std::regex valid_name(R"(^[a-zA-Z0-9][a-zA-Z0-9_.\-]*$)"); + return std::regex_match(name, valid_name); +} + +bool UePowerPlugin::isValidIpAddress(const std::string &ip) { + static const std::regex ip_regex( + R"(^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$)"); + std::smatch match; + if (!std::regex_match(ip, match, ip_regex)) { + return false; + } + for (int i = 1; i <= 4; ++i) { + int octet = std::stoi(match[i].str()); + if (octet < 0 || octet > 255) { + return false; + } + } + return true; +} + +bool UePowerPlugin::checkProcessRunning() { + std::string name = container_name.toStdString(); + if (!isValidContainerName(name)) { + return false; + } + std::string cmd = + "docker exec " + name + " pgrep nr-uesoftmodem > /dev/null 2>&1"; + int ret = system(cmd.c_str()); + return (ret == 0); +} + +std::string UePowerPlugin::buildStartCommand() const { + std::string name = container_name.toStdString(); + std::string ip = gnb_ip.toStdString(); + + if (version_index == 0) { + // v24: uses .conf file with --sa flag, freq 3619200000 + return "docker exec " + name + + " /bin/bash -c" + " '/opt/oai-nr-ue/bin/nr-uesoftmodem" + " -O /opt/oai-nr-ue/etc/nr-ue.conf" + " -E --sa --rfsim -r 106 --numerology 1" + " -C 3619200000" + " --rfsimulator.serveraddr " + + ip + + " --log_config.global_log_options level,nocolor,time &'"; + } + // v26: uses .yaml file without --sa flag, freq 3319680000 + return "docker exec " + name + + " /bin/bash -c" + " '/opt/oai-nr-ue/bin/nr-uesoftmodem" + " -O /opt/oai-nr-ue/etc/nr-ue.yaml" + " -E --rfsim -r 106 --numerology 1" + " -C 3319680000" + " --rfsimulator.serveraddr " + + ip + " &'"; +} + +void UePowerPlugin::toggleProcess() { + std::string name = container_name.toStdString(); + if (!isValidContainerName(name)) { + ignerr << "[UePowerPlugin] Invalid container name: " << name + << std::endl; + return; + } + + // First click: check actual state, then become connected + if (!connected) { + process_running = checkProcessRunning(); + connected = true; + emit connectedChanged(); + emit processRunningChanged(); + ignmsg << "[UePowerPlugin] Connected to " << name << " — process is " + << (process_running ? "running" : "stopped") << std::endl; + return; + } + + // Subsequent clicks: toggle without checking + if (process_running) { + std::string cmd = + "docker exec " + name + " pkill nr-uesoftmodem 2>&1"; + ignmsg << "[UePowerPlugin] Running: " << cmd << std::endl; + int ret = system(cmd.c_str()); + ignmsg << "[UePowerPlugin] Kill exit=" << ret << std::endl; + process_running = false; + emit processRunningChanged(); + } else { + std::string ip = gnb_ip.toStdString(); + if (!isValidIpAddress(ip)) { + ignerr << "[UePowerPlugin] Invalid gNB IP address: " << ip + << std::endl; + return; + } + std::string cmd = buildStartCommand(); + ignmsg << "[UePowerPlugin] Running: " << cmd << std::endl; + int ret = system(cmd.c_str()); + ignmsg << "[UePowerPlugin] Start exit=" << ret << std::endl; + process_running = true; + emit processRunningChanged(); + } +} diff --git a/phine-plugins/src/phine_plugins/src/UePowerPlugin.hh b/phine-plugins/src/phine_plugins/src/UePowerPlugin.hh new file mode 100644 index 0000000..7caf7db --- /dev/null +++ b/phine-plugins/src/phine_plugins/src/UePowerPlugin.hh @@ -0,0 +1,77 @@ +/* Copyright 2025 phine.tech GmbH + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License.*/ + +#ifndef UE_POWER_PLUGIN_HH_ +#define UE_POWER_PLUGIN_HH_ + +#include +#include +#include + +namespace phine_plugins { + +class UePowerPlugin : public ignition::gui::Plugin +{ + Q_OBJECT + + Q_PROPERTY(QString containerName READ getContainerName WRITE + setContainerName NOTIFY containerNameChanged) + Q_PROPERTY(int versionIndex READ getVersionIndex WRITE setVersionIndex NOTIFY + versionIndexChanged) + Q_PROPERTY( + QString gnbIp READ getGnbIp WRITE setGnbIp NOTIFY gnbIpChanged) + Q_PROPERTY(bool processRunning READ isProcessRunning NOTIFY + processRunningChanged) + Q_PROPERTY(bool connected READ isConnected NOTIFY connectedChanged) + +public: + UePowerPlugin(); + ~UePowerPlugin() override; + void LoadConfig(const tinyxml2::XMLElement *_pluginElem) override; + + QString getContainerName() const; + void setContainerName(const QString &name); + int getVersionIndex() const; + void setVersionIndex(int index); + QString getGnbIp() const; + void setGnbIp(const QString &ip); + bool isProcessRunning() const; + bool isConnected() const; + +public slots: + void toggleProcess(); + +signals: + void containerNameChanged(); + void versionIndexChanged(); + void gnbIpChanged(); + void processRunningChanged(); + void connectedChanged(); + +private: + bool checkProcessRunning(); + std::string buildStartCommand() const; + static bool isValidContainerName(const std::string &name); + static bool isValidIpAddress(const std::string &ip); + + QString container_name{"ue_turtlebot"}; + int version_index{0}; // 0 = v24, 1 = v26 + QString gnb_ip{"192.168.70.160"}; + bool process_running{false}; + bool connected{false}; +}; + +} // namespace phine_plugins + +#endif // UE_POWER_PLUGIN_HH_ diff --git a/phine-plugins/src/phine_plugins/src/UePowerPlugin.qml b/phine-plugins/src/phine_plugins/src/UePowerPlugin.qml new file mode 100644 index 0000000..98e03ec --- /dev/null +++ b/phine-plugins/src/phine_plugins/src/UePowerPlugin.qml @@ -0,0 +1,153 @@ +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Layouts 1.3 + +Rectangle { + id: uePower + color: "#2b2b2b" + Layout.minimumWidth: 400 + Layout.minimumHeight: 270 + Layout.fillWidth: true + anchors.fill: parent + + ColumnLayout { + anchors.fill: parent + anchors.margins: 10 + spacing: 8 + + // Title + Label { + text: "UE Power Control" + font.bold: true + font.pixelSize: 16 + color: "#ffffff" + Layout.alignment: Qt.AlignHCenter + } + + Rectangle { + Layout.fillWidth: true + height: 1 + color: "#555555" + } + + // Container Name + RowLayout { + spacing: 8 + Label { + text: "Container:" + color: "#cccccc" + font.pixelSize: 13 + Layout.preferredWidth: 80 + } + TextField { + id: containerField + text: UePowerPlugin.containerName + placeholderText: "e.g. ue_turtlebot" + Layout.fillWidth: true + onTextChanged: UePowerPlugin.containerName = text + enabled: !UePowerPlugin.connected + font.pixelSize: 13 + background: Rectangle { + color: containerField.enabled ? "#3c3c3c" : "#2a2a2a" + border.color: "#666666" + radius: 3 + } + color: "#ffffff" + } + } + + // Version Selector + RowLayout { + spacing: 8 + Label { + text: "Version:" + color: "#cccccc" + font.pixelSize: 13 + Layout.preferredWidth: 80 + } + ComboBox { + id: versionCombo + model: ["v24 (.conf)", "v26 (.yaml)"] + currentIndex: UePowerPlugin.versionIndex + onCurrentIndexChanged: UePowerPlugin.versionIndex = currentIndex + enabled: !UePowerPlugin.connected + Layout.fillWidth: true + font.pixelSize: 13 + + background: Rectangle { + color: versionCombo.enabled ? "#3c3c3c" : "#2a2a2a" + border.color: "#666666" + radius: 3 + } + contentItem: Text { + text: versionCombo.displayText + color: "#ffffff" + font: versionCombo.font + verticalAlignment: Text.AlignVCenter + leftPadding: 8 + } + } + } + + // gNB IP Input + RowLayout { + spacing: 8 + Label { + text: "gNB IP:" + color: "#cccccc" + font.pixelSize: 13 + Layout.preferredWidth: 80 + } + TextField { + id: gnbIpField + text: UePowerPlugin.gnbIp + placeholderText: "e.g. 192.168.70.160" + Layout.fillWidth: true + onTextChanged: UePowerPlugin.gnbIp = text + enabled: !UePowerPlugin.connected + font.pixelSize: 13 + background: Rectangle { + color: gnbIpField.enabled ? "#3c3c3c" : "#2a2a2a" + border.color: "#666666" + radius: 3 + } + color: "#ffffff" + } + } + + Rectangle { + Layout.fillWidth: true + height: 1 + color: "#555555" + } + + // Power Toggle Button + Button { + id: powerButton + text: !UePowerPlugin.connected ? "Check Status" : + (UePowerPlugin.processRunning ? "Turn OFF" : "Turn ON") + Layout.fillWidth: true + Layout.preferredHeight: 48 + font.pixelSize: 16 + font.bold: true + onClicked: UePowerPlugin.toggleProcess() + + background: Rectangle { + color: !UePowerPlugin.connected ? "#666666" : + (UePowerPlugin.processRunning ? "#44aa44" : "#cc4444") + radius: 6 + } + contentItem: Text { + text: powerButton.text + font: powerButton.font + color: "#ffffff" + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + } + } + + Item { + Layout.fillHeight: true + } + } +} diff --git a/phine-plugins/src/phine_plugins/src/UePowerPlugin.qrc b/phine-plugins/src/phine_plugins/src/UePowerPlugin.qrc new file mode 100644 index 0000000..4df2113 --- /dev/null +++ b/phine-plugins/src/phine_plugins/src/UePowerPlugin.qrc @@ -0,0 +1,5 @@ + + + UePowerPlugin.qml + + diff --git a/phine-plugins/src/phine_plugins/src/gNBPowerPlugin.cc b/phine-plugins/src/phine_plugins/src/gNBPowerPlugin.cc new file mode 100644 index 0000000..7eab614 --- /dev/null +++ b/phine-plugins/src/phine_plugins/src/gNBPowerPlugin.cc @@ -0,0 +1,153 @@ +/* Copyright 2025 phine.tech GmbH + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License.*/ + +#include "gNBPowerPlugin.hh" +#include +#include +#include +#include +#include + +IGNITION_ADD_PLUGIN(phine_plugins::gNBPowerPlugin, ignition::gui::Plugin) + +using namespace phine_plugins; + +gNBPowerPlugin::gNBPowerPlugin() { + ignmsg << "[gNBPowerPlugin] constructor called" << std::endl; +} + +gNBPowerPlugin::~gNBPowerPlugin() {} + +void gNBPowerPlugin::LoadConfig(const tinyxml2::XMLElement *_pluginElem) { + if (this->title.empty()) { + this->title = "gNB Power Control"; + } + + if (_pluginElem != nullptr) { + auto *name_elem = _pluginElem->FirstChildElement("container_name"); + if (name_elem != nullptr && name_elem->GetText() != nullptr) { + container_name = QString::fromStdString(name_elem->GetText()); + } + + auto *ver_elem = _pluginElem->FirstChildElement("version"); + if (ver_elem != nullptr && ver_elem->GetText() != nullptr) { + std::string ver = ver_elem->GetText(); + if (ver == "v24") { + version_index = 0; + } else if (ver == "v26") { + version_index = 1; + } + } + } +} + +QString gNBPowerPlugin::getContainerName() const { return container_name; } + +void gNBPowerPlugin::setContainerName(const QString &name) { + if (container_name != name) { + container_name = name; + emit containerNameChanged(); + } +} + +int gNBPowerPlugin::getVersionIndex() const { return version_index; } + +void gNBPowerPlugin::setVersionIndex(int index) { + if (version_index != index) { + version_index = index; + emit versionIndexChanged(); + } +} + +bool gNBPowerPlugin::isProcessRunning() const { return process_running; } + +bool gNBPowerPlugin::isConnected() const { return connected; } + +bool gNBPowerPlugin::isValidContainerName(const std::string &name) { + if (name.empty() || name.size() > 128) { + return false; + } + static const std::regex valid_name(R"(^[a-zA-Z0-9][a-zA-Z0-9_.\-]*$)"); + return std::regex_match(name, valid_name); +} + +bool gNBPowerPlugin::checkProcessRunning() { + std::string name = container_name.toStdString(); + if (!isValidContainerName(name)) { + return false; + } + std::string cmd = + "docker exec " + name + " pgrep nr-softmodem > /dev/null 2>&1"; + int ret = system(cmd.c_str()); + return (ret == 0); +} + +std::string gNBPowerPlugin::buildStartCommand() const { + std::string name = container_name.toStdString(); + if (version_index == 0) { + // v24: uses .conf file with --sa flag + return "docker exec " + name + + " /bin/bash -c" + " '/opt/oai-gnb/bin/nr-softmodem" + " -O /opt/oai-gnb/etc/gnb.conf" + " --sa -E --rfsim" + " --log_config.global_log_options level,nocolor,time &'"; + } + // v26: uses .yaml file without --sa flag + return "docker exec " + name + + " /bin/bash -c" + " '/opt/oai-gnb/bin/nr-softmodem" + " -O /opt/oai-gnb/etc/gnb.yaml" + " -E --rfsim" + " --log_config.global_log_options level,nocolor,time &'"; +} + +void gNBPowerPlugin::toggleProcess() { + std::string name = container_name.toStdString(); + if (!isValidContainerName(name)) { + ignerr << "[gNBPowerPlugin] Invalid container name: " << name + << std::endl; + return; + } + + // First click: check actual state, then become connected + if (!connected) { + process_running = checkProcessRunning(); + connected = true; + emit connectedChanged(); + emit processRunningChanged(); + ignmsg << "[gNBPowerPlugin] Connected to " << name + << " — process is " + << (process_running ? "running" : "stopped") << std::endl; + return; + } + + // Subsequent clicks: toggle without checking + if (process_running) { + std::string cmd = + "docker exec " + name + " pkill nr-softmodem 2>&1"; + ignmsg << "[gNBPowerPlugin] Running: " << cmd << std::endl; + int ret = system(cmd.c_str()); + ignmsg << "[gNBPowerPlugin] Kill exit=" << ret << std::endl; + process_running = false; + emit processRunningChanged(); + } else { + std::string cmd = buildStartCommand(); + ignmsg << "[gNBPowerPlugin] Running: " << cmd << std::endl; + int ret = system(cmd.c_str()); + ignmsg << "[gNBPowerPlugin] Start exit=" << ret << std::endl; + process_running = true; + emit processRunningChanged(); + } +} diff --git a/phine-plugins/src/phine_plugins/src/gNBPowerPlugin.hh b/phine-plugins/src/phine_plugins/src/gNBPowerPlugin.hh new file mode 100644 index 0000000..e236125 --- /dev/null +++ b/phine-plugins/src/phine_plugins/src/gNBPowerPlugin.hh @@ -0,0 +1,70 @@ +/* Copyright 2025 phine.tech GmbH + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License.*/ + +#ifndef GNB_POWER_PLUGIN_HH_ +#define GNB_POWER_PLUGIN_HH_ + +#include +#include +#include + +namespace phine_plugins { + +class gNBPowerPlugin : public ignition::gui::Plugin +{ + Q_OBJECT + + Q_PROPERTY(QString containerName READ getContainerName WRITE + setContainerName NOTIFY containerNameChanged) + Q_PROPERTY(int versionIndex READ getVersionIndex WRITE setVersionIndex NOTIFY + versionIndexChanged) + Q_PROPERTY(bool processRunning READ isProcessRunning NOTIFY + processRunningChanged) + Q_PROPERTY(bool connected READ isConnected NOTIFY connectedChanged) + +public: + gNBPowerPlugin(); + ~gNBPowerPlugin() override; + void LoadConfig(const tinyxml2::XMLElement *_pluginElem) override; + + QString getContainerName() const; + void setContainerName(const QString &name); + int getVersionIndex() const; + void setVersionIndex(int index); + bool isProcessRunning() const; + bool isConnected() const; + +public slots: + void toggleProcess(); + +signals: + void containerNameChanged(); + void versionIndexChanged(); + void processRunningChanged(); + void connectedChanged(); + +private: + bool checkProcessRunning(); + std::string buildStartCommand() const; + static bool isValidContainerName(const std::string &name); + + QString container_name{"oai-gNB1"}; + int version_index{0}; // 0 = v24, 1 = v26 + bool process_running{false}; + bool connected{false}; +}; + +} // namespace phine_plugins + +#endif // GNB_POWER_PLUGIN_HH_ diff --git a/phine-plugins/src/phine_plugins/src/gNBPowerPlugin.qml b/phine-plugins/src/phine_plugins/src/gNBPowerPlugin.qml new file mode 100644 index 0000000..b245c57 --- /dev/null +++ b/phine-plugins/src/phine_plugins/src/gNBPowerPlugin.qml @@ -0,0 +1,127 @@ +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Layouts 1.3 + +Rectangle { + id: gnbPower + color: "#2b2b2b" + Layout.minimumWidth: 400 + Layout.minimumHeight: 220 + Layout.fillWidth: true + anchors.fill: parent + + ColumnLayout { + anchors.fill: parent + anchors.margins: 10 + spacing: 8 + + // Title + Label { + text: "gNB Power Control" + font.bold: true + font.pixelSize: 16 + color: "#ffffff" + Layout.alignment: Qt.AlignHCenter + } + + Rectangle { + Layout.fillWidth: true + height: 1 + color: "#555555" + } + + // Container Name + RowLayout { + spacing: 8 + Label { + text: "Container:" + color: "#cccccc" + font.pixelSize: 13 + Layout.preferredWidth: 80 + } + TextField { + id: containerField + text: gNBPowerPlugin.containerName + placeholderText: "e.g. oai-gNB1" + Layout.fillWidth: true + onTextChanged: gNBPowerPlugin.containerName = text + enabled: !gNBPowerPlugin.connected + font.pixelSize: 13 + background: Rectangle { + color: containerField.enabled ? "#3c3c3c" : "#2a2a2a" + border.color: "#666666" + radius: 3 + } + color: "#ffffff" + } + } + + // Version Selector + RowLayout { + spacing: 8 + Label { + text: "Version:" + color: "#cccccc" + font.pixelSize: 13 + Layout.preferredWidth: 80 + } + ComboBox { + id: versionCombo + model: ["v24 (.conf)", "v26 (.yaml)"] + currentIndex: gNBPowerPlugin.versionIndex + onCurrentIndexChanged: gNBPowerPlugin.versionIndex = currentIndex + enabled: !gNBPowerPlugin.connected + Layout.fillWidth: true + font.pixelSize: 13 + + background: Rectangle { + color: versionCombo.enabled ? "#3c3c3c" : "#2a2a2a" + border.color: "#666666" + radius: 3 + } + contentItem: Text { + text: versionCombo.displayText + color: "#ffffff" + font: versionCombo.font + verticalAlignment: Text.AlignVCenter + leftPadding: 8 + } + } + } + + Rectangle { + Layout.fillWidth: true + height: 1 + color: "#555555" + } + + // Power Toggle Button + Button { + id: powerButton + text: !gNBPowerPlugin.connected ? "Check Status" : + (gNBPowerPlugin.processRunning ? "Turn OFF" : "Turn ON") + Layout.fillWidth: true + Layout.preferredHeight: 48 + font.pixelSize: 16 + font.bold: true + onClicked: gNBPowerPlugin.toggleProcess() + + background: Rectangle { + color: !gNBPowerPlugin.connected ? "#666666" : + (gNBPowerPlugin.processRunning ? "#44aa44" : "#cc4444") + radius: 6 + } + contentItem: Text { + text: powerButton.text + font: powerButton.font + color: "#ffffff" + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + } + } + + Item { + Layout.fillHeight: true + } + } +} diff --git a/phine-plugins/src/phine_plugins/src/gNBPowerPlugin.qrc b/phine-plugins/src/phine_plugins/src/gNBPowerPlugin.qrc new file mode 100644 index 0000000..ff03da6 --- /dev/null +++ b/phine-plugins/src/phine_plugins/src/gNBPowerPlugin.qrc @@ -0,0 +1,5 @@ + + + gNBPowerPlugin.qml + +