blob: 0e8820d4c32b42b120215d1b19d109e36be2ae1e [file] [log] [blame]
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001#
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 Jeanneret2e3cb8d2019-11-16 09:22:41 -050016from __future__ import absolute_import
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050017import structlog
18from twisted.internet.defer import inlineCallbacks, returnValue, succeed
19
20
21NONE = 0
22BEST_EFFORT_SHARING = 1
23NON_ASSURED_SHARING = 2 # Should match xpon.py values
24DEFAULT = NONE
25
26
27class 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 Jeanneretf1e9c5d2019-02-08 07:41:29 -050037
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 Jeanneretf1e9c5d2019-02-08 07:41:29 -050049 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 Jeanneretf1e9c5d2019-02-08 07:41:29 -050058 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 Jeanneretf1e9c5d2019-02-08 07:41:29 -050066 return "OnuTrafficDescriptor: {}, {}/{}/{}".format(self.name,
67 self.fixed_bandwidth,
68 self.assured_bandwidth,
69 self.maximum_bandwidth)
70
71 def to_dict(self):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050072 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 Jeanneretf1e9c5d2019-02-08 07:41:29 -050083
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 Jeanneretf1e9c5d2019-02-08 07:41:29 -050099 results = succeed('TODO: Implement me')
100 returnValue(results)
101
102
103