summaryrefslogtreecommitdiffstats
path: root/pcu
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2018-03-08 11:51:23 +0100
committerHarald Welte <laforge@gnumonks.org>2018-03-12 14:23:57 +0000
commita0895f96a940c0a25379bf18a641943486744379 (patch)
treec5c3c58fc9f470a5b2309d8823f5f1227bf6879a /pcu
parent54242db850f623eb7f20160c39b4e026e65ed7f9 (diff)
pcu: Rename 'gprs_gb/Test' tp 'pcu/PCU_Tests' to align with other suites
Diffstat (limited to 'pcu')
-rw-r--r--pcu/GPRS_Context.ttcn12
-rw-r--r--pcu/GPRS_TBF.ttcn365
-rw-r--r--pcu/PCU_Tests.cfg58
-rw-r--r--pcu/PCU_Tests.ttcn539
-rwxr-xr-xpcu/gen_links.sh60
-rwxr-xr-xpcu/regen_makefile.sh5
6 files changed, 1039 insertions, 0 deletions
diff --git a/pcu/GPRS_Context.ttcn b/pcu/GPRS_Context.ttcn
new file mode 100644
index 0000000..af2b2e9
--- /dev/null
+++ b/pcu/GPRS_Context.ttcn
@@ -0,0 +1,12 @@
+module GPRS_Context {
+
+import from Osmocom_Types all;
+import from GSM_Types all;
+
+ type record MmContext {
+ hexstring imsi optional,
+ GprsTlli tlli,
+ uint9_t n_u
+ };
+
+}
diff --git a/pcu/GPRS_TBF.ttcn b/pcu/GPRS_TBF.ttcn
new file mode 100644
index 0000000..a35c780
--- /dev/null
+++ b/pcu/GPRS_TBF.ttcn
@@ -0,0 +1,365 @@
+module GPRS_TBF {
+
+/* GPRS TBF Routines, intended as minimal MS-Side GPRS implementation
+ *
+ * (C) 2018 by Harald Welte <laforge@gnumonks.org>
+ * All rights reserved.
+ *
+ * Released under the terms of GNU General Public License, Version 2 or
+ * (at your option) any later version.
+ */
+
+
+import from GSM_Types all;
+import from Osmocom_Types all;
+import from General_Types all;
+import from RLCMAC_Types all;
+import from RLCMAC_CSN1_Types all;
+import from LLC_Types all;
+import from GPRS_Context all;
+
+/* input parameters into TBF (mostly mode/cs + LLC PDUs */
+
+type record UlTbfPars {
+ /* Acknowledged mode (true) or unacknowledged (false) */
+ boolean ack_mode,
+ /* Coding Scheme for transmission, determines block size */
+ GprsCodingScheme initial_cs,
+ /* list of abstract/decoded LLC PDUs */
+ record of PDU_LLC llc_pdus optional,
+ /* possibly computed: list of encoded LLC PDUs */
+ record of octetstring llc_pdus_enc
+}
+
+type record RlcEndpointTx {
+ /* send state variable V(S) (9.1.1): 0 .. SNS-1 */
+ integer v_s,
+ /* acknowledge state variable V(A) (9.1.2): BSN value of oldest RLC data block that has not
+ * been positively acknowledged by peer. */
+ integer v_a,
+ /* acknowledge state array V(B) (9.1.3) */
+ bitstring v_b
+}
+private function f_RlcEndpointTx_init(inout RlcEndpointTx ep) {
+ ep.v_s := 0;
+ ep.v_a := 0;
+ ep.v_b := int2bit(0, 128); /* FIXME: EGPRS 2048 bits length */
+}
+
+type record RlcEndpointRx {
+ /* receive state variable V(R) (9.1.5): BSN one higher than highest BSN yet received (mod SNS) */
+ integer v_r,
+ /* receive window state variable V(Q) (9.1.6): Lowest BSN not yet received (mod SNS) */
+ integer v_q,
+ /* receive state array V(N) (9.1.7) */
+ bitstring v_n
+}
+
+private function f_RlcEndpointRx_init(inout RlcEndpointRx ep) {
+ ep.v_r := 0;
+ ep.v_q := 0;
+ ep.v_n := int2bit(0, 128); /* FIXME: EGPRS 2048 bits length */
+}
+
+
+type record UlTbfState {
+ /* "const" input state with TBF Data */
+ UlTbfPars tbf,
+ uint8_t num_ts,
+
+ RlcEndpointTx et,
+
+ integer tfi,
+ /* total length of all encoded LLC PDUs */
+ integer llc_pdu_totlen,
+ /* index of current/next PDU in llc_pdus_enc */
+ integer cur_pdu,
+ /* byte offset into current/next PDU; next byte to transmit */
+ integer cur_index,
+ /* block sequence number of next block within TBF */
+ integer bsn_p,
+ /* total number of bytes remaining in TBF */
+ integer total_bytes_remain,
+
+ /* list of already-sent RLC/MAC Blocks */
+ record of RlcmacUlBlock rlc_sent
+}
+
+function f_UlTbfState_init(inout UlTbfState us, in UlTbfPars utpars) {
+ var RlcmacUlBlock blk;
+
+ us.tbf := utpars;
+ us.num_ts := 1;
+
+ f_RlcEndpointTx_init(us.et);
+
+ us.tfi := 0; /* FIXME */
+ us.cur_pdu := 0;
+ us.cur_index := 0;
+ us.bsn_p := 0;
+ us.total_bytes_remain := 0;
+ us.rlc_sent := {};
+
+ /* encode all LLC PDUs from their abstract type to octetstring */
+ us.cur_pdu := 0; /* currently processed PDU */
+ us.cur_index := 0; /* next to-be transmitted index */
+ if (ispresent(us.tbf.llc_pdus)) {
+ us.tbf.llc_pdus_enc := {};
+ us.llc_pdu_totlen := 0;
+ for (var integer i := 0; i < sizeof(us.tbf.llc_pdus); i := i+1) {
+ var octetstring cur_enc := enc_PDU_LLC(us.tbf.llc_pdus[i]);
+ us.tbf.llc_pdus_enc := us.tbf.llc_pdus_enc & { cur_enc };
+ us.llc_pdu_totlen := us.llc_pdu_totlen + lengthof(cur_enc);
+ }
+ us.total_bytes_remain := us.llc_pdu_totlen;
+ }
+}
+
+private function f_UlTbf_ack_one_block(inout UlTbfState us, integer n) {
+ /* compute index into v_b */
+ var integer idx := n - us.et.v_a;
+ if (idx < 0 or idx > lengthof(us.et.v_b)) {
+ setverdict(fail, "UlTbf: Cannot ACK ", n, " while V(A) is ", us.et.v_a);
+ self.stop;
+ }
+ /* set the bit in the acknowledge state array */
+ us.et.v_b[idx] := '1'B;
+}
+
+/* check if V(B) contains '1' at lower end: if yes, advance V(A) and shift V(B) */
+private function f_UlTbf_check_advance_v_a(inout UlTbfState us) {
+ log("FIXME: Implement this");
+}
+
+/* copy 'len' number of bytes from current pending LLC PDU */
+private function f_copy_from_llc(inout UlTbfState us, integer len) return octetstring
+{
+ var integer pdu_len := lengthof(us.tbf.llc_pdus_enc[us.cur_pdu])
+ var octetstring ret;
+
+ ret := substr(us.tbf.llc_pdus_enc[us.cur_pdu], us.cur_index, len);
+
+ us.cur_index := us.cur_index + len;
+ us.total_bytes_remain := us.total_bytes_remain - len;
+
+ log("copy_from_llc: ", ret, " us: ", us);
+
+ /* if we completed this PDU, move on to the next, resetting the index */
+ if (us.cur_index >= pdu_len) {
+ us.cur_pdu := us.cur_pdu +1;
+ us.cur_index := 0;
+ log("copy_from_llc (incrementing pdu)");
+ }
+
+ return ret;
+}
+
+/* generate one LlcBlock (maximum size 'max_len') */
+private function f_ul_tbf_pull_one(out LlcBlock ret, inout LlcBlockHdr prev_hdr,
+ inout UlTbfState us, integer max_len,
+ boolean is_final) return boolean
+{
+ /* if we've already pulled all data from all LLC PDUs: nothing to do */
+ if (us.cur_pdu >= sizeof(us.tbf.llc_pdus_enc)) {
+ log("pull_one: No more data", us);
+ return false;
+ }
+
+ var integer pdu_len := lengthof(us.tbf.llc_pdus_enc[us.cur_pdu])
+ var integer cur_llc_remain_len := pdu_len - us.cur_index;
+ var integer len;
+ var LlcBlock lb;
+
+ if (us.cur_index == 0) {
+ /* start of a new LLC PDU */
+ prev_hdr.more := true;
+ }
+
+ if (cur_llc_remain_len > max_len) {
+ log("Chunk with length ", cur_llc_remain_len, " larger than space (",
+ max_len, ") left in block");
+ len := max_len;
+ lb := {
+ hdr := omit,
+ payload := f_copy_from_llc(us, len)
+ }
+ } else if (cur_llc_remain_len == max_len and is_final) {
+ /* final RLC block of TBF and LLC remainder fits exactly */
+ len := max_len;
+ lb := {
+ hdr := omit,
+ payload := f_copy_from_llc(us, len)
+ }
+ prev_hdr.e := true;
+ } else if (cur_llc_remain_len == max_len) {
+ /* LLC remaineder would fit exactly -> "singular case" with L=0 */
+ len := max_len - 1;
+ lb := {
+ hdr := {
+ length_ind := 0,
+ more := false,
+ e := true
+ },
+ payload := f_copy_from_llc(us, len)
+ }
+ prev_hdr.e := false;
+ } else {
+ /* normal case: cur_llc_remain_len < max_len */
+ len := cur_llc_remain_len;
+ lb := {
+ hdr := {
+ length_ind := len,
+ more := false,
+ e := true
+ },
+ payload := f_copy_from_llc(us, len)
+ }
+ prev_hdr.e := false;
+ }
+ ret := lb;
+ return true;
+}
+
+/* return encoded size of one given LlcBlock */
+private function f_LlcBlock_enc_len(LlcBlock blk) return integer {
+ if (isvalue(blk.hdr)) {
+ return 1 + lengthof(blk.payload);
+ } else {
+ return lengthof(blk.payload);
+ }
+}
+
+/* return encoded size of given record of LlcBlock */
+private function f_LlcBlocks_enc_len(LlcBlocks blks) return integer {
+ var integer sum := 0;
+ for (var integer i := 0; i < sizeof(blks); i := i+1) {
+ sum := sum + f_LlcBlock_enc_len(blks[i]);
+ }
+ return sum;
+}
+
+private function f_ul_tbf_pull_multi(out LlcBlocks ret, inout UlTbfState us, integer max_len,
+ boolean is_final) return boolean
+{
+ var integer space_left;
+ var boolean rc;
+ ret := {};
+
+ /* loop as long as we have pending LLC data and space left in the current block... */
+ for (space_left := max_len; space_left > 0; space_left := max_len - f_LlcBlocks_enc_len(ret)) {
+ var LlcBlock lb;
+ var integer ret_size := sizeof(ret);
+ if (ret_size > 0) {
+ rc := f_ul_tbf_pull_one(lb, ret[ret_size-1].hdr, us, space_left, is_final);
+ } else {
+ var LlcBlockHdr dummy_hdr;
+ rc := f_ul_tbf_pull_one(lb, dummy_hdr, us, space_left, is_final);
+ }
+ if (rc == false) {
+ /* we couldn't fill the full RLC block, insufficient LLC Data */
+ if (sizeof(ret) == 0) {
+ /* we couldn't obtain any LlcBlocks at all */
+ return false;
+ } else {
+ /* we have some LlcBlocks from earlier iterations */
+ return true;
+ }
+ }
+ ret := ret & {lb};
+ }
+ return true;
+}
+
+/* Determine 'K' value for given CS (TS 44.060 9.3.1.1) */
+private function f_k_for_cs(GprsCodingScheme cs) return integer {
+ /* FIXME: EGPRS */
+ return 1;
+}
+
+/* TS 44.060 9.3.1.1 */
+private function f_calc_cv(integer nbc, integer bsn_p, integer nts, GprsCodingScheme cs,
+ integer bs_cv_max) return integer {
+ var integer dividend := nbc - bsn_p - 1;
+ var integer k := f_k_for_cs(cs);
+ var integer divisor := nts * k;
+ var integer x := f_div_round_up(dividend, divisor);
+ if (x <= bs_cv_max) {
+ return x;
+ } else {
+ return 15;
+ }
+}
+
+private function f_rlcmac_hdr_size(boolean tlli_needed) return integer {
+ var integer ret := 2;
+ if (tlli_needed) {
+ ret := ret + 4;
+ }
+ return ret;
+}
+
+/* determine countdown value based on remaining length pending */
+private function f_ul_tbf_get_cv(inout UlTbfState us, GprsCodingScheme cs, boolean tlli_needed)
+return integer {
+ var integer hdr_size := f_rlcmac_hdr_size(tlli_needed); /* FIXME: PFI, ... */
+ var integer blk_len_net := f_gprs_blocksize(cs) - hdr_size;
+ var integer num_remain := f_div_round_up(us.total_bytes_remain, blk_len_net);
+ var integer cv := f_calc_cv(num_remain + sizeof(us.rlc_sent), us.bsn_p, us.num_ts, us.tbf.initial_cs, 14 /* FIXME */);
+ log("CV=", cv, ", num_rmain=", num_remain, " from ", us);
+ return cv;
+}
+
+
+function f_ul_tbf_get_next_block(out RlcmacUlBlock blk, inout UlTbfState us, inout MmContext mmctx,
+ boolean tlli_needed := false) return boolean {
+ var integer hdr_size := f_rlcmac_hdr_size(tlli_needed); /* FIXME: TLLI, PFI, ... */
+ var integer len_remain := f_gprs_blocksize(us.tbf.initial_cs) - hdr_size;
+ var octetstring payload;
+ var integer cv;
+ var LlcBlocks llc_blocks;
+
+ cv := f_ul_tbf_get_cv(us, us.tbf.initial_cs, tlli_needed);
+ /* potentially get multiple payload chunks of multiple LLC PDUs */
+ if (f_ul_tbf_pull_multi(llc_blocks, us, len_remain, false) == false) {
+ return false;
+ }
+
+ /* include TLLI when needed */
+ if (tlli_needed) {
+ blk := valueof(t_RLCMAC_UL_DATA_TLLI(us.tfi, cv, us.et.v_s,
+ llc_blocks, false, mmctx.tlli));
+ } else {
+ blk := valueof(t_RLCMAC_UL_DATA(us.tfi, cv, us.et.v_s, llc_blocks, false));
+ }
+
+ /* Increment Block Sequence Number */
+ us.bsn_p := us.bsn_p + 1;
+ us.et.v_s := us.bsn_p mod 128; /* FIXME: EGPRS SNS: 2048 */
+
+ /* append to list of sent blocks */
+ us.rlc_sent := us.rlc_sent & { blk };
+
+ return true;
+}
+
+function f_ul_tbf_process_acknack(inout UlTbfState us, RlcmacDlCtrlBlock db) {
+ if (ispresent(db.payload.u.ul_ack_nack.gprs)) {
+ var UlAckNackGprs uan_gprs := db.payload.u.ul_ack_nack.gprs;
+ if (ispresent(uan_gprs.cont_res_tlli)) {
+ /* FIXME: check for contention resolution */
+ }
+ var integer i;
+ /* iterate over received bitmap, ACK each block in our TBF state */
+ for (i := lengthof(uan_gprs.ack_nack_desc.receive_block_bitmap)-1; i >= 0; i := i-1) {
+ if (uan_gprs.ack_nack_desc.receive_block_bitmap[i] == '1'B) {
+ var integer seq := uan_gprs.ack_nack_desc.starting_seq_nr + i;
+ f_UlTbf_ack_one_block(us, seq);
+ }
+ }
+ f_UlTbf_check_advance_v_a(us);
+ }
+}
+
+
+
+}
diff --git a/pcu/PCU_Tests.cfg b/pcu/PCU_Tests.cfg
new file mode 100644
index 0000000..20de54c
--- /dev/null
+++ b/pcu/PCU_Tests.cfg
@@ -0,0 +1,58 @@
+[ORDERED_INCLUDE]
+# Common configuration, shared between test suites
+"../Common.cfg"
+
+[LOGGING]
+#*.FileMask := LOG_ALL
+ConsoleMask := ERROR | WARNING | TESTCASE | TIMEROP_START | DEBUG_ENCDEC
+
+[MODULE_PARAMETERS]
+#mp_local_ip := "192.168.100.239"
+#mp_local_udp_port := 23000
+#mp_remote_ip := "192.168.100.196"
+#mp_remote_udp_port := 21000
+NS_Emulation.mp_local_ip := "127.0.0.1"
+NS_Emulation.mp_local_udp_port := 23000
+NS_Emulation.mp_remote_ip := "127.0.0.1"
+NS_Emulation.mp_remote_udp_port := 23001
+NS_Emulation.mp_nsei := 1234
+NS_Emulation.mp_nsvci := 1234
+PCU_Tests.mp_gb_cfg := {
+ nsei := 1234,
+ bvci := 1234,
+ cell_id := {
+ ra_id := {
+ lai := {
+ mcc_mnc := '00101F'H, lac := 1
+ },
+ rac := 0
+ },
+ cell_id := 0
+ },
+ sgsn_role := true
+}
+
+[TESTPORT_PARAMETERS]
+#*.BSCVTY.CTRL_MODE := "client"
+#*.BSCVTY.CTRL_HOSTNAME := "127.0.0.1"
+#*.BSCVTY.CTRL_PORTNUM := "4242"
+#*.BSCVTY.CTRL_LOGIN_SKIPPED := "yes"
+#*.BSCVTY.CTRL_DETECT_SERVER_DISCONNECTED := "yes"
+#*.BSCVTY.CTRL_READMODE := "buffered"
+#*.BSCVTY.CTRL_CLIENT_CLEANUP_LINEFEED := "yes"
+#*.BSCVTY.PROMPT1 := "OpenBSC> "
+#*.BSCVTY.PROMPT2 := "OpenBSC# "
+#*.BSCVTY.REGEX_PROMPT1 := "^OpenBSC.*$"
+
+*.*.udpReuseAddress := "yes";
+
+[MAIN_CONTROLLER]
+
+[EXECUTE]
+#PCU_Tests.TC_selftest_llc
+#PCU_Tests.TC_selftest_rlcmac
+#PCU_Tests.TC_selftest_bssgp
+#PCU_Tests.TC_nsem
+#PCU_Tests.TC_paging
+PCU_Tests.TC_rach
+#PCU_Tests.TC_selftest_rr
diff --git a/pcu/PCU_Tests.ttcn b/pcu/PCU_Tests.ttcn
new file mode 100644
index 0000000..d4ce7ee
--- /dev/null
+++ b/pcu/PCU_Tests.ttcn
@@ -0,0 +1,539 @@
+module PCU_Tests {
+
+ import from General_Types all;
+ import from Osmocom_Types all;
+ import from GSM_Types all;
+ import from GSM_RR_Types all;
+ import from Osmocom_Gb_Types all;
+ import from BSSGP_Types all;
+ import from BSSGP_Emulation all;
+ import from NS_Types all;
+ import from NS_Emulation all;
+ import from LLC_Types all;
+ import from LLC_Templates all;
+ import from RLCMAC_Types all;
+ import from RLCMAC_CSN1_Types all;
+ import from LAPDm_RAW_PT all;
+ import from GPRS_Context all;
+ import from GPRS_TBF all;
+
+ modulepar {
+ BssgpConfig mp_gb_cfg := {
+ nsei := 1234,
+ bvci := 1234,
+ cell_id := {
+ ra_id := {
+ lai := {
+ mcc_mnc := '26242F'H, lac := 13135
+ },
+ rac := 0
+ },
+ cell_id := 20960
+ },
+ sgsn_role := true
+ };
+ }
+
+ type component dummy_CT extends BSSGP_Client_CT {
+ var lapdm_CT lapdm_component;
+ port LAPDm_PT L1;
+
+ var NS_CT ns_component;
+ var BSSGP_CT bssgp_component;
+
+ var MmContext g_mmctx := {
+ tlli := 'FFFFFFFF'O,
+ n_u := 0
+ };
+
+ var boolean g_initialized := false;
+ }
+
+ function f_init() runs on dummy_CT {
+ if (g_initialized == true) {
+ return;
+ }
+ g_initialized := true;
+ /* create a new NS component */
+ ns_component := NS_CT.create;
+ bssgp_component := BSSGP_CT.create;
+ /* connect our BSSGP port to the BSSGP Emulation */
+ connect(self:BSSGP, bssgp_component:BSSGP_SP);
+ connect(self:BSSGP_PROC, bssgp_component:BSSGP_PROC);
+ /* connect lower-end of BSSGP with BSSGP_CODEC_PORT (maps to NS_PT*/
+ connect(bssgp_component:BSCP, ns_component:NS_SP);
+ /* connect lower-end of NS emulation to NS_CODEC_PORT (on top of IPl4) */
+ map(ns_component:NSCP, system:NS_CODEC_PORT);
+ ns_component.start(NSStart());
+ bssgp_component.start(BssgpStart(mp_gb_cfg));
+
+ lapdm_component := lapdm_CT.create;
+ connect(self:L1, lapdm_component:LAPDM_SP);
+ map(lapdm_component:L1CTL, system:L1CTL);
+ lapdm_component.start(LAPDmStart());
+
+ f_bssgp_client_register(g_mmctx.imsi, g_mmctx.tlli, mp_gb_cfg.cell_id);
+ f_bssgp_establish();
+ }
+
+ function f_exit() runs on dummy_CT {
+ lapdm_component.stop;
+ ns_component.stop;
+ bssgp_component.stop;
+ }
+
+ function f_bssgp_dec_and_log(in octetstring inp) {
+ log("BSSGP Input: ", inp);
+ var PDU_BSSGP dec := dec_PDU_BSSGP(inp);
+ log("BSSGP Decoded: ", dec);
+ }
+
+ testcase TC_selftest_bssgp() runs on dummy_CT {
+ const octetstring c_bvc_reset_pcu := '2204820000078108088832f44000c80051e0'O;
+ const octetstring c_bvc_reset_q := '2204820000078100'O;
+ const octetstring c_status_pcu := '4107810515882204820000078103'O;
+ const octetstring c_reset_ack_q := '2304820000'O;
+ const octetstring c_reset_ack_pcu := '23048200c4'O;
+ const octetstring c_unblock_pcu := '24048200c4'O;
+ const octetstring c_unblock_ack_q := '25048200c4'O;
+ const octetstring c_fc_bvc_pcu := '261e8101058200fa038200c8018200fa1c8200c806820000'O;
+ const octetstring c_fc_bvc_ack_q := '271e8101'O;
+ const octetstring c_gmm_mo_att_req := '01bb146ddd000004088832f44000c80051e000800e003b01c001080103e5e000110a0005f4fb146ddd32f44000c8001d1b53432b37159ef9090070000dd9c6321200e00019b32c642401c0002017057bf0ec'O;
+ const octetstring c_gmm_mt_ac_req := '00bb146ddd0050001682ffff0a8204030e9c41c001081200102198c72477ea104895e8b959acc58b108182f4d045'O;
+ const octetstring c_gmm_mo_ac_resp := '01bb146ddd000004088832f44000c80051e000800e000e01c00508130122fa361f5fdd623d'O;
+ const octetstring c_gmm_mt_att_acc := '00bb146ddd0050001682ffff0a8204030e9841c005080201340432f44000c8001805f4fb146ddd0967d0'O;
+ const octetstring c_gmm_mt_det_req := '00bb146ddd0050001682ffff0a8204030e8941c00908050215f0b6'O;
+ const octetstring c_gmm_mo_att_cpl := '01fb146ddd000004088832f44000c80051e000800e000801c009080339d7bc'O;
+
+ f_bssgp_dec_and_log(c_bvc_reset_pcu);
+ f_bssgp_dec_and_log(c_bvc_reset_q);
+ f_bssgp_dec_and_log(c_status_pcu);
+ f_bssgp_dec_and_log(c_reset_ack_q);
+ f_bssgp_dec_and_log(c_reset_ack_pcu);
+ f_bssgp_dec_and_log(c_unblock_pcu);
+ f_bssgp_dec_and_log(c_unblock_ack_q);
+ f_bssgp_dec_and_log(c_fc_bvc_pcu);
+ f_bssgp_dec_and_log(c_fc_bvc_ack_q);
+ f_bssgp_dec_and_log(c_gmm_mo_att_req);
+ f_bssgp_dec_and_log(c_gmm_mt_ac_req);
+ f_bssgp_dec_and_log(c_gmm_mo_ac_resp);
+ f_bssgp_dec_and_log(c_gmm_mt_att_acc);
+ f_bssgp_dec_and_log(c_gmm_mt_det_req);
+ f_bssgp_dec_and_log(c_gmm_mo_att_cpl);
+
+ log(ts_BSSGP_PS_PAGING_IMSI(196, '262420123456789'H));
+ }
+
+ function f_ns_assert_prepr(in octetstring a, in octetstring b) {
+ log("NS Input: ", a);
+ log("NS Expected: ", b);
+
+ if (a != b) {
+ setverdict(fail);
+ } else {
+ setverdict(pass);
+ }
+ }
+
+ function f_ns_dec_and_log(in octetstring inp) {
+ log("NS Input: ", inp);
+ var PDU_NS dec := dec_PDU_NS(inp);
+ log("NS Decoded: ", dec);
+ }
+
+ testcase TC_selftest_ns() runs on dummy_CT {
+ const octetstring c_ns_reset_pcu := '000000c4271e813d'O;
+
+ /* single byte length to two byte length */
+ f_ns_assert_prepr('04058101'O, '0405000101'O);
+ f_ns_assert_prepr('040589000102030405060708'O, '04050009000102030405060708'O);
+ /* two byte length to two byte length */
+ f_ns_assert_prepr('0405000101'O, '0405000101'O);
+ /* special case: NS-UNITDATA */
+ f_ns_assert_prepr('00aabbccddeeffaa29822342'O, '00aabbccddeeffaa2900022342'O);
+ /* multiple TLVs */
+ f_ns_assert_prepr('234281aa4382bbbb'O, '23420001aa430002bbbb'O);
+ /* zero-length */
+ f_ns_assert_prepr('230080'O, '23000000'O);
+
+ f_ns_dec_and_log(c_ns_reset_pcu);
+ }
+
+ const octetstring gmm_auth_req := '081200102198c72477ea104895e8b959acc58b108182'O;
+
+ /* Wrap downlink GMM into LLC, encode + send it via BSSGP to PCU */
+ function tx_gmm(BIT1 c_r, in octetstring gmm_pdu, BIT4 sapi := c_LLC_SAPI_LLGMM) runs on dummy_CT {
+ var PDU_LLC llc;
+
+ //log("GMM Tx: ", dec_PDU_L3_SGSN_MS(gmm_pdu));
+
+ log(c_r, g_mmctx.n_u, gmm_pdu, sapi);
+ llc := valueof(ts_LLC_UI(gmm_pdu, sapi, c_r, g_mmctx.n_u));
+ log(llc);
+ g_mmctx.n_u := g_mmctx.n_u + 1;
+
+ log(ts_BSSGP_DL_UD(g_mmctx.tlli, enc_PDU_LLC(llc)));
+
+ BSSGP.send(ts_BSSGP_DL_UD(g_mmctx.tlli, enc_PDU_LLC(llc)));
+ }
+
+ /* Establish BSSGP connection to PCU */
+ function f_bssgp_establish() runs on dummy_CT {
+ timer T:= 10.0;
+
+ f_init();
+ T.start
+ alt {
+ [] BSSGP.receive(t_BssgpStsInd(?, ?, BVC_S_UNBLOCKED)) { }
+ [] BSSGP.receive { repeat; }
+ [] T.timeout { setverdict(fail); }
+ }
+ T.stop
+ log("BSSGP successfully initialized");
+ }
+
+ /* Send PS-PAGING via BSSGP to PCU, expect it to show up on L1/Um */
+ testcase TC_paging() runs on dummy_CT {
+ var hexstring imsi := '262420123456789'H;
+ var BssgpBvci bvci := 196;
+ var GsmTmsi tmsi := hex2int('01234567'H);
+
+ f_bssgp_establish();
+
+ BSSGP.send(ts_BSSGP_PS_PAGING_IMSI(bvci, imsi));
+ BSSGP.send(ts_BSSGP_PS_PAGING_PTMSI(bvci, imsi, tmsi));
+
+ while (true) {
+ var BssgpDecoded bd;
+ alt {
+ [] BSSGP.receive(tr_BD_L3_MT(?)) -> value bd {
+ log("BSSGP Rx: ", bd);
+ }
+ [] BSSGP.receive(t_BssgpStsInd(?, ?, BVC_S_UNBLOCKED)) { repeat; }
+ [] BSSGP.receive { repeat; }
+ }
+ }
+ }
+
+ /* Establish an UL TBF: Tune to ARFCN, send RACH, receive AGCH, enable TBF Rx */
+ function f_establish_ul_tbf() runs on dummy_CT {
+ timer T := 5.0;
+ var BCCH_tune_req tune_req := { { false, 871 }, true };
+ L1.send(tune_req);
+ /* FIXME: wait for confirm */
+
+ var TBF_establish_req est_req := { ra := hex2int('7B'H) };
+ L1.send(est_req);
+ T.start;
+ /* FIXME: wait for confirm */
+ alt {
+ [] L1.receive(TBF_establish_res:?) {}
+ [] L1.receive { repeat; }
+ [] T.timeout {
+ setverdict(fail, "Timeout establishing UL TBF");
+ self.stop;
+ }
+ }
+ T.stop;
+ }
+
+ /* compute a random TLLI; FIXME: what about TLLI prefix / local/foreign/...? */
+ function f_random_tlli() return GprsTlli {
+ var GprsTlli tlli := f_rnd_octstring(4);
+ return tlli;
+ }
+
+ /* Compute the frame number of the uplink block based on current fn + rrbp */
+ function f_rrbp_fn(GsmFrameNumber fn, MacRrbp rrbp) return GsmFrameNumber {
+ var integer add;
+ select (rrbp) {
+ case (RRBP_Nplus13_mod_2715648) {
+ add := 13;
+ }
+ case (RRBP_Nplus17_or_18_mod_2715648) {
+ add := 17; /* FIXME: What about 'or 18'? */
+ }
+ case (RRBP_Nplus21_or_22_mod_2715648) {
+ add := 21; /* FIXME: What about 'or 22'? */
+ }
+ case (RRBP_Nplus26_mod_2715648) {
+ add := 26;
+ }
+ }
+ return (fn + add) mod 2715648;
+ }
+
+
+function f_bssgp_wait_ul_ud(template BssgpDecoded bd_exp) runs on dummy_CT {
+ timer T := 5.0;
+ T.start;
+ alt {
+ [] BSSGP.receive(bd_exp) {
+ log("found matching BSSGP UL-UNITDATA PDU");
+ }
+ [] T.timeout {
+ setverdict(fail, "Timeout waiting for ", bd_exp);
+ }
+ }
+}
+
+
+function f_ul_tbf(inout UlTbfState us) runs on dummy_CT {
+ var RLCMAC_ph_data_ind dl;
+
+ /* Establish an UL-TBF */
+ f_establish_ul_tbf();
+
+ while (true) {
+ var RlcmacUlBlock blk;
+ if (f_ul_tbf_get_next_block(blk, us, g_mmctx, true) == false) {
+ break;
+ }
+
+ /* Send the block to L1 for transmission */
+ log("L1=", blk);
+ L1.send(RLCMAC_ph_data_req:{dyn:={tbf_id := 0, cs := us.tbf.initial_cs, block := blk}});
+ }
+
+ alt {
+ [] L1.receive(RLCMAC_ph_data_ind:{cs:=?, ts_nr:=?, fn:=?, block:=tr_RLCMAC_ACK_NACK(0, g_mmctx.tlli)}) -> value dl {
+ log("found matching ACK/NACK");
+ /* send CTRL ACK in uplink */
+ var GsmFrameNumber ul_fn := f_rrbp_fn(dl.fn, dl.block.ctrl.mac_hdr.rrbp);
+ var RlcmacUlCtrlMsg ctrl_ack := valueof(ts_RlcMacUlCtrl_PKT_CTRL_ACK(g_mmctx.tlli));
+ var RlcmacUlBlock ul_block := valueof(ts_RLC_UL_CTRL_ACK(ctrl_ack));
+ L1.send(ts_PH_DATA_ABS(0, CS1, dl.ts_nr, ul_fn, {false, 871}, ul_block));
+ /* wait for the final ACK */
+ if (dl.block.ctrl.payload.u.ul_ack_nack.gprs.ack_nack_desc.final_ack == '0'B) {
+ repeat;
+ }
+ }
+ [] L1.receive { repeat; }
+ }
+
+ for (var integer i := 0; i < sizeof(us.tbf.llc_pdus_enc); i := i+1) {
+ f_bssgp_wait_ul_ud(tr_BD_BSSGP(tr_BSSGP_UL_UD(g_mmctx.tlli, ?, us.tbf.llc_pdus_enc[i])));
+ }
+ setverdict(pass);
+
+ L1.send(DCCH_release_req:{});
+}
+
+ testcase TC_rach() runs on dummy_CT {
+ var BssgpBvci bvci := 196;
+ g_mmctx.imsi := '262420123456789'H;
+ g_mmctx.tlli := f_random_tlli();
+
+ f_init();
+
+ f_bssgp_client_register(g_mmctx.imsi, g_mmctx.tlli, mp_gb_cfg.cell_id);
+
+ f_bssgp_establish();
+ }
+
+
+ testcase TC_nsem() runs on dummy_CT {
+
+ f_bssgp_establish();
+
+ while (true) {
+ var BssgpDecoded bd;
+ alt {
+ [] BSSGP.receive(tr_BD_BSSGP(?)) -> value bd {
+ log("BSSGP Rx: ", bd);
+ //log("GMM Rx: ", dec_PDU_L3_MS_SGSN(pdu.payload));
+ g_mmctx.tlli := bd.bssgp.pDU_BSSGP_UL_UNITDATA.tLLI;
+ tx_gmm(LLC_CR_DL_CMD, gmm_auth_req);
+ }
+ [] BSSGP.receive(t_BssgpStsInd(?, ?, BVC_S_UNBLOCKED)) { repeat; }
+ [] BSSGP.receive { repeat; }
+ }
+ }
+ }
+
+
+ function f_llc_dec_and_log(in octetstring inp) {
+ log("LLC Input: ", inp);
+ var PDU_LLC dec := dec_PDU_LLC(inp);
+ log("LLC Decoded: ", dec);
+ }
+
+ function f_llc_assert(in octetstring a, in octetstring b) {
+ log("LLC Input: ", a);
+ log("LLC Expected: ", b);
+
+ if (a != b) {
+ setverdict(fail);
+ } else {
+ setverdict(pass);
+ }
+ }
+
+
+ testcase TC_selftest_llc() runs on dummy_CT {
+ const octetstring c_gmm_att_pcu := '01c001080103e5e000210a0005f4fb146ddd32f44000c8001d1b53432b37159ef9090070000dd9c6321200e00019b32c642401c00020170580460b'O;
+ const octetstring c_gmm_att_pcu_nofcs := '01c001080103e5e000210a0005f4fb146ddd32f44000c8001d1b53432b37159ef9090070000dd9c6321200e00019b32c642401c000201705'O;
+
+ f_llc_dec_and_log(c_gmm_att_pcu);
+
+ //f_llc_assert(f_LLC_append_fcs(c_gmm_att_pcu_nofcs), c_gmm_att_pcu);
+
+ log(valueof(ts_LLC_UI(gmm_auth_req, c_LLC_SAPI_LLGMM, LLC_CR_DL_CMD, g_mmctx.n_u)));
+ log(ts_LLC_UI(gmm_auth_req, c_LLC_SAPI_LLGMM, LLC_CR_DL_CMD, g_mmctx.n_u));
+ }
+
+ testcase TC_selftest_rlcmac() runs on dummy_CT {
+ var RlcmacDlCtrlBlock dcb;
+ var RlcmacUlCtrlBlock ucb;
+ const octetstring c_dl_ul_ack_nack := '40240080400000000000000077628dbba14b2b2b2b2b2b'O;
+ const octetstring c_dl_data := '0f00007341c001081200102198c72477ea104895e8b959acc58b108182f4d0454300'O;
+ const octetstring c_dl_data2 := '070002165dc0012b2b2b43c0012b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b00'O;
+ const octetstring c_ul_ctrl_ack := '4006ec51b7772b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b'O;
+ const octetstring c_ul_dl_ack_nack := '4008004000000000000000701000edc0000b2b2b2b2b2b'O;
+ const octetstring c_dl_ul_assign := '482857628dbbaf0126e68800082b2b2b2b2b2b2b2b2b2b'O;
+
+ log(c_dl_ul_ack_nack);
+ dcb := dec_RlcmacDlCtrlBlock(c_dl_ul_ack_nack);
+ log(dcb);
+ //log(dec_RlcmacDlCtrlMsg(dcb.payload));
+
+ f_rlcmac_dld_decenc(c_dl_data);
+
+ f_rlcmac_dld_decenc(c_dl_data2);
+
+ log(c_ul_ctrl_ack);
+ ucb := dec_RlcmacUlCtrlBlock(c_ul_ctrl_ack);
+ log(ucb);
+ //log(dec_RlcmacUlCtrlMsg(ucb.payload));
+
+ log(c_ul_dl_ack_nack);
+ ucb := dec_RlcmacUlCtrlBlock(c_ul_dl_ack_nack);
+ log(ucb);
+ //log(dec_RlcmacUlCtrlMsg(ucb.payload));
+
+ log(c_dl_ul_assign);
+ dcb := dec_RlcmacDlCtrlBlock(c_dl_ul_assign);
+ log(dcb);
+ //log(dec_RlcmacDlCtrlMsg(dcb.payload));
+
+ const octetstring c_uld_tlli_noext := '080101a61cab5201c001080103e5e000310a0005f4e61cab5232f44000c8001d1b00'O;
+ f_rlcmac_uld_decenc(c_uld_tlli_noext);
+
+ const octetstring c_uld_tlli_ext7pad := '0001041da61cab5200201705a96e102b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b00'O;
+ log("ULD_decenc");
+ f_rlcmac_uld_decenc(c_uld_tlli_ext7pad);
+ log("UL_decenc");
+ f_rlcmac_ul_decenc(c_uld_tlli_ext7pad);
+
+ f_rlcmac_ul_decenc(c_ul_dl_ack_nack);
+ }
+
+ function f_rlcmac_ul_decenc(in octetstring buf) {
+ log("==================================");
+ log("In: ", buf);
+ var RlcmacUlBlock udb := dec_RlcmacUlBlock(buf);
+ log("Dec: ", udb);
+ var octetstring enc := enc_RlcmacUlBlock(udb);
+ log("Enc: ", enc);
+ if (enc != buf) { setverdict(fail, "Re-encoded data doesn't equal input data"); }
+ }
+
+ function f_rlcmac_uld_decenc(in octetstring buf) {
+ log("==================================");
+ log("In: ", buf);
+ var RlcmacUlDataBlock udb := dec_RlcmacUlDataBlock(buf);
+ log("Dec: ", udb);
+ var octetstring enc := enc_RlcmacUlDataBlock(udb);
+ log("Enc: ", enc);
+ if (enc != buf) { setverdict(fail, "Re-encoded data doesn't equal input data"); }
+ }
+
+ function f_rlcmac_dld_decenc(in octetstring buf) {
+ log("==================================");
+ log("In: ", buf);
+ var RlcmacDlDataBlock udb := dec_RlcmacDlDataBlock(buf);
+ log("Dec: ", udb);
+ var octetstring enc := enc_RlcmacDlDataBlock(udb);
+ log("Enc: ", enc);
+ if (enc != buf) { setverdict(fail, "Re-encoded data doesn't equal input data"); }
+ }
+
+
+ testcase TC_selftest_rr() runs on dummy_CT {
+ //const octetstring c_paging_none := '06210001F02B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O
+ const octetstring c_paging_none := '1506210001F0'O;
+ const octetstring c_ia_tbf := '2d063f100fe3677bd8440000c800100b2b2b2b2b2b2b2b'O
+ log(c_paging_none);
+ log(dec_GsmRrMessage(c_paging_none));
+
+ log(c_ia_tbf);
+ log(dec_GsmRrMessage(c_ia_tbf));
+ }
+
+ function f_seq_octstr(integer len) return octetstring {
+ var octetstring payload := ''O;
+ for (var integer i := 0; i < len; i := i+1 ) {
+ payload := payload & int2oct(i mod 256, 1);
+ }
+ return payload;
+ }
+
+ testcase TC_ul_tbf_single_llc_sizes() runs on dummy_CT {
+ g_mmctx.imsi := '262420123456789'H;
+ g_mmctx.tlli := f_random_tlli();
+ f_init();
+
+ for (var integer len := 1; len <= 1560; len := len+1) {
+ log("Testing Uplink TBF with single LLC-PDU of ", len, " bytes");
+ var octetstring payload := f_seq_octstr(len);
+ var UlTbfPars ul_tbf_pars := {
+ ack_mode := true,
+ initial_cs := CS1,
+ llc_pdus := {
+ valueof(ts_LLC_UI(payload, c_LLC_SAPI_LLGMM, '0'B, g_mmctx.n_u))
+ }
+ }
+ var UlTbfState ul_tbf_state;
+ f_UlTbfState_init(ul_tbf_state, ul_tbf_pars);
+ f_ul_tbf(ul_tbf_state);
+ f_sleep(1.0);
+ }
+
+ f_exit();
+ }
+
+ testcase TC_ul_tbf() runs on dummy_CT {
+ g_mmctx.imsi := '262420123456789'H;
+ g_mmctx.tlli := f_random_tlli();
+ f_init();
+
+ var octetstring payload := f_seq_octstr(1023);
+ var UlTbfPars ul_tbf_pars := {
+ ack_mode := true,
+ initial_cs := CS1,
+ llc_pdus := {
+ valueof(ts_LLC_UI(payload, c_LLC_SAPI_LLGMM, '0'B, g_mmctx.n_u)),
+ valueof(ts_LLC_UI(payload, c_LLC_SAPI_LLGMM, '0'B, g_mmctx.n_u+1)),
+ valueof(ts_LLC_UI(payload, c_LLC_SAPI_LLGMM, '0'B, g_mmctx.n_u+2)),
+ valueof(ts_LLC_UI(payload, c_LLC_SAPI_LLGMM, '0'B, g_mmctx.n_u+3)),
+ valueof(ts_LLC_UI(payload, c_LLC_SAPI_LLGMM, '0'B, g_mmctx.n_u+4)),
+ valueof(ts_LLC_UI(payload, c_LLC_SAPI_LLGMM, '0'B, g_mmctx.n_u+5))
+ }
+ };
+ var UlTbfState ul_tbf_state;
+ f_UlTbfState_init(ul_tbf_state, ul_tbf_pars);
+ f_ul_tbf(ul_tbf_state);
+
+ f_exit();
+ }
+
+ control {
+ execute(TC_selftest_bssgp());
+ execute(TC_selftest_ns());
+ execute(TC_selftest_llc());
+ execute(TC_selftest_rr());
+ execute(TC_selftest_rlcmac());
+ execute(TC_nsem());
+ execute(TC_paging());
+ }
+};
diff --git a/pcu/gen_links.sh b/pcu/gen_links.sh
new file mode 100755
index 0000000..54d2bdd
--- /dev/null
+++ b/pcu/gen_links.sh
@@ -0,0 +1,60 @@
+#!/bin/bash
+
+BASEDIR=../deps
+
+gen_links() {
+ DIR=$1
+ FILES=$*
+ for f in $FILES; do
+ echo "Linking $f"
+ ln -sf $DIR/$f $f
+ done
+}
+
+#DIR=$BASEDIR/titan.TestPorts.UNIX_DOMAIN_SOCKETasp/src
+#FILES="UD_PT.cc UD_PT.hh UD_PortType.ttcn UD_Types.ttcn"
+#gen_links $DIR $FILES
+
+DIR=$BASEDIR/titan.Libraries.TCCUsefulFunctions/src
+FILES="TCCInterface_Functions.ttcn TCCConversion_Functions.ttcn TCCConversion.cc TCCInterface.cc TCCInterface_ip.h"
+gen_links $DIR $FILES
+
+DIR=$BASEDIR/titan.TestPorts.Common_Components.Socket-API/src
+FILES="Socket_API_Definitions.ttcn"
+gen_links $DIR $FILES
+
+DIR=$BASEDIR/titan.TestPorts.IPL4asp/src
+FILES="IPL4asp_Functions.ttcn IPL4asp_PT.cc IPL4asp_PT.hh IPL4asp_PortType.ttcn IPL4asp_Types.ttcn IPL4asp_discovery.cc IPL4asp_protocol_L234.hh"
+gen_links $DIR $FILES
+
+DIR=$BASEDIR/titan.TestPorts.UNIX_DOMAIN_SOCKETasp/src
+FILES="UD_PT.cc UD_PT.hh UD_PortType.ttcn UD_Types.ttcn"
+gen_links $DIR $FILES
+
+DIR=$BASEDIR/titan.ProtocolModules.NS_v7.3.0/src
+FILES="NS_Types.ttcn"
+gen_links $DIR $FILES
+
+DIR=$BASEDIR/titan.ProtocolModules.BSSGP_v13.0.0/src
+FILES="BSSGP_EncDec.cc BSSGP_Types.ttcn"
+gen_links $DIR $FILES
+
+DIR=$BASEDIR/titan.ProtocolModules.MobileL3_v13.4.0/src
+FILES="MobileL3_CC_Types.ttcn MobileL3_CommonIE_Types.ttcn MobileL3_GMM_SM_Types.ttcn MobileL3_MM_Types.ttcn MobileL3_RRM_Types.ttcn MobileL3_SMS_Types.ttcn MobileL3_SS_Types.ttcn MobileL3_Types.ttcn"
+gen_links $DIR $FILES
+
+DIR=$BASEDIR/titan.ProtocolModules.LLC_v7.1.0/src
+FILES="LLC_EncDec.cc LLC_Types.ttcn"
+gen_links $DIR $FILES
+
+DIR=$BASEDIR/titan.ProtocolModules.SNDCP_v7.0.0/src
+FILES="SNDCP_Types.ttcn"
+gen_links $DIR $FILES
+
+
+DIR=../library
+FILES="General_Types.ttcn GSM_Types.ttcn GSM_RR_Types.ttcn Osmocom_Types.ttcn RLCMAC_Types.ttcn RLCMAC_CSN1_Types.ttcn RLCMAC_EncDec.cc L1CTL_Types.ttcn L1CTL_PortType.ttcn L1CTL_PortType_CtrlFunct.ttcn L1CTL_PortType_CtrlFunctDef.cc LAPDm_RAW_PT.ttcn LAPDm_Types.ttcn "
+FILES+="NS_Emulation.ttcn NS_CodecPort.ttcn NS_CodecPort_CtrlFunct.ttcn NS_CodecPort_CtrlFunctDef.cc "
+FILES+="BSSGP_Emulation.ttcn Osmocom_Gb_Types.ttcn "
+FILES+="LLC_Templates.ttcn L3_Templates.ttcn L3_Common.ttcn "
+gen_links $DIR $FILES
diff --git a/pcu/regen_makefile.sh b/pcu/regen_makefile.sh
new file mode 100755
index 0000000..7eefd2c
--- /dev/null
+++ b/pcu/regen_makefile.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+FILES="*.ttcn BSSGP_EncDec.cc IPL4asp_PT.cc IPL4asp_discovery.cc TCCConversion.cc TCCInterface.cc NS_CodecPort_CtrlFunctDef.cc UD_PT.cc RLCMAC_EncDec.cc LLC_EncDec.cc L1CTL_PortType_CtrlFunctDef.cc"
+
+../regen-makefile.sh PCU_Tests.ttcn $FILES