blob: b9d3eadf6319f8cc772454e8699f13630f228d84 [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
Thomas Vachuska4c571ae2015-09-10 16:31:59 -070018import com.google.common.annotations.Beta;
Jonathan Harteb8c9472015-08-05 07:43:13 -070019import com.google.common.base.MoreObjects;
20import com.google.common.collect.Sets;
21import org.onlab.packet.MacAddress;
22import org.onlab.packet.VlanId;
23import org.onosproject.net.ConnectPoint;
24import org.onosproject.net.host.InterfaceIpAddress;
25
26import java.util.Objects;
27import java.util.Set;
28
Jonathan Hart4cb39882015-08-12 23:50:55 -040029import static com.google.common.base.Preconditions.checkNotNull;
30
Jonathan Harteb8c9472015-08-05 07:43:13 -070031/**
32 * An Interface maps network configuration information (such as addresses and
Luca Pretee3879f72015-10-16 11:19:53 +020033 * vlans) to a port in the network. This is considered a L2/L3 network
34 * interface.
Jonathan Harteb8c9472015-08-05 07:43:13 -070035 */
Thomas Vachuska4c571ae2015-09-10 16:31:59 -070036@Beta
Jonathan Harteb8c9472015-08-05 07:43:13 -070037public class Interface {
38 private final ConnectPoint connectPoint;
39 private final Set<InterfaceIpAddress> ipAddresses;
40 private final MacAddress macAddress;
41 private final VlanId vlan;
42
43 /**
44 * Creates new Interface with the provided configuration.
45 *
46 * @param connectPoint the connect point this interface maps to
47 * @param ipAddresses Set of IP addresses
48 * @param macAddress MAC address
49 * @param vlan VLAN ID
50 */
51 public Interface(ConnectPoint connectPoint,
52 Set<InterfaceIpAddress> ipAddresses,
53 MacAddress macAddress, VlanId vlan) {
Jonathan Hart4cb39882015-08-12 23:50:55 -040054 this.connectPoint = checkNotNull(connectPoint);
Luca Pretee3879f72015-10-16 11:19:53 +020055 this.ipAddresses = ipAddresses == null ? Sets.newHashSet() : ipAddresses;
56 this.macAddress = macAddress == null ? MacAddress.NONE : macAddress;
57 this.vlan = vlan == null ? VlanId.NONE : vlan;
Jonathan Harteb8c9472015-08-05 07:43:13 -070058 }
59
60 /**
61 * Retrieves the connection point that this interface maps to.
62 *
63 * @return the connection point
64 */
65 public ConnectPoint connectPoint() {
66 return connectPoint;
67 }
68
69 /**
70 * Retrieves the set of IP addresses that are assigned to the interface.
71 *
72 * @return the set of interface IP addresses
73 */
74 public Set<InterfaceIpAddress> ipAddresses() {
75 return ipAddresses;
76 }
77
78 /**
79 * Retrieves the MAC address that is assigned to the interface.
80 *
81 * @return the MAC address
82 */
83 public MacAddress mac() {
84 return macAddress;
85 }
86
87 /**
88 * Retrieves the VLAN ID that is assigned to the interface.
89 *
90 * @return the VLAN ID
91 */
92 public VlanId vlan() {
93 return vlan;
94 }
95
96 @Override
97 public boolean equals(Object other) {
98 if (!(other instanceof Interface)) {
99 return false;
100 }
101
102 Interface otherInterface = (Interface) other;
103
104 return Objects.equals(connectPoint, otherInterface.connectPoint) &&
105 Objects.equals(ipAddresses, otherInterface.ipAddresses) &&
106 Objects.equals(macAddress, otherInterface.macAddress) &&
107 Objects.equals(vlan, otherInterface.vlan);
108 }
109
110 @Override
111 public int hashCode() {
112 return Objects.hash(connectPoint, ipAddresses, macAddress, vlan);
113 }
114
115 @Override
116 public String toString() {
117 return MoreObjects.toStringHelper(getClass())
118 .add("connectPoint", connectPoint)
119 .add("ipAddresses", ipAddresses)
120 .add("macAddress", macAddress)
121 .add("vlan", vlan)
122 .toString();
123 }
124}