Jonathan Hart | eb8c947 | 2015-08-05 07:43:13 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.incubator.net.intf; |
| 17 | |
Thomas Vachuska | 4c571ae | 2015-09-10 16:31:59 -0700 | [diff] [blame] | 18 | import com.google.common.annotations.Beta; |
Jonathan Hart | eb8c947 | 2015-08-05 07:43:13 -0700 | [diff] [blame] | 19 | import com.google.common.base.MoreObjects; |
| 20 | import com.google.common.collect.Sets; |
| 21 | import org.onlab.packet.MacAddress; |
| 22 | import org.onlab.packet.VlanId; |
| 23 | import org.onosproject.net.ConnectPoint; |
| 24 | import org.onosproject.net.host.InterfaceIpAddress; |
| 25 | |
| 26 | import java.util.Objects; |
| 27 | import java.util.Set; |
| 28 | |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 29 | import static com.google.common.base.Preconditions.checkNotNull; |
| 30 | |
Jonathan Hart | eb8c947 | 2015-08-05 07:43:13 -0700 | [diff] [blame] | 31 | /** |
| 32 | * An Interface maps network configuration information (such as addresses and |
Luca Prete | e3879f7 | 2015-10-16 11:19:53 +0200 | [diff] [blame] | 33 | * vlans) to a port in the network. This is considered a L2/L3 network |
| 34 | * interface. |
Jonathan Hart | eb8c947 | 2015-08-05 07:43:13 -0700 | [diff] [blame] | 35 | */ |
Thomas Vachuska | 4c571ae | 2015-09-10 16:31:59 -0700 | [diff] [blame] | 36 | @Beta |
Jonathan Hart | eb8c947 | 2015-08-05 07:43:13 -0700 | [diff] [blame] | 37 | public 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 Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 54 | this.connectPoint = checkNotNull(connectPoint); |
Luca Prete | e3879f7 | 2015-10-16 11:19:53 +0200 | [diff] [blame] | 55 | this.ipAddresses = ipAddresses == null ? Sets.newHashSet() : ipAddresses; |
| 56 | this.macAddress = macAddress == null ? MacAddress.NONE : macAddress; |
| 57 | this.vlan = vlan == null ? VlanId.NONE : vlan; |
Jonathan Hart | eb8c947 | 2015-08-05 07:43:13 -0700 | [diff] [blame] | 58 | } |
| 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 | } |