blob: da639d35a689a0658b8f7ddd8a6ce1e94f4a8669 [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 Jeanneretf1e9c5d2019-02-08 07:41:29 -050040 def __init__(self, handler, uni_id, alloc_id, q_sched_policy, traffic_descriptor):
41
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
48 self.traffic_descriptor = traffic_descriptor
49
50 self._handler = handler
51 self._entity_id = None
52
53 def __str__(self):
54 return "OnuTCont - uni_id: {}, entity_id {}, alloc-id: {}, q_sched_policy: {}, traffic_descriptor: {}".format(
55 self.uni_id, self._entity_id, self.alloc_id, self.q_sched_policy, self.traffic_descriptor)
56
57 def __repr__(self):
58 return str(self)
59
60 @property
61 def entity_id(self):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050062 return self._entity_id
63
64 @property
65 def q_sched_policy(self):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050066 return self._q_sched_policy
67
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050068 @q_sched_policy.setter
69 def q_sched_policy(self, q_sched_policy):
70 sp = ('Null', 'WRR', 'StrictPriority')
71 if q_sched_policy in sp:
72 self._q_sched_policy = sp.index(q_sched_policy)
73 else:
74 self._q_sched_policy = 0
75
76 @staticmethod
77 def create(handler, tcont, td):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050078
79 return OnuTCont(handler,
80 tcont['uni_id'],
81 tcont['alloc-id'],
82 tcont['q_sched_policy'],
83 td
84 )
85
86 @inlineCallbacks
87 def add_to_hardware(self, omci, tcont_entity_id):
88 self.log.debug('add-to-hardware', tcont_entity_id=tcont_entity_id)
89
90 self._entity_id = tcont_entity_id
91
92 try:
93 # FIXME: self.q_sched_policy seems to be READ-ONLY
94 # Ideally the READ-ONLY or NOT attribute is available from ONU-2G ME
Girish Gowdraa73ee452019-12-20 18:52:17 +053095 # msg = TcontFrame(self.entity_id, self.alloc_id, self.q_sched_policy)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050096 msg = TcontFrame(self.entity_id, self.alloc_id)
97 frame = msg.set()
98 self.log.debug('openomci-msg', omci_msg=msg)
99 results = yield omci.send(frame)
100 self.check_status_and_state(results, 'set-tcont')
101
102 except Exception as e:
103 self.log.exception('tcont-set', e=e)
104 raise
105
106 returnValue(results)
107
108 @inlineCallbacks
109 def remove_from_hardware(self, omci):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500110 self.log.debug('remove-from-hardware', tcont_entity_id=self.entity_id)
111
112 # Release tcont by setting alloc_id=0xFFFF
113 # TODO: magic number, create a named variable
114
115 try:
Girish Gowdraa73ee452019-12-20 18:52:17 +0530116 initial_alloc_id_value = 0xFF
117
118 onu_device = self._handler.onu_omci_device
119 omcc_version = onu_device.configuration.omcc_version
120 if omcc_version in OnuTCont.G988_OMCC_VERSIONS:
121 initial_alloc_id_value = 0xFFFF
122
123 msg = TcontFrame(self.entity_id, initial_alloc_id_value)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500124 frame = msg.set()
125 self.log.debug('openomci-msg', omci_msg=msg)
126 results = yield omci.send(frame)
127 self.check_status_and_state(results, 'delete-tcont')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500128 except Exception as e:
129 self.log.exception('tcont-delete', e=e)
130 raise
131
132 returnValue(results)
133
134 def check_status_and_state(self, results, operation=''):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500135 omci_msg = results.fields['omci_message'].fields
136 status = omci_msg['success_code']
137 error_mask = omci_msg.get('parameter_error_attributes_mask', 'n/a')
138 failed_mask = omci_msg.get('failed_attributes_mask', 'n/a')
139 unsupported_mask = omci_msg.get('unsupported_attributes_mask', 'n/a')
140
Matt Jeannerete8fc53e2019-04-13 15:58:33 -0400141 self.log.debug("OMCI Result", operation=operation, omci_msg=omci_msg,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500142 status=status, error_mask=error_mask,
143 failed_mask=failed_mask, unsupported_mask=unsupported_mask)
144
145 if status == RC.Success:
146 return True
147
148 elif status == RC.InstanceExists:
149 return False