[MERGED] openbsc[master]: Move timezone settings up to network level

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Fri Dec 2 12:09:18 UTC 2016


Harald Welte has submitted this change and it was merged.

Change subject: Move timezone settings up to network level
......................................................................


Move timezone settings up to network level

Time zone used to be configurable per-BTS. In the upcoming MSC-split, no BTS
structures will be available on the MSC level. To simplify, drop the ability to
manage several time zones in a core network and place the time zone config on
the network VTY level, i.e. in gsm_network. If we are going to re-add fine
grained time zone settings, it should probably be tied to the LAC.

Adjust time zone VTY config code (to be moved to libcommon-cs in subsequent commit).

Adjust time zone Ctrl Interface code.

Change-Id: I69848887d92990f3d6f969be80f6ef91f6bdbbe8
---
M openbsc/include/openbsc/gsm_data.h
M openbsc/include/openbsc/gsm_data_shared.h
M openbsc/src/libbsc/bsc_vty.c
M openbsc/src/libmsc/gsm_04_08.c
M openbsc/src/osmo-bsc/osmo_bsc_ctrl.c
M openbsc/src/osmo-bsc/osmo_bsc_filter.c
M openbsc/tests/bsc/bsc_test.c
M openbsc/tests/ctrl_test_runner.py
M openbsc/tests/vty_test_runner.py
9 files changed, 98 insertions(+), 99 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/openbsc/include/openbsc/gsm_data.h b/openbsc/include/openbsc/gsm_data.h
index d4a4d6d..f820ba3 100644
--- a/openbsc/include/openbsc/gsm_data.h
+++ b/openbsc/include/openbsc/gsm_data.h
@@ -273,6 +273,13 @@
 #define GSM_T3113_DEFAULT 60
 #define GSM_T3122_DEFAULT 10
 
+struct gsm_tz {
+	int override; /* if 0, use system's time zone instead. */
+	int hr; /* hour */
+	int mn; /* minute */
+	int dst; /* daylight savings */
+};
+
 struct gsm_network {
 	/* global parameters */
 	uint16_t country_code;
@@ -367,6 +374,13 @@
 
 	/* all active subscriber connections. */
 	struct llist_head subscr_conns;
+
+	/* if override is nonzero, this timezone data is used for all MM
+	 * contexts. */
+	/* TODO: in OsmoNITB, tz-override used to be BTS-specific. To enable
+	 * BTS|RNC specific timezone overrides for multi-tz networks in
+	 * OsmoCSCN, this should be tied to the location area code (LAC). */
+	struct gsm_tz tz;
 };
 
 struct osmo_esme;
diff --git a/openbsc/include/openbsc/gsm_data_shared.h b/openbsc/include/openbsc/gsm_data_shared.h
index af79485..4ec4f69 100644
--- a/openbsc/include/openbsc/gsm_data_shared.h
+++ b/openbsc/include/openbsc/gsm_data_shared.h
@@ -679,14 +679,6 @@
 	/* buffers where we put the pre-computed SI */
 	sysinfo_buf_t si_buf[_MAX_SYSINFO_TYPE];
 
-	/* TimeZone hours, mins, and bts specific */
-	struct {
-		int hr;
-		int mn;
-		int override;
-		int dst;
-	} tz;
-
 	/* ip.accesss Unit ID's have Site/BTS/TRX layout */
 	union {
 		struct {
diff --git a/openbsc/src/libbsc/bsc_vty.c b/openbsc/src/libbsc/bsc_vty.c
index e3f0464..7afa8e1 100644
--- a/openbsc/src/libbsc/bsc_vty.c
+++ b/openbsc/src/libbsc/bsc_vty.c
@@ -554,14 +554,6 @@
 	if (bts->dtxd)
 		vty_out(vty, "  dtx downlink%s", VTY_NEWLINE);
 	vty_out(vty, "  base_station_id_code %u%s", bts->bsic, VTY_NEWLINE);
-	if (bts->tz.override != 0) {
-		if (bts->tz.dst)
-			vty_out(vty, "  timezone %d %d %d%s",
-				bts->tz.hr, bts->tz.mn, bts->tz.dst, VTY_NEWLINE);
-		else
-			vty_out(vty, "  timezone %d %d%s",
-				bts->tz.hr, bts->tz.mn, VTY_NEWLINE);
-	}
 	vty_out(vty, "  ms max power %u%s", bts->ms_max_power, VTY_NEWLINE);
 	vty_out(vty, "  cell reselection hysteresis %u%s",
 		bts->si_common.cell_sel_par.cell_resel_hyst*2, VTY_NEWLINE);
@@ -817,6 +809,15 @@
 	vty_out(vty, " timer t3141 %u%s", gsmnet->T3141, VTY_NEWLINE);
 	vty_out(vty, " subscriber-keep-in-ram %d%s",
 		gsmnet->subscr_group->keep_subscr, VTY_NEWLINE);
+	if (gsmnet->tz.override != 0) {
+		if (gsmnet->tz.dst)
+			vty_out(vty, " timezone %d %d %d%s",
+				gsmnet->tz.hr, gsmnet->tz.mn, gsmnet->tz.dst,
+				VTY_NEWLINE);
+		else
+			vty_out(vty, " timezone %d %d%s",
+				gsmnet->tz.hr, gsmnet->tz.mn, VTY_NEWLINE);
+	}
 
 	return CMD_SUCCESS;
 }
@@ -1735,10 +1736,10 @@
 	return CMD_SUCCESS;
 }
 
