version: '3.8'
services:
    mysql:
        container_name: "mysql"
        image: mysql:5.7
        volumes:
            - ./oai_db2.sql:/docker-entrypoint-initdb.d/oai_db.sql
            - ./mysql-healthcheck2.sh:/tmp/mysql-healthcheck.sh
        environment:
            - TZ=Europe/Paris
            - MYSQL_DATABASE=oai_db
            - MYSQL_USER=test
            - MYSQL_PASSWORD=test
            - MYSQL_ROOT_PASSWORD=linux
        healthcheck:
            test: /bin/bash -c "/tmp/mysql-healthcheck.sh"
            interval: 10s
            timeout: 5s
            retries: 5
        networks:
            public_net:
                ipv4_address: 192.168.70.131
    oai-udr:
        container_name: "oai-udr"
        image: oai-udr:latest
        environment:
            - TZ=Europe/Paris
            - INSTANCE=0
            - PID_DIRECTORY=/var/run
            - UDR_INTERFACE_NAME_FOR_NUDR=eth0
            - UDR_INTERFACE_PORT_FOR_NUDR=80
            - UDR_INTERFACE_HTTP2_PORT_FOR_NUDR=8080
            - UDR_API_VERSION=v1
            - MYSQL_IPV4_ADDRESS=192.168.70.131
            - MYSQL_USER=test
            - MYSQL_PASS=test
            - MYSQL_DB=oai_db
            - WAIT_MYSQL=120
        depends_on:
            - mysql
        networks:
            public_net:
                ipv4_address: 192.168.70.136
        volumes:
            - ./udr-healthcheck.sh:/openair-udr/bin/udr-healthcheck.sh
        healthcheck:
            test: /bin/bash -c "/openair-udr/bin/udr-healthcheck.sh"
            interval: 10s
            timeout: 5s
            retries: 5
    oai-udm:
        container_name: "oai-udm"
        image: oai-udm:latest
        environment:
            - TZ=Europe/Paris
            - INSTANCE=0
            - PID_DIRECTORY=/var/run
            - UDM_NAME=OAI_UDM
            - SBI_IF_NAME=eth0
            - SBI_PORT=80
            - UDM_VERSION_NB=v1
            - USE_FQDN_DNS=yes
            - UDR_IP_ADDRESS=192.168.70.136
            - UDR_PORT=80
            - UDR_VERSION_NB=v1
            - UDR_FQDN=oai-udr
        depends_on:
            - oai-udr
        networks:
            public_net:
                ipv4_address: 192.168.70.137
        volumes:
            - ./udm-healthcheck.sh:/openair-udm/bin/udm-healthcheck.sh
        healthcheck:
            test: /bin/bash -c "/openair-udm/bin/udm-healthcheck.sh"
            interval: 10s
            timeout: 5s
            retries: 5
    oai-ausf:
        container_name: "oai-ausf"
        image: oai-ausf:latest
        environment:
            - TZ=Europe/Paris
            - INSTANCE_ID=0
            - PID_DIR=/var/run
            - AUSF_NAME=OAI_AUSF
            - SBI_IF_NAME=eth0
            - SBI_PORT=80
            - USE_FQDN_DNS=yes
            - UDM_IP_ADDRESS=192.168.70.137
            - UDM_PORT=80
            - UDM_VERSION_NB=v1
            - UDM_FQDN=oai-udm
        depends_on:
            - oai-udm
        networks:
            public_net:
                ipv4_address: 192.168.70.138
        volumes:
            - ./ausf-healthcheck.sh:/openair-ausf/bin/ausf-healthcheck.sh
        healthcheck:
            test: /bin/bash -c "/openair-ausf/bin/ausf-healthcheck.sh"
            interval: 10s
            timeout: 5s
            retries: 5
    oai-amf:
        container_name: "oai-amf"
        image: oai-amf:latest
        environment:
            - TZ=Europe/paris
            - INSTANCE=0
            - PID_DIRECTORY=/var/run
            - MCC=208
            - MNC=95
            - REGION_ID=128
            - AMF_SET_ID=1
            - SERVED_GUAMI_MCC_0=208
            - SERVED_GUAMI_MNC_0=95
            - SERVED_GUAMI_REGION_ID_0=128
            - SERVED_GUAMI_AMF_SET_ID_0=1
            - SERVED_GUAMI_MCC_1=460
            - SERVED_GUAMI_MNC_1=11
            - SERVED_GUAMI_REGION_ID_1=10
            - SERVED_GUAMI_AMF_SET_ID_1=1
            - PLMN_SUPPORT_MCC=208
            - PLMN_SUPPORT_MNC=95
            - PLMN_SUPPORT_TAC=0xa000
            - SST_0=222
            - SD_0=123
            - SST_1=1
            - SD_1=12
            - AMF_INTERFACE_NAME_FOR_NGAP=eth0
            - AMF_INTERFACE_NAME_FOR_N11=eth0
            - SMF_INSTANCE_ID_0=1
            - SMF_FQDN_0=oai-smf
            - SMF_IPV4_ADDR_0=192.168.70.133
            - SMF_HTTP_VERSION_0=v1
            - SELECTED_0=true
            - SMF_INSTANCE_ID_1=2
            - SMF_FQDN_1=oai-smf
            - SMF_IPV4_ADDR_1=0.0.0.0
            - SMF_HTTP_VERSION_1=v1
            - SELECTED_1=false
            - MYSQL_SERVER=192.168.70.131
            - MYSQL_USER=root
            - MYSQL_PASS=linux
            - MYSQL_DB=oai_db
            - OPERATOR_KEY=63bfa50ee6523365ff14c1f45f88737d
            - NRF_IPV4_ADDRESS=0.0.0.0
            - NRF_PORT=80
            - EXTERNAL_NRF=no
            - NF_REGISTRATION=no
            - SMF_SELECTION=no
            - USE_FQDN_DNS=yes
            - EXTERNAL_AUSF=yes
            - NRF_API_VERSION=v1
            - NRF_FQDN=unknown
            - AUSF_IPV4_ADDRESS=192.168.70.138
            - AUSF_PORT=80
            - AUSF_API_VERSION=v1
            - AUSF_FQDN=oai-ausf
            - UDM_IPV4_ADDRESS=192.168.70.137
            - UDM_PORT=80
            - UDM_API_VERSION=v2
            - UDM_FQDN=oai-udm
        depends_on:
            - mysql
            - vpp-upf
            - oai-ext-dn
            - oai-ausf
        volumes:
            - ./amf-healthcheck.sh:/openair-amf/bin/amf-healthcheck.sh
        healthcheck:
            test: /bin/bash -c "/openair-amf/bin/amf-healthcheck.sh"
            interval: 10s
            timeout: 15s
            retries: 5
        networks:
            public_net:
                ipv4_address: 192.168.70.132
    oai-smf:
        container_name: "oai-smf"
        image: oai-smf:latest
        environment:
            - TZ=Europe/Paris
            - INSTANCE=0
            - PID_DIRECTORY=/var/run
            - SMF_INTERFACE_NAME_FOR_N4=eth0
            - SMF_INTERFACE_NAME_FOR_SBI=eth0
            - SMF_INTERFACE_PORT_FOR_SBI=80
            - SMF_INTERFACE_HTTP2_PORT_FOR_SBI=9090
            - SMF_API_VERSION=v1
            - DEFAULT_DNS_IPV4_ADDRESS=192.168.18.129
            - DEFAULT_DNS_SEC_IPV4_ADDRESS=192.168.18.129
            - AMF_IPV4_ADDRESS=192.168.70.132
            - AMF_PORT=80
            - AMF_API_VERSION=v1
            - AMF_FQDN=oai-amf
            - UDM_IPV4_ADDRESS=192.168.70.137
            - UDM_PORT=80
            - UDM_API_VERSION=v2
            - UDM_FQDN=oai-udm
            - UPF_IPV4_ADDRESS=192.168.70.202
            - UPF_FQDN_0=gw1.vppupf.node.5gcn.mnc95.mcc208.3gppnetwork.org
            - NRF_IPV4_ADDRESS=192.168.70.130
            - NRF_PORT=80
            - NRF_API_VERSION=v1
            - NRF_FQDN=unknown
            - REGISTER_NRF=no
            - DISCOVER_UPF=no
            - USE_FQDN_DNS=yes
            - USE_NETWORK_INSTANCE=yes
            - DNN_RANGE1=12.1.1.2 - 12.1.1.128
            - DNN_RANGE0=12.2.1.2 - 12.2.1.128
            - DNN_NI1=default
        extra_hosts:
            - "gw1.vppupf.node.5gcn.mnc95.mcc208.3gppnetwork.org:192.168.70.202"
        depends_on:
            - oai-amf
        volumes:
             - ./smf-healthcheck.sh:/openair-smf/bin/smf-healthcheck.sh
        healthcheck:
             test: /bin/bash -c "/openair-smf/bin/smf-healthcheck.sh"
             interval: 10s
             timeout: 5s
             retries: 5
        networks:
            public_net:
                ipv4_address: 192.168.70.133
    vpp-upf:
        image: oai-upf-vpp:latest
        privileged: true
        container_name: "vpp-upf"
        environment:
            - NWI_N3=access.oai.org
            - NWI_N6=core.oai.org
            - GW_ID=1
            - MNC03=95
            - MCC=208
            - REALM=3gppnetwork.org
            - NETWORK_UE_IP=12.2.1.0/24
            - N6_IPV4_ADDRESS_REMOTE=192.168.73.135 # EXT-DN (NAT Gateway) IP Address
            - VPP_MAIN_CORE=0
            - VPP_CORE_WORKER=1
