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 enum import Enum |
William Kurkian | 8235c1e | 2019-03-05 12:58:28 -0500 | [diff] [blame] | 19 | from voltha_protos.common_pb2 import OperStatus, AdminState |
| 20 | from voltha_protos.device_pb2 import Port |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 21 | |
| 22 | class 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 | |
Andrea Campanella | cf916ea | 2020-02-14 10:03:58 +0100 | [diff] [blame] | 30 | # ReservedVlan Transparent Vlan (Masked Vlan, VLAN_ANY in ONOS Flows) |
| 31 | |
| 32 | RESERVED_TRANSPARENT_VLAN = 4096 |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 33 | |
| 34 | class UniPort(object): |
| 35 | """Wraps southbound-port(s) support for ONU""" |
| 36 | |
| 37 | def __init__(self, handler, name, uni_id, port_no, ofp_port_no, |
| 38 | type=UniType.PPTP): |
| 39 | self.log = structlog.get_logger(device_id=handler.device_id, |
| 40 | port_no=port_no) |
| 41 | self._enabled = False |
| 42 | self._handler = handler |
| 43 | self._name = name |
| 44 | self._port = None |
| 45 | self._port_number = port_no |
| 46 | self._ofp_port_no = ofp_port_no |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 47 | self._entity_id = None |
| 48 | self._mac_bridge_port_num = 0 |
| 49 | self._type = type |
| 50 | self._uni_id = uni_id |
| 51 | |
Matt Jeanneret | f411322 | 2019-08-14 19:44:34 -0400 | [diff] [blame] | 52 | self._admin_state = AdminState.DISABLED |
| 53 | self._oper_status = OperStatus.DISCOVERED |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 54 | |
| 55 | def __str__(self): |
Matt Jeanneret | f411322 | 2019-08-14 19:44:34 -0400 | [diff] [blame] | 56 | return "UniPort - name: {}, port_number: {}, admin_state: {}, oper_state: {}, entity_id: {}, " \ |
| 57 | "mac_bridge_port_num: {}, type: {}, ofp_port: {}"\ |
| 58 | .format(self.name, self.port_number, self.adminstate, self.operstatus, self.entity_id, |
| 59 | self._mac_bridge_port_num, self.type, self._ofp_port_no) |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 60 | |
| 61 | def __repr__(self): |
| 62 | return str(self) |
| 63 | |
| 64 | @staticmethod |
| 65 | def create(handler, name, uni_id, port_no, ofp_port_no, type): |
| 66 | port = UniPort(handler, name, uni_id, port_no, ofp_port_no, type) |
| 67 | return port |
| 68 | |
| 69 | def _start(self): |
| 70 | self._cancel_deferred() |
| 71 | self._admin_state = AdminState.ENABLED |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 72 | |
| 73 | def _stop(self): |
| 74 | self._cancel_deferred() |
| 75 | self._admin_state = AdminState.DISABLED |
| 76 | self._oper_status = OperStatus.UNKNOWN |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 77 | |
| 78 | def delete(self): |
| 79 | self.enabled = False |
| 80 | self._handler = None |
| 81 | |
| 82 | def _cancel_deferred(self): |
| 83 | pass |
| 84 | |
| 85 | @property |
Matt Jeanneret | f411322 | 2019-08-14 19:44:34 -0400 | [diff] [blame] | 86 | def adminstate(self): |
| 87 | return self._admin_state |
| 88 | |
| 89 | @adminstate.setter |
| 90 | def adminstate(self, value): |
| 91 | self._admin_state = value |
| 92 | |
| 93 | @property |
| 94 | def operstatus(self): |
| 95 | return self._oper_status |
| 96 | |
| 97 | @operstatus.setter |
| 98 | def operstatus(self, value): |
| 99 | self._oper_status = value |
| 100 | |
| 101 | @property |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 102 | def name(self): |
| 103 | return self._name |
| 104 | |
| 105 | @property |
| 106 | def enabled(self): |
| 107 | return self._enabled |
| 108 | |
| 109 | @enabled.setter |
| 110 | def enabled(self, value): |
| 111 | if self._enabled != value: |
| 112 | self._enabled = value |
| 113 | |
| 114 | if value: |
| 115 | self._start() |
| 116 | else: |
| 117 | self._stop() |
| 118 | |
| 119 | @property |
| 120 | def uni_id(self): |
| 121 | """ |
| 122 | Physical prt index on ONU 0 - N |
| 123 | :return: (int) uni id |
| 124 | """ |
| 125 | return self._uni_id |
| 126 | |
| 127 | |
| 128 | @property |
| 129 | def mac_bridge_port_num(self): |
| 130 | """ |
| 131 | Port number used when creating MacBridgePortConfigurationDataFrame port number |
| 132 | :return: (int) port number |
| 133 | """ |
| 134 | return self._mac_bridge_port_num |
| 135 | |
| 136 | @mac_bridge_port_num.setter |
| 137 | def mac_bridge_port_num(self, value): |
| 138 | self._mac_bridge_port_num = value |
| 139 | |
| 140 | @property |
| 141 | def port_number(self): |
| 142 | """ |
| 143 | Physical device port number |
| 144 | :return: (int) port number |
| 145 | """ |
| 146 | return self._port_number |
| 147 | |
| 148 | @property |
| 149 | def entity_id(self): |
| 150 | """ |
| 151 | OMCI UNI_G entity ID for port |
| 152 | """ |
| 153 | return self._entity_id |
| 154 | |
| 155 | @entity_id.setter |
| 156 | def entity_id(self, value): |
| 157 | assert self._entity_id is None, 'Cannot reset the Entity ID' |
| 158 | self._entity_id = value |
| 159 | |
| 160 | @property |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 161 | def type(self): |
| 162 | """ |
| 163 | UNI Type used in OMCI messaging |
| 164 | :return: (UniType) One of the enumerated types |
| 165 | """ |
| 166 | return self._type |
| 167 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 168 | def get_port(self): |
| 169 | """ |
| 170 | Get the VOLTHA PORT object for this port |
| 171 | :return: VOLTHA Port object |
| 172 | """ |
| 173 | self._port = Port(port_no=self.port_number, |
| 174 | label=self.port_id_name(), |
| 175 | type=Port.ETHERNET_UNI, |
| 176 | admin_state=self._admin_state, |
| 177 | oper_status=self._oper_status) |
| 178 | return self._port |
| 179 | |
| 180 | def port_id_name(self): |
| 181 | return 'uni-{}'.format(self._port_number) |
| 182 | |