blob: 88de214dbf9f268b739c3dd722c5ddd5c0a33d53 [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska781d18b2014-10-27 10:31:25 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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
Thomas Vachuska781d18b2014-10-27 10:31:25 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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.
Thomas Vachuska781d18b2014-10-27 10:31:25 -070015 */
Jonathan Hartbac07a02014-10-13 21:29:54 -070016package org.onlab.onos.sdnip.config;
17
18import java.util.Objects;
Jonathan Hartdc711bd2014-10-15 11:24:23 -070019import java.util.Set;
Jonathan Hartbac07a02014-10-13 21:29:54 -070020
Jonathan Hartbac07a02014-10-13 21:29:54 -070021import org.onlab.onos.net.ConnectPoint;
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -070022import org.onlab.onos.net.host.InterfaceIpAddress;
Jonathan Hartdc711bd2014-10-15 11:24:23 -070023import org.onlab.onos.net.host.PortAddresses;
Jonathan Hartdc711bd2014-10-15 11:24:23 -070024import org.onlab.packet.MacAddress;
25
26import com.google.common.base.MoreObjects;
27import com.google.common.collect.Sets;
Jonathan Hartbac07a02014-10-13 21:29:54 -070028
29/**
Jonathan Hartdc711bd2014-10-15 11:24:23 -070030 * An Interface is a set of addresses that are logically mapped to a switch
31 * port in the network.
Jonathan Hartbac07a02014-10-13 21:29:54 -070032 */
33public class Interface {
Jonathan Hartdc711bd2014-10-15 11:24:23 -070034 private final ConnectPoint connectPoint;
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -070035 private final Set<InterfaceIpAddress> ipAddresses;
Jonathan Hartdc711bd2014-10-15 11:24:23 -070036 private final MacAddress macAddress;
Jonathan Hartbac07a02014-10-13 21:29:54 -070037
38 /**
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -070039 * Creates an Interface based on a connection point, a set of interface
40 * IP addresses, and a MAC address.
Jonathan Hartbac07a02014-10-13 21:29:54 -070041 *
Jonathan Hartdc711bd2014-10-15 11:24:23 -070042 * @param connectPoint the connect point this interface is mapped to
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -070043 * @param ipAddresses the IP addresses for the interface
Jonathan Hartdc711bd2014-10-15 11:24:23 -070044 * @param macAddress the MAC address of the interface
Jonathan Hartbac07a02014-10-13 21:29:54 -070045 */
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -070046 public Interface(ConnectPoint connectPoint,
47 Set<InterfaceIpAddress> ipAddresses,
Jonathan Hartdc711bd2014-10-15 11:24:23 -070048 MacAddress macAddress) {
49 this.connectPoint = connectPoint;
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -070050 this.ipAddresses = Sets.newHashSet(ipAddresses);
Jonathan Hartdc711bd2014-10-15 11:24:23 -070051 this.macAddress = macAddress;
Jonathan Hartbac07a02014-10-13 21:29:54 -070052 }
53
54 /**
Jonathan Hartdc711bd2014-10-15 11:24:23 -070055 * Creates an Interface based on a PortAddresses object.
Jonathan Hartbac07a02014-10-13 21:29:54 -070056 *
Jonathan Hartdc711bd2014-10-15 11:24:23 -070057 * @param portAddresses the PortAddresses object to turn into an Interface
Jonathan Hartbac07a02014-10-13 21:29:54 -070058 */
Jonathan Hartdc711bd2014-10-15 11:24:23 -070059 public Interface(PortAddresses portAddresses) {
60 connectPoint = portAddresses.connectPoint();
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -070061 ipAddresses = Sets.newHashSet(portAddresses.ipAddresses());
Jonathan Hartdc711bd2014-10-15 11:24:23 -070062 macAddress = portAddresses.mac();
Jonathan Hartbac07a02014-10-13 21:29:54 -070063 }
64
65 /**
Jonathan Hartdc711bd2014-10-15 11:24:23 -070066 * Retrieves the connection point that this interface maps to.
Jonathan Hartbac07a02014-10-13 21:29:54 -070067 *
Jonathan Hartdc711bd2014-10-15 11:24:23 -070068 * @return the connection point
Jonathan Hartbac07a02014-10-13 21:29:54 -070069 */
Jonathan Hartdc711bd2014-10-15 11:24:23 -070070 public ConnectPoint connectPoint() {
71 return connectPoint;
Jonathan Hartbac07a02014-10-13 21:29:54 -070072 }
73
74 /**
Jonathan Hartdc711bd2014-10-15 11:24:23 -070075 * Retrieves the set of IP addresses that are assigned to the interface.
Jonathan Hartbac07a02014-10-13 21:29:54 -070076 *
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -070077 * @return the set of interface IP addresses
Jonathan Hartbac07a02014-10-13 21:29:54 -070078 */
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -070079 public Set<InterfaceIpAddress> ipAddresses() {
Jonathan Hartdc711bd2014-10-15 11:24:23 -070080 return ipAddresses;
Jonathan Hartbac07a02014-10-13 21:29:54 -070081 }
82
Jonathan Hartdc711bd2014-10-15 11:24:23 -070083 /**
84 * Retrieves the MAC address that is assigned to the interface.
85 *
86 * @return the MAC address
87 */
88 public MacAddress mac() {
89 return macAddress;
90 }
91
Jonathan Hartbac07a02014-10-13 21:29:54 -070092 @Override
93 public boolean equals(Object other) {
94 if (!(other instanceof Interface)) {
95 return false;
96 }
97
98 Interface otherInterface = (Interface) other;
99
Jonathan Hartdc711bd2014-10-15 11:24:23 -0700100 return connectPoint.equals(otherInterface.connectPoint) &&
101 ipAddresses.equals(otherInterface.ipAddresses) &&
102 macAddress.equals(otherInterface.macAddress);
Jonathan Hartbac07a02014-10-13 21:29:54 -0700103 }
104
105 @Override
106 public int hashCode() {
Jonathan Hartdc711bd2014-10-15 11:24:23 -0700107 return Objects.hash(connectPoint, ipAddresses, macAddress);
108 }
109
110 @Override
111 public String toString() {
112 return MoreObjects.toStringHelper(getClass())
113 .add("connectPoint", connectPoint)
114 .add("ipAddresses", ipAddresses)
115 .add("macAddress", macAddress)
116 .toString();
Jonathan Hartbac07a02014-10-13 21:29:54 -0700117 }
118}