Jonathan Hart | 96c5a4a | 2015-07-31 14:23:33 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Jonathan Hart | 96c5a4a | 2015-07-31 14:23:33 -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 | */ |
| 16 | package org.onosproject.net.intent.constraint; |
| 17 | |
| 18 | import org.onosproject.net.Link; |
| 19 | import org.onosproject.net.Path; |
| 20 | import org.onosproject.net.intent.ConnectivityIntent; |
| 21 | import org.onosproject.net.intent.Constraint; |
| 22 | import org.onosproject.net.intent.Intent; |
Sho SHIMIZU | b1681bd | 2016-02-22 12:47:50 -0800 | [diff] [blame] | 23 | import org.onosproject.net.intent.ResourceContext; |
Jonathan Hart | 96c5a4a | 2015-07-31 14:23:33 -0700 | [diff] [blame] | 24 | |
| 25 | /** |
| 26 | * A constraint that allows intents that can only be partially compiled |
| 27 | * (i.e. MultiPointToSinglePointIntent or SinglePointToMultiPointIntent) |
| 28 | * to be installed when some endpoints or paths are not found. |
| 29 | */ |
| 30 | public class PartialFailureConstraint implements Constraint { |
Sho SHIMIZU | b1681bd | 2016-02-22 12:47:50 -0800 | [diff] [blame] | 31 | // doesn't use LinkResourceService |
Jonathan Hart | 96c5a4a | 2015-07-31 14:23:33 -0700 | [diff] [blame] | 32 | @Override |
Sho SHIMIZU | b1681bd | 2016-02-22 12:47:50 -0800 | [diff] [blame] | 33 | public double cost(Link link, ResourceContext context) { |
Jonathan Hart | 96c5a4a | 2015-07-31 14:23:33 -0700 | [diff] [blame] | 34 | return 1; |
| 35 | } |
| 36 | |
Sho SHIMIZU | b1681bd | 2016-02-22 12:47:50 -0800 | [diff] [blame] | 37 | // doesn't use LinkResourceService |
Jonathan Hart | 96c5a4a | 2015-07-31 14:23:33 -0700 | [diff] [blame] | 38 | @Override |
Sho SHIMIZU | b1681bd | 2016-02-22 12:47:50 -0800 | [diff] [blame] | 39 | public boolean validate(Path path, ResourceContext context) { |
Jonathan Hart | 96c5a4a | 2015-07-31 14:23:33 -0700 | [diff] [blame] | 40 | return true; |
| 41 | } |
| 42 | |
| 43 | public static boolean intentAllowsPartialFailure(Intent intent) { |
| 44 | if (intent instanceof ConnectivityIntent) { |
| 45 | ConnectivityIntent connectivityIntent = (ConnectivityIntent) intent; |
| 46 | return connectivityIntent.constraints().stream() |
| 47 | .anyMatch(c -> c instanceof PartialFailureConstraint); |
| 48 | } |
| 49 | return false; |
| 50 | } |
Yuta HIGUCHI | d0598ee | 2016-12-20 18:11:34 -0800 | [diff] [blame] | 51 | |
| 52 | @Override |
Luca Prete | 1346564 | 2017-01-04 10:31:48 -0800 | [diff] [blame] | 53 | public int hashCode() { |
| 54 | return 1; |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public boolean equals(Object obj) { |
| 59 | if (this == obj) { |
| 60 | return true; |
| 61 | } |
| 62 | if (obj == null || getClass() != obj.getClass()) { |
| 63 | return false; |
| 64 | } |
| 65 | return true; |
| 66 | } |
| 67 | |
| 68 | @Override |
Yuta HIGUCHI | d0598ee | 2016-12-20 18:11:34 -0800 | [diff] [blame] | 69 | public String toString() { |
| 70 | return "PartialFailureConstraint"; |
| 71 | } |
Jonathan Hart | 96c5a4a | 2015-07-31 14:23:33 -0700 | [diff] [blame] | 72 | } |