blob: 6482aed129307ff53ae9f689114da7c126a53d23 [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
Matt Jeanneret5e331892019-12-07 21:31:45 -050063 @entity_id.setter
64 def entity_id(self, value):
65 self._entity_id = value
66
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050067 @property
68 def q_sched_policy(self):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050069 return self._q_sched_policy
70
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050071 @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 Jeanneret3789d0d2020-01-19 09:03:42 -050080 def create(handler, tcont):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050081
82 return OnuTCont(handler,
83 tcont['uni_id'],
84 tcont['alloc-id'],
Matt Jeanneret3789d0d2020-01-19 09:03:42 -050085 tcont['q_sched_policy']
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050086 )
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 Gowdraa73ee452019-12-20 18:52:17 +053097 # msg = TcontFrame(self.entity_id, self.alloc_id, self.q_sched_policy)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050098 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 Jeanneretf1e9c5d2019-02-08 07:41:29 -0500112 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 Gowdraa73ee452019-12-20 18:52:17 +0530118 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 Jeanneretf1e9c5d2019-02-08 07:41:29 -0500126 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 Jeanneretf1e9c5d2019-02-08 07:41:29 -0500130 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 Jeanneretf1e9c5d2019-02-08 07:41:29 -0500137 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 Jeannerete8fc53e2019-04-13 15:58:33 -0400143 self.log.debug("OMCI Result", operation=operation, omci_msg=omci_msg,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500144 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