blob: bf7a60529d6b46261dffd27b259a24acc02c2df7 [file] [log] [blame]
Ivan Kluchnikov487a1412011-12-21 13:17:53 +03001/* RLCMACTest.cpp
2 *
3 * Copyright (C) 2011 Ivan Klyuchnikov
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20
21
22//#include <BitVector.h>
23#include <iostream>
24#include <cstdlib>
Ivan Kluchnikov835f91e2012-04-30 18:00:36 +040025#include <cstring>
Ivan Kluchnikov487a1412011-12-21 13:17:53 +030026#include "csn1.h"
27#include "gsm_rlcmac.h"
Max7426c5f2019-02-18 20:42:42 +010028#include "gprs_rlcmac.h"
29
Andreas Eversberg138f4e62013-01-14 12:31:11 +010030extern "C" {
31extern const struct log_info gprs_log_info;
32#include "pcu_vty.h"
33#include <osmocom/vty/telnet_interface.h>
34#include <osmocom/vty/logging.h>
Aravind Sirsikar9f5f0082016-08-30 13:20:23 +053035#include <osmocom/core/utils.h>
Andreas Eversberg138f4e62013-01-14 12:31:11 +010036#include <osmocom/core/application.h>
37}
Ivan Kluchnikov487a1412011-12-21 13:17:53 +030038using namespace std;
39
40void printSizeofRLCMAC()
41{
42 cout << "sizeof RlcMacUplink_t " << sizeof(RlcMacUplink_t) << endl;
43 cout << "sizeof Packet_Cell_Change_Failure_t " << sizeof(Packet_Cell_Change_Failure_t) << endl;
44 cout << "sizeof Packet_Control_Acknowledgement_t " << sizeof(Packet_Control_Acknowledgement_t) << endl;
45 cout << "sizeof Packet_Downlink_Ack_Nack_t " << sizeof(Packet_Downlink_Ack_Nack_t) << endl;
46 cout << "sizeof EGPRS_PD_AckNack_t " << sizeof(EGPRS_PD_AckNack_t) << endl;
47 cout << "sizeof Packet_Uplink_Dummy_Control_Block_t " << sizeof(Packet_Uplink_Dummy_Control_Block_t) << endl;
48 cout << "sizeof Packet_Measurement_Report_t " << sizeof(Packet_Measurement_Report_t) << endl;
49 cout << "sizeof Packet_Resource_Request_t " << sizeof(Packet_Resource_Request_t) << endl;
50 cout << "sizeof Packet_Mobile_TBF_Status_t " << sizeof(Packet_Mobile_TBF_Status_t) << endl;
51 cout << "sizeof Packet_PSI_Status_t " << sizeof(Packet_PSI_Status_t) << endl;
52 cout << "sizeof Packet_Enh_Measurement_Report_t " << sizeof(Packet_Enh_Measurement_Report_t) << endl;
53 cout << "sizeof Packet_Cell_Change_Notification_t " << sizeof(Packet_Cell_Change_Notification_t) << endl;
54 cout << "sizeof Packet_SI_Status_t " << sizeof(Packet_SI_Status_t) << endl;
55 cout << "sizeof Additional_MS_Rad_Access_Cap_t " << sizeof(Additional_MS_Rad_Access_Cap_t) << endl;
56 cout << "sizeof Packet_Pause_t " << sizeof(Packet_Pause_t) << endl;
57
58 cout << "sizeof RlcMacDownlink_t " << sizeof(RlcMacDownlink_t) << endl;
59 cout << "sizeof Packet_Access_Reject_t " << sizeof(Packet_Access_Reject_t) << endl;
Holger Hans Peter Freythere13298d2013-07-28 16:45:54 +020060 cout << "sizeof Packet_Cell_Change_Order_t " << sizeof(Packet_Cell_Change_Order_t) << endl;
61 cout << "sizeof Packet_Downlink_Assignment_t " << sizeof(Packet_Downlink_Assignment_t) << endl;
Ivan Kluchnikov487a1412011-12-21 13:17:53 +030062 cout << "sizeof Packet_Measurement_Order_Reduced_t " << sizeof(Packet_Measurement_Order_Reduced_t) << endl;
63 cout << "sizeof Packet_Neighbour_Cell_Data_t " << sizeof(Packet_Neighbour_Cell_Data_t) << endl;
64 cout << "sizeof Packet_Serving_Cell_Data_t " << sizeof(Packet_Serving_Cell_Data_t) << endl;
65 cout << "sizeof Packet_Paging_Request_t " << sizeof(Packet_Paging_Request_t) << endl;
66 cout << "sizeof Packet_PDCH_Release_t " << sizeof(Packet_PDCH_Release_t) << endl;
67 cout << "sizeof Packet_Polling_Request_t " << sizeof(Packet_Polling_Request_t) << endl;
68 cout << "sizeof Packet_Power_Control_Timing_Advance_t " << sizeof(Packet_Power_Control_Timing_Advance_t) << endl;
69 cout << "sizeof Packet_PRACH_Parameters_t " << sizeof(Packet_PRACH_Parameters_t) << endl;
70 cout << "sizeof Packet_Queueing_Notification_t " << sizeof(Packet_Queueing_Notification_t) << endl;
71 cout << "sizeof Packet_Timeslot_Reconfigure_t " << sizeof(Packet_Timeslot_Reconfigure_t) << endl;
72 cout << "sizeof Packet_TBF_Release_t " << sizeof(Packet_TBF_Release_t) << endl;
73 cout << "sizeof Packet_Uplink_Ack_Nack_t " << sizeof(Packet_Uplink_Ack_Nack_t) << endl;
74 cout << "sizeof Packet_Uplink_Assignment_t " << sizeof(Packet_Uplink_Assignment_t) << endl;
75 cout << "sizeof Packet_Cell_Change_Continue_t " << sizeof(Packet_Cell_Change_Continue_t) << endl;
76 cout << "sizeof Packet_Handover_Command_t " << sizeof(Packet_Handover_Command_t) << endl;
77 cout << "sizeof Packet_PhysicalInformation_t " << sizeof(Packet_PhysicalInformation_t) << endl;
78 cout << "sizeof Packet_Downlink_Dummy_Control_Block_t " << sizeof(Packet_Downlink_Dummy_Control_Block_t) << endl;
79 cout << "sizeof PSI1_t " << sizeof(PSI1_t) << endl;
80 cout << "sizeof PSI2_t " << sizeof(PSI2_t) << endl;
81 cout << "sizeof PSI3_t " << sizeof(PSI3_t) << endl;
82 cout << "sizeof PSI3_BIS_t " << sizeof(PSI3_BIS_t) << endl;
83 cout << "sizeof PSI4_t " << sizeof(PSI4_t) << endl;
84 cout << "sizeof PSI13_t " << sizeof(PSI13_t) << endl;
85 cout << "sizeof PSI5_t " << sizeof(PSI5_t) << endl;
86}
87
Alexander Couzensccde5c92017-02-04 03:10:08 +010088void testRlcMacDownlink(void *test_ctx)
Ivan Kluchnikov487a1412011-12-21 13:17:53 +030089{
Alexander Couzensccde5c92017-02-04 03:10:08 +010090 struct bitvec *resultVector = bitvec_alloc(23, test_ctx);
Max7426c5f2019-02-18 20:42:42 +010091 bitvec_unhex(resultVector, DUMMY_VEC);
Ivan Kluchnikov487a1412011-12-21 13:17:53 +030092
93 std::string testData[] = {
94 "4e082500e3f1a81d080820800b2b2b2b2b2b2b2b2b2b2b", // Packet Downlink Assignment
Saurabh Sharan656eed52016-03-10 14:15:29 +053095 "48282407a6a07422720100032b2b2b2b2b2b2b2b2b2b2b", // Packet Uplink Assignment
Ivan Kluchnikov487a1412011-12-21 13:17:53 +030096 "47240c00400000000000000079eb2ac9402b2b2b2b2b2b", // Packet Uplink Ack Nack
Saurabh Sharanbacb65b2016-03-10 17:24:49 +053097 "47283c367513ba333004242b2b2b2b2b2b2b2b2b2b2b2b", // Packet Uplink Assignment
98 "400820001a3904df0680efb3300b2b2b2b2b2b2b2b2b2b", // Packet Downlink Assignment (EGPRS)
Saurabh Sharan2b09c392016-03-16 19:17:32 +053099 "40284f0000001009810c826f4406809dcecb2b2b2b2b2b", // Packet Uplink Assignment (EGPRS)
Saurabh Sharanbacb65b2016-03-10 17:24:49 +0530100 "4024030f2f0000000087b0042b2b2b2b2b2b2b2b2b2b2b" // Packet Uplink Ack Nack (EGPRS)
Ivan Kluchnikov835f91e2012-04-30 18:00:36 +0400101 "4913e00850884013a8048b2b2b2b2b2b2b2b2b2b2b2b2b"
102 "412430007fffffffffffffffefd19c7ba12b2b2b2b2b2b"
103 "41942b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b"
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300104 };
105
106 int testDataSize = sizeof(testData)/sizeof(testData[0]);
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300107
108 cout << " DOWNLINK " << endl;
109 for (int i = 0; i < testDataSize; i++)
110 {
Alexander Couzensccde5c92017-02-04 03:10:08 +0100111 bitvec *vector = bitvec_alloc(23, test_ctx);
Ivan Kluchnikov835f91e2012-04-30 18:00:36 +0400112 bitvec_unhex(vector, testData[i].c_str());
113 cout << "vector1 = ";
114 for (int i = 0; i < 23; i++)
115 {
116 cout << hex << (unsigned)*(vector->data + i);
117 }
118 cout << endl;
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300119 RlcMacDownlink_t * data = (RlcMacDownlink_t *)malloc(sizeof(RlcMacDownlink_t));
120 cout << "=========Start DECODE===========" << endl;
Ivan Kluchnikov835f91e2012-04-30 18:00:36 +0400121 decode_gsm_rlcmac_downlink(vector, data);
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300122 cout << "+++++++++Finish DECODE++++++++++" << endl;
123 cout << "=========Start ENCODE=============" << endl;
Ivan Kluchnikov835f91e2012-04-30 18:00:36 +0400124 encode_gsm_rlcmac_downlink(resultVector, data);
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300125 cout << "+++++++++Finish ENCODE+++++++++++" << endl;
Ivan Kluchnikov835f91e2012-04-30 18:00:36 +0400126 cout << "vector1 = ";
127 for (int i = 0; i < 23; i++)
128 {
129 cout << (unsigned)*(vector->data + i);
130 }
131 cout << endl;
132 cout << "vector2 = ";
133 for (int i = 0; i < 23; i++)
134 {
135 cout << (unsigned)*(resultVector->data + i);
136 }
137 cout << endl;
138 if (memcmp(vector->data, resultVector->data, 23) == 0)
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300139 {
140 cout << "vector1 == vector2 : TRUE" << endl;
141 }
142 else
143 {
144 cout << "vector1 == vector2 : FALSE" << endl;
145 }
Max7426c5f2019-02-18 20:42:42 +0100146 bitvec_unhex(resultVector, DUMMY_VEC);
Ivan Kluchnikov835f91e2012-04-30 18:00:36 +0400147 bitvec_free(vector);
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300148 free(data);
149 }
Andreas Eversberg273a2222013-01-16 08:56:33 +0100150
151 bitvec_free(resultVector);
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300152}
153
154
Alexander Couzensccde5c92017-02-04 03:10:08 +0100155void testRlcMacUplink(void *test_ctx)
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300156{
Alexander Couzensccde5c92017-02-04 03:10:08 +0100157 struct bitvec *resultVector = bitvec_alloc(23, test_ctx);
Max7426c5f2019-02-18 20:42:42 +0100158 bitvec_unhex(resultVector, DUMMY_VEC);
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300159
160 std::string testData[] = {
Saurabh Sharan656eed52016-03-10 14:15:29 +0530161 "400e1e61d11d2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b", // Packet Uplink Dummy Control Block
162 "400b8020000000000000002480e0032b2b2b2b2b2b2b2b", // Packet Downlink Ack/Nack
Saurabh Sharanbacb65b2016-03-10 17:24:49 +0530163 "4016713dc094270ca2ae57ef909006aa0fc0001f80222b", // Packet Resource Request
164 "40200ffc0021ec010b2b2b2b2b2b2b2b2b2b2b2b2b2b2b", // EPDAN
Ivan Kluchnikov835f91e2012-04-30 18:00:36 +0400165 "400a9020000000000000003010012a0800132b2b2b2b2b"
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300166 };
167
168 int testDataSize = sizeof(testData)/sizeof(testData[0]);
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300169
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300170
171 cout << " UPLINK " << endl;
172 for (int i = 0; i < testDataSize; i++)
173 {
Alexander Couzensccde5c92017-02-04 03:10:08 +0100174 bitvec *vector = bitvec_alloc(23, test_ctx);
Ivan Kluchnikov835f91e2012-04-30 18:00:36 +0400175 bitvec_unhex(vector, testData[i].c_str());
176 cout << "vector1 = ";
177 for (int i = 0; i < 23; i++)
178 {
179 cout << hex << (unsigned)*(vector->data + i);
180 }
181 cout << endl;
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300182 RlcMacUplink_t * data = (RlcMacUplink_t *)malloc(sizeof(RlcMacUplink_t));
183 cout << "=========Start DECODE===========" << endl;
Ivan Kluchnikov835f91e2012-04-30 18:00:36 +0400184 decode_gsm_rlcmac_uplink(vector, data);
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300185 cout << "+++++++++Finish DECODE++++++++++" << endl;
186 cout << "=========Start ENCODE=============" << endl;
Ivan Kluchnikov835f91e2012-04-30 18:00:36 +0400187 encode_gsm_rlcmac_uplink(resultVector, data);
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300188 cout << "+++++++++Finish ENCODE+++++++++++" << endl;
Ivan Kluchnikov835f91e2012-04-30 18:00:36 +0400189 cout << "vector1 = ";
190 for (int i = 0; i < 23; i++)
191 {
192 cout << (unsigned)*(vector->data + i);
193 }
194 cout << endl;
195 cout << "vector2 = ";
196 for (int i = 0; i < 23; i++)
197 {
198 cout << (unsigned)*(resultVector->data + i);
199 }
200 cout << endl;
201 if (memcmp(vector->data, resultVector->data, 23) == 0)
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300202 {
203 cout << "vector1 == vector2 : TRUE" << endl;
204 }
205 else
206 {
207 cout << "vector1 == vector2 : FALSE" << endl;
208 }
Max7426c5f2019-02-18 20:42:42 +0100209 bitvec_unhex(resultVector, DUMMY_VEC);
Ivan Kluchnikov835f91e2012-04-30 18:00:36 +0400210 bitvec_free(vector);
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300211 free(data);
212 }
Andreas Eversberg273a2222013-01-16 08:56:33 +0100213
214 bitvec_free(resultVector);
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300215}
216
Alexander Couzensccde5c92017-02-04 03:10:08 +0100217void testCsnLeftAlignedVarBmpBounds(void *test_ctx)
Aravind Sirsikar9f5f0082016-08-30 13:20:23 +0530218{
Alexander Couzensccde5c92017-02-04 03:10:08 +0100219 bitvec *vector = bitvec_alloc(23, test_ctx);
Aravind Sirsikar9f5f0082016-08-30 13:20:23 +0530220
221 bitvec_unhex(vector, "40200bffd161003e0e519ffffffb800000000000000000");
222 RlcMacUplink_t data;
223
224 EGPRS_AckNack_Desc_t *urbb =
225 &data.u.Egprs_Packet_Downlink_Ack_Nack.EGPRS_AckNack.Desc;
226 decode_gsm_rlcmac_uplink(vector, &data);
227
Aravind Sirsikar9f5f0082016-08-30 13:20:23 +0530228 OSMO_ASSERT(!strcmp(osmo_hexdump(urbb->URBB, 13),
Neels Hofmeyr02415262016-09-02 02:15:26 +0200229 "7f ff ff ee 00 00 00 00 00 00 00 00 00 "));
Aravind Sirsikar9f5f0082016-08-30 13:20:23 +0530230}
231
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300232int main(int argc, char *argv[])
233{
Alexander Couzensccde5c92017-02-04 03:10:08 +0100234 void *ctx = talloc_named_const(NULL, 1, "RLCMACTest");
Neels Hofmeyr42f2d612018-04-01 16:54:40 +0200235 osmo_init_logging2(ctx, &gprs_log_info);
Andreas Eversberg138f4e62013-01-14 12:31:11 +0100236
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300237 //printSizeofRLCMAC();
Alexander Couzensccde5c92017-02-04 03:10:08 +0100238 testRlcMacDownlink(ctx);
239 testRlcMacUplink(ctx);
240 testCsnLeftAlignedVarBmpBounds(ctx);
241 talloc_free(ctx);
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300242}