version: '3.8'

services:
    cassandra:
        image: cassandra:2.1
        container_name: rfsim4g-cassandra
        networks:
            private_net:
                ipv4_address: 192.168.68.2
        environment:
            CASSANDRA_CLUSTER_NAME: "OAI HSS Cluster"
            CASSANDRA_ENDPOINT_SNITCH: GossipingPropertyFileSnitch
        healthcheck:
            test: /bin/bash -c "nodetool status"
            interval: 10s
            timeout: 5s
            retries: 5

    db_init:
        image: cassandra:2.1
        container_name: rfsim4g-db-init
        depends_on: [cassandra]
        deploy:
            restart_policy:
                condition: on-failure
                max_attempts: 10
        networks:
            private_net:
                ipv4_address: 192.168.68.4
        volumes:
            - ../4g_rfsimulator_fdd_05MHz/oai_db.cql:/home/oai_db.cql
        entrypoint: /bin/bash -c "cqlsh --file /home/oai_db.cql 192.168.68.2 && echo 'OK'"

    oai_hss:
        image: oai-hss:latest
        container_name: rfsim4g-oai-hss
        privileged: true
        depends_on: [cassandra]
        networks:
            private_net:
                ipv4_address: 192.168.68.3
            public_net:
                ipv4_address: 192.168.61.2
        environment:
            REALM: openairinterface.org
            HSS_FQDN: hss.openairinterface.org
            PREFIX: /openair-hss/etc
            cassandra_Server_IP: 192.168.68.2
            OP_KEY: 1006020f0a478bf6b699f15c062e42b3
            LTE_K: fec86ba6eb707ed08905757b1bb44b8f
            APN1: oai.ipv4
            APN2: internet
            FIRST_IMSI: 208960100000001
            NB_USERS: 10
        healthcheck:
            test: /bin/bash -c "pgrep oai_hss"
            interval: 10s
            timeout: 5s
            retries: 5

    redis:
        image: redis:6.0.5
        container_name: rfsim4g-redis
        privileged: true
        networks:
            public_net:
                ipv4_address: 192.168.61.6
        volumes:
            - ../4g_rfsimulator_fdd_05MHz/redis_extern.conf:/usr/local/etc/redis/redis.conf
        entrypoint: /bin/bash -c "redis-server /usr/local/etc/redis/redis.conf"
        healthcheck:
            test: /bin/bash -c "redis-cli -h 192.168.61.6 -p 6380 ping"
            interval: 10s
            timeout: 5s
            retries: 5

    magma_mme:
        image: magma-mme:latest
        container_name: rfsim4g-magma-mme
        hostname: mme
        privileged: true
        depends_on: [oai_hss, redis]
        networks:
            public_net:
                ipv4_address: 192.168.61.3
        environment:
            TZ: Europe/Paris
            REALM: openairinterface.org
            PREFIX: /openair-mme/etc
            HSS_HOSTNAME: hss
            HSS_FQDN: hss.openairinterface.org
            HSS_REALM: openairinterface.org
            MME_FQDN: mme.openairinterface.org
            FEATURES: mme_oai
        volumes:
            - ../4g_rfsimulator_fdd_05MHz/mme_fd.sprint.conf:/magma-mme/etc/mme_fd.conf.tmplt
            - ../4g_rfsimulator_fdd_05MHz/mme.conf:/magma-mme/etc/mme.conf
            - ../4g_rfsimulator_fdd_05MHz/entrypoint.sh:/magma-mme/bin/entrypoint.sh
        entrypoint: /bin/bash -c "/magma-mme/bin/entrypoint.sh"
        healthcheck:
            test: /bin/bash -c "pgrep oai_mme"
            interval: 10s
            timeout: 5s
            retries: 5

    oai_spgwc:
        image: oai-spgwc:latest
        privileged: true
        depends_on: [magma_mme]
        container_name: rfsim4g-oai-spgwc
        networks:
            public_net:
                ipv4_address: 192.168.61.4
        environment:
            TZ: Europe/Paris
            SGW_INTERFACE_NAME_FOR_S11: eth0
            PGW_INTERFACE_NAME_FOR_SX: eth0
            DEFAULT_DNS_IPV4_ADDRESS: 172.21.3.100
            DEFAULT_DNS_SEC_IPV4_ADDRESS: 8.8.4.4
            PUSH_PROTOCOL_OPTION: 'true'
            APN_NI_1: oai.ipv4
            APN_NI_2: oai.ipv4_2
            DEFAULT_APN_NI_1: oai.ipv4
            UE_IP_ADDRESS_POOL_1: '12.0.0.2 - 12.0.0.254'
            UE_IP_ADDRESS_POOL_2: '12.1.1.2 - 12.1.1.254'
            MCC: '208'
            MNC: '96'
            MNC03: '096'
            TAC: 1
            GW_ID: 1
            REALM: openairinterface.org
        healthcheck:
            test: /bin/bash -c "pgrep oai_spgwc"
            interval: 10s
            timeout: 5s
            retries: 5

    oai_spgwu:
        image: oai-spgwu-tiny:latest
        privileged: true
        container_name: rfsim4g-oai-spgwu-tiny
        depends_on: [oai_spgwc]
        networks:
            public_net:
                ipv4_address: 192.168.61.5
        environment:
            TZ: Europe/Paris
            PID_DIRECTORY: /var/run
            INSTANCE: 1
            SGW_INTERFACE_NAME_FOR_S1U_S12_S4_UP: eth0
            PGW_INTERFACE_NAME_FOR_SGI: eth0
            SGW_INTERFACE_NAME_FOR_SX: eth0
            SPGWC0_IP_ADDRESS: 192.168.61.4
            NETWORK_UE_IP: '12.0.0.0/24'
            NETWORK_UE_NAT_OPTION: 'yes'
            MCC: '208'
            MNC: '96'
            MNC03: '096'
            TAC: 1
            GW_ID: 1
            REALM: openairinterface.org
        healthcheck:
            test: /bin/bash -c "pgrep oai_spgwu"
            interval: 10s
            timeout: 5s
            retries: 5

    trf_gen:
        image: oaisoftwarealliance/trf-gen-cn5g:focal
        privileged: true
        container_name: rfsim4g-trf-gen
        networks:
            public_net:
                ipv4_address: 192.168.61.11
        entrypoint: /bin/bash -c "ip route add 12.0.0.0/24 via 192.168.61.5 dev eth0; sleep infinity"
        healthcheck:
            test: /bin/bash -c "ping -c 2 192.168.61.5"
            interval: 10s
            timeout: 5s
            retries: 5

    oai_enb0:
        image: oaisoftwarealliance/oai-enb:develop
        privileged: true
        container_name: rfsim4g-oai-enb
        networks:
            public_net:
                ipv4_address: 192.168.61.20
        environment:
            TZ: Europe/Paris
            USE_ADDITIONAL_OPTIONS: --rfsim --log_config.global_log_options level,nocolor,time
        volumes:
            - ../../conf_files/enb.band38.25prb.rfsim.conf:/opt/oai-enb/etc/enb.conf
        healthcheck:
            test: /bin/bash -c "pgrep lte-softmodem"
            interval: 10s
            timeout: 5s
            retries: 5

    oai_ue0:
        image: oaisoftwarealliance/oai-lte-ue:develop
        privileged: true
        container_name: rfsim4g-oai-lte-ue0
        networks:
            public_net:
                ipv4_address: 192.168.61.30
        expose:
            - "10000"
        environment:
            TZ: Europe/Paris
            USE_ADDITIONAL_OPTIONS: --rfsim -T -C 2605000000 -r 25 --ue-rxgain 140 --ue-txgain 120 --rfsimulator.serveraddr 192.168.61.20 --log_config.global_log_options level,nocolor,time
        volumes:
            - ../../conf_files/lteue.usim-ci.conf:/opt/oai-lte-ue/etc/ue_usim.conf
        healthcheck:
            test: /bin/bash -c "pgrep lte-uesoftmodem"
            interval: 10s
            timeout: 5s
            retries: 5

networks:
    private_net:
        name: rfsim4g-oai-private-net
        ipam:
            config:
                - subnet: 192.168.68.0/26
        driver_opts:
            com.docker.network.bridge.name: "rfsim4g-private"
    public_net:
        name: rfsim4g-oai-public-net
        ipam:
            config:
                - subnet: 192.168.61.0/26
        driver_opts:
            com.docker.network.bridge.name: "rfsim4g-public"
