blob: 76640f2dea57609a2d36524315d2b80d7887e300 [file] [log] [blame]
alshabibab984662014-12-04 18:56:18 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
alshabibab984662014-12-04 18:56:18 -08003 *
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 */
Sho SHIMIZU6c28f832015-02-20 16:12:19 -080016package org.onosproject.net.intent.impl.compiler;
Michele Santuari4a338072014-11-05 18:38:55 +010017
Jonathan Hart066244c2015-06-23 09:46:19 -070018import com.google.common.collect.ImmutableSet;
Michele Santuari4a338072014-11-05 18:38:55 +010019import org.apache.felix.scr.annotations.Activate;
20import org.apache.felix.scr.annotations.Component;
21import org.apache.felix.scr.annotations.Deactivate;
Brian O'Connorabafb502014-12-02 22:26:20 -080022import org.onosproject.net.ConnectPoint;
23import org.onosproject.net.Link;
24import org.onosproject.net.Path;
25import org.onosproject.net.intent.Intent;
26import org.onosproject.net.intent.LinkCollectionIntent;
27import org.onosproject.net.intent.SinglePointToMultiPointIntent;
28import org.onosproject.net.provider.ProviderId;
Michele Santuari4a338072014-11-05 18:38:55 +010029
Jonathan Hart066244c2015-06-23 09:46:19 -070030import java.util.Collections;
31import java.util.HashSet;
32import java.util.List;
33import java.util.Set;
Pavlin Radoslavov2811c402015-02-25 14:30:17 -080034
Michele Santuari4a338072014-11-05 18:38:55 +010035@Component(immediate = true)
36public class SinglePointToMultiPointIntentCompiler
37 extends ConnectivityIntentCompiler<SinglePointToMultiPointIntent> {
38
39 // TODO: use off-the-shell core provider ID
40 private static final ProviderId PID =
Brian O'Connorabafb502014-12-02 22:26:20 -080041 new ProviderId("core", "org.onosproject.core", true);
Michele Santuari4a338072014-11-05 18:38:55 +010042
43 @Activate
44 public void activate() {
45 intentManager.registerCompiler(SinglePointToMultiPointIntent.class,
46 this);
47 }
48
49 @Deactivate
50 public void deactivate() {
51 intentManager.unregisterCompiler(SinglePointToMultiPointIntent.class);
52 }
53
54
55 @Override
56 public List<Intent> compile(SinglePointToMultiPointIntent intent,
Sho SHIMIZUec07ffd2016-02-22 20:45:21 -080057 List<Intent> installable) {
Michele Santuari4a338072014-11-05 18:38:55 +010058 Set<Link> links = new HashSet<>();
Jonathan Hart066244c2015-06-23 09:46:19 -070059
Michele Santuari4a338072014-11-05 18:38:55 +010060 for (ConnectPoint egressPoint : intent.egressPoints()) {
Jonathan Hart066244c2015-06-23 09:46:19 -070061 if (egressPoint.deviceId().equals(intent.ingressPoint().deviceId())) {
62 continue;
63 }
64
Michele Santuari4a338072014-11-05 18:38:55 +010065 Path path = getPath(intent, intent.ingressPoint().deviceId(), egressPoint.deviceId());
66 links.addAll(path.links());
67 }
68
Ray Milkeyebc5d222015-03-18 15:45:36 -070069 Intent result = LinkCollectionIntent.builder()
70 .appId(intent.appId())
71 .key(intent.key())
72 .selector(intent.selector())
73 .treatment(intent.treatment())
74 .links(links)
75 .ingressPoints(ImmutableSet.of(intent.ingressPoint()))
76 .egressPoints(intent.egressPoints())
77 .priority(intent.priority())
Nicholas Dean126b8af2016-07-18 14:43:13 -070078 .applyTreatmentOnEgress(true)
Sho SHIMIZU1b46a972015-04-10 17:33:00 -070079 .constraints(intent.constraints())
Pier Ventre27d42572016-08-29 17:37:08 -070080 .egressTreatments(intent.egressTreatments())
Ray Milkeyebc5d222015-03-18 15:45:36 -070081 .build();
Michele Santuari4a338072014-11-05 18:38:55 +010082
Sho SHIMIZU98ffca82015-05-11 08:39:24 -070083 return Collections.singletonList(result);
Michele Santuari4a338072014-11-05 18:38:55 +010084 }
Nicholas Dean126b8af2016-07-18 14:43:13 -070085}