alshabib | ab98466 | 2014-12-04 18:56:18 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
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; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 19 | import org.onosproject.net.ConnectPoint; |
| 20 | import org.onosproject.net.Link; |
| 21 | import org.onosproject.net.Path; |
| 22 | import org.onosproject.net.intent.Intent; |
Luca Prete | d26ea65 | 2017-01-03 15:59:30 -0800 | [diff] [blame] | 23 | import org.onosproject.net.intent.IntentException; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 24 | import org.onosproject.net.intent.LinkCollectionIntent; |
| 25 | import org.onosproject.net.intent.SinglePointToMultiPointIntent; |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame^] | 26 | import org.osgi.service.component.annotations.Activate; |
| 27 | import org.osgi.service.component.annotations.Component; |
| 28 | import org.osgi.service.component.annotations.Deactivate; |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 29 | |
Jonathan Hart | 066244c | 2015-06-23 09:46:19 -0700 | [diff] [blame] | 30 | import java.util.Collections; |
| 31 | import java.util.HashSet; |
| 32 | import java.util.List; |
| 33 | import java.util.Set; |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 34 | import java.util.stream.Collectors; |
| 35 | import java.util.stream.Stream; |
Pavlin Radoslavov | 2811c40 | 2015-02-25 14:30:17 -0800 | [diff] [blame] | 36 | |
Luca Prete | d26ea65 | 2017-01-03 15:59:30 -0800 | [diff] [blame] | 37 | import static org.onosproject.net.intent.constraint.PartialFailureConstraint.intentAllowsPartialFailure; |
| 38 | |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 39 | @Component(immediate = true) |
| 40 | public class SinglePointToMultiPointIntentCompiler |
| 41 | extends ConnectivityIntentCompiler<SinglePointToMultiPointIntent> { |
| 42 | |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 43 | @Activate |
| 44 | public void activate() { |
Luca Prete | d26ea65 | 2017-01-03 15:59:30 -0800 | [diff] [blame] | 45 | intentManager.registerCompiler(SinglePointToMultiPointIntent.class, this); |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | @Deactivate |
| 49 | public void deactivate() { |
| 50 | intentManager.unregisterCompiler(SinglePointToMultiPointIntent.class); |
| 51 | } |
| 52 | |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 53 | @Override |
| 54 | public List<Intent> compile(SinglePointToMultiPointIntent intent, |
Sho SHIMIZU | ec07ffd | 2016-02-22 20:45:21 -0800 | [diff] [blame] | 55 | List<Intent> installable) { |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 56 | Set<Link> links = new HashSet<>(); |
Jonathan Hart | 066244c | 2015-06-23 09:46:19 -0700 | [diff] [blame] | 57 | |
Luca Prete | d26ea65 | 2017-01-03 15:59:30 -0800 | [diff] [blame] | 58 | final boolean allowMissingPaths = intentAllowsPartialFailure(intent); |
| 59 | boolean hasPaths = false; |
| 60 | boolean missingSomePaths = false; |
| 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())) { |
Luca Prete | d26ea65 | 2017-01-03 15:59:30 -0800 | [diff] [blame] | 64 | // Do not need to look for paths, since ingress and egress |
| 65 | // devices are the same. |
| 66 | if (deviceService.isAvailable(egressPoint.deviceId())) { |
| 67 | hasPaths = true; |
| 68 | } else { |
| 69 | missingSomePaths = true; |
| 70 | } |
Jonathan Hart | 066244c | 2015-06-23 09:46:19 -0700 | [diff] [blame] | 71 | continue; |
| 72 | } |
| 73 | |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 74 | Path path = getPath(intent, intent.ingressPoint().deviceId(), egressPoint.deviceId()); |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 75 | |
Luca Prete | d26ea65 | 2017-01-03 15:59:30 -0800 | [diff] [blame] | 76 | if (path != null) { |
| 77 | hasPaths = true; |
| 78 | links.addAll(path.links()); |
| 79 | } else { |
| 80 | missingSomePaths = true; |
| 81 | } |
| 82 | } |
| 83 | |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 84 | // Allocate bandwidth if a bandwidth constraint is set |
| 85 | ConnectPoint ingressCP = intent.filteredIngressPoint().connectPoint(); |
| 86 | List<ConnectPoint> egressCPs = |
| 87 | intent.filteredEgressPoints().stream() |
| 88 | .map(fcp -> fcp.connectPoint()) |
| 89 | .collect(Collectors.toList()); |
| 90 | |
| 91 | List<ConnectPoint> pathCPs = |
| 92 | links.stream() |
| 93 | .flatMap(l -> Stream.of(l.src(), l.dst())) |
| 94 | .collect(Collectors.toList()); |
| 95 | |
| 96 | pathCPs.add(ingressCP); |
| 97 | pathCPs.addAll(egressCPs); |
| 98 | |
| 99 | allocateBandwidth(intent, pathCPs); |
| 100 | |
Luca Prete | d26ea65 | 2017-01-03 15:59:30 -0800 | [diff] [blame] | 101 | if (!hasPaths) { |
| 102 | throw new IntentException("Cannot find any path between ingress and egress points."); |
| 103 | } else if (!allowMissingPaths && missingSomePaths) { |
| 104 | throw new IntentException("Missing some paths between ingress and egress points."); |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 105 | } |
| 106 | |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 107 | Intent result = LinkCollectionIntent.builder() |
| 108 | .appId(intent.appId()) |
| 109 | .key(intent.key()) |
Pier Ventre | 973bb03 | 2016-10-11 08:57:39 -0700 | [diff] [blame] | 110 | .selector(intent.selector()) |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 111 | .treatment(intent.treatment()) |
| 112 | .links(links) |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 113 | .filteredIngressPoints(ImmutableSet.of(intent.filteredIngressPoint())) |
| 114 | .filteredEgressPoints(intent.filteredEgressPoints()) |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 115 | .priority(intent.priority()) |
Nicholas Dean | 126b8af | 2016-07-18 14:43:13 -0700 | [diff] [blame] | 116 | .applyTreatmentOnEgress(true) |
Sho SHIMIZU | 1b46a97 | 2015-04-10 17:33:00 -0700 | [diff] [blame] | 117 | .constraints(intent.constraints()) |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 118 | .resourceGroup(intent.resourceGroup()) |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 119 | .build(); |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 120 | |
Sho SHIMIZU | 98ffca8 | 2015-05-11 08:39:24 -0700 | [diff] [blame] | 121 | return Collections.singletonList(result); |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 122 | } |
Nicholas Dean | 126b8af | 2016-07-18 14:43:13 -0700 | [diff] [blame] | 123 | } |