Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 1 | # |
| 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 Jeanneret | 2e3cb8d | 2019-11-16 09:22:41 -0500 | [diff] [blame] | 16 | from __future__ import absolute_import |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 17 | import structlog |
| 18 | from twisted.internet.defer import inlineCallbacks, returnValue, succeed |
| 19 | |
| 20 | |
| 21 | NONE = 0 |
| 22 | BEST_EFFORT_SHARING = 1 |
| 23 | NON_ASSURED_SHARING = 2 # Should match xpon.py values |
| 24 | DEFAULT = NONE |
| 25 | |
| 26 | |
| 27 | class OnuTrafficDescriptor(object): |
| 28 | """ |
| 29 | Broadcom ONU specific implementation |
| 30 | """ |
| 31 | def __init__(self, fixed, assured, maximum, |
| 32 | additional=DEFAULT, |
| 33 | best_effort=None, |
| 34 | name=None): |
| 35 | |
| 36 | self.log = structlog.get_logger(fixed=fixed, assured=assured, maximum=maximum, additional=additional) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 37 | |
| 38 | self.name = name |
| 39 | self.fixed_bandwidth = fixed # bps |
| 40 | self.assured_bandwidth = assured # bps |
| 41 | self.maximum_bandwidth = maximum # bps |
| 42 | self.additional_bandwidth_eligibility = additional |
| 43 | |
| 44 | self.best_effort = best_effort if additional == BEST_EFFORT_SHARING else None |
| 45 | |
| 46 | |
| 47 | @staticmethod |
| 48 | def to_string(value): |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 49 | return { |
| 50 | NON_ASSURED_SHARING: "non-assured-sharing", |
| 51 | BEST_EFFORT_SHARING: "best-effort-sharing", |
| 52 | NONE: "none" |
| 53 | }.get(value, "unknown") |
| 54 | |
| 55 | |
| 56 | @staticmethod |
| 57 | def from_value(value): |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 58 | return { |
| 59 | 0: NONE, |
| 60 | 1: BEST_EFFORT_SHARING, |
| 61 | 2: NON_ASSURED_SHARING, |
| 62 | }.get(value, DEFAULT) |
| 63 | |
| 64 | |
| 65 | def __str__(self): |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 66 | return "OnuTrafficDescriptor: {}, {}/{}/{}".format(self.name, |
| 67 | self.fixed_bandwidth, |
| 68 | self.assured_bandwidth, |
| 69 | self.maximum_bandwidth) |
| 70 | |
| 71 | def to_dict(self): |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 72 | val = { |
| 73 | 'fixed-bandwidth': self.fixed_bandwidth, |
| 74 | 'assured-bandwidth': self.assured_bandwidth, |
| 75 | 'maximum-bandwidth': self.maximum_bandwidth, |
| 76 | 'additional-bandwidth-eligibility': OnuTrafficDescriptor.to_string(self.additional_bandwidth_eligibility) |
| 77 | } |
| 78 | return val |
| 79 | |
| 80 | |
| 81 | @staticmethod |
| 82 | def create(traffic_disc): |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 83 | |
| 84 | additional = OnuTrafficDescriptor.from_value( |
| 85 | traffic_disc['additional-bw-eligibility-indicator']) |
| 86 | |
| 87 | # TODO: this is all stub code. Doesnt do anything yet. tech profiles will likely make this clearer |
| 88 | best_effort = None |
| 89 | |
| 90 | return OnuTrafficDescriptor(traffic_disc['fixed-bandwidth'], |
| 91 | traffic_disc['assured-bandwidth'], |
| 92 | traffic_disc['maximum-bandwidth'], |
| 93 | name=traffic_disc['name'], |
| 94 | best_effort=best_effort, |
| 95 | additional=additional) |
| 96 | |
| 97 | @inlineCallbacks |
| 98 | def add_to_hardware(self, omci): |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 99 | results = succeed('TODO: Implement me') |
| 100 | returnValue(results) |
| 101 | |
| 102 | |
| 103 | |