blob: 98301dbd798100299acac46f5318ad32ca6faf02 [file] [log] [blame]
Matteo Scandolo8abd7022021-06-11 15:03:46 +02001/*
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
17package org.opencord.olt.cli;
18
19import org.apache.karaf.shell.api.action.lifecycle.Service;
20import org.onlab.osgi.DefaultServiceDirectory;
21import org.onosproject.cli.net.PortNumberCompleter;
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070022import org.onosproject.net.Device;
Matteo Scandolo8abd7022021-06-11 15:03:46 +020023import org.onosproject.net.DeviceId;
24import org.onosproject.net.device.DeviceService;
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070025import org.opencord.olt.impl.OltDeviceServiceInterface;
26
Matteo Scandolo8abd7022021-06-11 15:03:46 +020027import java.util.Collections;
28import java.util.List;
29import java.util.stream.Collectors;
Matteo Scandolo8abd7022021-06-11 15:03:46 +020030
31@Service
32public class OltUniPortCompleter extends PortNumberCompleter {
Matteo Scandolo8abd7022021-06-11 15:03:46 +020033
34 public OltUniPortCompleter() {
35 }
36
37 protected List<String> choices() {
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070038 DeviceService deviceService = DefaultServiceDirectory.getService(DeviceService.class);
Matteo Scandolo8abd7022021-06-11 15:03:46 +020039 DeviceId deviceId = this.lookForDeviceId();
40 if (deviceId == null) {
41 return Collections.emptyList();
42 } else {
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070043 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 Scandolo8abd7022021-06-11 15:03:46 +020050 }
51 }
52}