blob: 7cc9b9a4fded5b6fe4a5b77c01f0af60e1d63475 [file] [log] [blame]
Wei-Yu Chen49950b92021-11-08 19:19:18 +08001"""
2Copyright 2020 The Magma Authors.
3
4This source code is licensed under the BSD-style license found in the
5LICENSE file in the root directory of this source tree.
6
7Unless required by applicable law or agreed to in writing, software
8distributed under the License is distributed on an "AS IS" BASIS,
9WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10See the License for the specific language governing permissions and
11limitations under the License.
12"""
13
14from data_models.data_model_parameters import ParameterName
15# pylint: disable=protected-access
16from devices.device_utils import EnodebDeviceName
17from tests.test_utils.enb_acs_builder import (
18 EnodebAcsStateMachineBuilder,
19)
20from tests.test_utils.enodeb_handler import EnodebHandlerTestCase
21from tests.test_utils.tr069_msg_builder import Tr069MessageBuilder
22from tr069 import models
23
24
25class CaviumHandlerTests(EnodebHandlerTestCase):
26 def test_count_plmns_less(self) -> None:
27 """
28 Tests the Cavium provisioning up to GetObjectParameters.
29
30 In particular tests when the eNB reports NUM_PLMNS less
31 than actually listed. The eNB says there are no PLMNs
32 defined when actually there are two.
33
34 Verifies that the number of PLMNs is correctly accounted.
35 """
36 acs_state_machine = \
37 EnodebAcsStateMachineBuilder \
38 .build_acs_state_machine(EnodebDeviceName.CAVIUM)
39
40 # Send an Inform message
41 inform_msg = Tr069MessageBuilder.get_inform(
42 '000FB7',
43 'OC-LTE',
44 '120200002618AGP0003',
45 ['1 BOOT'],
46 )
47 resp = acs_state_machine.handle_tr069_message(inform_msg)
48
49 self.assertTrue(
50 isinstance(resp, models.InformResponse),
51 'Should respond with an InformResponse',
52 )
53
54 # Send an empty http request to kick off the rest of provisioning
55 req = models.DummyInput()
56 resp = acs_state_machine.handle_tr069_message(req)
57 self.assertTrue(
58 isinstance(resp, models.GetParameterValues),
59 'State machine should be requesting param values: %s' % resp,
60 )
61
62 # Transient config response and request for parameter values
63 req = Tr069MessageBuilder.get_read_only_param_values_response()
64 resp = acs_state_machine.handle_tr069_message(req)
65 self.assertTrue(
66 isinstance(resp, models.GetParameterValues),
67 'State machine should be requesting param values: %s' % resp,
68 )
69
70 # Send back typical values for the regular parameters
71 req = Tr069MessageBuilder.get_cavium_param_values_response(num_plmns=0)
72 resp = acs_state_machine.handle_tr069_message(req)
73
74 # SM will be requesting object parameter values
75 self.assertTrue(
76 isinstance(resp, models.GetParameterValues),
77 'State machine should be requesting object param vals',
78 )
79
80 # Send back some object parameters with TWO plmns
81 req = Tr069MessageBuilder.get_cavium_object_param_values_response(
82 num_plmns=2,
83 )
84 resp = acs_state_machine.handle_tr069_message(req)
85
86 # In this scenario, the ACS and thus state machine will not need
87 # to delete or add objects to the eNB configuration.
88 # SM should then just be attempting to set parameter values
89 self.assertTrue(
90 isinstance(resp, models.SetParameterValues),
91 'State machine should be setting param values',
92 )
93
94 # Number of PLMNs should reflect object count
95 num_plmns_cur = \
96 acs_state_machine \
97 .device_cfg.get_parameter(ParameterName.NUM_PLMNS)
98 self.assertEqual(num_plmns_cur, 2)
99
100 def test_count_plmns_more_defined(self) -> None:
101 """
102 Tests the Cavium provisioning up to GetObjectParameters.
103
104 In particular tests when the eNB has more PLMNs than is
105 currently defined in our data model (NUM_PLMNS_IN_CONFIG)
106 """
107 acs_state_machine = \
108 EnodebAcsStateMachineBuilder \
109 .build_acs_state_machine(EnodebDeviceName.CAVIUM)
110
111 # Send an Inform message
112 inform_msg = Tr069MessageBuilder.get_inform(
113 '000FB7',
114 'OC-LTE',
115 '120200002618AGP0003',
116 ['1 BOOT'],
117 )
118 resp = acs_state_machine.handle_tr069_message(inform_msg)
119
120 self.assertTrue(
121 isinstance(resp, models.InformResponse),
122 'Should respond with an InformResponse',
123 )
124
125 # Send an empty http request to kick off the rest of provisioning
126 req = models.DummyInput()
127 resp = acs_state_machine.handle_tr069_message(req)
128 self.assertTrue(
129 isinstance(resp, models.GetParameterValues),
130 'State machine should be requesting param values: %s' % resp,
131 )
132
133 # Transient config response and request for parameter values
134 req = Tr069MessageBuilder.get_read_only_param_values_response()
135 resp = acs_state_machine.handle_tr069_message(req)
136 self.assertTrue(
137 isinstance(resp, models.GetParameterValues),
138 'State machine should be requesting param values: %s' % resp,
139 )
140
141 # Send back regular parameters, and some absurd number of PLMNS
142 req = Tr069MessageBuilder.get_cavium_param_values_response(
143 num_plmns=100,
144 )
145 resp = acs_state_machine.handle_tr069_message(req)
146
147 # SM will be requesting object parameter values
148 self.assertTrue(
149 isinstance(resp, models.GetParameterValues),
150 'State machine should be requesting object param vals',
151 )
152
153 # Send back some object parameters with an absurd number of PLMNs
154 req = Tr069MessageBuilder.get_cavium_object_param_values_response(
155 num_plmns=100,
156 )
157 resp = acs_state_machine.handle_tr069_message(req)
158
159 # In this scenario, the ACS and thus state machine will not need
160 # to delete or add objects to the eNB configuration.
161 # SM should then just be attempting to set parameter values
162 self.assertTrue(
163 isinstance(resp, models.SetParameterValues),
164 'State machine should be setting param values',
165 )
166
167 # Number of PLMNs should reflect data model
168 num_plmns_cur = \
169 acs_state_machine \
170 .device_cfg.get_parameter(ParameterName.NUM_PLMNS)
171 self.assertEqual(num_plmns_cur, 6)