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