Andreas Eversberg | 050ace2 | 2013-03-16 16:22:02 +0100 | [diff] [blame] | 1 | /* Measurements |
| 2 | * |
| 3 | * Copyright (C) 2012 Andreas Eversberg <jolly@eversberg.eu> |
| 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 | */ |
Pau Espin Pedrol | 488aa29 | 2019-09-25 17:48:35 +0200 | [diff] [blame] | 19 | |
Stefan Sperling | 78ab624 | 2018-05-31 12:28:55 +0200 | [diff] [blame] | 20 | #include <osmocom/core/timer_compat.h> |
| 21 | |
Andreas Eversberg | 050ace2 | 2013-03-16 16:22:02 +0100 | [diff] [blame] | 22 | #include <gprs_rlcmac.h> |
| 23 | #include <gprs_debug.h> |
| 24 | #include <pcu_l1_if.h> |
Holger Hans Peter Freyther | 099535a | 2013-10-16 17:42:31 +0200 | [diff] [blame] | 25 | #include <tbf.h> |
Pau Espin Pedrol | 9d1cdb1 | 2019-09-25 17:47:02 +0200 | [diff] [blame] | 26 | #include <tbf_dl.h> |
Andreas Eversberg | 050ace2 | 2013-03-16 16:22:02 +0100 | [diff] [blame] | 27 | |
| 28 | #include <string.h> |
| 29 | #include <errno.h> |
| 30 | |
| 31 | /* |
| 32 | * downlink measurement |
| 33 | */ |
Max | 5a6bcfb | 2017-09-01 14:36:44 +0200 | [diff] [blame] | 34 | /* TODO: trigger the measurement report from the pollcontroller and use it for flow control */ |
Andreas Eversberg | 050ace2 | 2013-03-16 16:22:02 +0100 | [diff] [blame] | 35 | |
| 36 | /* received Measurement Report */ |
| 37 | int gprs_rlcmac_meas_rep(Packet_Measurement_Report_t *pmr) |
| 38 | { |
| 39 | NC_Measurement_Report_t *ncr; |
| 40 | NC_Measurements_t *nc; |
| 41 | int i; |
| 42 | |
| 43 | LOGP(DRLCMACMEAS, LOGL_INFO, "Measuement Report of TLLI=0x%08x:", |
| 44 | pmr->TLLI); |
| 45 | |
| 46 | switch (pmr->UnionType) { |
| 47 | case 0: |
| 48 | ncr = &pmr->u.NC_Measurement_Report; |
| 49 | LOGPC(DRLCMACMEAS, LOGL_INFO, " NC%u Serv %d dbm", |
| 50 | ncr->NC_MODE + 1, |
| 51 | ncr->Serving_Cell_Data.RXLEV_SERVING_CELL - 110); |
| 52 | for (i = 0; i < ncr->NUMBER_OF_NC_MEASUREMENTS; i++) { |
| 53 | nc = &ncr->NC_Measurements[i]; |
| 54 | LOGPC(DRLCMACMEAS, LOGL_DEBUG, ", Neigh %u %d dbm", |
| 55 | nc->FREQUENCY_N, nc->RXLEV_N - 110); |
| 56 | } |
| 57 | LOGPC(DRLCMACMEAS, LOGL_INFO, "\n"); |
| 58 | |
| 59 | break; |
| 60 | case 1: |
| 61 | LOGPC(DRLCMACMEAS, LOGL_INFO, |
| 62 | " <EXT Reporting not supported!>\n"); |
| 63 | break; |
| 64 | } |
| 65 | |
| 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | |
| 70 | /* |
| 71 | * uplink measurement |
| 72 | */ |
| 73 | |
| 74 | /* RSSI values received from MS */ |
| 75 | int gprs_rlcmac_rssi(struct gprs_rlcmac_tbf *tbf, int8_t rssi) |
| 76 | { |
Stefan Sperling | f0f7df1 | 2018-05-25 15:12:30 +0200 | [diff] [blame] | 77 | struct timespec now_tv, *rssi_tv = &tbf->meas.rssi_tv; |
Stefan Sperling | 78ab624 | 2018-05-31 12:28:55 +0200 | [diff] [blame] | 78 | struct timespec elapsed; |
Andreas Eversberg | 050ace2 | 2013-03-16 16:22:02 +0100 | [diff] [blame] | 79 | |
| 80 | tbf->meas.rssi_sum += rssi; |
| 81 | tbf->meas.rssi_num++; |
| 82 | |
Stefan Sperling | f0f7df1 | 2018-05-25 15:12:30 +0200 | [diff] [blame] | 83 | osmo_clock_gettime(CLOCK_MONOTONIC, &now_tv); |
Stefan Sperling | 78ab624 | 2018-05-31 12:28:55 +0200 | [diff] [blame] | 84 | |
| 85 | timespecsub(&now_tv, rssi_tv, &elapsed); |
| 86 | if (elapsed.tv_sec < 1) |
Andreas Eversberg | 050ace2 | 2013-03-16 16:22:02 +0100 | [diff] [blame] | 87 | return 0; |
| 88 | |
| 89 | gprs_rlcmac_rssi_rep(tbf); |
| 90 | |
| 91 | /* reset rssi values and timestamp */ |
Stefan Sperling | f0f7df1 | 2018-05-25 15:12:30 +0200 | [diff] [blame] | 92 | memcpy(rssi_tv, &now_tv, sizeof(*rssi_tv)); |
Andreas Eversberg | 050ace2 | 2013-03-16 16:22:02 +0100 | [diff] [blame] | 93 | tbf->meas.rssi_sum = 0; |
| 94 | tbf->meas.rssi_num = 0; |
| 95 | |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | /* Give RSSI report */ |
| 100 | int gprs_rlcmac_rssi_rep(struct gprs_rlcmac_tbf *tbf) |
| 101 | { |
| 102 | /* No measurement values */ |
| 103 | if (!tbf->meas.rssi_num) |
| 104 | return -EINVAL; |
| 105 | |
| 106 | LOGP(DRLCMACMEAS, LOGL_INFO, "UL RSSI of TLLI=0x%08x: %d dBm\n", |
Holger Hans Peter Freyther | 474685e | 2013-10-27 17:01:14 +0100 | [diff] [blame] | 107 | tbf->tlli(), tbf->meas.rssi_sum / tbf->meas.rssi_num); |
Andreas Eversberg | 050ace2 | 2013-03-16 16:22:02 +0100 | [diff] [blame] | 108 | |
| 109 | return 0; |
| 110 | } |
| 111 | |
| 112 | |
| 113 | /* |
| 114 | * lost frames |
| 115 | */ |
| 116 | |
| 117 | /* Lost frames reported from RLCMAC layer */ |
Daniel Willmann | 418a423 | 2014-08-08 11:21:04 +0200 | [diff] [blame] | 118 | int gprs_rlcmac_received_lost(struct gprs_rlcmac_dl_tbf *tbf, uint16_t received, |
Andreas Eversberg | 050ace2 | 2013-03-16 16:22:02 +0100 | [diff] [blame] | 119 | uint16_t lost) |
| 120 | { |
Stefan Sperling | f0f7df1 | 2018-05-25 15:12:30 +0200 | [diff] [blame] | 121 | struct timespec now_tv, *loss_tv = &tbf->m_bw.dl_loss_tv; |
Stefan Sperling | 78ab624 | 2018-05-31 12:28:55 +0200 | [diff] [blame] | 122 | struct timespec elapsed; |
Andreas Eversberg | 050ace2 | 2013-03-16 16:22:02 +0100 | [diff] [blame] | 123 | uint16_t sum = received + lost; |
| 124 | |
| 125 | /* No measurement values */ |
| 126 | if (!sum) |
| 127 | return -EINVAL; |
| 128 | |
| 129 | LOGP(DRLCMACMEAS, LOGL_DEBUG, "DL Loss of TLLI 0x%08x: Received: %4d " |
Holger Hans Peter Freyther | 474685e | 2013-10-27 17:01:14 +0100 | [diff] [blame] | 130 | "Lost: %4d Sum: %4d\n", tbf->tlli(), received, lost, sum); |
Andreas Eversberg | 050ace2 | 2013-03-16 16:22:02 +0100 | [diff] [blame] | 131 | |
Daniel Willmann | 418a423 | 2014-08-08 11:21:04 +0200 | [diff] [blame] | 132 | tbf->m_bw.dl_loss_received += received; |
| 133 | tbf->m_bw.dl_loss_lost += lost; |
Andreas Eversberg | 050ace2 | 2013-03-16 16:22:02 +0100 | [diff] [blame] | 134 | |
Harald Welte | 099f4f2 | 2018-10-21 11:50:10 +0200 | [diff] [blame] | 135 | osmo_clock_gettime(CLOCK_MONOTONIC, &now_tv); |
Stefan Sperling | 78ab624 | 2018-05-31 12:28:55 +0200 | [diff] [blame] | 136 | timespecsub(&now_tv, loss_tv, &elapsed); |
| 137 | if (elapsed.tv_sec < 1) |
Andreas Eversberg | 050ace2 | 2013-03-16 16:22:02 +0100 | [diff] [blame] | 138 | return 0; |
| 139 | |
| 140 | gprs_rlcmac_lost_rep(tbf); |
| 141 | |
| 142 | /* reset lost values and timestamp */ |
Stefan Sperling | f0f7df1 | 2018-05-25 15:12:30 +0200 | [diff] [blame] | 143 | memcpy(loss_tv, &now_tv, sizeof(*loss_tv)); |
Daniel Willmann | 418a423 | 2014-08-08 11:21:04 +0200 | [diff] [blame] | 144 | tbf->m_bw.dl_loss_received = 0; |
| 145 | tbf->m_bw.dl_loss_lost = 0; |
Andreas Eversberg | 050ace2 | 2013-03-16 16:22:02 +0100 | [diff] [blame] | 146 | |
| 147 | return 0; |
| 148 | } |
| 149 | |
| 150 | /* Give Lost report */ |
Daniel Willmann | 418a423 | 2014-08-08 11:21:04 +0200 | [diff] [blame] | 151 | int gprs_rlcmac_lost_rep(struct gprs_rlcmac_dl_tbf *tbf) |
Andreas Eversberg | 050ace2 | 2013-03-16 16:22:02 +0100 | [diff] [blame] | 152 | { |
Daniel Willmann | 418a423 | 2014-08-08 11:21:04 +0200 | [diff] [blame] | 153 | uint16_t sum = tbf->m_bw.dl_loss_lost + tbf->m_bw.dl_loss_received; |
Andreas Eversberg | 050ace2 | 2013-03-16 16:22:02 +0100 | [diff] [blame] | 154 | |
| 155 | /* No measurement values */ |
| 156 | if (!sum) |
| 157 | return -EINVAL; |
| 158 | |
Stefan Sperling | 082443d | 2018-06-05 11:37:00 +0200 | [diff] [blame] | 159 | LOGP(DRLCMACMEAS, LOGL_DEBUG, "DL packet loss of IMSI=%s / TLLI=0x%08x: " |
Holger Hans Peter Freyther | 5464c9b | 2013-10-27 20:57:35 +0100 | [diff] [blame] | 160 | "%d%%\n", tbf->imsi(), tbf->tlli(), |
Daniel Willmann | 418a423 | 2014-08-08 11:21:04 +0200 | [diff] [blame] | 161 | tbf->m_bw.dl_loss_lost * 100 / sum); |
Andreas Eversberg | 050ace2 | 2013-03-16 16:22:02 +0100 | [diff] [blame] | 162 | |
| 163 | return 0; |
| 164 | } |
| 165 | |
| 166 | |
| 167 | /* |
| 168 | * downlink bandwidth |
| 169 | */ |
| 170 | |
Daniel Willmann | 418a423 | 2014-08-08 11:21:04 +0200 | [diff] [blame] | 171 | int gprs_rlcmac_dl_bw(struct gprs_rlcmac_dl_tbf *tbf, uint16_t octets) |
Andreas Eversberg | 050ace2 | 2013-03-16 16:22:02 +0100 | [diff] [blame] | 172 | { |
Stefan Sperling | f0f7df1 | 2018-05-25 15:12:30 +0200 | [diff] [blame] | 173 | struct timespec now_tv, *bw_tv = &tbf->m_bw.dl_bw_tv; |
Stefan Sperling | 78ab624 | 2018-05-31 12:28:55 +0200 | [diff] [blame] | 174 | struct timespec elapsed; |
Andreas Eversberg | 050ace2 | 2013-03-16 16:22:02 +0100 | [diff] [blame] | 175 | |
Daniel Willmann | 418a423 | 2014-08-08 11:21:04 +0200 | [diff] [blame] | 176 | tbf->m_bw.dl_bw_octets += octets; |
Andreas Eversberg | 050ace2 | 2013-03-16 16:22:02 +0100 | [diff] [blame] | 177 | |
Stefan Sperling | f0f7df1 | 2018-05-25 15:12:30 +0200 | [diff] [blame] | 178 | osmo_clock_gettime(CLOCK_MONOTONIC, &now_tv); |
Stefan Sperling | 78ab624 | 2018-05-31 12:28:55 +0200 | [diff] [blame] | 179 | timespecsub(&now_tv, bw_tv, &elapsed); |
| 180 | if (elapsed.tv_sec < 1) |
Andreas Eversberg | 050ace2 | 2013-03-16 16:22:02 +0100 | [diff] [blame] | 181 | return 0; |
| 182 | |
Stefan Sperling | 78ab624 | 2018-05-31 12:28:55 +0200 | [diff] [blame] | 183 | tbf->m_bw.dl_throughput = (tbf->m_bw.dl_bw_octets << 10) / ((elapsed.tv_sec << 10) + (elapsed.tv_nsec >> 20)); |
Andreas Eversberg | 050ace2 | 2013-03-16 16:22:02 +0100 | [diff] [blame] | 184 | LOGP(DRLCMACMEAS, LOGL_INFO, "DL Bandwitdh of IMSI=%s / TLLI=0x%08x: " |
Stefan Sperling | 78ab624 | 2018-05-31 12:28:55 +0200 | [diff] [blame] | 185 | "%d KBits/s\n", tbf->imsi(), tbf->tlli(), tbf->m_bw.dl_throughput); |
Andreas Eversberg | 050ace2 | 2013-03-16 16:22:02 +0100 | [diff] [blame] | 186 | |
| 187 | /* reset bandwidth values timestamp */ |
Stefan Sperling | f0f7df1 | 2018-05-25 15:12:30 +0200 | [diff] [blame] | 188 | memcpy(bw_tv, &now_tv, sizeof(*bw_tv)); |
Daniel Willmann | 418a423 | 2014-08-08 11:21:04 +0200 | [diff] [blame] | 189 | tbf->m_bw.dl_bw_octets = 0; |
Andreas Eversberg | 050ace2 | 2013-03-16 16:22:02 +0100 | [diff] [blame] | 190 | |
| 191 | return 0; |
| 192 | } |