blob: 10fed00a4dc06704682980fd8a6956e536a9f3d3 [file] [log] [blame]
Chip Bolingfd1fd372017-12-20 13:34:12 -06001# Copyright 2017-present Adtran, Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import structlog
16import json
Chip Boling521735d2018-12-20 09:58:01 -060017from twisted.internet.defer import inlineCallbacks, returnValue
Chip Bolingfd1fd372017-12-20 13:34:12 -060018from tcont import TCont
Chip Boling521735d2018-12-20 09:58:01 -060019from voltha.adapters.openolt.protos import openolt_pb2
20from olt_traffic_descriptor import OltTrafficDescriptor
21from ..adtran_olt_handler import AdtranOltHandler
Chip Bolingfd1fd372017-12-20 13:34:12 -060022
23log = structlog.get_logger()
24
25
26class OltTCont(TCont):
27 """
28 Adtran OLT specific implementation
29 """
Chip Bolingcadafd92018-12-20 14:42:22 -060030 def __init__(self, alloc_id, tech_profile_id, traffic_descriptor, pon_id, onu_id, uni_id, is_mock=False):
31 super(OltTCont, self).__init__(alloc_id, tech_profile_id, traffic_descriptor, uni_id, is_mock=is_mock)
Chip Bolingb4868192018-11-01 16:38:44 -050032 self.pon_id = pon_id
33 self.onu_id = onu_id
Chip Boling521735d2018-12-20 09:58:01 -060034
35 def __str__(self):
Chip Bolingcadafd92018-12-20 14:42:22 -060036 return "TCont: {}/{}/{}, alloc-id: {}".format(self.pon_id, self.onu_id,
37 self.uni_id, self.alloc_id)
Chip Bolingfd1fd372017-12-20 13:34:12 -060038
39 @staticmethod
Chip Boling521735d2018-12-20 09:58:01 -060040 def create(tcont, pon_id, onu_id, tech_profile_id, uni_id, ofp_port_no):
41 # Only valid information in the upstream tcont of a tech profile
42 if tcont.direction != openolt_pb2.UPSTREAM:
43 return None
Chip Bolingfd1fd372017-12-20 13:34:12 -060044
Chip Boling521735d2018-12-20 09:58:01 -060045 td = OltTrafficDescriptor.create(tcont, pon_id, onu_id, uni_id, ofp_port_no)
Chip Bolingcadafd92018-12-20 14:42:22 -060046 return OltTCont(tcont.alloc_id, tech_profile_id, td, pon_id, onu_id, uni_id)
Chip Bolingfd1fd372017-12-20 13:34:12 -060047
48 @inlineCallbacks
Chip Bolingb4868192018-11-01 16:38:44 -050049 def add_to_hardware(self, session):
Chip Bolingfd1fd372017-12-20 13:34:12 -060050 if self._is_mock:
51 returnValue('mock')
52
Chip Bolingb4868192018-11-01 16:38:44 -050053 uri = AdtranOltHandler.GPON_TCONT_CONFIG_LIST_URI.format(self.pon_id, self.onu_id)
Chip Bolingfd1fd372017-12-20 13:34:12 -060054 data = json.dumps({'alloc-id': self.alloc_id})
Chip Bolingb4868192018-11-01 16:38:44 -050055 name = 'tcont-create-{}-{}: {}'.format(self.pon_id, self.onu_id, self.alloc_id)
Chip Bolingfd1fd372017-12-20 13:34:12 -060056
57 # For TCONT, only leaf is the key. So only post needed
58 try:
59 results = yield session.request('POST', uri, data=data, name=name,
Chip Bolingbb15b512018-06-01 11:39:58 -050060 suppress_error=False)
Chip Boling88354fb2018-09-21 12:17:19 -050061 except Exception as _e:
Chip Bolingfd1fd372017-12-20 13:34:12 -060062 results = None
63
64 if self.traffic_descriptor is not None:
65 try:
Chip Boling521735d2018-12-20 09:58:01 -060066 results = yield self.traffic_descriptor.add_to_hardware(session)
67
Chip Bolingfd1fd372017-12-20 13:34:12 -060068 except Exception as e:
69 log.exception('traffic-descriptor', tcont=self,
70 td=self.traffic_descriptor, e=e)
71 raise
72
73 returnValue(results)
74
Chip Bolingb4868192018-11-01 16:38:44 -050075 def remove_from_hardware(self, session):
Chip Boling521735d2018-12-20 09:58:01 -060076 if self._is_mock:
77 returnValue('mock')
Chip Bolingfd1fd372017-12-20 13:34:12 -060078
Chip Boling521735d2018-12-20 09:58:01 -060079 uri = AdtranOltHandler.GPON_TCONT_CONFIG_URI.format(self.pon_id, self.onu_id, self.alloc_id)
Chip Bolingb4868192018-11-01 16:38:44 -050080 name = 'tcont-delete-{}-{}: {}'.format(self.pon_id, self.onu_id, self.alloc_id)
Chip Bolingfd1fd372017-12-20 13:34:12 -060081 return session.request('DELETE', uri, name=name)
82
83
84
85
86
87
88
89
90