arehbein has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-bsc/+/30982 )
Change subject: bsc_ctrl_commands: Add GET for bts neighbor-list (local bts numbers) ......................................................................
bsc_ctrl_commands: Add GET for bts neighbor-list (local bts numbers)
Related: SYS#6287 Change-Id: I79aeffd93089086f57c66787fe20b439a4d8b6b4 --- M src/osmo-bsc/bts_ctrl.c A tests/ctrl/osmo-bsc-neighbor-list.cfg M tests/ctrl_test_runner.py 3 files changed, 180 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-bsc refs/changes/82/30982/1
diff --git a/src/osmo-bsc/bts_ctrl.c b/src/osmo-bsc/bts_ctrl.c index 728d89f..3a16b94 100644 --- a/src/osmo-bsc/bts_ctrl.c +++ b/src/osmo-bsc/bts_ctrl.c @@ -21,6 +21,7 @@
#include <errno.h> #include <time.h> +#include <inttypes.h>
#include <osmocom/ctrl/control_cmd.h>
@@ -578,6 +579,56 @@
CTRL_CMD_DEFINE_WO(bts_neighbor_list_del, "neighbor-list del");
+static void write_neighbors(struct llist_head *neighbors, struct osmo_strbuf *csv) +{ + struct neighbor *n; + llist_for_each_entry(n, neighbors, entry) { + if (n->type == NEIGHBOR_TYPE_BTS_NR) { + OSMO_STRBUF_PRINTF(*csv, "%" PRIu8 ",", n->bts_nr); + } + } +} + +static int get_bts_neighbor_list(struct ctrl_cmd *cmd, void *data) +{ + size_t buf_on_heap = 0; + char log_buf[4096]; + struct osmo_strbuf csv = { .buf = log_buf, + .len = sizeof(log_buf), + .pos = log_buf, + .chars_needed = 0 + }; + struct gsm_bts *bts = (struct gsm_bts *)cmd->node; + if (!bts) { + cmd->reply = "bts not found."; + return CTRL_CMD_ERROR; + } + write_neighbors(&bts->neighbors, &csv); + if (csv.chars_needed >= csv.len) { /* Just to be save, although this is very unlikely */ + buf_on_heap = csv.chars_needed + 1; + if (!(csv.buf = talloc_zero_size(cmd, buf_on_heap))) + goto oom; + csv.len = buf_on_heap; + csv.pos = csv.buf; + csv.chars_needed = 0; + write_neighbors(&bts->neighbors, &csv); + } + if (csv.buf == csv.pos) { + cmd->reply = "No BTS neighbors configured through BTS number"; + } else {/* Get rid of trailing comma */ + csv.pos[-1] = '\0'; + if (!(cmd->reply = talloc_strdup(cmd, csv.buf))) + goto oom; + } + return CTRL_CMD_REPLY; + +oom: + cmd->reply = "OOM"; + return CTRL_CMD_ERROR; +} + +CTRL_CMD_DEFINE_RO(bts_neighbor_list, "neighbor-list"); + static int verify_bts_neighbor_list_mode(struct ctrl_cmd *cmd, const char *value, void *_data) { if (!strcmp(value, "automatic")) @@ -643,6 +694,7 @@ rc |= ctrl_cmd_install(CTRL_NODE_BTS, &cmd_bts_neighbor_list_add); rc |= ctrl_cmd_install(CTRL_NODE_BTS, &cmd_bts_neighbor_list_del); rc |= ctrl_cmd_install(CTRL_NODE_BTS, &cmd_bts_neighbor_list_mode); + rc |= ctrl_cmd_install(CTRL_NODE_BTS, &cmd_bts_neighbor_list);
rc |= neighbor_ident_ctrl_init();
diff --git a/tests/ctrl/osmo-bsc-neighbor-list.cfg b/tests/ctrl/osmo-bsc-neighbor-list.cfg new file mode 100644 index 0000000..6d58b43 --- /dev/null +++ b/tests/ctrl/osmo-bsc-neighbor-list.cfg @@ -0,0 +1,109 @@ +network + bts 1 + type osmo-bts + band DCS1800 + cell_identity 123 + location_area_code 0x0001 + base_station_id_code 55 + ms max power 15 + cell reselection hysteresis 4 + rxlev access min 0 + radio-link-timeout 32 + channel allocator mode set-all ascending + rach tx integer 9 + rach max transmission 7 + channel-description attach 1 + channel-description bs-pa-mfrms 5 + channel-description bs-ag-blks-res 1 + early-classmark-sending forbidden + ipa unit-id 55 0 + oml ipa stream-id 255 line 0 + codec-support fr + gprs mode gprs + gprs routing area 6 + neighbor bts 0 + neighbor bts 2 + trx 0 + rf_locked 0 + arfcn 880 + nominal power 23 + ! to use full TRX power, set max_power_red 0 + max_power_red 20 + rsl e1 tei 0 + timeslot 0 + phys_chan_config CCCH+SDCCH4 + hopping enabled 0 + timeslot 1 + phys_chan_config TCH/F + hopping enabled 0 + timeslot 2 + phys_chan_config TCH/F + hopping enabled 0 + timeslot 3 + phys_chan_config TCH/F + hopping enabled 0 + timeslot 4 + phys_chan_config TCH/F + hopping enabled 0 + timeslot 5 + phys_chan_config TCH/F + hopping enabled 0 + timeslot 6 + phys_chan_config TCH/F + hopping enabled 0 + timeslot 7 + phys_chan_config TCH/F + hopping enabled 0 + bts 2 + type osmo-bts + band DCS1800 + cell_identity 125 + location_area_code 0x0001 + base_station_id_code 55 + ms max power 15 + cell reselection hysteresis 4 + rxlev access min 0 + radio-link-timeout 32 + channel allocator mode set-all ascending + rach tx integer 9 + rach max transmission 7 + channel-description attach 1 + channel-description bs-pa-mfrms 5 + channel-description bs-ag-blks-res 1 + early-classmark-sending forbidden + ipa unit-id 55 0 + oml ipa stream-id 255 line 0 + codec-support fr + gprs mode gprs + gprs routing area 6 + trx 0 + rf_locked 0 + arfcn 880 + nominal power 23 + ! to use full TRX power, set max_power_red 0 + max_power_red 20 + rsl e1 tei 0 + timeslot 0 + phys_chan_config CCCH+SDCCH4 + hopping enabled 0 + timeslot 1 + phys_chan_config TCH/F + hopping enabled 0 + timeslot 2 + phys_chan_config TCH/F + hopping enabled 0 + timeslot 3 + phys_chan_config TCH/F + hopping enabled 0 + timeslot 4 + phys_chan_config TCH/F + hopping enabled 0 + timeslot 5 + phys_chan_config TCH/F + hopping enabled 0 + timeslot 6 + phys_chan_config TCH/F + hopping enabled 0 + timeslot 7 + phys_chan_config TCH/F + hopping enabled 0 diff --git a/tests/ctrl_test_runner.py b/tests/ctrl_test_runner.py index 4c07d5e..8e92159 100755 --- a/tests/ctrl_test_runner.py +++ b/tests/ctrl_test_runner.py @@ -526,6 +526,7 @@ self.assertEqual(r['value'], 'OK')
def testNeighborList(self): + # Enter manual neighbor-list mode r = self.do_set('bts.0.neighbor-list.mode', 'manual') print('respose: ' + str(r)) @@ -566,6 +567,24 @@ self.assertEqual(r['mtype'], 'ERROR') self.assertEqual(r['error'], 'Invalid mode')
+ def testCtrlNeighborList(self): + + # Use alternative config file with neighbors (tested above...) + vty_cfg = os.path.join(confpath, 'tests/ctrl/osmo-bsc-neighbor-list.cfg') + r = self.do_set('apply-config-file', vty_cfg) + + # Get BTS locally configured neighbors (when none configured) + r = self.do_get('bts.0.neighbor-list') + self.assertEqual(r['mtype'], 'GET_REPLY') + self.assertEqual(r['var'], 'bts.0.neighbor-list') + self.assertEqual(r['value'], 'No BTS neighbors configured through BTS number') + + # Get BTS locally configured neighbors + r = self.do_get('bts.1.neighbor-list') + self.assertEqual(r['mtype'], 'GET_REPLY') + self.assertEqual(r['var'], 'bts.1.neighbor-list') + self.assertEqual(r['value'], '0,2') + class TestCtrlBSCNeighbor(TestCtrlBase):
def tearDown(self):