[PATCH] osmo-bsc[master]: HO: Implement load based handover, as handover_decision_2.c

2018-02-19 Thread Neels Hofmeyr
Hello Harald Welte, Jenkins Builder,

I'd like you to reexamine a change.  Please visit

https://gerrit.osmocom.org/6499

to look at the new patch set (#4).

HO: Implement load based handover, as handover_decision_2.c

Change-Id: Ie597eae82722baf32546331e443dd9d94f1f25e6
---
M configure.ac
M doc/examples/osmo-bsc/osmo-bsc.cfg
M doc/examples/osmo-bsc/osmo-bsc_custom-sccp.cfg
M include/osmocom/bsc/Makefile.am
M include/osmocom/bsc/gsm_data.h
M include/osmocom/bsc/handover_cfg.h
A include/osmocom/bsc/handover_decision_2.h
M src/libbsc/Makefile.am
A src/libbsc/handover_decision_2.c
M src/libbsc/handover_vty.c
M src/libbsc/net_init.c
M src/osmo-bsc/osmo_bsc_main.c
M tests/Makefile.am
A tests/handover/Makefile.am
A tests/handover/handover_test.c
A tests/handover/handover_test.ok
M tests/handover_cfg.vty
M tests/testsuite.at
18 files changed, 3,725 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-bsc refs/changes/99/6499/4

diff --git a/configure.ac b/configure.ac
index dac222f..e95a16d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -164,6 +164,7 @@
 tests/subscr/Makefile
 tests/nanobts_omlattr/Makefile
 tests/bssap/Makefile
+tests/handover/Makefile
 doc/Makefile
 doc/examples/Makefile
 Makefile)
diff --git a/doc/examples/osmo-bsc/osmo-bsc.cfg 
b/doc/examples/osmo-bsc/osmo-bsc.cfg
index 17412f7..59732af 100644
--- a/doc/examples/osmo-bsc/osmo-bsc.cfg
+++ b/doc/examples/osmo-bsc/osmo-bsc.cfg
@@ -10,6 +10,7 @@
  neci 0
  paging any use tch 0
  handover 0
+ handover algorithm 1
  handover window rxlev averaging 10
  handover window rxqual averaging 1
  handover window rxlev neighbor averaging 10
diff --git a/doc/examples/osmo-bsc/osmo-bsc_custom-sccp.cfg 
b/doc/examples/osmo-bsc/osmo-bsc_custom-sccp.cfg
index 581d541..aa2c99f 100644
--- a/doc/examples/osmo-bsc/osmo-bsc_custom-sccp.cfg
+++ b/doc/examples/osmo-bsc/osmo-bsc_custom-sccp.cfg
@@ -9,6 +9,7 @@
  neci 0
  paging any use tch 0
  handover 0
+ handover algorithm 1
  handover window rxlev averaging 10
  handover window rxqual averaging 1
  handover window rxlev neighbor averaging 10
diff --git a/include/osmocom/bsc/Makefile.am b/include/osmocom/bsc/Makefile.am
index 9247119..a5d7d18 100644
--- a/include/osmocom/bsc/Makefile.am
+++ b/include/osmocom/bsc/Makefile.am
@@ -24,6 +24,7 @@
handover.h \
handover_cfg.h \
handover_decision.h \
+   handover_decision_2.h \
handover_vty.h \
ipaccess.h \
meas_feed.h \
diff --git a/include/osmocom/bsc/gsm_data.h b/include/osmocom/bsc/gsm_data.h
index bf87595..07e5478 100644
--- a/include/osmocom/bsc/gsm_data.h
+++ b/include/osmocom/bsc/gsm_data.h
@@ -116,6 +116,7 @@
unsigned int ho_dtap_cache_len;
 
struct {
+   int failures;
struct penalty_timers *penalty_timers;
} hodec2;
 
@@ -1197,7 +1198,12 @@
/* bit-mask of permitted encryption algorithms. LSB=A5/0, MSB=A5/7 */
uint8_t a5_encryption_mask;
int neci;
+
struct handover_cfg *ho;
+   struct {
+   unsigned int congestion_check_interval_s;
+   struct osmo_timer_list congestion_check_timer;
+   } hodec2;
 
struct rate_ctr_group *bsc_ctrs;
 
diff --git a/include/osmocom/bsc/handover_cfg.h 
b/include/osmocom/bsc/handover_cfg.h
index 55b9dbc..024bc97 100644
--- a/include/osmocom/bsc/handover_cfg.h
+++ b/include/osmocom/bsc/handover_cfg.h
@@ -10,6 +10,8 @@
  * the defaults from 'network' level are used implicitly, and changes take 
effect immediately. */
 struct handover_cfg;
 
+#define HO_CFG_CONGESTION_CHECK_DEFAULT 10
+
 struct handover_cfg *ho_cfg_init(void *ctx, struct handover_cfg 
*higher_level_cfg);
 
 #define HO_CFG_STR_HANDOVER1 "Handover options for handover decision algorithm 
