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