dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/28218 )
Change subject: commands: add ".." notation to expand hexstrings
......................................................................
commands: add ".." notation to expand hexstrings
When updating files and records there are sometimes huge portions that
are just 0xff. Mostly this is at the end of a file or record that is not
completely used. Lets add a notation to tell PySim-shell how to fill
those sections.
Change-Id: Iedd7887bf7d706878f4a3beca8dbea456404610b
---
M pySim/commands.py
M pySim/utils.py
2 files changed, 64 insertions(+), 5 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/18/28218/1
diff --git a/pySim/commands.py b/pySim/commands.py
index a959851..7b50677 100644
--- a/pySim/commands.py
+++ b/pySim/commands.py
@@ -23,7 +23,7 @@
from construct import *
from pySim.construct import LV
-from pySim.utils import rpad, b2h, h2b, sw_match, bertlv_encode_len, Hexstr, h2i, str_sanitize
+from pySim.utils import rpad, b2h, h2b, sw_match, bertlv_encode_len, Hexstr, h2i, str_sanitize, expand_hex
from pySim.exceptions import SwMatchError
@@ -190,6 +190,10 @@
offset : byte offset in file from which to start writing
verify : Whether or not to verify data after write
"""
+
+ file_len = self.binary_size(ef)
+ data = expand_hex(data, file_len)
+
data_length = len(data) // 2
# Save write cycles by reading+comparing before write
@@ -255,16 +259,17 @@
verify : verify data by re-reading the record
conserve : read record and compare it with data, skip write on match
"""
+
res = self.select_path(ef)
+ rec_length = self.__record_len(res)
+ data = expand_hex(data, rec_length)
if force_len:
# enforce the record length by the actual length of the given data input
rec_length = len(data) // 2
else:
- # determine the record length from the select response of the file and pad
- # the input data with 0xFF if necessary. In cases where the input data
- # exceed we throw an exception.
- rec_length = self.__record_len(res)
+ # make sure the input data is padded to the record length using 0xFF.
+ # In cases where the input data exceed we throw an exception.
if (len(data) // 2 > rec_length):
raise ValueError('Data length exceeds record length (expected max %d, got %d)' % (
rec_length, len(data) // 2))
diff --git a/pySim/utils.py b/pySim/utils.py
index ef770f9..6b8ee37 100644
--- a/pySim/utils.py
+++ b/pySim/utils.py
@@ -1225,6 +1225,60 @@
return int(x, 0)
+def expand_hex(hexstring, length):
+ """Expand a given hexstring to a specified length by replacing "." or ".."
+ with a filler that is derived from the neighboring nibbles respective
+ bytes. Usually this will be the nibble respective byte before "." or
+ "..", execpt when the string begins with "." or "..", then the nibble
+ respective byte after "." or ".." is used.". In case the string cannot
+ be expanded for some reason, the input string is returned unmodified.
+
+ Args:
+ hexstring : hexstring to expand
+ length : desired length of the resulting hexstring.
+ Returns:
+ expanded hexstring
+ """
+
+ # expand digit aligned
+ if hexstring.count(".") == 1:
+ pos = hexstring.index(".")
+ if pos > 0:
+ filler = hexstring[pos - 1]
+ else:
+ filler = hexstring[pos + 1]
+
+ missing = length * 2 - (len(hexstring) - 1)
+ if missing <= 0:
+ return hexstring
+
+ return hexstring.replace(".", filler * missing)
+
+ # expand byte aligned
+ elif hexstring.count("..") == 1:
+ if len(hexstring) % 2:
+ return hexstring
+
+ pos = hexstring.index("..")
+
+ if pos % 2:
+ return hexstring
+
+ if pos > 1:
+ filler = hexstring[pos - 2:pos]
+ else:
+ filler = hexstring[pos + 2:pos+4]
+
+ missing = length * 2 - (len(hexstring) - 2)
+ if missing <= 0:
+ return hexstring
+
+ return hexstring.replace("..", filler * (missing // 2))
+
+ # no change
+ return hexstring
+
+
class JsonEncoder(json.JSONEncoder):
"""Extend the standard library JSONEncoder with support for more types."""
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/28218
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Iedd7887bf7d706878f4a3beca8dbea456404610b
Gerrit-Change-Number: 28218
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
Gerrit-MessageType: newchange
Attention is currently required from: neels, fixeria.
pespin has posted comments on this change. ( https://gerrit.osmocom.org/c/osmo-bsc/+/28205 )
Change subject: fix performance for chan_counts and all_allocated stats
......................................................................
Patch Set 4:
(1 comment)
File src/osmo-bsc/chan_counts.c:
https://gerrit.osmocom.org/c/osmo-bsc/+/28205/comment/56602ed2_449c9898
PS4, Line 242: chan_counts_trx_update(trx);
You could probably optimize it and simply do memset(0) in nsd->running == false, but fine anyway.
--
To view, visit https://gerrit.osmocom.org/c/osmo-bsc/+/28205
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-bsc
Gerrit-Branch: master
Gerrit-Change-Id: I580bfae329aac8d4552723164741536af6512011
Gerrit-Change-Number: 28205
Gerrit-PatchSet: 4
Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-Attention: neels <nhofmeyr(a)sysmocom.de>
Gerrit-Attention: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Comment-Date: Thu, 02 Jun 2022 12:40:54 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
Attention is currently required from: fixeria.
neels has posted comments on this change. ( https://gerrit.osmocom.org/c/osmo-bsc/+/28205 )
Change subject: fix performance for chan_counts and all_allocated stats
......................................................................
Patch Set 4:
(1 comment)
Patchset:
PS4:
It now works as expected with S_NM_RUNNING_CHG. Thanks!
--
To view, visit https://gerrit.osmocom.org/c/osmo-bsc/+/28205
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-bsc
Gerrit-Branch: master
Gerrit-Change-Id: I580bfae329aac8d4552723164741536af6512011
Gerrit-Change-Number: 28205
Gerrit-PatchSet: 4
Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-Attention: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Comment-Date: Thu, 02 Jun 2022 12:26:21 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
Attention is currently required from: neels, fixeria.
Hello Jenkins Builder, laforge, fixeria, pespin,
I'd like you to reexamine a change. Please visit
https://gerrit.osmocom.org/c/osmo-bsc/+/28205
to look at the new patch set (#4).
Change subject: fix performance for chan_counts and all_allocated stats
......................................................................
fix performance for chan_counts and all_allocated stats
The all_allocated_update_bsc() does inefficient iterating to count
active/inactive lchans, which scales badly for high numbers of TRX
managed by osmo-bsc.
We need to update the all_allocated flags immediately (periodic counting
alone would suffer from undersampling), so, until now, we are calling
this inefficient function every time a channel state changes.
Instead of iterating all channels for any chan state changes anywhere,
keep global state of the current channel counts, and on channel state
change only update those ts, trx, bts counts that actually change.
A desirable side effect: for connection stats and handover decision 2,
we can now also use the globally updated channel counts and save a bunch
of inefficient iterations.
To get accurate channel counts at all times, spread around some
chan_counts_ts_update() calls in pivotal places. It re-counts the given
timeslot and cascades counter changes, iff required.
Just in case I missed some channel accounting, still run an inefficient
iterating count regularly that detects errors, logs them and fixes them.
No real harm done if such error appears. None show in ttcn3 BSC_Tests.
It is fine to do the inefficient iteration once per second; channel
state changes can realistically happen hundreds of times per second.
Related: SYS#5976
Change-Id: I580bfae329aac8d4552723164741536af6512011
---
M include/osmocom/bsc/bsc_stats.h
M include/osmocom/bsc/bts.h
M include/osmocom/bsc/bts_trx.h
M include/osmocom/bsc/chan_counts.h
M include/osmocom/bsc/gsm_data.h
M src/osmo-bsc/abis_rsl.c
M src/osmo-bsc/bsc_stats.c
M src/osmo-bsc/chan_counts.c
M src/osmo-bsc/handover_decision_2.c
M src/osmo-bsc/lchan_fsm.c
M src/osmo-bsc/osmo_bsc_main.c
M src/osmo-bsc/timeslot_fsm.c
M tests/handover/handover_test.c
13 files changed, 323 insertions(+), 94 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-bsc refs/changes/05/28205/4
--
To view, visit https://gerrit.osmocom.org/c/osmo-bsc/+/28205
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-bsc
Gerrit-Branch: master
Gerrit-Change-Id: I580bfae329aac8d4552723164741536af6512011
Gerrit-Change-Number: 28205
Gerrit-PatchSet: 4
Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-Attention: neels <nhofmeyr(a)sysmocom.de>
Gerrit-Attention: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-MessageType: newpatchset
neels has posted comments on this change. ( https://gerrit.osmocom.org/c/osmo-bsc/+/28217 )
Change subject: nm_rcarrier_fsm: Trigger S_NM_RUNNING_CHG when Admin st changes in op=Enabled
......................................................................
Patch Set 3:
(1 comment)
Patchset:
PS3:
> I did run BSC_Tests. […]
I can confirm that S_NM_RUNNING_CHG now works as expected in my perf patch.
Thanks!
--
To view, visit https://gerrit.osmocom.org/c/osmo-bsc/+/28217
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-bsc
Gerrit-Branch: master
Gerrit-Change-Id: Ifbdc066fd88bdbf826800d14524e74416815b625
Gerrit-Change-Number: 28217
Gerrit-PatchSet: 3
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: neels <nhofmeyr(a)sysmocom.de>
Gerrit-Reviewer: osmith <osmith(a)sysmocom.de>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-Comment-Date: Thu, 02 Jun 2022 12:24:13 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: pespin <pespin(a)sysmocom.de>
Gerrit-MessageType: comment
pespin has submitted this change. ( https://gerrit.osmocom.org/c/osmo-bsc/+/28217 )
Change subject: nm_rcarrier_fsm: Trigger S_NM_RUNNING_CHG when Admin st changes in op=Enabled
......................................................................
nm_rcarrier_fsm: Trigger S_NM_RUNNING_CHG when Admin st changes in op=Enabled
It was described in [1] that the NM FSM failed to trigger the
S_NM_RUNNNG_CHG signal when locking/unlocking the TRX.
That's because current osmo-bts doesn't fully conform to TS 52.021 and
it doesn't go back to Op=Disabled Avail=Dependency when becoming
Admin=Locked. It's true though that TS 52.021 sec 5.3.1 is not really
helpful since it doesn't explicitly state that specific object should go
into Disabled Dependency, despite saying it for most of the other ones.
Hence, let's account for both possibilities at the BSC side.
[1] https://gerrit.osmocom.org/c/osmo-bsc/+/28205
Related: OS#5576
Change-Id: Ifbdc066fd88bdbf826800d14524e74416815b625
---
M src/osmo-bsc/nm_rcarrier_fsm.c
1 file changed, 20 insertions(+), 1 deletion(-)
Approvals:
fixeria: Looks good to me, but someone else must approve
osmith: Looks good to me, but someone else must approve
pespin: Looks good to me, approved
Jenkins Builder: Verified
diff --git a/src/osmo-bsc/nm_rcarrier_fsm.c b/src/osmo-bsc/nm_rcarrier_fsm.c
index fbd3179..c8b95ad 100644
--- a/src/osmo-bsc/nm_rcarrier_fsm.c
+++ b/src/osmo-bsc/nm_rcarrier_fsm.c
@@ -250,8 +250,27 @@
case NM_EV_STATE_CHG_REP:
nsd = (struct nm_statechg_signal_data *)data;
new_state = &nsd->new_state;
- if (new_state->operational == NM_OPSTATE_ENABLED)
+ /* Op state stays in Enabled, hence either Avail or Admin changed: */
+ if (new_state->operational == NM_OPSTATE_ENABLED) {
+ /* Some sort of availability change we don't care about: */
+ if (nsd->old_state.administrative == new_state->administrative)
+ return;
+ /* HACK: Admin state change without Op state change:
+ * According to TS 52.021 sec 5.3.1, Locking the NM obj should make
+ * it go into Disabled Dependency state, but current and older
+ * versions of osmo-bts (and potentially nanobts?) don't move from
+ * Operative=Enabled state and only change the Adminsitrative one.
+ * Let's account for this behavior here: */
+ switch (new_state->administrative) {
+ case NM_STATE_LOCKED:
+ nm_rcarrier_fsm_becomes_disabled(trx);
+ break;
+ case NM_STATE_UNLOCKED:
+ nm_rcarrier_fsm_becomes_enabled(trx);
+ break;
+ }
return;
+ }
switch (new_state->availability) { /* operational = DISABLED */
case NM_AVSTATE_NOT_INSTALLED:
case NM_AVSTATE_POWER_OFF:
--
To view, visit https://gerrit.osmocom.org/c/osmo-bsc/+/28217
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-bsc
Gerrit-Branch: master
Gerrit-Change-Id: Ifbdc066fd88bdbf826800d14524e74416815b625
Gerrit-Change-Number: 28217
Gerrit-PatchSet: 3
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: neels <nhofmeyr(a)sysmocom.de>
Gerrit-Reviewer: osmith <osmith(a)sysmocom.de>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-MessageType: merged