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 | |
| 18 | log = structlog.get_logger() |
| 19 | |
| 20 | |
| 21 | class BestEffort(object): |
| 22 | def __init__(self, bandwidth, priority, weight): |
| 23 | self.bandwidth = bandwidth # bps |
| 24 | self.priority = priority # 0.255 |
| 25 | self.weight = weight # 0..100 |
| 26 | |
| 27 | def __str__(self): |
| 28 | return "BestEffort: {}/p-{}/w-{}".format(self.bandwidth, |
| 29 | self.priority, |
| 30 | self.weight) |
| 31 | |
| 32 | def to_dict(self): |
| 33 | val = { |
| 34 | 'bandwidth': self.bandwidth, |
| 35 | 'priority': self.priority, |
| 36 | 'weight': self.weight |
| 37 | } |
| 38 | return val |
| 39 | |
| 40 | def add_to_hardware(self, session, pon_id, onu_id, alloc_id, best_effort): |
| 41 | from ..adtran_olt_handler import AdtranOltHandler |
| 42 | |
| 43 | uri = AdtranOltHandler.GPON_TCONT_CONFIG_URI.format(pon_id, onu_id, alloc_id) |
| 44 | data = json.dumps({'best-effort': best_effort.to_dict()}) |
| 45 | name = 'tcont-best-effort-{}-{}: {}'.format(pon_id, onu_id, alloc_id) |
| 46 | |
| 47 | return session.request('PATCH', uri, data=data, name=name) |