blob: 9ad4ac784c168d3e7aa0ed16b135080749ff78c5 [file] [log] [blame]
Thomas Vachuskaedc944c2014-11-04 15:42:25 -08001/*
2 * Copyright 2014 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 */
16package org.onlab.onos.net.intent.constraint;
17
18import org.onlab.onos.net.Link;
19import org.onlab.onos.net.Path;
20import org.onlab.onos.net.intent.Constraint;
21import org.onlab.onos.net.resource.LinkResourceService;
22
23/**
24 * Abstract base class for various constraints that evaluate link viability
25 * in a yes/no fashion.
26 */
27public abstract class BooleanConstraint implements Constraint {
28
29 /**
30 * Returns true if the specified link satisfies the constraint.
31 *
32 * @param link link to be validated
33 * @param resourceService resource service for checking available link resources
34 * @return true if link is viable
35 */
36 public abstract boolean isValid(Link link, LinkResourceService resourceService);
37
38 @Override
39 public double cost(Link link, LinkResourceService resourceService) {
40 return isValid(link, resourceService) ? +1 : -1;
41 }
42
43 @Override
44 public boolean validate(Path path, LinkResourceService resourceService) {
45 for (Link link : path.links()) {
46 if (isValid(link, resourceService)) {
47 return false;
48 }
49 }
50 return true;
51 }
52
53}