blob: 91600ac046f9f833f12bb43283e893d466dd9a38 [file] [log] [blame]
alshabibab984662014-12-04 18:56:18 -08001/*
2 * Copyright 2014 Open Networking Laboratory
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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.intent.impl;
Michele Santuari4a338072014-11-05 18:38:55 +010017
18import java.util.Arrays;
19import 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;
33import org.onosproject.net.resource.LinkResourceAllocations;
Michele Santuari4a338072014-11-05 18:38:55 +010034
Pavlin Radoslavov1b787232015-02-23 15:07:31 -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
68 Intent result = new LinkCollectionIntent(intent.appId(),
69 intent.selector(),
70 intent.treatment(), links,
Pavlin Radoslavov1b787232015-02-23 15:07:31 -080071 ImmutableSet.of(intent.ingressPoint()),
Michele Santuari4a338072014-11-05 18:38:55 +010072 intent.egressPoints(), null);
73
74 return Arrays.asList(result);
75 }
76}