blob: 8360820f02757b8368e13a95a1ec64dc97b76124 [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
Pavlin Radoslavov2811c402015-02-25 14:30:17 -080036import com.google.common.collect.ImmutableSet;
37
Michele Santuari4a338072014-11-05 18:38:55 +010038@Component(immediate = true)
39public class SinglePointToMultiPointIntentCompiler
40 extends ConnectivityIntentCompiler<SinglePointToMultiPointIntent> {
41
42 // TODO: use off-the-shell core provider ID
43 private static final ProviderId PID =
Brian O'Connorabafb502014-12-02 22:26:20 -080044 new ProviderId("core", "org.onosproject.core", true);
Michele Santuari4a338072014-11-05 18:38:55 +010045
46 @Activate
47 public void activate() {
48 intentManager.registerCompiler(SinglePointToMultiPointIntent.class,
49 this);
50 }
51
52 @Deactivate
53 public void deactivate() {
54 intentManager.unregisterCompiler(SinglePointToMultiPointIntent.class);
55 }
56
57
58 @Override
59 public List<Intent> compile(SinglePointToMultiPointIntent intent,
60 List<Intent> installable,
61 Set<LinkResourceAllocations> resources) {
62 Set<Link> links = new HashSet<>();
63 //FIXME: need to handle the case where ingress/egress points are on same switch
64 for (ConnectPoint egressPoint : intent.egressPoints()) {
65 Path path = getPath(intent, intent.ingressPoint().deviceId(), egressPoint.deviceId());
66 links.addAll(path.links());
67 }
68
69 Intent result = new LinkCollectionIntent(intent.appId(),
70 intent.selector(),
71 intent.treatment(), links,
Pavlin Radoslavov2811c402015-02-25 14:30:17 -080072 ImmutableSet.of(intent.ingressPoint()),
Sho SHIMIZUa15546f2015-01-19 18:26:27 -080073 intent.egressPoints(), Collections.emptyList());
Michele Santuari4a338072014-11-05 18:38:55 +010074
75 return Arrays.asList(result);
76 }
77}