2 * Copyright 2014-2015 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 com.google.common.base.MoreObjects;
20 import com.google.common.collect.ImmutableSet;
21 import org.onosproject.net.DeviceId;
22 import org.onosproject.net.Link;
23 import org.onosproject.net.resource.link.LinkResourceService;
25 import java.util.Collections;
26 import java.util.Objects;
30 * Constraint that evaluates elements not passed through.
33 public class ObstacleConstraint extends BooleanConstraint {
35 private final Set<DeviceId> obstacles;
38 * Creates a new constraint that the specified device are not passed through.
39 * @param obstacles devices not to be passed
41 public ObstacleConstraint(DeviceId... obstacles) {
42 this.obstacles = ImmutableSet.copyOf(obstacles);
45 // Constructor for serialization
46 private ObstacleConstraint() {
47 this.obstacles = Collections.emptySet();
51 * Returns the obstacle device ids.
53 * @return Set of obstacle device ids
55 public Set<DeviceId> obstacles() {
60 public boolean isValid(Link link, LinkResourceService resourceService) {
61 DeviceId src = link.src().deviceId();
62 DeviceId dst = link.dst().deviceId();
64 return !(obstacles.contains(src) || obstacles.contains(dst));
68 public int hashCode() {
69 return Objects.hash(obstacles);
73 public boolean equals(Object obj) {
78 if (!(obj instanceof ObstacleConstraint)) {
82 final ObstacleConstraint that = (ObstacleConstraint) obj;
83 return Objects.equals(this.obstacles, that.obstacles);
87 public String toString() {
88 return MoreObjects.toStringHelper(this)
89 .add("obstacles", obstacles)