blob: 7520843bcdbd6b89e15c589a385a214fa07a1802 [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;
Andrea Campanellafa3ec192018-04-06 16:30:18 +020025import org.onosproject.net.flow.DefaultTrafficSelector;
26import org.onosproject.net.flow.TrafficSelector;
Seyeon Jeong357bcec2020-02-28 01:17:34 -080027import org.onosproject.t3.api.MulticastRouteNib;
Andrea Campanellafa3ec192018-04-06 16:30:18 +020028import 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");
Seyeon Jeongf394bb32020-03-03 17:33:40 -080043 private static final String NO_SINK = "There is no sink for this mcast route";
44 private static final String GENERATOR_ERROR =
45 "Generator for mcast route trace has benn interrupted. The trace result may be incomplete.";
Andrea Campanellafa3ec192018-04-06 16:30:18 +020046
Seyeon Jeong357bcec2020-02-28 01:17:34 -080047 private final MulticastRouteNib mcastRouteNib;
Andrea Campanellafa3ec192018-04-06 16:30:18 +020048 private final TroubleshootManager manager;
49 private final VlanId vlanId;
50
51 /**
52 * Creates a generator for obtaining traces of all configured multicast routes.
53 *
Seyeon Jeong357bcec2020-02-28 01:17:34 -080054 * @param mcastRouteNib the multicast route NIB
Andrea Campanellafa3ec192018-04-06 16:30:18 +020055 * @param manager the troubleshoot manager issuing the request.
56 * @param vlanId the multicast configured VlanId.
57 */
Seyeon Jeong357bcec2020-02-28 01:17:34 -080058 McastGenerator(MulticastRouteNib mcastRouteNib, TroubleshootManager manager, VlanId vlanId) {
59 this.mcastRouteNib = mcastRouteNib;
Andrea Campanellafa3ec192018-04-06 16:30:18 +020060 this.manager = manager;
61 this.vlanId = vlanId;
62 }
63
64 @Override
65 protected void run() {
Seyeon Jeong357bcec2020-02-28 01:17:34 -080066 mcastRouteNib.getRoutes().forEach(route -> {
67 McastRouteData routeData = mcastRouteNib.routeData(route);
Andrea Campanellafa3ec192018-04-06 16:30:18 +020068 IpAddress group = route.group();
Andrea Campanella0ddf9b82018-04-27 15:54:42 +020069 routeData.sources().forEach((host, sources) -> {
70 sources.forEach(source -> {
71 TrafficSelector.Builder selector = DefaultTrafficSelector.builder()
72 .matchVlanId(vlanId)
73 .matchInPort(source.port());
74 if (group.isIp4()) {
75 selector.matchEthDst(IPV4_ADDRESS)
76 .matchIPDst(group.toIpPrefix())
77 .matchEthType(EthType.EtherType.IPV4.ethType().toShort());
78 } else {
79 selector.matchEthDst(IPV6_ADDRESS)
80 .matchIPv6Dst(group.toIpPrefix())
81 .matchEthType(EthType.EtherType.IPV6.ethType().toShort());
82 }
Seyeon Jeongf394bb32020-03-03 17:33:40 -080083
84 StaticPacketTrace trace;
85 // check this mcast route has no sink
86 if (routeData.allSinks().size() == 0) {
87 trace = new StaticPacketTrace(selector.build(), source);
88 trace.addResultMessage(NO_SINK);
89 // tracing mcast route with no sink is not a failure
90 trace.setSuccess(true);
91 } else {
92 trace = manager.trace(selector.build(), source);
93 }
Andrea Campanella0ddf9b82018-04-27 15:54:42 +020094 try {
Seyeon Jeongf394bb32020-03-03 17:33:40 -080095 yield(ImmutableSet.of(trace));
Andrea Campanella0ddf9b82018-04-27 15:54:42 +020096 } catch (InterruptedException e) {
97 log.warn("Interrupted generator", e.getMessage());
98 log.debug("exception", e);
Seyeon Jeongf394bb32020-03-03 17:33:40 -080099 trace.setSuccess(false);
100 trace.addResultMessage(GENERATOR_ERROR);
Andrea Campanella0ddf9b82018-04-27 15:54:42 +0200101 }
102 });
Andrea Campanellafa3ec192018-04-06 16:30:18 +0200103 });
Andrea Campanellafa3ec192018-04-06 16:30:18 +0200104 });
Andrea Campanellafa3ec192018-04-06 16:30:18 +0200105 }
106}