Ivan Kluchnikov | 487a141 | 2011-12-21 13:17:53 +0300 | [diff] [blame] | 1 | /* 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 Kluchnikov | 835f91e | 2012-04-30 18:00:36 +0400 | [diff] [blame] | 25 | #include <cstring> |
Ivan Kluchnikov | 487a141 | 2011-12-21 13:17:53 +0300 | [diff] [blame] | 26 | #include "csn1.h" |
| 27 | #include "gsm_rlcmac.h" |
Andreas Eversberg | 138f4e6 | 2013-01-14 12:31:11 +0100 | [diff] [blame] | 28 | extern "C" { |
| 29 | extern const struct log_info gprs_log_info; |
| 30 | #include "pcu_vty.h" |
| 31 | #include <osmocom/vty/telnet_interface.h> |
| 32 | #include <osmocom/vty/logging.h> |
| 33 | #include <osmocom/core/application.h> |
| 34 | } |
Ivan Kluchnikov | 487a141 | 2011-12-21 13:17:53 +0300 | [diff] [blame] | 35 | using namespace std; |
| 36 | |
| 37 | void printSizeofRLCMAC() |
| 38 | { |
| 39 | cout << "sizeof RlcMacUplink_t " << sizeof(RlcMacUplink_t) << endl; |
| 40 | cout << "sizeof Packet_Cell_Change_Failure_t " << sizeof(Packet_Cell_Change_Failure_t) << endl; |
| 41 | cout << "sizeof Packet_Control_Acknowledgement_t " << sizeof(Packet_Control_Acknowledgement_t) << endl; |
| 42 | cout << "sizeof Packet_Downlink_Ack_Nack_t " << sizeof(Packet_Downlink_Ack_Nack_t) << endl; |
| 43 | cout << "sizeof EGPRS_PD_AckNack_t " << sizeof(EGPRS_PD_AckNack_t) << endl; |
| 44 | cout << "sizeof Packet_Uplink_Dummy_Control_Block_t " << sizeof(Packet_Uplink_Dummy_Control_Block_t) << endl; |
| 45 | cout << "sizeof Packet_Measurement_Report_t " << sizeof(Packet_Measurement_Report_t) << endl; |
| 46 | cout << "sizeof Packet_Resource_Request_t " << sizeof(Packet_Resource_Request_t) << endl; |
| 47 | cout << "sizeof Packet_Mobile_TBF_Status_t " << sizeof(Packet_Mobile_TBF_Status_t) << endl; |
| 48 | cout << "sizeof Packet_PSI_Status_t " << sizeof(Packet_PSI_Status_t) << endl; |
| 49 | cout << "sizeof Packet_Enh_Measurement_Report_t " << sizeof(Packet_Enh_Measurement_Report_t) << endl; |
| 50 | cout << "sizeof Packet_Cell_Change_Notification_t " << sizeof(Packet_Cell_Change_Notification_t) << endl; |
| 51 | cout << "sizeof Packet_SI_Status_t " << sizeof(Packet_SI_Status_t) << endl; |
| 52 | cout << "sizeof Additional_MS_Rad_Access_Cap_t " << sizeof(Additional_MS_Rad_Access_Cap_t) << endl; |
| 53 | cout << "sizeof Packet_Pause_t " << sizeof(Packet_Pause_t) << endl; |
| 54 | |
| 55 | cout << "sizeof RlcMacDownlink_t " << sizeof(RlcMacDownlink_t) << endl; |
| 56 | cout << "sizeof Packet_Access_Reject_t " << sizeof(Packet_Access_Reject_t) << endl; |
Holger Hans Peter Freyther | e13298d | 2013-07-28 16:45:54 +0200 | [diff] [blame] | 57 | cout << "sizeof Packet_Cell_Change_Order_t " << sizeof(Packet_Cell_Change_Order_t) << endl; |
| 58 | cout << "sizeof Packet_Downlink_Assignment_t " << sizeof(Packet_Downlink_Assignment_t) << endl; |
Ivan Kluchnikov | 487a141 | 2011-12-21 13:17:53 +0300 | [diff] [blame] | 59 | cout << "sizeof Packet_Measurement_Order_Reduced_t " << sizeof(Packet_Measurement_Order_Reduced_t) << endl; |
| 60 | cout << "sizeof Packet_Neighbour_Cell_Data_t " << sizeof(Packet_Neighbour_Cell_Data_t) << endl; |
| 61 | cout << "sizeof Packet_Serving_Cell_Data_t " << sizeof(Packet_Serving_Cell_Data_t) << endl; |
| 62 | cout << "sizeof Packet_Paging_Request_t " << sizeof(Packet_Paging_Request_t) << endl; |
| 63 | cout << "sizeof Packet_PDCH_Release_t " << sizeof(Packet_PDCH_Release_t) << endl; |
| 64 | cout << "sizeof Packet_Polling_Request_t " << sizeof(Packet_Polling_Request_t) << endl; |
| 65 | cout << "sizeof Packet_Power_Control_Timing_Advance_t " << sizeof(Packet_Power_Control_Timing_Advance_t) << endl; |
| 66 | cout << "sizeof Packet_PRACH_Parameters_t " << sizeof(Packet_PRACH_Parameters_t) << endl; |
| 67 | cout << "sizeof Packet_Queueing_Notification_t " << sizeof(Packet_Queueing_Notification_t) << endl; |
| 68 | cout << "sizeof Packet_Timeslot_Reconfigure_t " << sizeof(Packet_Timeslot_Reconfigure_t) << endl; |
| 69 | cout << "sizeof Packet_TBF_Release_t " << sizeof(Packet_TBF_Release_t) << endl; |
| 70 | cout << "sizeof Packet_Uplink_Ack_Nack_t " << sizeof(Packet_Uplink_Ack_Nack_t) << endl; |
| 71 | cout << "sizeof Packet_Uplink_Assignment_t " << sizeof(Packet_Uplink_Assignment_t) << endl; |
| 72 | cout << "sizeof Packet_Cell_Change_Continue_t " << sizeof(Packet_Cell_Change_Continue_t) << endl; |
| 73 | cout << "sizeof Packet_Handover_Command_t " << sizeof(Packet_Handover_Command_t) << endl; |
| 74 | cout << "sizeof Packet_PhysicalInformation_t " << sizeof(Packet_PhysicalInformation_t) << endl; |
| 75 | cout << "sizeof Packet_Downlink_Dummy_Control_Block_t " << sizeof(Packet_Downlink_Dummy_Control_Block_t) << endl; |
| 76 | cout << "sizeof PSI1_t " << sizeof(PSI1_t) << endl; |
| 77 | cout << "sizeof PSI2_t " << sizeof(PSI2_t) << endl; |
| 78 | cout << "sizeof PSI3_t " << sizeof(PSI3_t) << endl; |
| 79 | cout << "sizeof PSI3_BIS_t " << sizeof(PSI3_BIS_t) << endl; |
| 80 | cout << "sizeof PSI4_t " << sizeof(PSI4_t) << endl; |
| 81 | cout << "sizeof PSI13_t " << sizeof(PSI13_t) << endl; |
| 82 | cout << "sizeof PSI5_t " << sizeof(PSI5_t) << endl; |
| 83 | } |
| 84 | |
| 85 | void testRlcMacDownlink() |
| 86 | { |
Ivan Kluchnikov | 835f91e | 2012-04-30 18:00:36 +0400 | [diff] [blame] | 87 | struct bitvec *resultVector = bitvec_alloc(23); |
| 88 | bitvec_unhex(resultVector, "2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b"); |
Ivan Kluchnikov | 487a141 | 2011-12-21 13:17:53 +0300 | [diff] [blame] | 89 | |
| 90 | std::string testData[] = { |
| 91 | "4e082500e3f1a81d080820800b2b2b2b2b2b2b2b2b2b2b", // Packet Downlink Assignment |
| 92 | "48282407a6a074227201000b2b2b2b2b2b2b2b2b2b2b2b", // Packet Uplink Assignment |
| 93 | "47240c00400000000000000079eb2ac9402b2b2b2b2b2b", // Packet Uplink Ack Nack |
| 94 | "47283c367513ba333004242b2b2b2b2b2b2b2b2b2b2b2b" // Packet Uplink Assignment |
Ivan Kluchnikov | 835f91e | 2012-04-30 18:00:36 +0400 | [diff] [blame] | 95 | "4913e00850884013a8048b2b2b2b2b2b2b2b2b2b2b2b2b" |
| 96 | "412430007fffffffffffffffefd19c7ba12b2b2b2b2b2b" |
| 97 | "41942b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b" |
Ivan Kluchnikov | 487a141 | 2011-12-21 13:17:53 +0300 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | int testDataSize = sizeof(testData)/sizeof(testData[0]); |
Ivan Kluchnikov | 487a141 | 2011-12-21 13:17:53 +0300 | [diff] [blame] | 101 | |
| 102 | cout << " DOWNLINK " << endl; |
| 103 | for (int i = 0; i < testDataSize; i++) |
| 104 | { |
Ivan Kluchnikov | 835f91e | 2012-04-30 18:00:36 +0400 | [diff] [blame] | 105 | bitvec *vector = bitvec_alloc(23); |
| 106 | bitvec_unhex(vector, testData[i].c_str()); |
| 107 | cout << "vector1 = "; |
| 108 | for (int i = 0; i < 23; i++) |
| 109 | { |
| 110 | cout << hex << (unsigned)*(vector->data + i); |
| 111 | } |
| 112 | cout << endl; |
Ivan Kluchnikov | 487a141 | 2011-12-21 13:17:53 +0300 | [diff] [blame] | 113 | RlcMacDownlink_t * data = (RlcMacDownlink_t *)malloc(sizeof(RlcMacDownlink_t)); |
| 114 | cout << "=========Start DECODE===========" << endl; |
Ivan Kluchnikov | 835f91e | 2012-04-30 18:00:36 +0400 | [diff] [blame] | 115 | decode_gsm_rlcmac_downlink(vector, data); |
Ivan Kluchnikov | 487a141 | 2011-12-21 13:17:53 +0300 | [diff] [blame] | 116 | cout << "+++++++++Finish DECODE++++++++++" << endl; |
| 117 | cout << "=========Start ENCODE=============" << endl; |
Ivan Kluchnikov | 835f91e | 2012-04-30 18:00:36 +0400 | [diff] [blame] | 118 | encode_gsm_rlcmac_downlink(resultVector, data); |
Ivan Kluchnikov | 487a141 | 2011-12-21 13:17:53 +0300 | [diff] [blame] | 119 | cout << "+++++++++Finish ENCODE+++++++++++" << endl; |
Ivan Kluchnikov | 835f91e | 2012-04-30 18:00:36 +0400 | [diff] [blame] | 120 | cout << "vector1 = "; |
| 121 | for (int i = 0; i < 23; i++) |
| 122 | { |
| 123 | cout << (unsigned)*(vector->data + i); |
| 124 | } |
| 125 | cout << endl; |
| 126 | cout << "vector2 = "; |
| 127 | for (int i = 0; i < 23; i++) |
| 128 | { |
| 129 | cout << (unsigned)*(resultVector->data + i); |
| 130 | } |
| 131 | cout << endl; |
| 132 | if (memcmp(vector->data, resultVector->data, 23) == 0) |
Ivan Kluchnikov | 487a141 | 2011-12-21 13:17:53 +0300 | [diff] [blame] | 133 | { |
| 134 | cout << "vector1 == vector2 : TRUE" << endl; |
| 135 | } |
| 136 | else |
| 137 | { |
| 138 | cout << "vector1 == vector2 : FALSE" << endl; |
| 139 | } |
Ivan Kluchnikov | 835f91e | 2012-04-30 18:00:36 +0400 | [diff] [blame] | 140 | bitvec_unhex(resultVector, "2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b"); |
| 141 | bitvec_free(vector); |
Ivan Kluchnikov | 487a141 | 2011-12-21 13:17:53 +0300 | [diff] [blame] | 142 | free(data); |
| 143 | } |
Andreas Eversberg | 273a222 | 2013-01-16 08:56:33 +0100 | [diff] [blame] | 144 | |
| 145 | bitvec_free(resultVector); |
Ivan Kluchnikov | 487a141 | 2011-12-21 13:17:53 +0300 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | |
| 149 | void testRlcMacUplink() |
| 150 | { |
Ivan Kluchnikov | 835f91e | 2012-04-30 18:00:36 +0400 | [diff] [blame] | 151 | struct bitvec *resultVector = bitvec_alloc(23); |
| 152 | bitvec_unhex(resultVector, "2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b"); |
Ivan Kluchnikov | 487a141 | 2011-12-21 13:17:53 +0300 | [diff] [blame] | 153 | |
| 154 | std::string testData[] = { |
| 155 | "400e1e61d11f2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b", // Packet Uplink Dummy Control Block |
| 156 | "400b8020000000000000002480e00b2b2b2b2b2b2b2b2b", // Packet Downlink Ack/Nack |
| 157 | "4016713dc094270ca2ae57ef909006aa0fc0001f80222b" // Packet Resource Request |
Ivan Kluchnikov | 835f91e | 2012-04-30 18:00:36 +0400 | [diff] [blame] | 158 | "400a9020000000000000003010012a0800132b2b2b2b2b" |
Ivan Kluchnikov | 487a141 | 2011-12-21 13:17:53 +0300 | [diff] [blame] | 159 | }; |
| 160 | |
| 161 | int testDataSize = sizeof(testData)/sizeof(testData[0]); |
Ivan Kluchnikov | 487a141 | 2011-12-21 13:17:53 +0300 | [diff] [blame] | 162 | |
Ivan Kluchnikov | 487a141 | 2011-12-21 13:17:53 +0300 | [diff] [blame] | 163 | |
| 164 | cout << " UPLINK " << endl; |
| 165 | for (int i = 0; i < testDataSize; i++) |
| 166 | { |
Ivan Kluchnikov | 835f91e | 2012-04-30 18:00:36 +0400 | [diff] [blame] | 167 | bitvec *vector = bitvec_alloc(23); |
| 168 | bitvec_unhex(vector, testData[i].c_str()); |
| 169 | cout << "vector1 = "; |
| 170 | for (int i = 0; i < 23; i++) |
| 171 | { |
| 172 | cout << hex << (unsigned)*(vector->data + i); |
| 173 | } |
| 174 | cout << endl; |
Ivan Kluchnikov | 487a141 | 2011-12-21 13:17:53 +0300 | [diff] [blame] | 175 | RlcMacUplink_t * data = (RlcMacUplink_t *)malloc(sizeof(RlcMacUplink_t)); |
| 176 | cout << "=========Start DECODE===========" << endl; |
Ivan Kluchnikov | 835f91e | 2012-04-30 18:00:36 +0400 | [diff] [blame] | 177 | decode_gsm_rlcmac_uplink(vector, data); |
Ivan Kluchnikov | 487a141 | 2011-12-21 13:17:53 +0300 | [diff] [blame] | 178 | cout << "+++++++++Finish DECODE++++++++++" << endl; |
| 179 | cout << "=========Start ENCODE=============" << endl; |
Ivan Kluchnikov | 835f91e | 2012-04-30 18:00:36 +0400 | [diff] [blame] | 180 | encode_gsm_rlcmac_uplink(resultVector, data); |
Ivan Kluchnikov | 487a141 | 2011-12-21 13:17:53 +0300 | [diff] [blame] | 181 | cout << "+++++++++Finish ENCODE+++++++++++" << endl; |
Ivan Kluchnikov | 835f91e | 2012-04-30 18:00:36 +0400 | [diff] [blame] | 182 | cout << "vector1 = "; |
| 183 | for (int i = 0; i < 23; i++) |
| 184 | { |
| 185 | cout << (unsigned)*(vector->data + i); |
| 186 | } |
| 187 | cout << endl; |
| 188 | cout << "vector2 = "; |
| 189 | for (int i = 0; i < 23; i++) |
| 190 | { |
| 191 | cout << (unsigned)*(resultVector->data + i); |
| 192 | } |
| 193 | cout << endl; |
| 194 | if (memcmp(vector->data, resultVector->data, 23) == 0) |
Ivan Kluchnikov | 487a141 | 2011-12-21 13:17:53 +0300 | [diff] [blame] | 195 | { |
| 196 | cout << "vector1 == vector2 : TRUE" << endl; |
| 197 | } |
| 198 | else |
| 199 | { |
| 200 | cout << "vector1 == vector2 : FALSE" << endl; |
| 201 | } |
Ivan Kluchnikov | 835f91e | 2012-04-30 18:00:36 +0400 | [diff] [blame] | 202 | bitvec_unhex(resultVector, "2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b"); |
| 203 | bitvec_free(vector); |
Ivan Kluchnikov | 487a141 | 2011-12-21 13:17:53 +0300 | [diff] [blame] | 204 | free(data); |
| 205 | } |
Andreas Eversberg | 273a222 | 2013-01-16 08:56:33 +0100 | [diff] [blame] | 206 | |
| 207 | bitvec_free(resultVector); |
Ivan Kluchnikov | 487a141 | 2011-12-21 13:17:53 +0300 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | int main(int argc, char *argv[]) |
| 211 | { |
Andreas Eversberg | 138f4e6 | 2013-01-14 12:31:11 +0100 | [diff] [blame] | 212 | osmo_init_logging(&gprs_log_info); |
| 213 | |
Ivan Kluchnikov | 487a141 | 2011-12-21 13:17:53 +0300 | [diff] [blame] | 214 | //printSizeofRLCMAC(); |
| 215 | testRlcMacDownlink(); |
| 216 | testRlcMacUplink(); |
| 217 | |
| 218 | } |