blob: bb521d5e5d5cadc9cd7bed3a0a2477532ad1291c [file] [log] [blame]
Michele Santuari02e47a42015-11-23 16:54:51 +01001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Michele Santuari02e47a42015-11-23 16:54:51 +01003 *
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;
Sho SHIMIZUb1681bd2016-02-22 12:47:50 -080022import org.onosproject.net.intent.ResourceContext;
Michele Santuari02e47a42015-11-23 16:54:51 +010023
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
Sho SHIMIZUb1681bd2016-02-22 12:47:50 -080045 // doesn't use LinkResourceService
Michele Santuari02e47a42015-11-23 16:54:51 +010046 @Override
Sho SHIMIZUb1681bd2016-02-22 12:47:50 -080047 public boolean isValid(Link link, ResourceContext context) {
Michele Santuari02e47a42015-11-23 16:54:51 +010048 //TODO: validate the availability of the resources for each link in the path.
49 //e.g., availability of MPLSlabels, VLANID
50
51 return true;
52 }
53
54 /**
55 * Returns the encapsulation type required by this constraint.
56 *
57 * @return encapType
58 */
59 public EncapsulationType encapType() {
60 return encapType;
61 }
62
63 @Override
64 public int hashCode() {
65 return encapType.hashCode();
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 EncapsulationConstraint other = (EncapsulationConstraint) obj;
77 return this.encapType() == other.encapType();
78 }
79
80 @Override
81 public String toString() {
82 return toStringHelper(this).add("encapType", encapType).toString();
83 }
84}