blob: d0bdad14e9f1ecab632981c47c6c8f4f1621379c [file] [log] [blame]
Kalhee Kimd94ceea2017-11-29 19:03:02 +00001/*
2 * Copyright 2017-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.onosproject.dhcprelay.cli;
18
Ray Milkey86ad7bb2018-09-27 12:32:28 -070019import org.apache.karaf.shell.api.action.Argument;
20import org.apache.karaf.shell.api.action.Command;
Ray Milkey58dd64e2018-10-03 11:30:46 -070021import org.apache.karaf.shell.api.action.Completion;
Ray Milkey7a2dee52018-09-28 10:58:28 -070022import org.apache.karaf.shell.api.action.lifecycle.Service;
Kalhee Kimd94ceea2017-11-29 19:03:02 +000023import org.onosproject.cli.AbstractShellCommand;
24import org.onosproject.dhcprelay.api.DhcpRelayService;
25import org.onosproject.dhcprelay.store.DhcpRelayCounters;
26import org.onosproject.dhcprelay.store.DhcpRelayCountersStore;
27
28
29import java.util.Map;
30import java.util.Optional;
31
32/**
33 * Prints Dhcp FPM Routes information.
34 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070035@Service
Kalhee Kimd94ceea2017-11-29 19:03:02 +000036@Command(scope = "onos", name = "dhcp-relay-agg-counters",
37 description = "DHCP Relay Aggregate Counters cli.")
38public class DhcpRelayAggCountersCommand extends AbstractShellCommand {
39 @Argument(index = 0, name = "reset",
40 description = "reset counters or not",
41 required = false, multiValued = false)
Ray Milkey58dd64e2018-10-03 11:30:46 -070042 @Completion(DhcpRelayResetCompleter.class)
Kalhee Kimd94ceea2017-11-29 19:03:02 +000043 String reset = null;
44
45 private static final String HEADER = "DHCP Relay Aggregate Counters :";
46 private static final String GCOUNT = "global";
47 private static final DhcpRelayService DHCP_RELAY_SERVICE = get(DhcpRelayService.class);
48
49 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070050 protected void doExecute() {
Kalhee Kimd94ceea2017-11-29 19:03:02 +000051 boolean toResetFlag;
52
53 if (reset != null) {
54 if (reset.equals("reset") || reset.equals("[reset]")) {
55 toResetFlag = true;
56 } else {
57 print("Last parameter is [reset]");
58 return;
59 }
60 } else {
61 toResetFlag = false;
62 }
63
64 print(HEADER);
65
66 DhcpRelayCountersStore counterStore = AbstractShellCommand.get(DhcpRelayCountersStore.class);
67
68 Optional<DhcpRelayCounters> perClassCounters = counterStore.getCounters(GCOUNT);
69
70 if (perClassCounters.isPresent()) {
71 Map<String, Integer> counters = perClassCounters.get().getCounters();
72 if (counters.size() > 0) {
73 counters.forEach((name, value) -> {
74 print("%-30s ............................ %-4d packets", name, value);
75 });
76 } else {
77 print("No counter for {}", GCOUNT);
78 }
79
80 if (toResetFlag) {
81 counterStore.resetCounters(GCOUNT);
82
83 }
84 }
85 }
86}