Michele Santuari | 02e47a4 | 2015-11-23 16:54:51 +0100 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
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 | |
| 20 | import org.onosproject.net.EncapsulationType; |
| 21 | import org.onosproject.net.Link; |
Sho SHIMIZU | b1681bd | 2016-02-22 12:47:50 -0800 | [diff] [blame] | 22 | import org.onosproject.net.intent.ResourceContext; |
Michele Santuari | 02e47a4 | 2015-11-23 16:54:51 +0100 | [diff] [blame] | 23 | |
| 24 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 25 | import static com.google.common.base.Preconditions.checkNotNull; |
| 26 | |
| 27 | /** |
| 28 | * Encapsulation to manage core transportation. |
| 29 | */ |
| 30 | public 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 SHIMIZU | b1681bd | 2016-02-22 12:47:50 -0800 | [diff] [blame] | 45 | // doesn't use LinkResourceService |
Michele Santuari | 02e47a4 | 2015-11-23 16:54:51 +0100 | [diff] [blame] | 46 | @Override |
Sho SHIMIZU | b1681bd | 2016-02-22 12:47:50 -0800 | [diff] [blame] | 47 | public boolean isValid(Link link, ResourceContext context) { |
Michele Santuari | 02e47a4 | 2015-11-23 16:54:51 +0100 | [diff] [blame] | 48 | //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 | } |