blob: 46689ec0d386568ec6dd86f4f3a166ce7b30c3e8 [file] [log] [blame]
Michele Santuari4a338072014-11-05 18:38:55 +01001package org.onlab.onos.net.intent.impl;
2
3import java.util.Arrays;
4import java.util.HashSet;
5import java.util.List;
6import java.util.Set;
7
8import org.apache.felix.scr.annotations.Activate;
9import org.apache.felix.scr.annotations.Component;
10import org.apache.felix.scr.annotations.Deactivate;
11import org.onlab.onos.net.ConnectPoint;
12import org.onlab.onos.net.Link;
13import org.onlab.onos.net.Path;
14import org.onlab.onos.net.intent.Intent;
15import org.onlab.onos.net.intent.LinkCollectionIntent;
16import org.onlab.onos.net.intent.SinglePointToMultiPointIntent;
17import org.onlab.onos.net.provider.ProviderId;
18import org.onlab.onos.net.resource.LinkResourceAllocations;
19
20@Component(immediate = true)
21public class SinglePointToMultiPointIntentCompiler
22 extends ConnectivityIntentCompiler<SinglePointToMultiPointIntent> {
23
24 // TODO: use off-the-shell core provider ID
25 private static final ProviderId PID =
26 new ProviderId("core", "org.onlab.onos.core", true);
27
28 @Activate
29 public void activate() {
30 intentManager.registerCompiler(SinglePointToMultiPointIntent.class,
31 this);
32 }
33
34 @Deactivate
35 public void deactivate() {
36 intentManager.unregisterCompiler(SinglePointToMultiPointIntent.class);
37 }
38
39
40 @Override
41 public List<Intent> compile(SinglePointToMultiPointIntent intent,
42 List<Intent> installable,
43 Set<LinkResourceAllocations> resources) {
44 Set<Link> links = new HashSet<>();
45 //FIXME: need to handle the case where ingress/egress points are on same switch
46 for (ConnectPoint egressPoint : intent.egressPoints()) {
47 Path path = getPath(intent, intent.ingressPoint().deviceId(), egressPoint.deviceId());
48 links.addAll(path.links());
49 }
50
51 Intent result = new LinkCollectionIntent(intent.appId(),
52 intent.selector(),
53 intent.treatment(), links,
54 intent.egressPoints(), null);
55
56 return Arrays.asList(result);
57 }
58}