1\n"
diff --git a/include/osmocom/bsc/handover_decision_2.h 
b/include/osmocom/bsc/handover_decision_2.h
new file mode 100644
index 000..f245b07
--- /dev/null
+++ b/include/osmocom/bsc/handover_decision_2.h
@@ -0,0 +1,9 @@
+/* Handover Decision Algorithm 2 for intra-BSC (inter-BTS) handover, public 
API for OsmoBSC */
+
+#pragma once
+struct gsm_bts;
+
+void hodec2_init(struct gsm_network *net);
+
+void hodec2_on_change_congestion_check_interval(struct gsm_network *net, 
unsigned int new_interval);
+void hodec2_congestion_check(struct gsm_network *net);
diff --git a/src/libbsc/Makefile.am b/src/libbsc/Makefile.am
index 81b7a66..bb14227 100644
--- a/src/libbsc/Makefile.am
+++ b/src/libbsc/Makefile.am
@@ -60,5 +60,6 @@
handover_vty.c \
handover_cfg.c \
penalty_timers.c \
+   handover_decision_2.c \
$(NULL)
 
diff --git a/src/libbsc/handover_decision_2.c b/src/libbsc/handover_decision_2.c
new file mode 100644
index 000..752b0d5
--- /dev/null
+++ b/src/libbsc/handover_decision_2.c
@@ -0,0 +1,1824 @@
+/* Handover Decision Algorithm 2 for intra-BSC (inter-BTS) handover, public 
API for OsmoBSC. */
+
+/* (C) 2009 by Andreas 

[PATCH] osmo-bsc[master]: HO: Implement load based handover, as handover_decision_2.c

2018-02-16 Thread Neels Hofmeyr
Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

https://gerrit.osmocom.org/6499

to look at the new patch set (#2).

HO: Implement load based handover, as handover_decision_2.c

Change-Id: Ie597eae82722baf32546331e443dd9d94f1f25e6
---
M configure.ac
M doc/examples/osmo-bsc/osmo-bsc.cfg
M doc/examples/osmo-bsc/osmo-bsc_custom-sccp.cfg
M include/osmocom/bsc/Makefile.am
M include/osmocom/bsc/gsm_data.h
M include/osmocom/bsc/handover_cfg.h
A include/osmocom/bsc/handover_decision_2.h
M src/libbsc/Makefile.am
A src/libbsc/handover_decision_2.c
M src/libbsc/handover_vty.c
M src/libbsc/net_init.c
M src/osmo-bsc/osmo_bsc_main.c
M tests/Makefile.am
A tests/handover/Makefile.am
A tests/handover/handover_test.c
A tests/handover/handover_test.ok
M tests/handover_cfg.vty
M tests/testsuite.at
18 files changed, 3,724 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-bsc refs/changes/99/6499/2

diff --git a/configure.ac b/configure.ac
index dac222f..e95a16d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -164,6 +164,7 @@
 tests/subscr/Makefile
 tests/nanobts_omlattr/Makefile
 tests/bssap/Makefile
+tests/handover/Makefile
 doc/Makefile
 doc/examples/Makefile
 Makefile)
diff --git a/doc/examples/osmo-bsc/osmo-bsc.cfg 
b/doc/examples/osmo-bsc/osmo-bsc.cfg
index 17412f7..59732af 100644
--- a/doc/examples/osmo-bsc/osmo-bsc.cfg
+++ b/doc/examples/osmo-bsc/osmo-bsc.cfg
@@ -10,6 +10,7 @@
  neci 0
  paging any use tch 0
  handover 0
+ handover algorithm 1
  handover window rxlev averaging 10
  handover window rxqual averaging 1
  handover window rxlev neighbor averaging 10
diff --git a/doc/examples/osmo-bsc/osmo-bsc_custom-sccp.cfg 
b/doc/examples/osmo-bsc/osmo-bsc_custom-sccp.cfg
index 581d541..aa2c99f 100644
--- a/doc/examples/osmo-bsc/osmo-bsc_custom-sccp.cfg
+++ b/doc/examples/osmo-bsc/osmo-bsc_custom-sccp.cfg
@@ -9,6 +9,7 @@
  neci 0
  paging any use tch 0
  handover 0
+ handover algorithm 1
  handover window rxlev averaging 10
  handover window rxqual averaging 1
  handover window rxlev neighbor averaging 10
diff --git a/include/osmocom/bsc/Makefile.am b/include/osmocom/bsc/Makefile.am
index 9247119..a5d7d18 100644
--- a/include/osmocom/bsc/Makefile.am
+++ b/include/osmocom/bsc/Makefile.am
@@ -24,6 +24,7 @@
handover.h \
handover_cfg.h \
handover_decision.h \
+   handover_decision_2.h \
handover_vty.h \
ipaccess.h \
meas_feed.h \
diff --git a/include/osmocom/bsc/gsm_data.h b/include/osmocom/bsc/gsm_data.h
index eedc7ad..2d36292 100644
--- a/include/osmocom/bsc/gsm_data.h
+++ b/include/osmocom/bsc/gsm_data.h
@@ -1152,7 +1152,12 @@
uint16_t network_code;
int a5_encryption;
int neci;
+
struct handover_cfg *ho;
+   struct {
+   unsigned int congestion_check_interval_s;
+   struct osmo_timer_list congestion_check_timer;
+   } hodec2;
 
struct rate_ctr_group *bsc_ctrs;
 
diff --git a/include/osmocom/bsc/handover_cfg.h 
b/include/osmocom/bsc/handover_cfg.h
index 55b9dbc..024bc97 100644
--- a/include/osmocom/bsc/handover_cfg.h
+++ b/include/osmocom/bsc/handover_cfg.h
@@ -10,6 +10,8 @@
  * the defaults from 'network' level are used implicitly, and changes take 
effect immediately. */
 struct handover_cfg;
 
