aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/tests
diff options
context:
space:
mode:
Diffstat (limited to 'openbsc/tests')
-rw-r--r--openbsc/tests/sgsn/sgsn_test.c93
-rw-r--r--openbsc/tests/sgsn/sgsn_test.ok1
-rw-r--r--openbsc/tests/vty_test_runner.py21
3 files changed, 115 insertions, 0 deletions
diff --git a/openbsc/tests/sgsn/sgsn_test.c b/openbsc/tests/sgsn/sgsn_test.c
index 7a14cdefa..5fa33a266 100644
--- a/openbsc/tests/sgsn/sgsn_test.c
+++ b/openbsc/tests/sgsn/sgsn_test.c
@@ -1784,6 +1784,98 @@ static void test_gmm_ptmsi_allocation(void)
sgsn->cfg.auth_policy = saved_auth_policy;
}
+static void test_apn_matching(void)
+{
+ struct apn_ctx *actx, *actxs[9];
+
+ printf("Testing APN matching\n");
+
+ actxs[0] = sgsn_apn_ctx_find_alloc("*.test", "");
+ actxs[1] = sgsn_apn_ctx_find_alloc("*.def.test", "");
+ actxs[2] = sgsn_apn_ctx_find_alloc("abc.def.test", "");
+ actxs[3] = NULL;
+
+ actxs[4] = sgsn_apn_ctx_find_alloc("abc.def.test", "456");
+ actxs[5] = sgsn_apn_ctx_find_alloc("abc.def.test", "456123");
+ actxs[6] = sgsn_apn_ctx_find_alloc("*.def.test", "456");
+ actxs[7] = sgsn_apn_ctx_find_alloc("*.def.test", "456123");
+
+ actxs[8] = sgsn_apn_ctx_find_alloc("ghi.def.test", "456");
+
+ actx = sgsn_apn_ctx_match("abc.def.test", "12345678");
+ OSMO_ASSERT(actx == actxs[2]);
+ actx = sgsn_apn_ctx_match("aBc.dEf.test", "12345678");
+ OSMO_ASSERT(actx == actxs[2]);
+ actx = sgsn_apn_ctx_match("xyz.def.test", "12345678");
+ OSMO_ASSERT(actx == actxs[1]);
+ actx = sgsn_apn_ctx_match("xyz.dEf.test", "12345678");
+ OSMO_ASSERT(actx == actxs[1]);
+ actx = sgsn_apn_ctx_match("xyz.uvw.test", "12345678");
+ OSMO_ASSERT(actx == actxs[0]);
+ actx = sgsn_apn_ctx_match("xyz.uvw.foo", "12345678");
+ OSMO_ASSERT(actx == NULL);
+
+ actxs[3] = sgsn_apn_ctx_find_alloc("*", "");
+ actx = sgsn_apn_ctx_match("xyz.uvw.foo", "12345678");
+ OSMO_ASSERT(actx == actxs[3]);
+
+ actx = sgsn_apn_ctx_match("abc.def.test", "45699900");
+ OSMO_ASSERT(actx == actxs[4]);
+
+ actx = sgsn_apn_ctx_match("xyz.def.test", "45699900");
+ OSMO_ASSERT(actx == actxs[6]);
+
+ actx = sgsn_apn_ctx_match("abc.def.test", "45612300");
+ OSMO_ASSERT(actx == actxs[5]);
+
+ actx = sgsn_apn_ctx_match("xyz.def.test", "45612300");
+ OSMO_ASSERT(actx == actxs[7]);
+
+ actx = sgsn_apn_ctx_match("ghi.def.test", "45699900");
+ OSMO_ASSERT(actx == actxs[8]);
+
+ actx = sgsn_apn_ctx_match("ghi.def.test", "45612300");
+ OSMO_ASSERT(actx == actxs[7]);
+
+ /* Free APN contexts and check how the matching changes */
+
+ sgsn_apn_ctx_free(actxs[7]);
+ actx = sgsn_apn_ctx_match("ghi.def.test", "45612300");
+ OSMO_ASSERT(actx == actxs[8]);
+
+ sgsn_apn_ctx_free(actxs[8]);
+ actx = sgsn_apn_ctx_match("ghi.def.test", "45612300");
+ OSMO_ASSERT(actx == actxs[6]);
+
+ sgsn_apn_ctx_free(actxs[6]);
+ actx = sgsn_apn_ctx_match("ghi.def.test", "45612300");
+ OSMO_ASSERT(actx == actxs[1]);
+
+ sgsn_apn_ctx_free(actxs[5]);
+ actx = sgsn_apn_ctx_match("abc.def.test", "45612300");
+ OSMO_ASSERT(actx == actxs[4]);
+
+ sgsn_apn_ctx_free(actxs[4]);
+ actx = sgsn_apn_ctx_match("abc.def.test", "45612300");
+ OSMO_ASSERT(actx == actxs[2]);
+
+ sgsn_apn_ctx_free(actxs[2]);
+ actx = sgsn_apn_ctx_match("abc.def.test", "12345678");
+ OSMO_ASSERT(actx == actxs[1]);
+
+ sgsn_apn_ctx_free(actxs[1]);
+ actx = sgsn_apn_ctx_match("abc.def.test", "12345678");
+ OSMO_ASSERT(actx == actxs[0]);
+
+ sgsn_apn_ctx_free(actxs[0]);
+ actx = sgsn_apn_ctx_match("abc.def.test", "12345678");
+ OSMO_ASSERT(actx == actxs[3]);
+
+ sgsn_apn_ctx_free(actxs[3]);
+ actx = sgsn_apn_ctx_match("abc.def.test", "12345678");
+ OSMO_ASSERT(actx == NULL);
+}
+
static struct log_info_cat gprs_categories[] = {
[DMM] = {
.name = "DMM",
@@ -1871,6 +1963,7 @@ int main(int argc, char **argv)
test_gmm_reject();
test_gmm_cancel();
test_gmm_ptmsi_allocation();
+ test_apn_matching();
printf("Done\n");
talloc_report_full(osmo_sgsn_ctx, stderr);
diff --git a/openbsc/tests/sgsn/sgsn_test.ok b/openbsc/tests/sgsn/sgsn_test.ok
index e5df50482..9f14721af 100644
--- a/openbsc/tests/sgsn/sgsn_test.ok
+++ b/openbsc/tests/sgsn/sgsn_test.ok
@@ -26,4 +26,5 @@ Testing P-TMSI allocation
- sgsn_alloc_ptmsi
- Repeated Attach Request
- Repeated RA Update Request
+Testing APN matching
Done
diff --git a/openbsc/tests/vty_test_runner.py b/openbsc/tests/vty_test_runner.py
index d87ebde0c..cae1c1414 100644
--- a/openbsc/tests/vty_test_runner.py
+++ b/openbsc/tests/vty_test_runner.py
@@ -794,6 +794,27 @@ class TestVTYSGSN(TestVTYGenericBSC):
res = self.vty.command('show subscriber cache')
self.assert_(res.find('1234567890') < 0)
+ def testVtyGgsn(self):
+ self.vty.enable()
+ self.assertTrue(self.vty.verify('configure terminal', ['']))
+ self.assertEquals(self.vty.node(), 'config')
+ self.assertTrue(self.vty.verify('sgsn', ['']))
+ self.assertEquals(self.vty.node(), 'config-sgsn')
+ self.assertTrue(self.vty.verify('ggsn 0 remote-ip 127.99.99.99', ['']))
+ self.assertTrue(self.vty.verify('ggsn 0 gtp-version 1', ['']))
+ self.assertTrue(self.vty.verify('apn * ggsn 0', ['']))
+ self.assertTrue(self.vty.verify('apn apn1.test ggsn 0', ['']))
+ self.assertTrue(self.vty.verify('apn apn1.test ggsn 1', ['% a GGSN with id 1 has not been defined']))
+ self.assertTrue(self.vty.verify('apn apn1.test imsi-prefix 123456 ggsn 0', ['']))
+ self.assertTrue(self.vty.verify('apn apn2.test imsi-prefix 123456 ggsn 0', ['']))
+ res = self.vty.command("show running-config")
+ self.assert_(res.find('ggsn 0 remote-ip 127.99.99.99') >= 0)
+ self.assert_(res.find('ggsn 0 gtp-version 1') >= 0)
+ self.assert_(res.find('apn * ggsn 0') >= 0)
+ self.assert_(res.find('apn apn1.test ggsn 0') >= 0)
+ self.assert_(res.find('apn apn1.test imsi-prefix 123456 ggsn 0') >= 0)
+ self.assert_(res.find('apn apn2.test imsi-prefix 123456 ggsn 0') >= 0)
+
def add_nat_test(suite, workdir):
if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc_nat/osmo-bsc_nat")):
print("Skipping the NAT test")