summaryrefslogtreecommitdiffstats
path: root/openbsc
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2014-03-04 17:16:58 +0100
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2014-03-04 20:38:49 +0100
commit3adb772853337666f4d926f2e297e154c25a3881 (patch)
tree7f3c1e151e265a2ec25d641043bfb6f3185fb90a /openbsc
parent6ca9f4f5c33e114940f2f0e66df2b61cd37e0357 (diff)
libbsc: Add command to set MNC/MCC and apply it if something changed
Change the splitting of the ctrl_test_runner.py. Make sure that we get one element and all the rest.
Diffstat (limited to 'openbsc')
-rw-r--r--openbsc/src/libbsc/bsc_ctrl_commands.c59
-rw-r--r--openbsc/tests/ctrl_test_runner.py46
2 files changed, 104 insertions, 1 deletions
diff --git a/openbsc/src/libbsc/bsc_ctrl_commands.c b/openbsc/src/libbsc/bsc_ctrl_commands.c
index fa8e63580..a137efac6 100644
--- a/openbsc/src/libbsc/bsc_ctrl_commands.c
+++ b/openbsc/src/libbsc/bsc_ctrl_commands.c
@@ -93,6 +93,64 @@ static int set_net_apply_config(struct ctrl_cmd *cmd, void *data)
CTRL_CMD_DEFINE(net_apply_config, "apply-configuration");
+static int verify_net_mcc_mnc_apply(struct ctrl_cmd *cmd, const char *value, void *d)
+{
+ char *tmp, *saveptr, *mcc, *mnc;
+
+ tmp = talloc_strdup(cmd, value);
+ if (!tmp)
+ return 1;
+
+ mcc = strtok_r(tmp, ",", &saveptr);
+ mnc = strtok_r(NULL, ",", &saveptr);
+ talloc_free(tmp);
+
+ if (!mcc || !mnc)
+ return 1;
+ return 0;
+}
+
+static int get_net_mcc_mnc_apply(struct ctrl_cmd *cmd, void *data)
+{
+ cmd->reply = "Write only attribute";
+ return CTRL_CMD_ERROR;
+}
+
+static int set_net_mcc_mnc_apply(struct ctrl_cmd *cmd, void *data)
+{
+ struct gsm_network *net = cmd->node;
+ char *tmp, *saveptr, *mcc_str, *mnc_str;
+ int mcc, mnc;
+
+ tmp = talloc_strdup(cmd, cmd->value);
+ if (!tmp)
+ goto oom;
+
+
+ mcc_str = strtok_r(tmp, ",", &saveptr);
+ mnc_str = strtok_r(NULL, ",", &saveptr);
+
+ mcc = atoi(mcc_str);
+ mnc = atoi(mnc_str);
+
+ talloc_free(tmp);
+
+ if (net->network_code == mnc && net->country_code == mcc) {
+ cmd->reply = "Nothing changed";
+ return CTRL_CMD_REPLY;
+ }
+
+ net->network_code = mnc;
+ net->country_code = mcc;
+
+ return set_net_apply_config(cmd, data);
+
+oom:
+ cmd->reply = "OOM";
+ return CTRL_CMD_ERROR;
+}
+CTRL_CMD_DEFINE(net_mcc_mnc_apply, "mcc-mnc-apply");
+
int bsc_base_ctrl_cmds_install(void)
{
int rc = 0;
@@ -101,6 +159,7 @@ int bsc_base_ctrl_cmds_install(void)
rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_net_short_name);
rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_net_long_name);
rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_net_apply_config);
+ rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_net_mcc_mnc_apply);
return rc;
}
diff --git a/openbsc/tests/ctrl_test_runner.py b/openbsc/tests/ctrl_test_runner.py
index 48d073440..5691d76aa 100644
--- a/openbsc/tests/ctrl_test_runner.py
+++ b/openbsc/tests/ctrl_test_runner.py
@@ -1,6 +1,7 @@
#!/usr/bin/env python
# (C) 2013 by Jacob Erlbeck <jerlbeck@sysmocom.de>
+# (C) 2014 by Holger Hans Peter Freyther
# based on vty_test_runner.py:
# (C) 2013 by Katerina Barone-Adesi <kat.obsc@gmail.com>
# (C) 2013 by Holger Hans Peter Freyther
@@ -131,7 +132,7 @@ class TestCtrlBase(unittest.TestCase):
if mtype == "ERROR":
rsp['error'] = msg
else:
- [rsp['var'], rsp['value']] = msg.split(None, 2)
+ [rsp['var'], rsp['value']] = msg.split(None, 1)
responses[id] = rsp
@@ -239,6 +240,49 @@ class TestCtrlBSC(TestCtrlBase):
self.assertEquals(r['var'], 'bts.0.timezone')
self.assertEquals(r['value'], 'off')
+ def testMccMncApply(self):
+ # Test some invalid input
+ r = self.do_set('mcc-mnc-apply', 'WRONG')
+ self.assertEquals(r['mtype'], 'ERROR')
+
+ r = self.do_set('mcc-mnc-apply', '1,')
+ self.assertEquals(r['mtype'], 'ERROR')
+
+ r = self.do_set('mcc-mnc-apply', '200,3')
+ self.assertEquals(r['mtype'], 'SET_REPLY')
+ self.assertEquals(r['var'], 'mcc-mnc-apply')
+ self.assertEquals(r['value'], 'Tried to drop the BTS')
+
+ # Set it again
+ r = self.do_set('mcc-mnc-apply', '200,3')
+ self.assertEquals(r['mtype'], 'SET_REPLY')
+ self.assertEquals(r['var'], 'mcc-mnc-apply')
+ self.assertEquals(r['value'], 'Nothing changed')
+
+ # Change it
+ r = self.do_set('mcc-mnc-apply', '200,4')
+ self.assertEquals(r['mtype'], 'SET_REPLY')
+ self.assertEquals(r['var'], 'mcc-mnc-apply')
+ self.assertEquals(r['value'], 'Tried to drop the BTS')
+
+ # Change it
+ r = self.do_set('mcc-mnc-apply', '201,4')
+ self.assertEquals(r['mtype'], 'SET_REPLY')
+ self.assertEquals(r['var'], 'mcc-mnc-apply')
+ self.assertEquals(r['value'], 'Tried to drop the BTS')
+
+ # Verify
+ r = self.do_get('mnc')
+ self.assertEquals(r['mtype'], 'GET_REPLY')
+ self.assertEquals(r['var'], 'mnc')
+ self.assertEquals(r['value'], '4')
+
+ r = self.do_get('mcc')
+ self.assertEquals(r['mtype'], 'GET_REPLY')
+ self.assertEquals(r['var'], 'mcc')
+ self.assertEquals(r['value'], '201')
+
+
def add_bsc_test(suite, workdir):
if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc/osmo-bsc")):
print("Skipping the BSC test")