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 | |
| 19 | import org.apache.karaf.shell.commands.Argument; |
| 20 | import org.apache.karaf.shell.commands.Command; |
| 21 | import org.apache.karaf.shell.commands.Option; |
| 22 | import org.onosproject.cli.AbstractShellCommand; |
| 23 | import org.onosproject.cli.net.HostIdCompleter; |
| 24 | import org.onosproject.net.HostId; |
| 25 | import org.onosproject.t3.api.StaticPacketTrace; |
| 26 | import org.onosproject.t3.api.TroubleshootService; |
| 27 | |
| 28 | import static org.onlab.packet.EthType.EtherType; |
| 29 | |
| 30 | /** |
| 31 | * Starts a Static Packet Trace for a given input and prints the result. |
| 32 | */ |
Andrea Campanella | d756ede | 2018-02-26 11:03:48 +0100 | [diff] [blame] | 33 | @Command(scope = "onos", name = "t3-troubleshoot-simple", |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 34 | description = "Given two hosts troubleshoots flows and groups between them, in case of segment routing") |
| 35 | public 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 | |
Andrea Campanella | 6a614fa | 2018-02-21 14:28:20 +0100 | [diff] [blame] | 62 | //Printing the traced hosts |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 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) { |
Andrea Campanella | 94dfb9e | 2018-02-27 12:36:00 +0100 | [diff] [blame] | 68 | print("Tracing Packet: %s", trace.getInitialPacket()); |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 69 | print("%s", T3CliUtils.printTrace(trace, verbosity1, verbosity2)); |
| 70 | } else { |
| 71 | print("Cannot obtain trace between %s and %s", srcHost, dstHost); |
| 72 | print("Reason: %s", trace.resultMessage()); |
| 73 | } |
| 74 | |
| 75 | |
| 76 | } |
| 77 | } |