blob: ddfd00a6796c993c96073e297cb402eaa5ce8d2d [file] [log] [blame]
nosignal5fd282e2016-09-16 16:11:40 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
nosignal5fd282e2016-09-16 16:11:40 -07003 *
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 */
16package org.onosproject.vpls.config;
17
Luca Prete092e8952016-10-26 16:25:56 +020018import com.google.common.collect.ImmutableSet;
19import org.onosproject.net.EncapsulationType;
nosignal5fd282e2016-09-16 16:11:40 -070020
Luca Prete092e8952016-10-26 16:25:56 +020021import java.util.Objects;
nosignal5fd282e2016-09-16 16:11:40 -070022import java.util.Set;
23
Luca Prete092e8952016-10-26 16:25:56 +020024import static com.google.common.base.Preconditions.checkNotNull;
25
nosignal5fd282e2016-09-16 16:11:40 -070026/**
Luca Prete092e8952016-10-26 16:25:56 +020027 * Configuration of a VPLS.
nosignal5fd282e2016-09-16 16:11:40 -070028 */
Luca Prete092e8952016-10-26 16:25:56 +020029public class VplsConfig {
30 private final String name;
31 private final Set<String> ifaces;
32 private final EncapsulationType encap;
nosignal5fd282e2016-09-16 16:11:40 -070033
34 /**
Luca Prete092e8952016-10-26 16:25:56 +020035 * Creates a new VPLS configuration.
nosignal5fd282e2016-09-16 16:11:40 -070036 *
37 * @param name the VPLS name
Luca Prete092e8952016-10-26 16:25:56 +020038 * @param ifaces the interfaces associated with the VPLS
39 * @param encap the encapsulation type if set
nosignal5fd282e2016-09-16 16:11:40 -070040 */
Luca Prete092e8952016-10-26 16:25:56 +020041 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.
Luca Prete092e8952016-10-26 16:25:56 +020076 * @param iface the interface attached to a VPLS
77 * @return true if the interface is associated to the VPLS; false otherwise
78 */
Carolina Fernandezb1cef5c2016-11-22 19:18:40 +010079 protected boolean isAttached(String iface) {
Luca Prete092e8952016-10-26 16:25:56 +020080 return ifaces.stream().anyMatch(iface::equals);
81 }
82
83 @Override
84 public boolean equals(Object obj) {
85 if (this == obj) {
86 return true;
nosignal5fd282e2016-09-16 16:11:40 -070087 }
Luca Prete092e8952016-10-26 16:25:56 +020088 if (obj instanceof VplsConfig) {
89 VplsConfig that = (VplsConfig) obj;
90 return Objects.equals(name, that.name) &&
Carolina Fernandezb1cef5c2016-11-22 19:18:40 +010091 Objects.equals(ifaces, that.ifaces) &&
92 Objects.equals(encap, that.encap);
nosignal5fd282e2016-09-16 16:11:40 -070093 }
Luca Prete092e8952016-10-26 16:25:56 +020094 return false;
nosignal5fd282e2016-09-16 16:11:40 -070095 }
96
Luca Prete092e8952016-10-26 16:25:56 +020097 @Override
98 public int hashCode() {
99 return Objects.hash(name, ifaces, encap);
nosignal5fd282e2016-09-16 16:11:40 -0700100 }
101}