blob: 5f90c1be71b14571e557109d45852d6c51b3c9ba [file] [log] [blame]
alshabib58fe6dc2015-08-19 17:16:13 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
alshabib58fe6dc2015-08-19 17:16:13 -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 */
16package org.onosproject.cli.net;
17
18import com.google.common.collect.Collections2;
19import org.apache.karaf.shell.commands.Argument;
20import org.apache.karaf.shell.commands.Command;
21import org.onosproject.cli.AbstractShellCommand;
22import org.onosproject.net.DeviceId;
23import org.onosproject.net.meter.Meter;
24import org.onosproject.net.meter.MeterService;
25
26import java.util.Collection;
27
28/**
29 * Add a meter.
30 */
31@Command(scope = "onos", name = "meters",
32 description = "Shows meters")
33public class Meters extends AbstractShellCommand {
34
35 @Argument(index = 0, name = "uri", description = "Device ID",
36 required = false, multiValued = false)
37 String uri = null;
38
39
40 @Override
41 protected void execute() {
42 MeterService service = get(MeterService.class);
43
44 Collection<Meter> meters = service.getAllMeters();
45 if (uri != null) {
46 DeviceId deviceId = DeviceId.deviceId(uri);
47 Collection<Meter> devMeters = Collections2.filter(meters,
48 m -> m.deviceId().equals(deviceId));
49 printMeters(devMeters);
50 } else {
51 printMeters(meters);
52 }
53 }
54
55 private void printMeters(Collection<Meter> meters) {
56 meters.forEach(m -> print(" %s", m));
57 }
58}