blob: 6d73fc2a110a812cd3d1c769d6e88aec34843aee [file] [log] [blame]
Sho SHIMIZU075268b2014-11-05 15:16:32 -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 com.google.common.base.MoreObjects;
19import com.google.common.collect.ImmutableSet;
20import org.onlab.onos.net.DeviceId;
21import org.onlab.onos.net.Link;
Sho SHIMIZU075268b2014-11-05 15:16:32 -080022import org.onlab.onos.net.resource.LinkResourceService;
23
24import java.util.Objects;
25import java.util.Set;
26
27/**
28 * Constraint that evaluates elements not passed through.
29 */
30public class ObstacleConstraint extends BooleanConstraint {
31
32 private final Set<DeviceId> obstacles;
33
34 /**
35 * Creates a new constraint that the specified device are not passed through.
36 * @param obstacles devices not to be passed
37 */
38 public ObstacleConstraint(DeviceId... obstacles) {
39 this.obstacles = ImmutableSet.copyOf(obstacles);
40 }
41
42 @Override
43 public boolean isValid(Link link, LinkResourceService resourceService) {
44 DeviceId src = link.src().deviceId();
45 DeviceId dst = link.dst().deviceId();
46
47 return !(obstacles.contains(src) || obstacles.contains(dst));
48 }
49
50 @Override
Sho SHIMIZU075268b2014-11-05 15:16:32 -080051 public int hashCode() {
52 return Objects.hash(obstacles);
53 }
54
55 @Override
56 public boolean equals(Object obj) {
57 if (this == obj) {
58 return true;
59 }
60
61 if (!(obj instanceof ObstacleConstraint)) {
62 return false;
63 }
64
65 final ObstacleConstraint that = (ObstacleConstraint) obj;
66 return Objects.equals(this.obstacles, that.obstacles);
67 }
68
69 @Override
70 public String toString() {
71 return MoreObjects.toStringHelper(this)
72 .add("obstacles", obstacles)
73 .toString();
74 }
75}