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