blob: da2307e4abf2091fc0493983035d7be189b9c9b2 [file] [log] [blame]
Matteo Scandoloaa2adde2021-09-13 12:45:32 -07001/*
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
17package org.opencord.olt.cli;
18
19import org.apache.karaf.shell.api.action.Command;
20import org.apache.karaf.shell.api.action.lifecycle.Service;
21import org.onosproject.cli.AbstractShellCommand;
22import org.onosproject.net.DeviceId;
23import org.opencord.olt.impl.MeterData;
24import org.opencord.olt.impl.OltMeterServiceInterface;
25
26import java.util.Map;
27/**
28 * Displays the programmed meters through the OLT app.
29 */
30@Service
31@Command(scope = "onos", name = "volt-programmed-meters",
32 description = "Shows information about programmed meters, including the relation with the Bandwidth Profile")
33public class ShowProgrammedMeters 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 return;
42 }
43 meters.forEach(this::display);
44 }
45
46 private void display(DeviceId deviceId, Map<String, MeterData> data) {
47 print("deviceId=%s, meterCount=%d", deviceId, data.size());
48 data.forEach((bp, md) ->
49 print("\tmeterId=%s bandwidthProfile=%s status=%s",
50 md.getMeterId(), bp, md.getMeterStatus()));
51
52 }
53}