Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 1 | /* |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 2 | * Copyright 2021-present Open Networking Foundation |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 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 | |
| 17 | package org.opencord.olt.cli; |
| 18 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 19 | import org.apache.karaf.shell.api.action.Argument; |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 20 | import org.apache.karaf.shell.api.action.Command; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 21 | import org.apache.karaf.shell.api.action.Completion; |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 22 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 23 | import org.onosproject.cli.AbstractShellCommand; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 24 | import org.onosproject.cli.net.DeviceIdCompleter; |
| 25 | import org.onosproject.net.DeviceId; |
| 26 | import org.onosproject.net.PortNumber; |
Gustavo Silva | 29fb20e | 2022-05-26 09:59:54 -0300 | [diff] [blame] | 27 | import org.opencord.olt.OltFlowServiceInterface; |
| 28 | import org.opencord.olt.ServiceKey; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 29 | import org.opencord.sadis.UniTagInformation; |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 30 | |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 31 | import java.util.Map; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 32 | import java.util.Set; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 33 | import java.util.stream.Collectors; |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 34 | |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 35 | /** |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 36 | * Shows programmed subscribers. |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 37 | */ |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 38 | @Service |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 39 | @Command(scope = "onos", name = "volt-programmed-subscribers", |
| 40 | description = "Shows subscribers programmed in the dataplane") |
| 41 | public class ShowProgrammedSubscribersCommand extends AbstractShellCommand { |
| 42 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 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 | |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 53 | @Override |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 54 | protected void doExecute() { |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 55 | 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 Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 72 | private void display(ServiceKey sk, UniTagInformation uniTag) { |
| 73 | print("location=%s tagInformation=%s", sk.getPort().connectPoint(), uniTag); |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 74 | } |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 75 | } |