NS_Emulation: Avoid g_unblocked_nsvcs_* overflowing
Sometimes we run into situations where the g_unblocked_nsvcs_* is
exceeding the number of NSVCs we have in g_nsvcs. This can only happen
as we blindly append integers to the ro_integer fields, rather than
checking if they are already contained.
Let's factor out the add_unique and del functions (in Osmocom_Types)
and use them from NS_Emulation.
Change-Id: Ib3273d6ce9b80f700c964d578fdb0f268eac6a14
diff --git a/library/NS_Emulation.ttcnpp b/library/NS_Emulation.ttcnpp
index ca44a02..6d8113c 100644
--- a/library/NS_Emulation.ttcnpp
+++ b/library/NS_Emulation.ttcnpp
@@ -310,30 +310,16 @@
/* add index to list of unblocked NSVCs */
if (not ischosen(g_nsvcs[i].cfg.provider.ip) or
g_nsvcs[i].cfg.provider.ip.signalling_weight > 0) {
- g_unblocked_nsvcs_sig := g_unblocked_nsvcs_sig & {i};
+ ro_integer_add_unique(g_unblocked_nsvcs_sig, i);
}
if (not ischosen(g_nsvcs[i].cfg.provider.ip) or
g_nsvcs[i].cfg.provider.ip.data_weight > 0) {
- g_unblocked_nsvcs_data := g_unblocked_nsvcs_data & {i};
+ ro_integer_add_unique(g_unblocked_nsvcs_data, i);
}
} else if (g_nsvcs[i].state == NSVC_S_ALIVE_UNBLOCKED and state != NSVC_S_ALIVE_UNBLOCKED) {
/* remove index to list of unblocked NSVCs */
- var Osmocom_Types.ro_integer new_unblocked_nsvcs_sig := {};
- for (var integer j := 0; j < lengthof(g_unblocked_nsvcs_sig); j := j+1) {
- if (g_unblocked_nsvcs_sig[j] != i) {
- new_unblocked_nsvcs_sig := new_unblocked_nsvcs_sig & {j};
- }
- }
- g_unblocked_nsvcs_sig := new_unblocked_nsvcs_sig;
-
- var Osmocom_Types.ro_integer new_unblocked_nsvcs_data := {};
- for (var integer j := 0; j < lengthof(g_unblocked_nsvcs_data); j := j+1) {
- if (g_unblocked_nsvcs_data[j] != i) {
- new_unblocked_nsvcs_data := new_unblocked_nsvcs_data & {j};
- }
- }
- g_unblocked_nsvcs_data := new_unblocked_nsvcs_data;
-
+ ro_integer_del(g_unblocked_nsvcs_sig, i);
+ ro_integer_del(g_unblocked_nsvcs_data, i);
}
g_nsvcs[i].state := state;
}
diff --git a/library/Osmocom_Types.ttcn b/library/Osmocom_Types.ttcn
index 06920bf..23f8fd9 100644
--- a/library/Osmocom_Types.ttcn
+++ b/library/Osmocom_Types.ttcn
@@ -294,6 +294,25 @@
return false;
}
+function ro_integer_add_unique(inout ro_integer roi, integer new_entry)
+{
+ if (ro_integer_contains(roi, new_entry)) {
+ return;
+ }
+ roi := roi & {new_entry};
+}
+
+function ro_integer_del(inout ro_integer roi, integer del_entry)
+{
+ var ro_integer tmp := {};
+ for (var integer j := 0; j < lengthof(roi); j := j+1) {
+ if (roi[j] != del_entry) {
+ tmp := tmp & { roi[j] };
+ }
+ }
+ roi := tmp;
+}
+
type record of ro_integer roro_integer;