ggsn: Move random number helpers to Osmocom_Types.ttcn
Change-Id: I141289cbf1807e81d72f07ac1183fa48b2dc54af
diff --git a/ggsn_tests/GGSN_Tests.ttcn b/ggsn_tests/GGSN_Tests.ttcn
index 22cdc21..23e7054 100644
--- a/ggsn_tests/GGSN_Tests.ttcn
+++ b/ggsn_tests/GGSN_Tests.ttcn
@@ -615,11 +615,6 @@
const octetstring c_ApnInet6 := '05696E657436'O;
const octetstring c_ApnInet46 := '06696E65743436'O;
- /* return random integer between 0 and max */
- function f_rnd_int(integer max) return integer {
- return float2int(rnd()*int2float(max));
- }
-
/* return random NSAPI */
function f_rnd_nsapi() return BIT4 {
return int2bit(f_rnd_int(16), 4);
@@ -630,35 +625,6 @@
return int2oct(f_rnd_int(4294967296), 4);
}
- /* return hexstring composed of random digits */
- function f_rnd_hexstring(in integer len, in integer max := 15) return hexstring {
- var integer i;
- var hexstring ret := ''H;
- for (i := 0; i < len; i := i + 1) {
- ret := ret & int2hex(f_rnd_int(max), 1);
- }
- return ret;
- }
-
- /* return octetstring composed of random bytes */
- function f_rnd_octstring(in integer len) return octetstring {
- var integer i;
- var octetstring ret := ''O;
- for (i := 0; i < len; i := i + 1) {
- ret := ret & int2oct(f_rnd_int(255), 1);
- }
- return ret;
- }
-
- function f_rnd_imsi(in hexstring prefix) return hexstring {
- return prefix & f_rnd_hexstring(15 - lengthof(prefix), 9);
- }
-
- function f_rnd_msisdn(in octetstring prefix, integer len := 6) return octetstring {
- return prefix & f_rnd_octstring(len - lengthof(prefix));
- }
-
-
/* define an (internal) representation of a PDP context */
template PdpContext t_DefinePDP(hexstring imsi, octetstring msisdn, octetstring apn,
EndUserAddress eua) := {
diff --git a/library/Osmocom_Types.ttcn b/library/Osmocom_Types.ttcn
index 484f6d1..495b684 100644
--- a/library/Osmocom_Types.ttcn
+++ b/library/Osmocom_Types.ttcn
@@ -27,4 +27,37 @@
uint15_t arfcn
} with { variant "" };
+ /* return random integer between 0 and max */
+ function f_rnd_int(integer max) return integer {
+ return float2int(rnd()*int2float(max));
+ }
+
+ /* return hexstring composed of random digits */
+ function f_rnd_hexstring(in integer len, in integer max := 15) return hexstring {
+ var integer i;
+ var hexstring ret := ''H;
+ for (i := 0; i < len; i := i + 1) {
+ ret := ret & int2hex(f_rnd_int(max), 1);
+ }
+ return ret;
+ }
+
+ /* return octetstring composed of random bytes */
+ function f_rnd_octstring(in integer len) return octetstring {
+ var integer i;
+ var octetstring ret := ''O;
+ for (i := 0; i < len; i := i + 1) {
+ ret := ret & int2oct(f_rnd_int(255), 1);
+ }
+ return ret;
+ }
+
+ function f_rnd_imsi(in hexstring prefix) return hexstring {
+ return prefix & f_rnd_hexstring(15 - lengthof(prefix), 9);
+ }
+
+ function f_rnd_msisdn(in octetstring prefix, integer len := 6) return octetstring {
+ return prefix & f_rnd_octstring(len - lengthof(prefix));
+ }
+
} with { encode "RAW"; variant "FIELDORDER(msb)" }