blob: 7b189134a733c3bfba4838862803bfe5515613db [file] [log] [blame]
Andrea Campanella55c3f422018-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 Milkey822567d2018-09-27 12:32:28 -070019import org.apache.karaf.shell.api.action.Argument;
20import org.apache.karaf.shell.api.action.Command;
Ray Milkeyba9c4f52018-10-10 14:32:38 -070021import org.apache.karaf.shell.api.action.Completion;
Ray Milkey822567d2018-09-27 12:32:28 -070022import org.apache.karaf.shell.api.action.Option;
Ray Milkeyac725032018-09-28 10:58:28 -070023import org.apache.karaf.shell.api.action.lifecycle.Service;
Andrea Campanella55c3f422018-02-08 17:10:11 +010024import org.onosproject.cli.AbstractShellCommand;
Ray Milkeyba9c4f52018-10-10 14:32:38 -070025import org.onosproject.cli.net.EthTypeCompleter;
Andrea Campanella55c3f422018-02-08 17:10:11 +010026import org.onosproject.cli.net.HostIdCompleter;
27import org.onosproject.net.HostId;
28import org.onosproject.t3.api.StaticPacketTrace;
29import org.onosproject.t3.api.TroubleshootService;
30
Andrea Campanella696ef032018-02-27 18:03:17 +010031import java.util.Set;
32
Andrea Campanella55c3f422018-02-08 17:10:11 +010033import static org.onlab.packet.EthType.EtherType;
34
35/**
36 * Starts a Static Packet Trace for a given input and prints the result.
37 */
Ray Milkeyac725032018-09-28 10:58:28 -070038@Service
Andrea Campanellad756ede2018-02-26 11:03:48 +010039@Command(scope = "onos", name = "t3-troubleshoot-simple",
Andrea Campanella55c3f422018-02-08 17:10:11 +010040 description = "Given two hosts troubleshoots flows and groups between them, in case of segment routing")
41public class TroubleshootSimpleTraceCommand extends AbstractShellCommand {
42
43 // OSGi workaround to introduce package dependency
44 HostIdCompleter completer;
45 @Argument(index = 0, name = "one", description = "One host ID",
46 required = true, multiValued = false)
Ray Milkeyba9c4f52018-10-10 14:32:38 -070047 @Completion(HostIdCompleter.class)
Andrea Campanella55c3f422018-02-08 17:10:11 +010048 String srcHost = null;
49
50 @Argument(index = 1, name = "two", description = "Another host ID",
51 required = true, multiValued = false)
Ray Milkeyba9c4f52018-10-10 14:32:38 -070052 @Completion(HostIdCompleter.class)
Andrea Campanella55c3f422018-02-08 17:10:11 +010053 String dstHost = null;
54
55 @Option(name = "-v", aliases = "--verbose", description = "Outputs complete path")
56 private boolean verbosity1 = false;
57
58 @Option(name = "-vv", aliases = "--veryverbose", description = "Outputs flows and groups for every device")
59 private boolean verbosity2 = false;
60
61 @Option(name = "-et", aliases = "--ethType", description = "ETH Type", valueToShowInHelp = "ipv4")
Ray Milkeyba9c4f52018-10-10 14:32:38 -070062 @Completion(EthTypeCompleter.class)
Andrea Campanella55c3f422018-02-08 17:10:11 +010063 String ethType = "ipv4";
64
65 @Override
Ray Milkey822567d2018-09-27 12:32:28 -070066 protected void doExecute() {
Andrea Campanella55c3f422018-02-08 17:10:11 +010067 TroubleshootService service = get(TroubleshootService.class);
68
69 EtherType type = EtherType.valueOf(ethType.toUpperCase());
70
Andrea Campanella6a614fa2018-02-21 14:28:20 +010071 //Printing the traced hosts
Andrea Campanella55c3f422018-02-08 17:10:11 +010072 print("Tracing between: %s and %s", srcHost, dstHost);
73
Andrea Campanella696ef032018-02-27 18:03:17 +010074 //Build the traces
75 Set<StaticPacketTrace> traces = service.trace(HostId.hostId(srcHost), HostId.hostId(dstHost), type);
76 traces.forEach(trace -> {
77 if (trace.getInitialPacket() != null) {
78 print("Tracing Packet: %s", trace.getInitialPacket());
79 print("%s", T3CliUtils.printTrace(trace, verbosity1, verbosity2));
80 } else {
81 print("Cannot obtain trace between %s and %s", srcHost, dstHost);
82 print("Reason: %s", trace.resultMessage());
83 }
84 });
Andrea Campanella55c3f422018-02-08 17:10:11 +010085
86
87 }
88}