blob: 347847a2596a9d03c250a206d805f1b8b9dada17 [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present 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 Hart2da1e602015-02-18 19:09:24 -080016package org.onosproject.routing.config;
Jonathan Hartbac07a02014-10-13 21:29:54 -070017
Jonathan Hart90a02c22015-02-13 11:52:07 -080018import com.google.common.base.MoreObjects;
19import com.google.common.collect.Sets;
Pavlin Radoslavov2020eac2015-01-06 17:26:10 -080020import org.onlab.packet.MacAddress;
Jonathan Hart6cd2f352015-01-13 17:44:45 -080021import org.onlab.packet.VlanId;
Brian O'Connorabafb502014-12-02 22:26:20 -080022import org.onosproject.net.ConnectPoint;
23import org.onosproject.net.host.InterfaceIpAddress;
Jonathan Hartdc711bd2014-10-15 11:24:23 -070024
Jonathan Hart90a02c22015-02-13 11:52:07 -080025import java.util.Objects;
26import java.util.Set;
Jonathan Hartbac07a02014-10-13 21:29:54 -070027
28/**
Jonathan Hartdc711bd2014-10-15 11:24:23 -070029 * An Interface is a set of addresses that are logically mapped to a switch
30 * port in the network.
Jonathan Hartbac07a02014-10-13 21:29:54 -070031 */
32public class Interface {
Jonathan Hartdc711bd2014-10-15 11:24:23 -070033 private final ConnectPoint connectPoint;
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -070034 private final Set<InterfaceIpAddress> ipAddresses;
Jonathan Hartdc711bd2014-10-15 11:24:23 -070035 private final MacAddress macAddress;
Jonathan Hart6cd2f352015-01-13 17:44:45 -080036 private final VlanId vlan;
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
Ray Milkeyf25d1352015-01-23 15:14:08 -080045 * @param vlan VLAN identifier
Jonathan Hartbac07a02014-10-13 21:29:54 -070046 */
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -070047 public Interface(ConnectPoint connectPoint,
48 Set<InterfaceIpAddress> ipAddresses,
Jonathan Hart6cd2f352015-01-13 17:44:45 -080049 MacAddress macAddress, VlanId vlan) {
Jonathan Hartdc711bd2014-10-15 11:24:23 -070050 this.connectPoint = connectPoint;
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -070051 this.ipAddresses = Sets.newHashSet(ipAddresses);
Jonathan Hartdc711bd2014-10-15 11:24:23 -070052 this.macAddress = macAddress;
Jonathan Hart6cd2f352015-01-13 17:44:45 -080053 this.vlan = vlan;
Jonathan Hartbac07a02014-10-13 21:29:54 -070054 }
55
56 /**
Jonathan Hartdc711bd2014-10-15 11:24:23 -070057 * Retrieves the connection point that this interface maps to.
Jonathan Hartbac07a02014-10-13 21:29:54 -070058 *
Jonathan Hartdc711bd2014-10-15 11:24:23 -070059 * @return the connection point
Jonathan Hartbac07a02014-10-13 21:29:54 -070060 */
Jonathan Hartdc711bd2014-10-15 11:24:23 -070061 public ConnectPoint connectPoint() {
62 return connectPoint;
Jonathan Hartbac07a02014-10-13 21:29:54 -070063 }
64
65 /**
Jonathan Hartdc711bd2014-10-15 11:24:23 -070066 * Retrieves the set of IP addresses that are assigned to the interface.
Jonathan Hartbac07a02014-10-13 21:29:54 -070067 *
Pavlin Radoslavov76b0ae22014-10-27 15:33:19 -070068 * @return the set of interface IP addresses
Jonathan Hartbac07a02014-10-13 21:29:54 -070069 */
Jonathan Hart6cd2f352015-01-13 17:44:45 -080070 public Set<InterfaceIpAddress> ipAddresses() {
Jonathan Hartdc711bd2014-10-15 11:24:23 -070071 return ipAddresses;
Jonathan Hartbac07a02014-10-13 21:29:54 -070072 }
73
Jonathan Hart6cd2f352015-01-13 17:44:45 -080074 /**
75 * Retrieves the MAC address that is assigned to the interface.
76 *
77 * @return the MAC address
78 */
79 public MacAddress mac() {
80 return macAddress;
81 }
82
83 /**
84 * Retrieves the VLAN ID that is assigned to the interface.
85 *
86 * @return the VLAN ID
87 */
88 public VlanId vlan() {
89 return vlan;
90 }
Jonathan Hartdc711bd2014-10-15 11:24:23 -070091
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) &&
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800102 macAddress.equals(otherInterface.macAddress) &&
103 vlan.equals(otherInterface.vlan);
Jonathan Hartbac07a02014-10-13 21:29:54 -0700104 }
105
106 @Override
107 public int hashCode() {
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800108 return Objects.hash(connectPoint, ipAddresses, macAddress, vlan);
Jonathan Hartdc711bd2014-10-15 11:24:23 -0700109 }
110
111 @Override
112 public String toString() {
113 return MoreObjects.toStringHelper(getClass())
114 .add("connectPoint", connectPoint)
115 .add("ipAddresses", ipAddresses)
116 .add("macAddress", macAddress)
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800117 .add("vlan", vlan)
Jonathan Hartdc711bd2014-10-15 11:24:23 -0700118 .toString();
Jonathan Hartbac07a02014-10-13 21:29:54 -0700119 }
120}