blob: 05484589483c38a061d71e38ac59d65d96561c14 [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
21from voltha_protos.openflow_13_pb2 import OFPPF_10GB_FD
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050022from pyvoltha.common.utils.nethelpers import mac_str_to_tuple
William Kurkian8235c1e2019-03-05 12:58:28 -050023from voltha_protos.logical_device_pb2 import LogicalPort
24from voltha_protos.openflow_13_pb2 import OFPPS_LIVE, OFPPF_FIBER, OFPPS_LINK_DOWN
25from voltha_protos.openflow_13_pb2 import ofp_port
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050026
27class UniType(Enum):
28 """
29 UNI Types Defined in G.988
30 """
31 PPTP = 'PhysicalPathTerminationPointEthernet'
32 VEIP = 'VirtualEthernetInterfacePoint'
33 # TODO: Add others as they become supported
34
35
36class UniPort(object):
37 """Wraps southbound-port(s) support for ONU"""
38
39 def __init__(self, handler, name, uni_id, port_no, ofp_port_no,
40 type=UniType.PPTP):
41 self.log = structlog.get_logger(device_id=handler.device_id,
42 port_no=port_no)
43 self._enabled = False
44 self._handler = handler
45 self._name = name
46 self._port = None
47 self._port_number = port_no
48 self._ofp_port_no = ofp_port_no
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050049 self._entity_id = None
50 self._mac_bridge_port_num = 0
51 self._type = type
52 self._uni_id = uni_id
53
54 self._admin_state = AdminState.ENABLED
55 self._oper_status = OperStatus.ACTIVE
56
57 def __str__(self):
58 return "UniPort - name: {}, port_number: {}, entity_id: {}, mac_bridge_port_num: {}, type: {}, ofp_port: {}"\
59 .format(self.name, self.port_number, self.entity_id, self._mac_bridge_port_num, self.type, self._ofp_port_no)
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
72 self._oper_status = OperStatus.ACTIVE
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050073
74 def _stop(self):
75 self._cancel_deferred()
76 self._admin_state = AdminState.DISABLED
77 self._oper_status = OperStatus.UNKNOWN
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050078
79 def delete(self):
80 self.enabled = False
81 self._handler = None
82
83 def _cancel_deferred(self):
84 pass
85
86 @property
87 def name(self):
88 return self._name
89
90 @property
91 def enabled(self):
92 return self._enabled
93
94 @enabled.setter
95 def enabled(self, value):
96 if self._enabled != value:
97 self._enabled = value
98
99 if value:
100 self._start()
101 else:
102 self._stop()
103
104 @property
105 def uni_id(self):
106 """
107 Physical prt index on ONU 0 - N
108 :return: (int) uni id
109 """
110 return self._uni_id
111
112
113 @property
114 def mac_bridge_port_num(self):
115 """
116 Port number used when creating MacBridgePortConfigurationDataFrame port number
117 :return: (int) port number
118 """
119 return self._mac_bridge_port_num
120
121 @mac_bridge_port_num.setter
122 def mac_bridge_port_num(self, value):
123 self._mac_bridge_port_num = value
124
125 @property
126 def port_number(self):
127 """
128 Physical device port number
129 :return: (int) port number
130 """
131 return self._port_number
132
133 @property
134 def entity_id(self):
135 """
136 OMCI UNI_G entity ID for port
137 """
138 return self._entity_id
139
140 @entity_id.setter
141 def entity_id(self, value):
142 assert self._entity_id is None, 'Cannot reset the Entity ID'
143 self._entity_id = value
144
145 @property
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500146 def type(self):
147 """
148 UNI Type used in OMCI messaging
149 :return: (UniType) One of the enumerated types
150 """
151 return self._type
152
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500153 def get_port(self):
154 """
155 Get the VOLTHA PORT object for this port
156 :return: VOLTHA Port object
157 """
158 self._port = Port(port_no=self.port_number,
159 label=self.port_id_name(),
160 type=Port.ETHERNET_UNI,
161 admin_state=self._admin_state,
162 oper_status=self._oper_status)
163 return self._port
164
165 def port_id_name(self):
166 return 'uni-{}'.format(self._port_number)
167