From de392254ff05a5304ef0bbd351314d74b2ffd1e3 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Fri, 1 Apr 2016 19:44:00 +0200 Subject: subscr: Add testcase creating an already created subscriber Add testcase to issue the subscriber create twice. db_create_subscriber in db.c will first try to find the subscriber and if it exists, it will update the "updated" column in the database. Related: OS Issue #1657 --- openbsc/tests/vty_test_runner.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'openbsc/tests') diff --git a/openbsc/tests/vty_test_runner.py b/openbsc/tests/vty_test_runner.py index 8db0825e3..ecf5204a4 100644 --- a/openbsc/tests/vty_test_runner.py +++ b/openbsc/tests/vty_test_runner.py @@ -307,6 +307,42 @@ class TestVTYNITB(TestVTYGenericBSC): if classNum != 10: self.assertEquals(res.find("rach access-control-class " + str(classNum) + " barred"), -1) + def testSubscriberCreateDeleteTwice(self): + """ + OS#1657 indicates that there might be an issue creating the + same subscriber twice. This test will use the VTY command to + create a subscriber and then issue a second create command + with the same IMSI. The test passes if the VTY continues to + respond to VTY commands. + """ + self.vty.enable() + + imsi = "204300854013739" + + # Initially we don't have this subscriber + self.vty.verify('show subscriber imsi '+imsi, ['% No subscriber found for imsi '+imsi]) + + # Lets create one + res = self.vty.command('subscriber create imsi '+imsi) + self.assert_(res.find(" IMSI: "+imsi) > 0) + # And now create one again. + res2 = self.vty.command('subscriber create imsi '+imsi) + self.assert_(res2.find(" IMSI: "+imsi) > 0) + self.assertEqual(res, res2) + + # Verify it has been created + res = self.vty.command('show subscriber imsi '+imsi) + self.assert_(res.find(" IMSI: "+imsi) > 0) + + # Delete it + res = self.vty.command('subscriber delete imsi '+imsi) + self.assert_(res != "") + + # Now it should not be there anymore + res = self.vty.command('show subscriber imsi '+imsi) + self.assert_(res != '% No subscriber found for imsi '+imsi) + + def testSubscriberCreateDelete(self): self.vty.enable() -- cgit v1.2.3 From 2826df56b2af5a6a0f20e5a9bcf1d50a1130f0ba Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Fri, 1 Apr 2016 20:21:03 +0200 Subject: subscr: Make db_create_subscriber fail on duplicates The issue of db_create_subscriber updating an already existing subscr is that the same subscriber will then have two entries in the active subscribers list. In general this will break assumptions that a subscr can be compared by comparing the pointer. In the case of the VTY this was not an issue as the created subscr was immediately destroyed again but it is better to avoid this problem. Change the VTY command to find the subscriber and then call sync to have the updated time set. The side-effect is we will now have two queries for the subscriber. Once through subscr_get_by_imsi and once through db_create_subscriber. Change the db_create_subscriber to fail if a subscriber already exists, and add a testcase for this behavior and do not updated the 'updated' timestamp of an already existing subscriber. Add a testcase for this behavior. Related: OS Issue #1657 --- openbsc/tests/db/db_test.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'openbsc/tests') diff --git a/openbsc/tests/db/db_test.c b/openbsc/tests/db/db_test.c index a02d1f801..fb159a5b1 100644 --- a/openbsc/tests/db/db_test.c +++ b/openbsc/tests/db/db_test.c @@ -1,5 +1,5 @@ /* (C) 2008 by Jan Luebbe - * (C) 2009 by Holger Hans Peter Freyther + * (C) 2009-2016 by Holger Hans Peter Freyther * (C) 2014 by Alexander Chemeris * All Rights Reserved * @@ -246,6 +246,10 @@ int main() SUBSCR_PUT(alice_db); SUBSCR_PUT(alice); + /* create it again and see it fails */ + alice = db_create_subscriber(alice_imsi); + OSMO_ASSERT(!alice); + test_sms(); test_sms_migrate(); -- cgit v1.2.3 From 9bcb1a56cbec710cbfa49ae6623c10595eab08ec Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Wed, 6 Apr 2016 22:41:12 +0200 Subject: ctrl: Extend ctrl command to optionally handle alg+ki Extend the existing ctrl command to be able to specify the algorithm and Ki. In contrast to the VTY no size check is done. Together with the VTY this code only supports a small part of what is supported by libosmocore. The algorithm and ki are considered optional but if a valid algorithm other than "none" is passed, a KI must be passed as well. Extend the test coverage by passing the potential values. It is not verified that the KI/algorithm is stored. --- openbsc/tests/ctrl_test_runner.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'openbsc/tests') diff --git a/openbsc/tests/ctrl_test_runner.py b/openbsc/tests/ctrl_test_runner.py index 21850e348..7a126437c 100644 --- a/openbsc/tests/ctrl_test_runner.py +++ b/openbsc/tests/ctrl_test_runner.py @@ -469,6 +469,33 @@ class TestCtrlNITB(TestCtrlBase): self.assertEquals(r['var'], 'number-of-bts') self.assertEquals(r['value'], '1') + def testSubscriberAddWithKi(self): + """Test that we can set the algorithm to none, xor, comp128v1""" + + r = self.do_set('subscriber-modify-v1', '2620345,445566') + self.assertEquals(r['mtype'], 'SET_REPLY') + self.assertEquals(r['var'], 'subscriber-modify-v1') + self.assertEquals(r['value'], 'OK') + + r = self.do_set('subscriber-modify-v1', '2620345,445566,none') + self.assertEquals(r['mtype'], 'SET_REPLY') + self.assertEquals(r['var'], 'subscriber-modify-v1') + self.assertEquals(r['value'], 'OK') + + r = self.do_set('subscriber-modify-v1', '2620345,445566,xor') + self.assertEquals(r['mtype'], 'ERROR') + self.assertEquals(r['error'], 'Value failed verification.') + + r = self.do_set('subscriber-modify-v1', '2620345,445566,comp128v1,00112233445566778899AABBCCDDEEFF') + self.assertEquals(r['mtype'], 'SET_REPLY') + self.assertEquals(r['var'], 'subscriber-modify-v1') + self.assertEquals(r['value'], 'OK') + + r = self.do_set('subscriber-modify-v1', '2620345,445566,none') + self.assertEquals(r['mtype'], 'SET_REPLY') + self.assertEquals(r['var'], 'subscriber-modify-v1') + self.assertEquals(r['value'], 'OK') + def testSubscriberAddRemove(self): r = self.do_set('subscriber-modify-v1', '2620345,445566') self.assertEquals(r['mtype'], 'SET_REPLY') -- cgit v1.2.3 From 714b170f895dfdc2f0d725ab110baf3dc14ef874 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 7 Apr 2016 12:27:11 +0200 Subject: NAT: allow allocating BSC in arbitrary order Check for existing BSC before allocating new one. Track number of remaining BSCs on deallocation. Explicitly use BSC number in allocation function. --- openbsc/tests/bsc-nat/bsc_nat_test.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'openbsc/tests') diff --git a/openbsc/tests/bsc-nat/bsc_nat_test.c b/openbsc/tests/bsc-nat/bsc_nat_test.c index a4b313c91..a405763bc 100644 --- a/openbsc/tests/bsc-nat/bsc_nat_test.c +++ b/openbsc/tests/bsc-nat/bsc_nat_test.c @@ -316,7 +316,7 @@ static void test_contrack() printf("Testing connection tracking.\n"); nat = bsc_nat_alloc(); con = bsc_connection_alloc(nat); - con->cfg = bsc_config_alloc(nat, "foo"); + con->cfg = bsc_config_alloc(nat, "foo", 0); bsc_config_add_lac(con->cfg, 23); bsc_config_add_lac(con->cfg, 49); bsc_config_add_lac(con->cfg, 42); @@ -434,7 +434,7 @@ static void test_paging(void) nat = bsc_nat_alloc(); con = bsc_connection_alloc(nat); - cfg = bsc_config_alloc(nat, "unknown"); + cfg = bsc_config_alloc(nat, "unknown", 0); con->cfg = cfg; bsc_config_add_lac(cfg, 23); con->authenticated = 1; @@ -476,7 +476,7 @@ static void test_mgcp_allocations(void) nat->mgcp_cfg->trunk.number_endpoints = 64; bsc = bsc_connection_alloc(nat); - bsc->cfg = bsc_config_alloc(nat, "foo"); + bsc->cfg = bsc_config_alloc(nat, "foo", 0); bsc->cfg->max_endpoints = 60; bsc_config_add_lac(bsc->cfg, 2323); bsc->last_endpoint = 0x22; @@ -522,7 +522,7 @@ static void test_mgcp_ass_tracking(void) mgcp_endpoints_allocate(&nat->mgcp_cfg->trunk); bsc = bsc_connection_alloc(nat); - bsc->cfg = bsc_config_alloc(nat, "foo"); + bsc->cfg = bsc_config_alloc(nat, "foo", 0); bsc_config_add_lac(bsc->cfg, 2323); bsc->last_endpoint = 0x1e; con.bsc = bsc; @@ -874,7 +874,7 @@ static void test_cr_filter() struct bsc_nat *nat = bsc_nat_alloc(); struct bsc_connection *bsc = bsc_connection_alloc(nat); - bsc->cfg = bsc_config_alloc(nat, "foo"); + bsc->cfg = bsc_config_alloc(nat, "foo", 0); bsc_config_add_lac(bsc->cfg, 1234); bsc->cfg->acc_lst_name = "bsc"; nat->acc_lst_name = "nat"; @@ -953,7 +953,7 @@ static void test_dt_filter() struct bsc_connection *bsc = bsc_connection_alloc(nat); struct nat_sccp_connection *con = talloc_zero(0, struct nat_sccp_connection); - bsc->cfg = bsc_config_alloc(nat, "foo"); + bsc->cfg = bsc_config_alloc(nat, "foo", 0); bsc_config_add_lac(bsc->cfg, 23); con->bsc = bsc; @@ -1525,7 +1525,7 @@ static void test_nat_extract_lac() /* initialize the testcase */ nat = bsc_nat_alloc(); bsc = bsc_connection_alloc(nat); - bsc->cfg = bsc_config_alloc(nat, "foo"); + bsc->cfg = bsc_config_alloc(nat, "foo", 0); memset(&con, 0, sizeof(con)); con.bsc = bsc; -- cgit v1.2.3 From 70cf7290da7cfca796eed8ffbd143073d9418dd2 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 13 Apr 2016 11:36:38 +0200 Subject: vty_test_runner: update ipa sending code Factor out 2, add 3 functions. Those functions are simple wrappers around hex strings specific to IPA protocol. Not all of them are utilized at the moment but they were checked with wireshark while working on the tests. It might come in handy if we'd like to further expand related test harness in future. The same goes for optional verbosity argument which is not used right now but will be handy for future debugging. --- openbsc/tests/vty_test_runner.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'openbsc/tests') diff --git a/openbsc/tests/vty_test_runner.py b/openbsc/tests/vty_test_runner.py index ecf5204a4..d57412989 100644 --- a/openbsc/tests/vty_test_runner.py +++ b/openbsc/tests/vty_test_runner.py @@ -736,13 +736,13 @@ class TestVTYNAT(TestVTYGenericBSC): self.assertEqual(data, "\x00\x01\xfe\x04") print "Going to send ID_RESP response" - res = ussdSocket.send("\x00\x07\xfe\x05\x00\x04\x01\x6b\x65\x79") + res = ipa_send_resp(ussdSocket, "\x6b\x65\x79") self.assertEqual(res, 10) # initiating PING/PONG cycle to know, that the ID_RESP message has been processed print "Going to send PING request" - res = ussdSocket.send("\x00\x01\xfe\x00") + res = ipa_send_ping(ussdSocket) self.assertEqual(res, 4) print "Expecting PONG response" @@ -1007,6 +1007,31 @@ def add_nat_test(suite, workdir): test = unittest.TestLoader().loadTestsFromTestCase(TestVTYNAT) suite.addTest(test) +def ipa_send_pong(x, verbose = False): + if (verbose): + print "\tBSC -> NAT: PONG!" + return x.send("\x00\x01\xfe\x01") + +def ipa_send_ping(x, verbose = False): + if (verbose): + print "\tBSC -> NAT: PING?" + return x.send("\x00\x01\xfe\x00") + +def ipa_send_ack(x, verbose = False): + if (verbose): + print "\tBSC -> NAT: IPA ID ACK" + return x.send("\x00\x01\xfe\x06") + +def ipa_send_reset(x, verbose = False): + if (verbose): + print "\tBSC -> NAT: RESET" + return x.send("\x00\x12\xfd\x09\x00\x03\x05\x07\x02\x42\xfe\x02\x42\xfe\x06\x00\x04\x30\x04\x01\x20") + +def ipa_send_resp(x, tk, verbose = False): + if (verbose): + print "\tBSC -> NAT: IPA ID RESP" + return x.send("\x00\x07\xfe\x05\x00\x04\x01" + tk) + def add_bsc_test(suite, workdir): if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc/osmo-bsc")): print("Skipping the BSC test") -- cgit v1.2.3 From 4936448761a6ca42ab661d130f5202dfdabca426 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 13 Apr 2016 11:36:39 +0200 Subject: NAT: reload BSCs config dynamically Add vty tests for BSC configuration reloading. Load BSCs configuration on bscs-config-file command: * remove all runtime configured BSC not in the config file * close connections to all BSC with updated token value Fixes: OS#1670 Sponsored-by: On-Waves ehf --- openbsc/tests/vty_test_runner.py | 120 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 119 insertions(+), 1 deletion(-) (limited to 'openbsc/tests') diff --git a/openbsc/tests/vty_test_runner.py b/openbsc/tests/vty_test_runner.py index d57412989..59fdd2f93 100644 --- a/openbsc/tests/vty_test_runner.py +++ b/openbsc/tests/vty_test_runner.py @@ -620,12 +620,61 @@ class TestVTYBSC(TestVTYGenericBSC): class TestVTYNAT(TestVTYGenericBSC): def vty_command(self): - return ["./src/osmo-bsc_nat/osmo-bsc_nat", "-c", + return ["./src/osmo-bsc_nat/osmo-bsc_nat", "-l", "127.0.0.1", "-c", "doc/examples/osmo-bsc_nat/osmo-bsc_nat.cfg"] def vty_app(self): return (4244, "src/osmo-bsc_nat/osmo-bsc_nat", "OsmoBSCNAT", "nat") + def testBSCreload(self): + # use separate ip to avoid interference with other tests + ip = "127.0.0.4" + self.vty.enable() + bscs1 = self.vty.command("show bscs-config") + nat_bsc_reload(self) + bscs2 = self.vty.command("show bscs-config") + # check that multiple calls to bscs-config-file give the same result + self.assertEquals(bscs1, bscs2) + + # add new bsc + self.vty.command("configure terminal") + self.vty.command("nat") + self.vty.command("bsc 5") + self.vty.command("token key") + self.vty.command("location_area_code 666") + self.vty.command("end") + + # update bsc token + self.vty.command("configure terminal") + self.vty.command("nat") + self.vty.command("bsc 1") + self.vty.command("token xyu") + self.vty.command("end") + + nat_msc_ip(self, ip) + msc = nat_msc_test(self, ip) + b0 = nat_bsc_sock_test(0, "lol") + b1 = nat_bsc_sock_test(1, "xyu") + b2 = nat_bsc_sock_test(5, "key") + + self.assertEquals("3 BSCs configured", self.vty.command("show nat num-bscs-configured")) + self.assertTrue(3 == nat_bsc_num_con(self)) + self.assertEquals("MSC is connected: 1", self.vty.command("show msc connection")) + + nat_bsc_reload(self) + bscs2 = self.vty.command("show bscs-config") + # check that the reset to initial config succeeded + self.assertEquals(bscs1, bscs2) + + self.assertEquals("2 BSCs configured", self.vty.command("show nat num-bscs-configured")) + self.assertTrue(1 == nat_bsc_num_con(self)) + rem = self.vty.command("show bsc connections").split(' ') + # remaining connection is for BSC0 + self.assertEquals('0', rem[2]) + # remaining connection is authorized + self.assertEquals('1', rem[4]) + self.assertEquals("MSC is connected: 1", self.vty.command("show msc connection")) + def testVtyTree(self): self.vty.enable() self.assertTrue(self.vty.verify('configure terminal', [''])) @@ -1032,6 +1081,75 @@ def ipa_send_resp(x, tk, verbose = False): print "\tBSC -> NAT: IPA ID RESP" return x.send("\x00\x07\xfe\x05\x00\x04\x01" + tk) +def nat_bsc_reload(x): + x.vty.command("configure terminal") + x.vty.command("nat") + x.vty.command("bscs-config-file bscs.config") + x.vty.command("end") + +def nat_msc_ip(x, ip): + x.vty.command("configure terminal") + x.vty.command("nat") + x.vty.command("msc ip " + ip) + x.vty.command("end") + +def data2str(d): + return "".join("{:02x}".format(ord(c)) for c in d) + +def nat_msc_test(x, ip, verbose = False): + msc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + msc.settimeout(32) + msc.bind((ip, 5000)) + msc.listen(5) + if (verbose): + print "MSC is ready at " + ip + while "MSC is connected: 0" == x.vty.command("show msc connection"): + conn, addr = msc.accept() + if (verbose): + print "MSC got connection from ", addr + return conn + +def ipa_handle_small(x, verbose = False): + s = data2str(x.recv(4)) + if "0001fe00" == s: + if (verbose): + print "\tBSC <- NAT: PING?" + ipa_send_pong(x, verbose) + elif "0001fe06" == s: + if (verbose): + print "\tBSC <- NAT: IPA ID ACK" + ipa_send_ack(x, verbose) + elif "0001fe00" == s: + if (verbose): + print "\tBSC <- NAT: PONG!" + else: + if (verbose): + print "\tBSC <- NAT: ", s + +def ipa_handle_resp(x, tk, verbose = False): + s = data2str(x.recv(38)) + if "0023fe040108010701020103010401050101010011" in s: + ipa_send_resp(x, tk, verbose) + else: + if (verbose): + print "\tBSC <- NAT: ", s + +def nat_bsc_num_con(x): + return len(x.vty.command("show bsc connections").split('\n')) + +def nat_bsc_sock_test(nr, tk, verbose = False): + bsc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + bsc.bind(('127.0.0.1' + str(nr), 0)) + bsc.connect(('127.0.0.1', 5000)) + if (verbose): + print "BSC%d " %nr + print "\tconnected to %s:%d" % bsc.getpeername() + ipa_handle_small(bsc, verbose) + ipa_handle_resp(bsc, tk, verbose) + bsc.recv(27) # MGCP msg + ipa_handle_small(bsc, verbose) + return bsc + def add_bsc_test(suite, workdir): if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc/osmo-bsc")): print("Skipping the BSC test") -- cgit v1.2.3 From f1a61bb99f13b054d912f47dac90a15b2cf56651 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Thu, 14 Apr 2016 08:50:25 -0400 Subject: nat/vty: Don't assume one can magically add IPv4 addresses to lo Don't assume that one can just bind to a local address that has not been configured. Remove the unspecific comment as I don't know to which other tests it is referred to. This should fix: ====================================================================== ERROR: testBSCreload (__main__.TestVTYNAT) ---------------------------------------------------------------------- Traceback (most recent call last): File "./vty_test_runner.py", line 655, in testBSCreload msc = nat_msc_test(self, ip) File "./vty_test_runner.py", line 1102, in nat_msc_test msc.bind((ip, 5000)) File "", line 1, in bind error: [Errno 99] Cannot assign requested address ---------------------------------------------------------------------- --- openbsc/tests/vty_test_runner.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'openbsc/tests') diff --git a/openbsc/tests/vty_test_runner.py b/openbsc/tests/vty_test_runner.py index 59fdd2f93..11b788bcc 100644 --- a/openbsc/tests/vty_test_runner.py +++ b/openbsc/tests/vty_test_runner.py @@ -627,8 +627,7 @@ class TestVTYNAT(TestVTYGenericBSC): return (4244, "src/osmo-bsc_nat/osmo-bsc_nat", "OsmoBSCNAT", "nat") def testBSCreload(self): - # use separate ip to avoid interference with other tests - ip = "127.0.0.4" + ip = "127.0.0.1" self.vty.enable() bscs1 = self.vty.command("show bscs-config") nat_bsc_reload(self) -- cgit v1.2.3 From 44ed4979c9fc6143023aad796cfd8628b08fc47a Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Thu, 14 Apr 2016 10:05:13 -0400 Subject: nat/vty: Use different port for the mock MSC Update the comment to reflect that the NAT itself will bind to port 5000 and then the mock MSC will fail to bind to it. Try to move the mock MSC to another port. Could fix: ====================================================================== ERROR: testBSCreload (__main__.TestVTYNAT) ---------------------------------------------------------------------- Traceback (most recent call last): File "./vty_test_runner.py", line 654, in testBSCreload msc = nat_msc_test(self, ip) File "./vty_test_runner.py", line 1101, in nat_msc_test msc.bind((ip, 5000)) File "", line 1, in bind error: [Errno 98] Address already in use ---------------------------------------------------------------------- --- openbsc/tests/vty_test_runner.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'openbsc/tests') diff --git a/openbsc/tests/vty_test_runner.py b/openbsc/tests/vty_test_runner.py index 11b788bcc..a4cfb607f 100644 --- a/openbsc/tests/vty_test_runner.py +++ b/openbsc/tests/vty_test_runner.py @@ -627,7 +627,10 @@ class TestVTYNAT(TestVTYGenericBSC): return (4244, "src/osmo-bsc_nat/osmo-bsc_nat", "OsmoBSCNAT", "nat") def testBSCreload(self): + # Use different port for the mock msc to avoid clashing with + # the osmo-bsc_nat itself ip = "127.0.0.1" + port = 5001 self.vty.enable() bscs1 = self.vty.command("show bscs-config") nat_bsc_reload(self) @@ -650,8 +653,8 @@ class TestVTYNAT(TestVTYGenericBSC): self.vty.command("token xyu") self.vty.command("end") - nat_msc_ip(self, ip) - msc = nat_msc_test(self, ip) + nat_msc_ip(self, ip, port) + msc = nat_msc_test(self, ip, port) b0 = nat_bsc_sock_test(0, "lol") b1 = nat_bsc_sock_test(1, "xyu") b2 = nat_bsc_sock_test(5, "key") @@ -1086,19 +1089,20 @@ def nat_bsc_reload(x): x.vty.command("bscs-config-file bscs.config") x.vty.command("end") -def nat_msc_ip(x, ip): +def nat_msc_ip(x, ip, port): x.vty.command("configure terminal") x.vty.command("nat") x.vty.command("msc ip " + ip) + x.vty.command("msc port " + port) x.vty.command("end") def data2str(d): return "".join("{:02x}".format(ord(c)) for c in d) -def nat_msc_test(x, ip, verbose = False): +def nat_msc_test(x, ip, port, verbose = False): msc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) msc.settimeout(32) - msc.bind((ip, 5000)) + msc.bind((ip, port)) msc.listen(5) if (verbose): print "MSC is ready at " + ip -- cgit v1.2.3 From 84ae27e7314ad1743c8fbdb2feae372122355066 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Thu, 14 Apr 2016 10:40:06 -0400 Subject: nat/vty: Convert into str for the VTY command ====================================================================== ERROR: testBSCreload (__main__.TestVTYNAT) ---------------------------------------------------------------------- Traceback (most recent call last): File "./vty_test_runner.py", line 656, in testBSCreload nat_msc_ip(self, ip, port) File "./vty_test_runner.py", line 1096, in nat_msc_ip x.vty.command("msc port " + port) TypeError: cannot concatenate 'str' and 'int' objects ---------------------------------------------------------------------- --- openbsc/tests/vty_test_runner.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'openbsc/tests') diff --git a/openbsc/tests/vty_test_runner.py b/openbsc/tests/vty_test_runner.py index a4cfb607f..f56b5764b 100644 --- a/openbsc/tests/vty_test_runner.py +++ b/openbsc/tests/vty_test_runner.py @@ -1093,7 +1093,7 @@ def nat_msc_ip(x, ip, port): x.vty.command("configure terminal") x.vty.command("nat") x.vty.command("msc ip " + ip) - x.vty.command("msc port " + port) + x.vty.command("msc port " + str(port)) x.vty.command("end") def data2str(d): -- cgit v1.2.3 From e98c9c7136e2612cedf87105eafe12fedff1f9a0 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Thu, 14 Apr 2016 10:58:58 -0400 Subject: nat/vty: And move to a different port.. --- openbsc/tests/vty_test_runner.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'openbsc/tests') diff --git a/openbsc/tests/vty_test_runner.py b/openbsc/tests/vty_test_runner.py index f56b5764b..3c2c233ed 100644 --- a/openbsc/tests/vty_test_runner.py +++ b/openbsc/tests/vty_test_runner.py @@ -630,7 +630,7 @@ class TestVTYNAT(TestVTYGenericBSC): # Use different port for the mock msc to avoid clashing with # the osmo-bsc_nat itself ip = "127.0.0.1" - port = 5001 + port = 5522 self.vty.enable() bscs1 = self.vty.command("show bscs-config") nat_bsc_reload(self) -- cgit v1.2.3 From 2abf2b072d7616ffa760461b6d6bd44a28490066 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Thu, 14 Apr 2016 21:13:51 -0400 Subject: nat/vty: Remove second assumption about lo and binding If we want to separate the BSCs we should separate based on the source port and not the source ip (at least in the current test setup). Fixes: ====================================================================== ERROR: testBSCreload (__main__.TestVTYNAT) ---------------------------------------------------------------------- Traceback (most recent call last): File "./vty_test_runner.py", line 658, in testBSCreload b0 = nat_bsc_sock_test(0, "lol") File "./vty_test_runner.py", line 1145, in nat_bsc_sock_test bsc.bind(('127.0.0.1' + str(nr), 0)) File "", line 1, in bind error: [Errno 99] Cannot assign requested address ---------------------------------------------------------------------- --- openbsc/tests/vty_test_runner.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'openbsc/tests') diff --git a/openbsc/tests/vty_test_runner.py b/openbsc/tests/vty_test_runner.py index 3c2c233ed..a767ff075 100644 --- a/openbsc/tests/vty_test_runner.py +++ b/openbsc/tests/vty_test_runner.py @@ -1142,7 +1142,7 @@ def nat_bsc_num_con(x): def nat_bsc_sock_test(nr, tk, verbose = False): bsc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - bsc.bind(('127.0.0.1' + str(nr), 0)) + bsc.bind(('127.0.0.1', 0)) bsc.connect(('127.0.0.1', 5000)) if (verbose): print "BSC%d " %nr -- cgit v1.2.3 From 8bb6204d50373ad99b769f8cf42850ae30551c08 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Thu, 14 Apr 2016 21:40:04 -0400 Subject: nat/vty: Fix construct not working with python 2.6 Use the simpler approach and just call encode('hex') on the str and then convert it to lower case to keep the tests working. reproduce: Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> d = '\0\0' >>> d '\x00\x00' >>> "".join("{:02x}".format(ord(c)) for c in d) Traceback (most recent call last): File "", line 1, in File "", line 1, in ValueError: zero length field name in format fixes: ====================================================================== ERROR: testBSCreload (__main__.TestVTYNAT) ---------------------------------------------------------------------- Traceback (most recent call last): File "./vty_test_runner.py", line 658, in testBSCreload b0 = nat_bsc_sock_test(0, "lol") File "./vty_test_runner.py", line 1150, in nat_bsc_sock_test ipa_handle_small(bsc, verbose) File "./vty_test_runner.py", line 1116, in ipa_handle_small s = data2str(x.recv(4)) File "./vty_test_runner.py", line 1100, in data2str return "".join("{:02x}".format(ord(c)) for c in d) File "./vty_test_runner.py", line 1100, in return "".join("{:02x}".format(ord(c)) for c in d) ValueError: zero length field name in format ---------------------------------------------------------------------- --- openbsc/tests/vty_test_runner.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'openbsc/tests') diff --git a/openbsc/tests/vty_test_runner.py b/openbsc/tests/vty_test_runner.py index a767ff075..143ba5d00 100644 --- a/openbsc/tests/vty_test_runner.py +++ b/openbsc/tests/vty_test_runner.py @@ -1097,7 +1097,7 @@ def nat_msc_ip(x, ip, port): x.vty.command("end") def data2str(d): - return "".join("{:02x}".format(ord(c)) for c in d) + return d.encode('hex').lower() def nat_msc_test(x, ip, port, verbose = False): msc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) -- cgit v1.2.3 From c9ac20ea43e0107c293b5d3f5c90076963e95059 Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Thu, 14 Apr 2016 15:21:33 +0200 Subject: gbproxy_test: assert msg allocation (CID #57873) --- openbsc/tests/gbproxy/gbproxy_test.c | 1 + 1 file changed, 1 insertion(+) (limited to 'openbsc/tests') diff --git a/openbsc/tests/gbproxy/gbproxy_test.c b/openbsc/tests/gbproxy/gbproxy_test.c index 0ba827f76..96a68b0e5 100644 --- a/openbsc/tests/gbproxy/gbproxy_test.c +++ b/openbsc/tests/gbproxy/gbproxy_test.c @@ -1293,6 +1293,7 @@ static int gprs_process_message(struct gprs_ns_inst *nsi, const char *text, stru } msg = gprs_ns_msgb_alloc(); + OSMO_ASSERT(msg); memmove(msg->data, data, data_len); msg->l2h = msg->data; msgb_put(msg, data_len); -- cgit v1.2.3 From 59a1bf3dae0d0a9e914d3c615c6aa7fc8955d7b5 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 15 Apr 2016 16:04:46 +0200 Subject: Add basic SI2quater support * support for sending arbitrary static SI2quater. * vty interface for neightbor EARFCNs specific to SI2quater. * dynamic generation of SI2quater messages. * unit test for SI2quater messages. Fixes: OS#1630 --- openbsc/tests/gsm0408/Makefile.am | 3 +- openbsc/tests/gsm0408/gsm0408_test.c | 69 +++++++++++++++++++++++++++++++++++ openbsc/tests/gsm0408/gsm0408_test.ok | 8 ++++ 3 files changed, 79 insertions(+), 1 deletion(-) (limited to 'openbsc/tests') diff --git a/openbsc/tests/gsm0408/Makefile.am b/openbsc/tests/gsm0408/Makefile.am index 1c29ece12..ee04102bb 100644 --- a/openbsc/tests/gsm0408/Makefile.am +++ b/openbsc/tests/gsm0408/Makefile.am @@ -7,6 +7,7 @@ EXTRA_DIST = gsm0408_test.ok gsm0408_test_SOURCES = gsm0408_test.c gsm0408_test_LDADD = $(top_builddir)/src/libbsc/libbsc.a \ $(top_builddir)/src/libmsc/libmsc.a \ + $(top_builddir)/src/libtrau/libtrau.a \ $(top_builddir)/src/libbsc/libbsc.a \ $(top_builddir)/src/libcommon/libcommon.a \ - $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) -ldbi + $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOABIS_LIBS) -ldbi diff --git a/openbsc/tests/gsm0408/gsm0408_test.c b/openbsc/tests/gsm0408/gsm0408_test.c index 781ef6147..d6abce61c 100644 --- a/openbsc/tests/gsm0408/gsm0408_test.c +++ b/openbsc/tests/gsm0408/gsm0408_test.c @@ -29,7 +29,11 @@ #include #include #include +#include +#include + #include +#include #define COMPARE(result, op, value) \ if (!((result) op (value))) {\ @@ -79,6 +83,70 @@ static void test_location_area_identifier(void) COMPARE(lai48.lac, ==, htons(0x000f)); } +static inline void add_arfcn_b(struct osmo_earfcn_si2q *e, uint16_t earfcn, + uint8_t bw) +{ + int r = osmo_earfcn_add(e, earfcn, bw); + if (r) + printf("failed to add EARFCN %u: %s\n", earfcn, strerror(r)); + else + printf("added EARFCN %u - ", earfcn); +} + +static inline void gen(struct gsm_bts *bts) +{ + int r = gsm_generate_si(bts, SYSINFO_TYPE_2quater); + if (r > 0) + printf("generated SI2quater: [%d] %s\n", r, + osmo_hexdump(bts->si_buf[SYSINFO_TYPE_2quater], r)); + else + printf("failed to generate SI2quater: %s\n", strerror(-r)); +} + +static inline void test_si2q(void) +{ + struct gsm_bts *bts; + struct gsm_network *network = gsm_network_init(1, 1, NULL); + printf("Testing SYSINFO_TYPE_2quater generation:\n"); + + if (!network) + exit(1); + bts = gsm_bts_alloc(network); + + bts->si_common.si2quater_neigh_list.arfcn = + bts->si_common.data.earfcn_list; + bts->si_common.si2quater_neigh_list.meas_bw = + bts->si_common.data.meas_bw_list; + bts->si_common.si2quater_neigh_list.length = MAX_EARFCN_LIST; + bts->si_common.si2quater_neigh_list.thresh_hi = 5; + + osmo_earfcn_init(&bts->si_common.si2quater_neigh_list); + + add_arfcn_b(&bts->si_common.si2quater_neigh_list, 1917, 1); + gen(bts); + + add_arfcn_b(&bts->si_common.si2quater_neigh_list, 1932, + OSMO_EARFCN_MEAS_INVALID); + gen(bts); + + add_arfcn_b(&bts->si_common.si2quater_neigh_list, 1937, 2); + gen(bts); + + add_arfcn_b(&bts->si_common.si2quater_neigh_list, 1945, + OSMO_EARFCN_MEAS_INVALID); + gen(bts); + + add_arfcn_b(&bts->si_common.si2quater_neigh_list, 1965, + OSMO_EARFCN_MEAS_INVALID); + gen(bts); + + add_arfcn_b(&bts->si_common.si2quater_neigh_list, 1967, 4); + gen(bts); + + add_arfcn_b(&bts->si_common.si2quater_neigh_list, 1982, 3); + gen(bts); +} + static void test_mi_functionality(void) { const char *imsi_odd = "987654321098763"; @@ -486,6 +554,7 @@ int main(int argc, char **argv) test_range_encoding(); test_gsm411_rp_ref_wrap(); + test_si2q(); printf("Done.\n"); return EXIT_SUCCESS; } diff --git a/openbsc/tests/gsm0408/gsm0408_test.ok b/openbsc/tests/gsm0408/gsm0408_test.ok index 058563aab..59319bfeb 100644 --- a/openbsc/tests/gsm0408/gsm0408_test.ok +++ b/openbsc/tests/gsm0408/gsm0408_test.ok @@ -62,4 +62,12 @@ testing RP-Reference wrap Allocated reference: 255 Allocated reference: 0 Allocated reference: 1 +Testing SYSINFO_TYPE_2quater generation: +added EARFCN 1917 - generated SI2quater: [23] 59 06 07 c0 00 04 86 59 83 be c8 50 0b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b +added EARFCN 1932 - generated SI2quater: [23] 59 06 07 c0 00 04 86 59 83 be cc 1e 30 14 03 2b 2b 2b 2b 2b 2b 2b 2b +added EARFCN 1937 - generated SI2quater: [23] 59 06 07 c0 00 04 86 59 83 be cc 1e 31 07 91 a0 a0 2b 2b 2b 2b 2b 2b +added EARFCN 1945 - generated SI2quater: [23] 59 06 07 c0 00 04 86 59 83 be cc 1e 31 07 91 a8 3c c8 28 0b 2b 2b 2b +added EARFCN 1965 - generated SI2quater: [23] 59 06 07 c0 00 04 86 59 83 be cc 1e 31 07 91 a8 3c ca 0f 5a 0a 03 2b +added EARFCN 1967 - failed to generate SI2quater: Cannot allocate memory +added EARFCN 1982 - failed to generate SI2quater: Cannot allocate memory Done. -- cgit v1.2.3 From 0c1bc26b644c2ea7832afd615e9269095921c159 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 20 Apr 2016 12:06:06 +0200 Subject: Fix earfcn deletion * fix typo in arg index * fix sign in error reporting * add vty test --- openbsc/tests/vty_test_runner.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'openbsc/tests') diff --git a/openbsc/tests/vty_test_runner.py b/openbsc/tests/vty_test_runner.py index 143ba5d00..7f64a80d3 100644 --- a/openbsc/tests/vty_test_runner.py +++ b/openbsc/tests/vty_test_runner.py @@ -231,6 +231,20 @@ class TestVTYNITB(TestVTYGenericBSC): self.assertEquals(self.vty.node(), 'config-mncc-int') + def testSi2Q(self): + self.vty.enable() + self.vty.command("configure terminal") + self.vty.command("network") + self.vty.command("bts 0") + before = self.vty.command("show running-config") + self.vty.command("si2quater neighbor-list add earfcn 1911 threshold 11 2") + self.vty.command("si2quater neighbor-list add earfcn 1924 threshold 11 3") + self.vty.command("si2quater neighbor-list add earfcn 2111 threshold 11") + self.vty.command("si2quater neighbor-list del earfcn 1911") + self.vty.command("si2quater neighbor-list del earfcn 1924") + self.vty.command("si2quater neighbor-list del earfcn 2111") + self.assertEquals(before, self.vty.command("show running-config")) + def testEnableDisablePeriodicLU(self): self.vty.enable() self.vty.command("configure terminal") -- cgit v1.2.3 From 26679e0475593aca645c7029e1aad899da73217a Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 20 Apr 2016 15:57:13 +0200 Subject: Add basic UARFCN support * add data structures, generation functions * vty interface for neightbor UARFCNs specific to SI2quater * vty test * unit test Fixes: OS#1666 --- openbsc/tests/gsm0408/gsm0408_test.c | 75 +++++++++++++++++++++++++---------- openbsc/tests/gsm0408/gsm0408_test.ok | 14 ++++++- openbsc/tests/vty_test_runner.py | 23 +++++++++++ 3 files changed, 91 insertions(+), 21 deletions(-) (limited to 'openbsc/tests') diff --git a/openbsc/tests/gsm0408/gsm0408_test.c b/openbsc/tests/gsm0408/gsm0408_test.c index d6abce61c..2d91b68f0 100644 --- a/openbsc/tests/gsm0408/gsm0408_test.c +++ b/openbsc/tests/gsm0408/gsm0408_test.c @@ -103,11 +103,55 @@ static inline void gen(struct gsm_bts *bts) printf("failed to generate SI2quater: %s\n", strerror(-r)); } -static inline void test_si2q(void) +static inline void test_si2q_u(void) { struct gsm_bts *bts; struct gsm_network *network = gsm_network_init(1, 1, NULL); - printf("Testing SYSINFO_TYPE_2quater generation:\n"); + printf("Testing SYSINFO_TYPE_2quater UARFCN generation:\n"); + + if (!network) + exit(1); + bts = gsm_bts_alloc(network); + + bts_uarfcn_add(bts, 1982, 13, 1); + gen(bts); + + bts_uarfcn_add(bts, 1982, 44, 0); + gen(bts); + + bts_uarfcn_add(bts, 1982, 61, 1); + gen(bts); + + bts_uarfcn_add(bts, 1982, 89, 1); + gen(bts); + + bts_uarfcn_add(bts, 1982, 113, 0); + gen(bts); + + bts_uarfcn_add(bts, 1982, 123, 0); + gen(bts); + + bts_uarfcn_add(bts, 1982, 56, 1); + gen(bts); + + bts_uarfcn_add(bts, 1982, 72, 1); + gen(bts); + + bts_uarfcn_add(bts, 1982, 223, 1); + gen(bts); + + bts_uarfcn_add(bts, 1982, 14, 0); + gen(bts); + + bts_uarfcn_add(bts, 1982, 88, 0); + gen(bts); +} + +static inline void test_si2q_e(void) +{ + struct gsm_bts *bts; + struct gsm_network *network = gsm_network_init(1, 1, NULL); + printf("Testing SYSINFO_TYPE_2quater EARFCN generation:\n"); if (!network) exit(1); @@ -230,11 +274,7 @@ static int test_single_range_encoding(int range, const int *orig_arfcns, f0, &f0_included); memset(w, 0, sizeof(w)); - rc = range_enc_arfcns(range, arfcns, arfcns_used, w, 0); - if (rc != 0) { - printf("Cannot compute range W(k), rc = %d\n", rc); - return 1; - } + range_enc_arfcns(range, arfcns, arfcns_used, w, 0); if (!silent) fprintf(stderr, "range=%d, arfcns_used=%d, f0=%d, f0_included=%d\n", @@ -243,24 +283,20 @@ static int test_single_range_encoding(int range, const int *orig_arfcns, /* Select the range and the amount of bits needed */ switch (range) { case ARFCN_RANGE_128: - rc = range_enc_range128(chan_list, f0, w); + range_enc_range128(chan_list, f0, w); break; case ARFCN_RANGE_256: - rc = range_enc_range256(chan_list, f0, w); + range_enc_range256(chan_list, f0, w); break; case ARFCN_RANGE_512: - rc = range_enc_range512(chan_list, f0, w); + range_enc_range512(chan_list, f0, w); break; case ARFCN_RANGE_1024: - rc = range_enc_range1024(chan_list, f0, f0_included, w); + range_enc_range1024(chan_list, f0, f0_included, w); break; default: return 1; }; - if (rc != 0) { - printf("Cannot encode range, rc = %d\n", rc); - return 1; - } if (!silent) printf("chan_list = %s\n", @@ -471,8 +507,7 @@ static void test_print_encoding() break; } - rc = range_enc_range512(chan_list, (1 << 9) | 0x96, w); - VERIFY(rc, ==, 0); + range_enc_range512(chan_list, (1 << 9) | 0x96, w); printf("Range512: %s\n", osmo_hexdump(chan_list, ARRAY_SIZE(chan_list))); } @@ -496,8 +531,7 @@ static void test_si_range_helpers() printf("Element is: %d => freqs[i] = %d\n", i, i >= 0 ? freqs3[i] : -1); VERIFY(i, ==, 0); - i = range_enc_arfcns(1023, freqs1, ARRAY_SIZE(freqs1), ws, 0); - VERIFY(i, ==, 0); + range_enc_arfcns(1023, freqs1, ARRAY_SIZE(freqs1), ws, 0); for (i = 0; i < sizeof(freqs1)/sizeof(freqs1[0]); ++i) { printf("w[%d]=%d\n", i, ws[i]); @@ -554,7 +588,8 @@ int main(int argc, char **argv) test_range_encoding(); test_gsm411_rp_ref_wrap(); - test_si2q(); + test_si2q_e(); + test_si2q_u(); printf("Done.\n"); return EXIT_SUCCESS; } diff --git a/openbsc/tests/gsm0408/gsm0408_test.ok b/openbsc/tests/gsm0408/gsm0408_test.ok index 59319bfeb..565eac672 100644 --- a/openbsc/tests/gsm0408/gsm0408_test.ok +++ b/openbsc/tests/gsm0408/gsm0408_test.ok @@ -62,7 +62,7 @@ testing RP-Reference wrap Allocated reference: 255 Allocated reference: 0 Allocated reference: 1 -Testing SYSINFO_TYPE_2quater generation: +Testing SYSINFO_TYPE_2quater EARFCN generation: added EARFCN 1917 - generated SI2quater: [23] 59 06 07 c0 00 04 86 59 83 be c8 50 0b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b added EARFCN 1932 - generated SI2quater: [23] 59 06 07 c0 00 04 86 59 83 be cc 1e 30 14 03 2b 2b 2b 2b 2b 2b 2b 2b added EARFCN 1937 - generated SI2quater: [23] 59 06 07 c0 00 04 86 59 83 be cc 1e 31 07 91 a0 a0 2b 2b 2b 2b 2b 2b @@ -70,4 +70,16 @@ added EARFCN 1945 - generated SI2quater: [23] 59 06 07 c0 00 04 86 59 83 be cc 1 added EARFCN 1965 - generated SI2quater: [23] 59 06 07 c0 00 04 86 59 83 be cc 1e 31 07 91 a8 3c ca 0f 5a 0a 03 2b added EARFCN 1967 - failed to generate SI2quater: Cannot allocate memory added EARFCN 1982 - failed to generate SI2quater: Cannot allocate memory +Testing SYSINFO_TYPE_2quater UARFCN generation: +generated SI2quater: [23] 59 06 07 c0 00 25 0f 7c 0c 1a 10 99 64 00 0b 2b 2b 2b 2b 2b 2b 2b 2b +generated SI2quater: [23] 59 06 07 c0 00 25 0f 7c 14 1a 1f 00 44 b2 00 03 2b 2b 2b 2b 2b 2b 2b +generated SI2quater: [23] 59 06 07 c0 00 25 0f 7c 18 58 12 f0 84 86 59 00 03 2b 2b 2b 2b 2b 2b +generated SI2quater: [23] 59 06 07 c0 00 25 0f 7c 20 58 2e f0 f2 04 86 59 00 03 2b 2b 2b 2b 2b +generated SI2quater: [23] 59 06 07 c0 00 25 0f 7c 28 58 2e 22 f2 4e 84 86 59 00 03 2b 2b 2b 2b +generated SI2quater: [23] 59 06 07 c0 00 25 0f 7c 34 1a 64 26 5d f2 05 04 86 59 00 03 2b 2b 2b +generated SI2quater: [23] 59 06 07 c0 00 25 0f 7c 38 58 12 22 fd ce 8e 05 04 86 59 00 03 2b 2b +generated SI2quater: [23] 59 06 07 c0 00 25 0f 7c 40 58 1d 22 fa ce 88 85 7b 00 44 b2 00 03 2b +generated SI2quater: [23] 59 06 07 c0 00 25 0f 7c 4c 7a 34 0e 64 77 85 43 55 c8 10 99 64 00 0b +failed to generate SI2quater: Cannot allocate memory +failed to generate SI2quater: Cannot allocate memory Done. diff --git a/openbsc/tests/vty_test_runner.py b/openbsc/tests/vty_test_runner.py index 7f64a80d3..c0888559e 100644 --- a/openbsc/tests/vty_test_runner.py +++ b/openbsc/tests/vty_test_runner.py @@ -244,6 +244,29 @@ class TestVTYNITB(TestVTYGenericBSC): self.vty.command("si2quater neighbor-list del earfcn 1924") self.vty.command("si2quater neighbor-list del earfcn 2111") self.assertEquals(before, self.vty.command("show running-config")) + self.vty.command("si2quater neighbor-list add uarfcn 1976 13 1") + self.vty.command("si2quater neighbor-list add uarfcn 1976 38 1") + self.vty.command("si2quater neighbor-list add uarfcn 1976 44 1") + self.vty.command("si2quater neighbor-list add uarfcn 1976 120 1") + self.vty.command("si2quater neighbor-list add uarfcn 1976 140 1") + self.vty.command("si2quater neighbor-list add uarfcn 1976 163 1") + self.vty.command("si2quater neighbor-list add uarfcn 1976 166 1") + self.vty.command("si2quater neighbor-list add uarfcn 1976 217 1") + self.vty.command("si2quater neighbor-list add uarfcn 1976 224 1") + self.vty.command("si2quater neighbor-list add uarfcn 1976 225 1") + self.vty.command("si2quater neighbor-list add uarfcn 1976 226 1") + self.vty.command("si2quater neighbor-list del uarfcn 1976 13") + self.vty.command("si2quater neighbor-list del uarfcn 1976 38") + self.vty.command("si2quater neighbor-list del uarfcn 1976 44") + self.vty.command("si2quater neighbor-list del uarfcn 1976 120") + self.vty.command("si2quater neighbor-list del uarfcn 1976 140") + self.vty.command("si2quater neighbor-list del uarfcn 1976 163") + self.vty.command("si2quater neighbor-list del uarfcn 1976 166") + self.vty.command("si2quater neighbor-list del uarfcn 1976 217") + self.vty.command("si2quater neighbor-list del uarfcn 1976 224") + self.vty.command("si2quater neighbor-list del uarfcn 1976 225") + self.vty.command("si2quater neighbor-list del uarfcn 1976 226") + self.assertEquals(before, self.vty.command("show running-config")) def testEnableDisablePeriodicLU(self): self.vty.enable() -- cgit v1.2.3 From aafff96c4060e9bf6ceb9dee9652a91d293a6e1e Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 20 Apr 2016 15:57:14 +0200 Subject: Add vty check for max si2quater size Explicitly check if added (U|E)ARFCN will fit into available si2quater message. --- openbsc/tests/gsm0408/gsm0408_test.c | 52 ++++++++++++++--------------------- openbsc/tests/gsm0408/gsm0408_test.ok | 5 ++-- 2 files changed, 24 insertions(+), 33 deletions(-) (limited to 'openbsc/tests') diff --git a/openbsc/tests/gsm0408/gsm0408_test.c b/openbsc/tests/gsm0408/gsm0408_test.c index 2d91b68f0..92626670c 100644 --- a/openbsc/tests/gsm0408/gsm0408_test.c +++ b/openbsc/tests/gsm0408/gsm0408_test.c @@ -103,6 +103,16 @@ static inline void gen(struct gsm_bts *bts) printf("failed to generate SI2quater: %s\n", strerror(-r)); } +static inline void _bts_uarfcn_add(struct gsm_bts *bts, uint16_t arfcn, + uint16_t scramble, bool diversity) +{ + int r = bts_uarfcn_add(bts, arfcn, scramble, diversity); + if (r < 0) + printf("failed to add UARFCN to SI2quater: %s\n", strerror(-r)); + else + gen(bts); +} + static inline void test_si2q_u(void) { struct gsm_bts *bts; @@ -113,37 +123,17 @@ static inline void test_si2q_u(void) exit(1); bts = gsm_bts_alloc(network); - bts_uarfcn_add(bts, 1982, 13, 1); - gen(bts); - - bts_uarfcn_add(bts, 1982, 44, 0); - gen(bts); - - bts_uarfcn_add(bts, 1982, 61, 1); - gen(bts); - - bts_uarfcn_add(bts, 1982, 89, 1); - gen(bts); - - bts_uarfcn_add(bts, 1982, 113, 0); - gen(bts); - - bts_uarfcn_add(bts, 1982, 123, 0); - gen(bts); - - bts_uarfcn_add(bts, 1982, 56, 1); - gen(bts); - - bts_uarfcn_add(bts, 1982, 72, 1); - gen(bts); - - bts_uarfcn_add(bts, 1982, 223, 1); - gen(bts); - - bts_uarfcn_add(bts, 1982, 14, 0); - gen(bts); - - bts_uarfcn_add(bts, 1982, 88, 0); + _bts_uarfcn_add(bts, 1982, 13, 1); + _bts_uarfcn_add(bts, 1982, 44, 0); + _bts_uarfcn_add(bts, 1982, 61, 1); + _bts_uarfcn_add(bts, 1982, 89, 1); + _bts_uarfcn_add(bts, 1982, 113, 0); + _bts_uarfcn_add(bts, 1982, 123, 0); + _bts_uarfcn_add(bts, 1982, 56, 1); + _bts_uarfcn_add(bts, 1982, 72, 1); + _bts_uarfcn_add(bts, 1982, 223, 1); + _bts_uarfcn_add(bts, 1982, 14, 0); + _bts_uarfcn_add(bts, 1982, 88, 0); gen(bts); } diff --git a/openbsc/tests/gsm0408/gsm0408_test.ok b/openbsc/tests/gsm0408/gsm0408_test.ok index 565eac672..7b7a2cc76 100644 --- a/openbsc/tests/gsm0408/gsm0408_test.ok +++ b/openbsc/tests/gsm0408/gsm0408_test.ok @@ -80,6 +80,7 @@ generated SI2quater: [23] 59 06 07 c0 00 25 0f 7c 34 1a 64 26 5d f2 05 04 86 59 generated SI2quater: [23] 59 06 07 c0 00 25 0f 7c 38 58 12 22 fd ce 8e 05 04 86 59 00 03 2b 2b generated SI2quater: [23] 59 06 07 c0 00 25 0f 7c 40 58 1d 22 fa ce 88 85 7b 00 44 b2 00 03 2b generated SI2quater: [23] 59 06 07 c0 00 25 0f 7c 4c 7a 34 0e 64 77 85 43 55 c8 10 99 64 00 0b -failed to generate SI2quater: Cannot allocate memory -failed to generate SI2quater: Cannot allocate memory +failed to add UARFCN to SI2quater: No space left on device +failed to add UARFCN to SI2quater: No space left on device +generated SI2quater: [23] 59 06 07 c0 00 25 0f 7c 4c 7a 34 0e 64 77 85 43 55 c8 10 99 64 00 0b Done. -- cgit v1.2.3 From 121e9a4164e65dfb68b2bf09297a8537a2f659c5 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Wed, 20 Apr 2016 13:13:19 +0200 Subject: Start to use struct osmo_auth_vector from gsm_auth_tuple Rather than having a 'private' structure for kc, sres and rand, we now finally (with 4 years delay) use osmo_auth_vector from libosmogsm, which encapsulates authentication vectors that can be either GSM triplets or UMTS quintuples or a combination of both. gsm_auth_tuple becomes a wrapper around osmo_auth_vector, adding use_count and key_seq to it. key_seq is no longer initialized inside gprs_gsup_messages.c, as there is no CKSN / key_seq inside the message anyway. If a usre of the code needs key_seq, they need to manage it themselves. --- openbsc/tests/mm_auth/mm_auth_test.c | 6 +++--- openbsc/tests/sgsn/sgsn_test.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'openbsc/tests') diff --git a/openbsc/tests/mm_auth/mm_auth_test.c b/openbsc/tests/mm_auth/mm_auth_test.c index 34d96f187..b8777a8c5 100644 --- a/openbsc/tests/mm_auth/mm_auth_test.c +++ b/openbsc/tests/mm_auth/mm_auth_test.c @@ -26,9 +26,9 @@ static char *auth_tuple_str(struct gsm_auth_tuple *atuple) print2buf("gsm_auth_tuple {\n"); print2buf(" .use_count = %d\n", atuple->use_count); print2buf(" .key_seq = %d\n", atuple->key_seq); - print2buf(" .rand = %s\n", osmo_hexdump(atuple->rand, sizeof(atuple->rand))); - print2buf(" .sres = %s\n", osmo_hexdump(atuple->sres, sizeof(atuple->sres))); - print2buf(" .kc = %s\n", osmo_hexdump(atuple->kc, sizeof(atuple->kc))); + print2buf(" .rand = %s\n", osmo_hexdump(atuple->vec.rand, sizeof(atuple->vec.rand))); + print2buf(" .sres = %s\n", osmo_hexdump(atuple->vec.sres, sizeof(atuple->vec.sres))); + print2buf(" .kc = %s\n", osmo_hexdump(atuple->vec.kc, sizeof(atuple->vec.kc))); print2buf("}\n"); #undef print2buf diff --git a/openbsc/tests/sgsn/sgsn_test.c b/openbsc/tests/sgsn/sgsn_test.c index 1acd6f2f8..fe41e759b 100644 --- a/openbsc/tests/sgsn/sgsn_test.c +++ b/openbsc/tests/sgsn/sgsn_test.c @@ -1132,7 +1132,7 @@ static void test_gmm_attach_subscr_fake_auth(void) int my_subscr_request_auth_info_real_auth(struct sgsn_mm_ctx *mmctx) { struct gsm_auth_tuple at = { - .sres = {0x51, 0xe5, 0x51, 0xe5}, + .vec.sres = {0x51, 0xe5, 0x51, 0xe5}, .key_seq = 0 }; -- cgit v1.2.3 From 53373bca8f9fe79ca981f9fc1ef644586bd5c3b2 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Wed, 20 Apr 2016 17:11:43 +0200 Subject: move gsm_04_08_gprs.h to libosmocore This requres the corresponding commit in libosmocore. --- openbsc/tests/gbproxy/gbproxy_test.c | 2 +- openbsc/tests/oap/Makefile.am | 1 - openbsc/tests/sgsn/Makefile.am | 1 - openbsc/tests/sgsn/sgsn_test.c | 1 - 4 files changed, 1 insertion(+), 4 deletions(-) (limited to 'openbsc/tests') diff --git a/openbsc/tests/gbproxy/gbproxy_test.c b/openbsc/tests/gbproxy/gbproxy_test.c index 96a68b0e5..a2ff95b1d 100644 --- a/openbsc/tests/gbproxy/gbproxy_test.c +++ b/openbsc/tests/gbproxy/gbproxy_test.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -34,7 +35,6 @@ #include #include #include -#include #include #include diff --git a/openbsc/tests/oap/Makefile.am b/openbsc/tests/oap/Makefile.am index 3a76b11ad..538e1787e 100644 --- a/openbsc/tests/oap/Makefile.am +++ b/openbsc/tests/oap/Makefile.am @@ -15,7 +15,6 @@ oap_test_LDADD = \ $(top_builddir)/src/gprs/oap.o \ $(top_builddir)/src/gprs/oap_messages.o \ $(top_builddir)/src/gprs/gprs_utils.o \ - $(top_builddir)/src/gprs/gsm_04_08_gprs.o \ $(top_builddir)/src/libcommon/libcommon.a \ $(LIBOSMOCORE_LIBS) \ $(LIBOSMOGSM_LIBS) \ diff --git a/openbsc/tests/sgsn/Makefile.am b/openbsc/tests/sgsn/Makefile.am index d432fb139..aebcf0105 100644 --- a/openbsc/tests/sgsn/Makefile.am +++ b/openbsc/tests/sgsn/Makefile.am @@ -27,7 +27,6 @@ sgsn_test_LDADD = \ $(top_builddir)/src/gprs/gprs_gsup_client.o \ $(top_builddir)/src/gprs/gprs_utils.o \ $(top_builddir)/src/gprs/gprs_subscriber.o \ - $(top_builddir)/src/gprs/gsm_04_08_gprs.o \ $(top_builddir)/src/gprs/gprs_gb_parse.o \ $(top_builddir)/src/gprs/oap.o \ $(top_builddir)/src/gprs/oap_messages.o \ diff --git a/openbsc/tests/sgsn/sgsn_test.c b/openbsc/tests/sgsn/sgsn_test.c index fe41e759b..94c277f55 100644 --- a/openbsc/tests/sgsn/sgsn_test.c +++ b/openbsc/tests/sgsn/sgsn_test.c @@ -32,7 +32,6 @@ #include #include -#include #include #include -- cgit v1.2.3 From d3fa84dbba3b67cdbe2d8c789b2833b5ddf42068 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Wed, 20 Apr 2016 17:50:17 +0200 Subject: use new libosmocore gsm_23_003.h for IMEI/IMSI length ... rather than our private definitions everwhere. As an added benefit, gprs_gsup_messages.h is now free of any header dependencies within openbsc. --- openbsc/tests/gtphub/gtphub_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'openbsc/tests') diff --git a/openbsc/tests/gtphub/gtphub_test.c b/openbsc/tests/gtphub/gtphub_test.c index 8ce83c82e..e24967b85 100644 --- a/openbsc/tests/gtphub/gtphub_test.c +++ b/openbsc/tests/gtphub/gtphub_test.c @@ -388,7 +388,7 @@ static void test_expiry(void) #undef MAP3 } -char resolve_ggsn_got_imsi[GSM_IMSI_LENGTH]; +char resolve_ggsn_got_imsi[GSM23003_IMSI_MAX_DIGITS+1]; char resolve_ggsn_got_ni[GSM_APN_LENGTH]; struct osmo_sockaddr resolved_ggsn_addr; -- cgit v1.2.3 From 50f1c0af567423b6ade9a84aaa5197ecf6237819 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Mon, 25 Apr 2016 19:01:26 +0200 Subject: move utils.h functions to libosmocore This needs the corresponding commit in libosmocore which imports the related functions --- openbsc/tests/gprs/Makefile.am | 3 +- openbsc/tests/gprs/gprs_test.c | 243 +--------------------------------------- openbsc/tests/gprs/gprs_test.ok | 1 - 3 files changed, 2 insertions(+), 245 deletions(-) (limited to 'openbsc/tests') diff --git a/openbsc/tests/gprs/Makefile.am b/openbsc/tests/gprs/Makefile.am index b57977b94..633c362f8 100644 --- a/openbsc/tests/gprs/Makefile.am +++ b/openbsc/tests/gprs/Makefile.am @@ -6,7 +6,6 @@ EXTRA_DIST = gprs_test.ok noinst_PROGRAMS = gprs_test gprs_test_SOURCES = gprs_test.c $(top_srcdir)/src/gprs/gprs_utils.c \ - $(top_srcdir)/src/gprs/gprs_gsup_messages.c \ - $(top_srcdir)/src/libcommon/utils.c + $(top_srcdir)/src/gprs/gprs_gsup_messages.c gprs_test_LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) diff --git a/openbsc/tests/gprs/gprs_test.c b/openbsc/tests/gprs/gprs_test.c index c78b98ab5..24e44cf3f 100644 --- a/openbsc/tests/gprs/gprs_test.c +++ b/openbsc/tests/gprs/gprs_test.c @@ -146,247 +146,7 @@ static void test_gsm_03_03_apn(void) } } -/* TODO: Move tlv testing to libosmocore */ -static void check_tlv_parse(uint8_t **data, size_t *data_len, - uint8_t exp_tag, size_t exp_len, const uint8_t *exp_val) -{ - uint8_t *value; - size_t value_len; - uint8_t tag; - int rc; - uint8_t *saved_data = *data; - size_t saved_data_len = *data_len; - - rc = gprs_match_tlv(data, data_len, exp_tag ^ 1, NULL, NULL); - OSMO_ASSERT(rc == 0); - - rc = gprs_match_tlv(data, data_len, exp_tag, &value, &value_len); - OSMO_ASSERT(rc == (int)value_len + 2); - OSMO_ASSERT(value_len == exp_len); - OSMO_ASSERT(memcmp(value, exp_val, exp_len) == 0); - - /* restore data/data_len */ - *data = saved_data; - *data_len = saved_data_len; - - rc = gprs_shift_tlv(data, data_len, &tag, &value, &value_len); - OSMO_ASSERT(rc == (int)value_len + 2); - OSMO_ASSERT(tag == exp_tag); - OSMO_ASSERT(value_len == exp_len); - OSMO_ASSERT(memcmp(value, exp_val, exp_len) == 0); -} - -static void check_tv_fixed_match(uint8_t **data, size_t *data_len, - uint8_t tag, size_t len, const uint8_t *exp_val) -{ - uint8_t *value; - int rc; - - rc = gprs_match_tv_fixed(data, data_len, tag ^ 1, len, NULL); - OSMO_ASSERT(rc == 0); - - rc = gprs_match_tv_fixed(data, data_len, tag, len, &value); - OSMO_ASSERT(rc == (int)len + 1); - OSMO_ASSERT(memcmp(value, exp_val, len) == 0); -} - -static void check_v_fixed_shift(uint8_t **data, size_t *data_len, - size_t len, const uint8_t *exp_val) -{ - uint8_t *value; - int rc; - - rc = gprs_shift_v_fixed(data, data_len, len, &value); - OSMO_ASSERT(rc == (int)len); - OSMO_ASSERT(memcmp(value, exp_val, len) == 0); -} - -static void check_lv_shift(uint8_t **data, size_t *data_len, - size_t exp_len, const uint8_t *exp_val) -{ - uint8_t *value; - size_t value_len; - int rc; - - rc = gprs_shift_lv(data, data_len, &value, &value_len); - OSMO_ASSERT(rc == (int)value_len + 1); - OSMO_ASSERT(value_len == exp_len); - OSMO_ASSERT(memcmp(value, exp_val, exp_len) == 0); -} - -static void check_tlv_match_data_len(size_t data_len, uint8_t tag, size_t len, - const uint8_t *test_data) -{ - uint8_t buf[300] = {0}; - - uint8_t *unchanged_ptr = buf - 1; - size_t unchanged_len = 0xdead; - size_t tmp_data_len = data_len; - uint8_t *value = unchanged_ptr; - size_t value_len = unchanged_len; - uint8_t *data = buf; - - OSMO_ASSERT(data_len <= sizeof(buf)); - - tlv_put(data, tag, len, test_data); - if (data_len < len + 2) { - OSMO_ASSERT(-1 == gprs_match_tlv(&data, &tmp_data_len, - tag, &value, &value_len)); - OSMO_ASSERT(tmp_data_len == 0); - OSMO_ASSERT(data == buf + data_len); - OSMO_ASSERT(value == unchanged_ptr); - OSMO_ASSERT(value_len == unchanged_len); - } else { - OSMO_ASSERT(0 <= gprs_match_tlv(&data, &tmp_data_len, - tag, &value, &value_len)); - OSMO_ASSERT(value != unchanged_ptr); - OSMO_ASSERT(value_len != unchanged_len); - } -} - -static void check_tv_fixed_match_data_len(size_t data_len, - uint8_t tag, size_t len, - const uint8_t *test_data) -{ - uint8_t buf[300] = {0}; - - uint8_t *unchanged_ptr = buf - 1; - size_t tmp_data_len = data_len; - uint8_t *value = unchanged_ptr; - uint8_t *data = buf; - - OSMO_ASSERT(data_len <= sizeof(buf)); - - tv_fixed_put(data, tag, len, test_data); - - if (data_len < len + 1) { - OSMO_ASSERT(-1 == gprs_match_tv_fixed(&data, &tmp_data_len, - tag, len, &value)); - OSMO_ASSERT(tmp_data_len == 0); - OSMO_ASSERT(data == buf + data_len); - OSMO_ASSERT(value == unchanged_ptr); - } else { - OSMO_ASSERT(0 <= gprs_match_tv_fixed(&data, &tmp_data_len, - tag, len, &value)); - OSMO_ASSERT(value != unchanged_ptr); - } -} - -static void check_v_fixed_shift_data_len(size_t data_len, - size_t len, const uint8_t *test_data) -{ - uint8_t buf[300] = {0}; - - uint8_t *unchanged_ptr = buf - 1; - size_t tmp_data_len = data_len; - uint8_t *value = unchanged_ptr; - uint8_t *data = buf; - - OSMO_ASSERT(data_len <= sizeof(buf)); - - memcpy(data, test_data, len); - - if (data_len < len) { - OSMO_ASSERT(-1 == gprs_shift_v_fixed(&data, &tmp_data_len, - len, &value)); - OSMO_ASSERT(tmp_data_len == 0); - OSMO_ASSERT(data == buf + data_len); - OSMO_ASSERT(value == unchanged_ptr); - } else { - OSMO_ASSERT(0 <= gprs_shift_v_fixed(&data, &tmp_data_len, - len, &value)); - OSMO_ASSERT(value != unchanged_ptr); - } -} - -static void check_lv_shift_data_len(size_t data_len, - size_t len, const uint8_t *test_data) -{ - uint8_t buf[300] = {0}; - - uint8_t *unchanged_ptr = buf - 1; - size_t unchanged_len = 0xdead; - size_t tmp_data_len = data_len; - uint8_t *value = unchanged_ptr; - size_t value_len = unchanged_len; - uint8_t *data = buf; - - lv_put(data, len, test_data); - if (data_len < len + 1) { - OSMO_ASSERT(-1 == gprs_shift_lv(&data, &tmp_data_len, - &value, &value_len)); - OSMO_ASSERT(tmp_data_len == 0); - OSMO_ASSERT(data == buf + data_len); - OSMO_ASSERT(value == unchanged_ptr); - OSMO_ASSERT(value_len == unchanged_len); - } else { - OSMO_ASSERT(0 <= gprs_shift_lv(&data, &tmp_data_len, - &value, &value_len)); - OSMO_ASSERT(value != unchanged_ptr); - OSMO_ASSERT(value_len != unchanged_len); - } -} - -static void test_tlv_shift_functions() -{ - uint8_t test_data[1024]; - uint8_t buf[1024]; - uint8_t *data_end; - unsigned i, len; - uint8_t *data; - size_t data_len; - const uint8_t tag = 0x1a; - - printf("Test shift functions\n"); - - for (i = 0; i < ARRAY_SIZE(test_data); i++) - test_data[i] = (uint8_t)i; - - for (len = 0; len < 256; len++) { - const unsigned iterations = sizeof(buf) / (len + 2) / 4; - - memset(buf, 0xee, sizeof(buf)); - data_end = data = buf; - - for (i = 0; i < iterations; i++) { - data_end = tlv_put(data_end, tag, len, test_data); - data_end = tv_fixed_put(data_end, tag, len, test_data); - /* v_fixed_put */ - memcpy(data_end, test_data, len); - data_end += len; - data_end = lv_put(data_end, len, test_data); - } - - data_len = data_end - data; - OSMO_ASSERT(data_len <= sizeof(buf)); - - for (i = 0; i < iterations; i++) { - check_tlv_parse(&data, &data_len, tag, len, test_data); - check_tv_fixed_match(&data, &data_len, tag, len, test_data); - check_v_fixed_shift(&data, &data_len, len, test_data); - check_lv_shift(&data, &data_len, len, test_data); - } - - OSMO_ASSERT(data == data_end); - - /* Test at end of data */ - - OSMO_ASSERT(-1 == gprs_match_tlv(&data, &data_len, tag, NULL, NULL)); - OSMO_ASSERT(-1 == gprs_match_tv_fixed(&data, &data_len, tag, len, NULL)); - OSMO_ASSERT((len ? -1 : 0) == gprs_shift_v_fixed(&data, &data_len, len, NULL)); - OSMO_ASSERT(-1 == gprs_shift_lv(&data, &data_len, NULL, NULL)); - - /* Test invalid data_len */ - for (data_len = 0; data_len <= len + 2 + 1; data_len += 1) { - check_tlv_match_data_len(data_len, tag, len, test_data); - check_tv_fixed_match_data_len(data_len, tag, len, test_data); - check_v_fixed_shift_data_len(data_len, len, test_data); - check_lv_shift_data_len(data_len, len, test_data); - } - } -} - -/* Tests for gprs_gsup_messages.c */ +/* Tests for osmo_gsup_messages.c */ #define TEST_IMSI_IE 0x01, 0x08, 0x21, 0x43, 0x65, 0x87, 0x09, 0x21, 0x43, 0xf5 #define TEST_IMSI_STR "123456789012345" @@ -705,7 +465,6 @@ int main(int argc, char **argv) test_8_4_2(); test_gsm_03_03_apn(); - test_tlv_shift_functions(); test_gsup_messages_dec_enc(); test_gprs_timer_enc_dec(); diff --git a/openbsc/tests/gprs/gprs_test.ok b/openbsc/tests/gprs/gprs_test.ok index cf710769e..688d44b24 100644 --- a/openbsc/tests/gprs/gprs_test.ok +++ b/openbsc/tests/gprs/gprs_test.ok @@ -13,7 +13,6 @@ N(U) = 511, V(UR) = 511 => new N(U) = 510, V(UR) = 511 => retransmit N(U) = 481, V(UR) = 511 => retransmit N(U) = 479, V(UR) = 511 => new -Test shift functions Test GSUP message decoding/encoding Testing Send Authentication Info Request Testing Send Authentication Info Error -- cgit v1.2.3 From 23d77d56ea47bbb971bf2fc5d93d6ae2d7d30f03 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Mon, 25 Apr 2016 19:07:34 +0200 Subject: Move osmo_gsup_messages.[ch] to libosmocore This requires the corresponding commit in libosmocore. --- openbsc/tests/gprs/Makefile.am | 3 +- openbsc/tests/gprs/gprs_test.c | 239 +--------------------------------------- openbsc/tests/gprs/gprs_test.ok | 13 --- openbsc/tests/sgsn/Makefile.am | 1 - openbsc/tests/sgsn/sgsn_test.c | 18 +-- 5 files changed, 11 insertions(+), 263 deletions(-) (limited to 'openbsc/tests') diff --git a/openbsc/tests/gprs/Makefile.am b/openbsc/tests/gprs/Makefile.am index 633c362f8..902313f2a 100644 --- a/openbsc/tests/gprs/Makefile.am +++ b/openbsc/tests/gprs/Makefile.am @@ -5,7 +5,6 @@ EXTRA_DIST = gprs_test.ok noinst_PROGRAMS = gprs_test -gprs_test_SOURCES = gprs_test.c $(top_srcdir)/src/gprs/gprs_utils.c \ - $(top_srcdir)/src/gprs/gprs_gsup_messages.c +gprs_test_SOURCES = gprs_test.c $(top_srcdir)/src/gprs/gprs_utils.c gprs_test_LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) diff --git a/openbsc/tests/gprs/gprs_test.c b/openbsc/tests/gprs/gprs_test.c index 24e44cf3f..ff7740494 100644 --- a/openbsc/tests/gprs/gprs_test.c +++ b/openbsc/tests/gprs/gprs_test.c @@ -5,17 +5,14 @@ #include #include -#include - #include #include +#include #define ASSERT_FALSE(x) if (x) { printf("Should have returned false.\n"); abort(); } #define ASSERT_TRUE(x) if (!x) { printf("Should have returned true.\n"); abort(); } -#define VERBOSE_FPRINTF(...) - /** * GSM 04.64 8.4.2 Receipt of unacknowledged information */ @@ -146,239 +143,6 @@ static void test_gsm_03_03_apn(void) } } -/* Tests for osmo_gsup_messages.c */ - -#define TEST_IMSI_IE 0x01, 0x08, 0x21, 0x43, 0x65, 0x87, 0x09, 0x21, 0x43, 0xf5 -#define TEST_IMSI_STR "123456789012345" - -static void test_gsup_messages_dec_enc(void) -{ - int test_idx; - int rc; - uint8_t buf[1024]; - - static const uint8_t send_auth_info_req[] = { - 0x08, - TEST_IMSI_IE - }; - - static const uint8_t send_auth_info_err[] = { - 0x09, - TEST_IMSI_IE, - 0x02, 0x01, 0x07 /* GPRS no allowed */ - }; - - static const uint8_t send_auth_info_res[] = { - 0x0a, - TEST_IMSI_IE, - 0x03, 0x22, /* Auth tuple */ - 0x20, 0x10, - 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, - 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, - 0x21, 0x04, - 0x21, 0x22, 0x23, 0x24, - 0x22, 0x08, - 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, - 0x03, 0x22, /* Auth tuple */ - 0x20, 0x10, - 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, - 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, - 0x21, 0x04, - 0xa1, 0xa2, 0xa3, 0xa4, - 0x22, 0x08, - 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, - }; - - static const uint8_t update_location_req[] = { - 0x04, - TEST_IMSI_IE, - }; - - static const uint8_t update_location_err[] = { - 0x05, - TEST_IMSI_IE, - 0x02, 0x01, 0x07 /* GPRS no allowed */ - }; - - static const uint8_t update_location_res[] = { - 0x06, - TEST_IMSI_IE, - 0x08, 0x07, /* MSISDN of the subscriber */ - 0x91, 0x94, 0x61, 0x46, 0x32, 0x24, 0x43, - 0x09, 0x07, /* HLR-Number of the subscriber */ - 0x91, 0x83, 0x52, 0x38, 0x48, 0x83, 0x93, - 0x04, 0x00, /* PDP info complete */ - 0x05, 0x15, - 0x10, 0x01, 0x01, - 0x11, 0x02, 0xf1, 0x21, /* IPv4 */ - 0x12, 0x09, 0x04, 't', 'e', 's', 't', 0x03, 'a', 'p', 'n', - 0x13, 0x01, 0x02, - 0x05, 0x11, - 0x10, 0x01, 0x02, - 0x11, 0x02, 0xf1, 0x21, /* IPv4 */ - 0x12, 0x08, 0x03, 'f', 'o', 'o', 0x03, 'a', 'p', 'n', - }; - - static const uint8_t location_cancellation_req[] = { - 0x1c, - TEST_IMSI_IE, - 0x06, 0x01, 0x00, - }; - - static const uint8_t location_cancellation_err[] = { - 0x1d, - TEST_IMSI_IE, - 0x02, 0x01, 0x03 /* Illegal MS */ - }; - - static const uint8_t location_cancellation_res[] = { - 0x1e, - TEST_IMSI_IE, - }; - - static const uint8_t purge_ms_req[] = { - 0x0c, - TEST_IMSI_IE, - }; - - static const uint8_t purge_ms_err[] = { - 0x0d, - TEST_IMSI_IE, - 0x02, 0x01, 0x03, /* Illegal MS */ - }; - - static const uint8_t purge_ms_res[] = { - 0x0e, - TEST_IMSI_IE, - 0x07, 0x00, - }; - - static const struct test { - char *name; - const uint8_t *data; - size_t data_len; - } test_messages[] = { - {"Send Authentication Info Request", - send_auth_info_req, sizeof(send_auth_info_req)}, - {"Send Authentication Info Error", - send_auth_info_err, sizeof(send_auth_info_err)}, - {"Send Authentication Info Result", - send_auth_info_res, sizeof(send_auth_info_res)}, - {"Update Location Request", - update_location_req, sizeof(update_location_req)}, - {"Update Location Error", - update_location_err, sizeof(update_location_err)}, - {"Update Location Result", - update_location_res, sizeof(update_location_res)}, - {"Location Cancellation Request", - location_cancellation_req, sizeof(location_cancellation_req)}, - {"Location Cancellation Error", - location_cancellation_err, sizeof(location_cancellation_err)}, - {"Location Cancellation Result", - location_cancellation_res, sizeof(location_cancellation_res)}, - {"Purge MS Request", - purge_ms_req, sizeof(purge_ms_req)}, - {"Purge MS Error", - purge_ms_err, sizeof(purge_ms_err)}, - {"Purge MS Result", - purge_ms_res, sizeof(purge_ms_res)}, - }; - - printf("Test GSUP message decoding/encoding\n"); - - for (test_idx = 0; test_idx < ARRAY_SIZE(test_messages); test_idx++) { - const struct test *t = &test_messages[test_idx]; - struct gprs_gsup_message gm = {0}; - struct msgb *msg = msgb_alloc(4096, "gsup_test"); - - printf(" Testing %s\n", t->name); - - rc = gprs_gsup_decode(t->data, t->data_len, &gm); - OSMO_ASSERT(rc >= 0); - - gprs_gsup_encode(msg, &gm); - - fprintf(stderr, " generated message: %s\n", msgb_hexdump(msg)); - fprintf(stderr, " original message: %s\n", osmo_hexdump(t->data, t->data_len)); - fprintf(stderr, " IMSI: %s\n", gm.imsi); - OSMO_ASSERT(strcmp(gm.imsi, TEST_IMSI_STR) == 0); - OSMO_ASSERT(msgb_length(msg) == t->data_len); - OSMO_ASSERT(memcmp(msgb_data(msg), t->data, t->data_len) == 0); - - msgb_free(msg); - } - - /* simple truncation test */ - for (test_idx = 0; test_idx < ARRAY_SIZE(test_messages); test_idx++) { - int j; - const struct test *t = &test_messages[test_idx]; - int ie_end = t->data_len; - struct gprs_gsup_message gm = {0}; - int counter = 0; - int parse_err = 0; - - for (j = t->data_len - 1; j >= 0; --j) { - rc = gprs_gsup_decode(t->data, j, &gm); - counter += 1; - - VERBOSE_FPRINTF(stderr, - " partial message decoding: " - "orig_len = %d, trunc = %d, rc = %d, ie_end = %d\n", - t->data_len, j, rc, ie_end); - if (rc >= 0) { - VERBOSE_FPRINTF(stderr, - " remaing partial message: %s\n", - osmo_hexdump(t->data + j, ie_end - j)); - - OSMO_ASSERT(j <= ie_end - 2); - OSMO_ASSERT(t->data[j+0] <= GPRS_GSUP_KC_IE); - OSMO_ASSERT(t->data[j+1] <= ie_end - j - 2); - - ie_end = j; - } else { - parse_err += 1; - } - } - - fprintf(stderr, - " message %d: tested %d truncations, %d parse failures\n", - test_idx, counter, parse_err); - } - - /* message modification test (relies on ASAN or valgrind being used) */ - for (test_idx = 0; test_idx < ARRAY_SIZE(test_messages); test_idx++) { - int j; - const struct test *t = &test_messages[test_idx]; - struct gprs_gsup_message gm = {0}; - uint8_t val; - int counter = 0; - int parse_err = 0; - - OSMO_ASSERT(sizeof(buf) >= t->data_len); - - for (j = t->data_len - 1; j >= 0; --j) { - memcpy(buf, t->data, t->data_len); - val = 0; - do { - VERBOSE_FPRINTF(stderr, - "t = %d, len = %d, val = %d\n", - test_idx, j, val); - buf[j] = val; - rc = gprs_gsup_decode(buf, t->data_len, &gm); - counter += 1; - if (rc < 0) - parse_err += 1; - - val += 1; - } while (val != (uint8_t)256); - } - - fprintf(stderr, - " message %d: tested %d modifications, %d parse failures\n", - test_idx, counter, parse_err); - } -} - static void test_gprs_timer_enc_dec(void) { int i, u, secs, tmr; @@ -465,7 +229,6 @@ int main(int argc, char **argv) test_8_4_2(); test_gsm_03_03_apn(); - test_gsup_messages_dec_enc(); test_gprs_timer_enc_dec(); printf("Done.\n"); diff --git a/openbsc/tests/gprs/gprs_test.ok b/openbsc/tests/gprs/gprs_test.ok index 688d44b24..da7888c6a 100644 --- a/openbsc/tests/gprs/gprs_test.ok +++ b/openbsc/tests/gprs/gprs_test.ok @@ -13,18 +13,5 @@ N(U) = 511, V(UR) = 511 => new N(U) = 510, V(UR) = 511 => retransmit N(U) = 481, V(UR) = 511 => retransmit N(U) = 479, V(UR) = 511 => new -Test GSUP message decoding/encoding - Testing Send Authentication Info Request - Testing Send Authentication Info Error - Testing Send Authentication Info Result - Testing Update Location Request - Testing Update Location Error - Testing Update Location Result - Testing Location Cancellation Request - Testing Location Cancellation Error - Testing Location Cancellation Result - Testing Purge MS Request - Testing Purge MS Error - Testing Purge MS Result Test GPRS timer decoding/encoding Done. diff --git a/openbsc/tests/sgsn/Makefile.am b/openbsc/tests/sgsn/Makefile.am index aebcf0105..e3cec5086 100644 --- a/openbsc/tests/sgsn/Makefile.am +++ b/openbsc/tests/sgsn/Makefile.am @@ -23,7 +23,6 @@ sgsn_test_LDADD = \ $(top_builddir)/src/gprs/sgsn_libgtp.o \ $(top_builddir)/src/gprs/sgsn_auth.o \ $(top_builddir)/src/gprs/sgsn_ares.o \ - $(top_builddir)/src/gprs/gprs_gsup_messages.o \ $(top_builddir)/src/gprs/gprs_gsup_client.o \ $(top_builddir)/src/gprs/gprs_utils.o \ $(top_builddir)/src/gprs/gprs_subscriber.o \ diff --git a/openbsc/tests/sgsn/sgsn_test.c b/openbsc/tests/sgsn/sgsn_test.c index 94c277f55..5cffff289 100644 --- a/openbsc/tests/sgsn/sgsn_test.c +++ b/openbsc/tests/sgsn/sgsn_test.c @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include @@ -1266,13 +1266,13 @@ static void test_gmm_attach_subscr_gsup_auth(int retry) int my_gprs_gsup_client_send(struct gprs_gsup_client *gsupc, struct msgb *msg) { - struct gprs_gsup_message to_peer = {0}; - struct gprs_gsup_message from_peer = {0}; + struct osmo_gsup_message to_peer = {0}; + struct osmo_gsup_message from_peer = {0}; struct msgb *reply_msg; int rc; /* Simulate the GSUP peer */ - rc = gprs_gsup_decode(msgb_data(msg), msgb_length(msg), &to_peer); + rc = osmo_gsup_decode(msgb_data(msg), msgb_length(msg), &to_peer); OSMO_ASSERT(rc >= 0); OSMO_ASSERT(to_peer.imsi[0] != 0); strncpy(from_peer.imsi, to_peer.imsi, sizeof(from_peer.imsi)); @@ -1281,16 +1281,16 @@ int my_gprs_gsup_client_send(struct gprs_gsup_client *gsupc, struct msgb *msg) msgb_free(msg); switch (to_peer.message_type) { - case GPRS_GSUP_MSGT_UPDATE_LOCATION_REQUEST: + case OSMO_GSUP_MSGT_UPDATE_LOCATION_REQUEST: /* Send UPDATE_LOCATION_RESULT */ return my_subscr_request_update_gsup_auth(NULL); - case GPRS_GSUP_MSGT_SEND_AUTH_INFO_REQUEST: + case OSMO_GSUP_MSGT_SEND_AUTH_INFO_REQUEST: /* Send SEND_AUTH_INFO_RESULT */ return my_subscr_request_auth_info_gsup_auth(NULL); - case GPRS_GSUP_MSGT_PURGE_MS_REQUEST: - from_peer.message_type = GPRS_GSUP_MSGT_PURGE_MS_RESULT; + case OSMO_GSUP_MSGT_PURGE_MS_REQUEST: + from_peer.message_type = OSMO_GSUP_MSGT_PURGE_MS_RESULT; break; default: @@ -1308,7 +1308,7 @@ int my_gprs_gsup_client_send(struct gprs_gsup_client *gsupc, struct msgb *msg) reply_msg = gprs_gsup_msgb_alloc(); reply_msg->l2h = reply_msg->data; - gprs_gsup_encode(reply_msg, &from_peer); + osmo_gsup_encode(reply_msg, &from_peer); gprs_subscr_rx_gsup_message(reply_msg); msgb_free(reply_msg); -- cgit v1.2.3 From 31760a1f6089fb59475ba79faa3eb97e4cf00f68 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Wed, 27 Apr 2016 15:17:14 +0200 Subject: oap_message.h: Remove dependency to openbsc include This is a first step to moving oap_messages.h to libosmocore --- openbsc/tests/oap/oap_test.c | 1 + 1 file changed, 1 insertion(+) (limited to 'openbsc/tests') diff --git a/openbsc/tests/oap/oap_test.c b/openbsc/tests/oap/oap_test.c index 9a2063bdc..4ee5d4207 100644 --- a/openbsc/tests/oap/oap_test.c +++ b/openbsc/tests/oap/oap_test.c @@ -26,6 +26,7 @@ #include #include +#include static void test_oap_api(void) { -- cgit v1.2.3 From 564c06525b9acb3f4b90d4c92970e7d9cc5b1d8e Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Wed, 27 Apr 2016 18:14:14 +0200 Subject: OAP: use osmo_oap_ prefix for OAP, rather than plain oap_ this is in preparation of moving related code to libosmocore. --- openbsc/tests/oap/oap_test.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'openbsc/tests') diff --git a/openbsc/tests/oap/oap_test.c b/openbsc/tests/oap/oap_test.c index 4ee5d4207..625d8d892 100644 --- a/openbsc/tests/oap/oap_test.c +++ b/openbsc/tests/oap/oap_test.c @@ -95,8 +95,8 @@ static void test_oap_api(void) printf(" - AUTN failures\n"); - struct oap_message oap_rx; - struct oap_message oap_tx; + struct osmo_oap_message oap_rx; + struct osmo_oap_message oap_tx; struct msgb *msg_rx; struct msgb *msg_tx; @@ -168,7 +168,7 @@ static void test_oap_api(void) /* Expect the challenge response in msg_tx */ OSMO_ASSERT(msg_tx); - OSMO_ASSERT(oap_decode(msg_tx->data, msg_tx->len, &oap_tx) == 0); + OSMO_ASSERT(osmo_oap_decode(msg_tx->data, msg_tx->len, &oap_tx) == 0); OSMO_ASSERT(oap_tx.message_type == OAP_MSGT_CHALLENGE_RESULT); OSMO_ASSERT(strcmp("e2d05b598c61d9ba", osmo_hexdump_nospc(oap_tx.xres, sizeof(oap_tx.xres))) @@ -191,7 +191,7 @@ static void test_oap_api(void) OSMO_ASSERT(oap_handle(state, msg_rx, &msg_tx) == 0); OSMO_ASSERT(state->registration_failures == 1); OSMO_ASSERT(msg_tx); - OSMO_ASSERT(oap_decode(msg_tx->data, msg_tx->len, &oap_tx) == 0); + OSMO_ASSERT(osmo_oap_decode(msg_tx->data, msg_tx->len, &oap_tx) == 0); OSMO_ASSERT(oap_tx.message_type == OAP_MSGT_REGISTER_REQUEST); OSMO_ASSERT(state->state == OAP_REQUESTED_CHALLENGE); msgb_free(msg_tx); -- cgit v1.2.3 From 5d547a4358edbd18744d1996d6ecb40328f09061 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Wed, 27 Apr 2016 18:21:16 +0200 Subject: osmo_oap_decode(): Use common argument ordering In general, if a function generates output data like a msgb (or in this case filling an osmo_oap_message structure), the output argument precedes the source. This is what we use all over libosmo*, and it is modelled after memcpy(), where dst is the first argument, before src. Let's align osmo_oap_decode(). Intestingly, osmo_oap_encode was already correct, so the encode/decode functions used different conventions before. --- openbsc/tests/oap/oap_test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'openbsc/tests') diff --git a/openbsc/tests/oap/oap_test.c b/openbsc/tests/oap/oap_test.c index 625d8d892..339d77430 100644 --- a/openbsc/tests/oap/oap_test.c +++ b/openbsc/tests/oap/oap_test.c @@ -168,7 +168,7 @@ static void test_oap_api(void) /* Expect the challenge response in msg_tx */ OSMO_ASSERT(msg_tx); - OSMO_ASSERT(osmo_oap_decode(msg_tx->data, msg_tx->len, &oap_tx) == 0); + OSMO_ASSERT(osmo_oap_decode(&oap_tx, msg_tx->data, msg_tx->len) == 0); OSMO_ASSERT(oap_tx.message_type == OAP_MSGT_CHALLENGE_RESULT); OSMO_ASSERT(strcmp("e2d05b598c61d9ba", osmo_hexdump_nospc(oap_tx.xres, sizeof(oap_tx.xres))) @@ -191,7 +191,7 @@ static void test_oap_api(void) OSMO_ASSERT(oap_handle(state, msg_rx, &msg_tx) == 0); OSMO_ASSERT(state->registration_failures == 1); OSMO_ASSERT(msg_tx); - OSMO_ASSERT(osmo_oap_decode(msg_tx->data, msg_tx->len, &oap_tx) == 0); + OSMO_ASSERT(osmo_oap_decode(&oap_tx, msg_tx->data, msg_tx->len) == 0); OSMO_ASSERT(oap_tx.message_type == OAP_MSGT_REGISTER_REQUEST); OSMO_ASSERT(state->state == OAP_REQUESTED_CHALLENGE); msgb_free(msg_tx); -- cgit v1.2.3 From cd5e52605cdb77bdc6f36fce81a6a1bac7fbda48 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Fri, 6 May 2016 13:46:21 +0200 Subject: sgsn_test: Adapt test case to now-existing InsertSubscriberData We recently implementd InsertSubscriberData in the SGSN, adapt the test to reflect that. --- openbsc/tests/sgsn/sgsn_test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'openbsc/tests') diff --git a/openbsc/tests/sgsn/sgsn_test.c b/openbsc/tests/sgsn/sgsn_test.c index 5cffff289..afff30f32 100644 --- a/openbsc/tests/sgsn/sgsn_test.c +++ b/openbsc/tests/sgsn/sgsn_test.c @@ -610,8 +610,8 @@ static void test_subscriber_gsup(void) /* Inject InsertSubscrData GSUP message */ last_updated_subscr = NULL; rc = rx_gsup_message(insert_data_req, sizeof(insert_data_req)); - OSMO_ASSERT(rc == -GMM_CAUSE_MSGT_NOTEXIST_NOTIMPL); - OSMO_ASSERT(last_updated_subscr == NULL); + OSMO_ASSERT(rc = -ENOTSUP); /* not connected */ + OSMO_ASSERT(last_updated_subscr == s1); /* Inject DeleteSubscrData GSUP message */ last_updated_subscr = NULL; -- cgit v1.2.3