[CORD-2755] PingAll scenario for Ipv4 and Ipv6 hosts
Change-Id: I8d57568a94580807e62fb5953a881850a73f43ed
(cherry picked from commit fb68135647218cf0ee7142573bdaf5ca271e29a3)
diff --git a/src/main/java/org/onosproject/t3/cli/TroubleshootPingAllTraceCommand.java b/src/main/java/org/onosproject/t3/cli/TroubleshootPingAllTraceCommand.java
new file mode 100644
index 0000000..8cecc8d
--- /dev/null
+++ b/src/main/java/org/onosproject/t3/cli/TroubleshootPingAllTraceCommand.java
@@ -0,0 +1,110 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * 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.t3.cli;
+
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.commands.Option;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.net.Host;
+import org.onosproject.t3.api.StaticPacketTrace;
+import org.onosproject.t3.api.TroubleshootService;
+
+import java.util.List;
+
+import static org.onlab.packet.EthType.EtherType;
+
+/**
+ * Starts a Static Packet Trace for a given input and prints the result.
+ */
+@Command(scope = "onos", name = "t3-troubleshoot-pingall",
+ description = "Traces a ping between all hosts in the system of a given ETH type")
+public class TroubleshootPingAllTraceCommand extends AbstractShellCommand {
+
+ private static final String FMT_SHORT =
+ "id=%s, mac=%s, locations=%s, vlan=%s, ip(s)=%s";
+
+ @Option(name = "-et", aliases = "--ethType", description = "ETH Type", valueToShowInHelp = "ipv4")
+ String ethType = "ipv4";
+
+ @Option(name = "-v", aliases = "--verbose", description = "Outputs trace for each host to host combination")
+ private boolean verbosity1 = false;
+
+ @Override
+ protected void execute() {
+ TroubleshootService service = get(TroubleshootService.class);
+
+ EtherType type = EtherType.valueOf(ethType.toUpperCase());
+
+ print("Tracing between all %s hosts", ethType);
+
+ if (!type.equals(EtherType.IPV4) && !type.equals(EtherType.IPV6)) {
+ print("Command only support IPv4 or IPv6");
+ } else {
+ print("--------------------------------------------------------------------------");
+ //Obtain the list of traces
+ List<StaticPacketTrace> traces = service.pingAll(type);
+
+ if (traces.size() == 0) {
+ print("No traces were obtained, please check system configuration");
+ }
+
+ traces.forEach(trace -> {
+ if (trace.getInitialPacket() != null) {
+ if (verbosity1) {
+ printVerbose(trace);
+ } else {
+ printResultOnly(trace);
+ }
+ } else {
+ print("Error in obtaining trace: %s", trace.resultMessage());
+ }
+ print("--------------------------------------------------------------------------");
+ });
+ }
+
+
+ }
+
+ private void printResultOnly(StaticPacketTrace trace) {
+ if (trace.getEndpointHosts().isPresent()) {
+ Host source = trace.getEndpointHosts().get().getLeft();
+ Host destination = trace.getEndpointHosts().get().getRight();
+ print("Source %s --> Destination %s", source.id(), destination.id());
+ print("%s", trace.resultMessage());
+ } else {
+ print("Can't gather host information from trace");
+ print("%s", trace.resultMessage());
+ }
+ }
+
+ private void printVerbose(StaticPacketTrace trace) {
+ if (trace.getEndpointHosts().isPresent()) {
+ Host source = trace.getEndpointHosts().get().getLeft();
+ print("Source host %s", printHost(source));
+ Host destination = trace.getEndpointHosts().get().getRight();
+ print("Destination host %s", printHost(destination));
+ }
+ print("%s", trace.getInitialPacket());
+ print("%s", T3CliUtils.printTrace(trace, false, false));
+ }
+
+ private String printHost(Host host) {
+ return String.format(FMT_SHORT, host.id(), host.mac(),
+ host.locations(),
+ host.vlan(), host.ipAddresses());
+ }
+}
diff --git a/src/main/java/org/onosproject/t3/cli/TroubleshootSimpleTraceCommand.java b/src/main/java/org/onosproject/t3/cli/TroubleshootSimpleTraceCommand.java
index 997ef42..3674e32 100644
--- a/src/main/java/org/onosproject/t3/cli/TroubleshootSimpleTraceCommand.java
+++ b/src/main/java/org/onosproject/t3/cli/TroubleshootSimpleTraceCommand.java
@@ -59,7 +59,7 @@
EtherType type = EtherType.valueOf(ethType.toUpperCase());
- //Printing the created packet
+ //Printing the traced hosts
print("Tracing between: %s and %s", srcHost, dstHost);
//Build the trace