From 79737b4193df44bcf4db7f20187f7fd177d8a028 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Wed, 10 Apr 2019 10:39:30 +0200 Subject: ggsn: Verify that there are no duplicate PCO protocolIDs Introduce a function to verify there's no duplicate ProtocolIDs in the PCO returned from the GGSN. Change-Id: I9d439dab1696196cd125f4d7113b426f1711a405 Related: OS#3914 --- ggsn_tests/GGSN_Tests.ttcn | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'ggsn_tests') diff --git a/ggsn_tests/GGSN_Tests.ttcn b/ggsn_tests/GGSN_Tests.ttcn index 398aed3c..d793d27e 100644 --- a/ggsn_tests/GGSN_Tests.ttcn +++ b/ggsn_tests/GGSN_Tests.ttcn @@ -726,6 +726,33 @@ module GGSN_Tests { T_default.stop; } + /* list of protocols where we don't accept duplicates */ + const OCT2List protocol_ids_nodupes := { 'C021'O, 'C023'O, 'C223'O, '8021'O }; + private function f_PCO_permits_duplicates(OCT2 id) return boolean { + var integer i; + for (i := 0; i < lengthof(protocol_ids_nodupes); i := i+1) { + if (id == protocol_ids_nodupes[i]) { + return false; + } + } + return true; + } + + /* ensure that every given protocol Identifier exist only exactly once in the PCO */ + function f_PCO_ensure_no_duplicates(ProtConfigOptions pco) { + var OCT2List protocol_ids := {}; + var integer i, j; + for (i := 0; i < lengthof(pco.protocols); i := i+1) { + var OCT2 id := pco.protocols[i].protocolID; + for (j := 0; j < lengthof(protocol_ids); j := j+1) { + if (not f_PCO_permits_duplicates(id) and id == protocol_ids[j]) { + setverdict(fail, "Duplicate ProtocolID ", id, " already present in ", pco.protocols); + } + } + protocol_ids := protocol_ids & { id }; + } + } + /* Test IPv6 context activation for dynamic IPv6 EUA without request of IPv6 DNS */ testcase TC_pdp6_act_deact() runs on GT_CT { f_init(); @@ -743,6 +770,7 @@ module GGSN_Tests { ctx.pco_req := valueof(ts_PCO_IPv6_DNS); f_pdp_ctx_act(ctx); + f_PCO_ensure_no_duplicates(ctx.pco_neg); /* verify PCO contains both primary and secondary DNS */ var OCT4 ggsn_ip6_dns1 := f_inet6_addr(m_ggsn_ip6_dns1); if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 1), ggsn_ip6_dns1)) { @@ -765,6 +793,7 @@ module GGSN_Tests { ctx.pco_req := valueof(ts_PCO_IPv6_DNS); f_pdp_ctx_act(ctx); + f_PCO_ensure_no_duplicates(ctx.pco_neg); //f_send_gtpu(ctx, c_router_solicit); //f_send_gtpu(ctx, c_neigh_solicit); @@ -865,6 +894,7 @@ module GGSN_Tests { var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn))); ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP); f_pdp_ctx_act(ctx); + f_PCO_ensure_no_duplicates(ctx.pco_neg); /* verify IPCP is at all contained */ if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) { setverdict(fail, "IPCP not found in PCO"); @@ -888,6 +918,7 @@ module GGSN_Tests { ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT); f_pdp_ctx_act(ctx); + f_PCO_ensure_no_duplicates(ctx.pco_neg); /* verify PCO contains both primary and secondary DNS */ var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1); if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) { @@ -910,6 +941,7 @@ module GGSN_Tests { ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT); f_pdp_ctx_act(ctx); + f_PCO_ensure_no_duplicates(ctx.pco_neg); var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O); /* Check if we can use valid global src addr, should work */ @@ -986,6 +1018,7 @@ module GGSN_Tests { /* PCO with primary DNS only */ ctx.pco_req := valueof(ts_PCO_IPv4_PRI_DNS_IPCP); f_pdp_ctx_act(ctx); + f_PCO_ensure_no_duplicates(ctx.pco_neg); pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1); pco_neg_dns_expected := '0200000A8106'O & ggsn_ip4_dns1 /* Note: The prepended hex bytes encode the following information: @@ -1063,10 +1096,12 @@ module GGSN_Tests { var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn))); ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP); f_pdp_ctx_act(ctx); + f_PCO_ensure_no_duplicates(ctx.pco_neg); /* verify IPCP is at all contained */ if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) { setverdict(fail, "IPCP not found in PCO"); } + f_PCO_ensure_no_duplicates(ctx.pco_neg); /* verify IPCP contains both primary and secondary IPv4 DNS */ var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O)); if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) { @@ -1101,6 +1136,7 @@ module GGSN_Tests { ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT); f_pdp_ctx_act(ctx); + f_PCO_ensure_no_duplicates(ctx.pco_neg); /* verify PCO contains both primary and secondary IPv4 DNS */ var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1); if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) { @@ -1123,6 +1159,7 @@ module GGSN_Tests { ctx.pco_req := valueof(ts_PCO_IPv6_DNS); f_pdp_ctx_act(ctx); + f_PCO_ensure_no_duplicates(ctx.pco_neg); /* verify PCO contains both primary and secondary IPv6 DNS */ var OCT4 ggsn_ip6_dns1 := f_inet6_addr(m_ggsn_ip6_dns1); if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 1), ggsn_ip6_dns1)) { -- cgit v1.2.3