diff --git a/dockers/docker-database/database_config.json.j2 b/dockers/docker-database/database_config.json.j2 index bacc1d356649..b5c231a93f41 100644 --- a/dockers/docker-database/database_config.json.j2 +++ b/dockers/docker-database/database_config.json.j2 @@ -1,3 +1,4 @@ +{% set include_remote_db = (REMOTE_DB_IP is defined and REMOTE_DB_PORT is defined) %} { "INSTANCES": { "redis":{ @@ -15,6 +16,14 @@ "unix_socket_path": "/var/run/redis-chassis/redis_chassis.sock", "persistence_for_warm_boot" : "yes" } +{% if include_remote_db %} + ,"remote_redis":{ + "hostname" : "{{REMOTE_DB_IP}}", + "port" : {{REMOTE_DB_PORT}}, + "unix_socket_path": "" + "persistence_for_warm_boot" : "yes" + } +{% endif %} }, "DATABASES" : { "APPL_DB" : { @@ -102,23 +111,23 @@ "DPU_APPL_DB" : { "id" : 15, "separator": ":", - "instance" : "redis", + "instance" : {% if include_remote_db %} "remote_redis" {% else %} "redis" {% endif %}, "format": "proto" }, "DPU_APPL_STATE_DB" : { "id" : 16, "separator": "|", - "instance" : "redis" + "instance" : {% if include_remote_db %} "remote_redis" {% else %} "redis" {% endif %} }, "DPU_STATE_DB" : { "id" : 17, "separator": "|", - "instance" : "redis" + "instance" : {% if include_remote_db %} "remote_redis" {% else %} "redis" {% endif %} }, "DPU_COUNTERS_DB" : { "id" : 18, "separator": ":", - "instance" : "redis" + "instance" : {% if include_remote_db %} "remote_redis" {% else %} "redis" {% endif %} } {% endif %} }, diff --git a/dockers/docker-database/database_global.json.j2 b/dockers/docker-database/database_global.json.j2 index 032f5e722e12..1760a96f0286 100644 --- a/dockers/docker-database/database_global.json.j2 +++ b/dockers/docker-database/database_global.json.j2 @@ -26,7 +26,7 @@ {% if dpu_cnt > 0 %} {% for dpu in range(dpu_cnt) %} { - "database_name" : "dpu{{dpu}}", + "container_name" : "dpu{{dpu}}", "include" : "../../redisdpu{{dpu}}/sonic-db/database_config.json" {% if dpu == dpu_cnt-1 %} } diff --git a/dockers/docker-database/docker-database-init.sh b/dockers/docker-database/docker-database-init.sh index f3679e08aeab..467f33c212d1 100755 --- a/dockers/docker-database/docker-database-init.sh +++ b/dockers/docker-database/docker-database-init.sh @@ -28,6 +28,18 @@ if [[ $DATABASE_TYPE == "dpudb" ]]; then redis_port=`expr 6381 + $DPU_ID` fi +if [[ $IS_DPU_DEVICE == "true" ]] +then + midplane_ip=$( ip -4 -o addr show eth0-midplane | awk '{print $4}' | cut -d'/' -f1 ) + if [[ $midplane_ip != "" ]] + then + export DATABASE_TYPE="dpudb" + export REMOTE_DB_IP="169.254.200.254" + # Determine the DB PORT from midplane IP + IFS=. read -r a b c d <<< $midplane_ip + export REMOTE_DB_PORT=$((6380 + $d)) + fi +fi REDIS_DIR=/var/run/redis$NAMESPACE_ID mkdir -p $REDIS_DIR/sonic-db diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index 95c2e1fa52a8..694fdd1f85a9 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -341,6 +341,18 @@ start() { source $PLATFORM_ENV_CONF fi + # Parse the platform.json file to get the platform specific information + PLATFORM_JSON=/usr/share/sonic/device/$PLATFORM/platform.json + if [ -f "$PLATFORM_JSON" ]; then + NUM_DPU=$(jq -r '.DPUS | length' $PLATFORM_JSON 2>/dev/null) + jq -e '.DPU' $PLATFORM_JSON >/dev/null + if [[ $? -eq 0 ]]; then + IS_DPU_DEVICE="true" + else + IS_DPU_DEVICE="false" + fi + fi + {%- if sonic_asic_platform == "broadcom" %} {%- if docker_container_name == "syncd" %} # Set the SYNCD_SHM_SIZE if this variable not defined @@ -490,7 +502,7 @@ start() { redis_dir_list=`/usr/bin/python -c "import sys; import os; import json; f=open(sys.argv[1]); \ global_db_dir = os.path.dirname(sys.argv[1]); data=json.load(f); \ print(\" \".join([os.path.normpath(global_db_dir+'/'+elem['include']).partition('sonic-db')[0]\ - for elem in data['INCLUDES'] if 'namespace' in elem])); f.close()" $SONIC_DB_GLOBAL_JSON` + for elem in data['INCLUDES'] if 'namespace' in elem or 'container_name' in elem ])); f.close()" $SONIC_DB_GLOBAL_JSON` fi {%- if docker_container_name == "database" %} @@ -533,6 +545,7 @@ start() { DB_OPT=$DB_OPT" -v /var/run/redis$DEV:/var/run/redis:rw " DB_OPT=$DB_OPT" --env DATABASE_TYPE=$DATABASE_TYPE " DB_OPT=$DB_OPT" --env NUM_DPU=$NUM_DPU " + DB_OPT=$DB_OPT" --env IS_DPU_DEVICE=$IS_DPU_DEVICE " if [[ "$DEV" ]]; then DB_OPT=$DB_OPT" -v /var/run/redis$DEV:/var/run/redis$DEV:rw " fi