blob: 94e96abad1b7c420818f001222b28675bf275686 [file] [log] [blame]
nosignal5fd282e2016-09-16 16:11:40 -07001/*
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 */
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.
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;
nosignal5fd282e2016-09-16 16:11:40 -070088 }
Luca Prete092e8952016-10-26 16:25:56 +020089 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);
nosignal5fd282e2016-09-16 16:11:40 -070094 }
Luca Prete092e8952016-10-26 16:25:56 +020095 return false;
nosignal5fd282e2016-09-16 16:11:40 -070096 }
97
Luca Prete092e8952016-10-26 16:25:56 +020098 @Override
99 public int hashCode() {
100 return Objects.hash(name, ifaces, encap);
nosignal5fd282e2016-09-16 16:11:40 -0700101 }
102}