alshabib | ab98466 | 2014-12-04 18:56:18 -0800 | [diff] [blame] | 1 | /* |
| 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'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.intent.impl; |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 17 | |
| 18 | import java.util.Arrays; |
Sho SHIMIZU | a15546f | 2015-01-19 18:26:27 -0800 | [diff] [blame] | 19 | import java.util.Collections; |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 20 | import java.util.HashSet; |
| 21 | import java.util.List; |
| 22 | import java.util.Set; |
| 23 | |
| 24 | import org.apache.felix.scr.annotations.Activate; |
| 25 | import org.apache.felix.scr.annotations.Component; |
| 26 | import org.apache.felix.scr.annotations.Deactivate; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 27 | import org.onosproject.net.ConnectPoint; |
| 28 | import org.onosproject.net.Link; |
| 29 | import org.onosproject.net.Path; |
| 30 | import org.onosproject.net.intent.Intent; |
| 31 | import org.onosproject.net.intent.LinkCollectionIntent; |
| 32 | import org.onosproject.net.intent.SinglePointToMultiPointIntent; |
| 33 | import org.onosproject.net.provider.ProviderId; |
| 34 | import org.onosproject.net.resource.LinkResourceAllocations; |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 35 | |
| 36 | @Component(immediate = true) |
| 37 | public class SinglePointToMultiPointIntentCompiler |
| 38 | extends ConnectivityIntentCompiler<SinglePointToMultiPointIntent> { |
| 39 | |
| 40 | // TODO: use off-the-shell core provider ID |
| 41 | private static final ProviderId PID = |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 42 | new ProviderId("core", "org.onosproject.core", true); |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 43 | |
| 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 SHIMIZU | a15546f | 2015-01-19 18:26:27 -0800 | [diff] [blame] | 70 | intent.egressPoints(), Collections.emptyList()); |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 71 | |
| 72 | return Arrays.asList(result); |
| 73 | } |
| 74 | } |