blob: eba28984247d23b38c62ab7114a4d6206fe71682 [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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.intent.constraint;
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080017
Brian O'Connor9476fa12015-06-25 15:17:17 -040018import com.google.common.annotations.Beta;
Sho SHIMIZU03d42532015-11-23 17:16:30 -080019import org.onosproject.net.IndexedLambda;
Brian O'Connorabafb502014-12-02 22:26:20 -080020import org.onosproject.net.Link;
Brian O'Connor6de2e202015-05-21 14:30:41 -070021import org.onosproject.net.resource.link.LinkResourceService;
Brian O'Connorabafb502014-12-02 22:26:20 -080022import org.onosproject.net.resource.ResourceRequest;
23import org.onosproject.net.resource.ResourceType;
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080024
25import java.util.Objects;
26
27import static com.google.common.base.MoreObjects.toStringHelper;
28
29/**
30 * Constraint that evaluates links based on available lambda.
31 */
Brian O'Connor9476fa12015-06-25 15:17:17 -040032@Beta
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080033public class LambdaConstraint extends BooleanConstraint {
34
Sho SHIMIZU03d42532015-11-23 17:16:30 -080035 private final IndexedLambda lambda;
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080036
37 /**
38 * Creates a new optical lambda constraint.
39 *
40 * @param lambda optional lambda to indicate a specific lambda
41 */
Sho SHIMIZU03d42532015-11-23 17:16:30 -080042 public LambdaConstraint(IndexedLambda lambda) {
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080043 this.lambda = lambda;
44 }
45
Thomas Vachuska7d0032b2014-11-04 17:39:57 -080046 // Constructor for serialization
47 private LambdaConstraint() {
48 this.lambda = null;
49 }
50
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080051 @Override
52 public boolean isValid(Link link, LinkResourceService resourceService) {
53 for (ResourceRequest request : resourceService.getAvailableResources(link)) {
54 if (request.type() == ResourceType.LAMBDA) {
55 return true;
56 }
57 }
58 return false;
59 }
60
61 /**
62 * Returns the lambda required by this constraint.
63 *
64 * @return required lambda
65 */
Sho SHIMIZU03d42532015-11-23 17:16:30 -080066 public IndexedLambda lambda() {
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080067 return lambda;
68 }
69
70 @Override
71 public int hashCode() {
HIGUCHI Yutaca9cc8e2015-10-29 23:26:51 -070072 return Objects.hashCode(lambda);
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080073 }
74
75 @Override
76 public boolean equals(Object obj) {
77 if (this == obj) {
78 return true;
79 }
80 if (obj == null || getClass() != obj.getClass()) {
81 return false;
82 }
83 final LambdaConstraint other = (LambdaConstraint) obj;
84 return Objects.equals(this.lambda, other.lambda);
85 }
86
87 @Override
88 public String toString() {
89 return toStringHelper(this).add("lambda", lambda).toString();
90 }
91}