blob: ff66b80381002adc19e3f09693a7927154b77999 [file] [log] [blame]
Thomas Vachuska7f171b22015-08-21 12:49:08 -07001/*
2 * Copyright 2015 Open Networking Laboratory
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 org.apache.karaf.shell.commands.Command;
19import org.onosproject.cli.AbstractShellCommand;
20import org.onosproject.net.packet.PacketProcessor;
21import org.onosproject.net.packet.PacketService;
22
23import static org.onosproject.net.packet.PacketProcessor.ADVISOR_MAX;
24import static org.onosproject.net.packet.PacketProcessor.DIRECTOR_MAX;
25
26/**
27 * Lists packet processors.
28 */
29@Command(scope = "onos", name = "packet-processors",
30 description = "Lists packet processors")
31public class PacketProcessorsListCommand extends AbstractShellCommand {
32
33 private static final String FMT = "priority=%s, class=%s";
34
35 @Override
36 protected void execute() {
37 PacketService service = get(PacketService.class);
38 if (outputJson()) {
39 // TODO: implement this
40 print("Not implemented.");
41 } else {
42 service.getProcessors().forEach(this::print);
43 }
44 }
45
46 private void print(int priority, PacketProcessor processor) {
47 print(FMT, priorityFormat(priority), processor.getClass().getName());
48 }
49
50 private String priorityFormat(int priority) {
51 if (priority > DIRECTOR_MAX) {
52 return "observer(" + (priority - DIRECTOR_MAX - 1) + ")";
53 } else if (priority > ADVISOR_MAX) {
54 return "director(" + (priority - ADVISOR_MAX - 1) + ")";
55 }
56 return "advisor(" + (priority - 1) + ")";
57 }
58
59}