Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame^] | 1 | package org.onosproject.net.intent.impl; |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 2 | |
| 3 | import java.util.Arrays; |
| 4 | import java.util.HashSet; |
| 5 | import java.util.List; |
| 6 | import java.util.Set; |
| 7 | |
| 8 | import org.apache.felix.scr.annotations.Activate; |
| 9 | import org.apache.felix.scr.annotations.Component; |
| 10 | import org.apache.felix.scr.annotations.Deactivate; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame^] | 11 | import org.onosproject.net.ConnectPoint; |
| 12 | import org.onosproject.net.Link; |
| 13 | import org.onosproject.net.Path; |
| 14 | import org.onosproject.net.intent.Intent; |
| 15 | import org.onosproject.net.intent.LinkCollectionIntent; |
| 16 | import org.onosproject.net.intent.SinglePointToMultiPointIntent; |
| 17 | import org.onosproject.net.provider.ProviderId; |
| 18 | import org.onosproject.net.resource.LinkResourceAllocations; |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 19 | |
| 20 | @Component(immediate = true) |
| 21 | public class SinglePointToMultiPointIntentCompiler |
| 22 | extends ConnectivityIntentCompiler<SinglePointToMultiPointIntent> { |
| 23 | |
| 24 | // TODO: use off-the-shell core provider ID |
| 25 | private static final ProviderId PID = |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame^] | 26 | new ProviderId("core", "org.onosproject.core", true); |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 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 | } |