blob: 74727284c7bcfe98c044a392bd4c66ab21c0b8da [file] [log] [blame]
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001#
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 Jeanneret2e3cb8d2019-11-16 09:22:41 -050016from __future__ import absolute_import
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050017import structlog
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050018from twisted.internet.defer import inlineCallbacks, returnValue
19from pyvoltha.adapters.extensions.omci.omci_me import TcontFrame
20from pyvoltha.adapters.extensions.omci.omci_defs import ReasonCodes
Girish Gowdraa73ee452019-12-20 18:52:17 +053021from pyvoltha.adapters.extensions.omci.onu_configuration import OMCCVersion
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050022
23RC = ReasonCodes
24
25
26class OnuTCont(object):
Girish Gowdraa73ee452019-12-20 18:52:17 +053027 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 Jeanneretf1e9c5d2019-02-08 07:41:29 -050036 """
37 Broadcom ONU specific implementation
38 """
Girish Gowdraa73ee452019-12-20 18:52:17 +053039
Matt Jeanneret3789d0d2020-01-19 09:03:42 -050040 def __init__(self, handler, uni_id, alloc_id, q_sched_policy):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050041
42 self.log = structlog.get_logger(device_id=handler.device_id, uni_id=uni_id, alloc_id=alloc_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050043
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 Jeanneretf1e9c5d2019-02-08 07:41:29 -050048
49 self._handler = handler
50 self._entity_id = None
51
52 def __str__(self):
Matt Jeanneret3789d0d2020-01-19 09:03:42 -050053 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 Jeanneretf1e9c5d2019-02-08 07:41:29 -050055
56 def __repr__(self):
57 return str(self)
58
59 @property
60 def entity_id(self):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050061 return self._entity_id
62
63 @property
64 def q_sched_policy(self):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050065 return self._q_sched_policy
66
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050067 @q_sched_policy.setter
68 def q_sched_policy(self, q_sched_policy):
69 sp = ('Null', 'WRR', 'StrictPriority')
70 if q_sched_policy in sp:
71 self._q_sched_policy = sp.index(q_sched_policy)
72 else:
73 self._q_sched_policy = 0
74
75 @staticmethod
Matt Jeanneret3789d0d2020-01-19 09:03:42 -050076 def create(handler, tcont):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050077
78 return OnuTCont(handler,
79 tcont['uni_id'],
80 tcont['alloc-id'],
Matt Jeanneret3789d0d2020-01-19 09:03:42 -050081 tcont['q_sched_policy']
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050082 )
83
84 @inlineCallbacks
85 def add_to_hardware(self, omci, tcont_entity_id):
86 self.log.debug('add-to-hardware', tcont_entity_id=tcont_entity_id)
87
88 self._entity_id = tcont_entity_id
89
90 try:
91 # FIXME: self.q_sched_policy seems to be READ-ONLY
92 # Ideally the READ-ONLY or NOT attribute is available from ONU-2G ME
Girish Gowdraa73ee452019-12-20 18:52:17 +053093 # msg = TcontFrame(self.entity_id, self.alloc_id, self.q_sched_policy)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050094 msg = TcontFrame(self.entity_id, self.alloc_id)
95 frame = msg.set()
96 self.log.debug('openomci-msg', omci_msg=msg)
97 results = yield omci.send(frame)
98 self.check_status_and_state(results, 'set-tcont')
99
100 except Exception as e:
101 self.log.exception('tcont-set', e=e)
102 raise
103
104 returnValue(results)
105
106 @inlineCallbacks
107 def remove_from_hardware(self, omci):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500108 self.log.debug('remove-from-hardware', tcont_entity_id=self.entity_id)
109
110 # Release tcont by setting alloc_id=0xFFFF
111 # TODO: magic number, create a named variable
112
113 try:
Girish Gowdraa73ee452019-12-20 18:52:17 +0530114 initial_alloc_id_value = 0xFF
115
116 onu_device = self._handler.onu_omci_device
117 omcc_version = onu_device.configuration.omcc_version
118 if omcc_version in OnuTCont.G988_OMCC_VERSIONS:
119 initial_alloc_id_value = 0xFFFF
120
121 msg = TcontFrame(self.entity_id, initial_alloc_id_value)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500122 frame = msg.set()
123 self.log.debug('openomci-msg', omci_msg=msg)
124 results = yield omci.send(frame)
125 self.check_status_and_state(results, 'delete-tcont')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500126 except Exception as e:
127 self.log.exception('tcont-delete', e=e)
128 raise
129
130 returnValue(results)
131
132 def check_status_and_state(self, results, operation=''):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500133 omci_msg = results.fields['omci_message'].fields
134 status = omci_msg['success_code']
135 error_mask = omci_msg.get('parameter_error_attributes_mask', 'n/a')
136 failed_mask = omci_msg.get('failed_attributes_mask', 'n/a')
137 unsupported_mask = omci_msg.get('unsupported_attributes_mask', 'n/a')
138
Matt Jeannerete8fc53e2019-04-13 15:58:33 -0400139 self.log.debug("OMCI Result", operation=operation, omci_msg=omci_msg,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500140 status=status, error_mask=error_mask,
141 failed_mask=failed_mask, unsupported_mask=unsupported_mask)
142
143 if status == RC.Success:
144 return True
145
146 elif status == RC.InstanceExists:
147 return False