blob: f6e330c9a60db486aa4c628c9123bde8c2b37eec [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
35@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,
57 List<Intent> installable,
58 Set<LinkResourceAllocations> resources) {
59 Set<Link> links = new HashSet<>();
60 //FIXME: need to handle the case where ingress/egress points are on same switch
61 for (ConnectPoint egressPoint : intent.egressPoints()) {
62 Path path = getPath(intent, intent.ingressPoint().deviceId(), egressPoint.deviceId());
63 links.addAll(path.links());
64 }
65
66 Intent result = new LinkCollectionIntent(intent.appId(),
67 intent.selector(),
68 intent.treatment(), links,
69 intent.egressPoints(), null);
70
71 return Arrays.asList(result);
72 }
73}