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