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 | from enum import Enum |
| 16 | |
| 17 | |
| 18 | class TrafficDescriptor(object): |
| 19 | """ |
| 20 | Class to wrap the uplink traffic descriptor. |
| 21 | """ |
| 22 | class AdditionalBwEligibility(Enum): |
| 23 | NONE = 0 |
| 24 | BEST_EFFORT_SHARING = 1 |
| 25 | NON_ASSURED_SHARING = 2 # Should match xpon.py values |
| 26 | DEFAULT = NONE |
| 27 | |
| 28 | @staticmethod |
| 29 | def to_string(value): |
| 30 | return { |
| 31 | TrafficDescriptor.AdditionalBwEligibility.NON_ASSURED_SHARING: "non-assured-sharing", |
| 32 | TrafficDescriptor.AdditionalBwEligibility.BEST_EFFORT_SHARING: "best-effort-sharing", |
| 33 | TrafficDescriptor.AdditionalBwEligibility.NONE: "none" |
| 34 | }.get(value, "unknown") |
| 35 | |
| 36 | @staticmethod |
| 37 | def from_value(value): |
| 38 | """ |
| 39 | Matches both Adtran and xPON values |
| 40 | :param value: |
| 41 | :return: |
| 42 | """ |
| 43 | return { |
| 44 | 0: TrafficDescriptor.AdditionalBwEligibility.NONE, |
| 45 | 1: TrafficDescriptor.AdditionalBwEligibility.BEST_EFFORT_SHARING, |
| 46 | 2: TrafficDescriptor.AdditionalBwEligibility.NON_ASSURED_SHARING, |
| 47 | }.get(value, TrafficDescriptor.AdditionalBwEligibility.DEFAULT) |
| 48 | |
| 49 | def __init__(self, fixed, assured, maximum, |
| 50 | additional=AdditionalBwEligibility.DEFAULT, |
| 51 | best_effort=None): |
| 52 | self.fixed_bandwidth = fixed # bps |
| 53 | self.assured_bandwidth = assured # bps |
| 54 | self.maximum_bandwidth = maximum # bps |
| 55 | self.additional_bandwidth_eligibility = additional |
| 56 | self.best_effort = best_effort\ |
| 57 | if additional == TrafficDescriptor.AdditionalBwEligibility.BEST_EFFORT_SHARING\ |
| 58 | else None |
| 59 | |
| 60 | def __str__(self): |
| 61 | return "TrafficDescriptor: {}/{}/{}".format(self.fixed_bandwidth, |
| 62 | self.assured_bandwidth, |
| 63 | self.maximum_bandwidth) |
| 64 | |
| 65 | def to_dict(self): |
| 66 | val = { |
| 67 | 'fixed-bandwidth': self.fixed_bandwidth, |
| 68 | 'assured-bandwidth': self.assured_bandwidth, |
| 69 | 'maximum-bandwidth': self.maximum_bandwidth, |
| 70 | 'additional-bandwidth-eligibility': |
| 71 | TrafficDescriptor.AdditionalBwEligibility.to_string( |
| 72 | self.additional_bandwidth_eligibility) |
| 73 | } |
| 74 | return val |
| 75 | |