Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1 | # |
| 2 | # Copyright 2018 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 | |
Matt Jeanneret | 2e3cb8d | 2019-11-16 09:22:41 -0500 | [diff] [blame] | 16 | from __future__ import absolute_import |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 17 | import structlog |
Matt Jeanneret | 2e3cb8d | 2019-11-16 09:22:41 -0500 | [diff] [blame] | 18 | from twisted.internet.defer import inlineCallbacks, returnValue |
| 19 | from pyvoltha.adapters.extensions.omci.omci_me import TcontFrame |
| 20 | from pyvoltha.adapters.extensions.omci.omci_defs import ReasonCodes |
Girish Gowdra | a73ee45 | 2019-12-20 18:52:17 +0530 | [diff] [blame] | 21 | from pyvoltha.adapters.extensions.omci.onu_configuration import OMCCVersion |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 22 | |
| 23 | RC = ReasonCodes |
| 24 | |
| 25 | |
| 26 | class OnuTCont(object): |
Girish Gowdra | a73ee45 | 2019-12-20 18:52:17 +0530 | [diff] [blame] | 27 | G988_OMCC_VERSIONS = [OMCCVersion.G_988_2010_Base, |
| 28 | OMCCVersion.G_988_2011_Amd_1_Base, |
| 29 | OMCCVersion.G_988_2012_Amd_2_Base, |
| 30 | OMCCVersion.G_988_2012_Base, |
| 31 | OMCCVersion.G_988_2010, |
| 32 | OMCCVersion.G_988_2011_Amd_1, |
| 33 | OMCCVersion.G_988_2012_Amd_2, |
| 34 | OMCCVersion.G_988_2012, |
| 35 | OMCCVersion.G_988_2014_Amd_1] |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 36 | """ |
| 37 | Broadcom ONU specific implementation |
| 38 | """ |
Girish Gowdra | a73ee45 | 2019-12-20 18:52:17 +0530 | [diff] [blame] | 39 | |
Matt Jeanneret | 3789d0d | 2020-01-19 09:03:42 -0500 | [diff] [blame] | 40 | def __init__(self, handler, uni_id, alloc_id, q_sched_policy): |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 41 | |
| 42 | self.log = structlog.get_logger(device_id=handler.device_id, uni_id=uni_id, alloc_id=alloc_id) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 43 | |
| 44 | self.uni_id = uni_id |
| 45 | self.alloc_id = alloc_id |
| 46 | self._q_sched_policy = 0 |
| 47 | self.q_sched_policy = q_sched_policy |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 48 | |
| 49 | self._handler = handler |
| 50 | self._entity_id = None |
| 51 | |
| 52 | def __str__(self): |
Matt Jeanneret | 3789d0d | 2020-01-19 09:03:42 -0500 | [diff] [blame] | 53 | return "OnuTCont - uni_id: {}, entity_id: {}, alloc-id: {}, q_sched_policy: {}".format( |
| 54 | self.uni_id, self._entity_id, self.alloc_id, self.q_sched_policy) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 55 | |
| 56 | def __repr__(self): |
| 57 | return str(self) |
| 58 | |
| 59 | @property |
| 60 | def entity_id(self): |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 61 | return self._entity_id |
| 62 | |
Matt Jeanneret | 5e33189 | 2019-12-07 21:31:45 -0500 | [diff] [blame] | 63 | @entity_id.setter |
| 64 | def entity_id(self, value): |
| 65 | self._entity_id = value |
| 66 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 67 | @property |
| 68 | def q_sched_policy(self): |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 69 | return self._q_sched_policy |
| 70 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 71 | @q_sched_policy.setter |
| 72 | def q_sched_policy(self, q_sched_policy): |
| 73 | sp = ('Null', 'WRR', 'StrictPriority') |
| 74 | if q_sched_policy in sp: |
| 75 | self._q_sched_policy = sp.index(q_sched_policy) |
| 76 | else: |
| 77 | self._q_sched_policy = 0 |
| 78 | |
| 79 | @staticmethod |
Matt Jeanneret | 3789d0d | 2020-01-19 09:03:42 -0500 | [diff] [blame] | 80 | def create(handler, tcont): |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 81 | |
| 82 | return OnuTCont(handler, |
| 83 | tcont['uni_id'], |
| 84 | tcont['alloc-id'], |
Matt Jeanneret | 3789d0d | 2020-01-19 09:03:42 -0500 | [diff] [blame] | 85 | tcont['q_sched_policy'] |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 86 | ) |
| 87 | |
| 88 | @inlineCallbacks |
| 89 | def add_to_hardware(self, omci, tcont_entity_id): |
| 90 | self.log.debug('add-to-hardware', tcont_entity_id=tcont_entity_id) |
| 91 | |
| 92 | self._entity_id = tcont_entity_id |
| 93 | |
| 94 | try: |
| 95 | # FIXME: self.q_sched_policy seems to be READ-ONLY |
| 96 | # Ideally the READ-ONLY or NOT attribute is available from ONU-2G ME |
Girish Gowdra | a73ee45 | 2019-12-20 18:52:17 +0530 | [diff] [blame] | 97 | # msg = TcontFrame(self.entity_id, self.alloc_id, self.q_sched_policy) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 98 | msg = TcontFrame(self.entity_id, self.alloc_id) |
| 99 | frame = msg.set() |
| 100 | self.log.debug('openomci-msg', omci_msg=msg) |
| 101 | results = yield omci.send(frame) |
| 102 | self.check_status_and_state(results, 'set-tcont') |
| 103 | |
| 104 | except Exception as e: |
| 105 | self.log.exception('tcont-set', e=e) |
| 106 | raise |
| 107 | |
| 108 | returnValue(results) |
| 109 | |
| 110 | @inlineCallbacks |
| 111 | def remove_from_hardware(self, omci): |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 112 | self.log.debug('remove-from-hardware', tcont_entity_id=self.entity_id) |
| 113 | |
| 114 | # Release tcont by setting alloc_id=0xFFFF |
| 115 | # TODO: magic number, create a named variable |
| 116 | |
| 117 | try: |
Girish Gowdra | a73ee45 | 2019-12-20 18:52:17 +0530 | [diff] [blame] | 118 | initial_alloc_id_value = 0xFF |
| 119 | |
| 120 | onu_device = self._handler.onu_omci_device |
| 121 | omcc_version = onu_device.configuration.omcc_version |
| 122 | if omcc_version in OnuTCont.G988_OMCC_VERSIONS: |
| 123 | initial_alloc_id_value = 0xFFFF |
| 124 | |
| 125 | msg = TcontFrame(self.entity_id, initial_alloc_id_value) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 126 | frame = msg.set() |
| 127 | self.log.debug('openomci-msg', omci_msg=msg) |
| 128 | results = yield omci.send(frame) |
| 129 | self.check_status_and_state(results, 'delete-tcont') |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 130 | except Exception as e: |
| 131 | self.log.exception('tcont-delete', e=e) |
| 132 | raise |
| 133 | |
| 134 | returnValue(results) |
| 135 | |
| 136 | def check_status_and_state(self, results, operation=''): |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 137 | omci_msg = results.fields['omci_message'].fields |
| 138 | status = omci_msg['success_code'] |
| 139 | error_mask = omci_msg.get('parameter_error_attributes_mask', 'n/a') |
| 140 | failed_mask = omci_msg.get('failed_attributes_mask', 'n/a') |
| 141 | unsupported_mask = omci_msg.get('unsupported_attributes_mask', 'n/a') |
| 142 | |
Matt Jeanneret | e8fc53e | 2019-04-13 15:58:33 -0400 | [diff] [blame] | 143 | self.log.debug("OMCI Result", operation=operation, omci_msg=omci_msg, |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 144 | status=status, error_mask=error_mask, |
| 145 | failed_mask=failed_mask, unsupported_mask=unsupported_mask) |
| 146 | |
| 147 | if status == RC.Success: |
| 148 | return True |
| 149 | |
| 150 | elif status == RC.InstanceExists: |
| 151 | return False |