blob: f5be3edd2078829b20e9cb0cc2e71b3ea56dc955 [file] [log] [blame]
Michele Santuari02e47a42015-11-23 16:54:51 +01001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
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
alessio225e2b02020-10-28 17:44:44 +010020import org.onlab.util.Identifier;
Michele Santuari02e47a42015-11-23 16:54:51 +010021import org.onosproject.net.EncapsulationType;
22import org.onosproject.net.Link;
Sho SHIMIZUb1681bd2016-02-22 12:47:50 -080023import org.onosproject.net.intent.ResourceContext;
Michele Santuari02e47a42015-11-23 16:54:51 +010024
alessio225e2b02020-10-28 17:44:44 +010025import java.util.Optional;
26
Michele Santuari02e47a42015-11-23 16:54:51 +010027import static com.google.common.base.MoreObjects.toStringHelper;
28import static com.google.common.base.Preconditions.checkNotNull;
29
30/**
31 * Encapsulation to manage core transportation.
32 */
33public class EncapsulationConstraint extends BooleanConstraint {
34
35 private EncapsulationType encapType;
alessio225e2b02020-10-28 17:44:44 +010036 private Optional<Identifier<?>> suggestedIdentifier;
Michele Santuari02e47a42015-11-23 16:54:51 +010037
38 /**
39 * Creates a new encapsulation constraint.
40 *
41 * @param encapType the encapsulation type {@link EncapsulationType}
42 */
43 public EncapsulationConstraint(EncapsulationType encapType) {
44 checkNotNull(encapType, "EncapsulationType cannot be null");
45 this.encapType = encapType;
alessio225e2b02020-10-28 17:44:44 +010046 this.suggestedIdentifier = Optional.empty();
Michele Santuari02e47a42015-11-23 16:54:51 +010047 }
48
alessio225e2b02020-10-28 17:44:44 +010049 /**
50 * Creates a new encapsulation constraint with suggested identifier.
51 *
52 * @param encapType the encapsulation type {@link EncapsulationType}
53 * @param identifier the suggested identifier
54 */
55 public EncapsulationConstraint(EncapsulationType encapType, Identifier<?> identifier) {
56 checkNotNull(encapType, "EncapsulationType cannot be null");
57 this.encapType = encapType;
58 this.suggestedIdentifier = Optional.of(identifier);
59 }
Michele Santuari02e47a42015-11-23 16:54:51 +010060
Sho SHIMIZUb1681bd2016-02-22 12:47:50 -080061 // doesn't use LinkResourceService
Michele Santuari02e47a42015-11-23 16:54:51 +010062 @Override
Sho SHIMIZUb1681bd2016-02-22 12:47:50 -080063 public boolean isValid(Link link, ResourceContext context) {
Michele Santuari02e47a42015-11-23 16:54:51 +010064 //TODO: validate the availability of the resources for each link in the path.
65 //e.g., availability of MPLSlabels, VLANID
66
67 return true;
68 }
69
70 /**
71 * Returns the encapsulation type required by this constraint.
72 *
73 * @return encapType
74 */
75 public EncapsulationType encapType() {
76 return encapType;
77 }
78
alessio225e2b02020-10-28 17:44:44 +010079 /**
80 * Returns the suggested identifier.
81 *
82 * @return suggestedIdentifier
83 */
84 public Optional<Identifier<?>> suggestedIdentifier() {
85 if (suggestedIdentifier.isPresent()) {
86 return suggestedIdentifier;
87 }
88 return Optional.empty();
89 }
90
Michele Santuari02e47a42015-11-23 16:54:51 +010091 @Override
92 public int hashCode() {
93 return encapType.hashCode();
94 }
95
96 @Override
97 public boolean equals(Object obj) {
98 if (this == obj) {
99 return true;
100 }
101 if (obj == null || getClass() != obj.getClass()) {
102 return false;
103 }
104 final EncapsulationConstraint other = (EncapsulationConstraint) obj;
105 return this.encapType() == other.encapType();
106 }
107
108 @Override
109 public String toString() {
110 return toStringHelper(this).add("encapType", encapType).toString();
111 }
112}