blob: 61f31b19468c124110fc81892e78f8f5a90dfb63 [file] [log] [blame]
Brian Stanke7a81b532016-06-14 15:43:51 -04001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Brian Stanke7a81b532016-06-14 15:43:51 -04003 *
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
Charles Chancd06c692017-04-27 20:46:06 -070028import java.util.Collections;
Brian Stanke7a81b532016-06-14 15:43:51 -040029import java.util.Objects;
30import java.util.Set;
31
32import static com.google.common.base.MoreObjects.toStringHelper;
33
34/**
35 * Default representation of a virtual host.
36 */
37public 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 Chancd06c692017-04-27 20:46:06 -070056 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 Stanke7a81b532016-06-14 15:43:51 -040072 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}