Andrea Campanella | fa3ec19 | 2018-04-06 16:30:18 +0200 | [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.commons.lang.StringUtils; |
| 20 | import org.apache.karaf.shell.commands.Command; |
| 21 | import org.apache.karaf.shell.commands.Option; |
| 22 | import org.onlab.packet.VlanId; |
| 23 | import org.onosproject.cli.AbstractShellCommand; |
| 24 | import org.onosproject.t3.api.StaticPacketTrace; |
| 25 | import org.onosproject.t3.api.TroubleshootService; |
| 26 | import org.onosproject.t3.impl.Generator; |
| 27 | |
| 28 | import java.util.Set; |
| 29 | |
| 30 | /** |
| 31 | * Starts a Static Packet Trace for all the multicast routes in the system and prints the result. |
| 32 | */ |
| 33 | @Command(scope = "onos", name = "t3-troubleshoot-mcast", |
| 34 | description = "Traces all the mcast routes present in the system") |
| 35 | public class TroubleshootMcastCommand extends AbstractShellCommand { |
| 36 | |
| 37 | |
| 38 | @Option(name = "-v", aliases = "--verbose", description = "Outputs trace for each host to host combination") |
| 39 | private boolean verbosity1 = false; |
| 40 | |
| 41 | @Option(name = "-vv", aliases = "--veryverbose", description = "Outputs details of every trace") |
| 42 | private boolean verbosity2 = false; |
| 43 | |
| 44 | @Option(name = "-vid", aliases = "--vlanId", description = "Vlan of incoming packet", valueToShowInHelp = "None") |
| 45 | String vlan = "None"; |
| 46 | |
| 47 | |
| 48 | @Override |
| 49 | protected void execute() { |
| 50 | TroubleshootService service = get(TroubleshootService.class); |
| 51 | print("Tracing all Multicast routes in the System"); |
| 52 | print("%s", StringUtils.rightPad("", 125, '-')); |
| 53 | |
| 54 | //Create the generator for the list of traces. |
| 55 | VlanId vlanId = vlan == null || vlan.isEmpty() ? VlanId.NONE : VlanId.vlanId(vlan); |
| 56 | Generator<Set<StaticPacketTrace>> generator = service.traceMcast(vlanId); |
| 57 | while (generator.iterator().hasNext()) { |
| 58 | //Print also Route if possible or packet |
| 59 | Set<StaticPacketTrace> traces = generator.iterator().next(); |
| 60 | traces.forEach(trace -> { |
| 61 | print("Tracing packet: %s", trace.getInitialPacket()); |
| 62 | print("%s", T3CliUtils.printTrace(trace, verbosity1, verbosity2)); |
| 63 | print("%s", StringUtils.rightPad("", 125, '-')); |
| 64 | }); |
| 65 | } |
| 66 | |
| 67 | } |
| 68 | } |