blob: 91341d20546e05080d8f79f18295b5d9846365c0 [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
Sho SHIMIZU98ffca82015-05-11 08:39:24 -070018import java.util.Collections;
Michele Santuari4a338072014-11-05 18:38:55 +010019import java.util.HashSet;
20import java.util.List;
21import java.util.Set;
22
23import org.apache.felix.scr.annotations.Activate;
24import org.apache.felix.scr.annotations.Component;
25import org.apache.felix.scr.annotations.Deactivate;
Brian O'Connorabafb502014-12-02 22:26:20 -080026import org.onosproject.net.ConnectPoint;
27import org.onosproject.net.Link;
28import org.onosproject.net.Path;
29import org.onosproject.net.intent.Intent;
30import org.onosproject.net.intent.LinkCollectionIntent;
31import org.onosproject.net.intent.SinglePointToMultiPointIntent;
32import org.onosproject.net.provider.ProviderId;
Brian O'Connor6de2e202015-05-21 14:30:41 -070033import org.onosproject.net.resource.link.LinkResourceAllocations;
Michele Santuari4a338072014-11-05 18:38:55 +010034
Pavlin Radoslavov2811c402015-02-25 14:30:17 -080035import com.google.common.collect.ImmutableSet;
36
Michele Santuari4a338072014-11-05 18:38:55 +010037@Component(immediate = true)
38public class SinglePointToMultiPointIntentCompiler
39 extends ConnectivityIntentCompiler<SinglePointToMultiPointIntent> {
40
41 // TODO: use off-the-shell core provider ID
42 private static final ProviderId PID =
Brian O'Connorabafb502014-12-02 22:26:20 -080043 new ProviderId("core", "org.onosproject.core", true);
Michele Santuari4a338072014-11-05 18:38:55 +010044
45 @Activate
46 public void activate() {
47 intentManager.registerCompiler(SinglePointToMultiPointIntent.class,
48 this);
49 }
50
51 @Deactivate
52 public void deactivate() {
53 intentManager.unregisterCompiler(SinglePointToMultiPointIntent.class);
54 }
55
56
57 @Override
58 public List<Intent> compile(SinglePointToMultiPointIntent intent,
59 List<Intent> installable,
60 Set<LinkResourceAllocations> resources) {
61 Set<Link> links = new HashSet<>();
62 //FIXME: need to handle the case where ingress/egress points are on same switch
63 for (ConnectPoint egressPoint : intent.egressPoints()) {
64 Path path = getPath(intent, intent.ingressPoint().deviceId(), egressPoint.deviceId());
65 links.addAll(path.links());
66 }
67
Ray Milkeyebc5d222015-03-18 15:45:36 -070068 Intent result = LinkCollectionIntent.builder()
69 .appId(intent.appId())
70 .key(intent.key())
71 .selector(intent.selector())
72 .treatment(intent.treatment())
73 .links(links)
74 .ingressPoints(ImmutableSet.of(intent.ingressPoint()))
75 .egressPoints(intent.egressPoints())
76 .priority(intent.priority())
Sho SHIMIZU1b46a972015-04-10 17:33:00 -070077 .constraints(intent.constraints())
Ray Milkeyebc5d222015-03-18 15:45:36 -070078 .build();
Michele Santuari4a338072014-11-05 18:38:55 +010079
Sho SHIMIZU98ffca82015-05-11 08:39:24 -070080 return Collections.singletonList(result);
Michele Santuari4a338072014-11-05 18:38:55 +010081 }
82}