• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 androidx.test.ext.junit.runners.AndroidJUnit4;
28 
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 
32 import java.util.HashSet;
33 import java.util.Set;
34 
35 @RunWith(AndroidJUnit4.class)
36 public class VcnCellUnderlyingNetworkTemplateTest extends VcnUnderlyingNetworkTemplateTestBase {
37     private static final Set<String> ALLOWED_PLMN_IDS = Set.of("123456", "12345");
38     private static final Set<Integer> ALLOWED_CARRIER_IDS = Set.of(100, 101);
39 
getTestNetworkTemplateBuilder()40     private static VcnCellUnderlyingNetworkTemplate.Builder getTestNetworkTemplateBuilder() {
41         return new VcnCellUnderlyingNetworkTemplate.Builder()
42                 .setMetered(MATCH_REQUIRED)
43                 .setRoaming(MATCH_REQUIRED)
44                 .setOpportunistic(MATCH_FORBIDDEN)
45                 .setOperatorPlmnIds(ALLOWED_PLMN_IDS)
46                 .setSimSpecificCarrierIds(ALLOWED_CARRIER_IDS)
47                 .setMinDownstreamBandwidthKbps(
48                         MIN_ENTRY_DOWN_BANDWIDTH_KBPS, MIN_EXIT_DOWN_BANDWIDTH_KBPS)
49                 .setMinUpstreamBandwidthKbps(
50                         MIN_ENTRY_UP_BANDWIDTH_KBPS, MIN_EXIT_UP_BANDWIDTH_KBPS);
51     }
52 
53     // Package private for use in VcnGatewayConnectionConfigTest
getTestNetworkTemplate()54     static VcnCellUnderlyingNetworkTemplate getTestNetworkTemplate() {
55         return getTestNetworkTemplateBuilder().build();
56     }
57 
setAllCapabilities( VcnCellUnderlyingNetworkTemplate.Builder builder, int matchCriteria)58     private static void setAllCapabilities(
59             VcnCellUnderlyingNetworkTemplate.Builder builder, int matchCriteria) {
60         builder.setCbs(matchCriteria);
61         builder.setDun(matchCriteria);
62         builder.setIms(matchCriteria);
63         builder.setInternet(matchCriteria);
64         builder.setMms(matchCriteria);
65         builder.setRcs(matchCriteria);
66     }
67 
verifyAllCapabilities( VcnCellUnderlyingNetworkTemplate template, int expectMatchCriteriaforNonInternet, int expectMatchCriteriaforInternet)68     private static void verifyAllCapabilities(
69             VcnCellUnderlyingNetworkTemplate template,
70             int expectMatchCriteriaforNonInternet,
71             int expectMatchCriteriaforInternet) {
72         assertEquals(expectMatchCriteriaforNonInternet, template.getCbs());
73         assertEquals(expectMatchCriteriaforNonInternet, template.getDun());
74         assertEquals(expectMatchCriteriaforNonInternet, template.getIms());
75         assertEquals(expectMatchCriteriaforNonInternet, template.getMms());
76         assertEquals(expectMatchCriteriaforNonInternet, template.getRcs());
77 
78         assertEquals(expectMatchCriteriaforInternet, template.getInternet());
79     }
80 
81     @Test
testBuilderAndGetters()82     public void testBuilderAndGetters() {
83         final VcnCellUnderlyingNetworkTemplate.Builder builder = getTestNetworkTemplateBuilder();
84         setAllCapabilities(builder, MATCH_REQUIRED);
85 
86         final VcnCellUnderlyingNetworkTemplate networkTemplate = builder.build();
87 
88         assertEquals(MATCH_REQUIRED, networkTemplate.getMetered());
89         assertEquals(MATCH_REQUIRED, networkTemplate.getRoaming());
90         assertEquals(MATCH_FORBIDDEN, networkTemplate.getOpportunistic());
91         assertEquals(ALLOWED_PLMN_IDS, networkTemplate.getOperatorPlmnIds());
92         assertEquals(ALLOWED_CARRIER_IDS, networkTemplate.getSimSpecificCarrierIds());
93         verifyBandwidthsWithTestValues(networkTemplate);
94         verifyAllCapabilities(networkTemplate, MATCH_REQUIRED, MATCH_REQUIRED);
95     }
96 
97     @Test
testBuilderAndGettersForDefaultValues()98     public void testBuilderAndGettersForDefaultValues() {
99         final VcnCellUnderlyingNetworkTemplate networkTemplate =
100                 new VcnCellUnderlyingNetworkTemplate.Builder().build();
101         assertEquals(MATCH_ANY, networkTemplate.getMetered());
102         assertEquals(MATCH_ANY, networkTemplate.getRoaming());
103         assertEquals(MATCH_ANY, networkTemplate.getOpportunistic());
104         assertEquals(new HashSet<String>(), networkTemplate.getOperatorPlmnIds());
105         assertEquals(new HashSet<Integer>(), networkTemplate.getSimSpecificCarrierIds());
106         verifyBandwidthsWithDefaultValues(networkTemplate);
107         verifyAllCapabilities(networkTemplate, MATCH_ANY, MATCH_REQUIRED);
108     }
109 
110     @Test
testBuildWithEmptySets()111     public void testBuildWithEmptySets() {
112         final VcnCellUnderlyingNetworkTemplate networkTemplate =
113                 new VcnCellUnderlyingNetworkTemplate.Builder()
114                         .setOperatorPlmnIds(new HashSet<String>())
115                         .setSimSpecificCarrierIds(new HashSet<Integer>())
116                         .build();
117         assertEquals(new HashSet<String>(), networkTemplate.getOperatorPlmnIds());
118         assertEquals(new HashSet<Integer>(), networkTemplate.getSimSpecificCarrierIds());
119     }
120 
121     @Test
testBuildWithNullOperatorPlmnIds()122     public void testBuildWithNullOperatorPlmnIds() {
123         try {
124             new VcnCellUnderlyingNetworkTemplate.Builder().setOperatorPlmnIds(null);
125             fail("Expect to fail due to the null argument");
126         } catch (Exception expected) {
127         }
128     }
129 
verifyBuildWithInvalidOperatorPlmnIds(String plmnId)130     private static void verifyBuildWithInvalidOperatorPlmnIds(String plmnId) {
131         try {
132             new VcnCellUnderlyingNetworkTemplate.Builder().setOperatorPlmnIds(Set.of(plmnId));
133             fail("Expect to fail due to the invalid PLMN ID");
134         } catch (Exception expected) {
135         }
136     }
137 
138     @Test
testBuildWithInvalidOperatorPlmnIds()139     public void testBuildWithInvalidOperatorPlmnIds() {
140         verifyBuildWithInvalidOperatorPlmnIds("1234567");
141         verifyBuildWithInvalidOperatorPlmnIds("1234");
142         verifyBuildWithInvalidOperatorPlmnIds("abcde");
143     }
144 
145     @Test
testBuildWithNullCarrierIds()146     public void testBuildWithNullCarrierIds() {
147         try {
148             new VcnCellUnderlyingNetworkTemplate.Builder().setSimSpecificCarrierIds(null);
149             fail("Expect to fail due to the null argument");
150         } catch (Exception expected) {
151         }
152     }
153 
154     @Test
testBuildWithInvalidDownstreamBandwidth()155     public void testBuildWithInvalidDownstreamBandwidth() {
156         try {
157             new VcnCellUnderlyingNetworkTemplate.Builder()
158                     .setMinDownstreamBandwidthKbps(
159                             MIN_ENTRY_DOWN_BANDWIDTH_KBPS, MIN_ENTRY_DOWN_BANDWIDTH_KBPS + 1);
160             fail("Expect to fail because entry bandwidth is smaller than exit bandwidth");
161         } catch (Exception expected) {
162         }
163     }
164 
165     @Test
testBuildWithInvalidUpstreamBandwidth()166     public void testBuildWithInvalidUpstreamBandwidth() {
167         try {
168             new VcnCellUnderlyingNetworkTemplate.Builder()
169                     .setMinUpstreamBandwidthKbps(
170                             MIN_ENTRY_UP_BANDWIDTH_KBPS, MIN_ENTRY_UP_BANDWIDTH_KBPS + 1);
171             fail("Expect to fail because entry bandwidth is smaller than exit bandwidth");
172         } catch (Exception expected) {
173         }
174     }
175 }
176