2 * Copyright 2014 Open Networking Laboratory
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onosproject.net.intent.constraint;
18 import com.google.common.annotations.Beta;
19 import org.onosproject.net.Link;
20 import org.onosproject.net.resource.link.LambdaResource;
21 import org.onosproject.net.resource.link.LinkResourceService;
22 import org.onosproject.net.resource.ResourceRequest;
23 import org.onosproject.net.resource.ResourceType;
25 import java.util.Objects;
27 import static com.google.common.base.MoreObjects.toStringHelper;
30 * Constraint that evaluates links based on available lambda.
33 public class LambdaConstraint extends BooleanConstraint {
35 private final LambdaResource lambda;
38 * Creates a new optical lambda constraint.
40 * @param lambda optional lambda to indicate a specific lambda
42 public LambdaConstraint(LambdaResource lambda) {
46 // Constructor for serialization
47 private LambdaConstraint() {
52 public boolean isValid(Link link, LinkResourceService resourceService) {
53 for (ResourceRequest request : resourceService.getAvailableResources(link)) {
54 if (request.type() == ResourceType.LAMBDA) {
62 * Returns the lambda required by this constraint.
64 * @return required lambda
66 public LambdaResource lambda() {
71 public int hashCode() {
72 return Objects.hashCode(lambda);
76 public boolean equals(Object obj) {
80 if (obj == null || getClass() != obj.getClass()) {
83 final LambdaConstraint other = (LambdaConstraint) obj;
84 return Objects.equals(this.lambda, other.lambda);
88 public String toString() {
89 return toStringHelper(this).add("lambda", lambda).toString();