diff mbox

[2/3] nitb/ctrl: Add ctrl command to get/set band

Message ID 1399390559-22655-2-git-send-email-kluchnikovi@gmail.com
State Changes Requested
Headers show

Commit Message

Ivan Kluchnikov May 6, 2014, 3:35 p.m. UTC
---
 openbsc/src/libbsc/bsc_ctrl_commands.c |   33 ++++++++++++++++++++++++++++++++
 openbsc/tests/ctrl_test_runner.py      |   19 ++++++++++++++++++
 2 files changed, 52 insertions(+)

Comments

Holger Freyther May 7, 2014, 7:19 a.m. UTC | #1
On Tue, May 06, 2014 at 07:35:58PM +0400, Ivan Kluchnikov wrote:

> +	if ((int)gsm_band_parse(value) < 0) {
> +		return -1;
> +	}


Same as with the previous patch. Either add a bottom element to
to the gsm_band or return int from the method. But the above is
the wrong thing to do.

> +    def testBtsBand(self):
> +        bands = ['GSM450', 'GSM480', 'GSM750', 'GSM810',
> +                 'GSM850', 'GSM900', 'DCS1800', 'PCS1900']

We handle PCS1800 or DCS900 as well. Maybe just make it 'public'
and add these to the test. E.g. a matrix out of {'GSM','DCS',
'PCS'}x{450, 480, ...} for the test
diff mbox

Patch

diff --git a/openbsc/src/libbsc/bsc_ctrl_commands.c b/openbsc/src/libbsc/bsc_ctrl_commands.c
index 3cb77cc..bbd4fbd 100644
--- a/openbsc/src/libbsc/bsc_ctrl_commands.c
+++ b/openbsc/src/libbsc/bsc_ctrl_commands.c
@@ -183,6 +183,37 @@  oom:
 }
 CTRL_CMD_DEFINE(net_mcc_mnc_apply, "mcc-mnc-apply");
 
+/* BTS related commands below here */
+static int verify_bts_band(struct ctrl_cmd *cmd, const char *value, void *data)
+{
+
+	if ((int)gsm_band_parse(value) < 0) {
+		return -1;
+	}
+
+	return 0;
+}
+
+static int get_bts_band(struct ctrl_cmd *cmd, void *data)
+{
+	struct gsm_bts *bts = cmd->node;
+	cmd->reply = talloc_asprintf(cmd, "%s", gsm_band_name(bts->band));
+	if (!cmd->reply) {
+		cmd->reply = "OOM";
+		return CTRL_CMD_ERROR;
+	}
+	return CTRL_CMD_REPLY;
+}
+
+static int set_bts_band(struct ctrl_cmd *cmd, void *data)
+{
+	struct gsm_bts *bts = cmd->node;
+	bts->band = gsm_band_parse(cmd->value);
+	return get_bts_band(cmd, data);
+}
+
+CTRL_CMD_DEFINE(bts_band, "band");
+
 /* TRX related commands below here */
 CTRL_HELPER_GET_INT(trx_max_power, struct gsm_bts_trx, max_power_red);
 static int verify_trx_max_power(struct ctrl_cmd *cmd, const char *value, void *_data)
@@ -234,6 +265,8 @@  int bsc_base_ctrl_cmds_install(void)
 	rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_net_apply_config);
 	rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_net_mcc_mnc_apply);
 
+	rc |= ctrl_cmd_install(CTRL_NODE_BTS, &cmd_bts_band);
+
 	rc |= ctrl_cmd_install(CTRL_NODE_TRX, &cmd_trx_max_power);
 	return rc;
 }
diff --git a/openbsc/tests/ctrl_test_runner.py b/openbsc/tests/ctrl_test_runner.py
index f24d52a..243ac0f 100644
--- a/openbsc/tests/ctrl_test_runner.py
+++ b/openbsc/tests/ctrl_test_runner.py
@@ -380,6 +380,25 @@  class TestCtrlNITB(TestCtrlBase):
         self.assertEquals(r['mtype'], 'ERROR')
         self.assertEquals(r['error'], 'Value failed verification.')
 
+    def testBtsBand(self):
+        bands = ['GSM450', 'GSM480', 'GSM750', 'GSM810',
+                 'GSM850', 'GSM900', 'DCS1800', 'PCS1900']
+
+        for band in bands:
+            r = self.do_set('bts.0.band', band)
+            self.assertEquals(r['mtype'], 'SET_REPLY')
+            self.assertEquals(r['var'], 'bts.0.band')
+            self.assertEquals(r['value'], band)
+
+            r = self.do_get('bts.0.band')
+            self.assertEquals(r['mtype'], 'GET_REPLY')
+            self.assertEquals(r['var'], 'bts.0.band')
+            self.assertEquals(r['value'], band)
+
+        r = self.do_set('bts.0.band', 'qwerty')
+        self.assertEquals(r['mtype'], 'ERROR')
+        self.assertEquals(r['error'], 'Value failed verification.')
+
     def testSubscriberAddRemove(self):
         r = self.do_set('subscriber-modify-v1', '2620345,445566')
         self.assertEquals(r['mtype'], 'SET_REPLY')