blob: 780de09d3b9c97d3e7b29cb58ef6c94ec6e6c060 [file] [log] [blame]
Andrea Campanellabd15bf52018-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;
pierventrefe57fda2020-08-04 22:52:02 +020024import org.onlab.util.Generator;
Andrea Campanellabd15bf52018-04-06 16:30:18 +020025import org.onosproject.mcast.api.McastRouteData;
Andrea Campanellabd15bf52018-04-06 16:30:18 +020026import org.onosproject.net.flow.DefaultTrafficSelector;
27import org.onosproject.net.flow.TrafficSelector;
Seyeon Jeong83e79862020-02-28 01:17:34 -080028import org.onosproject.t3.api.MulticastRouteNib;
Andrea Campanellabd15bf52018-04-06 16:30:18 +020029import org.onosproject.t3.api.StaticPacketTrace;
30import org.slf4j.Logger;
31
32import java.util.Set;
33
34import static org.slf4j.LoggerFactory.getLogger;
35
36/**
37 * Implementation of the generator class that yields a set of Packet Traces.
38 */
39public class McastGenerator extends Generator<Set<StaticPacketTrace>> {
40
41 private static final Logger log = getLogger(McastGenerator.class);
42 protected static final MacAddress IPV4_ADDRESS = MacAddress.valueOf("01:00:5E:00:00:00");
43 protected static final MacAddress IPV6_ADDRESS = MacAddress.valueOf("33:33:00:00:00:00");
Seyeon Jeongf84f8062020-03-03 17:33:40 -080044 private static final String NO_SINK = "There is no sink for this mcast route";
45 private static final String GENERATOR_ERROR =
46 "Generator for mcast route trace has benn interrupted. The trace result may be incomplete.";
Andrea Campanellabd15bf52018-04-06 16:30:18 +020047
Seyeon Jeong83e79862020-02-28 01:17:34 -080048 private final MulticastRouteNib mcastRouteNib;
Andrea Campanellabd15bf52018-04-06 16:30:18 +020049 private final TroubleshootManager manager;
50 private final VlanId vlanId;
51
52 /**
53 * Creates a generator for obtaining traces of all configured multicast routes.
54 *
Seyeon Jeong83e79862020-02-28 01:17:34 -080055 * @param mcastRouteNib the multicast route NIB
Andrea Campanellabd15bf52018-04-06 16:30:18 +020056 * @param manager the troubleshoot manager issuing the request.
57 * @param vlanId the multicast configured VlanId.
58 */
Seyeon Jeong83e79862020-02-28 01:17:34 -080059 McastGenerator(MulticastRouteNib mcastRouteNib, TroubleshootManager manager, VlanId vlanId) {
60 this.mcastRouteNib = mcastRouteNib;
Andrea Campanellabd15bf52018-04-06 16:30:18 +020061 this.manager = manager;
62 this.vlanId = vlanId;
63 }
64
65 @Override
66 protected void run() {
Seyeon Jeong83e79862020-02-28 01:17:34 -080067 mcastRouteNib.getRoutes().forEach(route -> {
68 McastRouteData routeData = mcastRouteNib.routeData(route);
Andrea Campanellabd15bf52018-04-06 16:30:18 +020069 IpAddress group = route.group();
Andrea Campanellae1b50162018-04-27 15:54:42 +020070 routeData.sources().forEach((host, sources) -> {
71 sources.forEach(source -> {
72 TrafficSelector.Builder selector = DefaultTrafficSelector.builder()
73 .matchVlanId(vlanId)
74 .matchInPort(source.port());
75 if (group.isIp4()) {
76 selector.matchEthDst(IPV4_ADDRESS)
77 .matchIPDst(group.toIpPrefix())
78 .matchEthType(EthType.EtherType.IPV4.ethType().toShort());
79 } else {
80 selector.matchEthDst(IPV6_ADDRESS)
81 .matchIPv6Dst(group.toIpPrefix())
82 .matchEthType(EthType.EtherType.IPV6.ethType().toShort());
83 }
Seyeon Jeongf84f8062020-03-03 17:33:40 -080084
85 StaticPacketTrace trace;
86 // check this mcast route has no sink
87 if (routeData.allSinks().size() == 0) {
88 trace = new StaticPacketTrace(selector.build(), source);
89 trace.addResultMessage(NO_SINK);
90 // tracing mcast route with no sink is not a failure
91 trace.setSuccess(true);
92 } else {
93 trace = manager.trace(selector.build(), source);
94 }
Andrea Campanellae1b50162018-04-27 15:54:42 +020095 try {
Seyeon Jeongf84f8062020-03-03 17:33:40 -080096 yield(ImmutableSet.of(trace));
Andrea Campanellae1b50162018-04-27 15:54:42 +020097 } catch (InterruptedException e) {
98 log.warn("Interrupted generator", e.getMessage());
99 log.debug("exception", e);
Seyeon Jeongf84f8062020-03-03 17:33:40 -0800100 trace.setSuccess(false);
101 trace.addResultMessage(GENERATOR_ERROR);
Andrea Campanellae1b50162018-04-27 15:54:42 +0200102 }
103 });
Andrea Campanellabd15bf52018-04-06 16:30:18 +0200104 });
Andrea Campanellabd15bf52018-04-06 16:30:18 +0200105 });
Andrea Campanellabd15bf52018-04-06 16:30:18 +0200106 }
107}