blob: b59fe0bc68d064045941d90dd74d86080a7b4e03 [file] [log] [blame]
Matteo Scandoloaa2adde2021-09-13 12:45:32 -07001/*
Joey Armstrong7f6d6d22023-01-09 17:09:50 -05002 * Copyright 2021-2023 Open Networking Foundation (ONF) and the ONF Contributors
Matteo Scandoloaa2adde2021-09-13 12:45:32 -07003 *
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.Argument;
20import org.apache.karaf.shell.api.action.Command;
21import org.apache.karaf.shell.api.action.Completion;
22import org.apache.karaf.shell.api.action.lifecycle.Service;
23import org.onosproject.cli.AbstractShellCommand;
24import org.onosproject.cli.net.DeviceIdCompleter;
25import org.onosproject.net.DeviceId;
26import org.onosproject.net.PortNumber;
Gustavo Silva29fb20e2022-05-26 09:59:54 -030027import org.opencord.olt.OltFlowServiceInterface;
28import org.opencord.olt.ServiceKey;
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070029
30import java.util.Map;
31import java.util.Set;
32import java.util.stream.Collectors;
33
34/**
35 * Shows requested subscribers.
36 */
37@Service
38@Command(scope = "onos", name = "volt-requested-subscribers",
39 description = "Shows subscribers programmed by the operator. " +
40 "Their data-plane status depends on the ONU status.")
41public class ShowRequestedSubscribersCommand extends AbstractShellCommand {
42
43 @Argument(index = 0, name = "deviceId", description = "Access device ID",
44 required = false, multiValued = false)
45 @Completion(DeviceIdCompleter.class)
46 private String strDeviceId = null;
47
48 @Argument(index = 1, name = "port", description = "Subscriber port number",
49 required = false, multiValued = false)
50 @Completion(OltUniPortCompleter.class)
51 private String strPort = null;
52
53 @Override
54 protected void doExecute() {
55 OltFlowServiceInterface service = AbstractShellCommand.get(OltFlowServiceInterface.class);
56 Map<ServiceKey, Boolean> info = service.getRequestedSubscribers();
57 Set<Map.Entry<ServiceKey, Boolean>> entries = info.entrySet();
58 if (strDeviceId != null && !strDeviceId.isEmpty()) {
59 entries = entries.stream().filter(entry -> entry.getKey().getPort().connectPoint().deviceId()
60 .equals(DeviceId.deviceId(strDeviceId))).collect(Collectors.toSet());
61 }
62
63 if (strPort != null && !strPort.isEmpty()) {
64 PortNumber portNumber = PortNumber.portNumber(strPort);
65 entries = entries.stream().filter(entry -> entry.getKey().getPort().connectPoint().port()
66 .equals(portNumber)).collect(Collectors.toSet());
67 }
68
69 entries.forEach(entry -> display(entry.getKey(), entry.getValue()));
70 }
71
72 private void display(ServiceKey sk, Boolean status) {
73 print("location=%s service=%s provisioned=%s", sk.getPort(), sk.getService().getServiceName(), status);
74 }
75}