Simon Hunt | 026a287 | 2017-11-13 17:09:43 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-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 | |
Andrea Campanella | 17d4519 | 2018-01-18 17:11:42 +0100 | [diff] [blame] | 19 | import com.google.common.base.Preconditions; |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 20 | import com.google.common.collect.ImmutableList; |
Andrea Campanella | 696ef03 | 2018-02-27 18:03:17 +0100 | [diff] [blame] | 21 | import com.google.common.collect.ImmutableSet; |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 22 | import com.google.common.collect.Lists; |
Andrea Campanella | 5befe1c | 2018-02-27 14:50:45 +0100 | [diff] [blame] | 23 | import com.google.common.collect.Sets; |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame] | 24 | import com.google.common.collect.Maps; |
Seyeon Jeong | 5018bdd | 2020-02-28 01:17:34 -0800 | [diff] [blame] | 25 | import org.apache.commons.lang.StringUtils; |
Andrea Campanella | 6a614fa | 2018-02-21 14:28:20 +0100 | [diff] [blame] | 26 | import org.apache.commons.lang3.tuple.Pair; |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 27 | import org.onlab.packet.IpAddress; |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 28 | import org.onlab.packet.VlanId; |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame] | 29 | import org.onlab.util.Generator; |
Andrea Campanella | 54923d6 | 2018-01-23 12:46:04 +0100 | [diff] [blame] | 30 | import org.onosproject.cluster.NodeId; |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame] | 31 | |
Simon Hunt | 026a287 | 2017-11-13 17:09:43 -0800 | [diff] [blame] | 32 | import org.onosproject.net.ConnectPoint; |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame] | 33 | import org.onosproject.net.DataPlaneEntity; |
| 34 | import org.onosproject.net.Device; |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 35 | import org.onosproject.net.DeviceId; |
| 36 | import org.onosproject.net.Host; |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 37 | import org.onosproject.net.HostId; |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 38 | import org.onosproject.net.Link; |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame] | 39 | import org.onosproject.net.PipelineTraceableHitChain; |
| 40 | import org.onosproject.net.PipelineTraceableInput; |
| 41 | import org.onosproject.net.PipelineTraceableOutput; |
| 42 | import org.onosproject.net.PipelineTraceableOutput.PipelineTraceableResult; |
pierventre | 4fd3b46 | 2020-10-15 17:31:44 +0200 | [diff] [blame^] | 43 | import org.onosproject.net.PipelineTraceablePacket; |
Andrea Campanella | 1445f7a | 2018-02-07 12:00:12 +0100 | [diff] [blame] | 44 | import org.onosproject.net.Port; |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 45 | import org.onosproject.net.PortNumber; |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame] | 46 | import org.onosproject.net.behaviour.PipelineTraceable; |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 47 | import org.onosproject.net.config.ConfigException; |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 48 | import org.onosproject.net.config.basics.InterfaceConfig; |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 49 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 50 | import org.onosproject.net.flow.FlowEntry; |
Simon Hunt | 026a287 | 2017-11-13 17:09:43 -0800 | [diff] [blame] | 51 | import org.onosproject.net.flow.TrafficSelector; |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 52 | import org.onosproject.net.flow.criteria.Criteria; |
| 53 | import org.onosproject.net.flow.criteria.Criterion; |
| 54 | import org.onosproject.net.flow.criteria.EthCriterion; |
| 55 | import org.onosproject.net.flow.criteria.EthTypeCriterion; |
| 56 | import org.onosproject.net.flow.criteria.IPCriterion; |
Andrea Campanella | e679801 | 2018-02-06 15:46:52 +0100 | [diff] [blame] | 57 | import org.onosproject.net.flow.criteria.VlanIdCriterion; |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 58 | import org.onosproject.net.group.Group; |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 59 | import org.onosproject.net.host.InterfaceIpAddress; |
| 60 | import org.onosproject.net.intf.Interface; |
Andrea Campanella | 08d07e1 | 2018-03-07 14:27:54 -0800 | [diff] [blame] | 61 | import org.onosproject.routeservice.ResolvedRoute; |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 62 | import org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig; |
Seyeon Jeong | 83e7986 | 2020-02-28 01:17:34 -0800 | [diff] [blame] | 63 | import org.onosproject.t3.api.DeviceNib; |
| 64 | import org.onosproject.t3.api.DriverNib; |
| 65 | import org.onosproject.t3.api.EdgePortNib; |
| 66 | import org.onosproject.t3.api.FlowNib; |
| 67 | import org.onosproject.t3.api.GroupNib; |
Seyeon Jeong | 83e7986 | 2020-02-28 01:17:34 -0800 | [diff] [blame] | 68 | import org.onosproject.t3.api.HostNib; |
| 69 | import org.onosproject.t3.api.LinkNib; |
| 70 | import org.onosproject.t3.api.MastershipNib; |
| 71 | import org.onosproject.t3.api.MulticastRouteNib; |
| 72 | import org.onosproject.t3.api.NetworkConfigNib; |
Seyeon Jeong | 5018bdd | 2020-02-28 01:17:34 -0800 | [diff] [blame] | 73 | import org.onosproject.t3.api.NibProfile; |
Seyeon Jeong | 83e7986 | 2020-02-28 01:17:34 -0800 | [diff] [blame] | 74 | import org.onosproject.t3.api.RouteNib; |
Simon Hunt | 026a287 | 2017-11-13 17:09:43 -0800 | [diff] [blame] | 75 | import org.onosproject.t3.api.StaticPacketTrace; |
| 76 | import org.onosproject.t3.api.TroubleshootService; |
Ray Milkey | 9511b51 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 77 | import org.osgi.service.component.annotations.Component; |
Simon Hunt | 026a287 | 2017-11-13 17:09:43 -0800 | [diff] [blame] | 78 | import org.slf4j.Logger; |
| 79 | |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame] | 80 | import java.util.Map; |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 81 | import java.util.List; |
| 82 | import java.util.Set; |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame] | 83 | import java.util.HashSet; |
| 84 | import java.util.Optional; |
| 85 | import java.util.ArrayList; |
| 86 | import java.util.Collections; |
| 87 | |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 88 | import java.util.stream.Collectors; |
Seyeon Jeong | 83e7986 | 2020-02-28 01:17:34 -0800 | [diff] [blame] | 89 | import java.util.stream.Stream; |
psneha | b823c51 | 2018-08-02 07:41:43 -0400 | [diff] [blame] | 90 | import java.util.stream.StreamSupport; |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 91 | |
| 92 | import static org.onlab.packet.EthType.EtherType; |
Andrea Campanella | e679801 | 2018-02-06 15:46:52 +0100 | [diff] [blame] | 93 | import static org.onosproject.net.flow.TrafficSelector.Builder; |
Simon Hunt | 026a287 | 2017-11-13 17:09:43 -0800 | [diff] [blame] | 94 | import static org.slf4j.LoggerFactory.getLogger; |
| 95 | |
| 96 | /** |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 97 | * Manager to troubleshoot packets inside the network. |
| 98 | * Given a representation of a packet follows it's path in the network according to the existing flows and groups in |
| 99 | * the devices. |
Simon Hunt | 026a287 | 2017-11-13 17:09:43 -0800 | [diff] [blame] | 100 | */ |
Ray Milkey | 9511b51 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 101 | @Component(immediate = true, service = TroubleshootService.class) |
Simon Hunt | 026a287 | 2017-11-13 17:09:43 -0800 | [diff] [blame] | 102 | public class TroubleshootManager implements TroubleshootService { |
| 103 | |
| 104 | private static final Logger log = getLogger(TroubleshootManager.class); |
| 105 | |
Andrea Campanella | 1445f7a | 2018-02-07 12:00:12 +0100 | [diff] [blame] | 106 | static final String PACKET_TO_CONTROLLER = "Packet goes to the controller"; |
| 107 | |
Seyeon Jeong | 83e7986 | 2020-02-28 01:17:34 -0800 | [diff] [blame] | 108 | // uses a snapshot (cache) of NIBs instead of interacting with ONOS core in runtime |
Seyeon Jeong | 5018bdd | 2020-02-28 01:17:34 -0800 | [diff] [blame] | 109 | protected FlowNib flowNib = FlowNib.getInstance(); |
| 110 | protected GroupNib groupNib = GroupNib.getInstance(); |
| 111 | protected LinkNib linkNib = LinkNib.getInstance(); |
| 112 | protected HostNib hostNib = HostNib.getInstance(); |
| 113 | protected DeviceNib deviceNib = DeviceNib.getInstance(); |
| 114 | protected DriverNib driverNib = DriverNib.getInstance(); |
| 115 | protected MastershipNib mastershipNib = MastershipNib.getInstance(); |
| 116 | protected EdgePortNib edgePortNib = EdgePortNib.getInstance(); |
| 117 | protected RouteNib routeNib = RouteNib.getInstance(); |
| 118 | protected NetworkConfigNib networkConfigNib = NetworkConfigNib.getInstance(); |
| 119 | protected MulticastRouteNib mcastRouteNib = MulticastRouteNib.getInstance(); |
Simon Hunt | 026a287 | 2017-11-13 17:09:43 -0800 | [diff] [blame] | 120 | |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame] | 121 | // FIXME Revisit offline mode after a first implementation |
| 122 | private final Map<DeviceId, PipelineTraceable> pipelineTraceables = Maps.newConcurrentMap(); |
| 123 | |
Seyeon Jeong | 83e7986 | 2020-02-28 01:17:34 -0800 | [diff] [blame] | 124 | @Override |
Seyeon Jeong | 5018bdd | 2020-02-28 01:17:34 -0800 | [diff] [blame] | 125 | public boolean checkNibValidity() { |
Seyeon Jeong | 83e7986 | 2020-02-28 01:17:34 -0800 | [diff] [blame] | 126 | return Stream.of(flowNib, groupNib, linkNib, hostNib, deviceNib, driverNib, |
| 127 | mastershipNib, edgePortNib, routeNib, networkConfigNib, mcastRouteNib) |
Seyeon Jeong | 5018bdd | 2020-02-28 01:17:34 -0800 | [diff] [blame] | 128 | .allMatch(nib -> nib != null && nib.isValid()); |
Seyeon Jeong | 83e7986 | 2020-02-28 01:17:34 -0800 | [diff] [blame] | 129 | } |
Simon Hunt | 026a287 | 2017-11-13 17:09:43 -0800 | [diff] [blame] | 130 | |
Seyeon Jeong | 83e7986 | 2020-02-28 01:17:34 -0800 | [diff] [blame] | 131 | @Override |
Seyeon Jeong | 5018bdd | 2020-02-28 01:17:34 -0800 | [diff] [blame] | 132 | public String printNibSummary() { |
| 133 | StringBuilder summary = new StringBuilder().append("*** Current NIB in valid: ***\n"); |
| 134 | Stream.of(flowNib, groupNib, linkNib, hostNib, deviceNib, driverNib, |
| 135 | mastershipNib, edgePortNib, routeNib, networkConfigNib, mcastRouteNib) |
| 136 | .forEach(nib -> { |
| 137 | NibProfile profile = nib.getProfile(); |
| 138 | summary.append(String.format( |
| 139 | nib.getClass().getName() + " created %s from %s\n", |
| 140 | profile.date(), profile.sourceType())); |
| 141 | }); |
| 142 | |
| 143 | return summary.append(StringUtils.rightPad("", 125, '-')).toString(); |
Seyeon Jeong | 83e7986 | 2020-02-28 01:17:34 -0800 | [diff] [blame] | 144 | } |
Andrea Campanella | bd15bf5 | 2018-04-06 16:30:18 +0200 | [diff] [blame] | 145 | |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 146 | @Override |
Andrea Campanella | 0cc6acd | 2018-02-28 16:43:16 +0100 | [diff] [blame] | 147 | public Generator<Set<StaticPacketTrace>> pingAllGenerator(EtherType type) { |
Seyeon Jeong | 83e7986 | 2020-02-28 01:17:34 -0800 | [diff] [blame] | 148 | return new PingAllGenerator(type, hostNib, this); |
Andrea Campanella | 0cc6acd | 2018-02-28 16:43:16 +0100 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | @Override |
Andrea Campanella | bd15bf5 | 2018-04-06 16:30:18 +0200 | [diff] [blame] | 152 | public Generator<Set<StaticPacketTrace>> traceMcast(VlanId vlanId) { |
Seyeon Jeong | 83e7986 | 2020-02-28 01:17:34 -0800 | [diff] [blame] | 153 | return new McastGenerator(mcastRouteNib, this, vlanId); |
Andrea Campanella | bd15bf5 | 2018-04-06 16:30:18 +0200 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | @Override |
Andrea Campanella | 696ef03 | 2018-02-27 18:03:17 +0100 | [diff] [blame] | 157 | public Set<StaticPacketTrace> trace(HostId sourceHost, HostId destinationHost, EtherType etherType) { |
Seyeon Jeong | 83e7986 | 2020-02-28 01:17:34 -0800 | [diff] [blame] | 158 | Host source = hostNib.getHost(sourceHost); |
| 159 | Host destination = hostNib.getHost(destinationHost); |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 160 | |
Andrea Campanella | 6a614fa | 2018-02-21 14:28:20 +0100 | [diff] [blame] | 161 | //Temporary trace to fail in case we don't have enough information or what is provided is incoherent |
| 162 | StaticPacketTrace failTrace = new StaticPacketTrace(null, null, Pair.of(source, destination)); |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 163 | |
| 164 | if (source == null) { |
| 165 | failTrace.addResultMessage("Source Host " + sourceHost + " does not exist"); |
Andrea Campanella | 5af2d2b | 2018-03-12 19:25:44 -0700 | [diff] [blame] | 166 | failTrace.setSuccess(false); |
| 167 | |
Andrea Campanella | 696ef03 | 2018-02-27 18:03:17 +0100 | [diff] [blame] | 168 | return ImmutableSet.of(failTrace); |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | if (destination == null) { |
| 172 | failTrace.addResultMessage("Destination Host " + destinationHost + " does not exist"); |
Andrea Campanella | 5af2d2b | 2018-03-12 19:25:44 -0700 | [diff] [blame] | 173 | failTrace.setSuccess(false); |
Andrea Campanella | 696ef03 | 2018-02-27 18:03:17 +0100 | [diff] [blame] | 174 | return ImmutableSet.of(failTrace); |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder() |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 178 | .matchEthType(etherType.ethType().toShort()) |
| 179 | .matchEthDst(source.mac()) |
| 180 | .matchVlanId(source.vlan()); |
| 181 | |
| 182 | |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 183 | try { |
Andrea Campanella | e24d492 | 2018-03-26 10:39:22 -0700 | [diff] [blame] | 184 | ImmutableSet.Builder<StaticPacketTrace> traces = ImmutableSet.builder(); |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 185 | //if the location deviceId is the same, the two hosts are under same subnet and vlan on the interface |
| 186 | // we are under same leaf so it's L2 Unicast. |
| 187 | if (areBridged(source, destination)) { |
| 188 | selectorBuilder.matchEthDst(destination.mac()); |
Andrea Campanella | 696ef03 | 2018-02-27 18:03:17 +0100 | [diff] [blame] | 189 | source.locations().forEach(hostLocation -> { |
Andrea Campanella | 2ff88a9 | 2018-03-06 15:21:09 -0800 | [diff] [blame] | 190 | selectorBuilder.matchInPort(hostLocation.port()); |
Andrea Campanella | 696ef03 | 2018-02-27 18:03:17 +0100 | [diff] [blame] | 191 | StaticPacketTrace trace = trace(selectorBuilder.build(), hostLocation); |
| 192 | trace.addEndpointHosts(Pair.of(source, destination)); |
| 193 | traces.add(trace); |
| 194 | }); |
Andrea Campanella | e24d492 | 2018-03-26 10:39:22 -0700 | [diff] [blame] | 195 | //The destination host is not dual homed, if it is the other path might be done through routing. |
| 196 | if (destination.locations().size() == 1) { |
| 197 | return traces.build(); |
| 198 | } |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 199 | } |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 200 | //handle the IPs for src and dst in case of L3 |
| 201 | if (etherType.equals(EtherType.IPV4) || etherType.equals(EtherType.IPV6)) { |
| 202 | |
| 203 | //Match on the source IP |
| 204 | if (!matchIP(source, failTrace, selectorBuilder, etherType, true)) { |
Andrea Campanella | 696ef03 | 2018-02-27 18:03:17 +0100 | [diff] [blame] | 205 | return ImmutableSet.of(failTrace); |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | //Match on destination IP |
| 209 | if (!matchIP(destination, failTrace, selectorBuilder, etherType, false)) { |
Andrea Campanella | 696ef03 | 2018-02-27 18:03:17 +0100 | [diff] [blame] | 210 | return ImmutableSet.of(failTrace); |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | } else { |
| 214 | failTrace.addResultMessage("Host based trace supports only IPv4 or IPv6 as EtherType, " + |
| 215 | "please use packet based"); |
Andrea Campanella | 5af2d2b | 2018-03-12 19:25:44 -0700 | [diff] [blame] | 216 | failTrace.setSuccess(false); |
Andrea Campanella | 696ef03 | 2018-02-27 18:03:17 +0100 | [diff] [blame] | 217 | return ImmutableSet.of(failTrace); |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | //l3 unicast, we get the dst mac of the leaf the source is connected to from netcfg |
Seyeon Jeong | 83e7986 | 2020-02-28 01:17:34 -0800 | [diff] [blame] | 221 | SegmentRoutingDeviceConfig segmentRoutingConfig = networkConfigNib.getConfig(source.location() |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 222 | .deviceId(), SegmentRoutingDeviceConfig.class); |
| 223 | if (segmentRoutingConfig != null) { |
| 224 | selectorBuilder.matchEthDst(segmentRoutingConfig.routerMac()); |
| 225 | } else { |
| 226 | failTrace.addResultMessage("Can't get " + source.location().deviceId() + |
| 227 | " router MAC from segment routing config can't perform L3 tracing."); |
Andrea Campanella | 5af2d2b | 2018-03-12 19:25:44 -0700 | [diff] [blame] | 228 | failTrace.setSuccess(false); |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 229 | } |
Andrea Campanella | 696ef03 | 2018-02-27 18:03:17 +0100 | [diff] [blame] | 230 | source.locations().forEach(hostLocation -> { |
Andrea Campanella | 2ff88a9 | 2018-03-06 15:21:09 -0800 | [diff] [blame] | 231 | selectorBuilder.matchInPort(hostLocation.port()); |
Andrea Campanella | 696ef03 | 2018-02-27 18:03:17 +0100 | [diff] [blame] | 232 | StaticPacketTrace trace = trace(selectorBuilder.build(), hostLocation); |
| 233 | trace.addEndpointHosts(Pair.of(source, destination)); |
| 234 | traces.add(trace); |
| 235 | }); |
| 236 | return traces.build(); |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 237 | |
| 238 | } catch (ConfigException e) { |
| 239 | failTrace.addResultMessage("Can't get config " + e.getMessage()); |
Andrea Campanella | 696ef03 | 2018-02-27 18:03:17 +0100 | [diff] [blame] | 240 | return ImmutableSet.of(failTrace); |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 241 | } |
| 242 | } |
| 243 | |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame] | 244 | private PipelineTraceable getPipelineMatchable(DeviceId deviceId) { |
| 245 | return pipelineTraceables.compute(deviceId, (k, v) -> { |
| 246 | if (v == null) { |
| 247 | log.info("PipelineMatchable not found for {}", deviceId); |
| 248 | Device d = deviceNib.getDevice(deviceId); |
| 249 | if (d.is(PipelineTraceable.class)) { |
| 250 | v = d.as(PipelineTraceable.class); |
| 251 | v.init(); |
| 252 | } else { |
| 253 | log.warn("PipelineMatchable behaviour not supported for device {}", |
| 254 | deviceId); |
| 255 | } |
| 256 | } |
| 257 | return v; |
| 258 | }); |
| 259 | } |
| 260 | |
| 261 | private List<DataPlaneEntity> getDataPlaneEntities(DeviceId deviceId) { |
| 262 | List<DataPlaneEntity> dataPlaneEntities = Lists.newArrayList(); |
| 263 | flowNib.getFlowEntriesByState(deviceId, FlowEntry.FlowEntryState.ADDED).forEach(entity -> |
| 264 | dataPlaneEntities.add(new DataPlaneEntity(entity))); |
| 265 | groupNib.getGroupsByState(deviceId, Group.GroupState.ADDED).forEach(entity -> |
| 266 | dataPlaneEntities.add(new DataPlaneEntity(entity))); |
| 267 | return dataPlaneEntities; |
| 268 | } |
| 269 | |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 270 | /** |
| 271 | * Matches src and dst IPs based on host information. |
| 272 | * |
| 273 | * @param host the host |
| 274 | * @param failTrace the trace to use in case of failure |
| 275 | * @param selectorBuilder the packet we are building to trace |
| 276 | * @param etherType the traffic type |
| 277 | * @param src is this src host or dst host |
| 278 | * @return true if properly matched |
| 279 | */ |
| 280 | private boolean matchIP(Host host, StaticPacketTrace failTrace, Builder selectorBuilder, |
| 281 | EtherType etherType, boolean src) { |
Andrea Campanella | 6a614fa | 2018-02-21 14:28:20 +0100 | [diff] [blame] | 282 | List<IpAddress> ips = getIpAddresses(host, etherType, true); |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 283 | |
| 284 | if (ips.size() > 0) { |
Andrea Campanella | bf8d930 | 2018-02-21 14:43:21 +0100 | [diff] [blame] | 285 | if (etherType.equals(EtherType.IPV4)) { |
| 286 | if (src) { |
| 287 | selectorBuilder.matchIPSrc(ips.get(0).toIpPrefix()); |
| 288 | } else { |
| 289 | selectorBuilder.matchIPDst(ips.get(0).toIpPrefix()); |
| 290 | } |
| 291 | } else if (etherType.equals(EtherType.IPV6)) { |
| 292 | if (src) { |
| 293 | selectorBuilder.matchIPv6Src(ips.get(0).toIpPrefix()); |
| 294 | } else { |
| 295 | selectorBuilder.matchIPv6Dst(ips.get(0).toIpPrefix()); |
| 296 | } |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 297 | } |
| 298 | } else { |
| 299 | failTrace.addResultMessage("Host " + host + " has no " + etherType + " address"); |
Andrea Campanella | 5af2d2b | 2018-03-12 19:25:44 -0700 | [diff] [blame] | 300 | failTrace.setSuccess(false); |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 301 | return false; |
| 302 | } |
| 303 | return true; |
| 304 | } |
| 305 | |
Andrea Campanella | 0cc6acd | 2018-02-28 16:43:16 +0100 | [diff] [blame] | 306 | List<IpAddress> getIpAddresses(Host host, EtherType etherType, boolean checklocal) { |
Andrea Campanella | 6a614fa | 2018-02-21 14:28:20 +0100 | [diff] [blame] | 307 | return host.ipAddresses().stream().filter(ipAddress -> { |
| 308 | boolean correctIp = false; |
| 309 | if (etherType.equals(EtherType.IPV4)) { |
| 310 | correctIp = ipAddress.isIp4(); |
| 311 | } else if (etherType.equals(EtherType.IPV6)) { |
| 312 | correctIp = ipAddress.isIp6(); |
| 313 | } |
| 314 | if (checklocal) { |
| 315 | correctIp = correctIp && !ipAddress.isLinkLocal(); |
| 316 | } |
| 317 | return correctIp; |
| 318 | }).collect(Collectors.toList()); |
| 319 | } |
| 320 | |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 321 | /** |
| 322 | * Checks that two hosts are bridged (L2Unicast). |
| 323 | * |
| 324 | * @param source the source host |
| 325 | * @param destination the destination host |
| 326 | * @return true if bridged. |
| 327 | * @throws ConfigException if config can't be properly retrieved |
| 328 | */ |
| 329 | private boolean areBridged(Host source, Host destination) throws ConfigException { |
| 330 | |
Andrea Campanella | 2ff88a9 | 2018-03-06 15:21:09 -0800 | [diff] [blame] | 331 | //If the locations is not the same we don't even check vlan or subnets |
| 332 | if (Collections.disjoint(source.locations(), destination.locations())) { |
| 333 | return false; |
| 334 | } |
| 335 | |
| 336 | if (!source.vlan().equals(VlanId.NONE) && !destination.vlan().equals(VlanId.NONE) |
| 337 | && !source.vlan().equals(destination.vlan())) { |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 338 | return false; |
| 339 | } |
| 340 | |
Seyeon Jeong | 83e7986 | 2020-02-28 01:17:34 -0800 | [diff] [blame] | 341 | InterfaceConfig interfaceCfgH1 = networkConfigNib.getConfig(source.location(), InterfaceConfig.class); |
| 342 | InterfaceConfig interfaceCfgH2 = networkConfigNib.getConfig(destination.location(), InterfaceConfig.class); |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 343 | if (interfaceCfgH1 != null && interfaceCfgH2 != null) { |
| 344 | |
| 345 | //following can be optimized but for clarity is left as is |
| 346 | Interface intfH1 = interfaceCfgH1.getInterfaces().stream().findFirst().get(); |
| 347 | Interface intfH2 = interfaceCfgH2.getInterfaces().stream().findFirst().get(); |
| 348 | |
Andrea Campanella | 2ff88a9 | 2018-03-06 15:21:09 -0800 | [diff] [blame] | 349 | if (source.vlan().equals(VlanId.NONE) && !destination.vlan().equals(VlanId.NONE)) { |
| 350 | return intfH1.vlanUntagged().equals(destination.vlan()) || |
| 351 | intfH1.vlanNative().equals(destination.vlan()); |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 352 | } |
| 353 | |
Andrea Campanella | 2ff88a9 | 2018-03-06 15:21:09 -0800 | [diff] [blame] | 354 | if (!source.vlan().equals(VlanId.NONE) && destination.vlan().equals(VlanId.NONE)) { |
| 355 | return intfH2.vlanUntagged().equals(source.vlan()) || |
| 356 | intfH2.vlanNative().equals(source.vlan()); |
| 357 | } |
| 358 | |
| 359 | if (!intfH1.vlanNative().equals(intfH2.vlanNative())) { |
Andrea Campanella | 55c3f42 | 2018-02-08 17:10:11 +0100 | [diff] [blame] | 360 | return false; |
| 361 | } |
| 362 | |
| 363 | if (!intfH1.vlanUntagged().equals(intfH2.vlanUntagged())) { |
| 364 | return false; |
| 365 | } |
| 366 | |
| 367 | List<InterfaceIpAddress> intersection = new ArrayList<>(intfH1.ipAddressesList()); |
| 368 | intersection.retainAll(intfH2.ipAddressesList()); |
| 369 | if (intersection.size() == 0) { |
| 370 | return false; |
| 371 | } |
| 372 | } |
| 373 | return true; |
| 374 | } |
| 375 | |
Simon Hunt | 026a287 | 2017-11-13 17:09:43 -0800 | [diff] [blame] | 376 | @Override |
| 377 | public StaticPacketTrace trace(TrafficSelector packet, ConnectPoint in) { |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 378 | log.info("Tracing packet {} coming in through {}", packet, in); |
Andrea Campanella | 17d4519 | 2018-01-18 17:11:42 +0100 | [diff] [blame] | 379 | //device must exist in ONOS |
Seyeon Jeong | 83e7986 | 2020-02-28 01:17:34 -0800 | [diff] [blame] | 380 | Preconditions.checkNotNull(deviceNib.getDevice(in.deviceId()), |
Andrea Campanella | 17d4519 | 2018-01-18 17:11:42 +0100 | [diff] [blame] | 381 | "Device " + in.deviceId() + " must exist in ONOS"); |
| 382 | |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 383 | StaticPacketTrace trace = new StaticPacketTrace(packet, in); |
Andrea Campanella | 696ef03 | 2018-02-27 18:03:17 +0100 | [diff] [blame] | 384 | boolean isDualHomed = getHosts(trace).stream().anyMatch(host -> host.locations().size() > 1); |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 385 | //FIXME this can be done recursively |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 386 | //Building output connect Points |
| 387 | List<ConnectPoint> path = new ArrayList<>(); |
Andrea Campanella | d5e16ff | 2018-03-21 10:08:55 -0700 | [diff] [blame] | 388 | trace = traceInDevice(trace, packet, in, isDualHomed, path); |
Andrea Campanella | 696ef03 | 2018-02-27 18:03:17 +0100 | [diff] [blame] | 389 | trace = getTrace(path, in, trace, isDualHomed); |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 390 | return trace; |
| 391 | } |
| 392 | |
| 393 | /** |
| 394 | * Computes a trace for a give packet that start in the network at the given connect point. |
| 395 | * |
| 396 | * @param completePath the path traversed by the packet |
| 397 | * @param in the input connect point |
| 398 | * @param trace the trace to build |
Andrea Campanella | 696ef03 | 2018-02-27 18:03:17 +0100 | [diff] [blame] | 399 | * @param isDualHomed true if the trace we are doing starts or ends in a dual homed host |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 400 | * @return the build trace for that packet. |
| 401 | */ |
Andrea Campanella | 696ef03 | 2018-02-27 18:03:17 +0100 | [diff] [blame] | 402 | private StaticPacketTrace getTrace(List<ConnectPoint> completePath, ConnectPoint in, StaticPacketTrace trace, |
| 403 | boolean isDualHomed) { |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 404 | |
Andrea Campanella | b022b5e | 2018-01-31 14:59:03 +0100 | [diff] [blame] | 405 | log.debug("------------------------------------------------------------"); |
| 406 | |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 407 | //if the trace already contains the input connect point there is a loop |
| 408 | if (pathContainsDevice(completePath, in.deviceId())) { |
| 409 | trace.addResultMessage("Loop encountered in device " + in.deviceId()); |
Andrea Campanella | 3ddbadb | 2018-03-09 14:52:10 -0800 | [diff] [blame] | 410 | completePath.add(in); |
| 411 | trace.addCompletePath(completePath); |
Andrea Campanella | 5af2d2b | 2018-03-12 19:25:44 -0700 | [diff] [blame] | 412 | trace.setSuccess(false); |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 413 | return trace; |
| 414 | } |
| 415 | |
| 416 | //let's add the input connect point |
| 417 | completePath.add(in); |
| 418 | |
| 419 | //If the trace has no outputs for the given input we stop here |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame] | 420 | if (trace.getHitChains(in.deviceId()) == null) { |
| 421 | TroubleshootUtils.computePath(completePath, trace, null); |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 422 | trace.addResultMessage("No output out of device " + in.deviceId() + ". Packet is dropped"); |
Andrea Campanella | 5af2d2b | 2018-03-12 19:25:44 -0700 | [diff] [blame] | 423 | trace.setSuccess(false); |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 424 | return trace; |
| 425 | } |
Andrea Campanella | 7d3cf65 | 2018-01-22 15:10:30 +0100 | [diff] [blame] | 426 | |
Andrea Campanella | 27140da | 2018-04-09 14:22:32 +0200 | [diff] [blame] | 427 | //If the trace has outputs we analyze them all |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame] | 428 | for (PipelineTraceableHitChain outputPath : trace.getHitChains(in.deviceId())) { |
Andrea Campanella | 54923d6 | 2018-01-23 12:46:04 +0100 | [diff] [blame] | 429 | |
pierventre | 4fd3b46 | 2020-10-15 17:31:44 +0200 | [diff] [blame^] | 430 | ConnectPoint cp = outputPath.outputPort(); |
Andrea Campanella | b022b5e | 2018-01-31 14:59:03 +0100 | [diff] [blame] | 431 | log.debug("Connect point in {}", in); |
Andrea Campanella | 54923d6 | 2018-01-23 12:46:04 +0100 | [diff] [blame] | 432 | log.debug("Output path {}", cp); |
pierventre | 4fd3b46 | 2020-10-15 17:31:44 +0200 | [diff] [blame^] | 433 | log.debug("{}", outputPath.egressPacket()); |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame] | 434 | |
| 435 | if (outputPath.isDropped()) { |
| 436 | continue; |
| 437 | } |
Andrea Campanella | 54923d6 | 2018-01-23 12:46:04 +0100 | [diff] [blame] | 438 | |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 439 | //Hosts for the the given output |
Seyeon Jeong | 83e7986 | 2020-02-28 01:17:34 -0800 | [diff] [blame] | 440 | Set<Host> hostsList = hostNib.getConnectedHosts(cp); |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 441 | //Hosts queried from the original ip or mac |
| 442 | Set<Host> hosts = getHosts(trace); |
| 443 | |
Andrea Campanella | 2ff88a9 | 2018-03-06 15:21:09 -0800 | [diff] [blame] | 444 | if (in.equals(cp) && trace.getInitialPacket().getCriterion(Criterion.Type.VLAN_VID) != null && |
pierventre | 4fd3b46 | 2020-10-15 17:31:44 +0200 | [diff] [blame^] | 445 | outputPath.egressPacket().packet().getCriterion(Criterion.Type.VLAN_VID) != null |
Andrea Campanella | 2ff88a9 | 2018-03-06 15:21:09 -0800 | [diff] [blame] | 446 | && ((VlanIdCriterion) trace.getInitialPacket().getCriterion(Criterion.Type.VLAN_VID)).vlanId() |
pierventre | 4fd3b46 | 2020-10-15 17:31:44 +0200 | [diff] [blame^] | 447 | .equals(((VlanIdCriterion) outputPath.egressPacket() |
| 448 | .packet().getCriterion(Criterion.Type.VLAN_VID)).vlanId())) { |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame] | 449 | if (trace.getHitChains(in.deviceId()).size() == 1 && |
pierventre | 4fd3b46 | 2020-10-15 17:31:44 +0200 | [diff] [blame^] | 450 | TroubleshootUtils.computePath(completePath, trace, outputPath.outputPort())) { |
Andrea Campanella | fe5d8df | 2018-03-12 11:07:35 -0700 | [diff] [blame] | 451 | trace.addResultMessage("Connect point out " + cp + " is same as initial input " + in); |
Andrea Campanella | 5af2d2b | 2018-03-12 19:25:44 -0700 | [diff] [blame] | 452 | trace.setSuccess(false); |
Andrea Campanella | fe5d8df | 2018-03-12 11:07:35 -0700 | [diff] [blame] | 453 | } |
Andrea Campanella | d5e16ff | 2018-03-21 10:08:55 -0700 | [diff] [blame] | 454 | } else if (!Collections.disjoint(hostsList, hosts)) { |
Andrea Campanella | 5af2d2b | 2018-03-12 19:25:44 -0700 | [diff] [blame] | 455 | //If the two host collections contain the same item it means we reached the proper output |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame] | 456 | log.debug("Stopping here because host is expected destination, reached through {}", completePath); |
pierventre | 4fd3b46 | 2020-10-15 17:31:44 +0200 | [diff] [blame^] | 457 | if (TroubleshootUtils.computePath(completePath, trace, outputPath.outputPort())) { |
Andrea Campanella | 696ef03 | 2018-02-27 18:03:17 +0100 | [diff] [blame] | 458 | trace.addResultMessage("Reached required destination Host " + cp); |
Andrea Campanella | 0cc6acd | 2018-02-28 16:43:16 +0100 | [diff] [blame] | 459 | trace.setSuccess(true); |
Andrea Campanella | 696ef03 | 2018-02-27 18:03:17 +0100 | [diff] [blame] | 460 | } |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 461 | break; |
Andrea Campanella | 8292ba6 | 2018-01-31 16:43:23 +0100 | [diff] [blame] | 462 | |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame] | 463 | } else if (cp.port().equals(PortNumber.CONTROLLER)) { |
Andrea Campanella | 54923d6 | 2018-01-23 12:46:04 +0100 | [diff] [blame] | 464 | //Getting the master when the packet gets sent as packet in |
Seyeon Jeong | 83e7986 | 2020-02-28 01:17:34 -0800 | [diff] [blame] | 465 | NodeId master = mastershipNib.getMasterFor(cp.deviceId()); |
| 466 | // TODO if we don't need to print master node id, exclude mastership NIB which is used only here |
Andrea Campanella | 1445f7a | 2018-02-07 12:00:12 +0100 | [diff] [blame] | 467 | trace.addResultMessage(PACKET_TO_CONTROLLER + " " + master.id()); |
pierventre | 4fd3b46 | 2020-10-15 17:31:44 +0200 | [diff] [blame^] | 468 | TroubleshootUtils.computePath(completePath, trace, outputPath.outputPort()); |
Seyeon Jeong | 83e7986 | 2020-02-28 01:17:34 -0800 | [diff] [blame] | 469 | } else if (linkNib.getEgressLinks(cp).size() > 0) { |
Andrea Campanella | b022b5e | 2018-01-31 14:59:03 +0100 | [diff] [blame] | 470 | //TODO this can be optimized if we use a Tree structure for paths. |
| 471 | //if we already have outputs let's check if the one we are considering starts from one of the devices |
| 472 | // in any of the ones we have. |
| 473 | if (trace.getCompletePaths().size() > 0) { |
| 474 | ConnectPoint inputForOutput = null; |
| 475 | List<ConnectPoint> previousPath = new ArrayList<>(); |
| 476 | for (List<ConnectPoint> path : trace.getCompletePaths()) { |
| 477 | for (ConnectPoint connect : path) { |
| 478 | //if the path already contains the input for the output we've found we use it |
| 479 | if (connect.equals(in)) { |
| 480 | inputForOutput = connect; |
| 481 | previousPath = path; |
| 482 | break; |
| 483 | } |
| 484 | } |
| 485 | } |
Andrea Campanella | 3ddbadb | 2018-03-09 14:52:10 -0800 | [diff] [blame] | 486 | |
Andrea Campanella | b022b5e | 2018-01-31 14:59:03 +0100 | [diff] [blame] | 487 | //we use the pre-existing path up to the point we fork to a new output |
| 488 | if (inputForOutput != null && completePath.contains(inputForOutput)) { |
| 489 | List<ConnectPoint> temp = new ArrayList<>(previousPath); |
Andrea Campanella | 3ddbadb | 2018-03-09 14:52:10 -0800 | [diff] [blame] | 490 | temp = temp.subList(0, previousPath.indexOf(inputForOutput) + 1); |
| 491 | if (completePath.containsAll(temp)) { |
| 492 | completePath = temp; |
| 493 | } |
Andrea Campanella | b022b5e | 2018-01-31 14:59:03 +0100 | [diff] [blame] | 494 | } |
| 495 | } |
| 496 | |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 497 | //let's add the ouput for the input |
| 498 | completePath.add(cp); |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 499 | //let's compute the links for the given output |
Seyeon Jeong | 83e7986 | 2020-02-28 01:17:34 -0800 | [diff] [blame] | 500 | Set<Link> links = linkNib.getEgressLinks(cp); |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 501 | log.debug("Egress Links {}", links); |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 502 | //For each link we trace the corresponding device |
| 503 | for (Link link : links) { |
| 504 | ConnectPoint dst = link.dst(); |
| 505 | //change in-port to the dst link in port |
Andrea Campanella | 8292ba6 | 2018-01-31 16:43:23 +0100 | [diff] [blame] | 506 | Builder updatedPacket = DefaultTrafficSelector.builder(); |
pierventre | 4fd3b46 | 2020-10-15 17:31:44 +0200 | [diff] [blame^] | 507 | outputPath.egressPacket().packet().criteria().forEach(updatedPacket::add); |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 508 | updatedPacket.add(Criteria.matchInPort(dst.port())); |
| 509 | log.debug("DST Connect Point {}", dst); |
| 510 | //build the elements for that device |
Andrea Campanella | d5e16ff | 2018-03-21 10:08:55 -0700 | [diff] [blame] | 511 | traceInDevice(trace, updatedPacket.build(), dst, isDualHomed, completePath); |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 512 | //continue the trace along the path |
Andrea Campanella | 696ef03 | 2018-02-27 18:03:17 +0100 | [diff] [blame] | 513 | getTrace(completePath, dst, trace, isDualHomed); |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 514 | } |
pierventre | 4fd3b46 | 2020-10-15 17:31:44 +0200 | [diff] [blame^] | 515 | } else if (edgePortNib.isEdgePoint(outputPath.outputPort()) && |
Andrea Campanella | 4c6170a | 2018-01-17 16:34:51 +0100 | [diff] [blame] | 516 | trace.getInitialPacket().getCriterion(Criterion.Type.ETH_DST) != null && |
| 517 | ((EthCriterion) trace.getInitialPacket().getCriterion(Criterion.Type.ETH_DST)) |
| 518 | .mac().isMulticast()) { |
pierventre | 4fd3b46 | 2020-10-15 17:31:44 +0200 | [diff] [blame^] | 519 | trace.addResultMessage("Packet is multicast and reached output " + outputPath.outputPort() + |
Andrea Campanella | 4c6170a | 2018-01-17 16:34:51 +0100 | [diff] [blame] | 520 | " which is enabled and is edge port"); |
Andrea Campanella | 0cc6acd | 2018-02-28 16:43:16 +0100 | [diff] [blame] | 521 | trace.setSuccess(true); |
pierventre | 4fd3b46 | 2020-10-15 17:31:44 +0200 | [diff] [blame^] | 522 | TroubleshootUtils.computePath(completePath, trace, outputPath.outputPort()); |
| 523 | if (!hasOtherOutput(in.deviceId(), trace, outputPath.outputPort())) { |
Andrea Campanella | 4c6170a | 2018-01-17 16:34:51 +0100 | [diff] [blame] | 524 | return trace; |
| 525 | } |
Seyeon Jeong | 83e7986 | 2020-02-28 01:17:34 -0800 | [diff] [blame] | 526 | } else if (deviceNib.getPort(cp) != null && deviceNib.getPort(cp).isEnabled()) { |
Andrea Campanella | 1445f7a | 2018-02-07 12:00:12 +0100 | [diff] [blame] | 527 | EthTypeCriterion ethTypeCriterion = (EthTypeCriterion) trace.getInitialPacket() |
| 528 | .getCriterion(Criterion.Type.ETH_TYPE); |
| 529 | //We treat as correct output only if it's not LLDP or BDDP |
| 530 | if (!(ethTypeCriterion.ethType().equals(EtherType.LLDP.ethType()) |
Andrea Campanella | c6d10fc | 2018-02-27 12:42:28 +0100 | [diff] [blame] | 531 | && !ethTypeCriterion.ethType().equals(EtherType.BDDP.ethType()))) { |
pierventre | 4fd3b46 | 2020-10-15 17:31:44 +0200 | [diff] [blame^] | 532 | if (TroubleshootUtils.computePath(completePath, trace, outputPath.outputPort())) { |
Andrea Campanella | 08d07e1 | 2018-03-07 14:27:54 -0800 | [diff] [blame] | 533 | if (hostsList.isEmpty()) { |
pierventre | 4fd3b46 | 2020-10-15 17:31:44 +0200 | [diff] [blame^] | 534 | trace.addResultMessage("Packet is " + ((EthTypeCriterion) outputPath.egressPacket() |
| 535 | .packet().getCriterion(Criterion.Type.ETH_TYPE)).ethType() + " and reached " + |
Andrea Campanella | 08d07e1 | 2018-03-07 14:27:54 -0800 | [diff] [blame] | 536 | cp + " with no hosts connected "); |
| 537 | } else { |
| 538 | IpAddress ipAddress = null; |
| 539 | if (trace.getInitialPacket().getCriterion(Criterion.Type.IPV4_DST) != null) { |
| 540 | ipAddress = ((IPCriterion) trace.getInitialPacket() |
| 541 | .getCriterion(Criterion.Type.IPV4_DST)).ip().address(); |
| 542 | } else if (trace.getInitialPacket().getCriterion(Criterion.Type.IPV6_DST) != null) { |
| 543 | ipAddress = ((IPCriterion) trace.getInitialPacket() |
| 544 | .getCriterion(Criterion.Type.IPV6_DST)).ip().address(); |
| 545 | } |
| 546 | if (ipAddress != null) { |
| 547 | IpAddress finalIpAddress = ipAddress; |
| 548 | if (hostsList.stream().anyMatch(host -> host.ipAddresses().contains(finalIpAddress)) || |
Seyeon Jeong | 83e7986 | 2020-02-28 01:17:34 -0800 | [diff] [blame] | 549 | hostNib.getHostsByIp(finalIpAddress).isEmpty()) { |
Andrea Campanella | 08d07e1 | 2018-03-07 14:27:54 -0800 | [diff] [blame] | 550 | trace.addResultMessage("Packet is " + |
pierventre | 4fd3b46 | 2020-10-15 17:31:44 +0200 | [diff] [blame^] | 551 | ((EthTypeCriterion) outputPath.egressPacket().packet() |
Andrea Campanella | 7fa8f0a | 2018-03-09 15:30:22 -0800 | [diff] [blame] | 552 | .getCriterion(Criterion.Type.ETH_TYPE)).ethType() + |
| 553 | " and reached " + cp + " with hosts " + hostsList); |
Andrea Campanella | 08d07e1 | 2018-03-07 14:27:54 -0800 | [diff] [blame] | 554 | } else { |
| 555 | trace.addResultMessage("Wrong output " + cp + " for required destination ip " + |
| 556 | ipAddress); |
Andrea Campanella | 5af2d2b | 2018-03-12 19:25:44 -0700 | [diff] [blame] | 557 | trace.setSuccess(false); |
Andrea Campanella | 08d07e1 | 2018-03-07 14:27:54 -0800 | [diff] [blame] | 558 | } |
| 559 | } else { |
pierventre | 4fd3b46 | 2020-10-15 17:31:44 +0200 | [diff] [blame^] | 560 | trace.addResultMessage("Packet is " + ((EthTypeCriterion) outputPath.egressPacket() |
| 561 | .packet().getCriterion(Criterion.Type.ETH_TYPE)).ethType() |
| 562 | + " and reached " + cp + " with hosts " + hostsList); |
Andrea Campanella | 2ff88a9 | 2018-03-06 15:21:09 -0800 | [diff] [blame] | 563 | } |
Andrea Campanella | 2ff88a9 | 2018-03-06 15:21:09 -0800 | [diff] [blame] | 564 | } |
Andrea Campanella | 08d07e1 | 2018-03-07 14:27:54 -0800 | [diff] [blame] | 565 | trace.setSuccess(true); |
Andrea Campanella | 1445f7a | 2018-02-07 12:00:12 +0100 | [diff] [blame] | 566 | } |
Andrea Campanella | 8292ba6 | 2018-01-31 16:43:23 +0100 | [diff] [blame] | 567 | } |
Andrea Campanella | 8292ba6 | 2018-01-31 16:43:23 +0100 | [diff] [blame] | 568 | |
| 569 | } else { |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame] | 570 | TroubleshootUtils.computePath(completePath, trace, cp); |
Andrea Campanella | 5af2d2b | 2018-03-12 19:25:44 -0700 | [diff] [blame] | 571 | trace.setSuccess(false); |
Seyeon Jeong | 83e7986 | 2020-02-28 01:17:34 -0800 | [diff] [blame] | 572 | if (deviceNib.getPort(cp) == null) { |
Jon Hall | 4a28fc9 | 2018-04-24 18:03:10 -0700 | [diff] [blame] | 573 | //Port is not existent on device. |
Andrea Campanella | e24d492 | 2018-03-26 10:39:22 -0700 | [diff] [blame] | 574 | log.warn("Port {} is not available on device.", cp); |
| 575 | trace.addResultMessage("Port " + cp + "is not available on device. Packet is dropped"); |
| 576 | } else { |
| 577 | //No links means that the packet gets dropped. |
| 578 | log.warn("No links out of {}", cp); |
| 579 | trace.addResultMessage("No links depart from " + cp + ". Packet is dropped"); |
| 580 | } |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 581 | } |
| 582 | } |
| 583 | return trace; |
| 584 | } |
| 585 | |
Andrea Campanella | e679801 | 2018-02-06 15:46:52 +0100 | [diff] [blame] | 586 | /** |
Andrea Campanella | 4c6170a | 2018-01-17 16:34:51 +0100 | [diff] [blame] | 587 | * Checks if the device has other outputs than the given connect point. |
| 588 | * |
| 589 | * @param inDeviceId the device |
| 590 | * @param trace the trace we are building |
| 591 | * @param cp an output connect point |
| 592 | * @return true if the device has other outputs. |
| 593 | */ |
| 594 | private boolean hasOtherOutput(DeviceId inDeviceId, StaticPacketTrace trace, ConnectPoint cp) { |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame] | 595 | return trace.getHitChains(inDeviceId).stream().filter(groupsInDevice -> |
pierventre | 4fd3b46 | 2020-10-15 17:31:44 +0200 | [diff] [blame^] | 596 | !groupsInDevice.outputPort().equals(cp)).count() > 0; |
Andrea Campanella | 4c6170a | 2018-01-17 16:34:51 +0100 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | /** |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 600 | * Checks if the path contains the device. |
| 601 | * |
| 602 | * @param completePath the path |
| 603 | * @param deviceId the device to check |
| 604 | * @return true if the path contains the device |
| 605 | */ |
| 606 | //TODO might prove costly, improvement: a class with both CPs and DeviceIds point. |
| 607 | private boolean pathContainsDevice(List<ConnectPoint> completePath, DeviceId deviceId) { |
| 608 | for (ConnectPoint cp : completePath) { |
| 609 | if (cp.deviceId().equals(deviceId)) { |
| 610 | return true; |
| 611 | } |
| 612 | } |
| 613 | return false; |
| 614 | } |
| 615 | |
| 616 | /** |
| 617 | * Gets the hosts for the given initial packet. |
| 618 | * |
| 619 | * @param trace the trace we are building |
| 620 | * @return set of the hosts we are trying to reach |
| 621 | */ |
| 622 | private Set<Host> getHosts(StaticPacketTrace trace) { |
| 623 | IPCriterion ipv4Criterion = ((IPCriterion) trace.getInitialPacket() |
| 624 | .getCriterion(Criterion.Type.IPV4_DST)); |
| 625 | IPCriterion ipv6Criterion = ((IPCriterion) trace.getInitialPacket() |
| 626 | .getCriterion(Criterion.Type.IPV6_DST)); |
| 627 | Set<Host> hosts = new HashSet<>(); |
| 628 | if (ipv4Criterion != null) { |
Seyeon Jeong | 83e7986 | 2020-02-28 01:17:34 -0800 | [diff] [blame] | 629 | hosts.addAll(hostNib.getHostsByIp(ipv4Criterion.ip().address())); |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 630 | } |
| 631 | if (ipv6Criterion != null) { |
Seyeon Jeong | 83e7986 | 2020-02-28 01:17:34 -0800 | [diff] [blame] | 632 | hosts.addAll(hostNib.getHostsByIp(ipv6Criterion.ip().address())); |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 633 | } |
| 634 | EthCriterion ethCriterion = ((EthCriterion) trace.getInitialPacket() |
| 635 | .getCriterion(Criterion.Type.ETH_DST)); |
| 636 | if (ethCriterion != null) { |
Seyeon Jeong | 83e7986 | 2020-02-28 01:17:34 -0800 | [diff] [blame] | 637 | hosts.addAll(hostNib.getHostsByMac(ethCriterion.mac())); |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 638 | } |
| 639 | return hosts; |
| 640 | } |
| 641 | |
| 642 | /** |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 643 | * Traces the packet inside a device starting from an input connect point. |
| 644 | * |
Andrea Campanella | d5e16ff | 2018-03-21 10:08:55 -0700 | [diff] [blame] | 645 | * @param trace the trace we are building |
| 646 | * @param packet the packet we are tracing |
| 647 | * @param in the input connect point. |
| 648 | * @param isDualHomed true if the trace we are doing starts or ends in a dual homed host |
| 649 | * @param completePath the path up until this device |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 650 | * @return updated trace |
| 651 | */ |
Andrea Campanella | 696ef03 | 2018-02-27 18:03:17 +0100 | [diff] [blame] | 652 | private StaticPacketTrace traceInDevice(StaticPacketTrace trace, TrafficSelector packet, ConnectPoint in, |
Andrea Campanella | d5e16ff | 2018-03-21 10:08:55 -0700 | [diff] [blame] | 653 | boolean isDualHomed, List<ConnectPoint> completePath) { |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame] | 654 | // Get the behavior - do not proceed if there is no PipelineMatchable for the given device |
| 655 | PipelineTraceable pipelineMatchable = getPipelineMatchable(in.deviceId()); |
| 656 | if (pipelineMatchable == null) { |
| 657 | trace.addResultMessage("No PipelineMatchable behavior for " + in.deviceId() + ". Aborting"); |
| 658 | TroubleshootUtils.computePath(completePath, trace, null); |
| 659 | trace.setSuccess(false); |
| 660 | return trace; |
| 661 | } |
Andrea Campanella | b022b5e | 2018-01-31 14:59:03 +0100 | [diff] [blame] | 662 | |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame] | 663 | // Verify the presence of multiple routes - if the device has been visited in the past |
Andrea Campanella | 08d07e1 | 2018-03-07 14:27:54 -0800 | [diff] [blame] | 664 | boolean multipleRoutes = false; |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame] | 665 | if (trace.getHitChains(in.deviceId()) != null) { |
Andrea Campanella | 08d07e1 | 2018-03-07 14:27:54 -0800 | [diff] [blame] | 666 | multipleRoutes = multipleRoutes(trace); |
| 667 | } |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame] | 668 | if (trace.getHitChains(in.deviceId()) != null && !isDualHomed && !multipleRoutes) { |
Andrea Campanella | b022b5e | 2018-01-31 14:59:03 +0100 | [diff] [blame] | 669 | log.debug("Trace already contains device and given outputs"); |
| 670 | return trace; |
| 671 | } |
Andrea Campanella | 08d07e1 | 2018-03-07 14:27:54 -0800 | [diff] [blame] | 672 | |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 673 | log.debug("Packet {} coming in from {}", packet, in); |
Andrea Campanella | 17d4519 | 2018-01-18 17:11:42 +0100 | [diff] [blame] | 674 | |
| 675 | //if device is not available exit here. |
Seyeon Jeong | 83e7986 | 2020-02-28 01:17:34 -0800 | [diff] [blame] | 676 | if (!deviceNib.isAvailable(in.deviceId())) { |
Andrea Campanella | 17d4519 | 2018-01-18 17:11:42 +0100 | [diff] [blame] | 677 | trace.addResultMessage("Device is offline " + in.deviceId()); |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame] | 678 | TroubleshootUtils.computePath(completePath, trace, null); |
Andrea Campanella | 17d4519 | 2018-01-18 17:11:42 +0100 | [diff] [blame] | 679 | return trace; |
| 680 | } |
| 681 | |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame] | 682 | // Handle when the input is the controller. |
| 683 | // NOTE, we are using the input port as a convenience to carry the CONTROLLER port number even if |
Andrea Campanella | 1445f7a | 2018-02-07 12:00:12 +0100 | [diff] [blame] | 684 | // a packet in from the controller will not actually traverse the pipeline and have no such notion |
| 685 | // as the input port. |
| 686 | if (in.port().equals(PortNumber.CONTROLLER)) { |
| 687 | StaticPacketTrace outputTrace = inputFromController(trace, in); |
| 688 | if (outputTrace != null) { |
| 689 | return trace; |
| 690 | } |
| 691 | } |
| 692 | |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame] | 693 | // Get the device state in the form of DataPlaneEntity objects - do not proceed if there is no state |
| 694 | List<DataPlaneEntity> dataPlaneEntities = getDataPlaneEntities(in.deviceId()); |
| 695 | if (dataPlaneEntities.isEmpty()) { |
| 696 | trace.addResultMessage("No device state for " + in.deviceId() + ". Aborting"); |
| 697 | TroubleshootUtils.computePath(completePath, trace, null); |
Andrea Campanella | 5af2d2b | 2018-03-12 19:25:44 -0700 | [diff] [blame] | 698 | trace.setSuccess(false); |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 699 | return trace; |
| 700 | } |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 701 | |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame] | 702 | // Applies pipeline processing |
pierventre | 4fd3b46 | 2020-10-15 17:31:44 +0200 | [diff] [blame^] | 703 | PipelineTraceableInput input = new PipelineTraceableInput(new PipelineTraceablePacket(packet), |
| 704 | in, dataPlaneEntities); |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame] | 705 | PipelineTraceableOutput output = pipelineMatchable.apply(input); |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 706 | |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame] | 707 | // Update the trace |
pierventre | 4fd3b46 | 2020-10-15 17:31:44 +0200 | [diff] [blame^] | 708 | List<PipelineTraceableHitChain> hitChains = output.hitChains(); |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame] | 709 | hitChains.forEach(hitChain -> trace.addHitChain(in.deviceId(), hitChain)); |
pierventre | 4fd3b46 | 2020-10-15 17:31:44 +0200 | [diff] [blame^] | 710 | trace.addResultMessage(output.log()); |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 711 | |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame] | 712 | // If there was an error set the success to false |
pierventre | 4fd3b46 | 2020-10-15 17:31:44 +0200 | [diff] [blame^] | 713 | if (output.result() != PipelineTraceableResult.SUCCESS) { |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame] | 714 | TroubleshootUtils.computePath(completePath, trace, null); |
| 715 | trace.setSuccess(false); |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 716 | } |
| 717 | |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame] | 718 | // We are done! |
Andrea Campanella | 08d07e1 | 2018-03-07 14:27:54 -0800 | [diff] [blame] | 719 | return trace; |
| 720 | } |
| 721 | |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame] | 722 | // Compute whether or not there are multiple routes. |
Andrea Campanella | 08d07e1 | 2018-03-07 14:27:54 -0800 | [diff] [blame] | 723 | private boolean multipleRoutes(StaticPacketTrace trace) { |
| 724 | boolean multipleRoutes = false; |
| 725 | IPCriterion ipCriterion = ((IPCriterion) trace.getInitialPacket().getCriterion(Criterion.Type.IPV4_DST)); |
| 726 | IpAddress ip = null; |
| 727 | if (ipCriterion != null) { |
| 728 | ip = ipCriterion.ip().address(); |
| 729 | } else if (trace.getInitialPacket().getCriterion(Criterion.Type.IPV6_DST) != null) { |
| 730 | ip = ((IPCriterion) trace.getInitialPacket().getCriterion(Criterion.Type.IPV6_DST)).ip().address(); |
Andrea Campanella | 54923d6 | 2018-01-23 12:46:04 +0100 | [diff] [blame] | 731 | } |
Andrea Campanella | dd71aca | 2018-04-04 13:10:45 +0200 | [diff] [blame] | 732 | if (ip != null) { |
Seyeon Jeong | 83e7986 | 2020-02-28 01:17:34 -0800 | [diff] [blame] | 733 | Optional<ResolvedRoute> optionalRoute = routeNib.longestPrefixLookup(ip); |
Andrea Campanella | dd71aca | 2018-04-04 13:10:45 +0200 | [diff] [blame] | 734 | if (optionalRoute.isPresent()) { |
| 735 | ResolvedRoute route = optionalRoute.get(); |
Seyeon Jeong | 83e7986 | 2020-02-28 01:17:34 -0800 | [diff] [blame] | 736 | multipleRoutes = routeNib.getAllResolvedRoutes(route.prefix()).size() > 1; |
Andrea Campanella | dd71aca | 2018-04-04 13:10:45 +0200 | [diff] [blame] | 737 | } |
Andrea Campanella | 8292ba6 | 2018-01-31 16:43:23 +0100 | [diff] [blame] | 738 | } |
Andrea Campanella | 08d07e1 | 2018-03-07 14:27:54 -0800 | [diff] [blame] | 739 | return multipleRoutes; |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 740 | } |
| 741 | |
Andrea Campanella | 1445f7a | 2018-02-07 12:00:12 +0100 | [diff] [blame] | 742 | /** |
| 743 | * Handles the specific case where the Input is the controller. |
| 744 | * Note that the in port is used as a convenience to store the port of the controller even if the packet in |
| 745 | * from a controller should not have a physical input port. The in port from the Controller is used to make sure |
| 746 | * the flood to all active physical ports of the device. |
| 747 | * |
| 748 | * @param trace the trace |
| 749 | * @param in the controller port |
| 750 | * @return the augmented trace. |
| 751 | */ |
| 752 | private StaticPacketTrace inputFromController(StaticPacketTrace trace, ConnectPoint in) { |
| 753 | EthTypeCriterion ethTypeCriterion = (EthTypeCriterion) trace.getInitialPacket() |
| 754 | .getCriterion(Criterion.Type.ETH_TYPE); |
| 755 | //If the packet is LLDP or BDDP we flood it on all active ports of the switch. |
| 756 | if (ethTypeCriterion != null && (ethTypeCriterion.ethType().equals(EtherType.LLDP.ethType()) |
| 757 | || ethTypeCriterion.ethType().equals(EtherType.BDDP.ethType()))) { |
| 758 | //get the active ports |
Seyeon Jeong | 83e7986 | 2020-02-28 01:17:34 -0800 | [diff] [blame] | 759 | List<Port> enabledPorts = deviceNib.getPorts(in.deviceId()).stream() |
Andrea Campanella | 1445f7a | 2018-02-07 12:00:12 +0100 | [diff] [blame] | 760 | .filter(Port::isEnabled) |
| 761 | .collect(Collectors.toList()); |
| 762 | //build an output from each one |
| 763 | enabledPorts.forEach(port -> { |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame] | 764 | PipelineTraceableHitChain hitChain = new PipelineTraceableHitChain( |
| 765 | new ConnectPoint(port.element().id(), port.number()), ImmutableList.of(), |
pierventre | 4fd3b46 | 2020-10-15 17:31:44 +0200 | [diff] [blame^] | 766 | new PipelineTraceablePacket(trace.getInitialPacket())); |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame] | 767 | trace.addHitChain(in.deviceId(), hitChain); |
Andrea Campanella | 1445f7a | 2018-02-07 12:00:12 +0100 | [diff] [blame] | 768 | }); |
| 769 | return trace; |
| 770 | } |
| 771 | return null; |
| 772 | } |
| 773 | |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame] | 774 | //////////////////////////////// |
| 775 | // Cemetery - Deprecated code // |
| 776 | //////////////////////////////// |
| 777 | @Override |
| 778 | public List<StaticPacketTrace> pingAll(EtherType type) { |
| 779 | ImmutableList.Builder<StaticPacketTrace> tracesBuilder = ImmutableList.builder(); |
| 780 | hostNib.getHosts().forEach(host -> { |
| 781 | List<IpAddress> ipAddresses = getIpAddresses(host, type, false); |
| 782 | if (ipAddresses.size() > 0) { |
| 783 | //check if the host has only local IPs of that ETH type |
| 784 | boolean onlyLocalSrc = ipAddresses.size() == 1 && ipAddresses.get(0).isLinkLocal(); |
| 785 | hostNib.getHosts().forEach(hostToPing -> { |
| 786 | List<IpAddress> ipAddressesToPing = getIpAddresses(hostToPing, type, false); |
| 787 | //check if the other host has only local IPs of that ETH type |
| 788 | boolean onlyLocalDst = ipAddressesToPing.size() == 1 && ipAddressesToPing.get(0).isLinkLocal(); |
| 789 | boolean sameLocation = Sets.intersection(host.locations(), hostToPing.locations()).size() > 0; |
| 790 | //Trace is done only if they are both local and under the same location |
| 791 | // or not local and if they are not the same host. |
| 792 | if (((sameLocation && onlyLocalDst && onlyLocalSrc) || |
| 793 | (!onlyLocalSrc && !onlyLocalDst && ipAddressesToPing.size() > 0)) |
| 794 | && !host.equals(hostToPing)) { |
| 795 | tracesBuilder.addAll(trace(host.id(), hostToPing.id(), type)); |
| 796 | } |
| 797 | }); |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 798 | } |
| 799 | }); |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame] | 800 | return tracesBuilder.build(); |
Simon Hunt | 026a287 | 2017-11-13 17:09:43 -0800 | [diff] [blame] | 801 | } |
Andrea Campanella | 4c6170a | 2018-01-17 16:34:51 +0100 | [diff] [blame] | 802 | |
pierventre | fe57fda | 2020-08-04 22:52:02 +0200 | [diff] [blame] | 803 | @Override |
| 804 | public List<Set<StaticPacketTrace>> getMulitcastTrace(VlanId vlanId) { |
| 805 | Generator<Set<StaticPacketTrace>> gen = new McastGenerator(mcastRouteNib, this, vlanId); |
| 806 | List<Set<StaticPacketTrace>> multicastTraceList = |
| 807 | StreamSupport.stream(gen.spliterator(), false).collect(Collectors.toList()); |
| 808 | return multicastTraceList; |
Andrea Campanella | 4c6170a | 2018-01-17 16:34:51 +0100 | [diff] [blame] | 809 | } |
| 810 | |
Simon Hunt | 026a287 | 2017-11-13 17:09:43 -0800 | [diff] [blame] | 811 | } |