Matteo Scandolo | 8abd702 | 2021-06-11 15:03:46 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2021-present Open Networking Foundation |
| 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 | */ |
| 16 | |
| 17 | package org.opencord.olt.cli; |
| 18 | |
| 19 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
| 20 | import org.onlab.osgi.DefaultServiceDirectory; |
| 21 | import org.onosproject.cli.net.PortNumberCompleter; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 22 | import org.onosproject.net.Device; |
Matteo Scandolo | 8abd702 | 2021-06-11 15:03:46 +0200 | [diff] [blame] | 23 | import org.onosproject.net.DeviceId; |
| 24 | import org.onosproject.net.device.DeviceService; |
Gustavo Silva | 29fb20e | 2022-05-26 09:59:54 -0300 | [diff] [blame] | 25 | import org.opencord.olt.OltDeviceServiceInterface; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 26 | |
Matteo Scandolo | 8abd702 | 2021-06-11 15:03:46 +0200 | [diff] [blame] | 27 | import java.util.Collections; |
| 28 | import java.util.List; |
| 29 | import java.util.stream.Collectors; |
Matteo Scandolo | 8abd702 | 2021-06-11 15:03:46 +0200 | [diff] [blame] | 30 | |
| 31 | @Service |
| 32 | public class OltUniPortCompleter extends PortNumberCompleter { |
Matteo Scandolo | 8abd702 | 2021-06-11 15:03:46 +0200 | [diff] [blame] | 33 | |
| 34 | public OltUniPortCompleter() { |
| 35 | } |
| 36 | |
| 37 | protected List<String> choices() { |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 38 | DeviceService deviceService = DefaultServiceDirectory.getService(DeviceService.class); |
Matteo Scandolo | 8abd702 | 2021-06-11 15:03:46 +0200 | [diff] [blame] | 39 | DeviceId deviceId = this.lookForDeviceId(); |
| 40 | if (deviceId == null) { |
| 41 | return Collections.emptyList(); |
| 42 | } else { |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 43 | Device device = deviceService.getDevice(DeviceId.deviceId(deviceId.toString())); |
| 44 | OltDeviceServiceInterface oltDeviceService = |
| 45 | DefaultServiceDirectory.getService(OltDeviceServiceInterface.class); |
| 46 | return deviceService.getPorts(deviceId).stream() |
| 47 | .filter((port) -> port.isEnabled() && !oltDeviceService.isNniPort(device, port.number())) |
| 48 | .map((port) -> port.number().toString()) |
| 49 | .collect(Collectors.toList()); |
Matteo Scandolo | 8abd702 | 2021-06-11 15:03:46 +0200 | [diff] [blame] | 50 | } |
| 51 | } |
| 52 | } |