From 976bab472d9dcb59336cc75b6e2207f43e6a891a Mon Sep 17 00:00:00 2001 From: vpriya623 Date: Wed, 4 Feb 2026 23:17:27 +0530 Subject: [PATCH] RDKB-63270 Test migration from non dhcp-manager to dhcp manager scenario. Added new script that checks for PSM records of dhcpv4 and dhcpv6 virtual interface of respective WAN actual interface and updates values from bbhm_def_cfg.xml file otherwise it updates the proper values for the empty records Added a line in RdkWanManager.service file to check for the script before to execute --- systemd_units/RdkWanManager.service | 1 + systemd_units/scripts/DHCPMgrPSMValueCheck.sh | 105 ++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 systemd_units/scripts/DHCPMgrPSMValueCheck.sh diff --git a/systemd_units/RdkWanManager.service b/systemd_units/RdkWanManager.service index 56494dd01..91ba491c9 100644 --- a/systemd_units/RdkWanManager.service +++ b/systemd_units/RdkWanManager.service @@ -28,6 +28,7 @@ Environment="LOG4C_RCPATH=/etc" EnvironmentFile=/etc/device.properties WorkingDirectory=/usr/rdk/wanmanager ExecStartPre=/bin/touch /tmp/OS_WANMANAGER_ENABLED +ExecStartPre=-/bin/sh -c '[ -x /usr/ccsp/dhcpmgr/DHCPMgrPSMValueCheck.sh ] && (/usr/ccsp/dhcpmgr/DHCPMgrPSMValueCheck.sh)' ExecStartPre=/bin/sh -c '(/usr/ccsp/utopiaInitCheck.sh)' ExecStart=/usr/rdk/wanmanager/wanmanager -subsys $Subsys ExecStop=/bin/sh -c 'echo "`date`: Stopping/Restarting RdkWanManager" >> ${PROCESS_RESTART_LOG}' diff --git a/systemd_units/scripts/DHCPMgrPSMValueCheck.sh b/systemd_units/scripts/DHCPMgrPSMValueCheck.sh new file mode 100644 index 000000000..648da6b74 --- /dev/null +++ b/systemd_units/scripts/DHCPMgrPSMValueCheck.sh @@ -0,0 +1,105 @@ +#!/bin/sh +########################################################################## +# If not stated otherwise in this file or this component's LICENSE +# file the following copyright and licenses apply: +# +# Copyright 2026 RDK Management. +# +# 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. +########################################################################## + +if [ -e /etc/log_timestamp.sh ] +then + . /etc/log_timestamp.sh +else + echo_t() + { + echo "$(date +"%y%m%d-%T.%6N") $1" + } +fi + +LOG_FILE=/rdklogs/logs/Consolelog.txt.0 +BBHM_DEF_CFG_FILE=/usr/ccsp/config/bbhm_def_cfg.xml + +get_psm_value() { + local param=$1 + + echo_t "[get_psm_value] $param" >> $LOG_FILE + # Check if the file exists + if [ ! -f "$BBHM_DEF_CFG_FILE" ]; then + echo_t "[get_psm_value] FILE NOT FOUND!" >> $LOG_FILE + return 1 + fi + + # Search for the parameter and extract the value using grep and sed + local value=$(grep "]*>\([^<]*\)<\/Record>/\1/p') + + # If a result is found, return it otherwise return empty + if [ -n "$value" ]; then + echo "$value" + else + echo "" + fi +} + +echo_t "[DHCP Manager PSM Check] Running the script to check psm records" >> $LOG_FILE + +wanifcount=$(psmcli get dmsb.wanmanager.wan.interfacecount) +if ! echo "$wanifcount" | grep -qE "^[0-9]+$"; then + echo_t "[DHCP Manager PSM Check] Invalid interface count: '$wanifcount'" >> $LOG_FILE + exit 1 +fi + +echo_t "[DHCP Manager PSM Check] Number of wan interface is ${wanifcount}" >> $LOG_FILE + +cnt=1 +while [ "$cnt" -le "$wanifcount" ] +do + dhcp4_obj_path="dmsb.wanmanager.if.${cnt}.VirtualInterface.1.IP.DHCPV4Interface" + dhcp6_obj_path="dmsb.wanmanager.if.${cnt}.VirtualInterface.1.IP.DHCPV6Interface" + psmDHCPv4=$(psmcli get ${dhcp4_obj_path}) + psmDHCPv6=$(psmcli get ${dhcp6_obj_path}) + + if [ -z "$psmDHCPv4" ]; then + psmDHCPv4_value=$(get_psm_value "${dhcp4_obj_path}") + if [ -z "$psmDHCPv4_value" ]; then + echo_t "[DHCP Manager PSM Check] PSM value NOT found in "$BBHM_DEF_CFG_FILE" for record \"${dhcp4_obj_path}\"" >> $LOG_FILE + psmcli set ${dhcp4_obj_path} Device.DHCPv4.Client.${cnt} 2> /dev/null + echo_t "[DHCP Manager PSM Check] PSM record \"${dhcp4_obj_path}\" is set with \"Device.DHCPv4.Client.${cnt}\"" >> $LOG_FILE + else + echo_t "[DHCP Manager PSM Check] PSM value found in "$BBHM_DEF_CFG_FILE" for record \"${dhcp4_obj_path}\" is \"${psmDHCPv4_value}\"" >> $LOG_FILE + psmcli set ${dhcp4_obj_path} ${psmDHCPv4_value} 2> /dev/null + echo_t "[DHCP Manager PSM Check] PSM record \"${dhcp4_obj_path}\" is set with \"${psmDHCPv4_value}\"" >> $LOG_FILE + fi + else + echo_t "[DHCP Manager PSM Check] PSM record \"${dhcp4_obj_path}\" already exists with value: \"${psmDHCPv4}\"" >> $LOG_FILE + fi + + if [ -z "$psmDHCPv6" ]; then + psmDHCPv6_value=$(get_psm_value "${dhcp6_obj_path}") + if [ -z "$psmDHCPv6_value" ]; then + echo_t "[DHCP Manager PSM Check] PSM value NOT found in "$BBHM_DEF_CFG_FILE" for record \"${dhcp6_obj_path}\"" >> $LOG_FILE + psmcli set ${dhcp6_obj_path} Device.DHCPv6.Client.${cnt} 2> /dev/null + echo_t "[DHCP Manager PSM Check] PSM record \"${dhcp6_obj_path}\" is set with \"Device.DHCPv6.Client.${cnt}\"" >> $LOG_FILE + else + echo_t "[DHCP Manager PSM Check] PSM value found in "$BBHM_DEF_CFG_FILE" for record \"${dhcp6_obj_path}\" is \"${psmDHCPv6_value}\"" >> $LOG_FILE + psmcli set ${dhcp6_obj_path} ${psmDHCPv6_value} 2> /dev/null + echo_t "[DHCP Manager PSM Check] PSM record \"${dhcp6_obj_path}\" is set with \"${psmDHCPv6_value}\"" >> $LOG_FILE + fi + else + echo_t "[DHCP Manager PSM Check] PSM record \"${dhcp6_obj_path}\" already exists with value: \"${psmDHCPv6}\"" >> $LOG_FILE + fi + cnt=$((cnt + 1)) +done +echo_t "[DHCP Manager PSM Check] End Of the Script" >> $LOG_FILE +