blob: 7a5ecc7d94fb9a0629013a3ec8acc1a5ac904055 [file] [log] [blame]
Andrea Campanellaaf34b7c2018-02-08 17:10:11 +01001/*
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 */
16
17package org.onosproject.t3.cli;
18
Ray Milkey86ad7bb2018-09-27 12:32:28 -070019import org.apache.karaf.shell.api.action.Argument;
20import org.apache.karaf.shell.api.action.Command;
Ray Milkeyebe0ec62018-10-10 14:32:38 -070021import org.apache.karaf.shell.api.action.Completion;
Ray Milkey86ad7bb2018-09-27 12:32:28 -070022import org.apache.karaf.shell.api.action.Option;
Ray Milkey7a2dee52018-09-28 10:58:28 -070023import org.apache.karaf.shell.api.action.lifecycle.Service;
Andrea Campanellaaf34b7c2018-02-08 17:10:11 +010024import org.onosproject.cli.AbstractShellCommand;
Seyeon Jeong357bcec2020-02-28 01:17:34 -080025import org.onosproject.cli.PlaceholderCompleter;
Ray Milkeyebe0ec62018-10-10 14:32:38 -070026import org.onosproject.cli.net.EthTypeCompleter;
Andrea Campanellaaf34b7c2018-02-08 17:10:11 +010027import org.onosproject.cli.net.HostIdCompleter;
28import org.onosproject.net.HostId;
29import org.onosproject.t3.api.StaticPacketTrace;
30import org.onosproject.t3.api.TroubleshootService;
31
Andrea Campanella79cb17d2018-02-27 18:03:17 +010032import java.util.Set;
33
Andrea Campanellaaf34b7c2018-02-08 17:10:11 +010034import static org.onlab.packet.EthType.EtherType;
35
36/**
37 * Starts a Static Packet Trace for a given input and prints the result.
38 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070039@Service
Andrea Campanella36769e22018-02-26 11:03:48 +010040@Command(scope = "onos", name = "t3-troubleshoot-simple",
Andrea Campanellaaf34b7c2018-02-08 17:10:11 +010041 description = "Given two hosts troubleshoots flows and groups between them, in case of segment routing")
42public class TroubleshootSimpleTraceCommand extends AbstractShellCommand {
43
44 // OSGi workaround to introduce package dependency
45 HostIdCompleter completer;
46 @Argument(index = 0, name = "one", description = "One host ID",
47 required = true, multiValued = false)
Ray Milkeyebe0ec62018-10-10 14:32:38 -070048 @Completion(HostIdCompleter.class)
Andrea Campanellaaf34b7c2018-02-08 17:10:11 +010049 String srcHost = null;
50
51 @Argument(index = 1, name = "two", description = "Another host ID",
52 required = true, multiValued = false)
Ray Milkeyebe0ec62018-10-10 14:32:38 -070053 @Completion(HostIdCompleter.class)
Andrea Campanellaaf34b7c2018-02-08 17:10:11 +010054 String dstHost = null;
55
56 @Option(name = "-v", aliases = "--verbose", description = "Outputs complete path")
Seyeon Jeong357bcec2020-02-28 01:17:34 -080057 @Completion(PlaceholderCompleter.class)
Andrea Campanellaaf34b7c2018-02-08 17:10:11 +010058 private boolean verbosity1 = false;
59
60 @Option(name = "-vv", aliases = "--veryverbose", description = "Outputs flows and groups for every device")
Seyeon Jeong357bcec2020-02-28 01:17:34 -080061 @Completion(PlaceholderCompleter.class)
Andrea Campanellaaf34b7c2018-02-08 17:10:11 +010062 private boolean verbosity2 = false;
63
64 @Option(name = "-et", aliases = "--ethType", description = "ETH Type", valueToShowInHelp = "ipv4")
Ray Milkeyebe0ec62018-10-10 14:32:38 -070065 @Completion(EthTypeCompleter.class)
Andrea Campanellaaf34b7c2018-02-08 17:10:11 +010066 String ethType = "ipv4";
67
68 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070069 protected void doExecute() {
Andrea Campanellaaf34b7c2018-02-08 17:10:11 +010070 TroubleshootService service = get(TroubleshootService.class);
Seyeon Jeong357bcec2020-02-28 01:17:34 -080071 if (service.checkNibsUnavailable()) {
72 print(TroubleshootLoadFileCommand.ERROR_NULL);
73 return;
74 }
75 if (srcHost.equals(dstHost)) {
76 print("Source and destination are same. Use different hosts");
77 return;
78 }
Andrea Campanellaaf34b7c2018-02-08 17:10:11 +010079
80 EtherType type = EtherType.valueOf(ethType.toUpperCase());
81
Andrea Campanella6be5c872018-02-21 14:28:20 +010082 //Printing the traced hosts
Andrea Campanellaaf34b7c2018-02-08 17:10:11 +010083 print("Tracing between: %s and %s", srcHost, dstHost);
84
Andrea Campanella79cb17d2018-02-27 18:03:17 +010085 //Build the traces
86 Set<StaticPacketTrace> traces = service.trace(HostId.hostId(srcHost), HostId.hostId(dstHost), type);
87 traces.forEach(trace -> {
88 if (trace.getInitialPacket() != null) {
89 print("Tracing Packet: %s", trace.getInitialPacket());
90 print("%s", T3CliUtils.printTrace(trace, verbosity1, verbosity2));
91 } else {
92 print("Cannot obtain trace between %s and %s", srcHost, dstHost);
93 print("Reason: %s", trace.resultMessage());
94 }
95 });
Andrea Campanellaaf34b7c2018-02-08 17:10:11 +010096
97
98 }
99}