blob: 98e81850f15adad48a1c98cdef6a5bf05e7cc1fd [file] [log] [blame]
Jacob Erlbeck62e96a32015-06-04 09:42:14 +02001/* pcu_vty_functions.cpp
2 *
3 * Copyright (C) 2015 by Sysmocom s.f.m.c. GmbH
4 * Author: Jacob Erlbeck <jerlbeck@sysmocom.de>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20/* OsmoBTS VTY interface */
21
22
23#include <stdint.h>
24#include <stdlib.h>
25#include "pcu_vty_functions.h"
Jacob Erlbeckf47f68a2015-06-04 10:23:24 +020026#include "bts.h"
27#include "gprs_ms_storage.h"
28#include "gprs_ms.h"
29#include "cxx_linuxlist.h"
Max1187a772018-01-26 13:31:42 +010030#include <gprs_coding_scheme.h>
31#include <llc.h>
32#include <pcu_l1_if.h>
33#include <rlc.h>
34#include <tbf.h>
Max6dc90b82018-02-19 17:17:28 +010035#include <pdch.h>
Jacob Erlbeck62e96a32015-06-04 09:42:14 +020036
37extern "C" {
Maxd2d51ed2018-01-25 15:41:28 +010038#include <osmocom/vty/command.h>
39#include <osmocom/vty/logging.h>
40#include <osmocom/vty/misc.h>
Max1187a772018-01-26 13:31:42 +010041 #include <osmocom/core/linuxlist.h>
42 #include <osmocom/core/utils.h>
43 #include <osmocom/vty/vty.h>
Max136ebcc2019-03-05 14:59:03 +010044 #include "coding_scheme.h"
Jacob Erlbeck62e96a32015-06-04 09:42:14 +020045}
46
Max12a09872018-02-01 16:07:33 +010047static void tbf_print_vty_info(struct vty *vty, gprs_rlcmac_tbf *tbf, bool show_ccch, bool show_pacch)
Jacob Erlbeckbf49f042015-12-28 19:06:09 +010048{
Jacob Erlbeck9f686702016-01-19 17:10:07 +010049 gprs_rlcmac_ul_tbf *ul_tbf = as_ul_tbf(tbf);
50 gprs_rlcmac_dl_tbf *dl_tbf = as_dl_tbf(tbf);
51
Max12a09872018-02-01 16:07:33 +010052 if (show_ccch && !(tbf->state_flags & (1 << GPRS_RLCMAC_FLAG_CCCH)))
53 return;
54
55 if (show_pacch && !(tbf->state_flags & (1 << GPRS_RLCMAC_FLAG_PACCH)))
56 return;
57
Minh-Quang Nguyen8d555632017-11-01 15:00:08 -040058 vty_out(vty, "TBF: TFI=%d TLLI=0x%08x (%s) TA=%u DIR=%s IMSI=%s%s", tbf->tfi(),
Jacob Erlbeckbf49f042015-12-28 19:06:09 +010059 tbf->tlli(), tbf->is_tlli_valid() ? "valid" : "invalid",
Minh-Quang Nguyen8d555632017-11-01 15:00:08 -040060 tbf->ta(),
Jacob Erlbeckbf49f042015-12-28 19:06:09 +010061 tbf->direction == GPRS_RLCMAC_UL_TBF ? "UL" : "DL",
62 tbf->imsi(), VTY_NEWLINE);
Max5441e1f2018-01-30 17:49:53 +010063 vty_out(vty, " created=%lu state=%08x [CCCH:%u, PACCH:%u] 1st_TS=%d 1st_cTS=%d ctrl_TS=%d MS_CLASS=%d/%d%s",
64 tbf->created_ts(), tbf->state_flags,
65 tbf->state_flags & (1 << GPRS_RLCMAC_FLAG_CCCH),
66 tbf->state_flags & (1 << GPRS_RLCMAC_FLAG_PACCH),
67 tbf->first_ts,
Jacob Erlbeckf2694b72016-01-26 21:46:26 +010068 tbf->first_common_ts, tbf->control_ts,
69 tbf->ms_class(),
Jacob Erlbeck08c72fb2016-01-19 16:04:30 +010070 tbf->ms() ? tbf->ms()->egprs_ms_class() : -1,
Jacob Erlbeckbf49f042015-12-28 19:06:09 +010071 VTY_NEWLINE);
72 vty_out(vty, " TS_alloc=");
73 for (int i = 0; i < 8; i++) {
Jacob Erlbeck81a04f72016-01-28 16:14:58 +010074 bool is_ctrl = tbf->is_control_ts(i);
Jacob Erlbeckbf49f042015-12-28 19:06:09 +010075 if (tbf->pdch[i])
Jacob Erlbeck81a04f72016-01-28 16:14:58 +010076 vty_out(vty, "%d%s ", i, is_ctrl ? "!" : "");
Jacob Erlbeckbf49f042015-12-28 19:06:09 +010077 }
Mrinal Mishrad453eaa2016-10-26 15:41:56 +053078 if (tbf->trx != NULL)
79 vty_out(vty, " TRX_ID=%d", tbf->trx->trx_no);
Max136ebcc2019-03-05 14:59:03 +010080 vty_out(vty, " CS=%s", mcs_name(tbf->current_cs()));
Jacob Erlbeck9f686702016-01-19 17:10:07 +010081
82 if (ul_tbf) {
Max00fd0df2018-01-12 16:24:18 +010083 gprs_rlc_ul_window *win = ul_tbf->window();
Maxa4f570f2017-12-15 11:21:57 +010084 vty_out(vty, " WS=%u V(Q)=%d V(R)=%d",
85 ul_tbf->window_size(), win->v_q(), win->v_r());
sivasankarida7250a2016-12-16 12:57:18 +053086 vty_out(vty, "%s", VTY_NEWLINE);
87 vty_out(vty, " TBF Statistics:%s", VTY_NEWLINE);
Maxa4de02d2019-03-13 16:35:09 +010088 if(GPRS == tbf->ms()->mode()) {
sivasankarida7250a2016-12-16 12:57:18 +053089 vty_out_rate_ctr_group(vty, " ", ul_tbf->m_ul_gprs_ctrs);
90 } else {
91 vty_out_rate_ctr_group(vty, " ", ul_tbf->m_ul_egprs_ctrs);
92 }
Jacob Erlbeck9f686702016-01-19 17:10:07 +010093 }
94 if (dl_tbf) {
Max00fd0df2018-01-12 16:24:18 +010095 gprs_rlc_dl_window *win = dl_tbf->window();
Maxa4f570f2017-12-15 11:21:57 +010096 vty_out(vty, " WS=%u V(A)=%d V(S)=%d nBSN=%d%s",
97 dl_tbf->window_size(), win->v_a(), win->v_s(), win->resend_needed(),
Jacob Erlbeck9f686702016-01-19 17:10:07 +010098 win->window_stalled() ? " STALLED" : "");
sivasankari53950732016-12-08 17:15:17 +053099 vty_out(vty, "%s", VTY_NEWLINE);
100 vty_out_rate_ctr_group(vty, " ", tbf->m_ctrs);
Maxa4de02d2019-03-13 16:35:09 +0100101 if(GPRS == tbf->ms()->mode()) {
sivasankari53950732016-12-08 17:15:17 +0530102 vty_out_rate_ctr_group(vty, " ", dl_tbf->m_dl_gprs_ctrs);
103 } else {
104 vty_out_rate_ctr_group(vty, " ", dl_tbf->m_dl_egprs_ctrs);
105 }
Jacob Erlbeck9f686702016-01-19 17:10:07 +0100106 }
107 vty_out(vty, "%s%s", VTY_NEWLINE, VTY_NEWLINE);
Jacob Erlbeckbf49f042015-12-28 19:06:09 +0100108}
109
Max12a09872018-02-01 16:07:33 +0100110int pcu_vty_show_tbf_all(struct vty *vty, struct gprs_rlcmac_bts *bts_data, bool show_ccch, bool show_pacch)
Jacob Erlbecked2dbf62015-12-28 19:15:40 +0100111{
112 BTS *bts = bts_data->bts;
113 LListHead<gprs_rlcmac_tbf> *ms_iter;
114
115 vty_out(vty, "UL TBFs%s", VTY_NEWLINE);
116 llist_for_each(ms_iter, &bts->ul_tbfs())
Max12a09872018-02-01 16:07:33 +0100117 tbf_print_vty_info(vty, ms_iter->entry(), show_ccch, show_pacch);
Jacob Erlbecked2dbf62015-12-28 19:15:40 +0100118
119 vty_out(vty, "%sDL TBFs%s", VTY_NEWLINE, VTY_NEWLINE);
120 llist_for_each(ms_iter, &bts->dl_tbfs())
Max12a09872018-02-01 16:07:33 +0100121 tbf_print_vty_info(vty, ms_iter->entry(), show_ccch, show_pacch);
Jacob Erlbecked2dbf62015-12-28 19:15:40 +0100122
123 return CMD_SUCCESS;
124}
125
Jacob Erlbeckf47f68a2015-06-04 10:23:24 +0200126int pcu_vty_show_ms_all(struct vty *vty, struct gprs_rlcmac_bts *bts_data)
127{
128 BTS *bts = bts_data->bts;
129 LListHead<GprsMs> *ms_iter;
130
131 llist_for_each(ms_iter, &bts->ms_store().ms_list()) {
132 GprsMs *ms = ms_iter->entry();
133
Max39eb95f2017-12-06 13:13:34 +0100134 vty_out(vty, "MS TLLI=%08x, TA=%d, CS-UL=%s, CS-DL=%s, LLC=%zd, Cl=%d, E-Cl=%d,"
135 " TBF-UL=%s, TBF-DL=%s, IMSI=%s%s",
Jacob Erlbeckf47f68a2015-06-04 10:23:24 +0200136 ms->tlli(),
Max136ebcc2019-03-05 14:59:03 +0100137 ms->ta(), mcs_name(ms->current_cs_ul()),
138 mcs_name(ms->current_cs_dl()),
Jacob Erlbeck159d4de2015-08-21 16:02:11 +0200139 ms->llc_queue()->size(),
Max39eb95f2017-12-06 13:13:34 +0100140 ms->ms_class(),
141 ms->egprs_ms_class(),
142 ms->ul_tbf() ? ms->ul_tbf()->state_name() : "NA",
143 ms->dl_tbf() ? ms->dl_tbf()->state_name() : "NA",
Jacob Erlbeckf47f68a2015-06-04 10:23:24 +0200144 ms->imsi(),
145 VTY_NEWLINE);
146 }
147 return CMD_SUCCESS;
148}
Jacob Erlbeck37e896d2015-06-05 16:33:33 +0200149
150static int show_ms(struct vty *vty, GprsMs *ms)
151{
Jacob Erlbeck51b11512015-06-11 16:54:50 +0200152 unsigned i;
Jacob Erlbeckc62216b2015-08-21 15:46:16 +0200153 LListHead<gprs_rlcmac_tbf> *i_tbf;
Jacob Erlbeck7c72aca2016-01-22 17:06:14 +0100154 uint8_t slots;
Jacob Erlbeck51b11512015-06-11 16:54:50 +0200155
Jacob Erlbeck37e896d2015-06-05 16:33:33 +0200156 vty_out(vty, "MS TLLI=%08x, IMSI=%s%s", ms->tlli(), ms->imsi(), VTY_NEWLINE);
157 vty_out(vty, " Timing advance (TA): %d%s", ms->ta(), VTY_NEWLINE);
Max136ebcc2019-03-05 14:59:03 +0100158 vty_out(vty, " Coding scheme uplink: %s%s", mcs_name(ms->current_cs_ul()),
Jacob Erlbeck37e896d2015-06-05 16:33:33 +0200159 VTY_NEWLINE);
Max136ebcc2019-03-05 14:59:03 +0100160 vty_out(vty, " Coding scheme downlink: %s%s", mcs_name(ms->current_cs_dl()),
Jacob Erlbeck37e896d2015-06-05 16:33:33 +0200161 VTY_NEWLINE);
Maxa4de02d2019-03-13 16:35:09 +0100162 vty_out(vty, " Mode: %s%s", mode_name(ms->mode()), VTY_NEWLINE);
Jacob Erlbeck37e896d2015-06-05 16:33:33 +0200163 vty_out(vty, " MS class: %d%s", ms->ms_class(), VTY_NEWLINE);
Jacob Erlbeckc3c58042015-09-28 17:55:32 +0200164 vty_out(vty, " EGPRS MS class: %d%s", ms->egprs_ms_class(), VTY_NEWLINE);
Jacob Erlbeck7c72aca2016-01-22 17:06:14 +0100165 vty_out(vty, " PACCH: ");
166 slots = ms->current_pacch_slots();
167 for (int i = 0; i < 8; i++)
168 if (slots & (1 << i))
169 vty_out(vty, "%d ", i);
170 vty_out(vty, "%s", VTY_NEWLINE);
Harald Welte63d33ad2016-03-30 22:08:18 +0200171 vty_out(vty, " LLC queue length: %zd%s", ms->llc_queue()->size(),
Jacob Erlbeck37e896d2015-06-05 16:33:33 +0200172 VTY_NEWLINE);
Harald Welte63d33ad2016-03-30 22:08:18 +0200173 vty_out(vty, " LLC queue octets: %zd%s", ms->llc_queue()->octets(),
Jacob Erlbeck159d4de2015-08-21 16:02:11 +0200174 VTY_NEWLINE);
Jacob Erlbecke4bcb622015-06-08 11:26:38 +0200175 if (ms->l1_meas()->have_rssi)
176 vty_out(vty, " RSSI: %d dBm%s",
177 ms->l1_meas()->rssi, VTY_NEWLINE);
178 if (ms->l1_meas()->have_ber)
179 vty_out(vty, " Bit error rate: %d %%%s",
180 ms->l1_meas()->ber, VTY_NEWLINE);
181 if (ms->l1_meas()->have_link_qual)
182 vty_out(vty, " Link quality: %d dB%s",
183 ms->l1_meas()->link_qual, VTY_NEWLINE);
184 if (ms->l1_meas()->have_bto)
185 vty_out(vty, " Burst timing offset: %d/4 bit%s",
186 ms->l1_meas()->bto, VTY_NEWLINE);
Jacob Erlbeck51b11512015-06-11 16:54:50 +0200187 if (ms->l1_meas()->have_ms_rx_qual)
Jacob Erlbeck04a10862015-06-12 16:01:56 +0200188 vty_out(vty, " Downlink NACK rate: %d %%%s",
189 ms->nack_rate_dl(), VTY_NEWLINE);
190 if (ms->l1_meas()->have_ms_rx_qual)
Jacob Erlbeck51b11512015-06-11 16:54:50 +0200191 vty_out(vty, " MS RX quality: %d %%%s",
192 ms->l1_meas()->ms_rx_qual, VTY_NEWLINE);
193 if (ms->l1_meas()->have_ms_c_value)
194 vty_out(vty, " MS C value: %d dB%s",
195 ms->l1_meas()->ms_c_value, VTY_NEWLINE);
196 if (ms->l1_meas()->have_ms_sign_var)
197 vty_out(vty, " MS SIGN variance: %d dB%s",
198 ms->l1_meas()->ms_sign_var, VTY_NEWLINE);
199 for (i = 0; i < ARRAY_SIZE(ms->l1_meas()->ts); ++i) {
200 if (ms->l1_meas()->ts[i].have_ms_i_level)
201 vty_out(vty, " MS I level (slot %d): %d dB%s",
202 i, ms->l1_meas()->ts[i].ms_i_level, VTY_NEWLINE);
203 }
sivasankarida7250a2016-12-16 12:57:18 +0530204 vty_out(vty, " RLC/MAC DL Control Msg: %d%s", ms->dl_ctrl_msg(),
205 VTY_NEWLINE);
Jacob Erlbeck37e896d2015-06-05 16:33:33 +0200206 if (ms->ul_tbf())
207 vty_out(vty, " Uplink TBF: TFI=%d, state=%s%s",
208 ms->ul_tbf()->tfi(),
209 ms->ul_tbf()->state_name(),
210 VTY_NEWLINE);
sivasankari53950732016-12-08 17:15:17 +0530211 if (ms->dl_tbf()) {
Jacob Erlbeck37e896d2015-06-05 16:33:33 +0200212 vty_out(vty, " Downlink TBF: TFI=%d, state=%s%s",
213 ms->dl_tbf()->tfi(),
214 ms->dl_tbf()->state_name(),
215 VTY_NEWLINE);
sivasankari53950732016-12-08 17:15:17 +0530216 vty_out(vty, " Current DL Throughput: %d Kbps %s",
217 ms->dl_tbf()->m_bw.dl_throughput,
218 VTY_NEWLINE);
219 }
Jacob Erlbeck37e896d2015-06-05 16:33:33 +0200220
Jacob Erlbeckc62216b2015-08-21 15:46:16 +0200221 llist_for_each(i_tbf, &ms->old_tbfs())
222 vty_out(vty, " Old %-19s TFI=%d, state=%s%s",
223 i_tbf->entry()->direction == GPRS_RLCMAC_UL_TBF ?
224 "Uplink TBF:" : "Downlink TBF:",
225 i_tbf->entry()->tfi(),
226 i_tbf->entry()->state_name(),
227 VTY_NEWLINE);
228
Jacob Erlbeck37e896d2015-06-05 16:33:33 +0200229 return CMD_SUCCESS;
230}
231
232int pcu_vty_show_ms_by_tlli(struct vty *vty, struct gprs_rlcmac_bts *bts_data,
233 uint32_t tlli)
234{
235 BTS *bts = bts_data->bts;
236 GprsMs *ms = bts->ms_store().get_ms(tlli);
237 if (!ms) {
238 vty_out(vty, "Unknown TLLI %08x.%s", tlli, VTY_NEWLINE);
239 return CMD_WARNING;
240 }
241
242 return show_ms(vty, ms);
243}
244
245int pcu_vty_show_ms_by_imsi(struct vty *vty, struct gprs_rlcmac_bts *bts_data,
246 const char *imsi)
247{
248 BTS *bts = bts_data->bts;
249 GprsMs *ms = bts->ms_store().get_ms(0, 0, imsi);
250 if (!ms) {
251 vty_out(vty, "Unknown IMSI '%s'.%s", imsi, VTY_NEWLINE);
252 return CMD_WARNING;
253 }
254
255 return show_ms(vty, ms);
256}