Andrea Campanella | e408440 | 2017-12-15 15:27:31 +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.impl; |
| 18 | |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame^] | 19 | import com.google.common.collect.ImmutableList; |
| 20 | import org.onosproject.net.ConnectPoint; |
| 21 | import org.onosproject.t3.api.StaticPacketTrace; |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 22 | |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame^] | 23 | import java.util.ArrayList; |
| 24 | import java.util.List; |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 25 | |
| 26 | /** |
| 27 | * Utility class for the troubleshooting tool. |
| 28 | */ |
| 29 | final class TroubleshootUtils { |
| 30 | |
| 31 | private TroubleshootUtils() { |
| 32 | //Banning construction |
| 33 | } |
| 34 | |
| 35 | /** |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame^] | 36 | * Computes the list of traversed connect points. |
| 37 | * |
| 38 | * @param completePath the list of devices |
| 39 | * @param trace the trace we are building |
| 40 | * @param output the final output connect point |
| 41 | * @return true only if the path is successfully computed and added to the trace |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 42 | */ |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame^] | 43 | static boolean computePath(List<ConnectPoint> completePath, StaticPacketTrace trace, ConnectPoint output) { |
| 44 | List<ConnectPoint> traverseList = new ArrayList<>(); |
| 45 | if (!completePath.contains(trace.getInitialConnectPoint())) { |
| 46 | traverseList.add(trace.getInitialConnectPoint()); |
Andrea Campanella | 4c6170a | 2018-01-17 16:34:51 +0100 | [diff] [blame] | 47 | } |
| 48 | |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame^] | 49 | if (output != null && trace.getInitialConnectPoint().deviceId().equals(output.deviceId())) { |
| 50 | trace.addCompletePath(ImmutableList.of(trace.getInitialConnectPoint(), output)); |
| 51 | return true; |
| 52 | } |
| 53 | |
| 54 | traverseList.addAll(completePath); |
| 55 | if (output != null && !completePath.contains(output)) { |
| 56 | traverseList.add(output); |
| 57 | } |
| 58 | if (!trace.getCompletePaths().contains(traverseList)) { |
| 59 | trace.addCompletePath(ImmutableList.copyOf(traverseList)); |
| 60 | return true; |
| 61 | } |
| 62 | return false; |
Andrea Campanella | 4c6170a | 2018-01-17 16:34:51 +0100 | [diff] [blame] | 63 | } |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame^] | 64 | |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 65 | } |