From 81391595dca425ae58e2294898f09f11d9a32dbc Mon Sep 17 00:00:00 2001 From: Ashlee Young Date: Tue, 22 Sep 2015 12:49:09 -0700 Subject: bringing src to commit tag 65d551b50e782b0c1ea76c1a9ed1c5a801a5a7e4 Change-Id: Ib2da78962eaef856f418636c31b0f5c84286244f --- .../main/java/org/onosproject/cli/Comparators.java | 8 --- .../org/onosproject/cli/MetricNameCompleter.java | 2 +- .../onosproject/cli/cfg/NetworkConfigCommand.java | 12 +++-- .../org/onosproject/cli/net/AddMplsIntent.java | 15 ++++++ .../cli/net/LinkResourceTestCommand.java | 15 ++++++ .../cli/net/PacketProcessorsListCommand.java | 59 ++++++++++++++++++++++ .../cli/net/PacketRequestsListCommand.java | 47 +++++++++++++++++ 7 files changed, 146 insertions(+), 12 deletions(-) create mode 100644 framework/src/onos/cli/src/main/java/org/onosproject/cli/net/PacketProcessorsListCommand.java create mode 100644 framework/src/onos/cli/src/main/java/org/onosproject/cli/net/PacketRequestsListCommand.java (limited to 'framework/src/onos/cli/src/main/java') diff --git a/framework/src/onos/cli/src/main/java/org/onosproject/cli/Comparators.java b/framework/src/onos/cli/src/main/java/org/onosproject/cli/Comparators.java index 0ab6845f..b0cbbdd6 100644 --- a/framework/src/onos/cli/src/main/java/org/onosproject/cli/Comparators.java +++ b/framework/src/onos/cli/src/main/java/org/onosproject/cli/Comparators.java @@ -25,7 +25,6 @@ import org.onosproject.net.ElementId; import org.onosproject.net.Port; import org.onosproject.net.flow.FlowRule; import org.onosproject.net.group.Group; -import org.onosproject.net.host.PortAddresses; import org.onosproject.net.topology.TopologyCluster; import java.util.Comparator; @@ -113,13 +112,6 @@ public final class Comparators { } }; - public static final Comparator ADDRESSES_COMPARATOR = new Comparator() { - @Override - public int compare(PortAddresses arg0, PortAddresses arg1) { - return CONNECT_POINT_COMPARATOR.compare(arg0.connectPoint(), arg1.connectPoint()); - } - }; - public static final Comparator INTERFACES_COMPARATOR = (intf1, intf2) -> CONNECT_POINT_COMPARATOR.compare(intf1.connectPoint(), intf2.connectPoint()); diff --git a/framework/src/onos/cli/src/main/java/org/onosproject/cli/MetricNameCompleter.java b/framework/src/onos/cli/src/main/java/org/onosproject/cli/MetricNameCompleter.java index f05181f5..5ab15b08 100644 --- a/framework/src/onos/cli/src/main/java/org/onosproject/cli/MetricNameCompleter.java +++ b/framework/src/onos/cli/src/main/java/org/onosproject/cli/MetricNameCompleter.java @@ -28,7 +28,7 @@ public class MetricNameCompleter extends AbstractChoicesCompleter { @Override protected List choices() { MetricsService metricsService = AbstractShellCommand.get(MetricsService.class); - return new ArrayList(metricsService.getMetrics().keySet()); + return new ArrayList<>(metricsService.getMetrics().keySet()); } } diff --git a/framework/src/onos/cli/src/main/java/org/onosproject/cli/cfg/NetworkConfigCommand.java b/framework/src/onos/cli/src/main/java/org/onosproject/cli/cfg/NetworkConfigCommand.java index 5f2f86ee..d99a1839 100644 --- a/framework/src/onos/cli/src/main/java/org/onosproject/cli/cfg/NetworkConfigCommand.java +++ b/framework/src/onos/cli/src/main/java/org/onosproject/cli/cfg/NetworkConfigCommand.java @@ -15,6 +15,7 @@ */ package org.onosproject.cli.cfg; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; @@ -52,7 +53,7 @@ public class NetworkConfigCommand extends AbstractShellCommand { @Override protected void execute() { service = get(NetworkConfigService.class); - JsonNode root = new ObjectMapper().createObjectNode(); + JsonNode root = mapper.createObjectNode(); if (isNullOrEmpty(subjectKey)) { addAll((ObjectNode) root); } else { @@ -68,14 +69,19 @@ public class NetworkConfigCommand extends AbstractShellCommand { } } } - print("%s", root.toString()); + + try { + print("%s", mapper.writerWithDefaultPrettyPrinter().writeValueAsString(root)); + } catch (JsonProcessingException e) { + throw new RuntimeException("Error writing JSON to string", e); + } } @SuppressWarnings("unchecked") private void addAll(ObjectNode root) { service.getSubjectClasses() .forEach(sc -> { - SubjectFactory sf = service.getSubjectFactory((Class) sc); + SubjectFactory sf = service.getSubjectFactory(sc); addSubjectClass(newObject(root, sf.subjectKey()), sf); }); } diff --git a/framework/src/onos/cli/src/main/java/org/onosproject/cli/net/AddMplsIntent.java b/framework/src/onos/cli/src/main/java/org/onosproject/cli/net/AddMplsIntent.java index 1929b726..a736f99a 100644 --- a/framework/src/onos/cli/src/main/java/org/onosproject/cli/net/AddMplsIntent.java +++ b/framework/src/onos/cli/src/main/java/org/onosproject/cli/net/AddMplsIntent.java @@ -1,3 +1,18 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.onosproject.cli.net; import org.apache.karaf.shell.commands.Argument; diff --git a/framework/src/onos/cli/src/main/java/org/onosproject/cli/net/LinkResourceTestCommand.java b/framework/src/onos/cli/src/main/java/org/onosproject/cli/net/LinkResourceTestCommand.java index d68084c7..12e9ab5f 100644 --- a/framework/src/onos/cli/src/main/java/org/onosproject/cli/net/LinkResourceTestCommand.java +++ b/framework/src/onos/cli/src/main/java/org/onosproject/cli/net/LinkResourceTestCommand.java @@ -1,3 +1,18 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.onosproject.cli.net; import java.util.Set; diff --git a/framework/src/onos/cli/src/main/java/org/onosproject/cli/net/PacketProcessorsListCommand.java b/framework/src/onos/cli/src/main/java/org/onosproject/cli/net/PacketProcessorsListCommand.java new file mode 100644 index 00000000..ff66b803 --- /dev/null +++ b/framework/src/onos/cli/src/main/java/org/onosproject/cli/net/PacketProcessorsListCommand.java @@ -0,0 +1,59 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.cli.net; + +import org.apache.karaf.shell.commands.Command; +import org.onosproject.cli.AbstractShellCommand; +import org.onosproject.net.packet.PacketProcessor; +import org.onosproject.net.packet.PacketService; + +import static org.onosproject.net.packet.PacketProcessor.ADVISOR_MAX; +import static org.onosproject.net.packet.PacketProcessor.DIRECTOR_MAX; + +/** + * Lists packet processors. + */ +@Command(scope = "onos", name = "packet-processors", + description = "Lists packet processors") +public class PacketProcessorsListCommand extends AbstractShellCommand { + + private static final String FMT = "priority=%s, class=%s"; + + @Override + protected void execute() { + PacketService service = get(PacketService.class); + if (outputJson()) { + // TODO: implement this + print("Not implemented."); + } else { + service.getProcessors().forEach(this::print); + } + } + + private void print(int priority, PacketProcessor processor) { + print(FMT, priorityFormat(priority), processor.getClass().getName()); + } + + private String priorityFormat(int priority) { + if (priority > DIRECTOR_MAX) { + return "observer(" + (priority - DIRECTOR_MAX - 1) + ")"; + } else if (priority > ADVISOR_MAX) { + return "director(" + (priority - ADVISOR_MAX - 1) + ")"; + } + return "advisor(" + (priority - 1) + ")"; + } + +} diff --git a/framework/src/onos/cli/src/main/java/org/onosproject/cli/net/PacketRequestsListCommand.java b/framework/src/onos/cli/src/main/java/org/onosproject/cli/net/PacketRequestsListCommand.java new file mode 100644 index 00000000..9bdeadb3 --- /dev/null +++ b/framework/src/onos/cli/src/main/java/org/onosproject/cli/net/PacketRequestsListCommand.java @@ -0,0 +1,47 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.cli.net; + +import org.apache.karaf.shell.commands.Command; +import org.onosproject.cli.AbstractShellCommand; +import org.onosproject.net.packet.PacketRequest; +import org.onosproject.net.packet.PacketService; + +/** + * Lists packet requests. + */ +@Command(scope = "onos", name = "packet-requests", + description = "Lists packet requests") +public class PacketRequestsListCommand extends AbstractShellCommand { + + private static final String FMT = "priority=%s, appId=%s, criteria=%s"; + + @Override + protected void execute() { + PacketService service = get(PacketService.class); + if (outputJson()) { + // TODO: implement this + print("Not implemented."); + } else { + service.getRequests().forEach(this::print); + } + } + + private void print(PacketRequest request) { + print(FMT, request.priority(), request.appId().name(), request.selector().criteria()); + } + +} -- cgit 1.2.3-korg