blob: 56565908ffb6d794d22ef82f27d8077ccce49baf [file] [log] [blame]
alshabibab984662014-12-04 18:56:18 -08001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 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;
Brian O'Connor6de2e202015-05-21 14:30:41 -070029import org.onosproject.net.resource.link.LinkResourceAllocations;
Michele Santuari4a338072014-11-05 18:38:55 +010030
Jonathan Hart066244c2015-06-23 09:46:19 -070031import java.util.Collections;
32import java.util.HashSet;
33import java.util.List;
34import java.util.Set;
Pavlin Radoslavov2811c402015-02-25 14:30:17 -080035
Michele Santuari4a338072014-11-05 18:38:55 +010036@Component(immediate = true)
37public class SinglePointToMultiPointIntentCompiler
38 extends ConnectivityIntentCompiler<SinglePointToMultiPointIntent> {
39
40 // TODO: use off-the-shell core provider ID
41 private static final ProviderId PID =
Brian O'Connorabafb502014-12-02 22:26:20 -080042 new ProviderId("core", "org.onosproject.core", true);
Michele Santuari4a338072014-11-05 18:38:55 +010043
44 @Activate
45 public void activate() {
46 intentManager.registerCompiler(SinglePointToMultiPointIntent.class,
47 this);
48 }
49
50 @Deactivate
51 public void deactivate() {
52 intentManager.unregisterCompiler(SinglePointToMultiPointIntent.class);
53 }
54
55
56 @Override
57 public List<Intent> compile(SinglePointToMultiPointIntent intent,
58 List<Intent> installable,
59 Set<LinkResourceAllocations> resources) {
60 Set<Link> links = new HashSet<>();
Jonathan Hart066244c2015-06-23 09:46:19 -070061
Michele Santuari4a338072014-11-05 18:38:55 +010062 for (ConnectPoint egressPoint : intent.egressPoints()) {
Jonathan Hart066244c2015-06-23 09:46:19 -070063 if (egressPoint.deviceId().equals(intent.ingressPoint().deviceId())) {
64 continue;
65 }
66
Michele Santuari4a338072014-11-05 18:38:55 +010067 Path path = getPath(intent, intent.ingressPoint().deviceId(), egressPoint.deviceId());
68 links.addAll(path.links());
69 }
70
Ray Milkeyebc5d222015-03-18 15:45:36 -070071 Intent result = LinkCollectionIntent.builder()
72 .appId(intent.appId())
73 .key(intent.key())
74 .selector(intent.selector())
75 .treatment(intent.treatment())
76 .links(links)
77 .ingressPoints(ImmutableSet.of(intent.ingressPoint()))
78 .egressPoints(intent.egressPoints())
79 .priority(intent.priority())
Sho SHIMIZU1b46a972015-04-10 17:33:00 -070080 .constraints(intent.constraints())
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 }
85}