blob: 8c4bd45504afe4e56cf96834e9ff65d4f4d01623 [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
19import org.apache.karaf.shell.commands.Argument;
20import org.apache.karaf.shell.commands.Command;
21import org.apache.karaf.shell.commands.Option;
22import 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
28import static org.onlab.packet.EthType.EtherType;
29
30/**
31 * Starts a Static Packet Trace for a given input and prints the result.
32 */
33@Command(scope = "onos", name = "troubleshoot-simple",
34 description = "Given two hosts troubleshoots flows and groups between them, in case of segment routing")
35public class TroubleshootSimpleTraceCommand extends AbstractShellCommand {
36
37 // OSGi workaround to introduce package dependency
38 HostIdCompleter completer;
39 @Argument(index = 0, name = "one", description = "One host ID",
40 required = true, multiValued = false)
41 String srcHost = null;
42
43 @Argument(index = 1, name = "two", description = "Another host ID",
44 required = true, multiValued = false)
45 String dstHost = null;
46
47 @Option(name = "-v", aliases = "--verbose", description = "Outputs complete path")
48 private boolean verbosity1 = false;
49
50 @Option(name = "-vv", aliases = "--veryverbose", description = "Outputs flows and groups for every device")
51 private boolean verbosity2 = false;
52
53 @Option(name = "-et", aliases = "--ethType", description = "ETH Type", valueToShowInHelp = "ipv4")
54 String ethType = "ipv4";
55
56 @Override
57 protected void execute() {
58 TroubleshootService service = get(TroubleshootService.class);
59
60 EtherType type = EtherType.valueOf(ethType.toUpperCase());
61
62 //Printing the created packet
63 print("Tracing between: %s and %s", srcHost, dstHost);
64
65 //Build the trace
66 StaticPacketTrace trace = service.trace(HostId.hostId(srcHost), HostId.hostId(dstHost), type);
67 if (trace.getInitialPacket() != null) {
68 print("%s", T3CliUtils.printTrace(trace, verbosity1, verbosity2));
69 } else {
70 print("Cannot obtain trace between %s and %s", srcHost, dstHost);
71 print("Reason: %s", trace.resultMessage());
72 }
73
74
75 }
76}