Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.opencord.olt.cli; |
| 18 | |
| 19 | import org.apache.karaf.shell.api.action.Command; |
| 20 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
| 21 | import org.onosproject.cli.AbstractShellCommand; |
| 22 | import org.onosproject.net.DeviceId; |
Gustavo Silva | 29fb20e | 2022-05-26 09:59:54 -0300 | [diff] [blame] | 23 | import org.opencord.olt.MeterData; |
| 24 | import org.opencord.olt.OltMeterServiceInterface; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 25 | |
| 26 | import java.util.Map; |
| 27 | /** |
| 28 | * Shows meters to bandwidth profile mappings. |
| 29 | */ |
| 30 | @Service |
| 31 | @Command(scope = "onos", name = "volt-bpmeter-mappings", |
| 32 | description = "Shows information about programmed meters, including the relation with the Bandwidth Profile") |
| 33 | public class ShowMeterMappings extends AbstractShellCommand { |
| 34 | |
| 35 | @Override |
| 36 | protected void doExecute() { |
| 37 | OltMeterServiceInterface service = AbstractShellCommand.get(OltMeterServiceInterface.class); |
| 38 | Map<DeviceId, Map<String, MeterData>> meters = service.getProgrammedMeters(); |
| 39 | if (meters.isEmpty()) { |
| 40 | print("No meters programmed by the olt app"); |
| 41 | } |
| 42 | meters.forEach(this::display); |
| 43 | } |
| 44 | |
| 45 | private void display(DeviceId deviceId, Map<String, MeterData> data) { |
| 46 | data.forEach((bp, md) -> |
| 47 | print("\tbpInfo=%s deviceId=%s meterId=%s", |
| 48 | deviceId, bp, md.getMeterId())); |
| 49 | |
| 50 | } |
| 51 | } |