inter-BSC HO: add neighbor_ident API to manage neighbor-BSS-cells

Depends: Ia71ba742108b5ff020997bfb612ad5eb30d04fcd (libosmocore)
Change-Id: I0153d7069817fba9146ddc11214de2757d7d37bf
diff --git a/tests/handover/neighbor_ident_test.ok b/tests/handover/neighbor_ident_test.ok
new file mode 100644
index 0000000..280b6f2
--- /dev/null
+++ b/tests/handover/neighbor_ident_test.ok
@@ -0,0 +1,249 @@
+
+--- testing NULL neighbor_ident_list
+neighbor_ident_add(k(0, 1, BSIC_6BIT, 2), &cgi1) --> expect rc=-ENOMEM, got -12
+     (empty)
+neighbor_ident_get(k(0, 1, BSIC_6BIT, 2)) --> NULL
+neighbor_ident_del(k(0, 1, BSIC_6BIT, 2)) --> nothing deleted
+     (empty)
+
+--- adding entries, test that no two identical entries are added
+neighbor_ident_add(k(0, 1, BSIC_6BIT, 2), &cgi1) --> expect rc=1, got 1
+  0: BTS 0 to ARFCN 1 BSIC 2
+     cell_id_list cgi[1] = {
+        0: 001-02-3-4
+     }
+neighbor_ident_get(k(0, 1, BSIC_6BIT, 2)) --> entry returned
+     cell_id_list cgi[1] = {
+        0: 001-02-3-4
+     }
+neighbor_ident_add(k(0, 1, BSIC_6BIT, 2), &cgi1) --> expect rc=1, got 1
+  0: BTS 0 to ARFCN 1 BSIC 2
+     cell_id_list cgi[1] = {
+        0: 001-02-3-4
+     }
+neighbor_ident_add(k(0, 1, BSIC_6BIT, 2), &cgi2) --> expect rc=2, got 2
+  0: BTS 0 to ARFCN 1 BSIC 2
+     cell_id_list cgi[2] = {
+        0: 001-02-3-4
+        1: 005-006-7-8
+     }
+neighbor_ident_add(k(0, 1, BSIC_6BIT, 2), &cgi2) --> expect rc=2, got 2
+  0: BTS 0 to ARFCN 1 BSIC 2
+     cell_id_list cgi[2] = {
+        0: 001-02-3-4
+        1: 005-006-7-8
+     }
+neighbor_ident_del(k(0, 1, BSIC_6BIT, 2)) --> entry deleted
+     (empty)
+
+--- Cannot mix cell identifier types for one entry
+neighbor_ident_add(k(0, 1, BSIC_6BIT, 2), &cgi1) --> expect rc=1, got 1
+  0: BTS 0 to ARFCN 1 BSIC 2
+     cell_id_list cgi[1] = {
+        0: 001-02-3-4
+     }
+neighbor_ident_add(k(0, 1, BSIC_6BIT, 2), &lac1) --> expect rc=-EINVAL, got -22
+  0: BTS 0 to ARFCN 1 BSIC 2
+     cell_id_list cgi[1] = {
+        0: 001-02-3-4
+     }
+neighbor_ident_del(k(0, 1, BSIC_6BIT, 2)) --> entry deleted
+     (empty)
+
+--- BTS matching: specific BTS is stronger
+neighbor_ident_add(k(NEIGHBOR_IDENT_KEY_ANY_BTS, 1, BSIC_6BIT, 2), &lac1) --> expect rc=1, got 1
+  0: BTS * to ARFCN 1 BSIC 2
+     cell_id_list lac[1] = {
+       0: 123
+     }
+neighbor_ident_add(k(3, 1, BSIC_6BIT, 2), &lac2) --> expect rc=2, got 2
+  0: BTS * to ARFCN 1 BSIC 2
+     cell_id_list lac[1] = {
+       0: 123
+     }
+  1: BTS 3 to ARFCN 1 BSIC 2
+     cell_id_list lac[2] = {
+       0: 456
+       1: 789
+     }
+neighbor_ident_get(k(2, 1, BSIC_6BIT, 2)) --> entry returned
+     cell_id_list lac[1] = {
+       0: 123
+     }
+neighbor_ident_get(k(3, 1, BSIC_6BIT, 2)) --> entry returned
+     cell_id_list lac[2] = {
+       0: 456
+       1: 789
+     }
+neighbor_ident_get(k(4, 1, BSIC_6BIT, 2)) --> entry returned
+     cell_id_list lac[1] = {
+       0: 123
+     }
+neighbor_ident_get(k(NEIGHBOR_IDENT_KEY_ANY_BTS, 1, BSIC_6BIT, 2)) --> entry returned
+     cell_id_list lac[1] = {
+       0: 123
+     }
+
+--- BSIC matching: 6bit and 9bit are different realms, and wildcard match is weaker
+neighbor_ident_add(k(0, 1, BSIC_NONE, 0), &cgi1) --> expect rc=1, got 1
+  0: BTS 0 to ARFCN 1 (any BSIC)
+     cell_id_list cgi[1] = {
+        0: 001-02-3-4
+     }
+neighbor_ident_add(k(0, 1, BSIC_6BIT, 2), &lac1) --> expect rc=1, got 1
+  0: BTS 0 to ARFCN 1 (any BSIC)
+     cell_id_list cgi[1] = {
+        0: 001-02-3-4
+     }
+  1: BTS 0 to ARFCN 1 BSIC 2
+     cell_id_list lac[1] = {
+       0: 123
+     }
+neighbor_ident_add(k(0, 1, BSIC_9BIT, 2), &lac2) --> expect rc=2, got 2
+  0: BTS 0 to ARFCN 1 (any BSIC)
+     cell_id_list cgi[1] = {
+        0: 001-02-3-4
+     }
+  1: BTS 0 to ARFCN 1 BSIC 2
+     cell_id_list lac[1] = {
+       0: 123
+     }
+  2: BTS 0 to ARFCN 1 BSIC 2(9bit)
+     cell_id_list lac[2] = {
+       0: 456
+       1: 789
+     }
+neighbor_ident_get(k(0, 1, BSIC_6BIT, 2)) --> entry returned
+     cell_id_list lac[1] = {
+       0: 123
+     }
+neighbor_ident_get(k(0, 1, BSIC_9BIT, 2)) --> entry returned
+     cell_id_list lac[2] = {
+       0: 456
+       1: 789
+     }
+--- wildcard matches both 6bit and 9bit BSIC regardless:
+neighbor_ident_get(k(0, 1, BSIC_6BIT, 23)) --> entry returned
+     cell_id_list cgi[1] = {
+        0: 001-02-3-4
+     }
+neighbor_ident_get(k(0, 1, BSIC_9BIT, 23)) --> entry returned
+     cell_id_list cgi[1] = {
+        0: 001-02-3-4
+     }
+
+--- Value ranges
+neighbor_ident_add(k(0, 6, BSIC_6BIT, 1 << 6), &lac1) --> expect rc=-ERANGE, got -34
+     (empty)
+neighbor_ident_add(k(0, 9, BSIC_9BIT, 1 << 9), &lac1) --> expect rc=-ERANGE, got -34
+     (empty)
+neighbor_ident_add(k(0, 6, BSIC_6BIT, -1), &lac1) --> expect rc=-ERANGE, got -34
+     (empty)
+neighbor_ident_add(k(0, 9, BSIC_9BIT, -1), &lac1) --> expect rc=-ERANGE, got -34
+     (empty)
+neighbor_ident_add(k(NEIGHBOR_IDENT_KEY_ANY_BTS - 1, 1, BSIC_NONE, 1), &cgi2) --> expect rc=-ERANGE, got -34
+     (empty)
+neighbor_ident_add(k(256, 1, BSIC_NONE, 1), &cgi2) --> expect rc=-ERANGE, got -34
+     (empty)
+neighbor_ident_add(k(0, 0, BSIC_NONE, 0), &cgi1) --> expect rc=1, got 1
+  0: BTS 0 to ARFCN 0 (any BSIC)
+     cell_id_list cgi[1] = {
+        0: 001-02-3-4
+     }
+neighbor_ident_add(k(255, 65535, BSIC_NONE, 65535), &lac1) --> expect rc=1, got 1
+  0: BTS 0 to ARFCN 0 (any BSIC)
+     cell_id_list cgi[1] = {
+        0: 001-02-3-4
+     }
+  1: BTS 255 to ARFCN 65535 (any BSIC)
+     cell_id_list lac[1] = {
+       0: 123
+     }
+neighbor_ident_add(k(0, 0, BSIC_6BIT, 0), &cgi2) --> expect rc=2, got 2
+  0: BTS 0 to ARFCN 0 (any BSIC)
+     cell_id_list cgi[1] = {
+        0: 001-02-3-4
+     }
+  1: BTS 255 to ARFCN 65535 (any BSIC)
+     cell_id_list lac[1] = {
+       0: 123
+     }
+  2: BTS 0 to ARFCN 0 BSIC 0
+     cell_id_list cgi[2] = {
+        0: 001-02-3-4
+        1: 005-006-7-8
+     }
+neighbor_ident_add(k(255, 65535, BSIC_6BIT, 0x3f), &lac2) --> expect rc=2, got 2
+  0: BTS 0 to ARFCN 0 (any BSIC)
+     cell_id_list cgi[1] = {
+        0: 001-02-3-4
+     }
+  1: BTS 255 to ARFCN 65535 (any BSIC)
+     cell_id_list lac[1] = {
+       0: 123
+     }
+  2: BTS 0 to ARFCN 0 BSIC 0
+     cell_id_list cgi[2] = {
+        0: 001-02-3-4
+        1: 005-006-7-8
+     }
+  3: BTS 255 to ARFCN 65535 BSIC 63
+     cell_id_list lac[2] = {
+       0: 456
+       1: 789
+     }
+neighbor_ident_add(k(0, 0, BSIC_9BIT, 0), &cgi1) --> expect rc=1, got 1
+  0: BTS 0 to ARFCN 0 (any BSIC)
+     cell_id_list cgi[1] = {
+        0: 001-02-3-4
+     }
+  1: BTS 255 to ARFCN 65535 (any BSIC)
+     cell_id_list lac[1] = {
+       0: 123
+     }
+  2: BTS 0 to ARFCN 0 BSIC 0
+     cell_id_list cgi[2] = {
+        0: 001-02-3-4
+        1: 005-006-7-8
+     }
+  3: BTS 255 to ARFCN 65535 BSIC 63
+     cell_id_list lac[2] = {
+       0: 456
+       1: 789
+     }
+  4: BTS 0 to ARFCN 0 BSIC 0(9bit)
+     cell_id_list cgi[1] = {
+        0: 001-02-3-4
+     }
+neighbor_ident_add(k(255, 65535, BSIC_9BIT, 0x1ff), &cgi2) --> expect rc=2, got 2
+  0: BTS 0 to ARFCN 0 (any BSIC)
+     cell_id_list cgi[1] = {
+        0: 001-02-3-4
+     }
+  1: BTS 255 to ARFCN 65535 (any BSIC)
+     cell_id_list lac[1] = {
+       0: 123
+     }
+  2: BTS 0 to ARFCN 0 BSIC 0
+     cell_id_list cgi[2] = {
+        0: 001-02-3-4
+        1: 005-006-7-8
+     }
+  3: BTS 255 to ARFCN 65535 BSIC 63
+     cell_id_list lac[2] = {
+       0: 456
+       1: 789
+     }
+  4: BTS 0 to ARFCN 0 BSIC 0(9bit)
+     cell_id_list cgi[1] = {
+        0: 001-02-3-4
+     }
+  5: BTS 255 to ARFCN 65535 BSIC 511(9bit)
+     cell_id_list cgi[2] = {
+        0: 001-02-3-4
+        1: 005-006-7-8
+     }
+
+--- size limits
+Added first cell identifier list (added 127) --> rc = 127
+Added second cell identifier list (tried to add 1) --> rc = -28