blob: a337040e629a779149ef391e947ab04efe30e5d0 [file] [log] [blame]
helenyrwu2a674902016-07-20 09:48:04 -07001/*
2 * Copyright 2016-present 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
17package org.onosproject.net.intent.constraint;
18
19import com.google.common.annotations.Beta;
20import org.onosproject.net.Link;
21import org.onosproject.net.Path;
22import org.onosproject.net.intent.Constraint;
23import org.onosproject.net.intent.Intent;
24import org.onosproject.net.intent.PointToPointIntent;
25import org.onosproject.net.intent.ResourceContext;
26
27/**
28 * Constraint that determines whether to employ path protection.
29 */
30@Beta
31public class ProtectionConstraint implements Constraint {
Yuta HIGUCHI23547b32016-09-01 16:02:40 -070032 private static final ProtectionConstraint PROTECTION_CONSTRAINT = new ProtectionConstraint();
33
helenyrwu2a674902016-07-20 09:48:04 -070034 // doesn't use LinkResourceService
35 @Override
36 public double cost(Link link, ResourceContext context) {
37 return 1;
38 }
39
40 // doesn't use LinkResourceService
41 @Override
42 public boolean validate(Path path, ResourceContext context) {
43 return true;
44 }
45
46 /**
47 * Determines whether to utilize path protection for the given intent.
48 *
49 * @param intent intent to be inspected
50 * @return whether the intent has a ProtectionConstraint
51 */
52 public static boolean requireProtectedPath(Intent intent) {
53 if (intent instanceof PointToPointIntent) {
54 PointToPointIntent pointToPointIntent = (PointToPointIntent) intent;
55 return pointToPointIntent.constraints().stream()
56 .anyMatch(p -> p instanceof ProtectionConstraint);
57 }
58 return false;
59 }
Yuta HIGUCHI23547b32016-09-01 16:02:40 -070060
61 /**
62 * Returns protection constraint.
63 *
64 * @return
65 */
66 public static ProtectionConstraint protection() {
67 return PROTECTION_CONSTRAINT;
68 }
69
70 protected ProtectionConstraint() {
71 }
72
73 @Override
74 public String toString() {
75 return "Protection";
76 }
helenyrwu2a674902016-07-20 09:48:04 -070077}