Holger Hans Peter Freyther | 68c6f88 | 2014-09-30 09:10:25 +0200 | [diff] [blame] | 1 | /* Test the SGSN */ |
| 2 | /* |
| 3 | * (C) 2014 by Holger Hans Peter Freyther |
| 4 | * (C) 2014 by sysmocom s.f.m.c. GmbH |
| 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU Affero General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU Affero General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Affero General Public License |
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | * |
| 20 | */ |
| 21 | |
Holger Hans Peter Freyther | 4299c05 | 2014-10-02 21:27:24 +0200 | [diff] [blame^] | 22 | #include <openbsc/gprs_llc.h> |
| 23 | #include <openbsc/sgsn.h> |
| 24 | #include <openbsc/debug.h> |
| 25 | |
| 26 | #include <osmocom/gsm/gsm_utils.h> |
| 27 | |
| 28 | #include <osmocom/core/application.h> |
| 29 | #include <osmocom/core/msgb.h> |
| 30 | |
Holger Hans Peter Freyther | 68c6f88 | 2014-09-30 09:10:25 +0200 | [diff] [blame] | 31 | #include <stdio.h> |
| 32 | |
Holger Hans Peter Freyther | 4299c05 | 2014-10-02 21:27:24 +0200 | [diff] [blame^] | 33 | extern void *tall_msgb_ctx; |
| 34 | |
| 35 | void *tall_bsc_ctx; |
| 36 | static struct sgsn_instance sgsn_inst = { |
| 37 | .config_file = "osmo_sgsn.cfg", |
| 38 | .cfg = { |
| 39 | .gtp_statedir = "./", |
| 40 | .acl_enabled = 1, |
| 41 | }, |
| 42 | }; |
| 43 | struct sgsn_instance *sgsn = &sgsn_inst; |
| 44 | |
| 45 | static int count(struct llist_head *head) |
| 46 | { |
| 47 | struct llist_head *cur; |
| 48 | int count = 0; |
| 49 | |
| 50 | llist_for_each(cur, head) |
| 51 | count += 1; |
| 52 | |
| 53 | return count; |
| 54 | } |
| 55 | |
| 56 | static void test_llme(void) |
| 57 | { |
| 58 | struct gprs_llc_lle *lle, *lle_copy; |
| 59 | uint32_t local_tlli; |
| 60 | uint32_t foreign_tlli; |
| 61 | |
| 62 | printf("Testing LLME allocations\n"); |
| 63 | local_tlli = gprs_tmsi2tlli(0x234, TLLI_LOCAL); |
| 64 | foreign_tlli = gprs_tmsi2tlli(0x234, TLLI_FOREIGN); |
| 65 | |
| 66 | /* initial state */ |
| 67 | OSMO_ASSERT(count(gprs_llme_list()) == 0); |
| 68 | |
| 69 | /* Create a new entry */ |
| 70 | lle = gprs_lle_get_or_create(local_tlli, 3); |
| 71 | OSMO_ASSERT(lle); |
| 72 | OSMO_ASSERT(count(gprs_llme_list()) == 1); |
| 73 | |
| 74 | /* No new entry is created */ |
| 75 | lle_copy = gprs_lle_get_or_create(local_tlli, 3); |
| 76 | OSMO_ASSERT(lle == lle_copy); |
| 77 | OSMO_ASSERT(count(gprs_llme_list()) == 1); |
| 78 | lle_copy = gprs_lle_get_or_create(foreign_tlli, 3); |
| 79 | OSMO_ASSERT(lle == lle_copy); |
| 80 | OSMO_ASSERT(count(gprs_llme_list()) == 1); |
| 81 | |
| 82 | /* unassign which should delete it*/ |
| 83 | gprs_llgmm_assign(lle->llme, lle->llme->tlli, 0xffffffff, GPRS_ALGO_GEA0, NULL); |
| 84 | |
| 85 | /* Check that everything was cleaned up */ |
| 86 | OSMO_ASSERT(count(gprs_llme_list()) == 0); |
| 87 | } |
| 88 | |
| 89 | |
| 90 | static struct log_info_cat gprs_categories[] = { |
| 91 | [DMM] = { |
| 92 | .name = "DMM", |
| 93 | .description = "Layer3 Mobility Management (MM)", |
| 94 | .color = "\033[1;33m", |
| 95 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 96 | }, |
| 97 | [DPAG] = { |
| 98 | .name = "DPAG", |
| 99 | .description = "Paging Subsystem", |
| 100 | .color = "\033[1;38m", |
| 101 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 102 | }, |
| 103 | [DMEAS] = { |
| 104 | .name = "DMEAS", |
| 105 | .description = "Radio Measurement Processing", |
| 106 | .enabled = 0, .loglevel = LOGL_NOTICE, |
| 107 | }, |
| 108 | [DREF] = { |
| 109 | .name = "DREF", |
| 110 | .description = "Reference Counting", |
| 111 | .enabled = 0, .loglevel = LOGL_NOTICE, |
| 112 | }, |
| 113 | [DGPRS] = { |
| 114 | .name = "DGPRS", |
| 115 | .description = "GPRS Packet Service", |
| 116 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 117 | }, |
| 118 | [DNS] = { |
| 119 | .name = "DNS", |
| 120 | .description = "GPRS Network Service (NS)", |
| 121 | .enabled = 1, .loglevel = LOGL_INFO, |
| 122 | }, |
| 123 | [DBSSGP] = { |
| 124 | .name = "DBSSGP", |
| 125 | .description = "GPRS BSS Gateway Protocol (BSSGP)", |
| 126 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 127 | }, |
| 128 | [DLLC] = { |
| 129 | .name = "DLLC", |
| 130 | .description = "GPRS Logical Link Control Protocol (LLC)", |
| 131 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 132 | }, |
| 133 | [DSNDCP] = { |
| 134 | .name = "DSNDCP", |
| 135 | .description = "GPRS Sub-Network Dependent Control Protocol (SNDCP)", |
| 136 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 137 | }, |
| 138 | }; |
| 139 | |
| 140 | static struct log_info info = { |
| 141 | .cat = gprs_categories, |
| 142 | .num_cat = ARRAY_SIZE(gprs_categories), |
| 143 | }; |
| 144 | |
Holger Hans Peter Freyther | 68c6f88 | 2014-09-30 09:10:25 +0200 | [diff] [blame] | 145 | int main(int argc, char **argv) |
| 146 | { |
Holger Hans Peter Freyther | 4299c05 | 2014-10-02 21:27:24 +0200 | [diff] [blame^] | 147 | osmo_init_logging(&info); |
| 148 | tall_bsc_ctx = talloc_named_const(NULL, 0, "osmo_sgsn"); |
| 149 | tall_msgb_ctx = talloc_named_const(tall_bsc_ctx, 0, "msgb"); |
| 150 | |
| 151 | test_llme(); |
| 152 | printf("Done\n"); |
Holger Hans Peter Freyther | 68c6f88 | 2014-09-30 09:10:25 +0200 | [diff] [blame] | 153 | return 0; |
| 154 | } |
Holger Hans Peter Freyther | 4299c05 | 2014-10-02 21:27:24 +0200 | [diff] [blame^] | 155 | |
| 156 | |
| 157 | /* stubs */ |
| 158 | struct osmo_prim_hdr; |
| 159 | int bssgp_prim_cb(struct osmo_prim_hdr *oph, void *ctx) |
| 160 | { |
| 161 | abort(); |
| 162 | } |