-DEFUN(cfg_bts_timezone,
-      cfg_bts_timezone_cmd,
+DEFUN(cfg_net_timezone,
+      cfg_net_timezone_cmd,
       "timezone <-19-19> (0|15|30|45)",
-      "Set the Timezone Offset of this BTS\n"
+      "Set the Timezone Offset of the network\n"
       "Timezone offset (hours)\n"
       "Timezone offset (00 minutes)\n"
       "Timezone offset (15 minutes)\n"
@@ -1746,22 +1747,22 @@
       "Timezone offset (45 minutes)\n"
       )
 {
-	struct gsm_bts *bts = vty->index;
+	struct gsm_network *net = vty->index;
 	int tzhr = atoi(argv[0]);
 	int tzmn = atoi(argv[1]);
 
-	bts->tz.hr = tzhr;
-	bts->tz.mn = tzmn;
-	bts->tz.dst = 0;
-	bts->tz.override = 1;
+	net->tz.hr = tzhr;
+	net->tz.mn = tzmn;
+	net->tz.dst = 0;
+	net->tz.override = 1;
 
 	return CMD_SUCCESS;
 }
 
-DEFUN(cfg_bts_timezone_dst,
-      cfg_bts_timezone_dst_cmd,
+DEFUN(cfg_net_timezone_dst,
+      cfg_net_timezone_dst_cmd,
       "timezone <-19-19> (0|15|30|45) <0-2>",
-      "Set the Timezone Offset of this BTS\n"
+      "Set the Timezone Offset of the network\n"
       "Timezone offset (hours)\n"
       "Timezone offset (00 minutes)\n"
       "Timezone offset (15 minutes)\n"
@@ -1770,28 +1771,28 @@
       "DST offset (hours)\n"
       )
 {
-	struct gsm_bts *bts = vty->index;
+	struct gsm_network *net = vty->index;
 	int tzhr = atoi(argv[0]);
 	int tzmn = atoi(argv[1]);
 	int tzdst = atoi(argv[2]);
 
-	bts->tz.hr = tzhr;
-	bts->tz.mn = tzmn;
-	bts->tz.dst = tzdst;
-	bts->tz.override = 1;
+	net->tz.hr = tzhr;
+	net->tz.mn = tzmn;
+	net->tz.dst = tzdst;
+	net->tz.override = 1;
 
 	return CMD_SUCCESS;
 }
 
-DEFUN(cfg_bts_no_timezone,
-      cfg_bts_no_timezone_cmd,
+DEFUN(cfg_net_no_timezone,
+      cfg_net_no_timezone_cmd,
       "no timezone",
       NO_STR
-      "Disable BTS specific timezone\n")
+      "Disable network timezone override, use system tz\n")
 {
-	struct gsm_bts *bts = vty->index;
+	struct gsm_network *net = vty->index;
 
-	bts->tz.override = 0;
+	net->tz.override = 0;
 
 	return CMD_SUCCESS;
 }
@@ -3949,6 +3950,9 @@
 	install_element(GSMNET_NODE, &cfg_net_T3141_cmd);
 	install_element(GSMNET_NODE, &cfg_net_dtx_cmd);
 	install_element(GSMNET_NODE, &cfg_net_pag_any_tch_cmd);
+	install_element(GSMNET_NODE, &cfg_net_timezone_cmd);
+	install_element(GSMNET_NODE, &cfg_net_timezone_dst_cmd);
+	install_element(GSMNET_NODE, &cfg_net_no_timezone_cmd);
 
 	install_element(GSMNET_NODE, &cfg_bts_cmd);
 	install_node(&bts_node, config_write_bts);
@@ -3967,9 +3971,6 @@
 	install_element(BTS_NODE, &cfg_bts_bsic_cmd);
 	install_element(BTS_NODE, &cfg_bts_unit_id_cmd);
 	install_element(BTS_NODE, &cfg_bts_rsl_ip_cmd);
-	install_element(BTS_NODE, &cfg_bts_timezone_cmd);
-	install_element(BTS_NODE, &cfg_bts_timezone_dst_cmd);
-	install_element(BTS_NODE, &cfg_bts_no_timezone_cmd);
 	install_element(BTS_NODE, &cfg_bts_nokia_site_skip_reset_cmd);
 	install_element(BTS_NODE, &cfg_bts_nokia_site_no_loc_rel_cnf_cmd);
 	install_element(BTS_NODE, &cfg_bts_nokia_site_bts_reset_timer_cnf_cmd);
diff --git a/openbsc/src/libmsc/gsm_04_08.c b/openbsc/src/libmsc/gsm_04_08.c
index 3e362fa..d10f8cf 100644
--- a/openbsc/src/libmsc/gsm_04_08.c
+++ b/openbsc/src/libmsc/gsm_04_08.c
@@ -733,7 +733,6 @@
 	struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 MM INF");
 	struct gsm48_hdr *gh;
 	struct gsm_network *net = conn->network;
-	struct gsm_bts *bts = conn->bts;
 	uint8_t *ptr8;
 	int name_len, name_pad;
 
@@ -821,23 +820,23 @@
 	ptr8[5] = bcdify(gmt_time->tm_min);
 	ptr8[6] = bcdify(gmt_time->tm_sec);
 
-	if (bts->tz.override) {
+	if (net->tz.override) {
 		/* Convert tz.hr and tz.mn to units */
-		if (bts->tz.hr < 0) {
-			tzunits = ((bts->tz.hr/-1)*4);
-			tzunits = tzunits + (bts->tz.mn/15);
+		if (net->tz.hr < 0) {
+			tzunits = ((net->tz.hr/-1)*4);
+			tzunits = tzunits + (net->tz.mn/15);
 			ptr8[7] = bcdify(tzunits);
 			/* Set negative time */
 			ptr8[7] |= 0x08;
 		}
 		else {
-			tzunits = bts->tz.hr*4;
-			tzunits = tzunits + (bts->tz.mn/15);
+			tzunits = net->tz.hr*4;
+			tzunits = tzunits + (net->tz.mn/15);
 			ptr8[7] = bcdify(tzunits);
 		}
 		/* Convert DST value */
-		if (bts->tz.dst >= 0 && bts->tz.dst <= 2)
-			dst = bts->tz.dst;
+		if (net->tz.dst >= 0 && net->tz.dst <= 2)
+			dst = net->tz.dst;
 	}
 	else {
 		/* Need to get GSM offset and convert into 15 min units */
diff --git a/openbsc/src/osmo-bsc/osmo_bsc_ctrl.c b/openbsc/src/osmo-bsc/osmo_bsc_ctrl.c
index 40e1960..f10a74a 100644
--- a/openbsc/src/osmo-bsc/osmo_bsc_ctrl.c
+++ b/openbsc/src/osmo-bsc/osmo_bsc_ctrl.c
@@ -362,18 +362,15 @@
 	return 1;
 }
 
-CTRL_CMD_DEFINE(bts_timezone, "timezone");
-static int get_bts_timezone(struct ctrl_cmd *cmd, void *data)
+CTRL_CMD_DEFINE(net_timezone, "timezone");
+static int get_net_timezone(struct ctrl_cmd *cmd, void *data)
 {
-	struct gsm_bts *bts = (struct gsm_bts *) cmd->node;
-	if (!bts) {
-		cmd->reply = "bts not found.";
-		return CTRL_CMD_ERROR;
-	}
+	struct gsm_network *net = (struct gsm_network*)cmd->node;
 
-	if (bts->tz.override)
+	struct gsm_tz *tz = &net->tz;
+	if (tz->override)
 		cmd->reply = talloc_asprintf(cmd, "%d,%d,%d",
-			       bts->tz.hr, bts->tz.mn, bts->tz.dst);
+			       tz->hr, tz->mn, tz->dst);
 	else
 		cmd->reply = talloc_asprintf(cmd, "off");
 
@@ -385,16 +382,11 @@
 	return CTRL_CMD_REPLY;
 }
 
-static int set_bts_timezone(struct ctrl_cmd *cmd, void *data)
+static int set_net_timezone(struct ctrl_cmd *cmd, void *data)
 {
 	char *saveptr, *hourstr, *minstr, *dststr, *tmp = 0;
 	int override;
-	struct gsm_bts *bts = (struct gsm_bts *) cmd->node;
-
-	if (!bts) {
-		cmd->reply = "bts not found.";
-		return CTRL_CMD_ERROR;
-	}
+	struct gsm_network *net = (struct gsm_network*)cmd->node;
 
 	tmp = talloc_strdup(cmd, cmd->value);
 	if (!tmp)
@@ -409,25 +401,26 @@
 	if (hourstr != NULL)
 		override = strcasecmp(hourstr, "off") != 0;
 
-	bts->tz.override = override;
+	struct gsm_tz *tz = &net->tz;
+	tz->override = override;
 
 	if (override) {
-		bts->tz.hr  = hourstr ? atol(hourstr) : 0;
-		bts->tz.mn  = minstr ? atol(minstr) : 0;
-		bts->tz.dst = dststr ? atol(dststr) : 0;
+		tz->hr  = hourstr ? atol(hourstr) : 0;
+		tz->mn  = minstr ? atol(minstr) : 0;
+		tz->dst = dststr ? atol(dststr) : 0;
 	}
 
 	talloc_free(tmp);
 	tmp = NULL;
 
-	return get_bts_timezone(cmd, data);
+	return get_net_timezone(cmd, data);
 
 oom:
 	cmd->reply = "OOM";
 	return CTRL_CMD_ERROR;
 }
 
-static int verify_bts_timezone(struct ctrl_cmd *cmd, const char *value, void *data)
+static int verify_net_timezone(struct ctrl_cmd *cmd, const char *value, void *data)
 {
 	char *saveptr, *hourstr, *minstr, *dststr, *tmp;
 	int override, tz_hours, tz_mins, tz_dst;
@@ -655,7 +648,7 @@
 	rc = ctrl_cmd_install(CTRL_NODE_BTS, &cmd_bts_loc);
 	if (rc)
 		goto end;
-	rc = ctrl_cmd_install(CTRL_NODE_BTS, &cmd_bts_timezone);
+	rc = ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_net_timezone);
 	if (rc)
 		goto end;
 	rc = ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_msc_connection_status);
diff --git a/openbsc/src/osmo-bsc/osmo_bsc_filter.c b/openbsc/src/osmo-bsc/osmo_bsc_filter.c
index 66c6406..d5ca2fd 100644
--- a/openbsc/src/osmo-bsc/osmo_bsc_filter.c
+++ b/openbsc/src/osmo-bsc/osmo_bsc_filter.c
@@ -270,23 +270,24 @@
 		return 0;
 
 	/* Is TZ patching enabled? */
-	if (!bts->tz.override)
+	struct gsm_tz *tz = &bts->network->tz;
+	if (!tz->override)
 		return 0;
 
 	/* Convert tz.hr and tz.mn to units */
-	if (bts->tz.hr < 0) {
-		tzunits = -bts->tz.hr*4;
+	if (tz->hr < 0) {
+		tzunits = -tz->hr*4;
 		tzbsd |= 0x08;
 	} else
-		tzunits = bts->tz.hr*4;
+		tzunits = tz->hr*4;
 
-	tzunits = tzunits + (bts->tz.mn/15);
+	tzunits = tzunits + (tz->mn/15);
 
 	tzbsd |= (tzunits % 10)*0x10 + (tzunits / 10);
 
 	/* Convert DST value */
-	if (bts->tz.dst >= 0 && bts->tz.dst <= 2)
-		dst = bts->tz.dst;
+	if (tz->dst >= 0 && tz->dst <= 2)
+		dst = tz->dst;
 
 	if (TLVP_PRESENT(&tp, GSM48_IE_UTC)) {
 		LOGP(DMSC, LOGL_DEBUG,
diff --git a/openbsc/tests/bsc/bsc_test.c b/openbsc/tests/bsc/bsc_test.c
index 6d41941..7174828 100644
--- a/openbsc/tests/bsc/bsc_test.c
+++ b/openbsc/tests/bsc/bsc_test.c
@@ -147,10 +147,10 @@
 		struct msgb *msg = msgb_alloc(4096, "test-message");
 		int is_set = 0;
 
-		bts->tz.hr = get_int(test_def->params, test_def->n_params, "tz_hr", 0, &is_set);
-		bts->tz.mn = get_int(test_def->params, test_def->n_params, "tz_mn", 0, &is_set);
-		bts->tz.dst = get_int(test_def->params, test_def->n_params, "tz_dst", 0, &is_set);
-		bts->tz.override = 1;
+		net->tz.hr = get_int(test_def->params, test_def->n_params, "tz_hr", 0, &is_set);
+		net->tz.mn = get_int(test_def->params, test_def->n_params, "tz_mn", 0, &is_set);
+		net->tz.dst = get_int(test_def->params, test_def->n_params, "tz_dst", 0, &is_set);
+		net->tz.override = 1;
 
 		printf("Going to test item: %d\n", i);
 		msg->l3h = msgb_put(msg, test_def->length);
diff --git a/openbsc/tests/ctrl_test_runner.py b/openbsc/tests/ctrl_test_runner.py
index bed685a..4fd831f 100644
--- a/openbsc/tests/ctrl_test_runner.py
+++ b/openbsc/tests/ctrl_test_runner.py
@@ -331,41 +331,41 @@
         self.assertEquals(r['value'], 'state=off,policy=on')
 
     def testTimezone(self):
-        r = self.do_get('bts.0.timezone')
+        r = self.do_get('timezone')
         self.assertEquals(r['mtype'], 'GET_REPLY')
-        self.assertEquals(r['var'], 'bts.0.timezone')
+        self.assertEquals(r['var'], 'timezone')
         self.assertEquals(r['value'], 'off')
 
-        r = self.do_set('bts.0.timezone', '-2,15,2')
+        r = self.do_set('timezone', '-2,15,2')
         self.assertEquals(r['mtype'], 'SET_REPLY')
-        self.assertEquals(r['var'], 'bts.0.timezone')
+        self.assertEquals(r['var'], 'timezone')
         self.assertEquals(r['value'], '-2,15,2')
 
-        r = self.do_get('bts.0.timezone')
+        r = self.do_get('timezone')
         self.assertEquals(r['mtype'], 'GET_REPLY')
-        self.assertEquals(r['var'], 'bts.0.timezone')
+        self.assertEquals(r['var'], 'timezone')
         self.assertEquals(r['value'], '-2,15,2')
 
         # Test invalid input
-        r = self.do_set('bts.0.timezone', '-2,15,2,5,6,7')
+        r = self.do_set('timezone', '-2,15,2,5,6,7')
         self.assertEquals(r['mtype'], 'SET_REPLY')
-        self.assertEquals(r['var'], 'bts.0.timezone')
+        self.assertEquals(r['var'], 'timezone')
         self.assertEquals(r['value'], '-2,15,2')
 
-        r = self.do_set('bts.0.timezone', '-2,15')
+        r = self.do_set('timezone', '-2,15')
         self.assertEquals(r['mtype'], 'ERROR')
-        r = self.do_set('bts.0.timezone', '-2')
+        r = self.do_set('timezone', '-2')
         self.assertEquals(r['mtype'], 'ERROR')
-        r = self.do_set('bts.0.timezone', '1')
+        r = self.do_set('timezone', '1')
 
-        r = self.do_set('bts.0.timezone', 'off')
+        r = self.do_set('timezone', 'off')
         self.assertEquals(r['mtype'], 'SET_REPLY')
-        self.assertEquals(r['var'], 'bts.0.timezone')
+        self.assertEquals(r['var'], 'timezone')
         self.assertEquals(r['value'], 'off')
 
-        r = self.do_get('bts.0.timezone')
+        r = self.do_get('timezone')
         self.assertEquals(r['mtype'], 'GET_REPLY')
-        self.assertEquals(r['var'], 'bts.0.timezone')
+        self.assertEquals(r['var'], 'timezone')
         self.assertEquals(r['value'], 'off')
 
     def testMcc(self):
diff --git a/openbsc/tests/vty_test_runner.py b/openbsc/tests/vty_test_runner.py
index a73dadd..cf2cf18 100644
--- a/openbsc/tests/vty_test_runner.py
+++ b/openbsc/tests/vty_test_runner.py
@@ -651,7 +651,6 @@
         self.vty.enable()
         self.vty.verify("configure terminal", [''])
         self.vty.verify("network", [''])
-        self.vty.verify("bts 0", [''])
 
         # Test invalid input
         self.vty.verify("timezone", ['% Command incomplete.'])

-- 
To view, visit https://gerrit.osmocom.org/1137
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I69848887d92990f3d6f969be80f6ef91f6bdbbe8
Gerrit-PatchSet: 9
Gerrit-Project: openbsc
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>



More information about the gerrit-log mailing list