Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 1 | # 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 | |
| 15 | import structlog |
| 16 | import json |
Chip Boling | 521735d | 2018-12-20 09:58:01 -0600 | [diff] [blame] | 17 | from twisted.internet.defer import inlineCallbacks, returnValue |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 18 | from tcont import TCont |
Chip Boling | 521735d | 2018-12-20 09:58:01 -0600 | [diff] [blame] | 19 | from voltha.adapters.openolt.protos import openolt_pb2 |
| 20 | from olt_traffic_descriptor import OltTrafficDescriptor |
| 21 | from ..adtran_olt_handler import AdtranOltHandler |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 22 | |
| 23 | log = structlog.get_logger() |
| 24 | |
| 25 | |
| 26 | class OltTCont(TCont): |
| 27 | """ |
| 28 | Adtran OLT specific implementation |
| 29 | """ |
Chip Boling | cadafd9 | 2018-12-20 14:42:22 -0600 | [diff] [blame^] | 30 | 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 Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame] | 32 | self.pon_id = pon_id |
| 33 | self.onu_id = onu_id |
Chip Boling | 521735d | 2018-12-20 09:58:01 -0600 | [diff] [blame] | 34 | |
| 35 | def __str__(self): |
Chip Boling | cadafd9 | 2018-12-20 14:42:22 -0600 | [diff] [blame^] | 36 | return "TCont: {}/{}/{}, alloc-id: {}".format(self.pon_id, self.onu_id, |
| 37 | self.uni_id, self.alloc_id) |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 38 | |
| 39 | @staticmethod |
Chip Boling | 521735d | 2018-12-20 09:58:01 -0600 | [diff] [blame] | 40 | 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 Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 44 | |
Chip Boling | 521735d | 2018-12-20 09:58:01 -0600 | [diff] [blame] | 45 | td = OltTrafficDescriptor.create(tcont, pon_id, onu_id, uni_id, ofp_port_no) |
Chip Boling | cadafd9 | 2018-12-20 14:42:22 -0600 | [diff] [blame^] | 46 | return OltTCont(tcont.alloc_id, tech_profile_id, td, pon_id, onu_id, uni_id) |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 47 | |
| 48 | @inlineCallbacks |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame] | 49 | def add_to_hardware(self, session): |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 50 | if self._is_mock: |
| 51 | returnValue('mock') |
| 52 | |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame] | 53 | uri = AdtranOltHandler.GPON_TCONT_CONFIG_LIST_URI.format(self.pon_id, self.onu_id) |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 54 | data = json.dumps({'alloc-id': self.alloc_id}) |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame] | 55 | name = 'tcont-create-{}-{}: {}'.format(self.pon_id, self.onu_id, self.alloc_id) |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 56 | |
| 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 Boling | bb15b51 | 2018-06-01 11:39:58 -0500 | [diff] [blame] | 60 | suppress_error=False) |
Chip Boling | 88354fb | 2018-09-21 12:17:19 -0500 | [diff] [blame] | 61 | except Exception as _e: |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 62 | results = None |
| 63 | |
| 64 | if self.traffic_descriptor is not None: |
| 65 | try: |
Chip Boling | 521735d | 2018-12-20 09:58:01 -0600 | [diff] [blame] | 66 | results = yield self.traffic_descriptor.add_to_hardware(session) |
| 67 | |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 68 | 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 Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame] | 75 | def remove_from_hardware(self, session): |
Chip Boling | 521735d | 2018-12-20 09:58:01 -0600 | [diff] [blame] | 76 | if self._is_mock: |
| 77 | returnValue('mock') |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 78 | |
Chip Boling | 521735d | 2018-12-20 09:58:01 -0600 | [diff] [blame] | 79 | uri = AdtranOltHandler.GPON_TCONT_CONFIG_URI.format(self.pon_id, self.onu_id, self.alloc_id) |
Chip Boling | b486819 | 2018-11-01 16:38:44 -0500 | [diff] [blame] | 80 | name = 'tcont-delete-{}-{}: {}'.format(self.pon_id, self.onu_id, self.alloc_id) |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 81 | return session.request('DELETE', uri, name=name) |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |