blob: bc1f2306645c90857a73390114cd41e25315d639 [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)
43 self.log.debug('function-entry')
44
45 self.uni_id = uni_id
46 self.alloc_id = alloc_id
47 self._q_sched_policy = 0
48 self.q_sched_policy = q_sched_policy
49 self.traffic_descriptor = traffic_descriptor
50
51 self._handler = handler
52 self._entity_id = None
53
54 def __str__(self):
55 return "OnuTCont - uni_id: {}, entity_id {}, alloc-id: {}, q_sched_policy: {}, traffic_descriptor: {}".format(
56 self.uni_id, self._entity_id, self.alloc_id, self.q_sched_policy, self.traffic_descriptor)
57
58 def __repr__(self):
59 return str(self)
60
61 @property
62 def entity_id(self):
63 self.log.debug('function-entry')
64 return self._entity_id
65
66 @property
67 def q_sched_policy(self):
68 self.log.debug('function-entry')
69 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
80 def create(handler, tcont, td):
81 log = structlog.get_logger(tcont=tcont, td=td)
82 log.debug('function-entry', tcont=tcont)
83
84 return OnuTCont(handler,
85 tcont['uni_id'],
86 tcont['alloc-id'],
87 tcont['q_sched_policy'],
88 td
89 )
90
91 @inlineCallbacks
92 def add_to_hardware(self, omci, tcont_entity_id):
93 self.log.debug('add-to-hardware', tcont_entity_id=tcont_entity_id)
94
95 self._entity_id = tcont_entity_id
96
97 try:
98 # FIXME: self.q_sched_policy seems to be READ-ONLY
99 # Ideally the READ-ONLY or NOT attribute is available from ONU-2G ME
Girish Gowdraa73ee452019-12-20 18:52:17 +0530100 # msg = TcontFrame(self.entity_id, self.alloc_id, self.q_sched_policy)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500101 msg = TcontFrame(self.entity_id, self.alloc_id)
102 frame = msg.set()
103 self.log.debug('openomci-msg', omci_msg=msg)
104 results = yield omci.send(frame)
105 self.check_status_and_state(results, 'set-tcont')
106
107 except Exception as e:
108 self.log.exception('tcont-set', e=e)
109 raise
110
111 returnValue(results)
112
113 @inlineCallbacks
114 def remove_from_hardware(self, omci):
115 self.log.debug('function-entry', omci=omci)
116 self.log.debug('remove-from-hardware', tcont_entity_id=self.entity_id)
117
118 # Release tcont by setting alloc_id=0xFFFF
119 # TODO: magic number, create a named variable
120
121 try:
Girish Gowdraa73ee452019-12-20 18:52:17 +0530122 initial_alloc_id_value = 0xFF
123
124 onu_device = self._handler.onu_omci_device
125 omcc_version = onu_device.configuration.omcc_version
126 if omcc_version in OnuTCont.G988_OMCC_VERSIONS:
127 initial_alloc_id_value = 0xFFFF
128
129 msg = TcontFrame(self.entity_id, initial_alloc_id_value)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500130 frame = msg.set()
131 self.log.debug('openomci-msg', omci_msg=msg)
132 results = yield omci.send(frame)
133 self.check_status_and_state(results, 'delete-tcont')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500134 except Exception as e:
135 self.log.exception('tcont-delete', e=e)
136 raise
137
138 returnValue(results)
139
140 def check_status_and_state(self, results, operation=''):
141 self.log.debug('function-entry')
142 omci_msg = results.fields['omci_message'].fields
143 status = omci_msg['success_code']
144 error_mask = omci_msg.get('parameter_error_attributes_mask', 'n/a')
145 failed_mask = omci_msg.get('failed_attributes_mask', 'n/a')
146 unsupported_mask = omci_msg.get('unsupported_attributes_mask', 'n/a')
147
Matt Jeannerete8fc53e2019-04-13 15:58:33 -0400148 self.log.debug("OMCI Result", operation=operation, omci_msg=omci_msg,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500149 status=status, error_mask=error_mask,
150 failed_mask=failed_mask, unsupported_mask=unsupported_mask)
151
152 if status == RC.Success:
153 return True
154
155 elif status == RC.InstanceExists:
156 return False