blob: e8539398d9379b1c75d26d2ea0d26fa6bbdc5346 [file] [log] [blame]
Michele Santuari02e47a42015-11-23 16:54:51 +01001/*
2 * Copyright 2014-2015 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 */
16
17package org.onosproject.net.intent.constraint;
18
19
20import org.onosproject.net.EncapsulationType;
21import org.onosproject.net.Link;
22import org.onosproject.net.resource.link.LinkResourceService;
23
24import static com.google.common.base.MoreObjects.toStringHelper;
25import static com.google.common.base.Preconditions.checkNotNull;
26
27/**
28 * Encapsulation to manage core transportation.
29 */
30public class EncapsulationConstraint extends BooleanConstraint {
31
32 private EncapsulationType encapType;
33
34 /**
35 * Creates a new encapsulation constraint.
36 *
37 * @param encapType the encapsulation type {@link EncapsulationType}
38 */
39 public EncapsulationConstraint(EncapsulationType encapType) {
40 checkNotNull(encapType, "EncapsulationType cannot be null");
41 this.encapType = encapType;
42 }
43
44
45 @Override
46 public boolean isValid(Link link, LinkResourceService resourceService) {
47 //TODO: validate the availability of the resources for each link in the path.
48 //e.g., availability of MPLSlabels, VLANID
49
50 return true;
51 }
52
53 /**
54 * Returns the encapsulation type required by this constraint.
55 *
56 * @return encapType
57 */
58 public EncapsulationType encapType() {
59 return encapType;
60 }
61
62 @Override
63 public int hashCode() {
64 return encapType.hashCode();
65 }
66
67 @Override
68 public boolean equals(Object obj) {
69 if (this == obj) {
70 return true;
71 }
72 if (obj == null || getClass() != obj.getClass()) {
73 return false;
74 }
75 final EncapsulationConstraint other = (EncapsulationConstraint) obj;
76 return this.encapType() == other.encapType();
77 }
78
79 @Override
80 public String toString() {
81 return toStringHelper(this).add("encapType", encapType).toString();
82 }
83}