blob: 15ecf340ec3b1ee2ee4c97dcf09b1857837c76c7 [file] [log] [blame]
Jonathan Harteb8c9472015-08-05 07:43:13 -07001/*
2 * Copyright 2014-2015 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.incubator.net.intf;
17
18import com.google.common.base.MoreObjects;
19import com.google.common.collect.Sets;
20import org.onlab.packet.MacAddress;
21import org.onlab.packet.VlanId;
22import org.onosproject.net.ConnectPoint;
23import org.onosproject.net.host.InterfaceIpAddress;
24
25import java.util.Objects;
26import java.util.Set;
27
Jonathan Hart4cb39882015-08-12 23:50:55 -040028import static com.google.common.base.Preconditions.checkNotNull;
29
Jonathan Harteb8c9472015-08-05 07:43:13 -070030/**
31 * An Interface maps network configuration information (such as addresses and
32 * vlans) to a port in the network.
33 */
34public class Interface {
35 private final ConnectPoint connectPoint;
36 private final Set<InterfaceIpAddress> ipAddresses;
37 private final MacAddress macAddress;
38 private final VlanId vlan;
39
40 /**
41 * Creates new Interface with the provided configuration.
42 *
43 * @param connectPoint the connect point this interface maps to
44 * @param ipAddresses Set of IP addresses
45 * @param macAddress MAC address
46 * @param vlan VLAN ID
47 */
48 public Interface(ConnectPoint connectPoint,
49 Set<InterfaceIpAddress> ipAddresses,
50 MacAddress macAddress, VlanId vlan) {
Jonathan Hart4cb39882015-08-12 23:50:55 -040051 this.connectPoint = checkNotNull(connectPoint);
52 this.ipAddresses = Sets.newHashSet(checkNotNull(ipAddresses));
53 this.macAddress = checkNotNull(macAddress);
54 this.vlan = checkNotNull(vlan);
Jonathan Harteb8c9472015-08-05 07:43:13 -070055 }
56
57 /**
58 * Retrieves the connection point that this interface maps to.
59 *
60 * @return the connection point
61 */
62 public ConnectPoint connectPoint() {
63 return connectPoint;
64 }
65
66 /**
67 * Retrieves the set of IP addresses that are assigned to the interface.
68 *
69 * @return the set of interface IP addresses
70 */
71 public Set<InterfaceIpAddress> ipAddresses() {
72 return ipAddresses;
73 }
74
75 /**
76 * Retrieves the MAC address that is assigned to the interface.
77 *
78 * @return the MAC address
79 */
80 public MacAddress mac() {
81 return macAddress;
82 }
83
84 /**
85 * Retrieves the VLAN ID that is assigned to the interface.
86 *
87 * @return the VLAN ID
88 */
89 public VlanId vlan() {
90 return vlan;
91 }
92
93 @Override
94 public boolean equals(Object other) {
95 if (!(other instanceof Interface)) {
96 return false;
97 }
98
99 Interface otherInterface = (Interface) other;
100
101 return Objects.equals(connectPoint, otherInterface.connectPoint) &&
102 Objects.equals(ipAddresses, otherInterface.ipAddresses) &&
103 Objects.equals(macAddress, otherInterface.macAddress) &&
104 Objects.equals(vlan, otherInterface.vlan);
105 }
106
107 @Override
108 public int hashCode() {
109 return Objects.hash(connectPoint, ipAddresses, macAddress, vlan);
110 }
111
112 @Override
113 public String toString() {
114 return MoreObjects.toStringHelper(getClass())
115 .add("connectPoint", connectPoint)
116 .add("ipAddresses", ipAddresses)
117 .add("macAddress", macAddress)
118 .add("vlan", vlan)
119 .toString();
120 }
121}