blob: 46f6122c195395f72c41fb6e8dd482ffbf6d829f [file] [log] [blame]
Charles Chan33f4a912018-04-19 23:35:30 -07001/*
2 * Copyright 2018-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.cli.net;
17
18import com.google.common.collect.ListMultimap;
19import org.apache.karaf.shell.commands.Command;
20import org.apache.karaf.shell.commands.Option;
21import org.onlab.osgi.ServiceNotFoundException;
22import org.onosproject.cli.AbstractShellCommand;
23import org.onosproject.net.flowobjective.FilteringObjQueueKey;
24import org.onosproject.net.flowobjective.FlowObjectiveService;
25import org.onosproject.net.flowobjective.ForwardingObjQueueKey;
26import org.onosproject.net.flowobjective.NextObjQueueKey;
27import org.onosproject.net.flowobjective.Objective;
28
29import java.util.Map;
30
31/**
32 * Displays flow objective that are waiting for the completion of previous objective with the same key.
33 */
34@Command(scope = "onos", name = "obj-queues",
35 description = "Display flow objective queues")
36public class FlowObjectiveQueueListCommand extends AbstractShellCommand {
37
38 @Option(name = "-s", aliases = "--size",
39 description = "Print queue size only",
40 required = false, multiValued = false)
41 private boolean sizeOnly = false;
42
43 @Option(name = "-c", aliases = "--cache",
44 description = "Print cache",
45 required = false, multiValued = false)
46 private boolean cache = false;
47
48 @Override
49 protected void execute() {
50 try {
51 FlowObjectiveService service = get(FlowObjectiveService.class);
52 ListMultimap<FilteringObjQueueKey, Objective> filtObjQueue = service.getFilteringObjQueue();
53 ListMultimap<ForwardingObjQueueKey, Objective> fwdObjQueue = service.getForwardingObjQueue();
54 ListMultimap<NextObjQueueKey, Objective> nextObjQueue = service.getNextObjQueue();
55 Map<FilteringObjQueueKey, Objective> filtObjQueueHead = service.getFilteringObjQueueHead();
56 Map<ForwardingObjQueueKey, Objective> fwdObjQueueHead = service.getForwardingObjQueueHead();
57 Map<NextObjQueueKey, Objective> nextObjQueueHead = service.getNextObjQueueHead();
58
59 if (cache) {
60 printMap("Filtering objective cache", filtObjQueueHead, sizeOnly);
61 printMap("Forwarding objective cache", fwdObjQueueHead, sizeOnly);
62 printMap("Next objective cache", nextObjQueueHead, sizeOnly);
63 } else {
64 printMap("Filtering objective queue", filtObjQueue.asMap(), sizeOnly);
65 printMap("Forwarding objective queue", fwdObjQueue.asMap(), sizeOnly);
66 printMap("Next objective queue", nextObjQueue.asMap(), sizeOnly);
67 }
68 } catch (ServiceNotFoundException e) {
69 print("FlowObjectiveService unavailable");
70 }
71 }
72
73 @SuppressWarnings("unchecked")
74 private void printMap(String mapName, Map map, boolean sizeOnly) {
75 print("%s size = %d", mapName, map.size());
76 if (!sizeOnly) {
77 map.forEach((k, v) -> print("%s -> %s", k, v));
78 }
79 }
80}