Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [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; |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 17 | |
Jonathan Hart | 066244c | 2015-06-23 09:46:19 -0700 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableSet; |
| 19 | import com.google.common.collect.Sets; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 20 | import org.onosproject.net.ConnectPoint; |
| 21 | import org.onosproject.net.DeviceId; |
| 22 | import org.onosproject.net.Link; |
| 23 | import org.onosproject.net.Path; |
| 24 | import org.onosproject.net.intent.Intent; |
Jonathan Hart | 96c5a4a | 2015-07-31 14:23:33 -0700 | [diff] [blame] | 25 | import org.onosproject.net.intent.IntentException; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 26 | import org.onosproject.net.intent.LinkCollectionIntent; |
| 27 | import org.onosproject.net.intent.MultiPointToSinglePointIntent; |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 28 | import org.osgi.service.component.annotations.Activate; |
| 29 | import org.osgi.service.component.annotations.Component; |
| 30 | import org.osgi.service.component.annotations.Deactivate; |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 31 | |
Jonathan Hart | 066244c | 2015-06-23 09:46:19 -0700 | [diff] [blame] | 32 | import java.util.Collections; |
| 33 | import java.util.HashMap; |
| 34 | import java.util.List; |
| 35 | import java.util.Map; |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 36 | import java.util.stream.Collectors; |
| 37 | import java.util.stream.Stream; |
Ray Milkey | 6e0fb30 | 2015-04-16 14:44:12 -0700 | [diff] [blame] | 38 | |
Jonathan Hart | 96c5a4a | 2015-07-31 14:23:33 -0700 | [diff] [blame] | 39 | import static org.onosproject.net.intent.constraint.PartialFailureConstraint.intentAllowsPartialFailure; |
| 40 | |
| 41 | |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 42 | /** |
| 43 | * An intent compiler for |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 44 | * {@link org.onosproject.net.intent.MultiPointToSinglePointIntent}. |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 45 | */ |
| 46 | @Component(immediate = true) |
| 47 | public class MultiPointToSinglePointIntentCompiler |
Luca Prete | d26ea65 | 2017-01-03 15:59:30 -0800 | [diff] [blame] | 48 | extends ConnectivityIntentCompiler<MultiPointToSinglePointIntent> { |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 49 | |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 50 | @Activate |
| 51 | public void activate() { |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 52 | intentManager.registerCompiler(MultiPointToSinglePointIntent.class, this); |
| 53 | } |
| 54 | |
| 55 | @Deactivate |
| 56 | public void deactivate() { |
wu | 76a3d67 | 2017-04-11 14:06:44 +0800 | [diff] [blame] | 57 | intentManager.unregisterCompiler(MultiPointToSinglePointIntent.class); |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | @Override |
Sho SHIMIZU | ec07ffd | 2016-02-22 20:45:21 -0800 | [diff] [blame] | 61 | public List<Intent> compile(MultiPointToSinglePointIntent intent, List<Intent> installable) { |
Jonathan Hart | f5e3580 | 2014-12-01 20:45:18 -0800 | [diff] [blame] | 62 | Map<DeviceId, Link> links = new HashMap<>(); |
Ray Milkey | 6e0fb30 | 2015-04-16 14:44:12 -0700 | [diff] [blame] | 63 | ConnectPoint egressPoint = intent.egressPoint(); |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 64 | |
Jonathan Hart | 96c5a4a | 2015-07-31 14:23:33 -0700 | [diff] [blame] | 65 | final boolean allowMissingPaths = intentAllowsPartialFailure(intent); |
Luca Prete | d26ea65 | 2017-01-03 15:59:30 -0800 | [diff] [blame] | 66 | boolean hasPaths = false; |
| 67 | boolean missingSomePaths = false; |
| 68 | |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 69 | for (ConnectPoint ingressPoint : intent.ingressPoints()) { |
Ray Milkey | 6e0fb30 | 2015-04-16 14:44:12 -0700 | [diff] [blame] | 70 | if (ingressPoint.deviceId().equals(egressPoint.deviceId())) { |
Jonathan Hart | 96c5a4a | 2015-07-31 14:23:33 -0700 | [diff] [blame] | 71 | if (deviceService.isAvailable(ingressPoint.deviceId())) { |
Luca Prete | d26ea65 | 2017-01-03 15:59:30 -0800 | [diff] [blame] | 72 | hasPaths = true; |
Jonathan Hart | 96c5a4a | 2015-07-31 14:23:33 -0700 | [diff] [blame] | 73 | } else { |
Luca Prete | d26ea65 | 2017-01-03 15:59:30 -0800 | [diff] [blame] | 74 | missingSomePaths = true; |
Ray Milkey | 6e0fb30 | 2015-04-16 14:44:12 -0700 | [diff] [blame] | 75 | } |
Jonathan Hart | 96c5a4a | 2015-07-31 14:23:33 -0700 | [diff] [blame] | 76 | continue; |
Jonathan Hart | f5e3580 | 2014-12-01 20:45:18 -0800 | [diff] [blame] | 77 | } |
Jonathan Hart | 96c5a4a | 2015-07-31 14:23:33 -0700 | [diff] [blame] | 78 | |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 79 | Path path = getPath(intent, ingressPoint.deviceId(), egressPoint.deviceId()); |
Luca Prete | d26ea65 | 2017-01-03 15:59:30 -0800 | [diff] [blame] | 80 | |
Jonathan Hart | 96c5a4a | 2015-07-31 14:23:33 -0700 | [diff] [blame] | 81 | if (path != null) { |
Luca Prete | d26ea65 | 2017-01-03 15:59:30 -0800 | [diff] [blame] | 82 | hasPaths = true; |
Jonathan Hart | 96c5a4a | 2015-07-31 14:23:33 -0700 | [diff] [blame] | 83 | |
| 84 | for (Link link : path.links()) { |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 85 | if (links.containsKey(link.dst().deviceId())) { |
Jonathan Hart | 96c5a4a | 2015-07-31 14:23:33 -0700 | [diff] [blame] | 86 | // We've already reached the existing tree with the first |
| 87 | // part of this path. Add the merging point with different |
| 88 | // incoming port, but don't add the remainder of the path |
| 89 | // in case it differs from the path we already have. |
| 90 | links.put(link.src().deviceId(), link); |
| 91 | break; |
| 92 | } |
| 93 | links.put(link.src().deviceId(), link); |
| 94 | } |
| 95 | } else { |
Luca Prete | d26ea65 | 2017-01-03 15:59:30 -0800 | [diff] [blame] | 96 | missingSomePaths = true; |
Jonathan Hart | 96c5a4a | 2015-07-31 14:23:33 -0700 | [diff] [blame] | 97 | } |
| 98 | } |
| 99 | |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 100 | // Allocate bandwidth on existing paths if a bandwidth constraint is set |
| 101 | List<ConnectPoint> ingressCPs = |
| 102 | intent.filteredIngressPoints().stream() |
| 103 | .map(fcp -> fcp.connectPoint()) |
| 104 | .collect(Collectors.toList()); |
| 105 | ConnectPoint egressCP = intent.filteredEgressPoint().connectPoint(); |
| 106 | |
| 107 | List<ConnectPoint> pathCPs = |
| 108 | links.values().stream() |
| 109 | .flatMap(l -> Stream.of(l.src(), l.dst())) |
| 110 | .collect(Collectors.toList()); |
| 111 | |
| 112 | pathCPs.addAll(ingressCPs); |
| 113 | pathCPs.add(egressCP); |
| 114 | |
| 115 | allocateBandwidth(intent, pathCPs); |
| 116 | |
Luca Prete | d26ea65 | 2017-01-03 15:59:30 -0800 | [diff] [blame] | 117 | if (!hasPaths) { |
| 118 | throw new IntentException("Cannot find any path between ingress and egress points."); |
| 119 | } else if (!allowMissingPaths && missingSomePaths) { |
| 120 | throw new IntentException("Missing some paths between ingress and egress points."); |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 121 | } |
| 122 | |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 123 | Intent result = LinkCollectionIntent.builder() |
| 124 | .appId(intent.appId()) |
Yuta HIGUCHI | 652f27f | 2016-10-31 16:54:30 -0700 | [diff] [blame] | 125 | .key(intent.key()) |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 126 | .treatment(intent.treatment()) |
Pier Ventre | 973bb03 | 2016-10-11 08:57:39 -0700 | [diff] [blame] | 127 | .selector(intent.selector()) |
Jonathan Hart | 066244c | 2015-06-23 09:46:19 -0700 | [diff] [blame] | 128 | .links(Sets.newHashSet(links.values())) |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 129 | .filteredIngressPoints(intent.filteredIngressPoints()) |
| 130 | .filteredEgressPoints(ImmutableSet.of(intent.filteredEgressPoint())) |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 131 | .priority(intent.priority()) |
Sho SHIMIZU | 1b46a97 | 2015-04-10 17:33:00 -0700 | [diff] [blame] | 132 | .constraints(intent.constraints()) |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 133 | .resourceGroup(intent.resourceGroup()) |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 134 | .build(); |
| 135 | |
Sho SHIMIZU | 98ffca8 | 2015-05-11 08:39:24 -0700 | [diff] [blame] | 136 | return Collections.singletonList(result); |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 137 | } |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 138 | } |