blob: a5022a2130f11e0ecbfaa276c09813f68d9e320d [file] [log] [blame]
Andrea Campanellafa3ec192018-04-06 16:30:18 +02001/*
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
19import com.google.common.collect.ImmutableSet;
20import org.onlab.packet.EthType;
21import org.onlab.packet.IpAddress;
22import org.onlab.packet.MacAddress;
23import org.onlab.packet.VlanId;
24import org.onosproject.mcast.api.McastRouteData;
25import org.onosproject.mcast.api.MulticastRouteService;
26import org.onosproject.net.flow.DefaultTrafficSelector;
27import org.onosproject.net.flow.TrafficSelector;
28import org.onosproject.t3.api.StaticPacketTrace;
29import org.slf4j.Logger;
30
31import java.util.Set;
32
33import static org.slf4j.LoggerFactory.getLogger;
34
35/**
36 * Implementation of the generator class that yields a set of Packet Traces.
37 */
38public 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();
Andrea Campanella0ddf9b82018-04-27 15:54:42 +020066 routeData.sources().forEach((host, sources) -> {
67 sources.forEach(source -> {
68 TrafficSelector.Builder selector = DefaultTrafficSelector.builder()
69 .matchVlanId(vlanId)
70 .matchInPort(source.port());
71 if (group.isIp4()) {
72 selector.matchEthDst(IPV4_ADDRESS)
73 .matchIPDst(group.toIpPrefix())
74 .matchEthType(EthType.EtherType.IPV4.ethType().toShort());
75 } else {
76 selector.matchEthDst(IPV6_ADDRESS)
77 .matchIPv6Dst(group.toIpPrefix())
78 .matchEthType(EthType.EtherType.IPV6.ethType().toShort());
79 }
80 try {
81 yield(ImmutableSet.of(manager.trace(selector.build(), source)));
82 } catch (InterruptedException e) {
83 log.warn("Interrupted generator", e.getMessage());
84 log.debug("exception", e);
85 }
86 });
Andrea Campanellafa3ec192018-04-06 16:30:18 +020087 });
88
89 });
90
91 }
92}