enb: add basic TDD config option

this patch adds the basic notion of FDD and TDD duplexing modes
to the eNB object. So far we've always assume FDD.

Since only Amarisoft eNB supports TDD, the required config
template changes, etc. are only applied there.

The patch also adds a scenario to enable the default TDD config.

Change-Id: I37216b5bfdf527d221913283b6c41d3c8fd6b500
diff --git a/src/osmo_gsm_tester/obj/enb.py b/src/osmo_gsm_tester/obj/enb.py
index f15bbe3..906164e 100644
--- a/src/osmo_gsm_tester/obj/enb.py
+++ b/src/osmo_gsm_tester/obj/enb.py
@@ -30,6 +30,9 @@
         'gtp_bind_addr': schema.IPV4,
         'id': schema.UINT,
         'num_prb': schema.UINT,
+        'duplex': schema.STR,
+        'tdd_uldl_config': schema.UINT,
+        'tdd_special_subframe_pattern': schema.UINT,
         'transmission_mode': schema.LTE_TRANSMISSION_MODE,
         'tx_gain': schema.UINT,
         'rx_gain': schema.UINT,
@@ -83,6 +86,7 @@
         self.set_name('%s_%s' % (name, self._run_node.run_addr()))
         self._txmode = 0
         self._id = None
+        self._duplex = None
         self._num_prb = 0
         self._num_cells = None
         self._epc = None
@@ -144,6 +148,8 @@
         config.overlay(values, dict(enb=self._conf))
         self._id = int(values['enb'].get('id', None))
         assert self._id is not None
+        self._duplex = values['enb'].get('duplex', None)
+        assert self._duplex
         self._num_prb = int(values['enb'].get('num_prb', None))
         assert self._num_prb
         self._txmode = int(values['enb'].get('transmission_mode', None))
diff --git a/src/osmo_gsm_tester/obj/enb_amarisoft.py b/src/osmo_gsm_tester/obj/enb_amarisoft.py
index 9bed63e..ef28100 100644
--- a/src/osmo_gsm_tester/obj/enb_amarisoft.py
+++ b/src/osmo_gsm_tester/obj/enb_amarisoft.py
@@ -263,6 +263,12 @@
         return rfemu_obj
 
     def ue_max_rate(self, downlink=True, num_carriers=1):
+        if self._duplex == 'fdd':
+            return self.ue_max_rate_fdd(downlink, num_carriers)
+        else:
+            return self.ue_max_rate_tdd(downlink, num_carriers)
+
+    def ue_max_rate_fdd(self, downlink, num_carriers):
         # The max rate for a single UE per PRB configuration in TM1 with MCS 28 QAM64
         max_phy_rate_tm1_dl = { 6 : 3.2e6,
                                15 : 9.2e6,
@@ -299,4 +305,19 @@
 
         return max_rate
 
+    def ue_max_rate_tdd(self, downlink, num_carriers):
+        # Max rate calculation for TDD depends on the acutal TDD configuration
+        # See: https://www.sharetechnote.com/html/Handbook_LTE_ThroughputCalculationExample_TDD.html
+        # and https://i0.wp.com/www.techtrained.com/wp-content/uploads/2017/09/Blog_Post_1_TDD_Max_Throughput_Theoretical.jpg
+        max_phy_rate_tdd_uldl_config0_sp0 = { 6 : 1.5e6,
+                               15 : 3.7e6,
+                               25 : 6.1e6,
+                               50 : 12.2e6,
+                               75 : 18.4e6,
+                               100 : 54.5e6 }
+        if downlink:
+            max_rate = max_phy_rate_tdd_uldl_config0_sp0[self.num_prb()]
+        else:
+            return 1e6 # dummy value, we need to replace that later
+
 # vim: expandtab tabstop=4 shiftwidth=4
diff --git a/src/osmo_gsm_tester/templates/amarisoft_enb.cfg.tmpl b/src/osmo_gsm_tester/templates/amarisoft_enb.cfg.tmpl
index c5b8a1e..a0f22ff 100644
--- a/src/osmo_gsm_tester/templates/amarisoft_enb.cfg.tmpl
+++ b/src/osmo_gsm_tester/templates/amarisoft_enb.cfg.tmpl
@@ -100,6 +100,11 @@
       "${'{0:03}'.format(int(enb.mcc))}${'{0:02}'.format(int(enb.mnc))}",
     ],
 
+% if enb.get('duplex') == "tdd":
+    uldl_config: ${enb.tdd_uldl_config},
+    sp_config: ${enb.tdd_special_subframe_pattern},
+% endif
+
 % if int(enb.get('transmission_mode')) == 1:
     n_antenna_dl: 1, /* number of DL antennas */
     n_antenna_ul: 1, /* number of UL antennas */
@@ -180,7 +185,10 @@
         /* TDD ack/nack feedback mode when a rel 10 UE is detected. It
            can be "bundling", "multiplexing", "cs" or "pucch3". By
            default is it the same as tdd_ack_nack_feedback_mode. */
+% if enb.get('duplex') == "tdd":
+        tdd_ack_nack_feedback_mode: "bundling",
         // tdd_ack_nack_feedback_mode_r10: "cs",
+% endif
 
         /* number of PUCCH 1b CS resources. It determines
            the maximum number of UEs that can be scheduled in one TTI