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.impl; |
| 18 | |
| 19 | import com.google.common.collect.ImmutableSet; |
| 20 | import org.onlab.packet.EthType; |
| 21 | import org.onlab.packet.IpAddress; |
| 22 | import org.onlab.packet.MacAddress; |
| 23 | import org.onlab.packet.VlanId; |
| 24 | import org.onosproject.mcast.api.McastRouteData; |
| 25 | import org.onosproject.mcast.api.MulticastRouteService; |
| 26 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 27 | import org.onosproject.net.flow.TrafficSelector; |
| 28 | import org.onosproject.t3.api.StaticPacketTrace; |
| 29 | import org.slf4j.Logger; |
| 30 | |
| 31 | import java.util.Set; |
| 32 | |
| 33 | import static org.slf4j.LoggerFactory.getLogger; |
| 34 | |
| 35 | /** |
| 36 | * Implementation of the generator class that yields a set of Packet Traces. |
| 37 | */ |
| 38 | public class McastGenerator extends Generator<Set<StaticPacketTrace>> { |
| 39 | |
| 40 | private static final Logger log = getLogger(McastGenerator.class); |
| 41 | protected static final MacAddress IPV4_ADDRESS = MacAddress.valueOf("01:00:5E:00:00:00"); |
| 42 | protected static final MacAddress IPV6_ADDRESS = MacAddress.valueOf("33:33:00:00:00:00"); |
| 43 | |
| 44 | private final MulticastRouteService mcastService; |
| 45 | private final TroubleshootManager manager; |
| 46 | private final VlanId vlanId; |
| 47 | |
| 48 | /** |
| 49 | * Creates a generator for obtaining traces of all configured multicast routes. |
| 50 | * |
| 51 | * @param service the host service |
| 52 | * @param manager the troubleshoot manager issuing the request. |
| 53 | * @param vlanId the multicast configured VlanId. |
| 54 | */ |
| 55 | McastGenerator(MulticastRouteService service, TroubleshootManager manager, VlanId vlanId) { |
| 56 | this.mcastService = service; |
| 57 | this.manager = manager; |
| 58 | this.vlanId = vlanId; |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | protected void run() { |
| 63 | mcastService.getRoutes().forEach(route -> { |
| 64 | McastRouteData routeData = mcastService.routeData(route); |
| 65 | IpAddress group = route.group(); |
| 66 | routeData.sources().forEach(source -> { |
| 67 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder() |
| 68 | .matchVlanId(vlanId) |
| 69 | .matchInPort(source.port()); |
| 70 | if (group.isIp4()) { |
| 71 | selector.matchEthDst(IPV4_ADDRESS) |
| 72 | .matchIPDst(group.toIpPrefix()) |
| 73 | .matchEthType(EthType.EtherType.IPV4.ethType().toShort()); |
| 74 | } else { |
| 75 | selector.matchEthDst(IPV6_ADDRESS) |
| 76 | .matchIPv6Dst(group.toIpPrefix()) |
| 77 | .matchEthType(EthType.EtherType.IPV6.ethType().toShort()); |
| 78 | } |
| 79 | try { |
| 80 | yield(ImmutableSet.of(manager.trace(selector.build(), source))); |
| 81 | } catch (InterruptedException e) { |
| 82 | log.warn("Interrupted generator", e.getMessage()); |
| 83 | log.debug("exception", e); |
| 84 | } |
| 85 | }); |
| 86 | |
| 87 | }); |
| 88 | |
| 89 | } |
| 90 | } |