Michele Santuari | 02e47a4 | 2015-11-23 16:54:51 +0100 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Michele Santuari | 02e47a4 | 2015-11-23 16:54:51 +0100 | [diff] [blame] | 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 | |
| 17 | package org.onosproject.net.intent.constraint; |
| 18 | |
| 19 | |
alessio | 225e2b0 | 2020-10-28 17:44:44 +0100 | [diff] [blame] | 20 | import org.onlab.util.Identifier; |
Michele Santuari | 02e47a4 | 2015-11-23 16:54:51 +0100 | [diff] [blame] | 21 | import org.onosproject.net.EncapsulationType; |
| 22 | import org.onosproject.net.Link; |
Sho SHIMIZU | b1681bd | 2016-02-22 12:47:50 -0800 | [diff] [blame] | 23 | import org.onosproject.net.intent.ResourceContext; |
Michele Santuari | 02e47a4 | 2015-11-23 16:54:51 +0100 | [diff] [blame] | 24 | |
alessio | 225e2b0 | 2020-10-28 17:44:44 +0100 | [diff] [blame] | 25 | import java.util.Optional; |
| 26 | |
Michele Santuari | 02e47a4 | 2015-11-23 16:54:51 +0100 | [diff] [blame] | 27 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 28 | import static com.google.common.base.Preconditions.checkNotNull; |
| 29 | |
| 30 | /** |
| 31 | * Encapsulation to manage core transportation. |
| 32 | */ |
| 33 | public class EncapsulationConstraint extends BooleanConstraint { |
| 34 | |
| 35 | private EncapsulationType encapType; |
alessio | 225e2b0 | 2020-10-28 17:44:44 +0100 | [diff] [blame] | 36 | private Optional<Identifier<?>> suggestedIdentifier; |
Michele Santuari | 02e47a4 | 2015-11-23 16:54:51 +0100 | [diff] [blame] | 37 | |
| 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; |
alessio | 225e2b0 | 2020-10-28 17:44:44 +0100 | [diff] [blame] | 46 | this.suggestedIdentifier = Optional.empty(); |
Michele Santuari | 02e47a4 | 2015-11-23 16:54:51 +0100 | [diff] [blame] | 47 | } |
| 48 | |
alessio | 225e2b0 | 2020-10-28 17:44:44 +0100 | [diff] [blame] | 49 | /** |
| 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 Santuari | 02e47a4 | 2015-11-23 16:54:51 +0100 | [diff] [blame] | 60 | |
Sho SHIMIZU | b1681bd | 2016-02-22 12:47:50 -0800 | [diff] [blame] | 61 | // doesn't use LinkResourceService |
Michele Santuari | 02e47a4 | 2015-11-23 16:54:51 +0100 | [diff] [blame] | 62 | @Override |
Sho SHIMIZU | b1681bd | 2016-02-22 12:47:50 -0800 | [diff] [blame] | 63 | public boolean isValid(Link link, ResourceContext context) { |
Michele Santuari | 02e47a4 | 2015-11-23 16:54:51 +0100 | [diff] [blame] | 64 | //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 | |
alessio | 225e2b0 | 2020-10-28 17:44:44 +0100 | [diff] [blame] | 79 | /** |
| 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 Santuari | 02e47a4 | 2015-11-23 16:54:51 +0100 | [diff] [blame] | 91 | @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 | } |