blob: 68ceca65fd1e4992999ab48e578309c4b3ac0ae4 [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;
22import org.onosproject.net.AnnotationKeys;
23import org.onosproject.net.DeviceId;
24import org.onosproject.net.device.DeviceService;
25import java.util.Collections;
26import java.util.List;
27import java.util.stream.Collectors;
28import java.util.stream.StreamSupport;
29
30@Service
31public class OltUniPortCompleter extends PortNumberCompleter {
32 private static final String NNI = "nni-";
33
34 public OltUniPortCompleter() {
35 }
36
37 protected List<String> choices() {
38 DeviceId deviceId = this.lookForDeviceId();
39 if (deviceId == null) {
40 return Collections.emptyList();
41 } else {
42 DeviceService deviceService = (DeviceService) DefaultServiceDirectory.getService(DeviceService.class);
43 return (List) StreamSupport.stream(deviceService.getPorts(deviceId).spliterator(), false)
44 .filter((port) -> {
45 return port.isEnabled() && !port.annotations().value(AnnotationKeys.PORT_NAME).startsWith(NNI);
46 })
47 .map((port) -> {
48 return port.number().toString();
49 }).collect(Collectors.toList());
50 }
51 }
52}