1#!/usr/bin/env python3 2# 3# Copyright 2021 - The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the 'License'); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an 'AS IS' BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17import acts.controllers.cellular_lib.BaseCellConfig as base_cell 18import acts.controllers.cellular_lib.LteSimulation as lte_sim 19 20 21class NrCellConfig(base_cell.BaseCellConfig): 22 """ NR cell configuration class. 23 24 Attributes: 25 band: an integer indicating the required band number. 26 bandwidth: a integer indicating the required channel bandwidth 27 """ 28 29 PARAM_BAND = 'band' 30 PARAM_BW = 'bw' 31 PARAM_DL_MCS = 'dlmcs' 32 PARAM_DL_RBS = 'dl_rbs' 33 PARAM_PADDING = 'mac_padding' 34 PARAM_MIMO = 'mimo' 35 PARAM_NRARFCN = 'nr_arfcn' 36 PARAM_SCHEDULING = "scheduling" 37 PARAM_SCHEDULING_DYNAMIC = "dynamic" 38 PARAM_SCHEDULING_STATIC = "static" 39 PARAM_UL_MCS = 'ulmcs' 40 PARAM_UL_RBS = 'ul_rbs' 41 42 def __init__(self, log): 43 """ Initialize the base station config by setting all its 44 parameters to None. 45 Args: 46 log: logger object. 47 """ 48 super().__init__(log) 49 self.band = None 50 self.bandwidth = None 51 self.dl_rbs = None 52 self.ul_rbs = None 53 self.dl_mcs = None 54 self.ul_mcs = None 55 self.mac_padding = None 56 self.mimo_mode = None 57 self.nr_arfcn = None 58 59 def configure(self, parameters): 60 """ Configures an NR cell using a dictionary of parameters. 61 62 Args: 63 parameters: a configuration dictionary 64 """ 65 if self.PARAM_BAND not in parameters: 66 raise ValueError( 67 "The configuration dictionary must include a key '{}' with " 68 "the required band number.".format(self.PARAM_BAND)) 69 nr_band = parameters[self.PARAM_BAND] 70 if nr_band[0] == 'n': 71 nr_band = nr_band[1:] 72 self.band = nr_band 73 74 if self.PARAM_NRARFCN in parameters: 75 self.nr_arfcn = int(parameters[self.PARAM_NRARFCN]) 76 77 if self.PARAM_BW not in parameters: 78 raise ValueError( 79 "The config dictionary must include parameter {} with an " 80 "int value (to indicate 1.4 MHz use 14).".format( 81 self.PARAM_BW)) 82 bw = float(parameters[self.PARAM_BW]) 83 84 if abs(bw - 14) < 0.00000000001: 85 bw = 1.4 86 87 self.bandwidth = bw 88 89 # Setup mimo mode 90 if self.PARAM_MIMO not in parameters: 91 raise ValueError( 92 "The config dictionary must include parameter '{}' with the " 93 "mimo mode.".format(self.PARAM_MIMO)) 94 95 for mimo_mode in lte_sim.MimoMode: 96 if parameters[self.PARAM_MIMO] == mimo_mode.value: 97 self.mimo_mode = mimo_mode 98 break 99 else: 100 raise ValueError("The value of {} must be one of the following:" 101 "1x1, 2x2 or 4x4.".format(self.PARAM_MIMO)) 102 103 if self.PARAM_SCHEDULING not in parameters: 104 self.scheduling_mode = lte_sim.SchedulingMode.STATIC 105 self.log.warning( 106 "The test config does not include the '{}' key. Setting to " 107 "static by default.".format(self.PARAM_SCHEDULING)) 108 elif parameters[ 109 self.PARAM_SCHEDULING] == self.PARAM_SCHEDULING_DYNAMIC: 110 self.scheduling_mode = lte_sim.SchedulingMode.DYNAMIC 111 elif parameters[self.PARAM_SCHEDULING] == self.PARAM_SCHEDULING_STATIC: 112 self.scheduling_mode = lte_sim.SchedulingMode.STATIC 113 else: 114 raise ValueError("Key '{}' must have a value of " 115 "'dynamic' or 'static'.".format( 116 self.PARAM_SCHEDULING)) 117 118 if self.scheduling_mode == lte_sim.SchedulingMode.STATIC: 119 120 if self.PARAM_PADDING not in parameters: 121 self.log.warning( 122 "The '{}' parameter was not set. Enabling MAC padding by " 123 "default.".format(self.PARAM_PADDING)) 124 self.mac_padding = True 125 126 if self.PARAM_DL_MCS in parameters: 127 self.dl_mcs = int(parameters[self.PARAM_DL_MCS]) 128 129 if self.PARAM_UL_MCS in parameters: 130 self.ul_mcs = int(parameters[self.PARAM_UL_MCS]) 131 132 # Temproraily setting: set 273 for bandwidth of 100 MHz 133 self.dl_rbs = 273 134 self.ul_rbs = 273 135 136 def __str__(self): 137 return str(vars(self)) 138