blob: 3bfa2079fe76a38f821f308466c3066e71806eb2 [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.cli.net.PortNumberCompleter;
26import org.onosproject.net.DeviceId;
27import org.onosproject.net.PortNumber;
Gustavo Silva29fb20e2022-05-26 09:59:54 -030028import org.opencord.olt.OltFlowServiceInterface;
29import org.opencord.olt.OltPortStatus;
30import org.opencord.olt.ServiceKey;
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070031import org.opencord.sadis.UniTagInformation;
32
33import java.util.HashMap;
34import java.util.Map;
35
36/**
37 * Shows ports' status of an OLT.
38 */
39@Service
40@Command(scope = "onos", name = "volt-port-status",
41 description = "Shows information about the OLT ports (default EAPOL, subscriber flows)")
42public class ShowPortStatus extends AbstractShellCommand {
43
44 @Argument(index = 0, name = "deviceId", description = "Access device ID",
45 required = false, multiValued = false)
46 @Completion(DeviceIdCompleter.class)
47 private String strDeviceId = null;
48
49 @Argument(index = 1, name = "port", description = "Subscriber port number",
50 required = false, multiValued = false)
51 @Completion(PortNumberCompleter.class)
52 private String strPort = null;
53
54 @Override
55 protected void doExecute() {
56
57 OltFlowServiceInterface service = AbstractShellCommand.get(OltFlowServiceInterface.class);
58 Map<ServiceKey, OltPortStatus> connectPointStatus = service.getConnectPointStatus();
59 if (connectPointStatus.isEmpty()) {
60 print("No ports handled by the olt app");
61 return;
62 }
63
64 Map<DeviceId, Map<PortNumber, Map<UniTagInformation, OltPortStatus>>> sortedStatus = new HashMap<>();
65
66 DeviceId deviceId = strDeviceId != null ? DeviceId.deviceId(strDeviceId) : null;
67 PortNumber portNumber = strPort != null ? PortNumber.portNumber(strPort) : null;
68
69 connectPointStatus.forEach((sk, fs) -> {
70 if (deviceId != null && !deviceId.equals(sk.getPort().connectPoint()
71 .deviceId())) {
72 return;
73 }
74 if (portNumber != null && !portNumber.equals(sk.getPort().connectPoint().port())) {
75 return;
76 }
77 sortedStatus.compute(sk.getPort().connectPoint().deviceId(), (id, portMap) -> {
78 if (portMap == null) {
79 portMap = new HashMap<>();
80 }
81 portMap.compute(sk.getPort().connectPoint().port(), (id2, ps) -> {
82 if (ps == null) {
83 ps = new HashMap<>();
84 }
85 ps.put(sk.getService(), fs);
86 return ps;
87 });
88
89 return portMap;
90 });
91 });
92
93 sortedStatus.forEach(this::display);
94 }
95
96 private void display(DeviceId deviceId, Map<PortNumber, Map<UniTagInformation, OltPortStatus>> ports) {
97 print("deviceId=%s, managedPorts=%d", deviceId, ports.size());
98
99 ports.forEach((port, subscribers) -> {
100 print("\tport=%s", port);
101 subscribers.forEach((uti, status) -> {
102 print("\t\tservice=%s defaultEapolStatus=%s subscriberFlowsStatus=%s dhcpStatus=%s",
103 uti.getServiceName(), status.defaultEapolStatus,
104 status.subscriberFlowsStatus, status.dhcpStatus);
105 });
106 });
107 }
108}