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