Brian Stanke | 7a81b53 | 2016-06-14 15:43:51 -0400 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Brian Stanke | 7a81b53 | 2016-06-14 15:43:51 -0400 | [diff] [blame] | 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 | |
| 17 | package org.onosproject.incubator.net.virtual; |
| 18 | |
| 19 | import org.onlab.packet.IpAddress; |
| 20 | import org.onlab.packet.MacAddress; |
| 21 | import org.onlab.packet.VlanId; |
| 22 | import org.onosproject.net.DefaultAnnotations; |
| 23 | import org.onosproject.net.DefaultHost; |
| 24 | import org.onosproject.net.HostId; |
| 25 | import org.onosproject.net.HostLocation; |
| 26 | import org.onosproject.net.provider.ProviderId; |
| 27 | |
Charles Chan | cd06c69 | 2017-04-27 20:46:06 -0700 | [diff] [blame] | 28 | import java.util.Collections; |
Brian Stanke | 7a81b53 | 2016-06-14 15:43:51 -0400 | [diff] [blame] | 29 | import java.util.Objects; |
| 30 | import java.util.Set; |
| 31 | |
| 32 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 33 | |
| 34 | /** |
| 35 | * Default representation of a virtual host. |
| 36 | */ |
| 37 | public final class DefaultVirtualHost extends DefaultHost implements VirtualHost { |
| 38 | |
| 39 | private static final String VIRTUAL = "virtual"; |
| 40 | private static final ProviderId PID = new ProviderId(VIRTUAL, VIRTUAL); |
| 41 | |
| 42 | private final NetworkId networkId; |
| 43 | |
| 44 | /** |
| 45 | * Creates a virtual host attributed to the specified provider. |
| 46 | * |
| 47 | * @param networkId network identifier |
| 48 | * @param id host identifier |
| 49 | * @param mac host MAC address |
| 50 | * @param vlan host VLAN identifier |
| 51 | * @param location host location |
| 52 | * @param ips host IP addresses |
| 53 | */ |
| 54 | public DefaultVirtualHost(NetworkId networkId, HostId id, MacAddress mac, |
| 55 | VlanId vlan, HostLocation location, Set<IpAddress> ips) { |
Charles Chan | cd06c69 | 2017-04-27 20:46:06 -0700 | [diff] [blame] | 56 | this(networkId, id, mac, vlan, Collections.singleton(location), ips); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Creates a virtual host attributed to the specified provider. |
| 61 | * |
| 62 | * @param networkId network identifier |
| 63 | * @param id host identifier |
| 64 | * @param mac host MAC address |
| 65 | * @param vlan host VLAN identifier |
| 66 | * @param locations host locations |
| 67 | * @param ips host IP addresses |
| 68 | */ |
| 69 | public DefaultVirtualHost(NetworkId networkId, HostId id, MacAddress mac, |
| 70 | VlanId vlan, Set<HostLocation> locations, Set<IpAddress> ips) { |
| 71 | super(PID, id, mac, vlan, locations, ips, false, DefaultAnnotations.builder().build()); |
Brian Stanke | 7a81b53 | 2016-06-14 15:43:51 -0400 | [diff] [blame] | 72 | this.networkId = networkId; |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public NetworkId networkId() { |
| 77 | return networkId; |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public int hashCode() { |
| 82 | return Objects.hash(networkId); |
| 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public boolean equals(Object obj) { |
| 87 | if (this == obj) { |
| 88 | return true; |
| 89 | } |
| 90 | if (obj instanceof DefaultVirtualHost) { |
| 91 | DefaultVirtualHost that = (DefaultVirtualHost) obj; |
| 92 | return super.equals(that) && Objects.equals(this.networkId, that.networkId); |
| 93 | } |
| 94 | return false; |
| 95 | } |
| 96 | |
| 97 | @Override |
| 98 | public String toString() { |
| 99 | return toStringHelper(this).add("networkId", networkId).toString(); |
| 100 | } |
| 101 | } |