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