Jonathan Hart | bc2b72c | 2015-07-31 14:23:33 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2015 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 | */ |
| 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; |
| 23 | import org.onosproject.net.resource.link.LinkResourceService; |
| 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 { |
| 31 | @Override |
| 32 | public double cost(Link link, LinkResourceService resourceService) { |
| 33 | return 1; |
| 34 | } |
| 35 | |
| 36 | @Override |
| 37 | public boolean validate(Path path, LinkResourceService resourceService) { |
| 38 | return true; |
| 39 | } |
| 40 | |
| 41 | public static boolean intentAllowsPartialFailure(Intent intent) { |
| 42 | if (intent instanceof ConnectivityIntent) { |
| 43 | ConnectivityIntent connectivityIntent = (ConnectivityIntent) intent; |
| 44 | return connectivityIntent.constraints().stream() |
| 45 | .anyMatch(c -> c instanceof PartialFailureConstraint); |
| 46 | } |
| 47 | return false; |
| 48 | } |
| 49 | } |