blob: 9e44bd4f76c8995811fc69af098259c3b8ac9daf [file] [log] [blame]
Sudhir Kumar Maurya2cc77982018-12-14 06:41:33 -05001/*
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 */
16package org.onosproject.packetstats.cli;
17
18import com.codahale.metrics.Counter;
19import com.codahale.metrics.MetricFilter;
20import org.apache.karaf.shell.api.action.Command;
21import org.onosproject.cli.AbstractShellCommand;
22import org.onlab.metrics.MetricsService;
23import java.util.Map;
24/**
25 * Displays the entries.
26 */
27@Command(scope = "onos", name = "pkt-stats-show", description = "Displays the packet statistics values")
28public 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 doExecute() {
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}