+#define HO_CFG_CONGESTION_CHECK_DEFAULT 10
+
 struct handover_cfg *ho_cfg_init(void *ctx, struct handover_cfg 
*higher_level_cfg);
 
 #define HO_CFG_STR_HANDOVER1 "Handover options for handover decision algorithm 
1\n"
diff --git a/include/osmocom/bsc/handover_decision_2.h 
b/include/osmocom/bsc/handover_decision_2.h
new file mode 100644
index 000..f245b07
--- /dev/null
+++ b/include/osmocom/bsc/handover_decision_2.h
@@ -0,0 +1,9 @@
+/* Handover Decision Algorithm 2 for intra-BSC (inter-BTS) handover, public 
API for OsmoBSC */
+
+#pragma once
+struct gsm_bts;
+
+void hodec2_init(struct gsm_network *net);
+
+void hodec2_on_change_congestion_check_interval(struct gsm_network *net, 
unsigned int new_interval);
+void hodec2_congestion_check(struct gsm_network *net);
diff --git a/src/libbsc/Makefile.am b/src/libbsc/Makefile.am
index 81b7a66..bb14227 100644
--- a/src/libbsc/Makefile.am
+++ b/src/libbsc/Makefile.am
@@ -60,5 +60,6 @@
handover_vty.c \
handover_cfg.c \
penalty_timers.c \
+   handover_decision_2.c \
$(NULL)
 
diff --git a/src/libbsc/handover_decision_2.c b/src/libbsc/handover_decision_2.c
new file mode 100644
index 000..752b0d5
--- /dev/null
+++ b/src/libbsc/handover_decision_2.c
@@ -0,0 +1,1824 @@
+/* Handover Decision Algorithm 2 for intra-BSC (inter-BTS) handover, public 
API for OsmoBSC. */
+
+/* (C) 2009 by Andreas Eversberg 
+ * (C) 2017-2018 by sysmocom - s.f.m.c. GmbH 
+ *
+ * All Rights Reserved
+ *
+ * Author: Andreas Eversberg 
+ * Neels Hofmeyr 
+ *
+ * This program is free 

[PATCH] osmo-bsc[master]: HO: Implement load based handover, as handover_decision_2.c

2018-02-15 Thread Neels Hofmeyr

Review at  https://gerrit.osmocom.org/6499

HO: Implement load based handover, as handover_decision_2.c

Change-Id: Ie597eae82722baf32546331e443dd9d94f1f25e6
---
M configure.ac
M doc/examples/osmo-bsc/osmo-bsc.cfg
M doc/examples/osmo-bsc/osmo-bsc_custom-sccp.cfg
M include/osmocom/bsc/Makefile.am
M include/osmocom/bsc/gsm_data.h
M include/osmocom/bsc/handover_cfg.h
A include/osmocom/bsc/handover_decision_2.h
M src/libbsc/Makefile.am
A src/libbsc/handover_decision_2.c
M src/libbsc/handover_vty.c
M src/libbsc/net_init.c
M src/osmo-bsc/osmo_bsc_main.c
M tests/Makefile.am
A tests/handover/Makefile.am
A tests/handover/handover_test.c
A tests/handover/handover_test.ok
M tests/handover_cfg.vty
M tests/testsuite.at
18 files changed, 3,687 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-bsc refs/changes/99/6499/1

diff --git a/configure.ac b/configure.ac
index dac222f..e95a16d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -164,6 +164,7 @@
 tests/subscr/Makefile
 tests/nanobts_omlattr/Makefile
 tests/bssap/Makefile
+tests/handover/Makefile
 doc/Makefile
 doc/examples/Makefile
 Makefile)
diff --git a/doc/examples/osmo-bsc/osmo-bsc.cfg 
b/doc/examples/osmo-bsc/osmo-bsc.cfg
index 17412f7..59732af 100644
--- a/doc/examples/osmo-bsc/osmo-bsc.cfg
+++ b/doc/examples/osmo-bsc/osmo-bsc.cfg
@@ -10,6 +10,7 @@
  neci 0
  paging any use tch 0
  handover 0
+ handover algorithm 1
  handover window rxlev averaging 10
  handover window rxqual averaging 1
  handover window rxlev neighbor averaging 10
diff --git a/doc/examples/osmo-bsc/osmo-bsc_custom-sccp.cfg 
b/doc/examples/osmo-bsc/osmo-bsc_custom-sccp.cfg
index 581d541..aa2c99f 100644
--- a/doc/examples/osmo-bsc/osmo-bsc_custom-sccp.cfg
+++ b/doc/examples/osmo-bsc/osmo-bsc_custom-sccp.cfg
@@ -9,6 +9,7 @@
  neci 0
  paging any use tch 0
  handover 0
+ handover algorithm 1
  handover window rxlev averaging 10
  handover window rxqual averaging 1
  handover window rxlev neighbor averaging 10
diff --git a/include/osmocom/bsc/Makefile.am b/include/osmocom/bsc/Makefile.am
index 9247119..a5d7d18 100644
--- a/include/osmocom/bsc/Makefile.am
+++ b/include/osmocom/bsc/Makefile.am
@@ -24,6 +24,7 @@
handover.h \
handover_cfg.h \
handover_decision.h \
+   handover_decision_2.h \
handover_vty.h \
ipaccess.h \
meas_feed.h \
diff --git a/include/osmocom/bsc/gsm_data.h b/include/osmocom/bsc/gsm_data.h
index eedc7ad..2d36292 100644
--- a/include/osmocom/bsc/gsm_data.h
+++ b/include/osmocom/bsc/gsm_data.h
@@ -1152,7 +1152,12 @@
uint16_t network_code;
int a5_encryption;
int neci;
+
struct handover_cfg *ho;
+   struct {
+   unsigned int congestion_check_interval_s;
+   struct osmo_timer_list congestion_check_timer;
+   } hodec2;
 
struct rate_ctr_group *bsc_ctrs;
 
diff --git a/include/osmocom/bsc/handover_cfg.h 
b/include/osmocom/bsc/handover_cfg.h
index 55b9dbc..024bc97 100644
--- a/include/osmocom/bsc/handover_cfg.h
+++ b/include/osmocom/bsc/handover_cfg.h
@@ -10,6 +10,8 @@
  * the defaults from 'network' level are used implicitly, and changes take 
effect immediately. */
 struct handover_cfg;
 
