Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.t3.cli; |
| 18 | |
Ray Milkey | 822567d | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 19 | import org.apache.karaf.shell.api.action.Argument; |
| 20 | import org.apache.karaf.shell.api.action.Command; |
Ray Milkey | ba9c4f5 | 2018-10-10 14:32:38 -0700 | [diff] [blame] | 21 | import org.apache.karaf.shell.api.action.Completion; |
Ray Milkey | 822567d | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 22 | import org.apache.karaf.shell.api.action.Option; |
Ray Milkey | ac72503 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 23 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 24 | import org.onosproject.cli.AbstractShellCommand; |
Seyeon Jeong | 83e7986 | 2020-02-28 01:17:34 -0800 | [diff] [blame^] | 25 | import org.onosproject.cli.PlaceholderCompleter; |
Ray Milkey | ba9c4f5 | 2018-10-10 14:32:38 -0700 | [diff] [blame] | 26 | import org.onosproject.cli.net.EthTypeCompleter; |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 27 | import org.onosproject.cli.net.HostIdCompleter; |
| 28 | import org.onosproject.net.HostId; |
| 29 | import org.onosproject.t3.api.StaticPacketTrace; |
| 30 | import org.onosproject.t3.api.TroubleshootService; |
| 31 | |
Andrea Campanella | 696ef03 | 2018-02-27 18:03:17 +0100 | [diff] [blame] | 32 | import java.util.Set; |
| 33 | |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 34 | import static org.onlab.packet.EthType.EtherType; |
| 35 | |
| 36 | /** |
| 37 | * Starts a Static Packet Trace for a given input and prints the result. |
| 38 | */ |
Ray Milkey | ac72503 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 39 | @Service |
Andrea Campanella | d756ede | 2018-02-26 11:03:48 +0100 | [diff] [blame] | 40 | @Command(scope = "onos", name = "t3-troubleshoot-simple", |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 41 | description = "Given two hosts troubleshoots flows and groups between them, in case of segment routing") |
| 42 | public 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 Milkey | ba9c4f5 | 2018-10-10 14:32:38 -0700 | [diff] [blame] | 48 | @Completion(HostIdCompleter.class) |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 49 | String srcHost = null; |
| 50 | |
| 51 | @Argument(index = 1, name = "two", description = "Another host ID", |
| 52 | required = true, multiValued = false) |
Ray Milkey | ba9c4f5 | 2018-10-10 14:32:38 -0700 | [diff] [blame] | 53 | @Completion(HostIdCompleter.class) |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 54 | String dstHost = null; |
| 55 | |
| 56 | @Option(name = "-v", aliases = "--verbose", description = "Outputs complete path") |
Seyeon Jeong | 83e7986 | 2020-02-28 01:17:34 -0800 | [diff] [blame^] | 57 | @Completion(PlaceholderCompleter.class) |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 58 | private boolean verbosity1 = false; |
| 59 | |
| 60 | @Option(name = "-vv", aliases = "--veryverbose", description = "Outputs flows and groups for every device") |
Seyeon Jeong | 83e7986 | 2020-02-28 01:17:34 -0800 | [diff] [blame^] | 61 | @Completion(PlaceholderCompleter.class) |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 62 | private boolean verbosity2 = false; |
| 63 | |
| 64 | @Option(name = "-et", aliases = "--ethType", description = "ETH Type", valueToShowInHelp = "ipv4") |
Ray Milkey | ba9c4f5 | 2018-10-10 14:32:38 -0700 | [diff] [blame] | 65 | @Completion(EthTypeCompleter.class) |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 66 | String ethType = "ipv4"; |
| 67 | |
| 68 | @Override |
Ray Milkey | 822567d | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 69 | protected void doExecute() { |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 70 | TroubleshootService service = get(TroubleshootService.class); |
Seyeon Jeong | 83e7986 | 2020-02-28 01:17:34 -0800 | [diff] [blame^] | 71 | 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 Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 79 | |
| 80 | EtherType type = EtherType.valueOf(ethType.toUpperCase()); |
| 81 | |
Andrea Campanella | 6a614fa | 2018-02-21 14:28:20 +0100 | [diff] [blame] | 82 | //Printing the traced hosts |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 83 | print("Tracing between: %s and %s", srcHost, dstHost); |
| 84 | |
Andrea Campanella | 696ef03 | 2018-02-27 18:03:17 +0100 | [diff] [blame] | 85 | //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 Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 96 | |
| 97 | |
| 98 | } |
| 99 | } |