blob: d1d33d65c3c741f294c5ef11e139ce4c7a8b2074 [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.resource.Lambda;
20import org.onlab.onos.net.resource.LinkResourceService;
21import org.onlab.onos.net.resource.ResourceRequest;
22import org.onlab.onos.net.resource.ResourceType;
23
24import java.util.Objects;
25
26import static com.google.common.base.MoreObjects.toStringHelper;
27
28/**
29 * Constraint that evaluates links based on available lambda.
30 */
31public class LambdaConstraint extends BooleanConstraint {
32
33 private final Lambda lambda;
34
35 /**
36 * Creates a new optical lambda constraint.
37 *
38 * @param lambda optional lambda to indicate a specific lambda
39 */
40 public LambdaConstraint(Lambda lambda) {
41 this.lambda = lambda;
42 }
43
44 @Override
45 public boolean isValid(Link link, LinkResourceService resourceService) {
46 for (ResourceRequest request : resourceService.getAvailableResources(link)) {
47 if (request.type() == ResourceType.LAMBDA) {
48 return true;
49 }
50 }
51 return false;
52 }
53
54 /**
55 * Returns the lambda required by this constraint.
56 *
57 * @return required lambda
58 */
59 public Lambda lambda() {
60 return lambda;
61 }
62
63 @Override
64 public int hashCode() {
65 return Objects.hash(lambda);
66 }
67
68 @Override
69 public boolean equals(Object obj) {
70 if (this == obj) {
71 return true;
72 }
73 if (obj == null || getClass() != obj.getClass()) {
74 return false;
75 }
76 final LambdaConstraint other = (LambdaConstraint) obj;
77 return Objects.equals(this.lambda, other.lambda);
78 }
79
80 @Override
81 public String toString() {
82 return toStringHelper(this).add("lambda", lambda).toString();
83 }
84}