HO: Implement load based handover, as handover_decision_2.c

Change-Id: Ie597eae82722baf32546331e443dd9d94f1f25e6
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 0000000..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);