blob: 3f0505d7adeda4a6af4c16d561fb7240e606ae5c [file] [log] [blame]
helenyrwu2a674902016-07-20 09:48:04 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
helenyrwu2a674902016-07-20 09:48:04 -07003 *
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
17package org.onosproject.net.intent.constraint;
18
19import com.google.common.annotations.Beta;
helenyrwu2a674902016-07-20 09:48:04 -070020import org.onosproject.net.intent.Intent;
21import org.onosproject.net.intent.PointToPointIntent;
helenyrwu2a674902016-07-20 09:48:04 -070022
23/**
24 * Constraint that determines whether to employ path protection.
25 */
26@Beta
Yuta HIGUCHIe37560f2017-02-02 19:53:26 -080027public final class ProtectionConstraint extends MarkerConstraint {
28
Yuta HIGUCHI23547b32016-09-01 16:02:40 -070029 private static final ProtectionConstraint PROTECTION_CONSTRAINT = new ProtectionConstraint();
30
helenyrwu2a674902016-07-20 09:48:04 -070031 /**
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 HIGUCHI23547b32016-09-01 16:02:40 -070045
46 /**
47 * Returns protection constraint.
48 *
Ray Milkeyef794342016-11-09 16:20:29 -080049 * @return protection constraint
Yuta HIGUCHI23547b32016-09-01 16:02:40 -070050 */
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 }
helenyrwu2a674902016-07-20 09:48:04 -070062}