1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package android.net.vcn.cts; 17 18 import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_ANY; 19 import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_FORBIDDEN; 20 import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_REQUIRED; 21 22 import static org.junit.Assert.assertEquals; 23 import static org.junit.Assert.fail; 24 25 import android.net.vcn.VcnCellUnderlyingNetworkTemplate; 26 27 import org.junit.Test; 28 29 import java.util.HashSet; 30 import java.util.Set; 31 32 public class VcnCellUnderlyingNetworkTemplateTest extends VcnUnderlyingNetworkTemplateTestBase { 33 private static final Set<String> ALLOWED_PLMN_IDS = Set.of("123456", "12345"); 34 private static final Set<Integer> ALLOWED_CARRIER_IDS = Set.of(100, 101); 35 getTestNetworkTemplateBuilder()36 private static VcnCellUnderlyingNetworkTemplate.Builder getTestNetworkTemplateBuilder() { 37 return new VcnCellUnderlyingNetworkTemplate.Builder() 38 .setMetered(MATCH_REQUIRED) 39 .setRoaming(MATCH_REQUIRED) 40 .setOpportunistic(MATCH_FORBIDDEN) 41 .setOperatorPlmnIds(ALLOWED_PLMN_IDS) 42 .setSimSpecificCarrierIds(ALLOWED_CARRIER_IDS) 43 .setMinDownstreamBandwidthKbps( 44 MIN_ENTRY_DOWN_BANDWIDTH_KBPS, MIN_EXIT_DOWN_BANDWIDTH_KBPS) 45 .setMinUpstreamBandwidthKbps( 46 MIN_ENTRY_UP_BANDWIDTH_KBPS, MIN_EXIT_UP_BANDWIDTH_KBPS); 47 } 48 49 // Package private for use in VcnGatewayConnectionConfigTest getTestNetworkTemplate()50 static VcnCellUnderlyingNetworkTemplate getTestNetworkTemplate() { 51 return getTestNetworkTemplateBuilder().build(); 52 } 53 setAllCapabilities( VcnCellUnderlyingNetworkTemplate.Builder builder, int matchCriteria)54 private static void setAllCapabilities( 55 VcnCellUnderlyingNetworkTemplate.Builder builder, int matchCriteria) { 56 builder.setCbs(matchCriteria); 57 builder.setDun(matchCriteria); 58 builder.setIms(matchCriteria); 59 builder.setInternet(matchCriteria); 60 builder.setMms(matchCriteria); 61 builder.setRcs(matchCriteria); 62 } 63 verifyAllCapabilities( VcnCellUnderlyingNetworkTemplate template, int expectMatchCriteriaforNonInternet, int expectMatchCriteriaforInternet)64 private static void verifyAllCapabilities( 65 VcnCellUnderlyingNetworkTemplate template, 66 int expectMatchCriteriaforNonInternet, 67 int expectMatchCriteriaforInternet) { 68 assertEquals(expectMatchCriteriaforNonInternet, template.getCbs()); 69 assertEquals(expectMatchCriteriaforNonInternet, template.getDun()); 70 assertEquals(expectMatchCriteriaforNonInternet, template.getIms()); 71 assertEquals(expectMatchCriteriaforNonInternet, template.getMms()); 72 assertEquals(expectMatchCriteriaforNonInternet, template.getRcs()); 73 74 assertEquals(expectMatchCriteriaforInternet, template.getInternet()); 75 } 76 77 @Test testBuilderAndGetters()78 public void testBuilderAndGetters() { 79 final VcnCellUnderlyingNetworkTemplate.Builder builder = getTestNetworkTemplateBuilder(); 80 setAllCapabilities(builder, MATCH_REQUIRED); 81 82 final VcnCellUnderlyingNetworkTemplate networkTemplate = builder.build(); 83 84 assertEquals(MATCH_REQUIRED, networkTemplate.getMetered()); 85 assertEquals(MATCH_REQUIRED, networkTemplate.getRoaming()); 86 assertEquals(MATCH_FORBIDDEN, networkTemplate.getOpportunistic()); 87 assertEquals(ALLOWED_PLMN_IDS, networkTemplate.getOperatorPlmnIds()); 88 assertEquals(ALLOWED_CARRIER_IDS, networkTemplate.getSimSpecificCarrierIds()); 89 verifyBandwidthsWithTestValues(networkTemplate); 90 verifyAllCapabilities(networkTemplate, MATCH_REQUIRED, MATCH_REQUIRED); 91 } 92 93 @Test testBuilderAndGettersForDefaultValues()94 public void testBuilderAndGettersForDefaultValues() { 95 final VcnCellUnderlyingNetworkTemplate networkTemplate = 96 new VcnCellUnderlyingNetworkTemplate.Builder().build(); 97 assertEquals(MATCH_ANY, networkTemplate.getMetered()); 98 assertEquals(MATCH_ANY, networkTemplate.getRoaming()); 99 assertEquals(MATCH_ANY, networkTemplate.getOpportunistic()); 100 assertEquals(new HashSet<String>(), networkTemplate.getOperatorPlmnIds()); 101 assertEquals(new HashSet<Integer>(), networkTemplate.getSimSpecificCarrierIds()); 102 verifyBandwidthsWithDefaultValues(networkTemplate); 103 verifyAllCapabilities(networkTemplate, MATCH_ANY, MATCH_REQUIRED); 104 } 105 106 @Test testBuildWithEmptySets()107 public void testBuildWithEmptySets() { 108 final VcnCellUnderlyingNetworkTemplate networkTemplate = 109 new VcnCellUnderlyingNetworkTemplate.Builder() 110 .setOperatorPlmnIds(new HashSet<String>()) 111 .setSimSpecificCarrierIds(new HashSet<Integer>()) 112 .build(); 113 assertEquals(new HashSet<String>(), networkTemplate.getOperatorPlmnIds()); 114 assertEquals(new HashSet<Integer>(), networkTemplate.getSimSpecificCarrierIds()); 115 } 116 117 @Test testBuildWithNullOperatorPlmnIds()118 public void testBuildWithNullOperatorPlmnIds() { 119 try { 120 new VcnCellUnderlyingNetworkTemplate.Builder().setOperatorPlmnIds(null); 121 fail("Expect to fail due to the null argument"); 122 } catch (Exception expected) { 123 } 124 } 125 verifyBuildWithInvalidOperatorPlmnIds(String plmnId)126 private static void verifyBuildWithInvalidOperatorPlmnIds(String plmnId) { 127 try { 128 new VcnCellUnderlyingNetworkTemplate.Builder().setOperatorPlmnIds(Set.of(plmnId)); 129 fail("Expect to fail due to the invalid PLMN ID"); 130 } catch (Exception expected) { 131 } 132 } 133 134 @Test testBuildWithInvalidOperatorPlmnIds()135 public void testBuildWithInvalidOperatorPlmnIds() { 136 verifyBuildWithInvalidOperatorPlmnIds("1234567"); 137 verifyBuildWithInvalidOperatorPlmnIds("1234"); 138 verifyBuildWithInvalidOperatorPlmnIds("abcde"); 139 } 140 141 @Test testBuildWithNullCarrierIds()142 public void testBuildWithNullCarrierIds() { 143 try { 144 new VcnCellUnderlyingNetworkTemplate.Builder().setSimSpecificCarrierIds(null); 145 fail("Expect to fail due to the null argument"); 146 } catch (Exception expected) { 147 } 148 } 149 150 @Test testBuildWithInvalidDownstreamBandwidth()151 public void testBuildWithInvalidDownstreamBandwidth() { 152 try { 153 new VcnCellUnderlyingNetworkTemplate.Builder() 154 .setMinDownstreamBandwidthKbps( 155 MIN_ENTRY_DOWN_BANDWIDTH_KBPS, MIN_ENTRY_DOWN_BANDWIDTH_KBPS + 1); 156 fail("Expect to fail because entry bandwidth is smaller than exit bandwidth"); 157 } catch (Exception expected) { 158 } 159 } 160 161 @Test testBuildWithInvalidUpstreamBandwidth()162 public void testBuildWithInvalidUpstreamBandwidth() { 163 try { 164 new VcnCellUnderlyingNetworkTemplate.Builder() 165 .setMinUpstreamBandwidthKbps( 166 MIN_ENTRY_UP_BANDWIDTH_KBPS, MIN_ENTRY_UP_BANDWIDTH_KBPS + 1); 167 fail("Expect to fail because entry bandwidth is smaller than exit bandwidth"); 168 } catch (Exception expected) { 169 } 170 } 171 } 172