Sudhir Kumar Maurya | 4242cbe | 2019-01-17 16:36:50 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-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 | package org.onosproject.packetstats.cli; |
| 17 | |
| 18 | import com.codahale.metrics.Counter; |
| 19 | import com.codahale.metrics.MetricFilter; |
| 20 | import org.apache.karaf.shell.commands.Command; |
| 21 | import org.onosproject.cli.AbstractShellCommand; |
| 22 | import org.onlab.metrics.MetricsService; |
| 23 | import java.util.Map; |
| 24 | /** |
| 25 | * Displays the entries. |
| 26 | */ |
| 27 | @Command(scope = "onos", name = "pkt-stats-show", description = "Displays the packet statistics values") |
| 28 | public class PacketStatisticsShowCommand extends AbstractShellCommand { |
| 29 | |
| 30 | private static final String METRIC_NAME = null; |
| 31 | private static final String FORMAT = "PacketType = %s, Count = %s"; |
| 32 | private static final String FORMAT_LLDP = "Device = %s, Count = %s"; |
| 33 | MetricFilter filter = METRIC_NAME != null ? (name, metric) -> name.equals(METRIC_NAME) : MetricFilter.ALL; |
| 34 | |
| 35 | |
| 36 | @Override |
| 37 | protected void execute() { |
| 38 | MetricsService service = get(MetricsService.class); |
| 39 | Map<String, Counter> counters = service.getCounters(filter); |
| 40 | |
| 41 | Counter arpCounter = counters.get("packetStatisticsComponent.arpFeature.arpPC"); |
| 42 | Counter lldpCounter = counters.get("packetStatisticsComponent.lldpFeature.lldpPC"); |
| 43 | Counter nsCounter = counters.get("packetStatisticsComponent.nbrSolicitFeature.nbrSolicitPC"); |
| 44 | Counter naCounter = counters.get("packetStatisticsComponent.nbrAdvertFeature.nbrAdvertPC"); |
| 45 | |
| 46 | print(FORMAT, "ARP ", arpCounter.getCount()); |
| 47 | print(FORMAT, "LLDP ", lldpCounter.getCount()); |
| 48 | print(FORMAT, "Neighbor Solicitation ", nsCounter.getCount()); |
| 49 | print(FORMAT, "Neighbor Advertisement ", naCounter.getCount()); |
| 50 | |
| 51 | } |
| 52 | |
| 53 | } |