blob: 43b27d9962feef331979895853e075c9a8a9b776 [file] [log] [blame]
Chip Boling67b674a2019-02-08 11:42:18 -06001#
2# Copyright 2017 the original author or authors.
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#
16from unittest import main, TestCase
17from pyvoltha.adapters.extensions.omci.omci_entities import *
18from pyvoltha.adapters.extensions.omci.tasks.mib_resync_task import MibResyncTask
19from pyvoltha.adapters.extensions.omci.database.mib_db_dict import MibDbVolatileDict as OnuDB
20from pyvoltha.adapters.extensions.omci.database.mib_db_ext import MibDbExternal as OltDB
21from mock.mock_adapter_agent import MockAdapterAgent, MockDevice
22
23_DEVICE_ID = 'br-549'
24
25
26class TestOmciMibResyncTask(TestCase):
27 def setUp(self):
28 self.adapter_agent = MockAdapterAgent()
29 self.adapter_agent.add_device(MockDevice(_DEVICE_ID)) # For Entity class lookups
30
31 self.onu_db = OnuDB(self.adapter_agent)
32 self.olt_db = OltDB(self.adapter_agent)
33
34 self.onu_db.start()
35 self.olt_db.start()
36
37 self.olt_db.add(_DEVICE_ID)
38 self.onu_db.add(_DEVICE_ID)
39
40 self.task = MibResyncTask(self.adapter_agent, _DEVICE_ID)
41
42 def tearDown(self):
43 self.onu_db.stop()
44 self.olt_db.stop()
45
46 def test_not_same_type_dbs(self):
47 #
48 # OLT DB is a copy of the 'external' DB, ONU is a volatile DB
49 #
50 self.assertNotEqual(type(self.olt_db), type(self.onu_db))
51
52 def test_db_same_format_str_field_serialization(self):
53 class_id = OltG.class_id
54 inst_id = 0
55 attributes = {
56 'olt_vendor_id': 'ABCD', # StrFixedLenField(4)
57 }
58 self.onu_db.set(_DEVICE_ID, class_id, inst_id, attributes)
59 self.olt_db.set(_DEVICE_ID, class_id, inst_id, attributes)
60
61 db_copy = self.olt_db.query(_DEVICE_ID)
62 db_active = self.onu_db.query(_DEVICE_ID)
63
64 olt_only, onu_only, attr_diffs = self.task.compare_mibs(db_copy, db_active)
65
66 self.assertEqual(len(olt_only), 0)
67 self.assertEqual(len(onu_only), 0)
68 self.assertEqual(len(attr_diffs), 0)
69
70 def test_db_same_format_mac_address_ip_field_serialization(self):
71 class_id = IpHostConfigData.class_id
72 inst_id = 0
73 attributes = {
74 'mac_address': '00:01:02:03:04:05', # MACField
75 'ip_address': '1.2.3.4', # IPField
76 }
77 self.onu_db.set(_DEVICE_ID, class_id, inst_id, attributes)
78 self.olt_db.set(_DEVICE_ID, class_id, inst_id, attributes)
79
80 db_copy = self.olt_db.query(_DEVICE_ID)
81 db_active = self.onu_db.query(_DEVICE_ID)
82
83 olt_only, onu_only, attr_diffs = self.task.compare_mibs(db_copy, db_active)
84
85 self.assertEqual(len(olt_only), 0)
86 self.assertEqual(len(onu_only), 0)
87 self.assertEqual(len(attr_diffs), 0)
88
89 def test_db_same_format_byte_and_short_field_serialization(self):
90 class_id = UniG.class_id
91 inst_id = 0
92 attributes = {
93 'administrative_state': int(1), # ByteField
94 'non_omci_management_identifier': int(12345) # IPField
95 }
96 self.onu_db.set(_DEVICE_ID, class_id, inst_id, attributes)
97 self.olt_db.set(_DEVICE_ID, class_id, inst_id, attributes)
98
99 db_copy = self.olt_db.query(_DEVICE_ID)
100 db_active = self.onu_db.query(_DEVICE_ID)
101
102 olt_only, onu_only, attr_diffs = self.task.compare_mibs(db_copy, db_active)
103
104 self.assertEqual(len(olt_only), 0)
105 self.assertEqual(len(onu_only), 0)
106 self.assertEqual(len(attr_diffs), 0)
107
108 def test_db_same_format_int_field_serialization(self):
109 class_id = PriorityQueueG.class_id
110 inst_id = 0
111 attributes = {
112 'related_port': int(1234567) # IntField
113 }
114 self.onu_db.set(_DEVICE_ID, class_id, inst_id, attributes)
115 self.olt_db.set(_DEVICE_ID, class_id, inst_id, attributes)
116
117 db_copy = self.olt_db.query(_DEVICE_ID)
118 db_active = self.onu_db.query(_DEVICE_ID)
119
120 olt_only, onu_only, attr_diffs = self.task.compare_mibs(db_copy, db_active)
121
122 self.assertEqual(len(olt_only), 0)
123 self.assertEqual(len(onu_only), 0)
124 self.assertEqual(len(attr_diffs), 0)
125
126 def test_db_same_format_long_field_serialization(self):
127 class_id = PriorityQueueG.class_id
128 inst_id = 0
129 attributes = {
130 'packet_drop_queue_thresholds': int(0x1234) # LongField
131 }
132 self.onu_db.set(_DEVICE_ID, class_id, inst_id, attributes)
133 self.olt_db.set(_DEVICE_ID, class_id, inst_id, attributes)
134
135 db_copy = self.olt_db.query(_DEVICE_ID)
136 db_active = self.onu_db.query(_DEVICE_ID)
137
138 olt_only, onu_only, attr_diffs = self.task.compare_mibs(db_copy, db_active)
139
140 self.assertEqual(len(olt_only), 0)
141 self.assertEqual(len(onu_only), 0)
142 self.assertEqual(len(attr_diffs), 0)
143
144 def test_db_same_format_bit_field_serialization(self):
145 class_id = OntG.class_id
146 inst_id = 0
147 attributes = {
148 'extended_tc_layer_options': long(0x1234), # BitField(16)
149 }
150 self.onu_db.set(_DEVICE_ID, class_id, inst_id, attributes)
151 self.olt_db.set(_DEVICE_ID, class_id, inst_id, attributes)
152
153 db_copy = self.olt_db.query(_DEVICE_ID)
154 db_active = self.onu_db.query(_DEVICE_ID)
155
156 olt_only, onu_only, attr_diffs = self.task.compare_mibs(db_copy, db_active)
157
158 self.assertEqual(len(olt_only), 0)
159 self.assertEqual(len(onu_only), 0)
160 self.assertEqual(len(attr_diffs), 0)
161
162 def test_db_same_format_list_field_serialization(self):
163 class_id = VlanTaggingFilterData.class_id
164 inst_id = 0
165 vlan_filter_list = [0] * 12
166 vlan_filter_list[0] = 0x1234
167
168 attributes = {
169 'vlan_filter_list': vlan_filter_list, # FieldListField
170 'forward_operation': 0,
171 'number_of_entries': 1
172 }
173 self.onu_db.set(_DEVICE_ID, class_id, inst_id, attributes)
174 self.olt_db.set(_DEVICE_ID, class_id, inst_id, attributes)
175
176 db_copy = self.olt_db.query(_DEVICE_ID)
177 db_active = self.onu_db.query(_DEVICE_ID)
178
179 olt_only, onu_only, attr_diffs = self.task.compare_mibs(db_copy, db_active)
180
181 self.assertEqual(len(olt_only), 0)
182 self.assertEqual(len(onu_only), 0)
183 self.assertEqual(len(attr_diffs), 0)
184
185 def test_db_same_format_complex_json_serialization(self):
186 class_id = ExtendedVlanTaggingOperationConfigurationData.class_id
187 inst_id = 0x202
188 table_data = VlanTaggingOperation(
189 filter_outer_priority=15,
190 filter_inner_priority=8,
191 filter_inner_vid=1024,
192 filter_inner_tpid_de=5,
193 filter_ether_type=0,
194 treatment_tags_to_remove=1,
195 pad3=2,
196 treatment_outer_priority=15,
197 treatment_inner_priority=8,
198 treatment_inner_vid=1024,
199 treatment_inner_tpid_de=4
200 )
201 attributes = dict(
202 received_frame_vlan_tagging_operation_table=table_data
203 )
204 self.onu_db.set(_DEVICE_ID, class_id, inst_id, attributes)
205 self.olt_db.set(_DEVICE_ID, class_id, inst_id, attributes)
206
207 db_copy = self.olt_db.query(_DEVICE_ID)
208 db_active = self.onu_db.query(_DEVICE_ID)
209
210 olt_only, onu_only, attr_diffs = self.task.compare_mibs(db_copy, db_active)
211
212 self.assertEqual(len(olt_only), 0)
213 self.assertEqual(len(onu_only), 0)
214 self.assertEqual(len(attr_diffs), 0)
215
216 def test_on_olt_only(self):
217 class_id = GemInterworkingTp.class_id
218 inst_id = 0
219 attributes = {
220 'gal_loopback_configuration': int(1)
221 }
222 self.olt_db.set(_DEVICE_ID, class_id, inst_id, attributes)
223
224 db_copy = self.olt_db.query(_DEVICE_ID)
225 db_active = self.onu_db.query(_DEVICE_ID)
226
227 olt_only, onu_only, attr_diffs = self.task.compare_mibs(db_copy, db_active)
228
229 self.assertEqual(len(olt_only), 1)
230 self.assertEqual(len(onu_only), 0)
231 self.assertEqual(len(attr_diffs), 0)
232 self.assertEqual(olt_only, [(class_id, inst_id)])
233
234 # Now a little more complex (extra instance on the OLT
235 self.olt_db.set(_DEVICE_ID, class_id, inst_id + 1, attributes)
236 self.onu_db.set(_DEVICE_ID, class_id, inst_id, attributes)
237
238 db_copy = self.olt_db.query(_DEVICE_ID)
239 db_active = self.onu_db.query(_DEVICE_ID)
240
241 olt_only, onu_only, attr_diffs = self.task.compare_mibs(db_copy, db_active)
242
243 self.assertEqual(len(olt_only), 1)
244 self.assertEqual(len(onu_only), 0)
245 self.assertEqual(len(attr_diffs), 0)
246 self.assertEqual(olt_only, [(class_id, inst_id + 1)])
247
248 def test_on_onu_only(self):
249 class_id = PriorityQueueG.class_id
250 inst_id = 0
251 attributes = {
252 'related_port': int(1234567) # IntField
253 }
254 self.onu_db.set(_DEVICE_ID, class_id, inst_id, attributes)
255
256 db_copy = self.olt_db.query(_DEVICE_ID)
257 db_active = self.onu_db.query(_DEVICE_ID)
258
259 olt_only, onu_only, attr_diffs = self.task.compare_mibs(db_copy, db_active)
260
261 self.assertEqual(len(olt_only), 0)
262 self.assertEqual(len(onu_only), 1)
263 self.assertEqual(len(attr_diffs), 0)
264 self.assertEqual(onu_only, [(class_id, inst_id)]) # Test contents of what was returned
265
266 # Now a little more complex (extra instance on the ONU
267 self.olt_db.set(_DEVICE_ID, class_id, inst_id, attributes)
268 self.onu_db.set(_DEVICE_ID, class_id, inst_id + 1, attributes)
269
270 db_copy = self.olt_db.query(_DEVICE_ID)
271 db_active = self.onu_db.query(_DEVICE_ID)
272
273 olt_only, onu_only, attr_diffs = self.task.compare_mibs(db_copy, db_active)
274
275 self.assertEqual(len(olt_only), 0)
276 self.assertEqual(len(onu_only), 1)
277 self.assertEqual(len(attr_diffs), 0)
278 self.assertEqual(onu_only, [(class_id, inst_id + 1)]) # Test contents of what was returned
279
280 def test_on_attr_different_value(self):
281 class_id = PriorityQueueG.class_id
282 inst_id = 0
283 attributes_olt = {
284 'weight': int(12) # ByteField
285 }
286 attributes_onu = {
287 'weight': int(34) # ByteField
288 }
289 self.onu_db.set(_DEVICE_ID, class_id, inst_id, attributes_onu)
290 self.olt_db.set(_DEVICE_ID, class_id, inst_id, attributes_olt)
291
292 db_copy = self.olt_db.query(_DEVICE_ID)
293 db_active = self.onu_db.query(_DEVICE_ID)
294
295 olt_only, onu_only, attr_diffs = self.task.compare_mibs(db_copy, db_active)
296
297 self.assertEqual(len(olt_only), 0)
298 self.assertEqual(len(onu_only), 0)
299 self.assertEqual(len(attr_diffs), 1)
300 self.assertEqual(attr_diffs, [(class_id, inst_id, 'weight')])
301
302 def test_ignore_read_only_attribute_differences(self):
303 class_id = PriorityQueueG.class_id
304 inst_id = 0
305 attributes_olt = {
306 'related_port': int(1234), # IntField (R/O)
307 'maximum_queue_size': int(222) # Only on OLT but read-only
308 }
309 attributes_onu = {
310 'related_port': int(5678) # IntField (R/O)
311 }
312 self.onu_db.set(_DEVICE_ID, class_id, inst_id, attributes_onu)
313 self.olt_db.set(_DEVICE_ID, class_id, inst_id, attributes_olt)
314
315 db_copy = self.olt_db.query(_DEVICE_ID)
316 db_active = self.onu_db.query(_DEVICE_ID)
317
318 olt_only, onu_only, attr_diffs = self.task.compare_mibs(db_copy, db_active)
319
320 self.assertEqual(len(olt_only), 0)
321 self.assertEqual(len(onu_only), 0)
322 self.assertEqual(len(attr_diffs), 0)
323
324 def test_on_attr_more_on_olt(self):
325 class_id = PriorityQueueG.class_id
326 inst_id = 0
327 attributes_olt = {
328 'related_port': int(1234), # IntField
329 'back_pressure_time': int(1234) # IntField
330 }
331 attributes_onu = {
332 'related_port': int(1234) # IntField
333 }
334 self.onu_db.set(_DEVICE_ID, class_id, inst_id, attributes_onu)
335 self.olt_db.set(_DEVICE_ID, class_id, inst_id, attributes_olt)
336
337 db_copy = self.olt_db.query(_DEVICE_ID)
338 db_active = self.onu_db.query(_DEVICE_ID)
339
340 olt_only, onu_only, attr_diffs = self.task.compare_mibs(db_copy, db_active)
341
342 self.assertEqual(len(olt_only), 0)
343 self.assertEqual(len(onu_only), 0)
344 self.assertEqual(len(attr_diffs), 1)
345 self.assertEqual(attr_diffs, [(class_id, inst_id, 'back_pressure_time')])
346
347 def test_on_attr_more_on_onu(self):
348 class_id = PriorityQueueG.class_id
349 inst_id = 0
350 attributes_olt = {
351 'related_port': int(1234) # IntField
352 }
353 attributes_onu = {
354 'related_port': int(1234), # IntField
355 'back_pressure_time': int(5678) # IntField
356 }
357 self.onu_db.set(_DEVICE_ID, class_id, inst_id, attributes_onu)
358 self.olt_db.set(_DEVICE_ID, class_id, inst_id, attributes_olt)
359
360 db_copy = self.olt_db.query(_DEVICE_ID)
361 db_active = self.onu_db.query(_DEVICE_ID)
362
363 olt_only, onu_only, attr_diffs = self.task.compare_mibs(db_copy, db_active)
364
365 self.assertEqual(len(olt_only), 0)
366 self.assertEqual(len(onu_only), 0)
367 self.assertEqual(len(attr_diffs), 1)
368 self.assertEqual(attr_diffs, [(class_id, inst_id, 'back_pressure_time')])
369
370
371if __name__ == '__main__':
372 main()