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
This commit is contained in:
parent
aaa0dfdd3f
commit
daf89681c4
|
@ -310,30 +310,16 @@ module NS_Emulation {
|
||||||
/* add index to list of unblocked NSVCs */
|
/* add index to list of unblocked NSVCs */
|
||||||
if (not ischosen(g_nsvcs[i].cfg.provider.ip) or
|
if (not ischosen(g_nsvcs[i].cfg.provider.ip) or
|
||||||
g_nsvcs[i].cfg.provider.ip.signalling_weight > 0) {
|
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
|
if (not ischosen(g_nsvcs[i].cfg.provider.ip) or
|
||||||
g_nsvcs[i].cfg.provider.ip.data_weight > 0) {
|
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) {
|
} else if (g_nsvcs[i].state == NSVC_S_ALIVE_UNBLOCKED and state != NSVC_S_ALIVE_UNBLOCKED) {
|
||||||
/* remove index to list of unblocked NSVCs */
|
/* remove index to list of unblocked NSVCs */
|
||||||
var Osmocom_Types.ro_integer new_unblocked_nsvcs_sig := {};
|
ro_integer_del(g_unblocked_nsvcs_sig, i);
|
||||||
for (var integer j := 0; j < lengthof(g_unblocked_nsvcs_sig); j := j+1) {
|
ro_integer_del(g_unblocked_nsvcs_data, i);
|
||||||
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;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
g_nsvcs[i].state := state;
|
g_nsvcs[i].state := state;
|
||||||
}
|
}
|
||||||
|
|
|
@ -294,6 +294,25 @@ function ro_integer_contains(ro_integer r, integer x) return boolean {
|
||||||
return false;
|
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;
|
type record of ro_integer roro_integer;
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue