blob: a7c5c369b52b0f50228fe26c984010287a141eeb [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;
21import org.apache.karaf.shell.api.action.Option;
Andrea Campanellaaf34b7c2018-02-08 17:10:11 +010022import org.onosproject.cli.AbstractShellCommand;
23import org.onosproject.cli.net.HostIdCompleter;
24import org.onosproject.net.HostId;
25import org.onosproject.t3.api.StaticPacketTrace;
26import org.onosproject.t3.api.TroubleshootService;
27
Andrea Campanella79cb17d2018-02-27 18:03:17 +010028import java.util.Set;
29
Andrea Campanellaaf34b7c2018-02-08 17:10:11 +010030import static org.onlab.packet.EthType.EtherType;
31
32/**
33 * Starts a Static Packet Trace for a given input and prints the result.
34 */
Andrea Campanella36769e22018-02-26 11:03:48 +010035@Command(scope = "onos", name = "t3-troubleshoot-simple",
Andrea Campanellaaf34b7c2018-02-08 17:10:11 +010036 description = "Given two hosts troubleshoots flows and groups between them, in case of segment routing")
37public class TroubleshootSimpleTraceCommand extends AbstractShellCommand {
38
39 // OSGi workaround to introduce package dependency
40 HostIdCompleter completer;
41 @Argument(index = 0, name = "one", description = "One host ID",
42 required = true, multiValued = false)
43 String srcHost = null;
44
45 @Argument(index = 1, name = "two", description = "Another host ID",
46 required = true, multiValued = false)
47 String dstHost = null;
48
49 @Option(name = "-v", aliases = "--verbose", description = "Outputs complete path")
50 private boolean verbosity1 = false;
51
52 @Option(name = "-vv", aliases = "--veryverbose", description = "Outputs flows and groups for every device")
53 private boolean verbosity2 = false;
54
55 @Option(name = "-et", aliases = "--ethType", description = "ETH Type", valueToShowInHelp = "ipv4")
56 String ethType = "ipv4";
57
58 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070059 protected void doExecute() {
Andrea Campanellaaf34b7c2018-02-08 17:10:11 +010060 TroubleshootService service = get(TroubleshootService.class);
61
62 EtherType type = EtherType.valueOf(ethType.toUpperCase());
63
Andrea Campanella6be5c872018-02-21 14:28:20 +010064 //Printing the traced hosts
Andrea Campanellaaf34b7c2018-02-08 17:10:11 +010065 print("Tracing between: %s and %s", srcHost, dstHost);
66
Andrea Campanella79cb17d2018-02-27 18:03:17 +010067 //Build the traces
68 Set<StaticPacketTrace> traces = service.trace(HostId.hostId(srcHost), HostId.hostId(dstHost), type);
69 traces.forEach(trace -> {
70 if (trace.getInitialPacket() != null) {
71 print("Tracing Packet: %s", trace.getInitialPacket());
72 print("%s", T3CliUtils.printTrace(trace, verbosity1, verbosity2));
73 } else {
74 print("Cannot obtain trace between %s and %s", srcHost, dstHost);
75 print("Reason: %s", trace.resultMessage());
76 }
77 });
Andrea Campanellaaf34b7c2018-02-08 17:10:11 +010078
79
80 }
81}