import time
import json
import slapos.testing.e2e as e2e
from amari_test_common import AmarisoftTestMixin

class BBUTest(AmarisoftTestMixin, e2e.EndToEndTestCase):
    @classmethod
    def setTestParameters(cls):
        cls.enb_instance_name = time.strftime('e2e-cb003-enb-%Y-%B-%d-%H:%M:%S')
        cls.cn_instance_name = time.strftime('e2e-cb003-core-network-%Y-%B-%d-%H:%M:%S')
        cls.sim_instance_name = time.strftime('e2e-cb003-sim-%Y-%B-%d-%H:%M:%S')
        cls.ue_instance_name = time.strftime('e2e-sb005-ue-%Y-%B-%d-%H:%M:%S')
        cls.product = "/opt/e2e/slapos/software/ors-amarisoft/software-fdd-lopcomm.cfg"
        cls.ue_product = "/opt/e2e/slapos/software/ors-amarisoft/software-fdd-lopcomm.cfg"

        cls.comp_enb ="COMP-3920"
        cls.comp_cn = "COMP-3920"
        cls.comp_ue = "COMP-3756"
        cls.dl_earfcn = 300

    @classmethod
    def request_enb(cls, custom_params=None):
        enb_parameters = {
            "bandwidth": "20 MHz",
            "n_antenna_dl": 1,
            "n_antenna_ul": 1,
            "cpri_mult": 16,
            "cell_list": {
                "RRH-B1": {
                    "cpri_rx_delay": 25.11,
                    "cpri_tx_delay": 13.77,
                    "cpri_tx_dbm": 56,
                    "ru_mac_addr": "00:0a:00:00:10:20",
                    "dl_earfcn": cls.dl_earfcn
                }
            },
            "dnsmasq": True,
            "txa0cc00_active": "ACTIVE",
            "rxa0cc00_active": "ACTIVE",
            "txa0cc00_center_frequency": 2140,
            "rxa0cc00_center_frequency_earfcn": 18300,
            "rxa0cc00_center_frequency": 1950,
            "txa0cc00_gain": -20,
            "user-authorized-key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDegkDlZaDJEoiXo5FZ5iJmYcVHyqd5G+YaWLmZ/Ae6wtY8Pp0e/+eCcARO67pwn73MAj9IELu3h5rdPuZvZx0xXWGOc3ceOQBsJh/h4eMpiBKvA5ELWVuXDIl98xgIIjiaO4QgZyw1OhpN5EB6EyUNKt/xCHuU37mZaFLbcNDW3h6JI5U5plIARY0e/dFPFywtKqCgnqhJubJh/kHcb4ZeJzQMnA33WGwVD/b+F015kHXfk4T259Z27yqMTokVjaiUnI2Wbac3e+Lc5bpecA68rlmhc6fs0bh5Geldy2Q8y8gJQUX3sihA9PjlDN+T8mNYHyk9QaCM/SQkwxB71D172nMoUcrppUZyf6JaLmB/cO0iVsIr8x2GnGT0EzL/y1hmvi1dD17E0DpgoRcjI3DxleTbUTpayT4ZHrtVnkp2Nf1LgEJmdTx0hqTb9HTqhXATTKLSETYAwIu0yWnlA9oK2MwsiPPQ/8IS5HzhN3XFEIdV+tQ7GZPVfv4sYpwt7us= root@root",
            "plmn_list": {"Australia": {"plmn": "50501"}}
        }

        if custom_params:
            enb_parameters.update(custom_params)

        json_enb_parameters = json.dumps(enb_parameters)

        cls.retry_request(cls.request, cls.product, cls.enb_instance_name,
                          filter_kw={"computer_guid": cls.comp_enb},
                          partition_parameter_kw={'_': json_enb_parameters},
                          software_type='enb')

    def test_max_rx_sample_db(self):
        pass

    def test_min_rxtx_delay(self):
        custom_params = {"min_rxtx_delay": 99}
        self.request_enb(custom_params)
        self.waitUntilPromises(self.enb_instance_name, promise_name="check-baseband-latency", expected=False)