+#define HO_CFG_CONGESTION_CHECK_DEFAULT 10
+
 struct handover_cfg *ho_cfg_init(void *ctx, struct handover_cfg 
*higher_level_cfg);
 
 #define HO_CFG_STR_HANDOVER1 "Handover options for handover decision algorithm 
1\n"
diff --git a/include/osmocom/bsc/handover_decision_2.h 
b/include/osmocom/bsc/handover_decision_2.h
new file mode 100644
index 000..f245b07
--- /dev/null
+++ b/include/osmocom/bsc/handover_decision_2.h
@@ -0,0 +1,9 @@
+/* Handover Decision Algorithm 2 for intra-BSC (inter-BTS) handover, public 
API for OsmoBSC */
+
+#pragma once
+struct gsm_bts;
+
+void hodec2_init(struct gsm_network *net);
+
+void hodec2_on_change_congestion_check_interval(struct gsm_network *net, 
unsigned int new_interval);
+void hodec2_congestion_check(struct gsm_network *net);
diff --git a/src/libbsc/Makefile.am b/src/libbsc/Makefile.am
index 81b7a66..bb14227 100644
--- a/src/libbsc/Makefile.am
+++ b/src/libbsc/Makefile.am
@@ -60,5 +60,6 @@
handover_vty.c \
handover_cfg.c \
penalty_timers.c \
+   handover_decision_2.c \
$(NULL)
 
diff --git a/src/libbsc/handover_decision_2.c b/src/libbsc/handover_decision_2.c
new file mode 100644
index 000..3174fde
--- /dev/null
+++ b/src/libbsc/handover_decision_2.c
@@ -0,0 +1,1787 @@
+/* Handover Decision Algorithm 2 for intra-BSC (inter-BTS) handover, public 
API for OsmoBSC. */
+
+/* (C) 2017 by sysmocom - s.f.m.c. GmbH 
+ *
+ * All Rights Reserved
+ *
+ * Author: Andreas Eversberg 
+ * Neels Hofmeyr 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; 

[PATCH] osmo-bsc[master]: HO: Implement load based handover, as handover_decision_2.c

2018-01-19 Thread Neels Hofmeyr
Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

https://gerrit.osmocom.org/5921

to look at the new patch set (#5).

HO: Implement load based handover, as handover_decision_2.c

Change-Id: Ice2d3ef5668564a9d3bc4d5118d59dfaa9af6978
---
M configure.ac
M include/osmocom/bsc/Makefile.am
M include/osmocom/bsc/gsm_data.h
M include/osmocom/bsc/gsm_data_shared.h
M include/osmocom/bsc/handover.h
M include/osmocom/bsc/handover_cfg.h
A include/osmocom/bsc/handover_decision_2.h
M include/osmocom/bsc/handover_vty.h
M include/osmocom/bsc/signal.h
M src/libbsc/Makefile.am
M src/libbsc/abis_rsl.c
M src/libbsc/bsc_api.c
M src/libbsc/bsc_vty.c
M src/libbsc/chan_alloc.c
A src/libbsc/handover_decision_2.c
M src/libbsc/handover_logic.c
M src/libbsc/handover_vty.c
M src/libbsc/net_init.c
M src/libcommon/gsm_data.c
M src/libcommon/handover_cfg.c
M src/osmo-bsc/osmo_bsc_bssap.c
M src/osmo-bsc/osmo_bsc_main.c
M tests/Makefile.am
A tests/handover/Makefile.am
A tests/handover/handover_test.c
A tests/handover/handover_test.ok
M tests/handover_cfg.vty
M tests/testsuite.at
28 files changed, 3,867 insertions(+), 50 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-bsc refs/changes/21/5921/5

diff --git a/configure.ac b/configure.ac
index d756970..fc4678f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -166,6 +166,7 @@
 tests/subscr/Makefile
 tests/nanobts_omlattr/Makefile
 tests/bssap/Makefile
+tests/handover/Makefile
 doc/Makefile
 doc/examples/Makefile
 Makefile)
diff --git a/include/osmocom/bsc/Makefile.am b/include/osmocom/bsc/Makefile.am
index 699aeb3..a3d9adf 100644
--- a/include/osmocom/bsc/Makefile.am
+++ b/include/osmocom/bsc/Makefile.am
@@ -27,6 +27,7 @@
handover.h \
handover_cfg.h \
handover_decision.h \
+   handover_decision_2.h \
handover_vty.h \
ipaccess.h \
meas_feed.h \
diff --git a/include/osmocom/bsc/gsm_data.h b/include/osmocom/bsc/gsm_data.h
index d9dd2d4..c24e22a 100644
--- a/include/osmocom/bsc/gsm_data.h
+++ b/include/osmocom/bsc/gsm_data.h
@@ -10,6 +10,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -74,8 +75,8 @@
 /* penalty timers for handover */
 struct ho_penalty_timer {
struct llist_head entry;
-   uint8_t bts;
-   time_t timeout;
+   uint8_t bts_nr;
+   unsigned int timeout;
 };
 
 /* active radio connection of a mobile subscriber */
