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