Holger Hans Peter Freyther | 6058220 | 2013-11-21 21:30:23 +0100 | [diff] [blame] | 1 | /* |
| 2 | * TypesTest.cpp Test the primitive data types |
| 3 | * |
| 4 | * Copyright (C) 2013 by Holger Hans Peter Freyther |
| 5 | * |
| 6 | * All Rights Reserved |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU Affero General Public License as published by |
| 10 | * the Free Software Foundation; either version 3 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Affero General Public License |
| 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | * |
| 21 | */ |
| 22 | #include "bts.h" |
| 23 | #include "tbf.h" |
| 24 | #include "gprs_debug.h" |
Daniel Willmann | 0f2b5fc | 2013-12-11 16:49:43 +0100 | [diff] [blame] | 25 | #include "encoding.h" |
Daniel Willmann | f1786a3 | 2013-12-11 18:44:49 +0100 | [diff] [blame] | 26 | #include "decoding.h" |
Holger Hans Peter Freyther | 6058220 | 2013-11-21 21:30:23 +0100 | [diff] [blame] | 27 | |
| 28 | extern "C" { |
| 29 | #include <osmocom/core/application.h> |
| 30 | #include <osmocom/core/msgb.h> |
| 31 | #include <osmocom/core/talloc.h> |
| 32 | #include <osmocom/core/utils.h> |
| 33 | } |
| 34 | |
Daniel Willmann | c3f4330 | 2013-12-11 16:47:19 +0100 | [diff] [blame] | 35 | #define OSMO_ASSERT_STR_EQ(a, b) \ |
| 36 | do { \ |
| 37 | if (strcmp(a, b)) { \ |
| 38 | printf("String mismatch:\nGot:\t%s\nWant:\t%s\n", a, b); \ |
| 39 | OSMO_ASSERT(false); \ |
| 40 | } \ |
| 41 | } while (0) |
| 42 | |
Holger Hans Peter Freyther | 6058220 | 2013-11-21 21:30:23 +0100 | [diff] [blame] | 43 | void *tall_pcu_ctx; |
| 44 | int16_t spoof_mnc = 0, spoof_mcc = 0; |
| 45 | |
| 46 | static void test_llc(void) |
| 47 | { |
| 48 | { |
| 49 | uint8_t data[LLC_MAX_LEN] = {1, 2, 3, 4, }; |
| 50 | uint8_t out; |
| 51 | gprs_llc llc; |
| 52 | llc.init(); |
| 53 | |
| 54 | OSMO_ASSERT(llc.chunk_size() == 0); |
| 55 | OSMO_ASSERT(llc.remaining_space() == LLC_MAX_LEN); |
| 56 | OSMO_ASSERT(llc.frame_length() == 0); |
| 57 | |
| 58 | llc.put_frame(data, 2); |
| 59 | OSMO_ASSERT(llc.remaining_space() == LLC_MAX_LEN - 2); |
| 60 | OSMO_ASSERT(llc.frame_length() == 2); |
| 61 | OSMO_ASSERT(llc.chunk_size() == 2); |
| 62 | OSMO_ASSERT(llc.frame[0] == 1); |
| 63 | OSMO_ASSERT(llc.frame[1] == 2); |
| 64 | |
| 65 | llc.append_frame(&data[3], 1); |
| 66 | OSMO_ASSERT(llc.remaining_space() == LLC_MAX_LEN - 3); |
| 67 | OSMO_ASSERT(llc.frame_length() == 3); |
| 68 | OSMO_ASSERT(llc.chunk_size() == 3); |
| 69 | |
| 70 | /* consume two bytes */ |
| 71 | llc.consume(&out, 1); |
| 72 | OSMO_ASSERT(llc.remaining_space() == LLC_MAX_LEN - 3); |
| 73 | OSMO_ASSERT(llc.frame_length() == 3); |
| 74 | OSMO_ASSERT(llc.chunk_size() == 2); |
| 75 | |
| 76 | /* check that the bytes are as we expected */ |
| 77 | OSMO_ASSERT(llc.frame[0] == 1); |
| 78 | OSMO_ASSERT(llc.frame[1] == 2); |
| 79 | OSMO_ASSERT(llc.frame[2] == 4); |
| 80 | |
| 81 | /* now fill the frame */ |
| 82 | llc.append_frame(data, llc.remaining_space() - 1); |
| 83 | OSMO_ASSERT(llc.fits_in_current_frame(1)); |
| 84 | OSMO_ASSERT(!llc.fits_in_current_frame(2)); |
| 85 | } |
| 86 | } |
| 87 | |
Holger Hans Peter Freyther | c6382dd | 2013-11-21 21:42:20 +0100 | [diff] [blame] | 88 | static void test_rlc() |
| 89 | { |
| 90 | { |
| 91 | struct gprs_rlc_data rlc = { 0, }; |
| 92 | memset(rlc.block, 0x23, RLC_MAX_LEN); |
| 93 | uint8_t *p = rlc.prepare(20); |
| 94 | OSMO_ASSERT(p == rlc.block); |
| 95 | for (int i = 0; i < 20; ++i) |
| 96 | OSMO_ASSERT(p[i] == 0x2B); |
| 97 | for (int i = 20; i < RLC_MAX_LEN; ++i) |
| 98 | OSMO_ASSERT(p[i] == 0x0); |
| 99 | } |
| 100 | } |
| 101 | |
Holger Hans Peter Freyther | 9525567 | 2013-11-23 16:18:18 +0100 | [diff] [blame] | 102 | static void test_rlc_v_b() |
| 103 | { |
| 104 | { |
| 105 | gprs_rlc_v_b vb; |
| 106 | vb.reset(); |
| 107 | |
Holger Hans Peter Freyther | 11f2d58 | 2013-11-26 23:32:49 +0100 | [diff] [blame] | 108 | for (size_t i = 0; i < RLC_MAX_SNS; ++i) |
Holger Hans Peter Freyther | 9525567 | 2013-11-23 16:18:18 +0100 | [diff] [blame] | 109 | OSMO_ASSERT(vb.is_invalid(i)); |
| 110 | |
| 111 | vb.mark_unacked(23); |
| 112 | OSMO_ASSERT(vb.is_unacked(23)); |
| 113 | |
| 114 | vb.mark_nacked(23); |
| 115 | OSMO_ASSERT(vb.is_nacked(23)); |
| 116 | |
| 117 | vb.mark_acked(23); |
| 118 | OSMO_ASSERT(vb.is_acked(23)); |
| 119 | |
| 120 | vb.mark_resend(23); |
| 121 | OSMO_ASSERT(vb.is_resend(23)); |
| 122 | |
| 123 | vb.mark_invalid(23); |
| 124 | OSMO_ASSERT(vb.is_invalid(23)); |
| 125 | } |
| 126 | } |
| 127 | |
Holger Hans Peter Freyther | e9b1ebb | 2013-11-24 22:00:43 +0100 | [diff] [blame] | 128 | static void test_rlc_v_n() |
| 129 | { |
| 130 | { |
| 131 | gprs_rlc_v_n vn; |
| 132 | vn.reset(); |
| 133 | |
| 134 | OSMO_ASSERT(!vn.is_received(0x23)); |
Daniel Willmann | d54d9f5 | 2013-12-28 21:16:13 +0100 | [diff] [blame] | 135 | OSMO_ASSERT(vn.state(0x23) == GPRS_RLC_UL_BSN_INVALID); |
Holger Hans Peter Freyther | e9b1ebb | 2013-11-24 22:00:43 +0100 | [diff] [blame] | 136 | |
| 137 | vn.mark_received(0x23); |
| 138 | OSMO_ASSERT(vn.is_received(0x23)); |
Daniel Willmann | d54d9f5 | 2013-12-28 21:16:13 +0100 | [diff] [blame] | 139 | OSMO_ASSERT(vn.state(0x23) == GPRS_RLC_UL_BSN_RECEIVED); |
Holger Hans Peter Freyther | e9b1ebb | 2013-11-24 22:00:43 +0100 | [diff] [blame] | 140 | |
| 141 | vn.mark_missing(0x23); |
| 142 | OSMO_ASSERT(!vn.is_received(0x23)); |
Daniel Willmann | d54d9f5 | 2013-12-28 21:16:13 +0100 | [diff] [blame] | 143 | OSMO_ASSERT(vn.state(0x23) == GPRS_RLC_UL_BSN_MISSING); |
Holger Hans Peter Freyther | e9b1ebb | 2013-11-24 22:00:43 +0100 | [diff] [blame] | 144 | } |
| 145 | } |
| 146 | |
Holger Hans Peter Freyther | faf3ef4 | 2013-11-24 22:17:40 +0100 | [diff] [blame] | 147 | static void test_rlc_dl_ul_basic() |
| 148 | { |
| 149 | { |
Jacob Erlbeck | a3a567e | 2015-12-28 13:46:32 +0100 | [diff] [blame] | 150 | gprs_rlc_dl_window dl_win; |
Holger Hans Peter Freyther | faf3ef4 | 2013-11-24 22:17:40 +0100 | [diff] [blame] | 151 | OSMO_ASSERT(dl_win.window_empty()); |
| 152 | OSMO_ASSERT(!dl_win.window_stalled()); |
| 153 | OSMO_ASSERT(dl_win.distance() == 0); |
| 154 | |
| 155 | dl_win.increment_send(); |
| 156 | OSMO_ASSERT(!dl_win.window_empty()); |
| 157 | OSMO_ASSERT(!dl_win.window_stalled()); |
| 158 | OSMO_ASSERT(dl_win.distance() == 1); |
| 159 | |
| 160 | for (int i = 1; i < 64; ++i) { |
| 161 | dl_win.increment_send(); |
| 162 | OSMO_ASSERT(!dl_win.window_empty()); |
| 163 | OSMO_ASSERT(dl_win.distance() == i + 1); |
| 164 | } |
| 165 | |
| 166 | OSMO_ASSERT(dl_win.distance() == 64); |
| 167 | OSMO_ASSERT(dl_win.window_stalled()); |
| 168 | |
| 169 | dl_win.raise(1); |
| 170 | OSMO_ASSERT(dl_win.distance() == 63); |
| 171 | OSMO_ASSERT(!dl_win.window_stalled()); |
| 172 | for (int i = 62; i >= 0; --i) { |
| 173 | dl_win.raise(1); |
| 174 | OSMO_ASSERT(dl_win.distance() == i); |
| 175 | } |
| 176 | |
| 177 | OSMO_ASSERT(dl_win.distance() == 0); |
| 178 | OSMO_ASSERT(dl_win.window_empty()); |
| 179 | |
| 180 | dl_win.increment_send(); |
| 181 | dl_win.increment_send(); |
| 182 | dl_win.increment_send(); |
| 183 | dl_win.increment_send(); |
| 184 | OSMO_ASSERT(dl_win.distance() == 4); |
| 185 | |
| 186 | for (int i = 0; i < 128; ++i) { |
| 187 | dl_win.increment_send(); |
| 188 | dl_win.increment_send(); |
| 189 | dl_win.raise(2); |
| 190 | OSMO_ASSERT(dl_win.distance() == 4); |
| 191 | } |
| 192 | } |
Holger Hans Peter Freyther | 11f2d58 | 2013-11-26 23:32:49 +0100 | [diff] [blame] | 193 | |
| 194 | { |
Jacob Erlbeck | a3a567e | 2015-12-28 13:46:32 +0100 | [diff] [blame] | 195 | gprs_rlc_ul_window ul_win; |
Holger Hans Peter Freyther | 11f2d58 | 2013-11-26 23:32:49 +0100 | [diff] [blame] | 196 | int count; |
Daniel Willmann | f86fb7a | 2013-11-27 17:56:02 +0100 | [diff] [blame] | 197 | const char *rbb; |
Daniel Willmann | c3f4330 | 2013-12-11 16:47:19 +0100 | [diff] [blame] | 198 | char win_rbb[65]; |
Daniel Willmann | 0f2b5fc | 2013-12-11 16:49:43 +0100 | [diff] [blame] | 199 | uint8_t bin_rbb[8]; |
Daniel Willmann | c3f4330 | 2013-12-11 16:47:19 +0100 | [diff] [blame] | 200 | win_rbb[64] = '\0'; |
Holger Hans Peter Freyther | 11f2d58 | 2013-11-26 23:32:49 +0100 | [diff] [blame] | 201 | |
Daniel Willmann | 7c3751b | 2013-12-28 13:59:24 +0100 | [diff] [blame] | 202 | ul_win.m_v_n.reset(); |
Holger Hans Peter Freyther | 11f2d58 | 2013-11-26 23:32:49 +0100 | [diff] [blame] | 203 | |
| 204 | OSMO_ASSERT(ul_win.is_in_window(0)); |
| 205 | OSMO_ASSERT(ul_win.is_in_window(63)); |
| 206 | OSMO_ASSERT(!ul_win.is_in_window(64)); |
| 207 | |
Daniel Willmann | 7c3751b | 2013-12-28 13:59:24 +0100 | [diff] [blame] | 208 | OSMO_ASSERT(!ul_win.m_v_n.is_received(0)); |
Holger Hans Peter Freyther | 11f2d58 | 2013-11-26 23:32:49 +0100 | [diff] [blame] | 209 | |
Daniel Willmann | f86fb7a | 2013-11-27 17:56:02 +0100 | [diff] [blame] | 210 | rbb = "IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII"; |
| 211 | OSMO_ASSERT(ul_win.ssn() == 0); |
Daniel Willmann | 7c3751b | 2013-12-28 13:59:24 +0100 | [diff] [blame] | 212 | ul_win.update_rbb(win_rbb); |
Daniel Willmann | c3f4330 | 2013-12-11 16:47:19 +0100 | [diff] [blame] | 213 | OSMO_ASSERT_STR_EQ(win_rbb, rbb); |
Daniel Willmann | 0f2b5fc | 2013-12-11 16:49:43 +0100 | [diff] [blame] | 214 | Encoding::encode_rbb(win_rbb, bin_rbb); |
| 215 | printf("rbb: %s\n", osmo_hexdump(bin_rbb, sizeof(bin_rbb))); |
Daniel Willmann | f1786a3 | 2013-12-11 18:44:49 +0100 | [diff] [blame] | 216 | Decoding::extract_rbb(bin_rbb, win_rbb); |
| 217 | OSMO_ASSERT_STR_EQ(win_rbb, rbb); |
Daniel Willmann | f86fb7a | 2013-11-27 17:56:02 +0100 | [diff] [blame] | 218 | |
Holger Hans Peter Freyther | 11f2d58 | 2013-11-26 23:32:49 +0100 | [diff] [blame] | 219 | /* simulate to have received 0, 1 and 5 */ |
| 220 | OSMO_ASSERT(ul_win.is_in_window(0)); |
Jacob Erlbeck | d87e1d6 | 2015-12-14 11:43:04 +0100 | [diff] [blame] | 221 | ul_win.receive_bsn(0); |
| 222 | count = ul_win.raise_v_q(); |
Daniel Willmann | 7c3751b | 2013-12-28 13:59:24 +0100 | [diff] [blame] | 223 | OSMO_ASSERT(ul_win.m_v_n.is_received(0)); |
Holger Hans Peter Freyther | 11f2d58 | 2013-11-26 23:32:49 +0100 | [diff] [blame] | 224 | OSMO_ASSERT(ul_win.v_q() == 1); |
| 225 | OSMO_ASSERT(ul_win.v_r() == 1); |
| 226 | OSMO_ASSERT(count == 1); |
| 227 | |
Daniel Willmann | f86fb7a | 2013-11-27 17:56:02 +0100 | [diff] [blame] | 228 | rbb = "IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIR"; |
| 229 | OSMO_ASSERT(ul_win.ssn() == 1); |
Daniel Willmann | 7c3751b | 2013-12-28 13:59:24 +0100 | [diff] [blame] | 230 | ul_win.update_rbb(win_rbb); |
Daniel Willmann | c3f4330 | 2013-12-11 16:47:19 +0100 | [diff] [blame] | 231 | OSMO_ASSERT_STR_EQ(win_rbb, rbb); |
Daniel Willmann | 0f2b5fc | 2013-12-11 16:49:43 +0100 | [diff] [blame] | 232 | Encoding::encode_rbb(win_rbb, bin_rbb); |
| 233 | printf("rbb: %s\n", osmo_hexdump(bin_rbb, sizeof(bin_rbb))); |
Daniel Willmann | f1786a3 | 2013-12-11 18:44:49 +0100 | [diff] [blame] | 234 | Decoding::extract_rbb(bin_rbb, win_rbb); |
| 235 | OSMO_ASSERT_STR_EQ(win_rbb, rbb); |
Daniel Willmann | f86fb7a | 2013-11-27 17:56:02 +0100 | [diff] [blame] | 236 | |
Holger Hans Peter Freyther | 11f2d58 | 2013-11-26 23:32:49 +0100 | [diff] [blame] | 237 | OSMO_ASSERT(ul_win.is_in_window(1)); |
Jacob Erlbeck | d87e1d6 | 2015-12-14 11:43:04 +0100 | [diff] [blame] | 238 | ul_win.receive_bsn(1); |
| 239 | count = ul_win.raise_v_q(); |
Daniel Willmann | 7c3751b | 2013-12-28 13:59:24 +0100 | [diff] [blame] | 240 | OSMO_ASSERT(ul_win.m_v_n.is_received(0)); |
Holger Hans Peter Freyther | 11f2d58 | 2013-11-26 23:32:49 +0100 | [diff] [blame] | 241 | OSMO_ASSERT(ul_win.v_q() == 2); |
| 242 | OSMO_ASSERT(ul_win.v_r() == 2); |
| 243 | OSMO_ASSERT(count == 1); |
| 244 | |
Daniel Willmann | f86fb7a | 2013-11-27 17:56:02 +0100 | [diff] [blame] | 245 | rbb = "IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIRR"; |
| 246 | OSMO_ASSERT(ul_win.ssn() == 2); |
Daniel Willmann | 7c3751b | 2013-12-28 13:59:24 +0100 | [diff] [blame] | 247 | ul_win.update_rbb(win_rbb); |
Daniel Willmann | c3f4330 | 2013-12-11 16:47:19 +0100 | [diff] [blame] | 248 | OSMO_ASSERT_STR_EQ(win_rbb, rbb); |
Daniel Willmann | 0f2b5fc | 2013-12-11 16:49:43 +0100 | [diff] [blame] | 249 | Encoding::encode_rbb(win_rbb, bin_rbb); |
| 250 | printf("rbb: %s\n", osmo_hexdump(bin_rbb, sizeof(bin_rbb))); |
Daniel Willmann | f1786a3 | 2013-12-11 18:44:49 +0100 | [diff] [blame] | 251 | Decoding::extract_rbb(bin_rbb, win_rbb); |
| 252 | OSMO_ASSERT_STR_EQ(win_rbb, rbb); |
Daniel Willmann | f86fb7a | 2013-11-27 17:56:02 +0100 | [diff] [blame] | 253 | |
Holger Hans Peter Freyther | 11f2d58 | 2013-11-26 23:32:49 +0100 | [diff] [blame] | 254 | OSMO_ASSERT(ul_win.is_in_window(5)); |
Jacob Erlbeck | d87e1d6 | 2015-12-14 11:43:04 +0100 | [diff] [blame] | 255 | ul_win.receive_bsn(5); |
| 256 | count = ul_win.raise_v_q(); |
Daniel Willmann | 7c3751b | 2013-12-28 13:59:24 +0100 | [diff] [blame] | 257 | OSMO_ASSERT(ul_win.m_v_n.is_received(0)); |
Holger Hans Peter Freyther | 11f2d58 | 2013-11-26 23:32:49 +0100 | [diff] [blame] | 258 | OSMO_ASSERT(ul_win.v_q() == 2); |
| 259 | OSMO_ASSERT(ul_win.v_r() == 6); |
| 260 | OSMO_ASSERT(count == 0); |
| 261 | |
Daniel Willmann | f86fb7a | 2013-11-27 17:56:02 +0100 | [diff] [blame] | 262 | rbb = "IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIRRIIIR"; |
| 263 | OSMO_ASSERT(ul_win.ssn() == 6); |
Daniel Willmann | 7c3751b | 2013-12-28 13:59:24 +0100 | [diff] [blame] | 264 | ul_win.update_rbb(win_rbb); |
Daniel Willmann | c3f4330 | 2013-12-11 16:47:19 +0100 | [diff] [blame] | 265 | OSMO_ASSERT_STR_EQ(win_rbb, rbb); |
Daniel Willmann | 0f2b5fc | 2013-12-11 16:49:43 +0100 | [diff] [blame] | 266 | Encoding::encode_rbb(win_rbb, bin_rbb); |
| 267 | printf("rbb: %s\n", osmo_hexdump(bin_rbb, sizeof(bin_rbb))); |
Daniel Willmann | f1786a3 | 2013-12-11 18:44:49 +0100 | [diff] [blame] | 268 | Decoding::extract_rbb(bin_rbb, win_rbb); |
| 269 | OSMO_ASSERT_STR_EQ(win_rbb, rbb); |
Daniel Willmann | f86fb7a | 2013-11-27 17:56:02 +0100 | [diff] [blame] | 270 | |
Holger Hans Peter Freyther | 11f2d58 | 2013-11-26 23:32:49 +0100 | [diff] [blame] | 271 | OSMO_ASSERT(ul_win.is_in_window(65)); |
| 272 | OSMO_ASSERT(ul_win.is_in_window(2)); |
Daniel Willmann | 7c3751b | 2013-12-28 13:59:24 +0100 | [diff] [blame] | 273 | OSMO_ASSERT(ul_win.m_v_n.is_received(5)); |
Jacob Erlbeck | d87e1d6 | 2015-12-14 11:43:04 +0100 | [diff] [blame] | 274 | ul_win.receive_bsn(65); |
| 275 | count = ul_win.raise_v_q(); |
Holger Hans Peter Freyther | 11f2d58 | 2013-11-26 23:32:49 +0100 | [diff] [blame] | 276 | OSMO_ASSERT(count == 0); |
Daniel Willmann | 7c3751b | 2013-12-28 13:59:24 +0100 | [diff] [blame] | 277 | OSMO_ASSERT(ul_win.m_v_n.is_received(5)); |
Holger Hans Peter Freyther | 11f2d58 | 2013-11-26 23:32:49 +0100 | [diff] [blame] | 278 | OSMO_ASSERT(ul_win.v_q() == 2); |
| 279 | OSMO_ASSERT(ul_win.v_r() == 66); |
| 280 | |
Daniel Willmann | f86fb7a | 2013-11-27 17:56:02 +0100 | [diff] [blame] | 281 | rbb = "IIIRIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIR"; |
| 282 | OSMO_ASSERT(ul_win.ssn() == 66); |
Daniel Willmann | 7c3751b | 2013-12-28 13:59:24 +0100 | [diff] [blame] | 283 | ul_win.update_rbb(win_rbb); |
Daniel Willmann | c3f4330 | 2013-12-11 16:47:19 +0100 | [diff] [blame] | 284 | OSMO_ASSERT_STR_EQ(win_rbb, rbb); |
Daniel Willmann | 0f2b5fc | 2013-12-11 16:49:43 +0100 | [diff] [blame] | 285 | Encoding::encode_rbb(win_rbb, bin_rbb); |
| 286 | printf("rbb: %s\n", osmo_hexdump(bin_rbb, sizeof(bin_rbb))); |
Daniel Willmann | f1786a3 | 2013-12-11 18:44:49 +0100 | [diff] [blame] | 287 | Decoding::extract_rbb(bin_rbb, win_rbb); |
| 288 | OSMO_ASSERT_STR_EQ(win_rbb, rbb); |
Daniel Willmann | f86fb7a | 2013-11-27 17:56:02 +0100 | [diff] [blame] | 289 | |
Holger Hans Peter Freyther | 11f2d58 | 2013-11-26 23:32:49 +0100 | [diff] [blame] | 290 | OSMO_ASSERT(ul_win.is_in_window(2)); |
| 291 | OSMO_ASSERT(!ul_win.is_in_window(66)); |
Jacob Erlbeck | d87e1d6 | 2015-12-14 11:43:04 +0100 | [diff] [blame] | 292 | ul_win.receive_bsn(2); |
| 293 | count = ul_win.raise_v_q(); |
Holger Hans Peter Freyther | 11f2d58 | 2013-11-26 23:32:49 +0100 | [diff] [blame] | 294 | OSMO_ASSERT(count == 1); |
| 295 | OSMO_ASSERT(ul_win.v_q() == 3); |
| 296 | OSMO_ASSERT(ul_win.v_r() == 66); |
| 297 | |
| 298 | OSMO_ASSERT(ul_win.is_in_window(66)); |
Jacob Erlbeck | d87e1d6 | 2015-12-14 11:43:04 +0100 | [diff] [blame] | 299 | ul_win.receive_bsn(66); |
| 300 | count = ul_win.raise_v_q(); |
Holger Hans Peter Freyther | 11f2d58 | 2013-11-26 23:32:49 +0100 | [diff] [blame] | 301 | OSMO_ASSERT(count == 0); |
| 302 | OSMO_ASSERT(ul_win.v_q() == 3); |
| 303 | OSMO_ASSERT(ul_win.v_r() == 67); |
| 304 | |
| 305 | for (int i = 3; i <= 67; ++i) { |
Daniel Willmann | 5584479 | 2013-12-28 14:41:00 +0100 | [diff] [blame] | 306 | ul_win.receive_bsn(i); |
Jacob Erlbeck | d87e1d6 | 2015-12-14 11:43:04 +0100 | [diff] [blame] | 307 | ul_win.raise_v_q(); |
Holger Hans Peter Freyther | 11f2d58 | 2013-11-26 23:32:49 +0100 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | OSMO_ASSERT(ul_win.v_q() == 68); |
| 311 | OSMO_ASSERT(ul_win.v_r() == 68); |
| 312 | |
Jacob Erlbeck | d87e1d6 | 2015-12-14 11:43:04 +0100 | [diff] [blame] | 313 | ul_win.receive_bsn(68); |
| 314 | count = ul_win.raise_v_q(); |
Holger Hans Peter Freyther | 11f2d58 | 2013-11-26 23:32:49 +0100 | [diff] [blame] | 315 | OSMO_ASSERT(ul_win.v_q() == 69); |
| 316 | OSMO_ASSERT(ul_win.v_r() == 69); |
| 317 | OSMO_ASSERT(count == 1); |
| 318 | |
| 319 | /* now test the wrapping */ |
| 320 | OSMO_ASSERT(ul_win.is_in_window(4)); |
| 321 | OSMO_ASSERT(!ul_win.is_in_window(5)); |
Jacob Erlbeck | d87e1d6 | 2015-12-14 11:43:04 +0100 | [diff] [blame] | 322 | ul_win.receive_bsn(4); |
| 323 | count = ul_win.raise_v_q(); |
Holger Hans Peter Freyther | 11f2d58 | 2013-11-26 23:32:49 +0100 | [diff] [blame] | 324 | OSMO_ASSERT(count == 0); |
Aravind Sirsikar | a35c911 | 2016-08-30 13:00:14 +0530 | [diff] [blame] | 325 | |
| 326 | /* |
| 327 | * SSN wrap around case |
Aravind Sirsikar | 7c7a86c | 2016-08-30 13:08:28 +0530 | [diff] [blame] | 328 | * Should not expect any BSN as nacked. |
Aravind Sirsikar | a35c911 | 2016-08-30 13:00:14 +0530 | [diff] [blame] | 329 | */ |
Aravind Sirsikar | 7c7a86c | 2016-08-30 13:08:28 +0530 | [diff] [blame] | 330 | rbb = "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR"; |
Aravind Sirsikar | a35c911 | 2016-08-30 13:00:14 +0530 | [diff] [blame] | 331 | for (int i = 0; i < 128; ++i) { |
| 332 | ul_win.receive_bsn(i); |
| 333 | ul_win.raise_v_q(); |
| 334 | } |
| 335 | ul_win.receive_bsn(0); |
| 336 | ul_win.raise_v_q(); |
| 337 | ul_win.receive_bsn(1); |
| 338 | ul_win.raise_v_q(); |
| 339 | ul_win.update_rbb(win_rbb); |
| 340 | OSMO_ASSERT_STR_EQ(win_rbb, rbb); |
| 341 | OSMO_ASSERT(ul_win.ssn() == 2); |
Holger Hans Peter Freyther | 11f2d58 | 2013-11-26 23:32:49 +0100 | [diff] [blame] | 342 | } |
Daniel Willmann | 48df40d | 2013-12-11 16:51:26 +0100 | [diff] [blame] | 343 | |
| 344 | { |
Daniel Willmann | 48df40d | 2013-12-11 16:51:26 +0100 | [diff] [blame] | 345 | uint16_t lost = 0, recv = 0; |
| 346 | char show_rbb[65]; |
Jacob Erlbeck | 419b034 | 2016-01-14 13:40:01 +0100 | [diff] [blame] | 347 | uint8_t bits_data[8]; |
Daniel Willmann | 48df40d | 2013-12-11 16:51:26 +0100 | [diff] [blame] | 348 | BTS dummy_bts; |
Jacob Erlbeck | a3a567e | 2015-12-28 13:46:32 +0100 | [diff] [blame] | 349 | gprs_rlc_dl_window dl_win; |
Jacob Erlbeck | 419b034 | 2016-01-14 13:40:01 +0100 | [diff] [blame] | 350 | bitvec bits; |
| 351 | int bsn_begin, bsn_end, num_blocks; |
| 352 | Ack_Nack_Description_t desc; |
Daniel Willmann | 48df40d | 2013-12-11 16:51:26 +0100 | [diff] [blame] | 353 | |
Daniel Willmann | 146514e | 2013-12-28 18:24:42 +0100 | [diff] [blame] | 354 | dl_win.m_v_b.reset(); |
Daniel Willmann | 48df40d | 2013-12-11 16:51:26 +0100 | [diff] [blame] | 355 | |
| 356 | OSMO_ASSERT(dl_win.window_empty()); |
| 357 | OSMO_ASSERT(!dl_win.window_stalled()); |
| 358 | OSMO_ASSERT(dl_win.distance() == 0); |
| 359 | |
| 360 | dl_win.increment_send(); |
| 361 | OSMO_ASSERT(!dl_win.window_empty()); |
| 362 | OSMO_ASSERT(!dl_win.window_stalled()); |
| 363 | OSMO_ASSERT(dl_win.distance() == 1); |
| 364 | |
| 365 | for (int i = 0; i < 35; ++i) { |
| 366 | dl_win.increment_send(); |
| 367 | OSMO_ASSERT(!dl_win.window_empty()); |
| 368 | OSMO_ASSERT(dl_win.distance() == i + 2); |
| 369 | } |
| 370 | |
| 371 | uint8_t rbb_cmp[8] = { 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff }; |
Jacob Erlbeck | 419b034 | 2016-01-14 13:40:01 +0100 | [diff] [blame] | 372 | bits.data = bits_data; |
| 373 | bits.data_len = sizeof(bits_data); |
| 374 | bits.cur_bit = 0; |
| 375 | |
| 376 | memcpy(desc.RECEIVED_BLOCK_BITMAP, rbb_cmp, |
| 377 | sizeof(desc.RECEIVED_BLOCK_BITMAP)); |
| 378 | desc.FINAL_ACK_INDICATION = 0; |
| 379 | desc.STARTING_SEQUENCE_NUMBER = 35; |
| 380 | |
| 381 | num_blocks = Decoding::decode_gprs_acknack_bits( |
| 382 | &desc, &bits, |
| 383 | &bsn_begin, &bsn_end, &dl_win); |
| 384 | Decoding::extract_rbb(&bits, show_rbb); |
Daniel Willmann | 48df40d | 2013-12-11 16:51:26 +0100 | [diff] [blame] | 385 | printf("show_rbb: %s\n", show_rbb); |
| 386 | |
Jacob Erlbeck | 419b034 | 2016-01-14 13:40:01 +0100 | [diff] [blame] | 387 | dl_win.update(&dummy_bts, &bits, 0, &lost, &recv); |
Daniel Willmann | 48df40d | 2013-12-11 16:51:26 +0100 | [diff] [blame] | 388 | OSMO_ASSERT(lost == 0); |
| 389 | OSMO_ASSERT(recv == 35); |
Jacob Erlbeck | 419b034 | 2016-01-14 13:40:01 +0100 | [diff] [blame] | 390 | OSMO_ASSERT(bsn_begin == 0); |
| 391 | OSMO_ASSERT(bsn_end == 35); |
| 392 | OSMO_ASSERT(num_blocks == 35); |
Daniel Willmann | 48df40d | 2013-12-11 16:51:26 +0100 | [diff] [blame] | 393 | |
Jacob Erlbeck | 419b034 | 2016-01-14 13:40:01 +0100 | [diff] [blame] | 394 | dl_win.raise(dl_win.move_window()); |
| 395 | |
| 396 | for (int i = 0; i < 8; ++i) { |
| 397 | dl_win.increment_send(); |
| 398 | OSMO_ASSERT(!dl_win.window_empty()); |
| 399 | OSMO_ASSERT(dl_win.distance() == 2 + i); |
| 400 | } |
| 401 | |
| 402 | uint8_t rbb_cmp2[8] = { 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0x31 }; |
| 403 | bits.data = bits_data; |
| 404 | bits.data_len = sizeof(bits_data); |
| 405 | bits.cur_bit = 0; |
| 406 | |
| 407 | memcpy(desc.RECEIVED_BLOCK_BITMAP, rbb_cmp2, |
| 408 | sizeof(desc.RECEIVED_BLOCK_BITMAP)); |
| 409 | desc.FINAL_ACK_INDICATION = 0; |
| 410 | desc.STARTING_SEQUENCE_NUMBER = 35 + 8; |
| 411 | |
| 412 | num_blocks = Decoding::decode_gprs_acknack_bits( |
| 413 | &desc, &bits, |
| 414 | &bsn_begin, &bsn_end, &dl_win); |
| 415 | Decoding::extract_rbb(&bits, show_rbb); |
| 416 | printf("show_rbb: %s\n", show_rbb); |
| 417 | |
| 418 | lost = recv = 0; |
| 419 | dl_win.update(&dummy_bts, &bits, 0, &lost, &recv); |
| 420 | OSMO_ASSERT(lost == 5); |
| 421 | OSMO_ASSERT(recv == 3); |
| 422 | OSMO_ASSERT(bitvec_get_bit_pos(&bits, 0) == 0); |
| 423 | OSMO_ASSERT(bitvec_get_bit_pos(&bits, 7) == 1); |
| 424 | OSMO_ASSERT(bsn_begin == 35); |
| 425 | OSMO_ASSERT(bsn_end == 43); |
| 426 | OSMO_ASSERT(num_blocks == 8); |
Daniel Willmann | 48df40d | 2013-12-11 16:51:26 +0100 | [diff] [blame] | 427 | } |
Holger Hans Peter Freyther | faf3ef4 | 2013-11-24 22:17:40 +0100 | [diff] [blame] | 428 | } |
| 429 | |
aravind sirsikar | c0c3afd | 2016-11-09 16:27:00 +0530 | [diff] [blame] | 430 | void test_immediate_assign_rej() |
| 431 | { |
| 432 | uint8_t plen; |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 433 | bitvec *immediate_assignment_rej = bitvec_alloc(22, tall_pcu_ctx); |
aravind sirsikar | c0c3afd | 2016-11-09 16:27:00 +0530 | [diff] [blame] | 434 | |
| 435 | bitvec_unhex(immediate_assignment_rej, |
| 436 | "2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b"); |
| 437 | plen = Encoding::write_immediate_assignment_reject( |
| 438 | immediate_assignment_rej, 112, 100, |
| 439 | GSM_L1_BURST_TYPE_ACCESS_1); |
| 440 | |
| 441 | printf("assignment reject: %s\n", |
| 442 | osmo_hexdump(immediate_assignment_rej->data, 22)); |
| 443 | |
| 444 | OSMO_ASSERT(plen == 19); |
| 445 | /* RA value */ |
| 446 | OSMO_ASSERT(immediate_assignment_rej->data[3] == 0x7f); |
| 447 | /* Extended RA value */ |
| 448 | OSMO_ASSERT(immediate_assignment_rej->data[19] == 0xc0); |
| 449 | |
| 450 | bitvec_unhex(immediate_assignment_rej, |
| 451 | "2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b"); |
| 452 | |
| 453 | plen = Encoding::write_immediate_assignment_reject( |
| 454 | immediate_assignment_rej, 112, 100, |
| 455 | GSM_L1_BURST_TYPE_ACCESS_0); |
| 456 | |
| 457 | printf("assignment reject: %s\n", |
| 458 | osmo_hexdump(immediate_assignment_rej->data, 22)); |
| 459 | |
| 460 | OSMO_ASSERT(plen == 19); |
| 461 | /* RA value */ |
| 462 | OSMO_ASSERT(immediate_assignment_rej->data[3] == 0x70); |
| 463 | |
| 464 | } |
| 465 | |
Holger Hans Peter Freyther | 6058220 | 2013-11-21 21:30:23 +0100 | [diff] [blame] | 466 | int main(int argc, char **argv) |
| 467 | { |
Holger Hans Peter Freyther | 11f2d58 | 2013-11-26 23:32:49 +0100 | [diff] [blame] | 468 | osmo_init_logging(&gprs_log_info); |
| 469 | log_set_use_color(osmo_stderr_target, 0); |
| 470 | log_set_print_filename(osmo_stderr_target, 0); |
| 471 | |
Holger Hans Peter Freyther | 6058220 | 2013-11-21 21:30:23 +0100 | [diff] [blame] | 472 | printf("Making some basic type testing.\n"); |
| 473 | test_llc(); |
Holger Hans Peter Freyther | c6382dd | 2013-11-21 21:42:20 +0100 | [diff] [blame] | 474 | test_rlc(); |
Holger Hans Peter Freyther | 9525567 | 2013-11-23 16:18:18 +0100 | [diff] [blame] | 475 | test_rlc_v_b(); |
Holger Hans Peter Freyther | e9b1ebb | 2013-11-24 22:00:43 +0100 | [diff] [blame] | 476 | test_rlc_v_n(); |
Holger Hans Peter Freyther | faf3ef4 | 2013-11-24 22:17:40 +0100 | [diff] [blame] | 477 | test_rlc_dl_ul_basic(); |
aravind sirsikar | c0c3afd | 2016-11-09 16:27:00 +0530 | [diff] [blame] | 478 | test_immediate_assign_rej(); |
Holger Hans Peter Freyther | 6058220 | 2013-11-21 21:30:23 +0100 | [diff] [blame] | 479 | return EXIT_SUCCESS; |
| 480 | } |
| 481 | |
| 482 | /* |
| 483 | * stubs that should not be reached |
| 484 | */ |
| 485 | extern "C" { |
| 486 | void l1if_pdch_req() { abort(); } |
| 487 | void l1if_connect_pdch() { abort(); } |
| 488 | void l1if_close_pdch() { abort(); } |
| 489 | void l1if_open_pdch() { abort(); } |
| 490 | } |