alshabib | ab98466 | 2014-12-04 18:56:18 -0800 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
alshabib | ab98466 | 2014-12-04 18:56:18 -0800 | [diff] [blame] | 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 SHIMIZU | 6c28f83 | 2015-02-20 16:12:19 -0800 | [diff] [blame] | 16 | package org.onosproject.net.intent.impl.compiler; |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 17 | |
Jonathan Hart | 066244c | 2015-06-23 09:46:19 -0700 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableSet; |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 19 | import org.apache.felix.scr.annotations.Activate; |
| 20 | import org.apache.felix.scr.annotations.Component; |
| 21 | import org.apache.felix.scr.annotations.Deactivate; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 22 | import org.onosproject.net.ConnectPoint; |
| 23 | import org.onosproject.net.Link; |
| 24 | import org.onosproject.net.Path; |
| 25 | import org.onosproject.net.intent.Intent; |
| 26 | import org.onosproject.net.intent.LinkCollectionIntent; |
| 27 | import org.onosproject.net.intent.SinglePointToMultiPointIntent; |
| 28 | import org.onosproject.net.provider.ProviderId; |
Brian O'Connor | 6de2e20 | 2015-05-21 14:30:41 -0700 | [diff] [blame] | 29 | import org.onosproject.net.resource.link.LinkResourceAllocations; |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 30 | |
Jonathan Hart | 066244c | 2015-06-23 09:46:19 -0700 | [diff] [blame] | 31 | import java.util.Collections; |
| 32 | import java.util.HashSet; |
| 33 | import java.util.List; |
| 34 | import java.util.Set; |
Pavlin Radoslavov | 2811c40 | 2015-02-25 14:30:17 -0800 | [diff] [blame] | 35 | |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 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<>(); |
Jonathan Hart | 066244c | 2015-06-23 09:46:19 -0700 | [diff] [blame] | 61 | |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 62 | for (ConnectPoint egressPoint : intent.egressPoints()) { |
Jonathan Hart | 066244c | 2015-06-23 09:46:19 -0700 | [diff] [blame] | 63 | if (egressPoint.deviceId().equals(intent.ingressPoint().deviceId())) { |
| 64 | continue; |
| 65 | } |
| 66 | |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 67 | Path path = getPath(intent, intent.ingressPoint().deviceId(), egressPoint.deviceId()); |
| 68 | links.addAll(path.links()); |
| 69 | } |
| 70 | |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 71 | Intent result = LinkCollectionIntent.builder() |
| 72 | .appId(intent.appId()) |
| 73 | .key(intent.key()) |
| 74 | .selector(intent.selector()) |
| 75 | .treatment(intent.treatment()) |
| 76 | .links(links) |
| 77 | .ingressPoints(ImmutableSet.of(intent.ingressPoint())) |
| 78 | .egressPoints(intent.egressPoints()) |
| 79 | .priority(intent.priority()) |
Sho SHIMIZU | 1b46a97 | 2015-04-10 17:33:00 -0700 | [diff] [blame] | 80 | .constraints(intent.constraints()) |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 81 | .build(); |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 82 | |
Sho SHIMIZU | 98ffca8 | 2015-05-11 08:39:24 -0700 | [diff] [blame] | 83 | return Collections.singletonList(result); |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 84 | } |
| 85 | } |