blob: fd344e2c15620a54470436f056fdd759102f1873 [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 */
Sho SHIMIZU6c28f832015-02-20 16:12:19 -080016package org.onosproject.net.intent.impl.compiler;
Michele Santuari4a338072014-11-05 18:38:55 +010017
18import java.util.Arrays;
Sho SHIMIZUa15546f2015-01-19 18:26:27 -080019import java.util.Collections;
Michele Santuari4a338072014-11-05 18:38:55 +010020import java.util.HashSet;
21import java.util.List;
22import java.util.Set;
23
24import org.apache.felix.scr.annotations.Activate;
25import org.apache.felix.scr.annotations.Component;
26import org.apache.felix.scr.annotations.Deactivate;
Brian O'Connorabafb502014-12-02 22:26:20 -080027import org.onosproject.net.ConnectPoint;
28import org.onosproject.net.Link;
29import org.onosproject.net.Path;
30import org.onosproject.net.intent.Intent;
31import org.onosproject.net.intent.LinkCollectionIntent;
32import org.onosproject.net.intent.SinglePointToMultiPointIntent;
33import org.onosproject.net.provider.ProviderId;
34import org.onosproject.net.resource.LinkResourceAllocations;
Michele Santuari4a338072014-11-05 18:38:55 +010035
36@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<>();
61 //FIXME: need to handle the case where ingress/egress points are on same switch
62 for (ConnectPoint egressPoint : intent.egressPoints()) {
63 Path path = getPath(intent, intent.ingressPoint().deviceId(), egressPoint.deviceId());
64 links.addAll(path.links());
65 }
66
67 Intent result = new LinkCollectionIntent(intent.appId(),
68 intent.selector(),
69 intent.treatment(), links,
Sho SHIMIZUa15546f2015-01-19 18:26:27 -080070 intent.egressPoints(), Collections.emptyList());
Michele Santuari4a338072014-11-05 18:38:55 +010071
72 return Arrays.asList(result);
73 }
74}