Use the new NS2 lib

Depends: Id7edb8feb96436ba170383fc62d43ceb16955d53 (libosmocore)
Depends: I2a9dcd14f4ad16211c0f6d98812ad4a13e910c2a (libosmocore)
Change-Id: Ib389925cf5c9f18951af6242c31ea70476218e9a
diff --git a/tests/emu/pcu_emu.cpp b/tests/emu/pcu_emu.cpp
index 7f99355..98da13e 100644
--- a/tests/emu/pcu_emu.cpp
+++ b/tests/emu/pcu_emu.cpp
@@ -93,15 +93,28 @@
 			uint32_t sgsn_ip, uint16_t sgsn_port)
 {
 	struct gprs_bssgp_pcu *pcu;
+	struct osmo_sockaddr local, remote;
 
-	pcu = gprs_bssgp_create_and_connect(bts, 0, sgsn_ip, sgsn_port,
-					20, 20, 20, 901, 99, false, 1, 0, 0);
+	local.u.sin.sin_family = AF_INET;
+	local.u.sin.sin_addr.s_addr = 0;
+	local.u.sin.sin_port = 0;
+
+	remote.u.sin.sin_family = AF_INET;
+	remote.u.sin.sin_addr.s_addr = htonl(sgsn_ip);
+	remote.u.sin.sin_port = htons(sgsn_port);
+
+	pcu = gprs_bssgp_init(bts, 20, 20, 901, 99, false, 1, 0, 0);
+	gprs_nsvc_create_and_connect(bts, &local, &remote,
+				     20, 20);
+
 	pcu->on_unblock_ack = bvci_unblocked;
 	pcu->on_dl_unit_data = bssgp_data;
 }
 
 int main(int argc, char **argv)
 {
+	struct gprs_rlcmac_bts *bts = bts_main_data();
+
 	tall_pcu_ctx = talloc_named_const(NULL, 1, "moiji-mobile Emu-PCU context");
 	if (!tall_pcu_ctx)
 		abort();
@@ -109,8 +122,8 @@
 	msgb_talloc_ctx_init(tall_pcu_ctx, 0);
 	osmo_init_logging2(tall_pcu_ctx, &gprs_log_info);
 
-	bssgp_nsi = gprs_ns_instantiate(&gprs_bssgp_ns_cb, tall_pcu_ctx);
-	if (!bssgp_nsi) {
+	bts->nsi = gprs_ns2_instantiate(tall_pcu_ctx, &gprs_ns_prim_cb, NULL);
+	if (!bts->nsi) {
 		LOGP(DBSSGP, LOGL_ERROR, "Failed to create NS instance\n");
 		abort();
 	}
@@ -121,7 +134,8 @@
 	current_test = 0;
 
 	init_main_bts();
-	create_and_connect_bssgp(bts_main_data(), INADDR_LOOPBACK, 23000);
+	bssgp_set_bssgp_callback(gprs_gp_send_cb, bts->nsi);
+	create_and_connect_bssgp(bts, INADDR_LOOPBACK, 23000);
 	
 	for (;;)
 		osmo_select_main(0);
diff --git a/tests/tbf/TbfTest.cpp b/tests/tbf/TbfTest.cpp
index b16c089..15a79d0 100644
--- a/tests/tbf/TbfTest.cpp
+++ b/tests/tbf/TbfTest.cpp
@@ -470,15 +470,15 @@
 
 	fprintf(stderr, "=== start %s ===\n", __func__);
 
-	bssgp_nsi = gprs_ns_instantiate(&gprs_bssgp_ns_cb, tall_pcu_ctx);
-	if (!bssgp_nsi) {
+	bts = the_bts.bts_data();
+	bts->nsi = gprs_ns2_instantiate(tall_pcu_ctx, gprs_ns_prim_cb, NULL);
+	if (!bts->nsi) {
 		LOGP(DBSSGP, LOGL_ERROR, "Failed to create NS instance\n");
 		abort();
 	}
 
-	bts = the_bts.bts_data();
 	setup_bts(&the_bts, ts_no);
-	gprs_bssgp_create_and_connect(bts, 33001, 0, 33001, 1234, 1234, 1234, 1, 1, false, 0, 0, 0);
+	gprs_bssgp_init(bts, 1234, 1234, 1, 1, false, 0, 0, 0);
 
 	for (i = 0; i < 1024; i++) {
 		uint32_t tlli = 0xc0000000 + i;
@@ -497,7 +497,7 @@
 	OSMO_ASSERT(rc == -EBUSY);
 	fprintf(stderr, "=== end %s ===\n", __func__);
 
-	gprs_bssgp_destroy();
+	gprs_bssgp_destroy(bts);
 }
 
 static void test_tbf_dl_llc_loss()
@@ -514,20 +514,20 @@
 
 	uint8_t buf[19];
 
-	bssgp_nsi = gprs_ns_instantiate(&gprs_bssgp_ns_cb, tall_pcu_ctx);
-	if (!bssgp_nsi) {
+	bts = the_bts.bts_data();
+	bts->nsi = gprs_ns2_instantiate(tall_pcu_ctx, gprs_ns_prim_cb, NULL);
+	if (!bts->nsi) {
 		LOGP(DBSSGP, LOGL_ERROR, "Failed to create NS instance\n");
 		abort();
 	}
 
 	fprintf(stderr, "=== start %s ===\n", __func__);
 
-	bts = the_bts.bts_data();
 	setup_bts(&the_bts, ts_no);
 	/* keep the MS object 10 seconds */
 	OSMO_ASSERT(osmo_tdef_set(bts->T_defs_pcu, -2030, 10, OSMO_TDEF_S) == 0);
 
-	gprs_bssgp_create_and_connect(bts, 33001, 0, 33001, 2234, 2234, 2234, 1, 1, false, 0, 0, 0);
+	gprs_bssgp_init(bts, 2234, 2234, 1, 1, false, 0, 0, 0);
 
 	/* Handle LLC frame 1 */
 	memset(buf, 1, sizeof(buf));
@@ -582,7 +582,7 @@
 
 	fprintf(stderr, "=== end %s ===\n", __func__);
 
-	gprs_bssgp_destroy();
+	gprs_bssgp_destroy(bts);
 }
 
 static gprs_rlcmac_ul_tbf *establish_ul_tbf_single_phase(BTS *the_bts,
@@ -2165,19 +2165,19 @@
 
 	fprintf(stderr, "=== start %s ===\n", __func__);
 
-	bssgp_nsi = gprs_ns_instantiate(&gprs_bssgp_ns_cb, tall_pcu_ctx);
-	if (!bssgp_nsi) {
+	bts = the_bts.bts_data();
+	bts->nsi = gprs_ns2_instantiate(tall_pcu_ctx, gprs_ns_prim_cb, NULL);
+	if (!bts->nsi) {
 		LOGP(DBSSGP, LOGL_ERROR, "Failed to create NS instance\n");
 		abort();
 	}
 
-	bts = the_bts.bts_data();
 	setup_bts(&the_bts, ts_no);
 
 	/* EGPRS-only */
 	bts->egprs_enabled = 1;
 
-	gprs_bssgp_create_and_connect(bts, 33001, 0, 33001, 3234, 3234, 3234, 1, 1, false, 0, 0, 0);
+	gprs_bssgp_init(bts, 3234, 3234, 1, 1, false, 0, 0, 0);
 
 	/* Does not support EGPRS */
 	rc = gprs_rlcmac_dl_tbf::handle(bts, tlli, 0, imsi, ms_class, 0,
@@ -2186,12 +2186,13 @@
 	OSMO_ASSERT(rc == -EBUSY);
 	fprintf(stderr, "=== end %s ===\n", __func__);
 
-	gprs_bssgp_destroy();
+	gprs_bssgp_destroy(bts);
 }
 
 static inline void ws_check(gprs_rlcmac_dl_tbf *dl_tbf, const char *test, uint8_t exp_slots, uint16_t exp_ws,
 			    bool free, bool end)
 {
+	gprs_rlcmac_bts *bts = dl_tbf->bts->bts_data();
 	if (!dl_tbf) {
 		fprintf(stderr, "%s(): FAILED (NULL TBF)\n", test);
 		return;
@@ -2213,7 +2214,7 @@
 
 	if (end) {
 		fprintf(stderr, "=== end %s ===\n", test);
-		gprs_bssgp_destroy();
+		gprs_bssgp_destroy(bts);
 	}
 }
 
@@ -2228,13 +2229,13 @@
 
 	fprintf(stderr, "=== start %s ===\n", __func__);
 
-	bssgp_nsi = gprs_ns_instantiate(&gprs_bssgp_ns_cb, tall_pcu_ctx);
-	if (!bssgp_nsi) {
+	bts = the_bts.bts_data();
+	bts->nsi = gprs_ns2_instantiate(tall_pcu_ctx, gprs_ns_prim_cb, NULL);
+	if (!bts->nsi) {
 		LOGP(DBSSGP, LOGL_ERROR, "Failed to create NS instance\n");
 		abort();
 	}
 
-	bts = the_bts.bts_data();
 	setup_bts(&the_bts, ts_no);
 
 	bts->ws_base = 128;
@@ -2245,7 +2246,7 @@
 	bts->trx[0].pdch[4].enable();
 	bts->trx[0].pdch[5].enable();
 
-	gprs_bssgp_create_and_connect(bts, 33001, 0, 33001, 4234, 4234, 4234, 1, 1, false, 0, 0, 0);
+	gprs_bssgp_init(bts, 4234, 4234, 1, 1, false, 0, 0, 0);
 
 	/* Does no support EGPRS */
 	ms = the_bts.ms_alloc(ms_class, 0);
@@ -2274,13 +2275,13 @@
 
 	fprintf(stderr, "=== start %s ===\n", __func__);
 
-	bssgp_nsi = gprs_ns_instantiate(&gprs_bssgp_ns_cb, tall_pcu_ctx);
-	if (!bssgp_nsi) {
+	bts = the_bts.bts_data();
+	bts->nsi = gprs_ns2_instantiate(tall_pcu_ctx, gprs_ns_prim_cb, NULL);
+	if (!bts->nsi) {
 		LOGP(DBSSGP, LOGL_ERROR, "Failed to create NS instance\n");
 		abort();
 	}
 
-	bts = the_bts.bts_data();
 	setup_bts(&the_bts, ts_no);
 
 	bts->ws_base = 128;
@@ -2291,7 +2292,7 @@
 	bts->trx[0].pdch[4].enable();
 	bts->trx[0].pdch[5].enable();
 
-	gprs_bssgp_create_and_connect(bts, 33001, 0, 33001, 5234, 5234, 5234, 1, 1, false, 0, 0, 0);
+	gprs_bssgp_init(bts, 5234, 5234, 1, 1, false, 0, 0, 0);
 
 	/* EGPRS-only */
 	bts->egprs_enabled = 1;