nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present 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 | package org.onosproject.vpls.config; |
| 17 | |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame^] | 18 | import com.google.common.collect.ImmutableSet; |
| 19 | import org.onosproject.net.EncapsulationType; |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 20 | |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame^] | 21 | import java.util.Objects; |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 22 | import java.util.Set; |
| 23 | |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame^] | 24 | import static com.google.common.base.Preconditions.checkNotNull; |
| 25 | |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 26 | /** |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame^] | 27 | * Configuration of a VPLS. |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 28 | */ |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame^] | 29 | public class VplsConfig { |
| 30 | private final String name; |
| 31 | private final Set<String> ifaces; |
| 32 | private final EncapsulationType encap; |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 33 | |
| 34 | /** |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame^] | 35 | * Creates a new VPLS configuration. |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 36 | * |
| 37 | * @param name the VPLS name |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame^] | 38 | * @param ifaces the interfaces associated with the VPLS |
| 39 | * @param encap the encapsulation type if set |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 40 | */ |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame^] | 41 | public VplsConfig(String name, Set<String> ifaces, EncapsulationType encap) { |
| 42 | this.name = checkNotNull(name); |
| 43 | this.ifaces = checkNotNull(ImmutableSet.copyOf(ifaces)); |
| 44 | this.encap = checkNotNull(encap); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * The name of the VPLS. |
| 49 | * |
| 50 | * @return the name of the VPLS |
| 51 | */ |
| 52 | public String name() { |
| 53 | return name; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * The name of the interfaces associated with the VPLS. |
| 58 | * |
| 59 | * @return a set of interface names associated with the VPLS |
| 60 | */ |
| 61 | public Set<String> ifaces() { |
| 62 | return ImmutableSet.copyOf(ifaces); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * The encapsulation type. |
| 67 | * |
| 68 | * @return the encapsulation type, if active; null otherwise |
| 69 | */ |
| 70 | public EncapsulationType encap() { |
| 71 | return encap; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * States if a given interface is part of a VPLS. |
| 76 | * |
| 77 | * @param iface the interface attached to a VPLS |
| 78 | * @return true if the interface is associated to the VPLS; false otherwise |
| 79 | */ |
| 80 | public boolean isAttached(String iface) { |
| 81 | return ifaces.stream().anyMatch(iface::equals); |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public boolean equals(Object obj) { |
| 86 | if (this == obj) { |
| 87 | return true; |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 88 | } |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame^] | 89 | if (obj instanceof VplsConfig) { |
| 90 | VplsConfig that = (VplsConfig) obj; |
| 91 | return Objects.equals(name, that.name) && |
| 92 | Objects.equals(ifaces, that.ifaces) && |
| 93 | Objects.equals(encap, that.encap); |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 94 | } |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame^] | 95 | return false; |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame^] | 98 | @Override |
| 99 | public int hashCode() { |
| 100 | return Objects.hash(name, ifaces, encap); |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 101 | } |
| 102 | } |