blob: b3c721b0b3c458b3a6305be05193132a5f05c272 [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
18import com.google.common.collect.ImmutableSet;
19
20import java.util.Objects;
21import java.util.Set;
22
23import static com.google.common.base.Preconditions.checkNotNull;
24
25/**
26 * Configuration of a VPLS Network.
27 */
28public class VplsNetworkConfig {
29 private final String name;
30 private final Set<String> ifaces;
31
32 /**
33 * Creates a new VPLS configuration.
34 *
35 * @param name the VPLS name
36 * @param ifaces the interfaces associated with the VPLS
37 */
38 public VplsNetworkConfig(String name, Set<String> ifaces) {
39 this.name = checkNotNull(name);
40 this.ifaces = checkNotNull(ImmutableSet.copyOf(ifaces));
41 }
42
43 /**
44 * Returns the name of the VPLS.
45 *
46 * @return the name of the VPLS
47 */
48 public String name() {
49 return name;
50 }
51
52 /**
53 * Returns the name of interfaces associated with the VPLS.
54 *
55 * @return a set of interface names associated with the VPLS
56 */
57 public Set<String> ifaces() {
58 return ImmutableSet.copyOf(ifaces);
59 }
60
61 /**
62 * States if a given interface is part of a VPLS.
63 *
64 * @param iface the interface attached to a VPLS
65 * @return true if the interface is associated to the VPLS; false otherwise
66 */
67 public boolean isAttached(String iface) {
68 return ifaces.stream().anyMatch(i -> i.equals(iface));
69 }
70
71 @Override
72 public boolean equals(Object obj) {
73 if (this == obj) {
74 return true;
75 }
76 if (obj instanceof VplsNetworkConfig) {
77 final VplsNetworkConfig that = (VplsNetworkConfig) obj;
78 return Objects.equals(this.name, that.name) &&
79 Objects.equals(this.ifaces, that.ifaces);
80 }
81 return false;
82 }
83
84 @Override
85 public int hashCode() {
86 return Objects.hash(name, ifaces);
87 }
88}