@@ -112,8 +113,18 @@
struct llist_head ho_dtap_cache;
unsigned int ho_dtap_cache_len;
 
-   /* penalty timers for handover */
+   /* failure count and penalty timers for handover */
+   int ho_failure;
struct llist_head ho_penalty_timers;
+
+   /* "Codec List (MSC Preferred)" as received by the BSSAP Assignment 
Request. 3GPP 48.008
+* 3.2.2.103 says:
+* The "Codec List (MSC Preferred)" shall not include codecs
+* that are not supported by the MS.
+* i.e. by heeding the "Codec list (MSC Preferred)", we inherently heed 
the MS bearer
+* capabilities, which the MSC is required to translate into the codec 
list. */
+   struct gsm0808_speech_codec_list codec_list;
+   bool codec_list_present;
 };
 
 static inline struct gsm_bts *conn_get_bts(struct gsm_subscriber_connection 
*conn) {
@@ -243,7 +254,12 @@
uint16_t network_code;
int a5_encryption;
int neci;
+
struct handover_cfg *ho;
+   struct {
+   unsigned int congestion_check_interval_s;
+   struct osmo_timer_list congestion_check_timer;
+   } ho2;
 
struct rate_ctr_group *bsc_ctrs;
 
@@ -443,4 +459,11 @@
 
 bool classmark_is_r99(struct gsm_classmark *cm);
 
+void conn_penalty_timer_add(struct gsm_subscriber_connection *conn,
+   struct gsm_bts *bts, int timeout);
+unsigned int conn_penalty_timer_remaining(struct gsm_subscriber_connection 
*conn,
+ struct gsm_bts *bts);
+void conn_penalty_timer_clear(struct gsm_subscriber_connection *conn,
+ struct gsm_bts *bts);
+
 #endif /* _GSM_DATA_H */
diff --git a/include/osmocom/bsc/gsm_data_shared.h 
b/include/osmocom/bsc/gsm_data_shared.h
index 86c5ca9..776e047 100644
--- a/include/osmocom/bsc/gsm_data_shared.h
+++ b/include/osmocom/bsc/gsm_data_shared.h
@@ -269,6 +269,7 @@
struct gsm_meas_rep meas_rep[MAX_MEAS_REP];
int meas_rep_idx;
int meas_rep_count;
+   uint8_t meas_rep_last_seen_nr;
 
/* GSM Random Access data */
struct gsm48_req_ref *rqd_ref;
diff --git a/include/osmocom/bsc/handover.h b/include/osmocom/bsc/handover.h
index a9349ee..f764456 100644
--- a/include/osmocom/bsc/handover.h
+++ b/include/osmocom/bsc/handover.h
@@ -5,6 +5,8 @@
 struct gsm_subscriber_connection;
 
 int bsc_handover_start(struct gsm_lchan *old_lchan, struct gsm_bts *bts);
+int bsc_handover_start_lchan_change(struct gsm_lchan *old_lchan, 

[PATCH] osmo-bsc[master]: HO: Implement load based handover, as handover_decision_2.c

2018-01-18 Thread Neels Hofmeyr
Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

https://gerrit.osmocom.org/5921

to look at the new patch set (#3).

HO: Implement load based handover, as handover_decision_2.c

Change-Id: Ice2d3ef5668564a9d3bc4d5118d59dfaa9af6978
---
M configure.ac
M include/osmocom/bsc/Makefile.am
M include/osmocom/bsc/gsm_data.h
M include/osmocom/bsc/gsm_data_shared.h
M include/osmocom/bsc/handover.h
M include/osmocom/bsc/handover_cfg.h
A include/osmocom/bsc/handover_decision_2.h
M include/osmocom/bsc/handover_vty.h
M include/osmocom/bsc/signal.h
M src/libbsc/Makefile.am
M src/libbsc/abis_rsl.c
M src/libbsc/bsc_api.c
M src/libbsc/bsc_vty.c
M src/libbsc/chan_alloc.c
A src/libbsc/handover_decision_2.c
M src/libbsc/handover_logic.c
M src/libbsc/handover_vty.c
M src/libbsc/net_init.c
M src/libcommon/gsm_data.c
M src/libcommon/handover_cfg.c
M src/osmo-bsc/osmo_bsc_bssap.c
M src/osmo-bsc/osmo_bsc_main.c
M tests/Makefile.am
A tests/handover/Makefile.am
A tests/handover/handover_test.c
A tests/handover/handover_test.ok
M tests/testsuite.at
27 files changed, 3,858 insertions(+), 73 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-bsc refs/changes/21/5921/3

diff --git a/configure.ac b/configure.ac
index d756970..fc4678f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -166,6 +166,7 @@
 tests/subscr/Makefile
 tests/nanobts_omlattr/Makefile
 tests/bssap/Makefile
+tests/handover/Makefile
 doc/Makefile
 doc/examples/Makefile
 Makefile)
diff --git a/include/osmocom/bsc/Makefile.am b/include/osmocom/bsc/Makefile.am
index 699aeb3..a3d9adf 100644
--- a/include/osmocom/bsc/Makefile.am
+++ b/include/osmocom/bsc/Makefile.am
@@ -27,6 +27,7 @@
handover.h \
handover_cfg.h \
handover_decision.h \
+   handover_decision_2.h \
handover_vty.h \
ipaccess.h \
meas_feed.h \
diff --git a/include/osmocom/bsc/gsm_data.h b/include/osmocom/bsc/gsm_data.h
index d9dd2d4..c24e22a 100644
--- a/include/osmocom/bsc/gsm_data.h
+++ b/include/osmocom/bsc/gsm_data.h
@@ -10,6 +10,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -74,8 +75,8 @@
 /* penalty timers for handover */
 struct ho_penalty_timer {
struct llist_head entry;
-   uint8_t bts;
-   time_t timeout;
+   uint8_t bts_nr;
+   unsigned int timeout;
 };
 
 /* active radio connection of a mobile subscriber */
@@ -112,8 +113,18 @@
struct llist_head ho_dtap_cache;
unsigned int ho_dtap_cache_len;
 
-   /* penalty timers for handover */
+   /* failure count and penalty timers for handover */
+   int ho_failure;
struct llist_head ho_penalty_timers;
+
+   /* "Codec List (MSC Preferred)" as received by the BSSAP Assignment 
Request. 3GPP 48.008
+* 3.2.2.103 says:
+* The "Codec List (MSC Preferred)" shall not include codecs
+* that are not supported by the MS.
+* i.e. by heeding the "Codec list (MSC Preferred)", we inherently heed 
the MS bearer
+* capabilities, which the MSC is required to translate into the codec 
list. */
+   struct gsm0808_speech_codec_list codec_list;
+   bool codec_list_present;
 };
 
 static inline struct gsm_bts *conn_get_bts(struct gsm_subscriber_connection 
*conn) {
@@ -243,7 +254,12 @@
uint16_t network_code;
int a5_encryption;
int neci;
+
struct handover_cfg *ho;
+   struct {
+   unsigned int congestion_check_interval_s;
+   struct osmo_timer_list congestion_check_timer;
+   } ho2;
 
struct rate_ctr_group *bsc_ctrs;
 
@@ -443,4 +459,11 @@
 
 bool classmark_is_r99(struct gsm_classmark *cm);
 
+void conn_penalty_timer_add(struct gsm_subscriber_connection *conn,
+   struct gsm_bts *bts, int timeout);
+unsigned int conn_penalty_timer_remaining(struct gsm_subscriber_connection 
*conn,
+ struct gsm_bts *bts);
+void conn_penalty_timer_clear(struct gsm_subscriber_connection *conn,
+ struct gsm_bts *bts);
+
 #endif /* _GSM_DATA_H */
diff --git a/include/osmocom/bsc/gsm_data_shared.h 
b/include/osmocom/bsc/gsm_data_shared.h
index 86c5ca9..776e047 100644
--- a/include/osmocom/bsc/gsm_data_shared.h
+++ b/include/osmocom/bsc/gsm_data_shared.h
@@ -269,6 +269,7 @@
struct gsm_meas_rep meas_rep[MAX_MEAS_REP];
int meas_rep_idx;
int meas_rep_count;
+   uint8_t meas_rep_last_seen_nr;
 
/* GSM Random Access data */
struct gsm48_req_ref *rqd_ref;
diff --git a/include/osmocom/bsc/handover.h b/include/osmocom/bsc/handover.h
index a9349ee..f764456 100644
--- a/include/osmocom/bsc/handover.h
+++ b/include/osmocom/bsc/handover.h
@@ -5,6 +5,8 @@
 struct gsm_subscriber_connection;
 
 int bsc_handover_start(struct gsm_lchan *old_lchan, struct gsm_bts *bts);
+int bsc_handover_start_lchan_change(struct gsm_lchan *old_lchan, struct 
gsm_bts *bts,
+   

[PATCH] osmo-bsc[master]: HO: Implement load based handover, as handover_decision_2.c

2018-01-18 Thread Neels Hofmeyr
Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

https://gerrit.osmocom.org/5921

to look at the new patch set (#2).

HO: Implement load based handover, as handover_decision_2.c

Change-Id: Ice2d3ef5668564a9d3bc4d5118d59dfaa9af6978
---
M configure.ac
M include/osmocom/bsc/Makefile.am
M include/osmocom/bsc/gsm_data.h
M include/osmocom/bsc/gsm_data_shared.h
M include/osmocom/bsc/handover.h
M include/osmocom/bsc/handover_cfg.h
A include/osmocom/bsc/handover_decision_2.h
M include/osmocom/bsc/handover_vty.h
M include/osmocom/bsc/signal.h
M src/libbsc/Makefile.am
M src/libbsc/abis_rsl.c
M src/libbsc/bsc_api.c
M src/libbsc/bsc_vty.c
M src/libbsc/chan_alloc.c
A src/libbsc/handover_decision_2.c
M src/libbsc/handover_logic.c
M src/libbsc/handover_vty.c
M src/libbsc/net_init.c
M src/libcommon/gsm_data.c
M src/libcommon/handover_cfg.c
M src/osmo-bsc/osmo_bsc_bssap.c
M src/osmo-bsc/osmo_bsc_main.c
M tests/Makefile.am
A tests/handover/Makefile.am
A tests/handover/handover_test.c
A tests/handover/handover_test.ok
M tests/testsuite.at
27 files changed, 3,859 insertions(+), 73 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-bsc refs/changes/21/5921/2

diff --git a/configure.ac b/configure.ac
index d756970..fc4678f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -166,6 +166,7 @@
 tests/subscr/Makefile
 tests/nanobts_omlattr/Makefile
 tests/bssap/Makefile
+tests/handover/Makefile
 doc/Makefile
 doc/examples/Makefile
 Makefile)
diff --git a/include/osmocom/bsc/Makefile.am b/include/osmocom/bsc/Makefile.am
index 699aeb3..a3d9adf 100644
--- a/include/osmocom/bsc/Makefile.am
+++ b/include/osmocom/bsc/Makefile.am
@@ -27,6 +27,7 @@
handover.h \
handover_cfg.h \
handover_decision.h \
+   handover_decision_2.h \
handover_vty.h \
ipaccess.h \
meas_feed.h \
diff --git a/include/osmocom/bsc/gsm_data.h b/include/osmocom/bsc/gsm_data.h
index d9dd2d4..c24e22a 100644
--- a/include/osmocom/bsc/gsm_data.h
+++ b/include/osmocom/bsc/gsm_data.h
@@ -10,6 +10,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -74,8 +75,8 @@
 /* penalty timers for handover */
 struct ho_penalty_timer {
struct llist_head entry;
-   uint8_t bts;
-   time_t timeout;
+   uint8_t bts_nr;
+   unsigned int timeout;
 };
 
 /* active radio connection of a mobile subscriber */
@@ -112,8 +113,18 @@
struct llist_head ho_dtap_cache;
unsigned int ho_dtap_cache_len;
 
-   /* penalty timers for handover */
+   /* failure count and penalty timers for handover */
+   int ho_failure;
struct llist_head ho_penalty_timers;
+
+   /* "Codec List (MSC Preferred)" as received by the BSSAP Assignment 
Request. 3GPP 48.008
+* 3.2.2.103 says:
+* The "Codec List (MSC Preferred)" shall not include codecs
+* that are not supported by the MS.
+* i.e. by heeding the "Codec list (MSC Preferred)", we inherently heed 
the MS bearer
+* capabilities, which the MSC is required to translate into the codec 
list. */
+   struct gsm0808_speech_codec_list codec_list;
+   bool codec_list_present;
 };
 
 static inline struct gsm_bts *conn_get_bts(struct gsm_subscriber_connection 
*conn) {
@@ -243,7 +254,12 @@
uint16_t network_code;
int a5_encryption;
int neci;
+
struct handover_cfg *ho;
+   struct {
+   unsigned int congestion_check_interval_s;
+   struct osmo_timer_list congestion_check_timer;
+   } ho2;
 
struct rate_ctr_group *bsc_ctrs;
 
@@ -443,4 +459,11 @@
 
 bool classmark_is_r99(struct gsm_classmark *cm);
 
+void conn_penalty_timer_add(struct gsm_subscriber_connection *conn,
+   struct gsm_bts *bts, int timeout);
+unsigned int conn_penalty_timer_remaining(struct gsm_subscriber_connection 
*conn,
+ struct gsm_bts *bts);
+void conn_penalty_timer_clear(struct gsm_subscriber_connection *conn,
+ struct gsm_bts *bts);
+
 #endif /* _GSM_DATA_H */
diff --git a/include/osmocom/bsc/gsm_data_shared.h 
b/include/osmocom/bsc/gsm_data_shared.h
index 86c5ca9..776e047 100644
--- a/include/osmocom/bsc/gsm_data_shared.h
+++ b/include/osmocom/bsc/gsm_data_shared.h
@@ -269,6 +269,7 @@
struct gsm_meas_rep meas_rep[MAX_MEAS_REP];
int meas_rep_idx;
int meas_rep_count;
+   uint8_t meas_rep_last_seen_nr;
 
/* GSM Random Access data */
struct gsm48_req_ref *rqd_ref;
diff --git a/include/osmocom/bsc/handover.h b/include/osmocom/bsc/handover.h
index a9349ee..f764456 100644
--- a/include/osmocom/bsc/handover.h
+++ b/include/osmocom/bsc/handover.h
@@ -5,6 +5,8 @@
 struct gsm_subscriber_connection;
 
 int bsc_handover_start(struct gsm_lchan *old_lchan, struct gsm_bts *bts);
+int bsc_handover_start_lchan_change(struct gsm_lchan *old_lchan, struct 
gsm_bts *bts,
+   

[PATCH] osmo-bsc[master]: HO: Implement load based handover, as handover_decision_2.c

2018-01-18 Thread Neels Hofmeyr

Review at  https://gerrit.osmocom.org/5921

HO: Implement load based handover, as handover_decision_2.c

Change-Id: Ice2d3ef5668564a9d3bc4d5118d59dfaa9af6978
---
M configure.ac
M include/osmocom/bsc/Makefile.am
M include/osmocom/bsc/gsm_data.h
M include/osmocom/bsc/gsm_data_shared.h
M include/osmocom/bsc/handover.h
M include/osmocom/bsc/handover_cfg.h
A include/osmocom/bsc/handover_decision_2.h
M include/osmocom/bsc/handover_vty.h
M include/osmocom/bsc/signal.h
M src/libbsc/Makefile.am
M src/libbsc/abis_rsl.c
M src/libbsc/bsc_api.c
M src/libbsc/bsc_vty.c
M src/libbsc/chan_alloc.c
A src/libbsc/handover_decision_2.c
M src/libbsc/handover_logic.c
M src/libbsc/handover_vty.c
M src/libbsc/net_init.c
M src/libcommon/gsm_data.c
M src/libcommon/handover_cfg.c
M src/osmo-bsc/osmo_bsc_bssap.c
M src/osmo-bsc/osmo_bsc_main.c
M tests/Makefile.am
A tests/handover/Makefile.am
A tests/handover/handover_test.c
A tests/handover/handover_test.ok
M tests/testsuite.at
27 files changed, 3,861 insertions(+), 73 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-bsc refs/changes/21/5921/1

diff --git a/configure.ac b/configure.ac
index d756970..fc4678f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -166,6 +166,7 @@
 tests/subscr/Makefile
 tests/nanobts_omlattr/Makefile
 tests/bssap/Makefile
+tests/handover/Makefile
 doc/Makefile
 doc/examples/Makefile
 Makefile)
diff --git a/include/osmocom/bsc/Makefile.am b/include/osmocom/bsc/Makefile.am
index 699aeb3..a3d9adf 100644
--- a/include/osmocom/bsc/Makefile.am
+++ b/include/osmocom/bsc/Makefile.am
@@ -27,6 +27,7 @@
handover.h \
handover_cfg.h \
handover_decision.h \
+   handover_decision_2.h \
handover_vty.h \
ipaccess.h \
meas_feed.h \
diff --git a/include/osmocom/bsc/gsm_data.h b/include/osmocom/bsc/gsm_data.h
index d9dd2d4..c24e22a 100644
--- a/include/osmocom/bsc/gsm_data.h
+++ b/include/osmocom/bsc/gsm_data.h
@@ -10,6 +10,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -74,8 +75,8 @@
 /* penalty timers for handover */
 struct ho_penalty_timer {
struct llist_head entry;
-   uint8_t bts;
-   time_t timeout;
+   uint8_t bts_nr;
+   unsigned int timeout;
 };
 
 /* active radio connection of a mobile subscriber */
@@ -112,8 +113,18 @@
struct llist_head ho_dtap_cache;
unsigned int ho_dtap_cache_len;
 
-   /* penalty timers for handover */
+   /* failure count and penalty timers for handover */
+   int ho_failure;
struct llist_head ho_penalty_timers;
+
+   /* "Codec List (MSC Preferred)" as received by the BSSAP Assignment 
Request. 3GPP 48.008
+* 3.2.2.103 says:
+* The "Codec List (MSC Preferred)" shall not include codecs
+* that are not supported by the MS.
+* i.e. by heeding the "Codec list (MSC Preferred)", we inherently heed 
the MS bearer
+* capabilities, which the MSC is required to translate into the codec 
list. */
+   struct gsm0808_speech_codec_list codec_list;
+   bool codec_list_present;
 };
 
 static inline struct gsm_bts *conn_get_bts(struct gsm_subscriber_connection 
*conn) {
@@ -243,7 +254,12 @@
uint16_t network_code;
int a5_encryption;
int neci;
+
struct handover_cfg *ho;
+   struct {
+   unsigned int congestion_check_interval_s;
+   struct osmo_timer_list congestion_check_timer;
+   } ho2;
 
struct rate_ctr_group *bsc_ctrs;
 
@@ -443,4 +459,11 @@
 
 bool classmark_is_r99(struct gsm_classmark *cm);
 
+void conn_penalty_timer_add(struct gsm_subscriber_connection *conn,
+   struct gsm_bts *bts, int timeout);
+unsigned int conn_penalty_timer_remaining(struct gsm_subscriber_connection 
*conn,
+ struct gsm_bts *bts);
+void conn_penalty_timer_clear(struct gsm_subscriber_connection *conn,
+ struct gsm_bts *bts);
+
 #endif /* _GSM_DATA_H */
diff --git a/include/osmocom/bsc/gsm_data_shared.h 
b/include/osmocom/bsc/gsm_data_shared.h
index 86c5ca9..776e047 100644
--- a/include/osmocom/bsc/gsm_data_shared.h
+++ b/include/osmocom/bsc/gsm_data_shared.h
@@ -269,6 +269,7 @@
struct gsm_meas_rep meas_rep[MAX_MEAS_REP];
int meas_rep_idx;
int meas_rep_count;
+   uint8_t meas_rep_last_seen_nr;
 
/* GSM Random Access data */
struct gsm48_req_ref *rqd_ref;
diff --git a/include/osmocom/bsc/handover.h b/include/osmocom/bsc/handover.h
index a9349ee..f764456 100644
--- a/include/osmocom/bsc/handover.h
+++ b/include/osmocom/bsc/handover.h
@@ -5,6 +5,8 @@
 struct gsm_subscriber_connection;
 
 int bsc_handover_start(struct gsm_lchan *old_lchan, struct gsm_bts *bts);
+int bsc_handover_start_lchan_change(struct gsm_lchan *old_lchan, struct 
gsm_bts *bts,
+   enum gsm_chan_t new_lchan_type);
 void bsc_clear_handover(struct