blob: ccc4715dcdeeb1fdf1b67a1079ba00b7c7d13f00 [file] [log] [blame]
Andrea Campanellae4084402017-12-15 15:27:31 +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.impl;
18
pierventrefe57fda2020-08-04 22:52:02 +020019import com.google.common.collect.ImmutableList;
20import org.onosproject.net.ConnectPoint;
21import org.onosproject.t3.api.StaticPacketTrace;
Andrea Campanellae4084402017-12-15 15:27:31 +010022
pierventrefe57fda2020-08-04 22:52:02 +020023import java.util.ArrayList;
24import java.util.List;
Andrea Campanellae4084402017-12-15 15:27:31 +010025
26/**
27 * Utility class for the troubleshooting tool.
28 */
29final class TroubleshootUtils {
30
31 private TroubleshootUtils() {
32 //Banning construction
33 }
34
35 /**
pierventrefe57fda2020-08-04 22:52:02 +020036 * 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 Campanellae4084402017-12-15 15:27:31 +010042 */
pierventrefe57fda2020-08-04 22:52:02 +020043 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 Campanella4c6170a2018-01-17 16:34:51 +010047 }
48
pierventrefe57fda2020-08-04 22:52:02 +020049 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 Campanella4c6170a2018-01-17 16:34:51 +010063 }
pierventrefe57fda2020-08-04 22:52:02 +020064
Andrea Campanellae4084402017-12-15 15:27:31 +010065}