blob: dca219d2b4e5542f8f9d17d2dc3f6ec6e4b09793 [file] [log] [blame]
Shad Ansari134947d2019-02-14 23:45:03 -08001#
2# Copyright 2019 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
17import socket
Shad Ansarif9b9b892019-02-27 17:10:27 -080018import voltha.core.flow_decomposer as fd
Shad Ansari134947d2019-02-14 23:45:03 -080019from voltha.adapters.openolt.openolt_utils import OpenoltUtils
Shad Ansarid5577972019-02-22 09:35:03 -080020from voltha.protos.device_pb2 import Port, Device
Shad Ansari134947d2019-02-14 23:45:03 -080021from voltha.protos.openflow_13_pb2 import OFPPS_LIVE, OFPPF_FIBER, \
22 OFPPS_LINK_DOWN, OFPPF_1GB_FD, OFPC_PORT_STATS, OFPC_TABLE_STATS, \
23 OFPC_FLOW_STATS, OFPC_GROUP_STATS, ofp_port, ofp_port_stats, ofp_desc, \
24 ofp_switch_features
25from voltha.core.logical_device_agent import mac_str_to_tuple
26from voltha.protos.logical_device_pb2 import LogicalPort
Shad Ansarid5577972019-02-22 09:35:03 -080027from voltha.protos.common_pb2 import OperStatus, AdminState, ConnectStatus
Shad Ansari134947d2019-02-14 23:45:03 -080028from voltha.protos.logical_device_pb2 import LogicalDevice
29from voltha.registry import registry
30
31
32class OpenOltDataModel(object):
Shad Ansari134947d2019-02-14 23:45:03 -080033
Shad Ansarid5577972019-02-22 09:35:03 -080034 def __init__(self, device, adapter_agent, platform):
Shad Ansari134947d2019-02-14 23:45:03 -080035 self.log = structlog.get_logger()
36
Shad Ansarid5577972019-02-22 09:35:03 -080037 self.device = device
38 self.adapter_agent = adapter_agent
39 self.platform = platform
40 self.logical_device_id = None
41
42 self.device.root = True
43 self.device.connect_status = ConnectStatus.UNREACHABLE
44 self.device.oper_status = OperStatus.ACTIVATING
45
46 self.adapter_agent.update_device(device)
47
Shad Ansarif9b9b892019-02-27 17:10:27 -080048 self.nni_intf_id = None
Shad Ansarief2029b2019-02-25 09:45:54 -080049
Shad Ansarid5577972019-02-22 09:35:03 -080050 def reconcile(self):
51 assert self.logical_device_id is not None
52 self.adapter_agent.reconcile_logical_device(
53 self.logical_device_id)
54
55 def olt_create(self, device_info):
56 if self.logical_device_id is not None:
57 return
58
Shad Ansari134947d2019-02-14 23:45:03 -080059 dpid = device_info.device_id
60 serial_number = device_info.device_serial_number
61
Shad Ansari134947d2019-02-14 23:45:03 -080062 if dpid is None or dpid == '':
Shad Ansarid5577972019-02-22 09:35:03 -080063 uri = self.device.host_and_port.split(":")[0]
Shad Ansari134947d2019-02-14 23:45:03 -080064 try:
65 socket.inet_pton(socket.AF_INET, uri)
66 dpid = '00:00:' + OpenoltUtils.ip_hex(uri)
67 except socket.error:
68 # this is not an IP
69 dpid = OpenoltUtils.str_to_mac(uri)
70
71 self.log.info('creating-openolt-logical-device', dp_id=dpid,
72 serial_number=serial_number)
73
74 hw_desc = device_info.model
75 if device_info.hardware_version:
76 hw_desc += '-' + device_info.hardware_version
77
78 # Create logical OF device
79 ld = LogicalDevice(
Shad Ansarid5577972019-02-22 09:35:03 -080080 root_device_id=self.device.id,
Shad Ansari134947d2019-02-14 23:45:03 -080081 switch_features=ofp_switch_features(
82 n_buffers=256, # TODO fake for now
83 n_tables=2, # TODO ditto
84 capabilities=( # TODO and ditto
85 OFPC_FLOW_STATS
86 | OFPC_TABLE_STATS
87 | OFPC_PORT_STATS
88 | OFPC_GROUP_STATS
89 )
90 ),
91 desc=ofp_desc(
92 serial_num=serial_number
93 )
94 )
Shad Ansarid5577972019-02-22 09:35:03 -080095 self.logical_device_id = \
96 self.adapter_agent.create_logical_device(ld, dpid=dpid).id
Shad Ansari134947d2019-02-14 23:45:03 -080097
Shad Ansarid5577972019-02-22 09:35:03 -080098 self.device.vendor = device_info.vendor
99 self.device.model = device_info.model
100 self.device.hardware_version = device_info.hardware_version
101 self.device.firmware_version = device_info.firmware_version
102 self.device.connect_status = ConnectStatus.REACHABLE
103 self.device.serial_number = serial_number
104
105 self.adapter_agent.update_device(self.device)
Shad Ansari134947d2019-02-14 23:45:03 -0800106
107 self.log.info('created-openolt-logical-device',
Shad Ansarid5577972019-02-22 09:35:03 -0800108 logical_device_id=self.logical_device_id)
Shad Ansari134947d2019-02-14 23:45:03 -0800109
Shad Ansarid5577972019-02-22 09:35:03 -0800110 return self.logical_device_id
Shad Ansari134947d2019-02-14 23:45:03 -0800111
Shad Ansarief2029b2019-02-25 09:45:54 -0800112 def olt_oper_up(self):
113 self.device.parent_id = self.logical_device_id
114 self.device.oper_status = OperStatus.ACTIVE
115 self.adapter_agent.update_device(self.device)
Shad Ansari134947d2019-02-14 23:45:03 -0800116
Shad Ansarief2029b2019-02-25 09:45:54 -0800117 def olt_oper_down(self):
Shad Ansarif9b9b892019-02-27 17:10:27 -0800118 self.__disable_logical_device()
Shad Ansarief2029b2019-02-25 09:45:54 -0800119
120 def olt_delete(self):
121 ld = self.adapter_agent.get_logical_device(self.logical_device_id)
122 self.adapter_agent.delete_logical_device(ld)
123
Shad Ansarif9b9b892019-02-27 17:10:27 -0800124 def olt_port_add_update(self, intf_id, intf_type, oper):
125 if oper == "up":
126 oper_status = OperStatus.ACTIVE
127 else:
128 oper_status = OperStatus.DISCOVERED
129
130 if intf_type == "nni":
131 port_type = Port.ETHERNET_NNI
132 elif intf_type == "pon":
133 port_type = Port.PON_OLT
134
135 port_no, label = self.__add_port(intf_id, port_type, oper_status)
136
137 if intf_type == "nni":
138 self.__add_logical_port(port_no, intf_id, oper_status)
139 self.nni_intf_id = intf_id
140
141 def olt_nni_intf_id(self):
142 if self.nni_intf_id is not None:
143 return self.nni_intf_id
144
145 port_list = self.adapter_agent.get_ports(self.device.id,
146 Port.ETHERNET_NNI)
147 logical_port = self.adapter_agent.get_logical_port(
148 self.logical_device_id, port_list[0].label)
149 self.nni_intf_id = self.platform.intf_id_from_nni_port_num(
150 logical_port.ofp_port.port_no)
151 self.log.debug("nni-intf-d ", nni_intf_id=self.nni_intf_id)
152 return self.nni_intf_id
153
Shad Ansarief2029b2019-02-25 09:45:54 -0800154 def onu_create(self, intf_id, onu_id, serial_number):
155 onu_device = self.adapter_agent.get_child_device(
156 self.device.id,
157 serial_number=serial_number)
158
159 if onu_device:
160 self.log.debug("data_model onu update", intf_id=intf_id,
161 onu_id=onu_id, serial_number=serial_number)
162 onu_device.oper_status = OperStatus.DISCOVERED
163 onu_device.connect_status = ConnectStatus.REACHABLE
164 self.adapter_agent.update_device(onu_device)
165 return
166
167 self.log.debug("data_model onu create", intf_id=intf_id,
168 onu_id=onu_id, serial_number=serial_number)
169
170 # NOTE - channel_id of onu is set to intf_id
171 proxy_address = Device.ProxyAddress(device_id=self.device.id,
172 channel_id=intf_id, onu_id=onu_id,
173 onu_session_id=onu_id)
174 port_no = self.platform.intf_id_to_port_no(intf_id, Port.PON_OLT)
175 vendor_id = serial_number[:4]
176 self.adapter_agent.add_onu_device(
177 parent_device_id=self.device.id, parent_port_no=port_no,
178 vendor_id=vendor_id, proxy_address=proxy_address,
179 root=False, serial_number=serial_number,
180 admin_state=AdminState.ENABLED,
181 connect_status=ConnectStatus.REACHABLE
182 )
183
184 def onu_delete(self, serial_number):
185 onu_device = self.adapter_agent.get_child_device(
186 self.device.id,
187 serial_number=serial_number)
188 try:
Shad Ansarif9b9b892019-02-27 17:10:27 -0800189 self.adapter_agent.delete_child_device(self.device.id,
Shad Ansarief2029b2019-02-25 09:45:54 -0800190 onu_device.id, onu_device)
191 except Exception as e:
192 self.log.error('adapter_agent error', error=e)
193
Shad Ansarif9b9b892019-02-27 17:10:27 -0800194 ofp_port_name = self.__get_uni_ofp_port_name(onu_device)
Shad Ansarief2029b2019-02-25 09:45:54 -0800195 if ofp_port_name is None:
196 self.log.exception("uni-ofp-port-not-found")
197 return
198
199 try:
Shad Ansarif9b9b892019-02-27 17:10:27 -0800200 self.__delete_logical_port(onu_device)
Shad Ansarief2029b2019-02-25 09:45:54 -0800201 except Exception as e:
202 self.log.error('logical_port delete error', error=e)
203 try:
204 self.delete_port(onu_device.serial_number)
205 except Exception as e:
206 self.log.error('port delete error', error=e)
207
208 def onu_id(self, serial_number):
209 onu_device = self.adapter_agent.get_child_device(
210 self.device.id,
211 serial_number=serial_number)
212
213 if onu_device:
214 return onu_device.proxy_address.onu_id
215 else:
216 return 0 # Invalid onu id
217
218 def onu_oper_down(self, intf_id, onu_id):
219
220 onu_device = self.adapter_agent.get_child_device(
221 self.device.id,
222 parent_port_no=self.platform.intf_id_to_port_no(intf_id,
223 Port.PON_OLT),
224 onu_id=onu_id)
225
226 if onu_device is None:
227 self.log.error('onu not found', intf_id=intf_id, onu_id=onu_id)
228 return
229
230 onu_adapter_agent = \
231 registry('adapter_loader').get_agent(onu_device.adapter)
232 if onu_adapter_agent is None:
233 self.log.error('onu_adapter_agent-could-not-be-retrieved',
234 onu_device=onu_device)
235 return
236
237 if onu_device.connect_status != ConnectStatus.UNREACHABLE:
238 onu_device.connect_status = ConnectStatus.UNREACHABLE
239 self.adapter_agent.update_device(onu_device)
240
241 # Move to discovered state
242 self.log.debug('onu-oper-state-is-down')
243
244 if onu_device.oper_status != OperStatus.DISCOVERED:
245 onu_device.oper_status = OperStatus.DISCOVERED
246 self.adapter_agent.update_device(onu_device)
247 # Set port oper state to Discovered
Shad Ansarif9b9b892019-02-27 17:10:27 -0800248 self.data_model.__onu_ports_down(onu_device)
Shad Ansarief2029b2019-02-25 09:45:54 -0800249
250 onu_adapter_agent.update_interface(onu_device,
251 {'oper_state': 'down'})
252
253 def onu_oper_up(self, intf_id, onu_id):
254
255 class _OnuIndication:
256 def __init__(self, intf_id, onu_id):
257 self.intf_id = intf_id
258 self.onu_id = onu_id
259
260 onu_device = self.adapter_agent.get_child_device(
261 self.device.id,
262 parent_port_no=self.platform.intf_id_to_port_no(intf_id,
263 Port.PON_OLT),
264 onu_id=onu_id)
265
266 if onu_device is None:
267 self.log.error('onu not found', intf_id=intf_id, onu_id=onu_id)
268 return
269
270 onu_adapter_agent = \
271 registry('adapter_loader').get_agent(onu_device.adapter)
272 if onu_adapter_agent is None:
273 self.log.error('onu_adapter_agent-could-not-be-retrieved',
274 onu_device=onu_device)
275 return
276 if onu_device.connect_status != ConnectStatus.REACHABLE:
277 onu_device.connect_status = ConnectStatus.REACHABLE
278 self.adapter_agent.update_device(onu_device)
279
280 if onu_device.oper_status != OperStatus.DISCOVERED:
281 self.log.debug("ignore onu indication",
282 intf_id=intf_id,
283 onu_id=onu_id,
284 state=onu_device.oper_status,
285 msg_oper_state="up")
286 return
287
288 onu_adapter_agent.create_interface(onu_device,
289 _OnuIndication(intf_id, onu_id))
290
Shad Ansarif9b9b892019-02-27 17:10:27 -0800291 def onu_download_tech_profile(self, intf_id, onu_id, uni_id, tp_path):
292 onu_device = self.adapter_agent.get_child_device(
293 self.device.id,
294 parent_port_no=self.platform.intf_id_to_port_no(intf_id,
295 Port.PON_OLT),
296 onu_id=onu_id)
297 msg = {'proxy_address': onu_device.proxy_address,
298 'uni_id': uni_id, 'event': 'download_tech_profile',
299 'event_data': tp_path}
300
301 # Send the event message to the ONU adapter
302 self.adapter_agent.publish_inter_adapter_message(
303 onu_device.id, msg)
304
305 # #######################################################################
306 # Flow decomposer utility functions
307 #
308 # Flow related functions that are used by the OpenOLT flow decomposer.
309 # These are all prefixed with _ to denote that they will likely be removed
310 # once OpenOLT adapter transitions back to using core's flow decomposer.
311 # #######################################################################
312
313 def _flow_extract_info(self, flow, flow_direction):
314 uni_port_no = None
315 child_device_id = None
316 if flow_direction == "upstream":
317 for field in fd.get_ofb_fields(flow):
318 if field.type == fd.IN_PORT:
319 is_uni, child_device_id = self.__is_uni_port(field.port)
320 if is_uni:
321 uni_port_no = field.port
322 elif flow_direction == "downstream":
323 for field in fd.get_ofb_fields(flow):
324 if field.type == fd.METADATA:
325 uni_port = field.table_metadata & 0xFFFFFFFF
326 is_uni, child_device_id = self.__is_uni_port(uni_port)
327 if is_uni:
328 uni_port_no = field.port
329
330 if uni_port_no is None:
331 for action in fd.get_actions(flow):
332 if action.type == fd.OUTPUT:
333 is_uni, child_device_id = \
334 self.__is_uni_port(action.output.port)
335 if is_uni:
336 uni_port_no = action.output.port
337
338 if child_device_id:
339 child_device = self.adapter_agent.get_device(child_device_id)
340 pon_intf = child_device.proxy_address.channel_id
341 onu_id = child_device.proxy_address.onu_id
342 uni_id = self.platform.uni_id_from_port_num(uni_port_no) \
343 if uni_port_no is not None else None
Shad Ansarief2029b2019-02-25 09:45:54 -0800344 else:
Shad Ansarif9b9b892019-02-27 17:10:27 -0800345 raise ValueError
Shad Ansarief2029b2019-02-25 09:45:54 -0800346
Shad Ansarif9b9b892019-02-27 17:10:27 -0800347 return pon_intf, onu_id, uni_id
Shad Ansarief2029b2019-02-25 09:45:54 -0800348
Shad Ansarif9b9b892019-02-27 17:10:27 -0800349 def _get_ofp_port_name(self, intf_id, onu_id, uni_id):
350 parent_port_no = self.platform.intf_id_to_port_no(intf_id,
351 Port.PON_OLT)
352 child_device = self.adapter_agent.get_child_device(
353 self.device.id, parent_port_no=parent_port_no, onu_id=onu_id)
354 if child_device is None:
355 self.log.error("could-not-find-child-device",
356 parent_port_no=intf_id, onu_id=onu_id)
357 return (None, None)
358 ports = self.adapter_agent.get_ports(child_device.id,
359 Port.ETHERNET_UNI)
360 logical_port = self.adapter_agent.get_logical_port(
361 self.logical_device_id, ports[uni_id].label)
362 ofp_port_name = (logical_port.ofp_port.name,
363 logical_port.ofp_port.port_no)
364 return ofp_port_name
Shad Ansarief2029b2019-02-25 09:45:54 -0800365
Shad Ansarif9b9b892019-02-27 17:10:27 -0800366 # #######################################################################
Shad Ansarief2029b2019-02-25 09:45:54 -0800367 # Private functions
Shad Ansarif9b9b892019-02-27 17:10:27 -0800368 #
369 # These functions are prefixed with __ to denote that they are private
370 # to openolt_data_model and should not be called directly from the adapter.
371 # #######################################################################
Shad Ansarief2029b2019-02-25 09:45:54 -0800372
Shad Ansarif9b9b892019-02-27 17:10:27 -0800373 def __disable_logical_device(self):
Shad Ansari134947d2019-02-14 23:45:03 -0800374 oper_state = OperStatus.UNKNOWN
375 connect_state = ConnectStatus.UNREACHABLE
376
Shad Ansarief2029b2019-02-25 09:45:54 -0800377 onu_devices = self.adapter_agent.get_child_devices(self.device.id)
378 for onu_device in onu_devices:
Shad Ansari134947d2019-02-14 23:45:03 -0800379 onu_adapter_agent = \
380 registry('adapter_loader').get_agent(onu_device.adapter)
381 onu_adapter_agent.update_interface(onu_device,
382 {'oper_state': 'down'})
Shad Ansarief2029b2019-02-25 09:45:54 -0800383 self.onu_ports_down(onu_device)
Shad Ansari134947d2019-02-14 23:45:03 -0800384
385 # Children devices
386 self.adapter_agent.update_child_devices_state(
Shad Ansarid5577972019-02-22 09:35:03 -0800387 self.device.id, oper_status=oper_state,
Shad Ansari134947d2019-02-14 23:45:03 -0800388 connect_status=connect_state)
389 # Device Ports
Shad Ansarid5577972019-02-22 09:35:03 -0800390 device_ports = self.adapter_agent.get_ports(self.device.id,
Shad Ansari134947d2019-02-14 23:45:03 -0800391 Port.ETHERNET_NNI)
392 logical_ports_ids = [port.label for port in device_ports]
Shad Ansarid5577972019-02-22 09:35:03 -0800393 device_ports += self.adapter_agent.get_ports(self.device.id,
Shad Ansari134947d2019-02-14 23:45:03 -0800394 Port.PON_OLT)
395
396 for port in device_ports:
397 port.oper_status = oper_state
Shad Ansarid5577972019-02-22 09:35:03 -0800398 self.adapter_agent.add_port(self.device.id, port)
Shad Ansari134947d2019-02-14 23:45:03 -0800399
400 # Device logical port
401 for logical_port_id in logical_ports_ids:
402 logical_port = self.adapter_agent.get_logical_port(
Shad Ansarid5577972019-02-22 09:35:03 -0800403 self.logical_device_id, logical_port_id)
Shad Ansari134947d2019-02-14 23:45:03 -0800404 logical_port.ofp_port.state = OFPPS_LINK_DOWN
405 self.adapter_agent.update_logical_port(self.logical_device_id,
406 logical_port)
Shad Ansarid5577972019-02-22 09:35:03 -0800407 self.device.oper_status = oper_state
408 self.device.connect_status = connect_state
409 self.adapter_agent.update_device(self.device)
Shad Ansari134947d2019-02-14 23:45:03 -0800410
Shad Ansarif9b9b892019-02-27 17:10:27 -0800411 def __add_logical_port(self, port_no, intf_id, oper_state):
Shad Ansari134947d2019-02-14 23:45:03 -0800412 self.log.info('adding-logical-port', port_no=port_no)
413
414 label = OpenoltUtils.port_name(port_no, Port.ETHERNET_NNI)
415
416 cap = OFPPF_1GB_FD | OFPPF_FIBER
417 curr_speed = OFPPF_1GB_FD
418 max_speed = OFPPF_1GB_FD
419
420 if oper_state == OperStatus.ACTIVE:
421 of_oper_state = OFPPS_LIVE
422 else:
423 of_oper_state = OFPPS_LINK_DOWN
424
425 ofp = ofp_port(
426 port_no=port_no,
427 hw_addr=mac_str_to_tuple(
428 OpenoltUtils.make_mac_from_port_no(port_no)),
429 name=label, config=0, state=of_oper_state, curr=cap,
430 advertised=cap, peer=cap, curr_speed=curr_speed,
431 max_speed=max_speed)
432
433 ofp_stats = ofp_port_stats(port_no=port_no)
434
435 logical_port = LogicalPort(
Shad Ansarid5577972019-02-22 09:35:03 -0800436 id=label, ofp_port=ofp, device_id=self.device.id,
Shad Ansari134947d2019-02-14 23:45:03 -0800437 device_port_no=port_no, root_port=True,
438 ofp_port_stats=ofp_stats)
439
Shad Ansarid5577972019-02-22 09:35:03 -0800440 self.adapter_agent.add_logical_port(self.logical_device_id,
441 logical_port)
442
Shad Ansarif9b9b892019-02-27 17:10:27 -0800443 def __delete_logical_port(self, child_device):
Shad Ansarief2029b2019-02-25 09:45:54 -0800444 logical_ports = self.proxy.get('/logical_devices/{}/ports'.format(
445 self.data_model.logical_device_id))
446 for logical_port in logical_ports:
447 if logical_port.device_id == child_device.id:
448 self.log.debug('delete-logical-port',
449 onu_device_id=child_device.id,
450 logical_port=logical_port)
451 self.flow_mgr.clear_flows_and_scheduler_for_logical_port(
452 child_device, logical_port)
453 self.adapter_agent.delete_logical_port(
454 self.data_model.logical_device_id, logical_port)
455 return
Shad Ansarid5577972019-02-22 09:35:03 -0800456
Shad Ansarif9b9b892019-02-27 17:10:27 -0800457 def __onu_ports_down(self, onu_device):
Shad Ansarief2029b2019-02-25 09:45:54 -0800458 onu_ports = self.proxy.get('devices/{}/ports'.format(onu_device.id))
459 for onu_port in onu_ports:
460 self.log.debug('onu-ports-down', onu_port=onu_port)
461 onu_port_id = onu_port.label
462 try:
463 onu_logical_port = self.adapter_agent.get_logical_port(
464 logical_device_id=self.data_model.logical_device_id,
465 port_id=onu_port_id)
466 onu_logical_port.ofp_port.state = OFPPS_LINK_DOWN
467 self.adapter_agent.update_logical_port(
468 logical_device_id=self.data_model.logical_device_id,
469 port=onu_logical_port)
470 self.log.debug('cascading-oper-state-to-port-and-logical-port')
471 except KeyError as e:
472 self.log.error('matching-onu-port-label-invalid',
473 onu_id=onu_device.id, olt_id=self.device.id,
474 onu_ports=onu_ports, onu_port_id=onu_port_id,
475 error=e)
Shad Ansarid5577972019-02-22 09:35:03 -0800476
Shad Ansarif9b9b892019-02-27 17:10:27 -0800477 def __add_port(self, intf_id, port_type, oper_status):
Shad Ansarief2029b2019-02-25 09:45:54 -0800478 port_no = self.platform.intf_id_to_port_no(intf_id, port_type)
Shad Ansarid5577972019-02-22 09:35:03 -0800479
Shad Ansarief2029b2019-02-25 09:45:54 -0800480 label = OpenoltUtils.port_name(port_no, port_type, intf_id)
Shad Ansarid5577972019-02-22 09:35:03 -0800481
Shad Ansarief2029b2019-02-25 09:45:54 -0800482 self.log.debug('adding-port', port_no=port_no, label=label,
483 port_type=port_type)
Shad Ansarid5577972019-02-22 09:35:03 -0800484
Shad Ansarief2029b2019-02-25 09:45:54 -0800485 port = Port(port_no=port_no, label=label, type=port_type,
486 admin_state=AdminState.ENABLED, oper_status=oper_status)
Shad Ansarid5577972019-02-22 09:35:03 -0800487
Shad Ansarief2029b2019-02-25 09:45:54 -0800488 self.adapter_agent.add_port(self.device.id, port)
Shad Ansarid5577972019-02-22 09:35:03 -0800489
Shad Ansarief2029b2019-02-25 09:45:54 -0800490 return port_no, label
Shad Ansarid5577972019-02-22 09:35:03 -0800491
Shad Ansarif9b9b892019-02-27 17:10:27 -0800492 def __get_uni_ofp_port_name(self, child_device):
Shad Ansarief2029b2019-02-25 09:45:54 -0800493 logical_ports = self.proxy.get('/logical_devices/{}/ports'.format(
494 self.data_model.logical_device_id))
495 for logical_port in logical_ports:
496 if logical_port.device_id == child_device.id:
497 return logical_port.ofp_port.name
498 return None
Shad Ansarif9b9b892019-02-27 17:10:27 -0800499
500 def __is_uni_port(self, port_no):
501 try:
502 port = self.adapter_agent.get_logical_port(
503 self.logical_device_id, 'uni-{}'.format(port_no))
504 if port is not None:
505 return (not port.root_port), port.device_id
506 else:
507 return False, None
508 except Exception as e:
509 self.log.error("error-retrieving-port", e=e)
510 return False, None