#           - VPP_PLUGIN_PATH=/usr/lib64/vpp_plugins/                # RHEL7
            - VPP_PLUGIN_PATH=/usr/lib/x86_64-linux-gnu/vpp_plugins/ # Ubntu18.04
            - INTERFACE_ACCESS=eth1
            - INTERFACE_CORE=eth2
            - INTERFACE_CP=eth0
            - NSSAI_SD_0=222
            - SST=123
            - DNN=default
            - REGISTER_NRF=no
            - NRF_IP_ADDR=0.0.0.0
            - NRF_PORT=80
            - HTTP_VERSION=2
        healthcheck:
            test: /bin/bash -c "pgrep vpp"
            interval: 10s
            timeout: 5s
            retries: 5
        networks:
            public_net:
                ipv4_address: 192.168.70.134
            public_net_access:
                ipv4_address: 192.168.72.134
            public_net_core:
                ipv4_address: 192.168.73.134
    oai-ext-dn:
        image: image: trf-gen-cn5g:latest
        privileged: true
        container_name: "oai-ext-dn"
        entrypoint: /bin/bash -c \
              "iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE;"\
              "ip route add 12.2.1.0/24 via 192.168.73.202 dev eth0; sleep infinity"
        command: ["/bin/bash", "-c", "trap : TERM INT; sleep infinity & wait"]
        depends_on:
            - vpp-upf
        networks:
            public_net_core:
                ipv4_address: 192.168.73.135
networks:
    public_net:
        driver: bridge
        name: demo-oai-public-net
        ipam:
            config:
                - subnet: 192.168.70.0/24
        driver_opts:
            com.docker.network.bridge.name: "demo-oai"
    public_net_access:
        name: oai-public-access
        ipam:
            config:
                - subnet: 192.168.72.0/24
        driver_opts:
            com.docker.network.bridge.name: "cn5g-access"
    public_net_core:
        name: oai-public-core
        ipam:
            config:
                - subnet: 192.168.73.0/24
        driver_opts:
            com.docker.network.bridge.name: "cn5g-core"
