Chip Boling | f5af85d | 2019-02-12 15:36:17 -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 |
| 17 | from adapters.adtran_common.xpon.traffic_descriptor import TrafficDescriptor |
| 18 | from twisted.internet.defer import inlineCallbacks, returnValue |
| 19 | from ..adtran_olt_handler import AdtranOltHandler |
| 20 | |
| 21 | log = structlog.get_logger() |
| 22 | |
| 23 | |
| 24 | class OltTrafficDescriptor(TrafficDescriptor): |
| 25 | """ |
| 26 | Adtran ONU specific implementation |
| 27 | """ |
| 28 | def __init__(self, pon_id, onu_id, alloc_id, fixed, assured, maximum, |
| 29 | additional=TrafficDescriptor.AdditionalBwEligibility.DEFAULT, |
| 30 | best_effort=None, |
| 31 | is_mock=False): |
| 32 | super(OltTrafficDescriptor, self).__init__(fixed, assured, maximum, |
| 33 | additional=additional, |
| 34 | best_effort=best_effort) |
| 35 | self.pon_id = pon_id |
| 36 | self.onu_id = onu_id |
| 37 | self.alloc_id = alloc_id |
| 38 | self._is_mock = is_mock |
| 39 | |
| 40 | @staticmethod |
| 41 | def create(tcont, pon_id, onu_id, _uni_id, _ofp_port_no): |
| 42 | alloc_id = tcont.alloc_id |
| 43 | shaping_info = tcont.traffic_shaping_info |
| 44 | fixed = shaping_info.cir |
| 45 | assured = 0 |
| 46 | maximum = shaping_info.pir |
| 47 | |
| 48 | best_effort = None |
| 49 | # if shaping_info.add_bw_ind == openolt_pb2.InferredAdditionBWIndication_Assured: |
| 50 | # pass |
| 51 | # TODO: Support additional BW decode |
| 52 | # elif shaping_info.add_bw_ind == openolt_pb2.InferredAdditionBWIndication_BestEffort: |
| 53 | # pass |
| 54 | # additional = TrafficDescriptor.AdditionalBwEligibility.from_value( |
| 55 | # traffic_disc['additional-bw-eligibility-indicator']) |
| 56 | # |
| 57 | # if additional == TrafficDescriptor.AdditionalBwEligibility.BEST_EFFORT_SHARING: |
| 58 | # best_effort = BestEffort(traffic_disc['maximum-bandwidth'], |
| 59 | # traffic_disc['priority'], |
| 60 | # traffic_disc['weight']) |
| 61 | # else: |
| 62 | # best_effort = None |
| 63 | |
| 64 | return OltTrafficDescriptor(pon_id, onu_id, alloc_id, |
| 65 | fixed, assured, maximum, best_effort=best_effort) |
| 66 | |
| 67 | @inlineCallbacks |
| 68 | def add_to_hardware(self, session): |
| 69 | # TODO: Traffic descriptors are no longer shared, save pon and onu ID to base class |
| 70 | if self._is_mock: |
| 71 | returnValue('mock') |
| 72 | |
| 73 | uri = AdtranOltHandler.GPON_TCONT_CONFIG_URI.format(self.pon_id, |
| 74 | self.onu_id, |
| 75 | self.alloc_id) |
| 76 | data = json.dumps({'traffic-descriptor': self.to_dict()}) |
| 77 | name = 'tcont-td-{}-{}: {}'.format(self.pon_id, self.onu_id, self.alloc_id) |
| 78 | try: |
| 79 | results = yield session.request('PATCH', uri, data=data, name=name) |
| 80 | |
| 81 | except Exception as e: |
| 82 | log.exception('traffic-descriptor', td=self, e=e) |
| 83 | raise |
| 84 | |
| 85 | # TODO: Add support for best-effort sharing |
| 86 | # if self.additional_bandwidth_eligibility == \ |
| 87 | # TrafficDescriptor.AdditionalBwEligibility.BEST_EFFORT_SHARING: |
| 88 | # if self.best_effort is None: |
| 89 | # raise ValueError('TCONT is best-effort but does not define best effort sharing') |
| 90 | # |
| 91 | # try: |
| 92 | # results = yield self.best_effort.add_to_hardware(session) |
| 93 | # |
| 94 | # except Exception as e: |
| 95 | # log.exception('best-effort', best_effort=self.best_effort, e=e) |
| 96 | # raise |
| 97 | |
| 98 | returnValue(results) |