blob: 045b8d339be7916fdcc257c6cc1dc16094333c71 [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 enum import Enum
William Kurkian8235c1e2019-03-05 12:58:28 -050019from voltha_protos.common_pb2 import OperStatus, AdminState
20from voltha_protos.device_pb2 import Port
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050021
22class UniType(Enum):
23 """
24 UNI Types Defined in G.988
25 """
26 PPTP = 'PhysicalPathTerminationPointEthernet'
27 VEIP = 'VirtualEthernetInterfacePoint'
28 # TODO: Add others as they become supported
29
30
31class UniPort(object):
32 """Wraps southbound-port(s) support for ONU"""
33
34 def __init__(self, handler, name, uni_id, port_no, ofp_port_no,
35 type=UniType.PPTP):
36 self.log = structlog.get_logger(device_id=handler.device_id,
37 port_no=port_no)
38 self._enabled = False
39 self._handler = handler
40 self._name = name
41 self._port = None
42 self._port_number = port_no
43 self._ofp_port_no = ofp_port_no
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050044 self._entity_id = None
45 self._mac_bridge_port_num = 0
46 self._type = type
47 self._uni_id = uni_id
48
Matt Jeanneretf4113222019-08-14 19:44:34 -040049 self._admin_state = AdminState.DISABLED
50 self._oper_status = OperStatus.DISCOVERED
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050051
52 def __str__(self):
Matt Jeanneretf4113222019-08-14 19:44:34 -040053 return "UniPort - name: {}, port_number: {}, admin_state: {}, oper_state: {}, entity_id: {}, " \
54 "mac_bridge_port_num: {}, type: {}, ofp_port: {}"\
55 .format(self.name, self.port_number, self.adminstate, self.operstatus, self.entity_id,
56 self._mac_bridge_port_num, self.type, self._ofp_port_no)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050057
58 def __repr__(self):
59 return str(self)
60
61 @staticmethod
62 def create(handler, name, uni_id, port_no, ofp_port_no, type):
63 port = UniPort(handler, name, uni_id, port_no, ofp_port_no, type)
64 return port
65
66 def _start(self):
67 self._cancel_deferred()
68 self._admin_state = AdminState.ENABLED
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050069
70 def _stop(self):
71 self._cancel_deferred()
72 self._admin_state = AdminState.DISABLED
73 self._oper_status = OperStatus.UNKNOWN
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050074
75 def delete(self):
76 self.enabled = False
77 self._handler = None
78
79 def _cancel_deferred(self):
80 pass
81
82 @property
Matt Jeanneretf4113222019-08-14 19:44:34 -040083 def adminstate(self):
84 return self._admin_state
85
86 @adminstate.setter
87 def adminstate(self, value):
88 self._admin_state = value
89
90 @property
91 def operstatus(self):
92 return self._oper_status
93
94 @operstatus.setter
95 def operstatus(self, value):
96 self._oper_status = value
97
98 @property
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050099 def name(self):
100 return self._name
101
102 @property
103 def enabled(self):
104 return self._enabled
105
106 @enabled.setter
107 def enabled(self, value):
108 if self._enabled != value:
109 self._enabled = value
110
111 if value:
112 self._start()
113 else:
114 self._stop()
115
116 @property
117 def uni_id(self):
118 """
119 Physical prt index on ONU 0 - N
120 :return: (int) uni id
121 """
122 return self._uni_id
123
124
125 @property
126 def mac_bridge_port_num(self):
127 """
128 Port number used when creating MacBridgePortConfigurationDataFrame port number
129 :return: (int) port number
130 """
131 return self._mac_bridge_port_num
132
133 @mac_bridge_port_num.setter
134 def mac_bridge_port_num(self, value):
135 self._mac_bridge_port_num = value
136
137 @property
138 def port_number(self):
139 """
140 Physical device port number
141 :return: (int) port number
142 """
143 return self._port_number
144
145 @property
146 def entity_id(self):
147 """
148 OMCI UNI_G entity ID for port
149 """
150 return self._entity_id
151
152 @entity_id.setter
153 def entity_id(self, value):
154 assert self._entity_id is None, 'Cannot reset the Entity ID'
155 self._entity_id = value
156
157 @property
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500158 def type(self):
159 """
160 UNI Type used in OMCI messaging
161 :return: (UniType) One of the enumerated types
162 """
163 return self._type
164
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500165 def get_port(self):
166 """
167 Get the VOLTHA PORT object for this port
168 :return: VOLTHA Port object
169 """
170 self._port = Port(port_no=self.port_number,
171 label=self.port_id_name(),
172 type=Port.ETHERNET_UNI,
173 admin_state=self._admin_state,
174 oper_status=self._oper_status)
175 return self._port
176
177 def port_id_name(self):
178 return 'uni-{}'.format(self._port_number)
179