helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -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 | |
| 17 | package org.onosproject.net.intent.constraint; |
| 18 | |
| 19 | import com.google.common.annotations.Beta; |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 20 | import org.onosproject.net.intent.Intent; |
| 21 | import org.onosproject.net.intent.PointToPointIntent; |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 22 | |
| 23 | /** |
| 24 | * Constraint that determines whether to employ path protection. |
| 25 | */ |
| 26 | @Beta |
Yuta HIGUCHI | e37560f | 2017-02-02 19:53:26 -0800 | [diff] [blame] | 27 | public final class ProtectionConstraint extends MarkerConstraint { |
| 28 | |
Yuta HIGUCHI | 23547b3 | 2016-09-01 16:02:40 -0700 | [diff] [blame] | 29 | private static final ProtectionConstraint PROTECTION_CONSTRAINT = new ProtectionConstraint(); |
| 30 | |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 31 | /** |
| 32 | * Determines whether to utilize path protection for the given intent. |
| 33 | * |
| 34 | * @param intent intent to be inspected |
| 35 | * @return whether the intent has a ProtectionConstraint |
| 36 | */ |
| 37 | public static boolean requireProtectedPath(Intent intent) { |
| 38 | if (intent instanceof PointToPointIntent) { |
| 39 | PointToPointIntent pointToPointIntent = (PointToPointIntent) intent; |
| 40 | return pointToPointIntent.constraints().stream() |
| 41 | .anyMatch(p -> p instanceof ProtectionConstraint); |
| 42 | } |
| 43 | return false; |
| 44 | } |
Yuta HIGUCHI | 23547b3 | 2016-09-01 16:02:40 -0700 | [diff] [blame] | 45 | |
| 46 | /** |
| 47 | * Returns protection constraint. |
| 48 | * |
Ray Milkey | ef79434 | 2016-11-09 16:20:29 -0800 | [diff] [blame] | 49 | * @return protection constraint |
Yuta HIGUCHI | 23547b3 | 2016-09-01 16:02:40 -0700 | [diff] [blame] | 50 | */ |
| 51 | public static ProtectionConstraint protection() { |
| 52 | return PROTECTION_CONSTRAINT; |
| 53 | } |
| 54 | |
| 55 | protected ProtectionConstraint() { |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public String toString() { |
| 60 | return "Protection"; |
| 61 | } |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 62 | } |