blob: a32fcc3696ea2b49049489188a21f011d7f9b848 [file] [log] [blame]
Saurav Das82b8e6d2018-10-04 15:25:12 -07001/*
Matteo Scandoloaa2adde2021-09-13 12:45:32 -07002 * Copyright 2021-present Open Networking Foundation
Saurav Das82b8e6d2018-10-04 15:25:12 -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
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070019import org.apache.karaf.shell.api.action.Argument;
Carmelo Casconeca931162019-07-15 18:22:24 -070020import org.apache.karaf.shell.api.action.Command;
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070021import org.apache.karaf.shell.api.action.Completion;
Carmelo Casconeca931162019-07-15 18:22:24 -070022import org.apache.karaf.shell.api.action.lifecycle.Service;
Saurav Das82b8e6d2018-10-04 15:25:12 -070023import org.onosproject.cli.AbstractShellCommand;
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070024import 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;
Andrea Campanellacbbb7952019-11-25 06:38:41 +000029import org.opencord.sadis.UniTagInformation;
Saurav Das82b8e6d2018-10-04 15:25:12 -070030
Carmelo Casconeca931162019-07-15 18:22:24 -070031import java.util.Map;
Andrea Campanellacbbb7952019-11-25 06:38:41 +000032import java.util.Set;
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070033import java.util.stream.Collectors;
Carmelo Casconeca931162019-07-15 18:22:24 -070034
Saurav Das82b8e6d2018-10-04 15:25:12 -070035/**
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070036 * Shows programmed subscribers.
Saurav Das82b8e6d2018-10-04 15:25:12 -070037 */
Carmelo Casconeca931162019-07-15 18:22:24 -070038@Service
Saurav Das82b8e6d2018-10-04 15:25:12 -070039@Command(scope = "onos", name = "volt-programmed-subscribers",
40 description = "Shows subscribers programmed in the dataplane")
41public class ShowProgrammedSubscribersCommand extends AbstractShellCommand {
42
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070043 @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
Saurav Das82b8e6d2018-10-04 15:25:12 -070053 @Override
Carmelo Casconeca931162019-07-15 18:22:24 -070054 protected void doExecute() {
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070055 OltFlowServiceInterface service = AbstractShellCommand.get(OltFlowServiceInterface.class);
56 Map<ServiceKey, UniTagInformation> info = service.getProgrammedSubscribers();
57 Set<Map.Entry<ServiceKey, UniTagInformation>> 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()));
Saurav Das82b8e6d2018-10-04 15:25:12 -070070 }
71
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070072 private void display(ServiceKey sk, UniTagInformation uniTag) {
73 print("location=%s tagInformation=%s", sk.getPort().connectPoint(), uniTag);
Saurav Das82b8e6d2018-10-04 15:25:12 -070074 }
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070075}