blob: cbb814a68f6b4b48e8e10c4bfb2e60f6eff1813e [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#
16
Zack Williams84a71e92019-11-15 09:00:19 -070017from __future__ import absolute_import
18from .mock_adapter_agent import MockProxyAddress, MockDevice
Chip Boling67b674a2019-02-08 11:42:18 -060019from pyvoltha.adapters.extensions.omci.omci_cc import *
20from pyvoltha.adapters.extensions.omci.omci_entities import entity_id_to_class_map
21
22
23class MockOnuHandler(MockDevice):
24 """
25 Minimal class to handle ONU needs in OpenOMCI testing
26
27 So that we do not have to duplicate the IAdapter functionality, just
28 the handler, the OLT and ONU handlers are derived from a mock Device
29 base class so that we can access the _devices map and get either a
30 Device to play with (like the real thing) or the associated handler
31 """
32 def __init__(self, adapter_agent, parent_id, device_id, pon_id, onu_id):
33
34 self.proxy_address = MockProxyAddress(parent_id, pon_id, onu_id)
35 super(MockOnuHandler, self).__init__(device_id, self.proxy_address)
36
37 self.device_id = device_id
38 self.device = self
39 self._adapter_agent = adapter_agent
40
41 self.onu_mock = None
42 self.omci_cc = OMCI_CC(adapter_agent, device_id, me_map=entity_id_to_class_map)
43
44 # Items that you can change to perform various test failures
45
46 self._enabled = True
47
48 def tearDown(self):
49 """Test case cleanup"""
50 if self.onu_mock is not None:
51 self.onu_mock.tearDown()
52 self.onu_mock = None
53
54 @property
55 def enabled(self):
56 return self._enabled
57
58 @enabled.setter
59 def enabled(self, value):
60 if self._enabled != value:
61 self._enabled = value
62 olt = self._adapter_agent.get_device(self.proxy_address.device_id)
63 if olt is not None and self.proxy_address.channel_id in olt.enabled_pons:
64 if self._enabled:
65 olt.activated_onus.add(self.serial_number)
66 else:
67 olt.activated_onus.discard(self.serial_number)
68
69 # Begin minimal set of needed IAdapter interfaces
70
71 # TODO: Implement minimal functionality
72
73 def send_proxied_message(self, proxy_address, msg):
74 assert False, 'OpenOMCI will implement this for the MOCK ONU'
75
76 def receive_proxied_message(self, _, msg):
77 # Rx of OMCI message from MOCK OLT
78
79 if self.omci_cc is not None and self.enabled:
80 self.omci_cc.receive_message(msg.decode('hex'))