blob: ba5d32bcae3762564b095be2d2155cbf520dde78 [file] [log] [blame]
Wei-Yu Chenad55cb82022-02-15 20:07:01 +08001# SPDX-FileCopyrightText: 2020 The Magma Authors.
2# SPDX-FileCopyrightText: 2022 Open Networking Foundation <support@opennetworking.org>
3#
4# SPDX-License-Identifier: BSD-3-Clause
Wei-Yu Chen49950b92021-11-08 19:19:18 +08005
6from data_models.data_model_parameters import ParameterName
7# pylint: disable=protected-access
8from devices.device_utils import EnodebDeviceName
9from tests.test_utils.enb_acs_builder import (
10 EnodebAcsStateMachineBuilder,
11)
12from tests.test_utils.enodeb_handler import EnodebHandlerTestCase
13from tests.test_utils.tr069_msg_builder import Tr069MessageBuilder
14from tr069 import models
15
16
17class CaviumHandlerTests(EnodebHandlerTestCase):
18 def test_count_plmns_less(self) -> None:
19 """
20 Tests the Cavium provisioning up to GetObjectParameters.
21
22 In particular tests when the eNB reports NUM_PLMNS less
23 than actually listed. The eNB says there are no PLMNs
24 defined when actually there are two.
25
26 Verifies that the number of PLMNs is correctly accounted.
27 """
28 acs_state_machine = \
29 EnodebAcsStateMachineBuilder \
30 .build_acs_state_machine(EnodebDeviceName.CAVIUM)
31
32 # Send an Inform message
33 inform_msg = Tr069MessageBuilder.get_inform(
34 '000FB7',
35 'OC-LTE',
36 '120200002618AGP0003',
37 ['1 BOOT'],
38 )
39 resp = acs_state_machine.handle_tr069_message(inform_msg)
40
41 self.assertTrue(
42 isinstance(resp, models.InformResponse),
43 'Should respond with an InformResponse',
44 )
45
46 # Send an empty http request to kick off the rest of provisioning
47 req = models.DummyInput()
48 resp = acs_state_machine.handle_tr069_message(req)
49 self.assertTrue(
50 isinstance(resp, models.GetParameterValues),
51 'State machine should be requesting param values: %s' % resp,
52 )
53
54 # Transient config response and request for parameter values
55 req = Tr069MessageBuilder.get_read_only_param_values_response()
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 # Send back typical values for the regular parameters
63 req = Tr069MessageBuilder.get_cavium_param_values_response(num_plmns=0)
64 resp = acs_state_machine.handle_tr069_message(req)
65
66 # SM will be requesting object parameter values
67 self.assertTrue(
68 isinstance(resp, models.GetParameterValues),
69 'State machine should be requesting object param vals',
70 )
71
72 # Send back some object parameters with TWO plmns
73 req = Tr069MessageBuilder.get_cavium_object_param_values_response(
74 num_plmns=2,
75 )
76 resp = acs_state_machine.handle_tr069_message(req)
77
78 # In this scenario, the ACS and thus state machine will not need
79 # to delete or add objects to the eNB configuration.
80 # SM should then just be attempting to set parameter values
81 self.assertTrue(
82 isinstance(resp, models.SetParameterValues),
83 'State machine should be setting param values',
84 )
85
86 # Number of PLMNs should reflect object count
87 num_plmns_cur = \
88 acs_state_machine \
89 .device_cfg.get_parameter(ParameterName.NUM_PLMNS)
90 self.assertEqual(num_plmns_cur, 2)
91
92 def test_count_plmns_more_defined(self) -> None:
93 """
94 Tests the Cavium provisioning up to GetObjectParameters.
95
96 In particular tests when the eNB has more PLMNs than is
97 currently defined in our data model (NUM_PLMNS_IN_CONFIG)
98 """
99 acs_state_machine = \
100 EnodebAcsStateMachineBuilder \
101 .build_acs_state_machine(EnodebDeviceName.CAVIUM)
102
103 # Send an Inform message
104 inform_msg = Tr069MessageBuilder.get_inform(
105 '000FB7',
106 'OC-LTE',
107 '120200002618AGP0003',
108 ['1 BOOT'],
109 )
110 resp = acs_state_machine.handle_tr069_message(inform_msg)
111
112 self.assertTrue(
113 isinstance(resp, models.InformResponse),
114 'Should respond with an InformResponse',
115 )
116
117 # Send an empty http request to kick off the rest of provisioning
118 req = models.DummyInput()
119 resp = acs_state_machine.handle_tr069_message(req)
120 self.assertTrue(
121 isinstance(resp, models.GetParameterValues),
122 'State machine should be requesting param values: %s' % resp,
123 )
124
125 # Transient config response and request for parameter values
126 req = Tr069MessageBuilder.get_read_only_param_values_response()
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 # Send back regular parameters, and some absurd number of PLMNS
134 req = Tr069MessageBuilder.get_cavium_param_values_response(
135 num_plmns=100,
136 )
137 resp = acs_state_machine.handle_tr069_message(req)
138
139 # SM will be requesting object parameter values
140 self.assertTrue(
141 isinstance(resp, models.GetParameterValues),
142 'State machine should be requesting object param vals',
143 )
144
145 # Send back some object parameters with an absurd number of PLMNs
146 req = Tr069MessageBuilder.get_cavium_object_param_values_response(
147 num_plmns=100,
148 )
149 resp = acs_state_machine.handle_tr069_message(req)
150
151 # In this scenario, the ACS and thus state machine will not need
152 # to delete or add objects to the eNB configuration.
153 # SM should then just be attempting to set parameter values
154 self.assertTrue(
155 isinstance(resp, models.SetParameterValues),
156 'State machine should be setting param values',
157 )
158
159 # Number of PLMNs should reflect data model
160 num_plmns_cur = \
161 acs_state_machine \
162 .device_cfg.get_parameter(ParameterName.NUM_PLMNS)
163 self.assertEqual(num_plmns_cur, 6)