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