blob: e4df559e36da23d16c9981ef44e8249d2008fd46 [file] [log] [blame]
Andreas Eversberg050ace22013-03-16 16:22:02 +01001/* 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 Pedrol488aa292019-09-25 17:48:35 +020019
Vadim Yanitskiyd2e50e72020-03-29 01:46:27 +070020extern "C" {
Stefan Sperling78ab6242018-05-31 12:28:55 +020021#include <osmocom/core/timer_compat.h>
Vadim Yanitskiyd2e50e72020-03-29 01:46:27 +070022}
Stefan Sperling78ab6242018-05-31 12:28:55 +020023
Andreas Eversberg050ace22013-03-16 16:22:02 +010024#include <gprs_rlcmac.h>
25#include <gprs_debug.h>
26#include <pcu_l1_if.h>
Holger Hans Peter Freyther099535a2013-10-16 17:42:31 +020027#include <tbf.h>
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +020028#include <tbf_dl.h>
Pau Espin Pedrolf2dad592020-08-18 20:26:25 +020029#include <gprs_ms.h>
Andreas Eversberg050ace22013-03-16 16:22:02 +010030
31#include <string.h>
32#include <errno.h>
33
34/*
35 * downlink measurement
36 */
Max5a6bcfb2017-09-01 14:36:44 +020037/* TODO: trigger the measurement report from the pollcontroller and use it for flow control */
Andreas Eversberg050ace22013-03-16 16:22:02 +010038
39/* received Measurement Report */
40int gprs_rlcmac_meas_rep(Packet_Measurement_Report_t *pmr)
41{
42 NC_Measurement_Report_t *ncr;
43 NC_Measurements_t *nc;
44 int i;
45
Pau Espin Pedrola2c574e2020-08-17 18:15:46 +020046 LOGP(DRLCMACMEAS, LOGL_INFO, "Measurement Report of TLLI=0x%08x:",
47 pmr->TLLI);
Andreas Eversberg050ace22013-03-16 16:22:02 +010048
49 switch (pmr->UnionType) {
50 case 0:
51 ncr = &pmr->u.NC_Measurement_Report;
52 LOGPC(DRLCMACMEAS, LOGL_INFO, " NC%u Serv %d dbm",
53 ncr->NC_MODE + 1,
54 ncr->Serving_Cell_Data.RXLEV_SERVING_CELL - 110);
55 for (i = 0; i < ncr->NUMBER_OF_NC_MEASUREMENTS; i++) {
56 nc = &ncr->NC_Measurements[i];
57 LOGPC(DRLCMACMEAS, LOGL_DEBUG, ", Neigh %u %d dbm",
58 nc->FREQUENCY_N, nc->RXLEV_N - 110);
59 }
60 LOGPC(DRLCMACMEAS, LOGL_INFO, "\n");
61
62 break;
63 case 1:
64 LOGPC(DRLCMACMEAS, LOGL_INFO,
65 " <EXT Reporting not supported!>\n");
66 break;
67 }
68
69 return 0;
70}
71
72
73/*
74 * uplink measurement
75 */
76
77/* RSSI values received from MS */
78int gprs_rlcmac_rssi(struct gprs_rlcmac_tbf *tbf, int8_t rssi)
79{
Stefan Sperlingf0f7df12018-05-25 15:12:30 +020080 struct timespec now_tv, *rssi_tv = &tbf->meas.rssi_tv;
Stefan Sperling78ab6242018-05-31 12:28:55 +020081 struct timespec elapsed;
Andreas Eversberg050ace22013-03-16 16:22:02 +010082
83 tbf->meas.rssi_sum += rssi;
84 tbf->meas.rssi_num++;
85
Stefan Sperlingf0f7df12018-05-25 15:12:30 +020086 osmo_clock_gettime(CLOCK_MONOTONIC, &now_tv);
Stefan Sperling78ab6242018-05-31 12:28:55 +020087
88 timespecsub(&now_tv, rssi_tv, &elapsed);
89 if (elapsed.tv_sec < 1)
Andreas Eversberg050ace22013-03-16 16:22:02 +010090 return 0;
91
92 gprs_rlcmac_rssi_rep(tbf);
93
94 /* reset rssi values and timestamp */
Stefan Sperlingf0f7df12018-05-25 15:12:30 +020095 memcpy(rssi_tv, &now_tv, sizeof(*rssi_tv));
Andreas Eversberg050ace22013-03-16 16:22:02 +010096 tbf->meas.rssi_sum = 0;
97 tbf->meas.rssi_num = 0;
98
99 return 0;
100}
101
102/* Give RSSI report */
103int gprs_rlcmac_rssi_rep(struct gprs_rlcmac_tbf *tbf)
104{
105 /* No measurement values */
106 if (!tbf->meas.rssi_num)
107 return -EINVAL;
108
Pau Espin Pedrolf2dad592020-08-18 20:26:25 +0200109 LOGPMS(tbf->ms(), DRLCMACMEAS, LOGL_INFO, "UL RSSI: %d dBm\n",
110 tbf->meas.rssi_sum / tbf->meas.rssi_num);
Andreas Eversberg050ace22013-03-16 16:22:02 +0100111
112 return 0;
113}
114
115
116/*
117 * lost frames
118 */
119
120/* Lost frames reported from RLCMAC layer */
Daniel Willmann418a4232014-08-08 11:21:04 +0200121int gprs_rlcmac_received_lost(struct gprs_rlcmac_dl_tbf *tbf, uint16_t received,
Andreas Eversberg050ace22013-03-16 16:22:02 +0100122 uint16_t lost)
123{
Stefan Sperlingf0f7df12018-05-25 15:12:30 +0200124 struct timespec now_tv, *loss_tv = &tbf->m_bw.dl_loss_tv;
Stefan Sperling78ab6242018-05-31 12:28:55 +0200125 struct timespec elapsed;
Andreas Eversberg050ace22013-03-16 16:22:02 +0100126 uint16_t sum = received + lost;
127
128 /* No measurement values */
129 if (!sum)
130 return -EINVAL;
131
132 LOGP(DRLCMACMEAS, LOGL_DEBUG, "DL Loss of TLLI 0x%08x: Received: %4d "
Holger Hans Peter Freyther474685e2013-10-27 17:01:14 +0100133 "Lost: %4d Sum: %4d\n", tbf->tlli(), received, lost, sum);
Andreas Eversberg050ace22013-03-16 16:22:02 +0100134
Daniel Willmann418a4232014-08-08 11:21:04 +0200135 tbf->m_bw.dl_loss_received += received;
136 tbf->m_bw.dl_loss_lost += lost;
Andreas Eversberg050ace22013-03-16 16:22:02 +0100137
Harald Welte099f4f22018-10-21 11:50:10 +0200138 osmo_clock_gettime(CLOCK_MONOTONIC, &now_tv);
Stefan Sperling78ab6242018-05-31 12:28:55 +0200139 timespecsub(&now_tv, loss_tv, &elapsed);
140 if (elapsed.tv_sec < 1)
Andreas Eversberg050ace22013-03-16 16:22:02 +0100141 return 0;
142
143 gprs_rlcmac_lost_rep(tbf);
144
145 /* reset lost values and timestamp */
Stefan Sperlingf0f7df12018-05-25 15:12:30 +0200146 memcpy(loss_tv, &now_tv, sizeof(*loss_tv));
Daniel Willmann418a4232014-08-08 11:21:04 +0200147 tbf->m_bw.dl_loss_received = 0;
148 tbf->m_bw.dl_loss_lost = 0;
Andreas Eversberg050ace22013-03-16 16:22:02 +0100149
150 return 0;
151}
152
153/* Give Lost report */
Daniel Willmann418a4232014-08-08 11:21:04 +0200154int gprs_rlcmac_lost_rep(struct gprs_rlcmac_dl_tbf *tbf)
Andreas Eversberg050ace22013-03-16 16:22:02 +0100155{
Daniel Willmann418a4232014-08-08 11:21:04 +0200156 uint16_t sum = tbf->m_bw.dl_loss_lost + tbf->m_bw.dl_loss_received;
Andreas Eversberg050ace22013-03-16 16:22:02 +0100157
158 /* No measurement values */
159 if (!sum)
160 return -EINVAL;
161
Stefan Sperling082443d2018-06-05 11:37:00 +0200162 LOGP(DRLCMACMEAS, LOGL_DEBUG, "DL packet loss of IMSI=%s / TLLI=0x%08x: "
Holger Hans Peter Freyther5464c9b2013-10-27 20:57:35 +0100163 "%d%%\n", tbf->imsi(), tbf->tlli(),
Daniel Willmann418a4232014-08-08 11:21:04 +0200164 tbf->m_bw.dl_loss_lost * 100 / sum);
Andreas Eversberg050ace22013-03-16 16:22:02 +0100165
166 return 0;
167}
168
169
170/*
171 * downlink bandwidth
172 */
173
Daniel Willmann418a4232014-08-08 11:21:04 +0200174int gprs_rlcmac_dl_bw(struct gprs_rlcmac_dl_tbf *tbf, uint16_t octets)
Andreas Eversberg050ace22013-03-16 16:22:02 +0100175{
Stefan Sperlingf0f7df12018-05-25 15:12:30 +0200176 struct timespec now_tv, *bw_tv = &tbf->m_bw.dl_bw_tv;
Stefan Sperling78ab6242018-05-31 12:28:55 +0200177 struct timespec elapsed;
Andreas Eversberg050ace22013-03-16 16:22:02 +0100178
Daniel Willmann418a4232014-08-08 11:21:04 +0200179 tbf->m_bw.dl_bw_octets += octets;
Andreas Eversberg050ace22013-03-16 16:22:02 +0100180
Stefan Sperlingf0f7df12018-05-25 15:12:30 +0200181 osmo_clock_gettime(CLOCK_MONOTONIC, &now_tv);
Stefan Sperling78ab6242018-05-31 12:28:55 +0200182 timespecsub(&now_tv, bw_tv, &elapsed);
183 if (elapsed.tv_sec < 1)
Andreas Eversberg050ace22013-03-16 16:22:02 +0100184 return 0;
185
Stefan Sperling78ab6242018-05-31 12:28:55 +0200186 tbf->m_bw.dl_throughput = (tbf->m_bw.dl_bw_octets << 10) / ((elapsed.tv_sec << 10) + (elapsed.tv_nsec >> 20));
Andreas Eversberg050ace22013-03-16 16:22:02 +0100187 LOGP(DRLCMACMEAS, LOGL_INFO, "DL Bandwitdh of IMSI=%s / TLLI=0x%08x: "
Stefan Sperling78ab6242018-05-31 12:28:55 +0200188 "%d KBits/s\n", tbf->imsi(), tbf->tlli(), tbf->m_bw.dl_throughput);
Andreas Eversberg050ace22013-03-16 16:22:02 +0100189
190 /* reset bandwidth values timestamp */
Stefan Sperlingf0f7df12018-05-25 15:12:30 +0200191 memcpy(bw_tv, &now_tv, sizeof(*bw_tv));
Daniel Willmann418a4232014-08-08 11:21:04 +0200192 tbf->m_bw.dl_bw_octets = 0;
Andreas Eversberg050ace22013-03-16 16:22:02 +0100193
194 return 0;
195}